-
Notifications
You must be signed in to change notification settings - Fork 122
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(heatmap): remove values when brushing only over axes #1364
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
67a5811
feat: crude attempt for limiting brush
rshen91 639a050
Merge remote-tracking branch 'upstream/master' into heatmap-brush-y
rshen91 51fce1b
Merge remote-tracking branch 'upstream/master' into heatmap-brush-y
rshen91 7c131ed
feat: remove x values from pickedShapes onbrushend event
rshen91 cd4b51a
test: add unit test
rshen91 e5ca9d9
style: inline mask id
rshen91 d6e1ca2
Merge remote-tracking branch 'upstream/master' into heatmap-brush-y
rshen91 11a84ec
feat: remove y values from x axis brushing
rshen91 d3aa056
fix: fix height calculation for the x axis hovering
rshen91 fb0b2db
Merge remote-tracking branch 'upstream/master' into heatmap-brush-y
rshen91 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
packages/charts/src/chart_types/heatmap/state/selectors/get_picked_cells.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { Store } from 'redux'; | ||
|
||
import { MockGlobalSpec, MockSeriesSpec } from '../../../../mocks/specs/specs'; | ||
import { MockStore } from '../../../../mocks/store/store'; | ||
import { ScaleType } from '../../../../scales/constants'; | ||
import { onPointerMove, onMouseDown, onMouseUp } from '../../../../state/actions/mouse'; | ||
import { GlobalChartState } from '../../../../state/chart_state'; | ||
import { createOnBrushEndCaller } from './on_brush_end_caller'; | ||
|
||
describe('Heatmap picked cells', () => { | ||
let store: Store<GlobalChartState>; | ||
let onBrushEndMock = jest.fn(); | ||
|
||
beforeEach(() => { | ||
store = MockStore.default({ width: 300, height: 300, top: 0, left: 0 }, 'chartId'); | ||
onBrushEndMock = jest.fn(); | ||
MockStore.addSpecs( | ||
[ | ||
MockGlobalSpec.settingsNoMargins(), | ||
MockSeriesSpec.heatmap({ | ||
xScaleType: ScaleType.Ordinal, | ||
data: [ | ||
{ x: 'a', y: 'ya', value: 1 }, | ||
{ x: 'b', y: 'ya', value: 2 }, | ||
{ x: 'c', y: 'ya', value: 3 }, | ||
{ x: 'a', y: 'yb', value: 4 }, | ||
{ x: 'b', y: 'yb', value: 5 }, | ||
{ x: 'c', y: 'yb', value: 6 }, | ||
{ x: 'a', y: 'yc', value: 7 }, | ||
{ x: 'b', y: 'yc', value: 8 }, | ||
{ x: 'c', y: 'yc', value: 9 }, | ||
], | ||
config: { | ||
brushTool: { visible: true }, | ||
grid: { | ||
cellHeight: { | ||
max: 'fill', | ||
}, | ||
cellWidth: { | ||
max: 'fill', | ||
}, | ||
}, | ||
xAxisLabel: { | ||
visible: true, | ||
}, | ||
yAxisLabel: { | ||
visible: true, | ||
}, | ||
margin: { top: 0, bottom: 0, left: 0, right: 0 }, | ||
onBrushEnd: onBrushEndMock, | ||
}, | ||
}), | ||
], | ||
store, | ||
); | ||
}); | ||
|
||
it('should pick cells', () => { | ||
const caller = createOnBrushEndCaller(); | ||
store.dispatch(onPointerMove({ x: 50, y: 50 }, 0)); | ||
store.dispatch(onMouseDown({ x: 50, y: 50 }, 100)); | ||
store.dispatch(onPointerMove({ x: 150, y: 250 }, 200)); | ||
store.dispatch(onMouseUp({ x: 150, y: 250 }, 300)); | ||
caller(store.getState()); | ||
const brushEvent = onBrushEndMock.mock.calls[0][0]; | ||
expect(brushEvent.x.length).toBe(2); | ||
}); | ||
it('should not include x values if only dragging along y-axis', () => { | ||
const caller = createOnBrushEndCaller(); | ||
store.dispatch(onPointerMove({ x: 0, y: 50 }, 0)); | ||
store.dispatch(onMouseDown({ x: 0, y: 50 }, 100)); | ||
store.dispatch(onPointerMove({ x: 0, y: 20 }, 200)); | ||
store.dispatch(onMouseUp({ x: 0, y: 20 }, 300)); | ||
caller(store.getState()); | ||
const brushEvent = onBrushEndMock.mock.calls[0][0]; | ||
expect(brushEvent.x.length).toBe(0); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also a preexisting code improvement opportunity: Here, we yield
null
if these predicates are true. But the continuation branch also yieldsnull
ifpointerOnLeftAxis
is true. So the bail can be deleted like this:A possible objection is that maybe it's stupid to calculate
pointerOnLeftAxis
if eg.dragShape === null
, its value won't be used. However, the way current JS engines work, it likely won't be computed, as JS engines are free to reorder operations, so most likely, it won't evaluate thepointerOnLeftAxis
expression unless needed so. It could be a different situation if thepointerOnLeftAxis
expression called some expensive function.Also, it's such a cheap calculation even if it were done, performance is not a concern, any difference is unmeasurable.
The gain is not just fewer lines to read (us) and send to the browser (payload) but the simpler, linear start to finish flow. Unless there's a strong reason, it's nice to work with expressions rather than statements, and it's nice to have a singular return point