@@ -31,6 +31,7 @@ import { stringToRGB } from '../../../partition_chart/layout/utils/color_library
3131import { HeatmapSpec } from '../../specs' ;
3232import { HeatmapTable } from '../../state/selectors/compute_chart_dimensions' ;
3333import { ColorScaleType } from '../../state/selectors/get_color_scale' ;
34+ import { GridHeightParams } from '../../state/selectors/get_grid_full_height' ;
3435import { Config } from '../types/config_types' ;
3536import {
3637 Cell ,
@@ -39,7 +40,6 @@ import {
3940 PickHighlightedArea ,
4041 ShapeViewModel ,
4142} from '../types/viewmodel_types' ;
42- import { getGridCellHeight } from './grid' ;
4343
4444export interface HeatmapCellDatum {
4545 x : string | number ;
@@ -84,11 +84,11 @@ export function shapeViewModel(
8484 heatmapTable : HeatmapTable ,
8585 colorScale : ColorScaleType ,
8686 filterRanges : Array < [ number , number | null ] > ,
87+ { height, pageSize } : GridHeightParams ,
8788) : ShapeViewModel {
8889 const gridStrokeWidth = config . grid . stroke . width ?? 1 ;
8990
90- const { table, yValues } = heatmapTable ;
91- const { xDomain } = heatmapTable ;
91+ const { table, yValues, xDomain } = heatmapTable ;
9292
9393 // measure the text width of all rows values to get the grid area width
9494 const boxedYValues = yValues . map < Box & { value : string | number } > ( ( value ) => {
@@ -99,26 +99,13 @@ export function shapeViewModel(
9999 } ;
100100 } ) ;
101101
102- const maxGridAreaWidth = chartDimensions . width ;
103- const maxGridAreaHeight = chartDimensions . height ;
104-
105- // compute the grid cell height
106- const gridCellHeight = getGridCellHeight ( yValues , config ) ;
107- const maxHeight = gridCellHeight * yValues . length ;
108-
109- // compute the pageSize: how many rows can be fitted into the current panel height
110- const pageSize : number =
111- gridCellHeight > 0 && maxHeight > maxGridAreaHeight
112- ? Math . floor ( maxGridAreaHeight / gridCellHeight )
113- : yValues . length ;
114-
115102 // compute the scale for the rows positions
116103 const yScale = scaleBand < string | number > ( )
117104 . domain ( yValues )
118- . range ( [ 0 , maxHeight ] ) ;
105+ . range ( [ 0 , height ] ) ;
119106
120107 const yInvertedScale = scaleQuantize < string | number > ( )
121- . domain ( [ 0 , maxHeight ] )
108+ . domain ( [ 0 , height ] )
122109 . range ( yValues ) ;
123110
124111 let xValues = xDomain . domain ;
@@ -129,7 +116,7 @@ export function shapeViewModel(
129116 {
130117 type : ScaleType . Time ,
131118 domain : xDomain . domain ,
132- range : [ 0 , maxGridAreaWidth ] ,
119+ range : [ 0 , chartDimensions . width ] ,
133120 } ,
134121 {
135122 ticks : getTicks ( chartDimensions . width , config . xAxisLabel ) ,
@@ -152,10 +139,10 @@ export function shapeViewModel(
152139 // compute the scale for the columns positions
153140 const xScale = scaleBand < string | number > ( )
154141 . domain ( xValues )
155- . range ( [ 0 , maxGridAreaWidth ] ) ;
142+ . range ( [ 0 , chartDimensions . width ] ) ;
156143
157144 const xInvertedScale = scaleQuantize < string | number > ( )
158- . domain ( [ 0 , maxGridAreaWidth ] )
145+ . domain ( [ 0 , chartDimensions . width ] )
159146 . range ( xValues ) ;
160147
161148 // compute the cell width (can be smaller then the available size depending on config
@@ -370,22 +357,22 @@ export function shapeViewModel(
370357 const width = endFromScale - startFromScale + ( isOutOfRange ? cellWidth : 0 ) ;
371358
372359 // resolve Y coordinated making sure the order is correct
373- const { y : yStart , height } = y . reduce (
360+ const { y : yStart , totalHeight } = y . reduce (
374361 ( acc , current , i ) => {
375362 if ( i === 0 ) {
376363 acc . y = yScale ( current ) || 0 ;
377364 }
378- acc . height += cellHeight ;
365+ acc . totalHeight += cellHeight ;
379366 return acc ;
380367 } ,
381- { y : 0 , height : 0 } ,
368+ { y : 0 , totalHeight : 0 } ,
382369 ) ;
383370
384371 return {
385372 x : xStart ,
386373 y : yStart ,
387374 width,
388- height,
375+ height : totalHeight ,
389376 } ;
390377 } ;
391378
0 commit comments