@antv/g2 5.0.0-beta.5 → 5.0.0-beta.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/g2-lite.min.js +4 -4
- package/dist/g2.min.js +4 -4
- package/esm/api/chart.d.ts +4 -0
- package/esm/api/chart.js +26 -4
- package/esm/api/chart.js.map +1 -1
- package/esm/api/mark/mark.js +1 -0
- package/esm/api/mark/mark.js.map +1 -1
- package/esm/api/mark/types.d.ts +1 -0
- package/esm/component/axis.js +18 -5
- package/esm/component/axis.js.map +1 -1
- package/esm/component/index.d.ts +2 -0
- package/esm/component/index.js +2 -0
- package/esm/component/index.js.map +1 -1
- package/esm/component/scrollbar.d.ts +9 -0
- package/esm/component/scrollbar.js +36 -0
- package/esm/component/scrollbar.js.map +1 -0
- package/esm/component/scrollbarX.d.ts +7 -0
- package/esm/component/scrollbarX.js +9 -0
- package/esm/component/scrollbarX.js.map +1 -0
- package/esm/component/scrollbarY.d.ts +7 -0
- package/esm/component/scrollbarY.js +9 -0
- package/esm/component/scrollbarY.js.map +1 -0
- package/esm/component/title.js +46 -22
- package/esm/component/title.js.map +1 -1
- package/esm/data/fold.js +4 -10
- package/esm/data/fold.js.map +1 -1
- package/esm/data/index.d.ts +2 -2
- package/esm/data/index.js +1 -1
- package/esm/data/index.js.map +1 -1
- package/esm/data/pick.js +10 -2
- package/esm/data/pick.js.map +1 -1
- package/esm/data/slice.d.ts +8 -0
- package/esm/data/slice.js +10 -0
- package/esm/data/slice.js.map +1 -0
- package/esm/interaction/index.d.ts +5 -0
- package/esm/interaction/index.js +4 -30
- package/esm/interaction/index.js.map +1 -1
- package/esm/interaction/native/brushAxisHighlight.d.ts +26 -0
- package/esm/interaction/native/brushAxisHighlight.js +159 -0
- package/esm/interaction/native/brushAxisHighlight.js.map +1 -0
- package/esm/interaction/native/brushFilter.d.ts +12 -0
- package/esm/interaction/native/brushFilter.js +147 -0
- package/esm/interaction/native/brushFilter.js.map +1 -0
- package/esm/interaction/native/brushHighlight.d.ts +30 -5
- package/esm/interaction/native/brushHighlight.js +92 -34
- package/esm/interaction/native/brushHighlight.js.map +1 -1
- package/esm/interaction/native/brushXFilter.d.ts +1 -0
- package/esm/interaction/native/brushXFilter.js +6 -0
- package/esm/interaction/native/brushXFilter.js.map +1 -0
- package/esm/interaction/native/brushXHighlight.d.ts +6 -1
- package/esm/interaction/native/brushXHighlight.js +5 -4
- package/esm/interaction/native/brushXHighlight.js.map +1 -1
- package/esm/interaction/native/brushYFilter.d.ts +1 -0
- package/esm/interaction/native/brushYFilter.js +6 -0
- package/esm/interaction/native/brushYFilter.js.map +1 -0
- package/esm/interaction/native/brushYHighlight.d.ts +6 -1
- package/esm/interaction/native/brushYHighlight.js +5 -4
- package/esm/interaction/native/brushYHighlight.js.map +1 -1
- package/esm/interaction/native/tooltip.js +6 -5
- package/esm/interaction/native/tooltip.js.map +1 -1
- package/esm/interaction/native/utils.d.ts +5 -1
- package/esm/interaction/native/utils.js +11 -3
- package/esm/interaction/native/utils.js.map +1 -1
- package/esm/mark/area.js +1 -1
- package/esm/mark/area.js.map +1 -1
- package/esm/mark/boxplot.js +5 -18
- package/esm/mark/boxplot.js.map +1 -1
- package/esm/runtime/component.js +33 -38
- package/esm/runtime/component.js.map +1 -1
- package/esm/runtime/layout.js +7 -7
- package/esm/runtime/layout.js.map +1 -1
- package/esm/runtime/plot.js +5 -1
- package/esm/runtime/plot.js.map +1 -1
- package/esm/runtime/render.d.ts +0 -1
- package/esm/runtime/render.js +4 -34
- package/esm/runtime/render.js.map +1 -1
- package/esm/runtime/transform.js +6 -2
- package/esm/runtime/transform.js.map +1 -1
- package/esm/runtime/types/common.d.ts +26 -9
- package/esm/runtime/types/options.d.ts +2 -5
- package/esm/runtime/types/theme.d.ts +2 -5
- package/esm/shape/area/curve.js +15 -8
- package/esm/shape/area/curve.js.map +1 -1
- package/esm/shape/box/box.js +1 -1
- package/esm/shape/box/box.js.map +1 -1
- package/esm/shape/connector/connector.js +2 -2
- package/esm/shape/connector/connector.js.map +1 -1
- package/esm/shape/image/image.js +2 -2
- package/esm/shape/image/image.js.map +1 -1
- package/esm/shape/interval/color.js +3 -1
- package/esm/shape/interval/color.js.map +1 -1
- package/esm/shape/label/position/default.d.ts +5 -7
- package/esm/shape/label/position/default.js +14 -40
- package/esm/shape/label/position/default.js.map +1 -1
- package/esm/shape/label/position/outside.d.ts +18 -1
- package/esm/shape/label/position/outside.js +66 -1
- package/esm/shape/label/position/outside.js.map +1 -1
- package/esm/shape/label/position/spider.d.ts +1 -1
- package/esm/shape/label/position/spider.js +12 -18
- package/esm/shape/label/position/spider.js.map +1 -1
- package/esm/shape/label/position/surround.d.ts +1 -1
- package/esm/shape/label/position/surround.js +12 -14
- package/esm/shape/label/position/surround.js.map +1 -1
- package/esm/shape/line/curve.js +1 -1
- package/esm/shape/line/curve.js.map +1 -1
- package/esm/shape/lineXY/line.js +2 -2
- package/esm/shape/lineXY/line.js.map +1 -1
- package/esm/shape/link/arc.js +2 -2
- package/esm/shape/link/arc.js.map +1 -1
- package/esm/shape/link/link.js +2 -2
- package/esm/shape/link/link.js.map +1 -1
- package/esm/shape/link/smooth.js +2 -2
- package/esm/shape/link/smooth.js.map +1 -1
- package/esm/shape/link/vhv.js +2 -2
- package/esm/shape/link/vhv.js.map +1 -1
- package/esm/shape/point/color.js +1 -1
- package/esm/shape/point/color.js.map +1 -1
- package/esm/shape/polygon/polygon.js +3 -3
- package/esm/shape/polygon/polygon.js.map +1 -1
- package/esm/shape/polygon/ribbon.js +3 -3
- package/esm/shape/polygon/ribbon.js.map +1 -1
- package/esm/shape/text/advance.js +1 -1
- package/esm/shape/text/advance.js.map +1 -1
- package/esm/shape/text/badge.js +3 -3
- package/esm/shape/text/badge.js.map +1 -1
- package/esm/shape/text/text.js +1 -1
- package/esm/shape/text/text.js.map +1 -1
- package/esm/shape/utils.d.ts +4 -0
- package/esm/shape/utils.js +6 -1
- package/esm/shape/utils.js.map +1 -1
- package/esm/shape/vector/vector.js +3 -3
- package/esm/shape/vector/vector.js.map +1 -1
- package/esm/spec/data.d.ts +24 -9
- package/esm/spec/geometry.d.ts +1 -0
- package/esm/spec/interaction.d.ts +22 -3
- package/esm/stdlib/index.js +5 -5
- package/esm/stdlib/index.js.map +1 -1
- package/esm/theme/academy.js +11 -15
- package/esm/theme/academy.js.map +1 -1
- package/esm/theme/dark.js +11 -18
- package/esm/theme/dark.js.map +1 -1
- package/esm/theme/light.js +25 -19
- package/esm/theme/light.js.map +1 -1
- package/lib/api/chart.d.ts +4 -0
- package/lib/api/chart.js +26 -4
- package/lib/api/chart.js.map +1 -1
- package/lib/api/mark/mark.js +1 -0
- package/lib/api/mark/mark.js.map +1 -1
- package/lib/api/mark/types.d.ts +1 -0
- package/lib/component/axis.js +18 -5
- package/lib/component/axis.js.map +1 -1
- package/lib/component/index.d.ts +2 -0
- package/lib/component/index.js +5 -1
- package/lib/component/index.js.map +1 -1
- package/lib/component/scrollbar.d.ts +9 -0
- package/lib/component/scrollbar.js +40 -0
- package/lib/component/scrollbar.js.map +1 -0
- package/lib/component/scrollbarX.d.ts +7 -0
- package/lib/component/scrollbarX.js +13 -0
- package/lib/component/scrollbarX.js.map +1 -0
- package/lib/component/scrollbarY.d.ts +7 -0
- package/lib/component/scrollbarY.js +13 -0
- package/lib/component/scrollbarY.js.map +1 -0
- package/lib/component/title.js +46 -22
- package/lib/component/title.js.map +1 -1
- package/lib/data/fold.js +4 -10
- package/lib/data/fold.js.map +1 -1
- package/lib/data/index.d.ts +2 -2
- package/lib/data/index.js +3 -3
- package/lib/data/index.js.map +1 -1
- package/lib/data/pick.js +10 -2
- package/lib/data/pick.js.map +1 -1
- package/lib/data/slice.d.ts +8 -0
- package/lib/data/slice.js +14 -0
- package/lib/data/slice.js.map +1 -0
- package/lib/interaction/index.d.ts +5 -0
- package/lib/interaction/index.js +9 -31
- package/lib/interaction/index.js.map +1 -1
- package/lib/interaction/native/brushAxisHighlight.d.ts +26 -0
- package/lib/interaction/native/brushAxisHighlight.js +164 -0
- package/lib/interaction/native/brushAxisHighlight.js.map +1 -0
- package/lib/interaction/native/brushFilter.d.ts +12 -0
- package/lib/interaction/native/brushFilter.js +152 -0
- package/lib/interaction/native/brushFilter.js.map +1 -0
- package/lib/interaction/native/brushHighlight.d.ts +30 -5
- package/lib/interaction/native/brushHighlight.js +91 -33
- package/lib/interaction/native/brushHighlight.js.map +1 -1
- package/lib/interaction/native/brushXFilter.d.ts +1 -0
- package/lib/interaction/native/brushXFilter.js +10 -0
- package/lib/interaction/native/brushXFilter.js.map +1 -0
- package/lib/interaction/native/brushXHighlight.d.ts +6 -1
- package/lib/interaction/native/brushXHighlight.js +7 -5
- package/lib/interaction/native/brushXHighlight.js.map +1 -1
- package/lib/interaction/native/brushYFilter.d.ts +1 -0
- package/lib/interaction/native/brushYFilter.js +10 -0
- package/lib/interaction/native/brushYFilter.js.map +1 -0
- package/lib/interaction/native/brushYHighlight.d.ts +6 -1
- package/lib/interaction/native/brushYHighlight.js +7 -5
- package/lib/interaction/native/brushYHighlight.js.map +1 -1
- package/lib/interaction/native/tooltip.js +6 -5
- package/lib/interaction/native/tooltip.js.map +1 -1
- package/lib/interaction/native/utils.d.ts +5 -1
- package/lib/interaction/native/utils.js +14 -5
- package/lib/interaction/native/utils.js.map +1 -1
- package/lib/mark/area.js +1 -1
- package/lib/mark/area.js.map +1 -1
- package/lib/mark/boxplot.js +5 -18
- package/lib/mark/boxplot.js.map +1 -1
- package/lib/runtime/component.js +33 -38
- package/lib/runtime/component.js.map +1 -1
- package/lib/runtime/layout.js +7 -7
- package/lib/runtime/layout.js.map +1 -1
- package/lib/runtime/plot.js +5 -1
- package/lib/runtime/plot.js.map +1 -1
- package/lib/runtime/render.d.ts +0 -1
- package/lib/runtime/render.js +4 -35
- package/lib/runtime/render.js.map +1 -1
- package/lib/runtime/transform.js +6 -2
- package/lib/runtime/transform.js.map +1 -1
- package/lib/runtime/types/common.d.ts +26 -9
- package/lib/runtime/types/options.d.ts +2 -5
- package/lib/runtime/types/theme.d.ts +2 -5
- package/lib/shape/area/curve.js +14 -7
- package/lib/shape/area/curve.js.map +1 -1
- package/lib/shape/box/box.js +1 -1
- package/lib/shape/box/box.js.map +1 -1
- package/lib/shape/connector/connector.js +2 -2
- package/lib/shape/connector/connector.js.map +1 -1
- package/lib/shape/image/image.js +2 -2
- package/lib/shape/image/image.js.map +1 -1
- package/lib/shape/interval/color.js +3 -1
- package/lib/shape/interval/color.js.map +1 -1
- package/lib/shape/label/position/default.d.ts +5 -7
- package/lib/shape/label/position/default.js +16 -40
- package/lib/shape/label/position/default.js.map +1 -1
- package/lib/shape/label/position/outside.d.ts +18 -1
- package/lib/shape/label/position/outside.js +72 -3
- package/lib/shape/label/position/outside.js.map +1 -1
- package/lib/shape/label/position/spider.d.ts +1 -1
- package/lib/shape/label/position/spider.js +12 -18
- package/lib/shape/label/position/spider.js.map +1 -1
- package/lib/shape/label/position/surround.d.ts +1 -1
- package/lib/shape/label/position/surround.js +11 -13
- package/lib/shape/label/position/surround.js.map +1 -1
- package/lib/shape/line/curve.js +1 -1
- package/lib/shape/line/curve.js.map +1 -1
- package/lib/shape/lineXY/line.js +2 -2
- package/lib/shape/lineXY/line.js.map +1 -1
- package/lib/shape/link/arc.js +2 -2
- package/lib/shape/link/arc.js.map +1 -1
- package/lib/shape/link/link.js +2 -2
- package/lib/shape/link/link.js.map +1 -1
- package/lib/shape/link/smooth.js +2 -2
- package/lib/shape/link/smooth.js.map +1 -1
- package/lib/shape/link/vhv.js +2 -2
- package/lib/shape/link/vhv.js.map +1 -1
- package/lib/shape/point/color.js +1 -1
- package/lib/shape/point/color.js.map +1 -1
- package/lib/shape/polygon/polygon.js +3 -3
- package/lib/shape/polygon/polygon.js.map +1 -1
- package/lib/shape/polygon/ribbon.js +3 -3
- package/lib/shape/polygon/ribbon.js.map +1 -1
- package/lib/shape/text/advance.js +1 -1
- package/lib/shape/text/advance.js.map +1 -1
- package/lib/shape/text/badge.js +3 -3
- package/lib/shape/text/badge.js.map +1 -1
- package/lib/shape/text/text.js +1 -1
- package/lib/shape/text/text.js.map +1 -1
- package/lib/shape/utils.d.ts +4 -0
- package/lib/shape/utils.js +6 -1
- package/lib/shape/utils.js.map +1 -1
- package/lib/shape/vector/vector.js +3 -3
- package/lib/shape/vector/vector.js.map +1 -1
- package/lib/spec/data.d.ts +24 -9
- package/lib/spec/geometry.d.ts +1 -0
- package/lib/spec/interaction.d.ts +22 -3
- package/lib/stdlib/index.js +2 -2
- package/lib/stdlib/index.js.map +1 -1
- package/lib/theme/academy.js +11 -15
- package/lib/theme/academy.js.map +1 -1
- package/lib/theme/dark.js +11 -18
- package/lib/theme/dark.js.map +1 -1
- package/lib/theme/light.js +25 -19
- package/lib/theme/light.js.map +1 -1
- package/package.json +1 -1
- package/src/api/chart.ts +29 -8
- package/src/api/mark/mark.ts +1 -0
- package/src/api/mark/types.ts +1 -0
- package/src/component/axis.ts +22 -5
- package/src/component/index.ts +2 -0
- package/src/component/scrollbar.ts +41 -0
- package/src/component/scrollbarX.ts +16 -0
- package/src/component/scrollbarY.ts +16 -0
- package/src/component/title.ts +69 -30
- package/src/data/fold.ts +6 -10
- package/src/data/index.ts +2 -2
- package/src/data/pick.ts +11 -2
- package/src/data/slice.ts +15 -0
- package/src/interaction/index.ts +20 -16
- package/src/interaction/native/brushAxisHighlight.ts +194 -0
- package/src/interaction/native/brushFilter.ts +163 -0
- package/src/interaction/native/brushHighlight.ts +104 -31
- package/src/interaction/native/brushXFilter.ts +9 -0
- package/src/interaction/native/brushXHighlight.ts +6 -4
- package/src/interaction/native/brushYFilter.ts +9 -0
- package/src/interaction/native/brushYHighlight.ts +6 -4
- package/src/interaction/native/tooltip.ts +9 -6
- package/src/interaction/native/utils.ts +15 -6
- package/src/mark/area.ts +1 -1
- package/src/mark/boxplot.ts +3 -1
- package/src/runtime/component.ts +46 -47
- package/src/runtime/layout.ts +6 -6
- package/src/runtime/plot.ts +6 -1
- package/src/runtime/render.ts +6 -58
- package/src/runtime/transform.ts +6 -2
- package/src/runtime/types/common.ts +26 -10
- package/src/runtime/types/options.ts +2 -5
- package/src/runtime/types/theme.ts +2 -5
- package/src/shape/area/curve.ts +15 -8
- package/src/shape/box/box.ts +6 -6
- package/src/shape/connector/connector.ts +2 -3
- package/src/shape/image/image.ts +2 -2
- package/src/shape/interval/color.ts +2 -1
- package/src/shape/label/position/default.ts +15 -55
- package/src/shape/label/position/outside.ts +121 -1
- package/src/shape/label/position/spider.ts +12 -19
- package/src/shape/label/position/surround.ts +13 -15
- package/src/shape/line/curve.ts +1 -1
- package/src/shape/lineXY/line.ts +2 -2
- package/src/shape/link/arc.ts +2 -2
- package/src/shape/link/link.ts +2 -2
- package/src/shape/link/smooth.ts +2 -2
- package/src/shape/link/vhv.ts +2 -2
- package/src/shape/point/color.ts +6 -5
- package/src/shape/polygon/polygon.ts +3 -3
- package/src/shape/polygon/ribbon.ts +3 -3
- package/src/shape/text/advance.ts +4 -1
- package/src/shape/text/badge.ts +8 -3
- package/src/shape/text/text.ts +1 -1
- package/src/shape/utils.ts +6 -5
- package/src/shape/vector/vector.ts +3 -3
- package/src/spec/action.ts +0 -1
- package/src/spec/data.ts +25 -10
- package/src/spec/geometry.ts +1 -0
- package/src/spec/interaction.ts +32 -2
- package/src/stdlib/index.ts +14 -2
- package/src/theme/academy.ts +11 -15
- package/src/theme/dark.ts +11 -18
- package/src/theme/light.ts +25 -19
- package/esm/data/subset.d.ts +0 -7
- package/esm/data/subset.js +0 -26
- package/esm/data/subset.js.map +0 -1
- package/lib/data/subset.d.ts +0 -7
- package/lib/data/subset.js +0 -30
- package/lib/data/subset.js.map +0 -1
- package/src/.DS_Store +0 -0
- package/src/data/.DS_Store +0 -0
- package/src/data/subset.ts +0 -35
- package/src/shape/.DS_Store +0 -0
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import { Rect } from '@antv/g';
|
|
2
|
+
import { subObject } from '../../utils/helper';
|
|
3
|
+
import { brush } from './brushHighlight';
|
|
4
|
+
import { brushXRegion } from './brushXHighlight';
|
|
5
|
+
import { brushYRegion } from './brushYHighlight';
|
|
6
|
+
import {
|
|
7
|
+
selectG2Elements,
|
|
8
|
+
createDatumof,
|
|
9
|
+
createValueof,
|
|
10
|
+
useState,
|
|
11
|
+
selectPlotArea,
|
|
12
|
+
} from './utils';
|
|
13
|
+
|
|
14
|
+
export const AXIS_CLASS_NAME = 'axis';
|
|
15
|
+
|
|
16
|
+
export const AXIS_LINE_CLASS_NAME = 'axis-line';
|
|
17
|
+
|
|
18
|
+
export const AXIS_MAIN_CLASS_NAME = 'axis-main-group';
|
|
19
|
+
|
|
20
|
+
export const AXIS_HOT_AREA_CLASS_NAME = 'axis-hot-area';
|
|
21
|
+
|
|
22
|
+
function axesOf(container) {
|
|
23
|
+
return container.getElementsByClassName(AXIS_CLASS_NAME);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function lineOf(axis) {
|
|
27
|
+
return axis.getElementsByClassName(AXIS_LINE_CLASS_NAME)[0];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function mainGroupOf(axis) {
|
|
31
|
+
return axis.getElementsByClassName(AXIS_MAIN_CLASS_NAME)[0];
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Use the bounds of main group of axis as the bounds of axis,
|
|
35
|
+
// get rid of grid and title.
|
|
36
|
+
function boundsOfAxis(axis) {
|
|
37
|
+
return mainGroupOf(axis).getLocalBounds();
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Brush for vertical axis.
|
|
41
|
+
function verticalBrush(axis, { cross, offsetX, offsetY, ...style }) {
|
|
42
|
+
const bounds = boundsOfAxis(axis);
|
|
43
|
+
const axisLine = lineOf(axis);
|
|
44
|
+
const [lineX] = axisLine.getLocalBounds().min;
|
|
45
|
+
const [minX, minY] = bounds.min;
|
|
46
|
+
const [maxX, maxY] = bounds.max;
|
|
47
|
+
const size = (maxX - minX) * 2;
|
|
48
|
+
return {
|
|
49
|
+
brushRegion: brushYRegion,
|
|
50
|
+
hotZone: new Rect({
|
|
51
|
+
className: AXIS_HOT_AREA_CLASS_NAME,
|
|
52
|
+
style: {
|
|
53
|
+
// If it is not cross, draw brush in both side of axisLine,
|
|
54
|
+
// otherwise the draw brush within bounds area.
|
|
55
|
+
x: cross ? minX : lineX - size / 2,
|
|
56
|
+
width: cross ? size / 2 : size,
|
|
57
|
+
y: minY,
|
|
58
|
+
height: maxY - minY,
|
|
59
|
+
...style,
|
|
60
|
+
},
|
|
61
|
+
}),
|
|
62
|
+
extent: cross
|
|
63
|
+
? // If it is cross, the x range is ignored.
|
|
64
|
+
(x, y, x1, y1) => [-Infinity, y, Infinity, y1]
|
|
65
|
+
: (x, y, x1, y1) => [
|
|
66
|
+
Math.floor(minX - offsetX),
|
|
67
|
+
y,
|
|
68
|
+
Math.ceil(maxX - offsetX),
|
|
69
|
+
y1,
|
|
70
|
+
],
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// Brush for horizontal axis.
|
|
75
|
+
function horizontalBrush(axis, { offsetY, offsetX, cross = false, ...style }) {
|
|
76
|
+
const bounds = boundsOfAxis(axis);
|
|
77
|
+
const axisLine = lineOf(axis);
|
|
78
|
+
const [, lineY] = axisLine.getLocalBounds().min;
|
|
79
|
+
const [minX, minY] = bounds.min;
|
|
80
|
+
const [maxX, maxY] = bounds.max;
|
|
81
|
+
const size = maxY - minY;
|
|
82
|
+
return {
|
|
83
|
+
brushRegion: brushXRegion,
|
|
84
|
+
hotZone: new Rect({
|
|
85
|
+
className: AXIS_HOT_AREA_CLASS_NAME,
|
|
86
|
+
style: {
|
|
87
|
+
x: minX,
|
|
88
|
+
width: maxX - minX,
|
|
89
|
+
// If it is not cross, draw brush in both side of axisLine,
|
|
90
|
+
// otherwise the draw brush within bounds area.
|
|
91
|
+
y: cross ? minY : lineY - size,
|
|
92
|
+
height: cross ? size : size * 2,
|
|
93
|
+
...style,
|
|
94
|
+
},
|
|
95
|
+
}),
|
|
96
|
+
extent: cross
|
|
97
|
+
? // If it is cross, the y range is ignored.
|
|
98
|
+
(x, y, x1, y1) => [x, -Infinity, x1, Infinity]
|
|
99
|
+
: (x, y, x1, y1) => [
|
|
100
|
+
x,
|
|
101
|
+
Math.floor(minY - offsetY),
|
|
102
|
+
x1,
|
|
103
|
+
Math.ceil(maxY - offsetY),
|
|
104
|
+
],
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export function brushAxisHighlight(
|
|
109
|
+
root,
|
|
110
|
+
{
|
|
111
|
+
axes: axesOf, // given root, return axes
|
|
112
|
+
elements: elementsOf, // given root, return elements
|
|
113
|
+
points: pointsOf, // given shape, return control points
|
|
114
|
+
horizontal: isHorizontal, // given axis, return direction
|
|
115
|
+
datum, // given shape, return datum
|
|
116
|
+
offsetY, // offsetY for shape area
|
|
117
|
+
offsetX, // offsetX for shape area
|
|
118
|
+
reverse = false,
|
|
119
|
+
...rest // style
|
|
120
|
+
},
|
|
121
|
+
) {
|
|
122
|
+
const elements = elementsOf(root);
|
|
123
|
+
const axes = axesOf(root);
|
|
124
|
+
const valueof = createValueof(elements, datum);
|
|
125
|
+
const { setState } = useState(rest, valueof);
|
|
126
|
+
const axisExtent = new Map();
|
|
127
|
+
const brushStyle = subObject(rest, 'mask');
|
|
128
|
+
|
|
129
|
+
// Only some of shape's points in all mask, it is selected.
|
|
130
|
+
const brushed = (points) =>
|
|
131
|
+
Array.from(axisExtent.values()).every(([x, y, x1, y1]) =>
|
|
132
|
+
points.some(([x0, y0]) => {
|
|
133
|
+
return x0 >= x && x0 <= x1 && y0 >= y && y0 <= y1;
|
|
134
|
+
}),
|
|
135
|
+
);
|
|
136
|
+
|
|
137
|
+
// Update element when brush changed.
|
|
138
|
+
const updateElement = () => {
|
|
139
|
+
for (const element of elements) {
|
|
140
|
+
const points = pointsOf(element);
|
|
141
|
+
if (brushed(points)) setState(element, 'highlighted');
|
|
142
|
+
else setState(element, 'unhighlighted');
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
// Distinguish between parallel coordinates and normal charts.
|
|
147
|
+
const cross = axes.some(isHorizontal) && axes.some((d) => !isHorizontal(d));
|
|
148
|
+
for (const axis of axes) {
|
|
149
|
+
const createBrush = isHorizontal(axis) ? horizontalBrush : verticalBrush;
|
|
150
|
+
const { hotZone, brushRegion, extent } = createBrush(axis, {
|
|
151
|
+
offsetY,
|
|
152
|
+
offsetX,
|
|
153
|
+
cross,
|
|
154
|
+
zIndex: 999, // Pin mask to top.
|
|
155
|
+
fill: 'transparent', // Make it interactive.
|
|
156
|
+
});
|
|
157
|
+
axis.parentNode.appendChild(hotZone);
|
|
158
|
+
brush(hotZone, {
|
|
159
|
+
...brushStyle,
|
|
160
|
+
reverse,
|
|
161
|
+
brushRegion,
|
|
162
|
+
brushended() {
|
|
163
|
+
axisExtent.delete(axis);
|
|
164
|
+
updateElement();
|
|
165
|
+
},
|
|
166
|
+
brushed(x, y, x1, y1) {
|
|
167
|
+
axisExtent.set(axis, extent(x, y, x1, y1));
|
|
168
|
+
updateElement();
|
|
169
|
+
},
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* @todo Support mask size.
|
|
176
|
+
*/
|
|
177
|
+
export function BrushAxisHighlight(options) {
|
|
178
|
+
return (target) => {
|
|
179
|
+
const { container, view } = target;
|
|
180
|
+
const plotArea = selectPlotArea(container);
|
|
181
|
+
const { x: x0, y: y0 } = plotArea.getBBox();
|
|
182
|
+
return brushAxisHighlight(container, {
|
|
183
|
+
elements: selectG2Elements,
|
|
184
|
+
axes: axesOf,
|
|
185
|
+
offsetY: y0,
|
|
186
|
+
offsetX: x0,
|
|
187
|
+
points: (element) => element.__data__.points,
|
|
188
|
+
horizontal: (axis) => axis.attributes.horizontal,
|
|
189
|
+
datum: createDatumof(view),
|
|
190
|
+
unhighlightedOpacity: 0.5,
|
|
191
|
+
...options,
|
|
192
|
+
});
|
|
193
|
+
};
|
|
194
|
+
}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import { deepMix } from '@antv/util';
|
|
2
|
+
import { bisectLeft, sort } from 'd3-array';
|
|
3
|
+
import { subObject } from '../../utils/helper';
|
|
4
|
+
import { selectPlotArea } from './utils';
|
|
5
|
+
import { brush as createBrush } from './brushHighlight';
|
|
6
|
+
|
|
7
|
+
// Mock dblclick events.
|
|
8
|
+
function dblclick(interval = 300) {
|
|
9
|
+
let preTimeStamp = null;
|
|
10
|
+
return (e) => {
|
|
11
|
+
const { timeStamp } = e;
|
|
12
|
+
if (preTimeStamp !== null && timeStamp - preTimeStamp < interval) {
|
|
13
|
+
preTimeStamp = timeStamp;
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
preTimeStamp = timeStamp;
|
|
17
|
+
return false;
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function brushFilter(
|
|
22
|
+
root,
|
|
23
|
+
{
|
|
24
|
+
filter,
|
|
25
|
+
reset,
|
|
26
|
+
brushRegion,
|
|
27
|
+
extent: optionalExtent,
|
|
28
|
+
reverse,
|
|
29
|
+
series = false,
|
|
30
|
+
...rest
|
|
31
|
+
},
|
|
32
|
+
) {
|
|
33
|
+
const brushStyle = subObject(rest, 'mask');
|
|
34
|
+
const { width: rootWidth, height: rootHeight } = root.getBBox();
|
|
35
|
+
const extent = optionalExtent
|
|
36
|
+
? optionalExtent
|
|
37
|
+
: [0, 0, rootWidth, rootHeight];
|
|
38
|
+
const isDblclick = dblclick();
|
|
39
|
+
|
|
40
|
+
const brush = createBrush(root, {
|
|
41
|
+
...brushStyle,
|
|
42
|
+
extent,
|
|
43
|
+
brushRegion,
|
|
44
|
+
reverse,
|
|
45
|
+
brushcreated,
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
root.addEventListener('click', click);
|
|
49
|
+
|
|
50
|
+
// Filter when brush created.
|
|
51
|
+
function brushcreated(x, y, x1, y1) {
|
|
52
|
+
filter(x, y, x1, y1);
|
|
53
|
+
brush.remove();
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Reset when dblclick.
|
|
57
|
+
function click(e) {
|
|
58
|
+
if (isDblclick(e)) reset();
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return () => {
|
|
62
|
+
brush.destroy();
|
|
63
|
+
root.removeEventListener('dblclick', click);
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function isOrdinalScale(scale) {
|
|
68
|
+
return scale.getBandWidth;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function constrain(x, lo, hi) {
|
|
72
|
+
return Math.min(hi, Math.max(lo, x));
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function invert(scale, x, start) {
|
|
76
|
+
if (!isOrdinalScale(scale)) return scale.invert(x);
|
|
77
|
+
const { adjustedRange } = scale;
|
|
78
|
+
const { domain } = scale.getOptions();
|
|
79
|
+
const offset = start ? -1 : 0;
|
|
80
|
+
const step = scale.getStep();
|
|
81
|
+
const range = start ? adjustedRange : adjustedRange.map((d) => d + step);
|
|
82
|
+
// R[i0 - 1] < x <= R[i0]
|
|
83
|
+
const i0 = bisectLeft(range, x);
|
|
84
|
+
const i1 = constrain(i0 + offset, 0, domain.length - 1);
|
|
85
|
+
return domain[i1];
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function domainOf(scale, values) {
|
|
89
|
+
if (!isOrdinalScale(scale)) return sort(values);
|
|
90
|
+
const { domain } = scale.getOptions();
|
|
91
|
+
const [v1, v2] = values;
|
|
92
|
+
const start = domain.indexOf(v1);
|
|
93
|
+
const end = domain.indexOf(v2);
|
|
94
|
+
return domain.slice(start, end + 1);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export function BrushFilter({ ...rest }) {
|
|
98
|
+
return (target, viewInstances) => {
|
|
99
|
+
const { container, view, options: viewOptions, update } = target;
|
|
100
|
+
const plotArea = selectPlotArea(container);
|
|
101
|
+
const defaultOptions = {
|
|
102
|
+
maskFill: '#777',
|
|
103
|
+
maskFillOpacity: '0.3',
|
|
104
|
+
maskStroke: '#fff',
|
|
105
|
+
unhighlightedOpacity: 0.5,
|
|
106
|
+
reverse: false,
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
let filtered = false;
|
|
110
|
+
let filtering = false;
|
|
111
|
+
let newView = view;
|
|
112
|
+
|
|
113
|
+
return brushFilter(plotArea, {
|
|
114
|
+
brushRegion: (x, y, x1, y1) => [x, y, x1, y1],
|
|
115
|
+
filter: async (x, y, x1, y1) => {
|
|
116
|
+
// Avoid redundant filter.
|
|
117
|
+
if (filtering) return;
|
|
118
|
+
filtering = true;
|
|
119
|
+
|
|
120
|
+
// Invert visual range to abstract domain.
|
|
121
|
+
const { scale, coordinate } = newView;
|
|
122
|
+
const { x: scaleX, y: scaleY } = scale;
|
|
123
|
+
const abstractDomain = (point, start) => {
|
|
124
|
+
const [x, y] = coordinate.invert(point);
|
|
125
|
+
return [invert(scaleX, x, start), invert(scaleY, y, start)];
|
|
126
|
+
};
|
|
127
|
+
const p0 = abstractDomain([x, y], true);
|
|
128
|
+
const p1 = abstractDomain([x1, y1], false);
|
|
129
|
+
|
|
130
|
+
// Update the domain of x and y scale to filter data.
|
|
131
|
+
const { marks } = viewOptions;
|
|
132
|
+
const newMarks = marks.map((mark) =>
|
|
133
|
+
deepMix({}, mark, {
|
|
134
|
+
scale: {
|
|
135
|
+
x: { domain: domainOf(scaleX, [p0[0], p1[0]]) },
|
|
136
|
+
y: { domain: domainOf(scaleY, [p0[1], p1[1]]) },
|
|
137
|
+
},
|
|
138
|
+
}),
|
|
139
|
+
);
|
|
140
|
+
|
|
141
|
+
// Rerender and update view.
|
|
142
|
+
const newOptions = {
|
|
143
|
+
...viewOptions,
|
|
144
|
+
marks: newMarks,
|
|
145
|
+
clip: true, // Clip shapes out of plot area.
|
|
146
|
+
};
|
|
147
|
+
const newState = await update(newOptions);
|
|
148
|
+
newView = newState.view;
|
|
149
|
+
filtering = false;
|
|
150
|
+
filtered = true;
|
|
151
|
+
},
|
|
152
|
+
reset: () => {
|
|
153
|
+
if (filtering || !filtered) return;
|
|
154
|
+
filtered = false;
|
|
155
|
+
newView = view;
|
|
156
|
+
update(viewOptions);
|
|
157
|
+
},
|
|
158
|
+
extent: undefined,
|
|
159
|
+
...defaultOptions,
|
|
160
|
+
...rest,
|
|
161
|
+
});
|
|
162
|
+
};
|
|
163
|
+
}
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
useState,
|
|
8
8
|
createValueof,
|
|
9
9
|
setCursor,
|
|
10
|
-
|
|
10
|
+
brushMousePosition,
|
|
11
11
|
selectFacetG2Elements,
|
|
12
12
|
} from './utils';
|
|
13
13
|
|
|
@@ -27,14 +27,23 @@ function normalizeBounds(x, y, x1, y1, extent) {
|
|
|
27
27
|
];
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
+
function bboxOf(root: DisplayObject) {
|
|
31
|
+
const { width, height } = root.getBBox();
|
|
32
|
+
return [0, 0, width, height];
|
|
33
|
+
}
|
|
34
|
+
|
|
30
35
|
export function brush(
|
|
31
36
|
root: DisplayObject,
|
|
32
37
|
{
|
|
33
|
-
brushed,
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
extent,
|
|
38
|
+
brushed = () => {},
|
|
39
|
+
brushended = () => {},
|
|
40
|
+
brushcreated = () => {},
|
|
41
|
+
extent = bboxOf(root),
|
|
42
|
+
brushRegion = (x, y, x1, y1, extent) => [x, y, x1, y1],
|
|
37
43
|
reverse = false,
|
|
44
|
+
fill = '#777',
|
|
45
|
+
fillOpacity = '0.3',
|
|
46
|
+
stroke = '#fff',
|
|
38
47
|
...style
|
|
39
48
|
}: Record<string, any>,
|
|
40
49
|
) {
|
|
@@ -63,6 +72,9 @@ export function brush(
|
|
|
63
72
|
background = new Path({
|
|
64
73
|
style: {
|
|
65
74
|
...style,
|
|
75
|
+
fill,
|
|
76
|
+
fillOpacity,
|
|
77
|
+
stroke,
|
|
66
78
|
pointerEvents: 'none',
|
|
67
79
|
},
|
|
68
80
|
});
|
|
@@ -83,6 +95,9 @@ export function brush(
|
|
|
83
95
|
// @ts-ignore
|
|
84
96
|
style: {
|
|
85
97
|
...style,
|
|
98
|
+
fill,
|
|
99
|
+
fillOpacity,
|
|
100
|
+
stroke,
|
|
86
101
|
draggable: true, // Make it response to drag event.
|
|
87
102
|
},
|
|
88
103
|
className: 'mask',
|
|
@@ -100,10 +115,10 @@ export function brush(
|
|
|
100
115
|
resizing = false;
|
|
101
116
|
mask = null;
|
|
102
117
|
background = null;
|
|
103
|
-
|
|
118
|
+
brushended();
|
|
104
119
|
};
|
|
105
120
|
|
|
106
|
-
// Update mask and invoke
|
|
121
|
+
// Update mask and invoke brushended callback.
|
|
107
122
|
const updateMask = (start, end) => {
|
|
108
123
|
const [x, y, x1, y1] = normalizeBounds(
|
|
109
124
|
start[0],
|
|
@@ -116,6 +131,7 @@ export function brush(
|
|
|
116
131
|
if (reverse) updateReverseMask(fx, fy, fx1, fy1);
|
|
117
132
|
else updateNormalMask(fx, fy, fx1, fy1);
|
|
118
133
|
brushed(fx, fy, fx1, fy1);
|
|
134
|
+
return [fx, fy, fx1, fy1];
|
|
119
135
|
};
|
|
120
136
|
|
|
121
137
|
const updateNormalMask = (x, y, x1, y1) => {
|
|
@@ -156,7 +172,7 @@ export function brush(
|
|
|
156
172
|
// If target is mask, about to update position.
|
|
157
173
|
const dragstart = (event) => {
|
|
158
174
|
const { target } = event;
|
|
159
|
-
const [offsetX, offsetY] =
|
|
175
|
+
const [offsetX, offsetY] = brushMousePosition(root, event);
|
|
160
176
|
if (target === mask) {
|
|
161
177
|
moveStart = [offsetX, offsetY];
|
|
162
178
|
return;
|
|
@@ -168,7 +184,7 @@ export function brush(
|
|
|
168
184
|
// If target is plot area, resize mask.
|
|
169
185
|
// If target is mask, move mask.
|
|
170
186
|
const drag = (event) => {
|
|
171
|
-
const mouse =
|
|
187
|
+
const mouse = brushMousePosition(root, event);
|
|
172
188
|
if (!start) return;
|
|
173
189
|
if (moveStart) return moveMask(mouse);
|
|
174
190
|
updateMask(start, mouse);
|
|
@@ -185,9 +201,10 @@ export function brush(
|
|
|
185
201
|
end = [x + width, y + height];
|
|
186
202
|
return;
|
|
187
203
|
}
|
|
188
|
-
end =
|
|
189
|
-
updateMask(start, end);
|
|
204
|
+
end = brushMousePosition(root, event);
|
|
205
|
+
const [fx, fy, fx1, fy1] = updateMask(start, end);
|
|
190
206
|
resizing = false;
|
|
207
|
+
brushcreated(fx, fy, fx1, fy1);
|
|
191
208
|
};
|
|
192
209
|
|
|
193
210
|
// Hide mask.
|
|
@@ -203,36 +220,69 @@ export function brush(
|
|
|
203
220
|
else setCursor(root, 'crosshair');
|
|
204
221
|
};
|
|
205
222
|
|
|
223
|
+
const pointerleave = () => {
|
|
224
|
+
setCursor(root, 'default');
|
|
225
|
+
};
|
|
226
|
+
|
|
206
227
|
root.addEventListener('dragstart', dragstart);
|
|
207
228
|
root.addEventListener('drag', drag);
|
|
208
229
|
root.addEventListener('dragend', dragend);
|
|
209
230
|
root.addEventListener('click', click);
|
|
210
231
|
root.addEventListener('pointermove', pointermove);
|
|
232
|
+
root.addEventListener('pointerleave', pointerleave);
|
|
211
233
|
|
|
212
|
-
return
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
234
|
+
return {
|
|
235
|
+
mask,
|
|
236
|
+
remove() {
|
|
237
|
+
if (mask) removeMask();
|
|
238
|
+
},
|
|
239
|
+
destroy() {
|
|
240
|
+
if (mask) removeMask();
|
|
241
|
+
root.removeEventListener('dragstart', dragstart);
|
|
242
|
+
root.removeEventListener('drag', drag);
|
|
243
|
+
root.removeEventListener('dragend', dragend);
|
|
244
|
+
root.removeEventListener('click', click);
|
|
245
|
+
root.removeEventListener('pointermove', pointermove);
|
|
246
|
+
root.removeEventListener('pointerleave', pointerleave);
|
|
247
|
+
},
|
|
220
248
|
};
|
|
221
249
|
}
|
|
222
250
|
|
|
251
|
+
function selectSiblingContainers(target, viewInstances, brushKey) {
|
|
252
|
+
return viewInstances
|
|
253
|
+
.filter((d) => {
|
|
254
|
+
if (d === target) return false;
|
|
255
|
+
const { interactions = [] } = d.options;
|
|
256
|
+
return interactions.find((d) => d.brushKey === brushKey);
|
|
257
|
+
})
|
|
258
|
+
.map((d) => selectPlotArea(d.container));
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* @todo Brush over view for series view.
|
|
263
|
+
* @todo Test perf.
|
|
264
|
+
*/
|
|
223
265
|
export function brushHighlight(
|
|
224
266
|
root,
|
|
225
267
|
{
|
|
226
268
|
elements: elementof,
|
|
269
|
+
siblings: siblingsof = (root) => [],
|
|
227
270
|
datum,
|
|
228
271
|
brushRegion,
|
|
229
272
|
extent: optionalExtent,
|
|
230
273
|
reverse,
|
|
231
274
|
series = false,
|
|
275
|
+
key = (d) => d,
|
|
276
|
+
bboxOf = (root) => {
|
|
277
|
+
const { x, y, width, height } = root.style;
|
|
278
|
+
return { x, y, width, height };
|
|
279
|
+
},
|
|
232
280
|
...rest
|
|
233
281
|
},
|
|
234
282
|
) {
|
|
235
283
|
const elements = elementof(root);
|
|
284
|
+
const siblings = siblingsof(root);
|
|
285
|
+
const siblingElements = siblings.flatMap(elementof);
|
|
236
286
|
const valueof = createValueof(elements, datum);
|
|
237
287
|
const brushStyle = subObject(rest, 'mask');
|
|
238
288
|
const { setState, removeState } = useState(rest, valueof);
|
|
@@ -242,24 +292,25 @@ export function brushHighlight(
|
|
|
242
292
|
height: rootHeight,
|
|
243
293
|
x: ordinalX,
|
|
244
294
|
y: ordinalY,
|
|
245
|
-
} = root
|
|
295
|
+
} = bboxOf(root);
|
|
246
296
|
const extent = optionalExtent
|
|
247
297
|
? optionalExtent
|
|
248
298
|
: [0, 0, rootWidth, rootHeight];
|
|
249
299
|
|
|
250
|
-
const
|
|
251
|
-
for (const element of elements
|
|
252
|
-
for (const cloned of clonedElement.values()) cloned.remove();
|
|
253
|
-
clonedElement.clear();
|
|
254
|
-
};
|
|
255
|
-
|
|
256
|
-
const brushend = () => {
|
|
257
|
-
for (const element of elements) {
|
|
300
|
+
const brushended = () => {
|
|
301
|
+
for (const element of [...elements, ...siblingElements]) {
|
|
258
302
|
removeState(element, 'highlighted', 'unhighlighted');
|
|
259
303
|
}
|
|
260
304
|
};
|
|
261
305
|
|
|
262
306
|
const brushed = (x, y, x1, y1) => {
|
|
307
|
+
// Hide brush for the sibling view.
|
|
308
|
+
for (const sibling of siblings) sibling.brush?.remove();
|
|
309
|
+
|
|
310
|
+
// Store the key of the highlighted element.
|
|
311
|
+
const keys = new Set();
|
|
312
|
+
|
|
313
|
+
// Highlight and store selected elements.
|
|
263
314
|
for (const element of elements) {
|
|
264
315
|
const { min, max } = element.getLocalBounds();
|
|
265
316
|
const [ex, ey] = min;
|
|
@@ -268,8 +319,21 @@ export function brushHighlight(
|
|
|
268
319
|
setState(element, 'unhighlighted');
|
|
269
320
|
} else {
|
|
270
321
|
setState(element, 'highlighted');
|
|
322
|
+
keys.add(key(element));
|
|
271
323
|
}
|
|
272
324
|
}
|
|
325
|
+
|
|
326
|
+
// Highlight elements with same key in sibling view.
|
|
327
|
+
for (const element of siblingElements) {
|
|
328
|
+
if (keys.has(key(element))) setState(element, 'highlighted');
|
|
329
|
+
else setState(element, 'unhighlighted');
|
|
330
|
+
}
|
|
331
|
+
};
|
|
332
|
+
|
|
333
|
+
const seriesBrushend = () => {
|
|
334
|
+
for (const element of elements) removeState(element, 'unhighlighted');
|
|
335
|
+
for (const cloned of clonedElement.values()) cloned.remove();
|
|
336
|
+
clonedElement.clear();
|
|
273
337
|
};
|
|
274
338
|
|
|
275
339
|
const seriesBrushed = (x, y, x1, y1) => {
|
|
@@ -299,12 +363,12 @@ export function brushHighlight(
|
|
|
299
363
|
extent,
|
|
300
364
|
brushRegion,
|
|
301
365
|
reverse,
|
|
302
|
-
|
|
366
|
+
brushended: series ? seriesBrushend : brushended,
|
|
303
367
|
brushed: series ? seriesBrushed : brushed,
|
|
304
368
|
});
|
|
305
369
|
}
|
|
306
370
|
|
|
307
|
-
export function BrushHighlight({ facet, ...rest }) {
|
|
371
|
+
export function BrushHighlight({ facet, brushKey, ...rest }) {
|
|
308
372
|
return (target, viewInstances) => {
|
|
309
373
|
const { container, view } = target;
|
|
310
374
|
const plotArea = selectPlotArea(container);
|
|
@@ -334,13 +398,22 @@ export function BrushHighlight({ facet, ...rest }) {
|
|
|
334
398
|
...rest,
|
|
335
399
|
});
|
|
336
400
|
}
|
|
337
|
-
|
|
401
|
+
|
|
402
|
+
const brush = brushHighlight(plotArea, {
|
|
338
403
|
elements: selectG2Elements,
|
|
404
|
+
key: (element) => element.__data__.key,
|
|
405
|
+
siblings: () => selectSiblingContainers(target, viewInstances, brushKey),
|
|
339
406
|
datum: createDatumof(view),
|
|
340
407
|
brushRegion: (x, y, x1, y1) => [x, y, x1, y1],
|
|
341
408
|
extent: undefined,
|
|
342
409
|
...defaultOptions,
|
|
343
410
|
...rest,
|
|
344
411
|
});
|
|
412
|
+
|
|
413
|
+
// Bind brush to the view it belongs to.
|
|
414
|
+
//@ts-ignore
|
|
415
|
+
plotArea.brush = brush;
|
|
416
|
+
|
|
417
|
+
return () => brush.destroy();
|
|
345
418
|
};
|
|
346
419
|
}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { BrushHighlight } from './brushHighlight';
|
|
2
2
|
|
|
3
|
+
export function brushXRegion(x, y, x1, y1, extent) {
|
|
4
|
+
const [, minY, , maxY] = extent;
|
|
5
|
+
return [x, minY, x1, maxY];
|
|
6
|
+
}
|
|
7
|
+
|
|
3
8
|
export function BrushXHighlight(options) {
|
|
4
9
|
return BrushHighlight({
|
|
5
10
|
...options,
|
|
6
|
-
brushRegion:
|
|
7
|
-
const [, minY, , maxY] = extent;
|
|
8
|
-
return [x, minY, x1, maxY];
|
|
9
|
-
},
|
|
11
|
+
brushRegion: brushXRegion,
|
|
10
12
|
});
|
|
11
13
|
}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { BrushHighlight } from './brushHighlight';
|
|
2
2
|
|
|
3
|
+
export function brushYRegion(x, y, x1, y1, extent) {
|
|
4
|
+
const [minX, , maxX] = extent;
|
|
5
|
+
return [minX, y, maxX, y1];
|
|
6
|
+
}
|
|
7
|
+
|
|
3
8
|
export function BrushYHighlight(options) {
|
|
4
9
|
return BrushHighlight({
|
|
5
10
|
...options,
|
|
6
|
-
brushRegion:
|
|
7
|
-
const [minX, , maxX] = extent;
|
|
8
|
-
return [minX, y, maxX, y1];
|
|
9
|
-
},
|
|
11
|
+
brushRegion: brushYRegion,
|
|
10
12
|
});
|
|
11
13
|
}
|