Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
f675049
feat: limit brush tool through brush area
rshen91 Jul 27, 2021
aeec60c
fix: use dragShape to restrict
rshen91 Jul 27, 2021
6f99962
refactor: remove unused selector
rshen91 Jul 27, 2021
f822a55
test: add vrt test
rshen91 Jul 27, 2021
5fc5f9c
fix: add dragShape to conditional
rshen91 Jul 28, 2021
f32b036
Merge branch 'master' into brushtool-brushArea
rshen91 Jul 28, 2021
01f06ba
Merge remote-tracking branch 'upstream/master' into brushtool-brushArea
rshen91 Jul 28, 2021
c073c69
Merge remote-tracking branch 'upstream/master' into brushtool-brushArea
rshen91 Jul 29, 2021
ba8d5db
Merge branch 'master' into brushtool-brushArea
markov00 Jul 30, 2021
08657e2
fix: clamp end y to fit into chart only
rshen91 Aug 2, 2021
e7ef078
Merge remote-tracking branch 'upstream/master' into brushtool-brushArea
rshen91 Aug 9, 2021
d0227fb
Merge branch 'master' into brushtool-brushArea
rshen91 Aug 12, 2021
545e6e4
fix: merge commit
rshen91 Aug 16, 2021
c1218ef
Merge remote-tracking branch 'origin/brushtool-brushArea' into brusht…
rshen91 Aug 16, 2021
25fc202
Merge branch 'master' into brushtool-brushArea
rshen91 Aug 16, 2021
206713d
fix: fix campedEndY
rshen91 Aug 16, 2021
5e970b7
test: update vrt
rshen91 Aug 16, 2021
d9c53e5
Merge branch 'master' into brushtool-brushArea
rshen91 Aug 16, 2021
01046a6
Merge branch 'master' into brushtool-brushArea
rshen91 Aug 16, 2021
fa9b234
Merge branch 'master' into brushtool-brushArea
rshen91 Aug 16, 2021
55f5d5b
Merge branch 'master' into brushtool-brushArea
rshen91 Aug 17, 2021
1c1cfed
Merge branch 'master' into brushtool-brushArea
rshen91 Aug 17, 2021
fad1f2c
Merge branch 'master' into brushtool-brushArea
rshen91 Aug 18, 2021
cac1dab
Merge remote-tracking branch 'upstream/master' into brushtool-brushArea
rshen91 Aug 19, 2021
a623099
Merge remote-tracking branch 'origin/brushtool-brushArea' into brusht…
rshen91 Aug 19, 2021
697084a
Merge branch 'master' into brushtool-brushArea
rshen91 Aug 20, 2021
d4f3be6
Merge branch 'master' into brushtool-brushArea
rshen91 Aug 20, 2021
1a37039
Merge remote-tracking branch 'upstream/master' into brushtool-brushArea
rshen91 Aug 20, 2021
b3376f3
test: update vrt
rshen91 Aug 20, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions integration/tests/heatmap_stories.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* 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 { common } from '../page_objects';

