@antv/g2 5.0.0-beta.7 → 5.0.0-beta.9
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 +3 -3
- package/dist/g2.min.js +4 -4
- package/esm/animation/morphing.js +22 -2
- package/esm/animation/morphing.js.map +1 -1
- package/esm/api/chart.d.ts +8 -3
- package/esm/api/chart.js +35 -16
- package/esm/api/chart.js.map +1 -1
- package/esm/api/composition/base.d.ts +18 -1
- package/esm/api/composition/base.js +44 -1
- package/esm/api/composition/base.js.map +1 -1
- package/esm/api/mark/base.d.ts +22 -0
- package/esm/api/mark/base.js +54 -0
- package/esm/api/mark/base.js.map +1 -0
- package/esm/api/mark/mark.d.ts +1 -7
- package/esm/api/mark/mark.js +1 -13
- package/esm/api/mark/mark.js.map +1 -1
- package/esm/api/props.js +0 -20
- package/esm/api/props.js.map +1 -1
- package/esm/component/axis.d.ts +5 -7
- package/esm/component/axis.js +126 -94
- package/esm/component/axis.js.map +1 -1
- package/esm/component/axisArc.d.ts +7 -0
- package/esm/component/axisArc.js +9 -0
- package/esm/component/axisArc.js.map +1 -0
- package/esm/component/axisRadar.d.ts +9 -0
- package/esm/component/axisRadar.js +46 -0
- package/esm/component/axisRadar.js.map +1 -0
- package/esm/component/axisX.d.ts +2 -1
- package/esm/component/axisX.js +5 -4
- package/esm/component/axisX.js.map +1 -1
- package/esm/component/axisY.d.ts +1 -1
- package/esm/component/axisY.js +4 -4
- package/esm/component/axisY.js.map +1 -1
- package/esm/component/index.d.ts +8 -0
- package/esm/component/index.js +5 -0
- package/esm/component/index.js.map +1 -1
- package/esm/component/legendCategory.d.ts +5 -3
- package/esm/component/legendCategory.js +80 -36
- package/esm/component/legendCategory.js.map +1 -1
- package/esm/component/legendContinuous.d.ts +4 -2
- package/esm/component/legendContinuous.js +76 -24
- package/esm/component/legendContinuous.js.map +1 -1
- package/esm/component/legendContinuousBlock.d.ts +4 -0
- package/esm/component/legendContinuousBlock.js +6 -0
- package/esm/component/legendContinuousBlock.js.map +1 -0
- package/esm/component/legendContinuousBlockSize.d.ts +4 -0
- package/esm/component/legendContinuousBlockSize.js +6 -0
- package/esm/component/legendContinuousBlockSize.js.map +1 -0
- package/esm/component/legendContinuousSize.d.ts +4 -0
- package/esm/component/legendContinuousSize.js +10 -0
- package/esm/component/legendContinuousSize.js.map +1 -0
- package/esm/component/scrollbar.js +1 -1
- package/esm/component/scrollbar.js.map +1 -1
- package/esm/component/slider.js +1 -1
- package/esm/component/slider.js.map +1 -1
- package/esm/component/title.js +1 -1
- package/esm/component/title.js.map +1 -1
- package/esm/component/utils.d.ts +12 -0
- package/esm/component/utils.js +35 -0
- package/esm/component/utils.js.map +1 -1
- package/esm/composition/facetCircle.js +1 -1
- package/esm/composition/facetCircle.js.map +1 -1
- package/esm/coordinate/index.d.ts +3 -3
- package/esm/coordinate/index.js +3 -3
- package/esm/coordinate/index.js.map +1 -1
- package/esm/coordinate/polar.d.ts +6 -0
- package/esm/coordinate/polar.js +18 -6
- package/esm/coordinate/polar.js.map +1 -1
- package/esm/coordinate/radial.d.ts +6 -0
- package/esm/coordinate/radial.js +17 -5
- package/esm/coordinate/radial.js.map +1 -1
- package/esm/coordinate/theta.d.ts +7 -0
- package/esm/coordinate/theta.js +16 -4
- package/esm/coordinate/theta.js.map +1 -1
- package/esm/interaction/builtin/elementHighlight.d.ts +2 -0
- package/esm/interaction/builtin/elementHighlightByColor.d.ts +2 -0
- package/esm/interaction/builtin/elementHighlightByX.d.ts +2 -0
- package/esm/interaction/index.d.ts +2 -0
- package/esm/interaction/index.js +2 -0
- package/esm/interaction/index.js.map +1 -1
- package/esm/interaction/native/brushAxisHighlight.js +6 -1
- package/esm/interaction/native/brushAxisHighlight.js.map +1 -1
- package/esm/interaction/native/brushFilter.js +1 -1
- package/esm/interaction/native/brushFilter.js.map +1 -1
- package/esm/interaction/native/elementHighlight.d.ts +7 -2
- package/esm/interaction/native/elementHighlight.js +72 -19
- package/esm/interaction/native/elementHighlight.js.map +1 -1
- package/esm/interaction/native/elementHighlightByColor.d.ts +4 -1
- package/esm/interaction/native/elementHighlightByColor.js +19 -3
- package/esm/interaction/native/elementHighlightByColor.js.map +1 -1
- package/esm/interaction/native/elementHighlightByX.d.ts +3 -3
- package/esm/interaction/native/elementHighlightByX.js +19 -3
- package/esm/interaction/native/elementHighlightByX.js.map +1 -1
- package/esm/interaction/native/elementSelect.d.ts +1 -1
- package/esm/interaction/native/elementSelect.js +42 -21
- package/esm/interaction/native/elementSelect.js.map +1 -1
- package/esm/interaction/native/elementSelectByColor.js +3 -2
- package/esm/interaction/native/elementSelectByColor.js.map +1 -1
- package/esm/interaction/native/elementSelectByX.js +3 -2
- package/esm/interaction/native/elementSelectByX.js.map +1 -1
- package/esm/interaction/native/legendFilter.d.ts +6 -0
- package/esm/interaction/native/legendFilter.js +26 -7
- package/esm/interaction/native/legendFilter.js.map +1 -1
- package/esm/interaction/native/legendHighlight.d.ts +4 -0
- package/esm/interaction/native/legendHighlight.js +93 -0
- package/esm/interaction/native/legendHighlight.js.map +1 -0
- package/esm/interaction/native/poptip.d.ts +5 -0
- package/esm/interaction/native/poptip.js +91 -0
- package/esm/interaction/native/poptip.js.map +1 -0
- package/esm/interaction/native/utils.d.ts +13 -2
- package/esm/interaction/native/utils.js +151 -26
- package/esm/interaction/native/utils.js.map +1 -1
- package/esm/label-transform/overlapDodgeY.js +0 -8
- package/esm/label-transform/overlapDodgeY.js.map +1 -1
- package/esm/mark/area.js +1 -1
- package/esm/mark/area.js.map +1 -1
- package/esm/mark/pack.js +0 -1
- package/esm/mark/pack.js.map +1 -1
- package/esm/mark/treemap.js +0 -1
- package/esm/mark/treemap.js.map +1 -1
- package/esm/runtime/component.d.ts +3 -0
- package/esm/runtime/component.js +246 -103
- package/esm/runtime/component.js.map +1 -1
- package/esm/runtime/coordinate.d.ts +11 -0
- package/esm/runtime/coordinate.js +23 -16
- package/esm/runtime/coordinate.js.map +1 -1
- package/esm/runtime/layout.d.ts +1 -1
- package/esm/runtime/layout.js +145 -76
- package/esm/runtime/layout.js.map +1 -1
- package/esm/runtime/plot.js +5 -4
- package/esm/runtime/plot.js.map +1 -1
- package/esm/runtime/render.js +18 -13
- package/esm/runtime/render.js.map +1 -1
- package/esm/runtime/scale.d.ts +2 -1
- package/esm/runtime/scale.js +35 -0
- package/esm/runtime/scale.js.map +1 -1
- package/esm/runtime/transform.js +1 -1
- package/esm/runtime/transform.js.map +1 -1
- package/esm/runtime/types/common.d.ts +11 -2
- package/esm/runtime/types/component.d.ts +9 -7
- package/esm/runtime/types/options.d.ts +8 -6
- package/esm/runtime/types/scale.d.ts +18 -0
- package/esm/runtime/types/scale.js +19 -0
- package/esm/runtime/types/scale.js.map +1 -0
- package/esm/runtime/types/theme.d.ts +2 -1
- package/esm/shape/area/hv.d.ts +3 -0
- package/esm/shape/area/hv.js +9 -0
- package/esm/shape/area/hv.js.map +1 -0
- package/esm/shape/area/hvh.d.ts +3 -0
- package/esm/shape/area/{step.js → hvh.js} +3 -3
- package/esm/shape/area/hvh.js.map +1 -0
- package/esm/shape/area/vh.d.ts +3 -0
- package/esm/shape/area/vh.js +9 -0
- package/esm/shape/area/vh.js.map +1 -0
- package/esm/shape/connector/connector.js +1 -1
- package/esm/shape/index.d.ts +6 -2
- package/esm/shape/index.js +3 -1
- package/esm/shape/index.js.map +1 -1
- package/esm/shape/interval/color.d.ts +1 -0
- package/esm/shape/interval/color.js +65 -53
- package/esm/shape/interval/color.js.map +1 -1
- package/esm/shape/utils.js.map +1 -1
- package/esm/spec/composition.d.ts +0 -3
- package/esm/spec/geometry.d.ts +1 -1
- package/esm/spec/interaction.d.ts +33 -15
- package/esm/spec/transform.d.ts +13 -3
- package/esm/stdlib/index.js +4 -9
- package/esm/stdlib/index.js.map +1 -1
- package/esm/theme/academy.js +10 -4
- package/esm/theme/academy.js.map +1 -1
- package/esm/theme/dark.js +10 -4
- package/esm/theme/dark.js.map +1 -1
- package/esm/theme/light.js +12 -4
- package/esm/theme/light.js.map +1 -1
- package/esm/transform/sample.js +42 -26
- package/esm/transform/sample.js.map +1 -1
- package/esm/transform/utils/lttb.d.ts +5 -0
- package/esm/transform/utils/lttb.js +56 -0
- package/esm/transform/utils/lttb.js.map +1 -0
- package/esm/utils/angle.d.ts +2 -0
- package/esm/utils/angle.js +7 -0
- package/esm/utils/angle.js.map +1 -0
- package/esm/utils/array.d.ts +8 -0
- package/esm/utils/array.js +35 -0
- package/esm/utils/array.js.map +1 -1
- package/esm/utils/coordinate.d.ts +4 -0
- package/esm/utils/coordinate.js +19 -0
- package/esm/utils/coordinate.js.map +1 -1
- package/esm/utils/event.d.ts +0 -2
- package/esm/utils/event.js +0 -18
- package/esm/utils/event.js.map +1 -1
- package/esm/utils/scale.d.ts +1 -0
- package/esm/utils/scale.js +3 -3
- package/esm/utils/scale.js.map +1 -1
- package/esm/utils/vector.d.ts +1 -1
- package/esm/utils/vector.js +1 -1
- package/lib/animation/morphing.js +22 -2
- package/lib/animation/morphing.js.map +1 -1
- package/lib/api/chart.d.ts +8 -3
- package/lib/api/chart.js +37 -15
- package/lib/api/chart.js.map +1 -1
- package/lib/api/composition/base.d.ts +18 -1
- package/lib/api/composition/base.js +44 -1
- package/lib/api/composition/base.js.map +1 -1
- package/lib/api/mark/base.d.ts +22 -0
- package/lib/api/mark/base.js +58 -0
- package/lib/api/mark/base.js.map +1 -0
- package/lib/api/mark/mark.d.ts +1 -7
- package/lib/api/mark/mark.js +28 -41
- package/lib/api/mark/mark.js.map +1 -1
- package/lib/api/props.js +0 -20
- package/lib/api/props.js.map +1 -1
- package/lib/component/axis.d.ts +5 -7
- package/lib/component/axis.js +127 -96
- package/lib/component/axis.js.map +1 -1
- package/lib/component/axisArc.d.ts +7 -0
- package/lib/component/axisArc.js +13 -0
- package/lib/component/axisArc.js.map +1 -0
- package/lib/component/axisRadar.d.ts +9 -0
- package/lib/component/axisRadar.js +50 -0
- package/lib/component/axisRadar.js.map +1 -0
- package/lib/component/axisX.d.ts +2 -1
- package/lib/component/axisX.js +6 -4
- package/lib/component/axisX.js.map +1 -1
- package/lib/component/axisY.d.ts +1 -1
- package/lib/component/axisY.js +3 -3
- package/lib/component/axisY.js.map +1 -1
- package/lib/component/index.d.ts +8 -0
- package/lib/component/index.js +12 -1
- package/lib/component/index.js.map +1 -1
- package/lib/component/legendCategory.d.ts +5 -3
- package/lib/component/legendCategory.js +79 -35
- package/lib/component/legendCategory.js.map +1 -1
- package/lib/component/legendContinuous.d.ts +4 -2
- package/lib/component/legendContinuous.js +75 -23
- package/lib/component/legendContinuous.js.map +1 -1
- package/lib/component/legendContinuousBlock.d.ts +4 -0
- package/lib/component/legendContinuousBlock.js +10 -0
- package/lib/component/legendContinuousBlock.js.map +1 -0
- package/lib/component/legendContinuousBlockSize.d.ts +4 -0
- package/lib/component/legendContinuousBlockSize.js +10 -0
- package/lib/component/legendContinuousBlockSize.js.map +1 -0
- package/lib/component/legendContinuousSize.d.ts +4 -0
- package/lib/component/legendContinuousSize.js +14 -0
- package/lib/component/legendContinuousSize.js.map +1 -0
- package/lib/component/scrollbar.js +1 -1
- package/lib/component/scrollbar.js.map +1 -1
- package/lib/component/slider.js +1 -1
- package/lib/component/slider.js.map +1 -1
- package/lib/component/title.js +1 -1
- package/lib/component/title.js.map +1 -1
- package/lib/component/utils.d.ts +12 -0
- package/lib/component/utils.js +39 -1
- package/lib/component/utils.js.map +1 -1
- package/lib/composition/facetCircle.js +1 -1
- package/lib/composition/facetCircle.js.map +1 -1
- package/lib/coordinate/index.d.ts +3 -3
- package/lib/coordinate/index.js +4 -1
- package/lib/coordinate/index.js.map +1 -1
- package/lib/coordinate/polar.d.ts +6 -0
- package/lib/coordinate/polar.js +20 -7
- package/lib/coordinate/polar.js.map +1 -1
- package/lib/coordinate/radial.d.ts +6 -0
- package/lib/coordinate/radial.js +19 -6
- package/lib/coordinate/radial.js.map +1 -1
- package/lib/coordinate/theta.d.ts +7 -0
- package/lib/coordinate/theta.js +18 -5
- package/lib/coordinate/theta.js.map +1 -1
- package/lib/interaction/builtin/elementHighlight.d.ts +2 -0
- package/lib/interaction/builtin/elementHighlightByColor.d.ts +2 -0
- package/lib/interaction/builtin/elementHighlightByX.d.ts +2 -0
- package/lib/interaction/index.d.ts +2 -0
- package/lib/interaction/index.js +5 -1
- package/lib/interaction/index.js.map +1 -1
- package/lib/interaction/native/brushAxisHighlight.js +6 -1
- package/lib/interaction/native/brushAxisHighlight.js.map +1 -1
- package/lib/interaction/native/brushFilter.js +1 -1
- package/lib/interaction/native/brushFilter.js.map +1 -1
- package/lib/interaction/native/elementHighlight.d.ts +7 -2
- package/lib/interaction/native/elementHighlight.js +71 -18
- package/lib/interaction/native/elementHighlight.js.map +1 -1
- package/lib/interaction/native/elementHighlightByColor.d.ts +4 -1
- package/lib/interaction/native/elementHighlightByColor.js +18 -2
- package/lib/interaction/native/elementHighlightByColor.js.map +1 -1
- package/lib/interaction/native/elementHighlightByX.d.ts +3 -3
- package/lib/interaction/native/elementHighlightByX.js +18 -2
- package/lib/interaction/native/elementHighlightByX.js.map +1 -1
- package/lib/interaction/native/elementSelect.d.ts +1 -1
- package/lib/interaction/native/elementSelect.js +41 -20
- package/lib/interaction/native/elementSelect.js.map +1 -1
- package/lib/interaction/native/elementSelectByColor.js +2 -1
- package/lib/interaction/native/elementSelectByColor.js.map +1 -1
- package/lib/interaction/native/elementSelectByX.js +2 -1
- package/lib/interaction/native/elementSelectByX.js.map +1 -1
- package/lib/interaction/native/legendFilter.d.ts +6 -0
- package/lib/interaction/native/legendFilter.js +31 -6
- package/lib/interaction/native/legendFilter.js.map +1 -1
- package/lib/interaction/native/legendHighlight.d.ts +4 -0
- package/lib/interaction/native/legendHighlight.js +97 -0
- package/lib/interaction/native/legendHighlight.js.map +1 -0
- package/lib/interaction/native/poptip.d.ts +5 -0
- package/lib/interaction/native/poptip.js +95 -0
- package/lib/interaction/native/poptip.js.map +1 -0
- package/lib/interaction/native/utils.d.ts +13 -2
- package/lib/interaction/native/utils.js +154 -27
- package/lib/interaction/native/utils.js.map +1 -1
- package/lib/label-transform/overlapDodgeY.js +0 -8
- package/lib/label-transform/overlapDodgeY.js.map +1 -1
- package/lib/mark/area.js +1 -1
- package/lib/mark/area.js.map +1 -1
- package/lib/mark/pack.js +0 -1
- package/lib/mark/pack.js.map +1 -1
- package/lib/mark/treemap.js +0 -1
- package/lib/mark/treemap.js.map +1 -1
- package/lib/runtime/component.d.ts +3 -0
- package/lib/runtime/component.js +250 -107
- package/lib/runtime/component.js.map +1 -1
- package/lib/runtime/coordinate.d.ts +11 -0
- package/lib/runtime/coordinate.js +26 -17
- package/lib/runtime/coordinate.js.map +1 -1
- package/lib/runtime/layout.d.ts +1 -1
- package/lib/runtime/layout.js +146 -77
- package/lib/runtime/layout.js.map +1 -1
- package/lib/runtime/plot.js +4 -3
- package/lib/runtime/plot.js.map +1 -1
- package/lib/runtime/render.js +20 -12
- package/lib/runtime/render.js.map +1 -1
- package/lib/runtime/scale.d.ts +2 -1
- package/lib/runtime/scale.js +37 -1
- package/lib/runtime/scale.js.map +1 -1
- package/lib/runtime/transform.js +1 -1
- package/lib/runtime/transform.js.map +1 -1
- package/lib/runtime/types/common.d.ts +11 -2
- package/lib/runtime/types/component.d.ts +9 -7
- package/lib/runtime/types/options.d.ts +8 -6
- package/lib/runtime/types/scale.d.ts +18 -0
- package/lib/runtime/types/scale.js +22 -0
- package/lib/runtime/types/scale.js.map +1 -0
- package/lib/runtime/types/theme.d.ts +2 -1
- package/lib/shape/area/hv.d.ts +3 -0
- package/lib/shape/area/hv.js +13 -0
- package/lib/shape/area/hv.js.map +1 -0
- package/lib/shape/area/hvh.d.ts +3 -0
- package/lib/shape/area/{step.js → hvh.js} +5 -5
- package/lib/shape/area/hvh.js.map +1 -0
- package/lib/shape/area/vh.d.ts +3 -0
- package/lib/shape/area/vh.js +13 -0
- package/lib/shape/area/vh.js.map +1 -0
- package/lib/shape/connector/connector.js +1 -1
- package/lib/shape/index.d.ts +6 -2
- package/lib/shape/index.js +7 -3
- package/lib/shape/index.js.map +1 -1
- package/lib/shape/interval/color.d.ts +1 -0
- package/lib/shape/interval/color.js +67 -54
- package/lib/shape/interval/color.js.map +1 -1
- package/lib/shape/utils.js.map +1 -1
- package/lib/spec/composition.d.ts +0 -3
- package/lib/spec/geometry.d.ts +1 -1
- package/lib/spec/interaction.d.ts +33 -15
- package/lib/spec/transform.d.ts +13 -3
- package/lib/stdlib/index.js +1 -1
- package/lib/stdlib/index.js.map +1 -1
- package/lib/theme/academy.js +10 -4
- package/lib/theme/academy.js.map +1 -1
- package/lib/theme/dark.js +10 -4
- package/lib/theme/dark.js.map +1 -1
- package/lib/theme/light.js +12 -4
- package/lib/theme/light.js.map +1 -1
- package/lib/transform/sample.js +42 -26
- package/lib/transform/sample.js.map +1 -1
- package/lib/transform/utils/lttb.d.ts +5 -0
- package/lib/transform/utils/lttb.js +60 -0
- package/lib/transform/utils/lttb.js.map +1 -0
- package/lib/utils/angle.d.ts +2 -0
- package/lib/utils/angle.js +12 -0
- package/lib/utils/angle.js.map +1 -0
- package/lib/utils/array.d.ts +8 -0
- package/lib/utils/array.js +38 -1
- package/lib/utils/array.js.map +1 -1
- package/lib/utils/coordinate.d.ts +4 -0
- package/lib/utils/coordinate.js +24 -1
- package/lib/utils/coordinate.js.map +1 -1
- package/lib/utils/event.d.ts +0 -2
- package/lib/utils/event.js +1 -21
- package/lib/utils/event.js.map +1 -1
- package/lib/utils/scale.d.ts +1 -0
- package/lib/utils/scale.js +5 -4
- package/lib/utils/scale.js.map +1 -1
- package/lib/utils/vector.d.ts +1 -1
- package/lib/utils/vector.js +1 -1
- package/package.json +7 -7
- package/src/animation/morphing.ts +23 -2
- package/src/api/chart.ts +43 -20
- package/src/api/composition/base.ts +46 -1
- package/src/api/mark/base.ts +58 -0
- package/src/api/mark/mark.ts +1 -20
- package/src/api/props.ts +0 -23
- package/src/component/axis.ts +199 -118
- package/src/component/axisArc.ts +16 -0
- package/src/component/axisRadar.ts +73 -0
- package/src/component/axisX.ts +7 -4
- package/src/component/axisY.ts +4 -4
- package/src/component/index.ts +8 -0
- package/src/component/legendCategory.ts +156 -35
- package/src/component/legendContinuous.ts +133 -32
- package/src/component/legendContinuousBlock.ts +17 -0
- package/src/component/legendContinuousBlockSize.ts +22 -0
- package/src/component/legendContinuousSize.ts +27 -0
- package/src/component/scrollbar.ts +1 -1
- package/src/component/slider.ts +1 -1
- package/src/component/title.ts +1 -1
- package/src/component/utils.ts +46 -0
- package/src/composition/facetCircle.ts +1 -1
- package/src/coordinate/index.ts +3 -3
- package/src/coordinate/polar.ts +19 -11
- package/src/coordinate/radial.ts +19 -10
- package/src/coordinate/theta.ts +18 -9
- package/src/interaction/index.ts +2 -0
- package/src/interaction/native/brushAxisHighlight.ts +9 -1
- package/src/interaction/native/brushFilter.ts +1 -1
- package/src/interaction/native/elementHighlight.ts +78 -12
- package/src/interaction/native/elementHighlightByColor.ts +9 -4
- package/src/interaction/native/elementHighlightByX.ts +9 -5
- package/src/interaction/native/elementSelect.ts +58 -15
- package/src/interaction/native/elementSelectByColor.ts +4 -1
- package/src/interaction/native/elementSelectByX.ts +4 -1
- package/src/interaction/native/legendFilter.ts +29 -7
- package/src/interaction/native/legendHighlight.ts +86 -0
- package/src/interaction/native/poptip.ts +87 -0
- package/src/interaction/native/utils.ts +183 -26
- package/src/label-transform/overlapDodgeY.ts +0 -7
- package/src/mark/area.ts +1 -1
- package/src/mark/pack.ts +0 -1
- package/src/mark/treemap.ts +0 -1
- package/src/runtime/component.ts +335 -124
- package/src/runtime/coordinate.ts +29 -16
- package/src/runtime/layout.ts +206 -97
- package/src/runtime/plot.ts +5 -4
- package/src/runtime/render.ts +26 -13
- package/src/runtime/scale.ts +41 -0
- package/src/runtime/transform.ts +3 -0
- package/src/runtime/types/common.ts +23 -10
- package/src/runtime/types/component.ts +19 -10
- package/src/runtime/types/options.ts +24 -16
- package/src/runtime/types/scale.ts +20 -0
- package/src/runtime/types/theme.ts +2 -1
- package/src/shape/area/hv.ts +20 -0
- package/src/shape/area/{step.ts → hvh.ts} +3 -3
- package/src/shape/area/vh.ts +20 -0
- package/src/shape/connector/connector.ts +1 -1
- package/src/shape/index.ts +7 -2
- package/src/shape/interval/color.ts +86 -54
- package/src/shape/utils.ts +2 -0
- package/src/spec/composition.ts +0 -1
- package/src/spec/geometry.ts +3 -1
- package/src/spec/interaction.ts +51 -19
- package/src/spec/transform.ts +27 -2
- package/src/stdlib/index.ts +22 -6
- package/src/theme/academy.ts +10 -4
- package/src/theme/dark.ts +10 -4
- package/src/theme/light.ts +12 -4
- package/src/transform/sample.ts +54 -18
- package/src/transform/utils/lttb.ts +73 -0
- package/src/utils/angle.ts +7 -0
- package/src/utils/array.ts +39 -0
- package/src/utils/coordinate.ts +29 -0
- package/src/utils/event.ts +0 -26
- package/src/utils/scale.ts +4 -4
- package/src/utils/vector.ts +1 -1
- package/esm/shape/area/step.d.ts +0 -3
- package/esm/shape/area/step.js.map +0 -1
- package/lib/shape/area/step.d.ts +0 -3
- package/lib/shape/area/step.js.map +0 -1
package/src/coordinate/radial.ts
CHANGED
|
@@ -5,18 +5,27 @@ import { Reflect } from './reflect';
|
|
|
5
5
|
|
|
6
6
|
export type RadialOptions = Omit<RadialCoordinate, 'type'>;
|
|
7
7
|
|
|
8
|
+
export const getRadialOptions = (options: RadialOptions = {}) => {
|
|
9
|
+
const defaultOptions = {
|
|
10
|
+
startAngle: -Math.PI / 2,
|
|
11
|
+
endAngle: (Math.PI * 3) / 2,
|
|
12
|
+
innerRadius: 0,
|
|
13
|
+
outerRadius: 1,
|
|
14
|
+
};
|
|
15
|
+
return { ...defaultOptions, ...options };
|
|
16
|
+
};
|
|
17
|
+
|
|
8
18
|
/**
|
|
9
19
|
* Radial
|
|
10
20
|
*/
|
|
11
|
-
export const Radial: CC<RadialOptions> = ({
|
|
12
|
-
startAngle
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
];
|
|
21
|
+
export const Radial: CC<RadialOptions> = (options) => {
|
|
22
|
+
const { startAngle, endAngle, innerRadius, outerRadius } =
|
|
23
|
+
getRadialOptions(options);
|
|
24
|
+
return [
|
|
25
|
+
['transpose'],
|
|
26
|
+
...Reflect(),
|
|
27
|
+
...Polar({ startAngle, endAngle, innerRadius, outerRadius }),
|
|
28
|
+
];
|
|
29
|
+
};
|
|
21
30
|
|
|
22
31
|
Radial.props = {};
|
package/src/coordinate/theta.ts
CHANGED
|
@@ -5,17 +5,26 @@ import { Transpose } from './transpose';
|
|
|
5
5
|
|
|
6
6
|
export type ThetaOptions = ThetaCoordinate;
|
|
7
7
|
|
|
8
|
+
export const getThetaOptions = (options: ThetaOptions = {}) => {
|
|
9
|
+
const defaultOptions = {
|
|
10
|
+
startAngle: -Math.PI / 2,
|
|
11
|
+
endAngle: (Math.PI * 3) / 2,
|
|
12
|
+
innerRadius: 0,
|
|
13
|
+
outerRadius: 1,
|
|
14
|
+
};
|
|
15
|
+
return { ...defaultOptions, ...options };
|
|
16
|
+
};
|
|
17
|
+
|
|
8
18
|
/**
|
|
9
19
|
* Theta = Transpose + Polar.
|
|
10
20
|
*/
|
|
11
|
-
export const Theta: CC<ThetaOptions> = ({
|
|
12
|
-
startAngle
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
})
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
];
|
|
21
|
+
export const Theta: CC<ThetaOptions> = (options) => {
|
|
22
|
+
const { startAngle, endAngle, innerRadius, outerRadius } =
|
|
23
|
+
getThetaOptions(options);
|
|
24
|
+
return [
|
|
25
|
+
...Transpose(),
|
|
26
|
+
...Polar({ startAngle, endAngle, innerRadius, outerRadius }),
|
|
27
|
+
];
|
|
28
|
+
};
|
|
20
29
|
|
|
21
30
|
Theta.props = {};
|
package/src/interaction/index.ts
CHANGED
|
@@ -10,6 +10,7 @@ export { ChartIndex } from './native/chartIndex';
|
|
|
10
10
|
export { Fisheye } from './native/fisheye';
|
|
11
11
|
export { Tooltip } from './native/tooltip';
|
|
12
12
|
export { LegendFilter } from './native/legendFilter';
|
|
13
|
+
export { LegendHighlight } from './native/legendHighlight';
|
|
13
14
|
export { BrushHighlight } from './native/brushHighlight';
|
|
14
15
|
export { BrushXHighlight } from './native/brushXHighlight';
|
|
15
16
|
export { BrushYHighlight } from './native/brushYHighlight';
|
|
@@ -18,6 +19,7 @@ export { BrushFilter } from './native/brushFilter';
|
|
|
18
19
|
export { BrushXFilter } from './native/brushXFilter';
|
|
19
20
|
export { BrushYFilter } from './native/brushYFilter';
|
|
20
21
|
export { SliderFilter } from './native/sliderFilter';
|
|
22
|
+
export { Poptip } from './native/poptip';
|
|
21
23
|
|
|
22
24
|
export { LEGEND_ITEMS_CLASS_NAME } from './native/legendFilter';
|
|
23
25
|
|
|
@@ -185,7 +185,15 @@ export function BrushAxisHighlight(options) {
|
|
|
185
185
|
offsetY: y0,
|
|
186
186
|
offsetX: x0,
|
|
187
187
|
points: (element) => element.__data__.points,
|
|
188
|
-
horizontal: (axis) =>
|
|
188
|
+
horizontal: (axis) => {
|
|
189
|
+
const {
|
|
190
|
+
startPos: [sx, sy],
|
|
191
|
+
endPos: [ex, ey],
|
|
192
|
+
} = axis.attributes;
|
|
193
|
+
// attention, non-horizontal does not mean vertical
|
|
194
|
+
// it may has a specific degree angle
|
|
195
|
+
return sx !== ex && sy === ey;
|
|
196
|
+
},
|
|
189
197
|
datum: createDatumof(view),
|
|
190
198
|
unhighlightedOpacity: 0.5,
|
|
191
199
|
...options,
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { DisplayObject } from '@antv/g';
|
|
2
2
|
import { group } from 'd3-array';
|
|
3
|
+
import { isPolar, isTranspose } from '../../utils/coordinate';
|
|
3
4
|
import { subObject } from '../../utils/helper';
|
|
4
5
|
import {
|
|
5
6
|
createValueof,
|
|
@@ -8,6 +9,9 @@ import {
|
|
|
8
9
|
useState,
|
|
9
10
|
renderLink,
|
|
10
11
|
applyDefaultsHighlightedStyle,
|
|
12
|
+
renderBackground,
|
|
13
|
+
selectPlotArea,
|
|
14
|
+
offsetTransform,
|
|
11
15
|
} from './utils';
|
|
12
16
|
|
|
13
17
|
/**
|
|
@@ -20,6 +24,11 @@ export function elementHighlight(
|
|
|
20
24
|
datum, // given each element returns the datum of it
|
|
21
25
|
groupKey = (d) => d, // group elements by specified key
|
|
22
26
|
link = false, // draw link or not
|
|
27
|
+
background = false, // draw background or not
|
|
28
|
+
delay = 60, // delay to unhighlighted element
|
|
29
|
+
scale,
|
|
30
|
+
coordinate,
|
|
31
|
+
offset = 0,
|
|
23
32
|
...rest
|
|
24
33
|
}: Record<string, any>,
|
|
25
34
|
) {
|
|
@@ -27,50 +36,107 @@ export function elementHighlight(
|
|
|
27
36
|
const elementSet = new Set(elements);
|
|
28
37
|
const keyGroup = group(elements, groupKey);
|
|
29
38
|
const valueof = createValueof(elements, datum);
|
|
30
|
-
const [appendLink, removeLink] = renderLink(
|
|
39
|
+
const [appendLink, removeLink] = renderLink({
|
|
31
40
|
elements,
|
|
32
41
|
valueof,
|
|
42
|
+
link,
|
|
43
|
+
coordinate,
|
|
33
44
|
...subObject(rest, 'link'),
|
|
34
45
|
});
|
|
35
|
-
const
|
|
46
|
+
const [appendBackground, removeBackground, isBackground] = renderBackground({
|
|
47
|
+
scale,
|
|
48
|
+
coordinate,
|
|
49
|
+
background,
|
|
50
|
+
valueof,
|
|
51
|
+
...subObject(rest, 'background'),
|
|
52
|
+
});
|
|
53
|
+
const elementStyle = {
|
|
54
|
+
...(offset !== 0 && {
|
|
55
|
+
// Apply translate to mock slice out.
|
|
56
|
+
highlightedTransform: (_, i) => {
|
|
57
|
+
return offsetTransform(elements[i], offset, coordinate);
|
|
58
|
+
},
|
|
59
|
+
}),
|
|
60
|
+
...rest,
|
|
61
|
+
};
|
|
62
|
+
const { setState, removeState, hasState } = useState(elementStyle, valueof);
|
|
36
63
|
|
|
64
|
+
let out; // Timer for delaying unhighlighted.
|
|
37
65
|
const pointerover = (event) => {
|
|
38
66
|
const { target: element } = event;
|
|
39
67
|
if (!elementSet.has(element)) return;
|
|
68
|
+
if (out) clearTimeout(out);
|
|
40
69
|
const k = groupKey(element);
|
|
41
70
|
const group = keyGroup.get(k);
|
|
42
71
|
const groupSet = new Set(group);
|
|
43
72
|
for (const e of elements) {
|
|
44
|
-
if (groupSet.has(e))
|
|
45
|
-
|
|
73
|
+
if (groupSet.has(e)) {
|
|
74
|
+
if (!hasState(e, 'highlighted')) setState(e, 'highlighted');
|
|
75
|
+
} else {
|
|
76
|
+
setState(e, 'unhighlighted');
|
|
77
|
+
removeLink(e);
|
|
78
|
+
}
|
|
79
|
+
if (e !== element) removeBackground(e);
|
|
80
|
+
}
|
|
81
|
+
appendBackground(element);
|
|
82
|
+
appendLink(group);
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
const delayUnhighlighted = () => {
|
|
86
|
+
if (out) clearTimeout(out);
|
|
87
|
+
out = setTimeout(() => {
|
|
88
|
+
unhighlighted();
|
|
89
|
+
out = null;
|
|
90
|
+
}, delay);
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
const unhighlighted = () => {
|
|
94
|
+
for (const e of elements) {
|
|
95
|
+
removeState(e, 'unhighlighted', 'highlighted');
|
|
96
|
+
removeBackground(e);
|
|
97
|
+
removeLink(e);
|
|
46
98
|
}
|
|
47
|
-
if (link) appendLink(group);
|
|
48
99
|
};
|
|
49
100
|
|
|
50
101
|
const pointerout = (event) => {
|
|
51
102
|
const { target: element } = event;
|
|
52
|
-
if (!
|
|
53
|
-
|
|
54
|
-
if (
|
|
103
|
+
if (background && !isBackground(element)) return;
|
|
104
|
+
if (!background && !elementSet.has(element)) return;
|
|
105
|
+
if (delay > 0) delayUnhighlighted();
|
|
106
|
+
else unhighlighted();
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
const pointerleave = () => {
|
|
110
|
+
unhighlighted();
|
|
55
111
|
};
|
|
56
112
|
|
|
57
113
|
root.addEventListener('pointerover', pointerover);
|
|
58
114
|
root.addEventListener('pointerout', pointerout);
|
|
115
|
+
root.addEventListener('pointerleave', pointerleave);
|
|
59
116
|
|
|
60
117
|
return () => {
|
|
61
118
|
root.removeEventListener('pointerover', pointerover);
|
|
62
119
|
root.removeEventListener('pointerout', pointerout);
|
|
63
|
-
|
|
120
|
+
root.removeEventListener('pointerleave', pointerleave);
|
|
121
|
+
for (const e of elements) {
|
|
122
|
+
removeBackground(e);
|
|
123
|
+
removeLink(e);
|
|
124
|
+
}
|
|
64
125
|
};
|
|
65
126
|
}
|
|
66
127
|
|
|
67
|
-
export function ElementHighlight(
|
|
128
|
+
export function ElementHighlight({ delay, ...rest }) {
|
|
68
129
|
return (context) => {
|
|
69
130
|
const { container, view } = context;
|
|
70
|
-
|
|
71
|
-
|
|
131
|
+
const { scale, coordinate } = view;
|
|
132
|
+
const plotArea = selectPlotArea(container);
|
|
133
|
+
return elementHighlight(plotArea, {
|
|
134
|
+
...applyDefaultsHighlightedStyle(rest),
|
|
72
135
|
elements: selectG2Elements,
|
|
73
136
|
datum: createDatumof(view),
|
|
137
|
+
scale,
|
|
138
|
+
coordinate,
|
|
139
|
+
delay,
|
|
74
140
|
});
|
|
75
141
|
};
|
|
76
142
|
}
|
|
@@ -3,21 +3,26 @@ import {
|
|
|
3
3
|
createDatumof,
|
|
4
4
|
selectG2Elements,
|
|
5
5
|
createColorKey,
|
|
6
|
+
selectPlotArea,
|
|
6
7
|
} from './utils';
|
|
7
8
|
import { elementHighlight } from './elementHighlight';
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
11
|
* @todo Bind abstract data or data index.
|
|
11
12
|
*/
|
|
12
|
-
export function ElementHighlightByColor(
|
|
13
|
+
export function ElementHighlightByColor({ delay, ...rest }) {
|
|
13
14
|
return (context) => {
|
|
14
15
|
const { container, view } = context;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
const { scale, coordinate } = view;
|
|
17
|
+
const plotArea = selectPlotArea(container);
|
|
18
|
+
return elementHighlight(plotArea, {
|
|
19
|
+
...applyDefaultsHighlightedStyle(rest),
|
|
18
20
|
elements: selectG2Elements,
|
|
19
21
|
datum: createDatumof(view),
|
|
20
22
|
groupKey: createColorKey(view),
|
|
23
|
+
scale,
|
|
24
|
+
coordinate,
|
|
25
|
+
delay,
|
|
21
26
|
});
|
|
22
27
|
};
|
|
23
28
|
}
|
|
@@ -3,6 +3,7 @@ import {
|
|
|
3
3
|
createDatumof,
|
|
4
4
|
selectG2Elements,
|
|
5
5
|
createXKey,
|
|
6
|
+
selectPlotArea,
|
|
6
7
|
} from './utils';
|
|
7
8
|
import { elementHighlight } from './elementHighlight';
|
|
8
9
|
|
|
@@ -10,16 +11,19 @@ import { elementHighlight } from './elementHighlight';
|
|
|
10
11
|
*
|
|
11
12
|
* @todo Bind abstract data or data index.
|
|
12
13
|
*/
|
|
13
|
-
export function ElementHighlightByX(
|
|
14
|
-
options = { selectedLineWidth: 1, selectedColor: 'black' },
|
|
15
|
-
) {
|
|
14
|
+
export function ElementHighlightByX({ delay, ...rest }) {
|
|
16
15
|
return (context) => {
|
|
17
16
|
const { container, view } = context;
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
const { scale, coordinate } = view;
|
|
18
|
+
const plotArea = selectPlotArea(container);
|
|
19
|
+
return elementHighlight(plotArea, {
|
|
20
|
+
...applyDefaultsHighlightedStyle(rest),
|
|
20
21
|
elements: selectG2Elements,
|
|
21
22
|
datum: createDatumof(view),
|
|
22
23
|
groupKey: createXKey(view),
|
|
24
|
+
scale,
|
|
25
|
+
coordinate,
|
|
26
|
+
delay,
|
|
23
27
|
});
|
|
24
28
|
};
|
|
25
29
|
}
|
|
@@ -8,6 +8,9 @@ import {
|
|
|
8
8
|
useState,
|
|
9
9
|
renderLink,
|
|
10
10
|
applyDefaultsHighlightedStyle,
|
|
11
|
+
renderBackground,
|
|
12
|
+
selectPlotArea,
|
|
13
|
+
offsetTransform,
|
|
11
14
|
} from './utils';
|
|
12
15
|
|
|
13
16
|
/**
|
|
@@ -21,6 +24,10 @@ export function elementSelect(
|
|
|
21
24
|
groupKey = (d) => d, // group elements by specified key
|
|
22
25
|
link = false, // draw link or not
|
|
23
26
|
single = false, // single select or not
|
|
27
|
+
coordinate,
|
|
28
|
+
background = false,
|
|
29
|
+
offset = 0,
|
|
30
|
+
scale,
|
|
24
31
|
...rest
|
|
25
32
|
}: Record<string, any>,
|
|
26
33
|
) {
|
|
@@ -28,15 +35,39 @@ export function elementSelect(
|
|
|
28
35
|
const elementSet = new Set(elements);
|
|
29
36
|
const keyGroup = group(elements, groupKey);
|
|
30
37
|
const valueof = createValueof(elements, datum);
|
|
31
|
-
const [appendLink, removeLink] = renderLink(
|
|
38
|
+
const [appendLink, removeLink] = renderLink({
|
|
39
|
+
link,
|
|
32
40
|
elements,
|
|
33
41
|
valueof,
|
|
42
|
+
coordinate,
|
|
34
43
|
...subObject(rest, 'link'),
|
|
35
44
|
});
|
|
36
|
-
|
|
45
|
+
|
|
46
|
+
const [appendBackground, removeBackground] = renderBackground({
|
|
47
|
+
background,
|
|
48
|
+
coordinate,
|
|
49
|
+
scale,
|
|
50
|
+
valueof,
|
|
51
|
+
...subObject(rest, 'background'),
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
const elementStyle = {
|
|
55
|
+
...(offset !== 0 && {
|
|
56
|
+
// Apply translate to mock slice out.
|
|
57
|
+
selectedTransform: (_, i) => {
|
|
58
|
+
return offsetTransform(elements[i], offset, coordinate);
|
|
59
|
+
},
|
|
60
|
+
}),
|
|
61
|
+
...rest,
|
|
62
|
+
};
|
|
63
|
+
const { setState, removeState, hasState } = useState(elementStyle, valueof);
|
|
64
|
+
|
|
37
65
|
const clear = () => {
|
|
38
|
-
for (const e of elements)
|
|
39
|
-
|
|
66
|
+
for (const e of elements) {
|
|
67
|
+
removeState(e, 'selected', 'unselected');
|
|
68
|
+
removeLink(e);
|
|
69
|
+
removeBackground(e);
|
|
70
|
+
}
|
|
40
71
|
return;
|
|
41
72
|
};
|
|
42
73
|
|
|
@@ -49,13 +80,14 @@ export function elementSelect(
|
|
|
49
80
|
const groupSet = new Set(group);
|
|
50
81
|
for (const e of elements) {
|
|
51
82
|
if (groupSet.has(e)) setState(e, 'selected');
|
|
52
|
-
else
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
appendLink(group);
|
|
83
|
+
else {
|
|
84
|
+
setState(e, 'unselected');
|
|
85
|
+
removeLink(e);
|
|
86
|
+
}
|
|
87
|
+
if (e !== element) removeBackground(e);
|
|
58
88
|
}
|
|
89
|
+
appendLink(group);
|
|
90
|
+
appendBackground(element);
|
|
59
91
|
}
|
|
60
92
|
};
|
|
61
93
|
|
|
@@ -70,7 +102,8 @@ export function elementSelect(
|
|
|
70
102
|
else if (!hasState(e, 'selected')) setState(e, 'unselected');
|
|
71
103
|
}
|
|
72
104
|
// Append link for each group only once.
|
|
73
|
-
if (!hasSelectedGroup && link) appendLink(group
|
|
105
|
+
if (!hasSelectedGroup && link) appendLink(group);
|
|
106
|
+
appendBackground(element);
|
|
74
107
|
} else {
|
|
75
108
|
// If there is no selected elements after resetting this group,
|
|
76
109
|
// clear the states.
|
|
@@ -80,8 +113,11 @@ export function elementSelect(
|
|
|
80
113
|
if (!hasSelected) return clear();
|
|
81
114
|
// If there are still some selected elements after resetting this group,
|
|
82
115
|
// only remove the link.
|
|
83
|
-
for (const e of group)
|
|
84
|
-
|
|
116
|
+
for (const e of group) {
|
|
117
|
+
setState(e, 'unselected');
|
|
118
|
+
removeLink(e);
|
|
119
|
+
removeBackground(e);
|
|
120
|
+
}
|
|
85
121
|
}
|
|
86
122
|
};
|
|
87
123
|
|
|
@@ -98,17 +134,24 @@ export function elementSelect(
|
|
|
98
134
|
|
|
99
135
|
return () => {
|
|
100
136
|
root.removeEventListener('click', click);
|
|
101
|
-
|
|
137
|
+
for (const e of elements) {
|
|
138
|
+
removeLink(e);
|
|
139
|
+
}
|
|
102
140
|
};
|
|
103
141
|
}
|
|
104
142
|
|
|
105
143
|
export function ElementSelect(options) {
|
|
106
144
|
return (context) => {
|
|
107
145
|
const { container, view } = context;
|
|
108
|
-
|
|
146
|
+
const { coordinate, scale } = view;
|
|
147
|
+
const plotArea = selectPlotArea(container);
|
|
148
|
+
return elementSelect(plotArea, {
|
|
149
|
+
...options,
|
|
109
150
|
...applyDefaultsHighlightedStyle(options),
|
|
110
151
|
elements: selectG2Elements,
|
|
111
152
|
datum: createDatumof(view),
|
|
153
|
+
coordinate,
|
|
154
|
+
scale,
|
|
112
155
|
});
|
|
113
156
|
};
|
|
114
157
|
}
|
|
@@ -3,13 +3,16 @@ import {
|
|
|
3
3
|
selectG2Elements,
|
|
4
4
|
applyDefaultsHighlightedStyle,
|
|
5
5
|
createColorKey,
|
|
6
|
+
selectPlotArea,
|
|
6
7
|
} from './utils';
|
|
7
8
|
import { elementSelect } from './elementSelect';
|
|
8
9
|
|
|
9
10
|
export function ElementSelectByColor(options) {
|
|
10
11
|
return (context) => {
|
|
11
12
|
const { container, view } = context;
|
|
12
|
-
|
|
13
|
+
const plot = selectPlotArea(container);
|
|
14
|
+
return elementSelect(plot, {
|
|
15
|
+
...options,
|
|
13
16
|
...applyDefaultsHighlightedStyle(options),
|
|
14
17
|
elements: selectG2Elements,
|
|
15
18
|
datum: createDatumof(view),
|
|
@@ -3,13 +3,16 @@ import {
|
|
|
3
3
|
selectG2Elements,
|
|
4
4
|
applyDefaultsHighlightedStyle,
|
|
5
5
|
createXKey,
|
|
6
|
+
selectPlotArea,
|
|
6
7
|
} from './utils';
|
|
7
8
|
import { elementSelect } from './elementSelect';
|
|
8
9
|
|
|
9
10
|
export function ElementSelectByX(options) {
|
|
10
11
|
return (context) => {
|
|
11
12
|
const { container, view } = context;
|
|
12
|
-
|
|
13
|
+
const plot = selectPlotArea(container);
|
|
14
|
+
return elementSelect(plot, {
|
|
15
|
+
...options,
|
|
13
16
|
...applyDefaultsHighlightedStyle(options),
|
|
14
17
|
elements: selectG2Elements,
|
|
15
18
|
datum: createDatumof(view),
|
|
@@ -11,27 +11,48 @@ export const LEGEND_MAKER_CLASS_NAME = 'legend-category-item-marker';
|
|
|
11
11
|
|
|
12
12
|
export const LEGEND_LABEL_CLASS_NAME = 'legend-category-item-label';
|
|
13
13
|
|
|
14
|
-
function markerOf(item) {
|
|
14
|
+
export function markerOf(item) {
|
|
15
15
|
return item.getElementsByClassName(LEGEND_MAKER_CLASS_NAME)[0];
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
function labelOf(item) {
|
|
18
|
+
export function labelOf(item) {
|
|
19
19
|
return item.getElementsByClassName(LEGEND_LABEL_CLASS_NAME)[0];
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
function
|
|
22
|
+
export function itemsOf(root) {
|
|
23
23
|
return root.getElementsByClassName(LEGEND_ITEMS_CLASS_NAME);
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
+
export function legendsOf(root) {
|
|
27
|
+
return root.getElementsByClassName(CATEGORY_LEGEND_CLASS_NAME);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function dataOf(root) {
|
|
31
|
+
// legend -> layout -> container
|
|
32
|
+
let parent = root.parentNode;
|
|
33
|
+
while (parent && !parent.__data__) {
|
|
34
|
+
parent = parent.parentNode;
|
|
35
|
+
}
|
|
36
|
+
return parent.__data__;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function attributesOf(root) {
|
|
40
|
+
let child = root;
|
|
41
|
+
while (child && !child.attr('class').startsWith('legend')) {
|
|
42
|
+
child = child.children[0];
|
|
43
|
+
}
|
|
44
|
+
return child.attributes;
|
|
45
|
+
}
|
|
46
|
+
|
|
26
47
|
function builtInAccessors(selectedLegend) {
|
|
27
48
|
// Get the value and scale type from legend.
|
|
28
|
-
const { data } = selectedLegend
|
|
29
|
-
|
|
30
|
-
const { name: channel } =
|
|
49
|
+
const { data } = attributesOf(selectedLegend);
|
|
50
|
+
// In theory, scales' channels are the same
|
|
51
|
+
const { name: channel } = dataOf(selectedLegend).scales[0];
|
|
31
52
|
return [
|
|
32
53
|
channel,
|
|
33
54
|
{
|
|
34
|
-
legends:
|
|
55
|
+
legends: itemsOf,
|
|
35
56
|
marker: markerOf,
|
|
36
57
|
label: labelOf,
|
|
37
58
|
datum: (d) => {
|
|
@@ -66,6 +87,7 @@ function legendFilter(
|
|
|
66
87
|
? {
|
|
67
88
|
labelUnselectedFill: '#aaa',
|
|
68
89
|
markerUnselectedFill: '#aaa',
|
|
90
|
+
markerUnselectedStroke: '#aaa',
|
|
69
91
|
}
|
|
70
92
|
: options;
|
|
71
93
|
const markerStyle = subObject(style, 'marker');
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { group } from 'd3-array';
|
|
2
|
+
import { subObject } from '../../utils/helper';
|
|
3
|
+
import { selectG2Elements, useState } from './utils';
|
|
4
|
+
import { markerOf, labelOf, itemsOf, legendsOf, dataOf } from './legendFilter';
|
|
5
|
+
|
|
6
|
+
export function LegendHighlight({ channel, ...rest }) {
|
|
7
|
+
return (context) => {
|
|
8
|
+
const { container, view } = context;
|
|
9
|
+
const legends = legendsOf(container);
|
|
10
|
+
const elements = selectG2Elements(container);
|
|
11
|
+
const channelOf = (legend) => {
|
|
12
|
+
return dataOf(legend).scales[0].name;
|
|
13
|
+
};
|
|
14
|
+
const scaleOf = (channel) => {
|
|
15
|
+
const {
|
|
16
|
+
scale: { [channel]: scale },
|
|
17
|
+
} = view;
|
|
18
|
+
return scale;
|
|
19
|
+
};
|
|
20
|
+
for (const legend of legends) {
|
|
21
|
+
const datumOf = (item) => {
|
|
22
|
+
const { data } = legend.attributes;
|
|
23
|
+
const { __data__: datum } = item;
|
|
24
|
+
const { index } = datum;
|
|
25
|
+
return data[index].label;
|
|
26
|
+
};
|
|
27
|
+
const channel = channelOf(legend);
|
|
28
|
+
const items = itemsOf(legend);
|
|
29
|
+
const scale = scaleOf(channel);
|
|
30
|
+
const elementGroup = group<any, any>(elements, (d) =>
|
|
31
|
+
scale.invert(d.__data__[channel]),
|
|
32
|
+
);
|
|
33
|
+
const { setState, removeState } = useState(rest);
|
|
34
|
+
const markerStyle = subObject(rest, 'marker');
|
|
35
|
+
const labelStyle = subObject(rest, 'label');
|
|
36
|
+
const { setState: setM, removeState: removeM } = useState(markerStyle);
|
|
37
|
+
const { setState: setL, removeState: removeL } = useState(labelStyle);
|
|
38
|
+
const updateLegendState = (highlight) => {
|
|
39
|
+
for (const item of items) {
|
|
40
|
+
const marker = markerOf(item);
|
|
41
|
+
const label = labelOf(item);
|
|
42
|
+
if (item === highlight || highlight === null) {
|
|
43
|
+
removeM(marker, 'unhighlighted');
|
|
44
|
+
removeL(label, 'unhighlighted');
|
|
45
|
+
} else {
|
|
46
|
+
setM(marker, 'unhighlighted');
|
|
47
|
+
setL(label, 'unhighlighted');
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const itemPointerover = new Map();
|
|
53
|
+
|
|
54
|
+
// Add listener for the legend items.
|
|
55
|
+
for (const item of items) {
|
|
56
|
+
const pointerover = () => {
|
|
57
|
+
const value = datumOf(item);
|
|
58
|
+
const elementSet = new Set(elementGroup.get(value));
|
|
59
|
+
for (const e of elements) {
|
|
60
|
+
if (elementSet.has(e)) setState(e, 'highlighted');
|
|
61
|
+
else setState(e, 'unhighlighted');
|
|
62
|
+
}
|
|
63
|
+
updateLegendState(item);
|
|
64
|
+
};
|
|
65
|
+
item.addEventListener('pointerover', pointerover);
|
|
66
|
+
itemPointerover.set(item, pointerover);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// Add listener for the legend group.
|
|
70
|
+
const pointerleave = () => {
|
|
71
|
+
for (const e of elements) {
|
|
72
|
+
removeState(e, 'unhighlighted', 'highlighted');
|
|
73
|
+
}
|
|
74
|
+
updateLegendState(null);
|
|
75
|
+
};
|
|
76
|
+
legend.addEventListener('pointerleave', pointerleave);
|
|
77
|
+
|
|
78
|
+
return () => {
|
|
79
|
+
legend.removeEventListener(pointerleave);
|
|
80
|
+
for (const [item, pointerover] of itemPointerover) {
|
|
81
|
+
item.removeEventListener(pointerover);
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
}
|