From 11ecc8eef373dc642b26f024c4c20d25ed0a65d3 Mon Sep 17 00:00:00 2001 From: Dima Arnautov Date: Tue, 6 Oct 2020 18:10:23 +0200 Subject: [PATCH] fix: filter highlighted y values --- .playground/playground.tsx | 7 +++++- .../heatmap/layout/viewmodel/viewmodel.ts | 22 ++++++++++--------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/.playground/playground.tsx b/.playground/playground.tsx index 969b107212..1de5c98987 100644 --- a/.playground/playground.tsx +++ b/.playground/playground.tsx @@ -148,7 +148,12 @@ export const SWIM_LANE_DATA = [ export class Playground extends React.Component { constructor(props: any) { super(props); - this.state = {}; + this.state = { + highlightedData: { + x: [1572874200000, 1572897600000], + y: ['Overall', 'test'], + }, + }; } onBrushEnd: HeatmapConfig['onBrushEnd'] = (e) => { diff --git a/src/chart_types/heatmap/layout/viewmodel/viewmodel.ts b/src/chart_types/heatmap/layout/viewmodel/viewmodel.ts index 2ea2d27db0..423dc79841 100644 --- a/src/chart_types/heatmap/layout/viewmodel/viewmodel.ts +++ b/src/chart_types/heatmap/layout/viewmodel/viewmodel.ts @@ -357,16 +357,18 @@ export function shapeViewModel( const width = endFromScale - startFromScale + (isOutOfRange ? cellWidth : 0); // resolve Y coordinated making sure the order is correct - const { y: yStart, totalHeight } = y.reduce( - (acc, current, i) => { - if (i === 0) { - acc.y = yScale(current) || 0; - } - acc.totalHeight += cellHeight; - return acc; - }, - { y: 0, totalHeight: 0 }, - ); + const { y: yStart, totalHeight } = y + .filter((v) => yValues.includes(v)) + .reduce( + (acc, current, i) => { + if (i === 0) { + acc.y = yScale(current) || 0; + } + acc.totalHeight += cellHeight; + return acc; + }, + { y: 0, totalHeight: 0 }, + ); return { x: xStart,