describe('Heatmap stories', () => {
it('should not have brush tool extend into axes', async () => {
await common.expectChartWithDragAtUrlToMatchScreenshot(
'http://localhost:9001/?path=/story/heatmap-alpha--basic',
{ left: 100, top: 100 },
{ left: 300, top: 300 },
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ export const HighlighterCellsComponent: FC<HighlighterCellsProps> = ({
if (!initialized || dragShape === null) return null;

const maskId = `echHighlighterMask__${chartId}`;

return (
<svg className="echHighlighter" width="100%" height="100%">
<defs>
<mask id={maskId}>
{/* the entire chart */}
{brushMask.visible && (
<rect
x={0}
Expand All @@ -56,13 +56,15 @@ export const HighlighterCellsComponent: FC<HighlighterCellsProps> = ({
)}
{brushArea.visible && (
<>
{/* the rectangle box */}
Comment thread
markov00 marked this conversation as resolved.
<rect
x={dragShape.x}
y={dragShape.y}
width={dragShape.width}
height={dragShape.height}
fill={brushArea.fill}
/>
{/* the left axis labels */}
<rect
x={0}
y={dragShape.y}
Expand All @@ -75,6 +77,7 @@ export const HighlighterCellsComponent: FC<HighlighterCellsProps> = ({
</mask>
</defs>
<g>
{/* the entire chart */}
{brushMask.visible && (
<rect
x={0}
Expand All @@ -87,6 +90,7 @@ export const HighlighterCellsComponent: FC<HighlighterCellsProps> = ({
)}
{brushArea.visible && (
<>
{/* top line for the box */}
<line
x1={dragShape.x}
y1={dragShape.y}
Expand All @@ -95,6 +99,7 @@ export const HighlighterCellsComponent: FC<HighlighterCellsProps> = ({
stroke={brushArea.stroke}
strokeWidth={brushArea.strokeWidth}
/>
{/* bottom line */}
<line
x1={dragShape.x}
y1={dragShape.y + dragShape.height}
Expand All @@ -103,6 +108,7 @@ export const HighlighterCellsComponent: FC<HighlighterCellsProps> = ({
stroke={brushArea.stroke}
strokeWidth={brushArea.strokeWidth}
/>
{/* left line */}
<line
x1={dragShape.x}
y1={dragShape.y}
Expand All @@ -111,6 +117,7 @@ export const HighlighterCellsComponent: FC<HighlighterCellsProps> = ({
stroke={brushArea.stroke}
strokeWidth={brushArea.strokeWidth}
/>
{/* right line */}
<line
x1={dragShape.x + dragShape.width}
y1={dragShape.y}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@
import { BrushAxis } from '../../../../specs';
import { GlobalChartState } from '../../../../state/chart_state';
import { createCustomCachedSelector } from '../../../../state/create_selector';
import { getChartRotationSelector } from '../../../../state/selectors/get_chart_rotation';
import { getSettingsSpecSelector } from '../../../../state/selectors/get_settings_specs';
import { clamp } from '../../../../utils/common';
import { Dimensions } from '../../../../utils/dimensions';
import { computeChartDimensionsSelector } from './compute_chart_dimensions';
import { getBrushedHighlightedShapesSelector } from './get_brushed_highlighted_shapes';
import { getGridHeightParamsSelector } from './get_grid_full_height';

const getMouseDownPosition = (state: GlobalChartState) => state.interactions.pointer.down;
const getIsDragging = (state: GlobalChartState) => state.interactions.pointer.dragging;
Expand All @@ -24,22 +26,37 @@ export const getBrushAreaSelector = createCustomCachedSelector(
getIsDragging,
getMouseDownPosition,
getCurrentPointerPosition,
getChartRotationSelector,
getSettingsSpecSelector,
computeChartDimensionsSelector,
getBrushedHighlightedShapesSelector,
getGridHeightParamsSelector,
],
(isDragging, mouseDownPosition, end, chartRotation, { brushAxis }, chartDimensions): Dimensions | null => {
if (!isDragging || !mouseDownPosition) {
(isDragging, mouseDownPosition, end, { brushAxis }, chartDimensions, dragShape, gridParams): Dimensions | null => {
if (!isDragging || !mouseDownPosition || !dragShape) {
return null;
}
const start = {
x: mouseDownPosition.position.x - chartDimensions.left,
y: mouseDownPosition.position.y,
};

const clampedEndY = clamp(end.y, 0, gridParams.gridCellHeight * gridParams.pageSize);

switch (brushAxis) {
case BrushAxis.Both:
return {
top: start.y,
left: start.x,
width: end.x - start.x - chartDimensions.left,
height: clampedEndY - start.y,
};
default:
return { top: start.y, left: start.x, width: end.x - start.x - chartDimensions.left, height: end.y - start.y };
return {
top: start.y,
left: start.x,
width: end.x - start.x - chartDimensions.left,
height: clampedEndY - start.y,
};
}
},
);
44 changes: 22 additions & 22 deletions packages/charts/src/components/brush/brush.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,28 @@ class BrushToolComponent extends React.Component<Props> {
}
}

render() {
const { initialized, isBrushAvailable, isBrushing, projectionContainer, zIndex } = this.props;
if (!initialized || !isBrushAvailable || !isBrushing) {
this.ctx = null;
return null;
}
const { width, height } = projectionContainer;
return (
<canvas
ref={this.canvasRef}
className="echBrushTool"
width={width * this.devicePixelRatio}
height={height * this.devicePixelRatio}
style={{
width,
height,
zIndex,
}}
/>
);
}

private drawCanvas = () => {
const { brushArea, mainProjectionArea, fillColor } = this.props;
const { ctx } = this;
Expand Down Expand Up @@ -113,28 +135,6 @@ class BrushToolComponent extends React.Component<Props> {
const canvas = this.canvasRef.current;
this.ctx = canvas && canvas.getContext('2d');
}

render() {
const { initialized, isBrushAvailable, isBrushing, projectionContainer, zIndex } = this.props;
if (!initialized || !isBrushAvailable || !isBrushing) {
this.ctx = null;
return null;
}
const { width, height } = projectionContainer;
return (
<canvas
ref={this.canvasRef}
className="echBrushTool"
width={width * this.devicePixelRatio}
height={height * this.devicePixelRatio}
style={{
width,
height,
zIndex,
}}
/>
);
}
}

const mapStateToProps = (state: GlobalChartState): StateProps => {
Expand Down
3 changes: 3 additions & 0 deletions storybook/stories/heatmap/1_basic.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ export const Example = () => {

const config: RecursivePartial<Config> = useMemo(
() => ({
brushTool: {
visible: true,
},
grid: {
cellHeight: {
min: 20,
Expand Down