@antv/g2 5.0.0-beta.3 → 5.0.0-beta.5
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 +5 -2
- package/dist/g2.min.js +5 -2
- package/esm/api/mark/mark.js +1 -2
- package/esm/api/mark/mark.js.map +1 -1
- package/esm/api/mark/types.d.ts +1 -2
- package/esm/component/axis.js +46 -24
- package/esm/component/axis.js.map +1 -1
- package/esm/component/index.d.ts +4 -0
- package/esm/component/index.js +2 -0
- package/esm/component/index.js.map +1 -1
- package/esm/component/legendCategory.js +1 -0
- package/esm/component/legendCategory.js.map +1 -1
- package/esm/component/slider.d.ts +9 -0
- package/esm/component/slider.js +57 -0
- package/esm/component/slider.js.map +1 -0
- package/esm/component/sliderX.d.ts +7 -0
- package/esm/component/sliderX.js +9 -0
- package/esm/component/sliderX.js.map +1 -0
- package/esm/component/sliderY.d.ts +7 -0
- package/esm/component/sliderY.js +9 -0
- package/esm/component/sliderY.js.map +1 -0
- package/esm/composition/facetRect.js +4 -4
- package/esm/composition/facetRect.js.map +1 -1
- package/esm/composition/mark.js +3 -1
- package/esm/composition/mark.js.map +1 -1
- package/esm/composition/repeatMatrix.js +2 -2
- package/esm/composition/repeatMatrix.js.map +1 -1
- package/esm/data/filter.d.ts +3 -3
- package/esm/data/filter.js.map +1 -1
- package/esm/data/index.d.ts +3 -1
- package/esm/data/index.js +1 -0
- package/esm/data/index.js.map +1 -1
- package/esm/data/sort.d.ts +8 -0
- package/esm/data/sort.js +12 -0
- package/esm/data/sort.js.map +1 -0
- package/esm/interaction/builtin/brushHighlight.d.ts +1 -1
- package/esm/interaction/builtin/tooltip.d.ts +6 -4
- package/esm/interaction/index.d.ts +5 -0
- package/esm/interaction/index.js +5 -0
- package/esm/interaction/index.js.map +1 -1
- package/esm/interaction/native/brushHighlight.d.ts +15 -0
- package/esm/interaction/native/brushHighlight.js +283 -0
- package/esm/interaction/native/brushHighlight.js.map +1 -0
- package/esm/interaction/native/brushXHighlight.d.ts +1 -0
- package/esm/interaction/native/brushXHighlight.js +8 -0
- package/esm/interaction/native/brushXHighlight.js.map +1 -0
- package/esm/interaction/native/brushYHighlight.d.ts +1 -0
- package/esm/interaction/native/brushYHighlight.js +8 -0
- package/esm/interaction/native/brushYHighlight.js.map +1 -0
- package/esm/interaction/native/legendFilter.d.ts +8 -0
- package/esm/interaction/native/legendFilter.js +180 -0
- package/esm/interaction/native/legendFilter.js.map +1 -0
- package/esm/interaction/native/tooltip.d.ts +2 -2
- package/esm/interaction/native/tooltip.js +134 -44
- package/esm/interaction/native/tooltip.js.map +1 -1
- package/esm/interaction/native/utils.d.ts +5 -1
- package/esm/interaction/native/utils.js +25 -2
- package/esm/interaction/native/utils.js.map +1 -1
- package/esm/label-transform/contrastReverse.d.ts +9 -0
- package/esm/label-transform/contrastReverse.js +48 -0
- package/esm/label-transform/contrastReverse.js.map +1 -0
- package/esm/label-transform/index.d.ts +8 -8
- package/esm/label-transform/index.js +4 -4
- package/esm/label-transform/index.js.map +1 -1
- package/esm/label-transform/overflowHide.d.ts +7 -0
- package/esm/label-transform/overflowHide.js +18 -0
- package/esm/label-transform/overflowHide.js.map +1 -0
- package/esm/label-transform/overlapDodgeY.d.ts +7 -0
- package/esm/label-transform/{dodgeY.js → overlapDodgeY.js} +4 -4
- package/esm/label-transform/overlapDodgeY.js.map +1 -0
- package/esm/label-transform/overlapHide.d.ts +7 -0
- package/esm/label-transform/overlapHide.js +24 -0
- package/esm/label-transform/overlapHide.js.map +1 -0
- package/esm/mark/area.js +1 -1
- package/esm/mark/area.js.map +1 -1
- package/esm/mark/line.js +1 -1
- package/esm/mark/line.js.map +1 -1
- package/esm/runtime/component.js +29 -1
- package/esm/runtime/component.js.map +1 -1
- package/esm/runtime/plot.js +38 -13
- package/esm/runtime/plot.js.map +1 -1
- package/esm/runtime/scale.js +17 -5
- package/esm/runtime/scale.js.map +1 -1
- package/esm/runtime/transform.js +10 -4
- package/esm/runtime/transform.js.map +1 -1
- package/esm/runtime/types/common.d.ts +1 -0
- package/esm/runtime/types/mark.d.ts +1 -1
- package/esm/runtime/types/options.d.ts +2 -0
- package/esm/runtime/types/theme.d.ts +5 -0
- package/esm/shape/label/label.js +3 -3
- package/esm/shape/label/label.js.map +1 -1
- package/esm/shape/label/position/area.d.ts +13 -0
- package/esm/shape/label/position/area.js +28 -0
- package/esm/shape/label/position/area.js.map +1 -0
- package/esm/shape/label/position/bottom.d.ts +1 -0
- package/esm/shape/label/position/bottom.js +2 -0
- package/esm/shape/label/position/bottom.js.map +1 -0
- package/esm/shape/label/position/bottomLeft.d.ts +1 -0
- package/esm/shape/label/position/bottomLeft.js +2 -0
- package/esm/shape/label/position/bottomLeft.js.map +1 -0
- package/esm/shape/label/position/bottomRight.d.ts +1 -0
- package/esm/shape/label/position/bottomRight.js +2 -0
- package/esm/shape/label/position/bottomRight.js.map +1 -0
- package/esm/shape/label/position/default.d.ts +20 -0
- package/esm/shape/label/{position.js → position/default.js} +9 -45
- package/esm/shape/label/position/default.js.map +1 -0
- package/esm/shape/label/position/index.d.ts +13 -0
- package/esm/shape/label/position/index.js +14 -0
- package/esm/shape/label/position/index.js.map +1 -0
- package/esm/shape/label/position/inside.d.ts +1 -0
- package/esm/shape/label/position/inside.js +2 -0
- package/esm/shape/label/position/inside.js.map +1 -0
- package/esm/shape/label/position/left.d.ts +1 -0
- package/esm/shape/label/position/left.js +2 -0
- package/esm/shape/label/position/left.js.map +1 -0
- package/esm/shape/label/position/outside.d.ts +1 -0
- package/esm/shape/label/position/outside.js +2 -0
- package/esm/shape/label/position/outside.js.map +1 -0
- package/esm/shape/label/position/right.d.ts +1 -0
- package/esm/shape/label/position/right.js +2 -0
- package/esm/shape/label/position/right.js.map +1 -0
- package/esm/shape/label/position/spider.d.ts +7 -0
- package/esm/shape/label/position/spider.js +40 -0
- package/esm/shape/label/position/spider.js.map +1 -0
- package/esm/shape/label/position/surround.d.ts +7 -0
- package/esm/shape/label/position/surround.js +37 -0
- package/esm/shape/label/position/surround.js.map +1 -0
- package/esm/shape/label/position/top.d.ts +1 -0
- package/esm/shape/label/position/top.js +2 -0
- package/esm/shape/label/position/top.js.map +1 -0
- package/esm/shape/label/position/topLeft.d.ts +1 -0
- package/esm/shape/label/position/topLeft.js +2 -0
- package/esm/shape/label/position/topLeft.js.map +1 -0
- package/esm/shape/label/position/topRight.d.ts +1 -0
- package/esm/shape/label/position/topRight.js +2 -0
- package/esm/shape/label/position/topRight.js.map +1 -0
- package/esm/spec/composition.d.ts +2 -0
- package/esm/spec/data.d.ts +10 -3
- package/esm/spec/geometry.d.ts +2 -1
- package/esm/spec/interaction.d.ts +28 -5
- package/esm/spec/labelTransform.d.ts +24 -11
- package/esm/spec/theme.d.ts +5 -2
- package/esm/spec/transform.d.ts +7 -2
- package/esm/stdlib/index.js +9 -10
- package/esm/stdlib/index.js.map +1 -1
- package/esm/theme/academy.d.ts +3 -0
- package/esm/theme/academy.js +402 -0
- package/esm/theme/academy.js.map +1 -0
- package/esm/theme/dark.js +80 -29
- package/esm/theme/dark.js.map +1 -1
- package/esm/theme/index.d.ts +1 -0
- package/esm/theme/index.js +1 -0
- package/esm/theme/index.js.map +1 -1
- package/esm/theme/light.js +71 -19
- package/esm/theme/light.js.map +1 -1
- package/esm/transform/filter.d.ts +7 -0
- package/esm/transform/filter.js +42 -0
- package/esm/transform/filter.js.map +1 -0
- package/esm/transform/index.d.ts +2 -0
- package/esm/transform/index.js +1 -0
- package/esm/transform/index.js.map +1 -1
- package/esm/transform/maybeTooltip.js +3 -1
- package/esm/transform/maybeTooltip.js.map +1 -1
- package/esm/utils/bounds.d.ts +26 -0
- package/esm/utils/bounds.js +41 -0
- package/esm/utils/bounds.js.map +1 -0
- package/esm/utils/color.d.ts +6 -0
- package/esm/utils/color.js +7 -0
- package/esm/utils/color.js.map +1 -0
- package/esm/utils/coordinate.d.ts +1 -0
- package/esm/utils/coordinate.js +12 -0
- package/esm/utils/coordinate.js.map +1 -1
- package/esm/utils/helper.d.ts +1 -0
- package/esm/utils/helper.js +3 -0
- package/esm/utils/helper.js.map +1 -1
- package/esm/utils/selection.d.ts +1 -0
- package/esm/utils/selection.js.map +1 -1
- package/esm/utils/size.js +1 -1
- package/esm/utils/size.js.map +1 -1
- package/lib/api/mark/mark.js +1 -2
- package/lib/api/mark/mark.js.map +1 -1
- package/lib/api/mark/types.d.ts +1 -2
- package/lib/component/axis.js +46 -24
- package/lib/component/axis.js.map +1 -1
- package/lib/component/index.d.ts +4 -0
- package/lib/component/index.js +5 -1
- package/lib/component/index.js.map +1 -1
- package/lib/component/legendCategory.js +1 -0
- package/lib/component/legendCategory.js.map +1 -1
- package/lib/component/slider.d.ts +9 -0
- package/lib/component/slider.js +61 -0
- package/lib/component/slider.js.map +1 -0
- package/lib/component/sliderX.d.ts +7 -0
- package/lib/component/sliderX.js +13 -0
- package/lib/component/sliderX.js.map +1 -0
- package/lib/component/sliderY.d.ts +7 -0
- package/lib/component/sliderY.js +13 -0
- package/lib/component/sliderY.js.map +1 -0
- package/lib/composition/facetRect.js +4 -4
- package/lib/composition/facetRect.js.map +1 -1
- package/lib/composition/mark.js +3 -1
- package/lib/composition/mark.js.map +1 -1
- package/lib/composition/repeatMatrix.js +2 -2
- package/lib/composition/repeatMatrix.js.map +1 -1
- package/lib/data/filter.d.ts +3 -3
- package/lib/data/filter.js.map +1 -1
- package/lib/data/index.d.ts +3 -1
- package/lib/data/index.js +3 -1
- package/lib/data/index.js.map +1 -1
- package/lib/data/sort.d.ts +8 -0
- package/lib/data/sort.js +17 -0
- package/lib/data/sort.js.map +1 -0
- package/lib/interaction/builtin/brushHighlight.d.ts +1 -1
- package/lib/interaction/builtin/tooltip.d.ts +6 -4
- package/lib/interaction/index.d.ts +5 -0
- package/lib/interaction/index.js +11 -1
- package/lib/interaction/index.js.map +1 -1
- package/lib/interaction/native/brushHighlight.d.ts +15 -0
- package/lib/interaction/native/brushHighlight.js +289 -0
- package/lib/interaction/native/brushHighlight.js.map +1 -0
- package/lib/interaction/native/brushXHighlight.d.ts +1 -0
- package/lib/interaction/native/brushXHighlight.js +12 -0
- package/lib/interaction/native/brushXHighlight.js.map +1 -0
- package/lib/interaction/native/brushYHighlight.d.ts +1 -0
- package/lib/interaction/native/brushYHighlight.js +12 -0
- package/lib/interaction/native/brushYHighlight.js.map +1 -0
- package/lib/interaction/native/legendFilter.d.ts +8 -0
- package/lib/interaction/native/legendFilter.js +184 -0
- package/lib/interaction/native/legendFilter.js.map +1 -0
- package/lib/interaction/native/tooltip.d.ts +2 -2
- package/lib/interaction/native/tooltip.js +131 -41
- package/lib/interaction/native/tooltip.js.map +1 -1
- package/lib/interaction/native/utils.d.ts +5 -1
- package/lib/interaction/native/utils.js +30 -3
- package/lib/interaction/native/utils.js.map +1 -1
- package/lib/label-transform/contrastReverse.d.ts +9 -0
- package/lib/label-transform/contrastReverse.js +52 -0
- package/lib/label-transform/contrastReverse.js.map +1 -0
- package/lib/label-transform/index.d.ts +8 -8
- package/lib/label-transform/index.js +9 -9
- package/lib/label-transform/index.js.map +1 -1
- package/lib/label-transform/overflowHide.d.ts +7 -0
- package/lib/label-transform/overflowHide.js +22 -0
- package/lib/label-transform/overflowHide.js.map +1 -0
- package/lib/label-transform/overlapDodgeY.d.ts +7 -0
- package/lib/label-transform/{dodgeY.js → overlapDodgeY.js} +6 -6
- package/lib/label-transform/overlapDodgeY.js.map +1 -0
- package/lib/label-transform/overlapHide.d.ts +7 -0
- package/lib/label-transform/overlapHide.js +28 -0
- package/lib/label-transform/overlapHide.js.map +1 -0
- package/lib/mark/area.js +1 -1
- package/lib/mark/area.js.map +1 -1
- package/lib/mark/line.js +1 -1
- package/lib/mark/line.js.map +1 -1
- package/lib/runtime/component.js +29 -1
- package/lib/runtime/component.js.map +1 -1
- package/lib/runtime/plot.js +38 -13
- package/lib/runtime/plot.js.map +1 -1
- package/lib/runtime/scale.js +16 -4
- package/lib/runtime/scale.js.map +1 -1
- package/lib/runtime/transform.js +10 -4
- package/lib/runtime/transform.js.map +1 -1
- package/lib/runtime/types/common.d.ts +1 -0
- package/lib/runtime/types/mark.d.ts +1 -1
- package/lib/runtime/types/options.d.ts +2 -0
- package/lib/runtime/types/theme.d.ts +5 -0
- package/lib/shape/label/label.js +3 -3
- package/lib/shape/label/label.js.map +1 -1
- package/lib/shape/label/position/area.d.ts +13 -0
- package/lib/shape/label/position/area.js +32 -0
- package/lib/shape/label/position/area.js.map +1 -0
- package/lib/shape/label/position/bottom.d.ts +1 -0
- package/lib/shape/label/position/bottom.js +6 -0
- package/lib/shape/label/position/bottom.js.map +1 -0
- package/lib/shape/label/position/bottomLeft.d.ts +1 -0
- package/lib/shape/label/position/bottomLeft.js +6 -0
- package/lib/shape/label/position/bottomLeft.js.map +1 -0
- package/lib/shape/label/position/bottomRight.d.ts +1 -0
- package/lib/shape/label/position/bottomRight.js +6 -0
- package/lib/shape/label/position/bottomRight.js.map +1 -0
- package/lib/shape/label/position/default.d.ts +20 -0
- package/lib/shape/label/{position.js → position/default.js} +10 -43
- package/lib/shape/label/position/default.js.map +1 -0
- package/lib/shape/label/position/index.d.ts +13 -0
- package/lib/shape/label/position/index.js +30 -0
- package/lib/shape/label/position/index.js.map +1 -0
- package/lib/shape/label/position/inside.d.ts +1 -0
- package/lib/shape/label/position/inside.js +6 -0
- package/lib/shape/label/position/inside.js.map +1 -0
- package/lib/shape/label/position/left.d.ts +1 -0
- package/lib/shape/label/position/left.js +6 -0
- package/lib/shape/label/position/left.js.map +1 -0
- package/lib/shape/label/position/outside.d.ts +1 -0
- package/lib/shape/label/position/outside.js +6 -0
- package/lib/shape/label/position/outside.js.map +1 -0
- package/lib/shape/label/position/right.d.ts +1 -0
- package/lib/shape/label/position/right.js +6 -0
- package/lib/shape/label/position/right.js.map +1 -0
- package/lib/shape/label/position/spider.d.ts +7 -0
- package/lib/shape/label/position/spider.js +44 -0
- package/lib/shape/label/position/spider.js.map +1 -0
- package/lib/shape/label/position/surround.d.ts +7 -0
- package/lib/shape/label/position/surround.js +41 -0
- package/lib/shape/label/position/surround.js.map +1 -0
- package/lib/shape/label/position/top.d.ts +1 -0
- package/lib/shape/label/position/top.js +6 -0
- package/lib/shape/label/position/top.js.map +1 -0
- package/lib/shape/label/position/topLeft.d.ts +1 -0
- package/lib/shape/label/position/topLeft.js +6 -0
- package/lib/shape/label/position/topLeft.js.map +1 -0
- package/lib/shape/label/position/topRight.d.ts +1 -0
- package/lib/shape/label/position/topRight.js +6 -0
- package/lib/shape/label/position/topRight.js.map +1 -0
- package/lib/spec/composition.d.ts +2 -0
- package/lib/spec/data.d.ts +10 -3
- package/lib/spec/geometry.d.ts +2 -1
- package/lib/spec/interaction.d.ts +28 -5
- package/lib/spec/labelTransform.d.ts +24 -11
- package/lib/spec/theme.d.ts +5 -2
- package/lib/spec/transform.d.ts +7 -2
- package/lib/stdlib/index.js +3 -4
- package/lib/stdlib/index.js.map +1 -1
- package/lib/theme/academy.d.ts +3 -0
- package/lib/theme/academy.js +406 -0
- package/lib/theme/academy.js.map +1 -0
- package/lib/theme/dark.js +80 -29
- package/lib/theme/dark.js.map +1 -1
- package/lib/theme/index.d.ts +1 -0
- package/lib/theme/index.js +3 -1
- package/lib/theme/index.js.map +1 -1
- package/lib/theme/light.js +71 -19
- package/lib/theme/light.js.map +1 -1
- package/lib/transform/filter.d.ts +7 -0
- package/lib/transform/filter.js +46 -0
- package/lib/transform/filter.js.map +1 -0
- package/lib/transform/index.d.ts +2 -0
- package/lib/transform/index.js +3 -1
- package/lib/transform/index.js.map +1 -1
- package/lib/transform/maybeTooltip.js +3 -1
- package/lib/transform/maybeTooltip.js.map +1 -1
- package/lib/utils/bounds.d.ts +26 -0
- package/lib/utils/bounds.js +48 -0
- package/lib/utils/bounds.js.map +1 -0
- package/lib/utils/color.d.ts +6 -0
- package/lib/utils/color.js +11 -0
- package/lib/utils/color.js.map +1 -0
- package/lib/utils/coordinate.d.ts +1 -0
- package/lib/utils/coordinate.js +14 -1
- package/lib/utils/coordinate.js.map +1 -1
- package/lib/utils/helper.d.ts +1 -0
- package/lib/utils/helper.js +5 -1
- package/lib/utils/helper.js.map +1 -1
- package/lib/utils/selection.d.ts +1 -0
- package/lib/utils/selection.js.map +1 -1
- package/lib/utils/size.js +1 -1
- package/lib/utils/size.js.map +1 -1
- package/package.json +4 -3
- package/src/api/mark/mark.ts +1 -2
- package/src/api/mark/types.ts +1 -2
- package/src/component/axis.ts +56 -96
- package/src/component/index.ts +4 -0
- package/src/component/legendCategory.ts +1 -0
- package/src/component/slider.ts +61 -0
- package/src/component/sliderX.ts +16 -0
- package/src/component/sliderY.ts +16 -0
- package/src/composition/facetRect.ts +4 -2
- package/src/composition/mark.ts +4 -0
- package/src/composition/repeatMatrix.ts +8 -1
- package/src/data/filter.ts +3 -3
- package/src/data/index.ts +3 -1
- package/src/data/sort.ts +18 -0
- package/src/interaction/index.ts +6 -0
- package/src/interaction/native/brushHighlight.ts +346 -0
- package/src/interaction/native/brushXHighlight.ts +11 -0
- package/src/interaction/native/brushYHighlight.ts +11 -0
- package/src/interaction/native/legendFilter.ts +195 -0
- package/src/interaction/native/tooltip.ts +173 -45
- package/src/interaction/native/utils.ts +33 -1
- package/src/label-transform/contrastReverse.ts +56 -0
- package/src/label-transform/index.ts +8 -8
- package/src/label-transform/overflowHide.ts +23 -0
- package/src/label-transform/{dodgeY.ts → overlapDodgeY.ts} +6 -6
- package/src/label-transform/overlapHide.ts +32 -0
- package/src/mark/area.ts +1 -1
- package/src/mark/line.ts +1 -1
- package/src/runtime/component.ts +49 -2
- package/src/runtime/plot.ts +46 -11
- package/src/runtime/scale.ts +15 -7
- package/src/runtime/transform.ts +13 -4
- package/src/runtime/types/common.ts +1 -0
- package/src/runtime/types/mark.ts +1 -1
- package/src/runtime/types/options.ts +2 -0
- package/src/runtime/types/theme.ts +5 -0
- package/src/shape/label/label.ts +4 -3
- package/src/shape/label/position/area.ts +39 -0
- package/src/shape/label/position/bottom.ts +1 -0
- package/src/shape/label/position/bottomLeft.ts +1 -0
- package/src/shape/label/position/bottomRight.ts +1 -0
- package/src/shape/label/{position.ts → position/default.ts} +12 -56
- package/src/shape/label/position/index.ts +13 -0
- package/src/shape/label/position/inside.ts +1 -0
- package/src/shape/label/position/left.ts +1 -0
- package/src/shape/label/position/outside.ts +1 -0
- package/src/shape/label/position/right.ts +1 -0
- package/src/shape/label/position/spider.ts +46 -0
- package/src/shape/label/position/surround.ts +42 -0
- package/src/shape/label/position/top.ts +1 -0
- package/src/shape/label/position/topLeft.ts +1 -0
- package/src/shape/label/position/topRight.ts +1 -0
- package/src/spec/composition.ts +2 -0
- package/src/spec/data.ts +12 -2
- package/src/spec/geometry.ts +3 -1
- package/src/spec/interaction.ts +38 -4
- package/src/spec/labelTransform.ts +29 -11
- package/src/spec/theme.ts +6 -2
- package/src/spec/transform.ts +9 -1
- package/src/stdlib/index.ts +31 -9
- package/src/theme/academy.ts +408 -0
- package/src/theme/dark.ts +81 -29
- package/src/theme/index.ts +1 -0
- package/src/theme/light.ts +71 -19
- package/src/transform/filter.ts +48 -0
- package/src/transform/index.ts +2 -0
- package/src/transform/maybeTooltip.ts +3 -1
- package/src/utils/bounds.ts +52 -0
- package/src/utils/color.ts +12 -0
- package/src/utils/coordinate.ts +12 -0
- package/src/utils/helper.ts +4 -0
- package/src/utils/selection.ts +2 -0
- package/src/utils/size.ts +1 -1
- package/esm/label-transform/dodgeY.d.ts +0 -7
- package/esm/label-transform/dodgeY.js.map +0 -1
- package/esm/label-transform/hideOverlap.d.ts +0 -4
- package/esm/label-transform/hideOverlap.js +0 -48
- package/esm/label-transform/hideOverlap.js.map +0 -1
- package/esm/label-transform/spider.d.ts +0 -7
- package/esm/label-transform/spider.js +0 -30
- package/esm/label-transform/spider.js.map +0 -1
- package/esm/label-transform/surround.d.ts +0 -7
- package/esm/label-transform/surround.js +0 -30
- package/esm/label-transform/surround.js.map +0 -1
- package/esm/shape/label/position.d.ts +0 -25
- package/esm/shape/label/position.js.map +0 -1
- package/lib/label-transform/dodgeY.d.ts +0 -7
- package/lib/label-transform/dodgeY.js.map +0 -1
- package/lib/label-transform/hideOverlap.d.ts +0 -4
- package/lib/label-transform/hideOverlap.js +0 -52
- package/lib/label-transform/hideOverlap.js.map +0 -1
- package/lib/label-transform/spider.d.ts +0 -7
- package/lib/label-transform/spider.js +0 -34
- package/lib/label-transform/spider.js.map +0 -1
- package/lib/label-transform/surround.d.ts +0 -7
- package/lib/label-transform/surround.js +0 -34
- package/lib/label-transform/surround.js.map +0 -1
- package/lib/shape/label/position.d.ts +0 -25
- package/lib/shape/label/position.js.map +0 -1
- package/src/label-transform/hideOverlap.ts +0 -62
- package/src/label-transform/spider.ts +0 -37
- package/src/label-transform/surround.ts +0 -37
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import { DisplayObject, IElement, Line } from '@antv/g';
|
|
2
|
-
import { sort,
|
|
2
|
+
import { sort, group, mean, range, bisector } from 'd3-array';
|
|
3
3
|
import { lowerFirst, throttle } from '@antv/util';
|
|
4
4
|
import { Tooltip as TooltipComponent } from '@antv/gui';
|
|
5
|
-
import {
|
|
5
|
+
import { Identity } from '@antv/scale';
|
|
6
|
+
import { defined, subObject, isStrictObject } from '../../utils/helper';
|
|
6
7
|
import {
|
|
7
8
|
selectG2Elements,
|
|
8
9
|
createXKey,
|
|
9
10
|
selectPlotArea,
|
|
10
11
|
mousePosition,
|
|
12
|
+
selectFacetG2Elements,
|
|
11
13
|
} from './utils';
|
|
12
14
|
|
|
13
15
|
function getContainer(group: IElement) {
|
|
@@ -34,6 +36,7 @@ function createTooltip(root, x0, y0) {
|
|
|
34
36
|
width: x1 - x,
|
|
35
37
|
height: y1 - y,
|
|
36
38
|
},
|
|
39
|
+
title: ' ',
|
|
37
40
|
position: 'bottom-right',
|
|
38
41
|
offset: [10, 10],
|
|
39
42
|
style: {
|
|
@@ -46,18 +49,18 @@ function createTooltip(root, x0, y0) {
|
|
|
46
49
|
},
|
|
47
50
|
},
|
|
48
51
|
});
|
|
52
|
+
// @ts-ignore
|
|
49
53
|
const container = getContainer(root);
|
|
50
54
|
container.appendChild(tooltipElement.HTMLTooltipElement);
|
|
51
55
|
return tooltipElement;
|
|
52
56
|
}
|
|
53
57
|
|
|
54
58
|
function showTooltip(root, data, x, y) {
|
|
55
|
-
const tooltipElement =
|
|
59
|
+
const { tooltipElement = createTooltip(root, x, y) } = root;
|
|
56
60
|
const { items, title } = data;
|
|
57
61
|
tooltipElement.show();
|
|
62
|
+
tooltipElement.position = [x, y];
|
|
58
63
|
tooltipElement.update({
|
|
59
|
-
x,
|
|
60
|
-
y,
|
|
61
64
|
items,
|
|
62
65
|
title,
|
|
63
66
|
});
|
|
@@ -82,16 +85,24 @@ function filterDefined(obj) {
|
|
|
82
85
|
function singleItem(element, item, scale) {
|
|
83
86
|
const { __data__: datum } = element;
|
|
84
87
|
const { title, ...rest } = datum;
|
|
85
|
-
const
|
|
88
|
+
const defaultColor = itemColorOf(element);
|
|
86
89
|
const items = Object.entries(rest)
|
|
87
90
|
.filter(([key]) => key.startsWith('tooltip'))
|
|
88
91
|
.map(([key, d]: any) => {
|
|
89
|
-
const { field, title =
|
|
92
|
+
const { field: f, title = f } = scale[key].getOptions();
|
|
93
|
+
const {
|
|
94
|
+
field = undefined,
|
|
95
|
+
color = defaultColor,
|
|
96
|
+
name = field || title,
|
|
97
|
+
value,
|
|
98
|
+
...rest
|
|
99
|
+
} = normalizeTooltip(d);
|
|
90
100
|
return {
|
|
101
|
+
...rest,
|
|
91
102
|
color,
|
|
92
|
-
name
|
|
93
|
-
value
|
|
94
|
-
...filterDefined(item({ channel: key, value
|
|
103
|
+
name,
|
|
104
|
+
value,
|
|
105
|
+
...filterDefined(item({ channel: key, value })),
|
|
95
106
|
};
|
|
96
107
|
})
|
|
97
108
|
.filter(({ value }) => value !== undefined);
|
|
@@ -101,15 +112,18 @@ function singleItem(element, item, scale) {
|
|
|
101
112
|
};
|
|
102
113
|
}
|
|
103
114
|
|
|
104
|
-
function
|
|
115
|
+
function groupNameOf(scale, datum) {
|
|
105
116
|
const { color: scaleColor, series: scaleSeries } = scale;
|
|
106
117
|
const { color, series } = datum;
|
|
107
|
-
|
|
108
|
-
|
|
118
|
+
const invertAble = (scale) => {
|
|
119
|
+
return scale && scale.invert && !(scale instanceof Identity);
|
|
120
|
+
};
|
|
121
|
+
if (invertAble(scaleColor)) return scaleColor.invert(color);
|
|
122
|
+
if (invertAble(scaleSeries)) return scaleSeries.invert(series);
|
|
109
123
|
return null;
|
|
110
124
|
}
|
|
111
125
|
|
|
112
|
-
function
|
|
126
|
+
function itemColorOf(element) {
|
|
113
127
|
const fill = element.getAttribute('fill');
|
|
114
128
|
const stroke = element.getAttribute('stroke');
|
|
115
129
|
const { __data__: datum } = element;
|
|
@@ -117,6 +131,10 @@ function itemColorof(element) {
|
|
|
117
131
|
return color;
|
|
118
132
|
}
|
|
119
133
|
|
|
134
|
+
function normalizeTooltip(d) {
|
|
135
|
+
return isStrictObject(d) ? d : { value: d === undefined ? d : `${d}` };
|
|
136
|
+
}
|
|
137
|
+
|
|
120
138
|
function groupItems(
|
|
121
139
|
elements,
|
|
122
140
|
item,
|
|
@@ -127,15 +145,23 @@ function groupItems(
|
|
|
127
145
|
const items = data.flatMap((datum, i) => {
|
|
128
146
|
const element = elements[i];
|
|
129
147
|
const { title, ...rest } = datum;
|
|
130
|
-
const
|
|
148
|
+
const defaultColor = itemColorOf(element);
|
|
131
149
|
return Object.entries(rest)
|
|
132
150
|
.filter(([key]) => key.startsWith('tooltip'))
|
|
133
151
|
.map(([key, d]: any) => {
|
|
134
|
-
const { field, title =
|
|
152
|
+
const { field: f, title = f } = scale[key].getOptions();
|
|
153
|
+
const {
|
|
154
|
+
field = undefined,
|
|
155
|
+
color = defaultColor,
|
|
156
|
+
name = groupNameOf(scale, datum) || field || title,
|
|
157
|
+
value,
|
|
158
|
+
...rest
|
|
159
|
+
} = normalizeTooltip(d);
|
|
135
160
|
return {
|
|
161
|
+
...rest,
|
|
162
|
+
name,
|
|
136
163
|
color,
|
|
137
|
-
|
|
138
|
-
value: d === undefined ? d : `${d}`,
|
|
164
|
+
value,
|
|
139
165
|
...filterDefined(item({ channel: key, value: d })),
|
|
140
166
|
};
|
|
141
167
|
})
|
|
@@ -147,13 +173,13 @@ function groupItems(
|
|
|
147
173
|
};
|
|
148
174
|
}
|
|
149
175
|
|
|
150
|
-
function updateRuleY(root, points, { height, ...rest }) {
|
|
176
|
+
function updateRuleY(root, points, { height, startX, startY, ...rest }) {
|
|
151
177
|
const X = points.map((p) => p[0]);
|
|
152
178
|
const x = mean(X);
|
|
153
|
-
const x1 = x;
|
|
154
|
-
const x2 = x;
|
|
155
|
-
const y1 =
|
|
156
|
-
const y2 = height;
|
|
179
|
+
const x1 = x + startX;
|
|
180
|
+
const x2 = x + startX;
|
|
181
|
+
const y1 = startY;
|
|
182
|
+
const y2 = height - startY;
|
|
157
183
|
const createLine = () => {
|
|
158
184
|
const line = new Line({
|
|
159
185
|
style: {
|
|
@@ -217,25 +243,72 @@ export function seriesTooltip(
|
|
|
217
243
|
trailing = false,
|
|
218
244
|
scale,
|
|
219
245
|
coordinate,
|
|
220
|
-
|
|
246
|
+
crosshairs,
|
|
221
247
|
item,
|
|
248
|
+
startX = 0,
|
|
249
|
+
startY = 0,
|
|
222
250
|
...rest
|
|
223
251
|
}: Record<string, any>,
|
|
224
252
|
) {
|
|
225
253
|
const elements = elementsof(root);
|
|
226
254
|
const [, height] = sizeof(root);
|
|
255
|
+
|
|
256
|
+
// Split elements into series elements and item elements.
|
|
257
|
+
const seriesElements = [];
|
|
258
|
+
const itemElements = [];
|
|
259
|
+
for (const element of elements) {
|
|
260
|
+
const { __data__: data } = element;
|
|
261
|
+
const { seriesX } = data;
|
|
262
|
+
if (seriesX) seriesElements.push(element);
|
|
263
|
+
else itemElements.push(element);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
// Get sortedIndex and X for each series elements
|
|
227
267
|
const elementSortedX = new Map(
|
|
228
|
-
|
|
268
|
+
seriesElements.map((element) => {
|
|
229
269
|
const { __data__: data } = element;
|
|
230
270
|
const { seriesX } = data;
|
|
231
|
-
|
|
271
|
+
const seriesIndex = seriesX.map((_, i) => i);
|
|
272
|
+
const sortedIndex = sort(seriesIndex, (i) => seriesX[+i]);
|
|
273
|
+
return [element, [sortedIndex, seriesX]];
|
|
232
274
|
}),
|
|
233
275
|
);
|
|
276
|
+
|
|
277
|
+
// Get sortedIndex and X for all item items.
|
|
278
|
+
const itemIndex = itemElements.map((_, i) => i);
|
|
279
|
+
const itemX = itemElements.map((element) => {
|
|
280
|
+
const { __data__: data } = element;
|
|
281
|
+
return data.x;
|
|
282
|
+
});
|
|
283
|
+
const itemSortedIndex = sort(itemIndex, (i) => itemX[i]);
|
|
284
|
+
|
|
234
285
|
const ruleStyle = subObject(rest, 'crosshairs');
|
|
286
|
+
const { x: scaleX } = scale;
|
|
287
|
+
|
|
288
|
+
// Apply offset for band scale x.
|
|
289
|
+
const offsetX = scaleX?.getBandWidth ? scaleX.getBandWidth() / 2 : 0;
|
|
290
|
+
|
|
291
|
+
const indexByFocus = (focus, I, X) => {
|
|
292
|
+
const [normalizedX] = coordinate.invert(focus);
|
|
293
|
+
const search = bisector((i) => X[+i]).center;
|
|
294
|
+
const i = search(I, normalizedX - offsetX);
|
|
295
|
+
return I[i];
|
|
296
|
+
};
|
|
235
297
|
|
|
236
|
-
const
|
|
298
|
+
const indicesByFocus = (focus, I, X) => {
|
|
299
|
+
const len = I.length;
|
|
300
|
+
if (len === 0) return [];
|
|
237
301
|
const [normalizedX] = coordinate.invert(focus);
|
|
238
|
-
|
|
302
|
+
const x = normalizedX - offsetX;
|
|
303
|
+
const search = bisector((i) => X[+i]).center;
|
|
304
|
+
const center = search(I, x);
|
|
305
|
+
|
|
306
|
+
// Find the least index and greatest index of X[center]
|
|
307
|
+
let left = center;
|
|
308
|
+
let right = center;
|
|
309
|
+
while (left - 1 > 0 && X[I[left - 1]] == X[I[center]]) left--;
|
|
310
|
+
while (right + 1 < len && X[I[right + 1]] === X[I[center]]) right++;
|
|
311
|
+
return range(left, right + 1).map((i) => I[i]);
|
|
239
312
|
};
|
|
240
313
|
|
|
241
314
|
const seriesData = (element, index) => {
|
|
@@ -252,23 +325,44 @@ export function seriesTooltip(
|
|
|
252
325
|
|
|
253
326
|
const update = throttle(
|
|
254
327
|
(event) => {
|
|
255
|
-
const
|
|
328
|
+
const mouse = mousePosition(root, event);
|
|
329
|
+
if (!mouse) return;
|
|
256
330
|
const bbox = root.getBounds();
|
|
257
331
|
const x = bbox.min[0];
|
|
258
332
|
const y = bbox.min[1];
|
|
333
|
+
const focus = [mouse[0] - startX, mouse[1] - startY];
|
|
259
334
|
if (!focus) return;
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
335
|
+
// Get selected item element.
|
|
336
|
+
const selectedItemIndices = indicesByFocus(focus, itemSortedIndex, itemX);
|
|
337
|
+
const selectedItems = selectedItemIndices.map((i) => itemElements[i]);
|
|
338
|
+
|
|
339
|
+
// Get selected data item from both series element and item element.
|
|
340
|
+
const selectedSeriesData = seriesElements.map((element) => {
|
|
341
|
+
const [sortedIndex, X] = elementSortedX.get(element);
|
|
342
|
+
const index = indexByFocus(focus, sortedIndex, X);
|
|
263
343
|
const d = seriesData(element, index);
|
|
264
344
|
const { x, y } = d;
|
|
265
|
-
return [d, coordinate.map([x, y])] as const;
|
|
345
|
+
return [d, coordinate.map([x + offsetX, y])] as const;
|
|
266
346
|
});
|
|
267
|
-
const
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
347
|
+
const selectedData = [
|
|
348
|
+
...selectedSeriesData.map((d) => d[0]),
|
|
349
|
+
...selectedItems.map((d) => d.__data__),
|
|
350
|
+
];
|
|
351
|
+
|
|
352
|
+
// Get the displayed tooltip data.
|
|
353
|
+
const selectedElements = [...seriesElements, ...selectedItems];
|
|
354
|
+
const tooltipData = groupItems(
|
|
355
|
+
selectedElements,
|
|
356
|
+
item,
|
|
357
|
+
scale,
|
|
358
|
+
selectedData,
|
|
359
|
+
);
|
|
360
|
+
|
|
361
|
+
showTooltip(root, tooltipData, mouse[0] + x, mouse[1] + y);
|
|
362
|
+
if (crosshairs) {
|
|
363
|
+
const points = selectedSeriesData.map((d) => d[1]);
|
|
364
|
+
updateRuleY(root, points, { ...ruleStyle, height, startX, startY });
|
|
365
|
+
}
|
|
272
366
|
},
|
|
273
367
|
wait,
|
|
274
368
|
{ leading, trailing },
|
|
@@ -276,7 +370,7 @@ export function seriesTooltip(
|
|
|
276
370
|
|
|
277
371
|
const hide = () => {
|
|
278
372
|
hideTooltip(root);
|
|
279
|
-
if (
|
|
373
|
+
if (crosshairs) hideRuleY(root);
|
|
280
374
|
};
|
|
281
375
|
|
|
282
376
|
root.addEventListener('pointerenter', update);
|
|
@@ -346,29 +440,63 @@ export function tooltip(
|
|
|
346
440
|
export function Tooltip(options) {
|
|
347
441
|
const {
|
|
348
442
|
shared,
|
|
349
|
-
|
|
443
|
+
crosshairs,
|
|
350
444
|
series,
|
|
351
445
|
name,
|
|
352
446
|
item = () => ({}),
|
|
447
|
+
facet = false,
|
|
353
448
|
...rest
|
|
354
449
|
} = options;
|
|
355
|
-
return (
|
|
356
|
-
const { container, view } =
|
|
450
|
+
return (target, viewInstances) => {
|
|
451
|
+
const { container, view } = target;
|
|
357
452
|
const { scale, markState, coordinate } = view;
|
|
453
|
+
|
|
358
454
|
// Get default value from mark states.
|
|
359
455
|
const defaultSeries = interactionKeyof(markState, 'seriesTooltip');
|
|
360
|
-
const defaultShowCrosshairs = interactionKeyof(markState, '
|
|
456
|
+
const defaultShowCrosshairs = interactionKeyof(markState, 'crosshairs');
|
|
361
457
|
const plotArea = selectPlotArea(container);
|
|
362
|
-
|
|
458
|
+
const isSeries = maybeValue(series, defaultSeries);
|
|
459
|
+
|
|
460
|
+
// For non-facet and series tooltip.
|
|
461
|
+
if (isSeries && !facet) {
|
|
363
462
|
return seriesTooltip(plotArea, {
|
|
364
463
|
...rest,
|
|
365
464
|
elements: selectG2Elements,
|
|
366
465
|
scale,
|
|
367
466
|
coordinate,
|
|
368
|
-
|
|
467
|
+
crosshairs: maybeValue(crosshairs, defaultShowCrosshairs),
|
|
369
468
|
item,
|
|
370
469
|
});
|
|
371
470
|
}
|
|
471
|
+
|
|
472
|
+
// For facet and series tooltip.
|
|
473
|
+
if (isSeries && facet) {
|
|
474
|
+
// Get sub view instances for this view.
|
|
475
|
+
const facetInstances = viewInstances.filter(
|
|
476
|
+
(d) => d !== target && d.options.parentKey === target.options.key,
|
|
477
|
+
);
|
|
478
|
+
const elements = selectFacetG2Elements(target, viewInstances);
|
|
479
|
+
// Use the scale of the first view.
|
|
480
|
+
const scale = facetInstances[0].view.scale;
|
|
481
|
+
const bbox = plotArea.getBounds();
|
|
482
|
+
const startX = bbox.min[0];
|
|
483
|
+
const startY = bbox.min[1];
|
|
484
|
+
|
|
485
|
+
// @todo Nested structure rather than flat structure for facet?
|
|
486
|
+
// Add listener to the root area.
|
|
487
|
+
// @ts-ignore
|
|
488
|
+
return seriesTooltip(plotArea.parentNode.parentNode, {
|
|
489
|
+
...rest,
|
|
490
|
+
elements: () => elements,
|
|
491
|
+
scale,
|
|
492
|
+
coordinate,
|
|
493
|
+
crosshairs: maybeValue(crosshairs, defaultShowCrosshairs),
|
|
494
|
+
item,
|
|
495
|
+
startX,
|
|
496
|
+
startY,
|
|
497
|
+
});
|
|
498
|
+
}
|
|
499
|
+
|
|
372
500
|
return tooltip(plotArea, {
|
|
373
501
|
...rest,
|
|
374
502
|
elements: selectG2Elements,
|
|
@@ -16,6 +16,13 @@ export function selectG2Elements(root: DisplayObject): DisplayObject[] {
|
|
|
16
16
|
return select(root).selectAll(`.${ELEMENT_CLASS_NAME}`).nodes();
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
+
export function selectFacetG2Elements(target, viewInstances): DisplayObject[] {
|
|
20
|
+
const facetInstances = viewInstances.filter(
|
|
21
|
+
(d) => d !== target && d.options.parentKey === target.options.key,
|
|
22
|
+
);
|
|
23
|
+
return facetInstances.flatMap(({ container }) => selectG2Elements(container));
|
|
24
|
+
}
|
|
25
|
+
|
|
19
26
|
export function selectPlotArea(root: DisplayObject): DisplayObject {
|
|
20
27
|
return select(root).select(`.${PLOT_CLASS_NAME}`).node();
|
|
21
28
|
}
|
|
@@ -33,6 +40,19 @@ export function mousePosition(target, event) {
|
|
|
33
40
|
return [offsetX - x, offsetY - y];
|
|
34
41
|
}
|
|
35
42
|
|
|
43
|
+
export function mousePositionClamp(target, event) {
|
|
44
|
+
const { offsetX, offsetY } = event;
|
|
45
|
+
const bbox = target.getBounds();
|
|
46
|
+
const {
|
|
47
|
+
min: [x, y],
|
|
48
|
+
max: [x1, y1],
|
|
49
|
+
} = bbox;
|
|
50
|
+
return [
|
|
51
|
+
Math.min(x1, Math.max(x, offsetX)) - x,
|
|
52
|
+
Math.min(y1, Math.max(y, offsetY)) - y,
|
|
53
|
+
];
|
|
54
|
+
}
|
|
55
|
+
|
|
36
56
|
export function applyDefaultsHighlightedStyle(
|
|
37
57
|
style: Record<string, any>,
|
|
38
58
|
): Record<string, any> {
|
|
@@ -73,6 +93,7 @@ export function createDatumof(view: G2ViewDescriptor) {
|
|
|
73
93
|
export function useState(
|
|
74
94
|
style: Record<string, any>,
|
|
75
95
|
valueof = (d, element) => d,
|
|
96
|
+
setAttribute = (element, key, v) => element.setAttribute(key, v),
|
|
76
97
|
) {
|
|
77
98
|
const STATES = '__states__';
|
|
78
99
|
const ORIGINAL = '__ordinal__';
|
|
@@ -91,7 +112,7 @@ export function useState(
|
|
|
91
112
|
for (const [key, value] of Object.entries(stateStyle)) {
|
|
92
113
|
const currentValue = element.getAttribute(key);
|
|
93
114
|
const v = valueof(value, element);
|
|
94
|
-
|
|
115
|
+
setAttribute(element, key, v);
|
|
95
116
|
// Store the attribute if it does not exist in original.
|
|
96
117
|
if (!(key in original)) original[key] = currentValue;
|
|
97
118
|
}
|
|
@@ -199,3 +220,14 @@ export function renderLink(
|
|
|
199
220
|
|
|
200
221
|
return [append, remove] as const;
|
|
201
222
|
}
|
|
223
|
+
|
|
224
|
+
export function setCursor(root, cursor) {
|
|
225
|
+
// @ts-ignore
|
|
226
|
+
const canvas = root.getRootNode().defaultView;
|
|
227
|
+
const dom = canvas.getContextService().getDomElement();
|
|
228
|
+
if (dom?.style) dom.style.cursor = cursor;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
export function restoreCursor(root) {
|
|
232
|
+
setCursor(root, 'default');
|
|
233
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { DisplayObject } from '@antv/g';
|
|
2
|
+
import { maxIndex } from 'd3-array';
|
|
3
|
+
import { ContrastReverseTransform } from '../spec';
|
|
4
|
+
import { LabelTransformComponent as LLC } from '../runtime';
|
|
5
|
+
import { parseToRGB } from '../utils/color';
|
|
6
|
+
|
|
7
|
+
export type ContrastReverseOptions = Omit<ContrastReverseTransform, 'type'>;
|
|
8
|
+
|
|
9
|
+
function getsRGB(s: number) {
|
|
10
|
+
let c = s / 255;
|
|
11
|
+
c = c <= 0.03928 ? c / 12.92 : Math.pow((c + 0.055) / 1.055, 2.4);
|
|
12
|
+
return c;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function getL(r: number, g: number, b: number) {
|
|
16
|
+
return 0.2126 * getsRGB(r) + 0.7152 * getsRGB(g) + 0.0722 * getsRGB(b);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Calculate the contrast. see https://webaim.org/resources/contrastchecker/
|
|
21
|
+
* @param foreground
|
|
22
|
+
* @param background
|
|
23
|
+
*/
|
|
24
|
+
function contrast(foreground, background): number {
|
|
25
|
+
const { r, g, b } = foreground;
|
|
26
|
+
const { r: rb, g: gb, b: bb } = background;
|
|
27
|
+
const L1 = getL(r, g, b);
|
|
28
|
+
const L2 = getL(rb, gb, bb);
|
|
29
|
+
return (Math.max(L1, L2) + 0.05) / (Math.min(L1, L2) + 0.05);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Reverse color for max contrast.
|
|
34
|
+
*/
|
|
35
|
+
function mostContrast(color, palette: string[]): string {
|
|
36
|
+
const i = maxIndex(palette, (c) => contrast(color, parseToRGB(c)));
|
|
37
|
+
return palette[i];
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Reverse the label color when the contrast is lower then `threshold`.
|
|
42
|
+
* The default value of `threshold` is 4.5.
|
|
43
|
+
* More about contract, see https://webaim.org/resources/contrastchecker/
|
|
44
|
+
*/
|
|
45
|
+
export const ContrastReverse: LLC<ContrastReverseOptions> = (options) => {
|
|
46
|
+
const { threshold = 4.5, palette = ['#000', '#fff'] } = options;
|
|
47
|
+
return (labels: DisplayObject[], coordinate) => {
|
|
48
|
+
labels.forEach((l) => {
|
|
49
|
+
const background = l.attr('dependentElement').parsedStyle.fill;
|
|
50
|
+
const foreground = l.parsedStyle.fill;
|
|
51
|
+
const c = contrast(foreground, background);
|
|
52
|
+
if (c < threshold) l.attr('fill', mostContrast(background, palette));
|
|
53
|
+
});
|
|
54
|
+
return labels;
|
|
55
|
+
};
|
|
56
|
+
};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
4
|
-
export {
|
|
1
|
+
export { OverlapHide } from './overlapHide';
|
|
2
|
+
export { OverlapDodgeY } from './overlapDodgeY';
|
|
3
|
+
export { ContrastReverse } from './contrastReverse';
|
|
4
|
+
export { OverflowHide } from './overflowHide';
|
|
5
5
|
|
|
6
|
-
export type {
|
|
7
|
-
export type {
|
|
8
|
-
export type {
|
|
9
|
-
export type {
|
|
6
|
+
export type { OverlapHideOptions } from './overlapHide';
|
|
7
|
+
export type { OverlapDodgeYOptions } from './overlapDodgeY';
|
|
8
|
+
export type { ContrastReverseOptions } from './contrastReverse';
|
|
9
|
+
export type { OverflowHideOptions } from './overflowHide';
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { DisplayObject } from '@antv/g';
|
|
2
|
+
import { OverflowHideTransform } from '../spec';
|
|
3
|
+
import { LabelTransformComponent as LLC } from '../runtime';
|
|
4
|
+
import { isOverflow, parseAABB } from '../utils/bounds';
|
|
5
|
+
|
|
6
|
+
export type OverflowHideOptions = Omit<OverflowHideTransform, 'type'>;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Hide the label when the label is overflowed from the element.
|
|
10
|
+
*/
|
|
11
|
+
export const OverflowHide: LLC<OverflowHideOptions> = (options) => {
|
|
12
|
+
return (labels: DisplayObject[], coordinate) => {
|
|
13
|
+
labels.forEach((l) => {
|
|
14
|
+
l.attr('visibility', 'visible');
|
|
15
|
+
|
|
16
|
+
const bounds = l.attr('bounds');
|
|
17
|
+
const b = l.getLocalBounds();
|
|
18
|
+
const overflow = isOverflow(parseAABB(b), bounds);
|
|
19
|
+
if (overflow) l.attr('visibility', 'hidden');
|
|
20
|
+
});
|
|
21
|
+
return labels;
|
|
22
|
+
};
|
|
23
|
+
};
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { DisplayObject } from '@antv/g';
|
|
2
2
|
import { ascending } from 'd3-array';
|
|
3
|
-
import {
|
|
3
|
+
import { OverlapDodgeYTransform } from '../spec';
|
|
4
4
|
import { LabelTransformComponent as LLC } from '../runtime';
|
|
5
5
|
|
|
6
|
+
export type OverlapDodgeYOptions = Omit<OverlapDodgeYTransform, 'type'>;
|
|
7
|
+
|
|
6
8
|
function isSegmentIntersect([a, b], [c, d]) {
|
|
7
9
|
return d > a && b > c;
|
|
8
10
|
}
|
|
@@ -14,8 +16,6 @@ function useMap<K, V>() {
|
|
|
14
16
|
return [get, set] as const;
|
|
15
17
|
}
|
|
16
18
|
|
|
17
|
-
export type DodgeYOptions = Omit<DodgeYLabelTransform, 'type'>;
|
|
18
|
-
|
|
19
19
|
function getBoundsWithoutConnector(shape: DisplayObject) {
|
|
20
20
|
const node = shape.cloneNode(true);
|
|
21
21
|
const connectorShape = node.getElementById('connector');
|
|
@@ -29,8 +29,8 @@ function getBoundsWithoutConnector(shape: DisplayObject) {
|
|
|
29
29
|
/**
|
|
30
30
|
* An iterative dodge method avoids label overlap. (n * log(n))
|
|
31
31
|
*/
|
|
32
|
-
export const
|
|
33
|
-
const {
|
|
32
|
+
export const OverlapDodgeY: LLC<OverlapDodgeYOptions> = (options) => {
|
|
33
|
+
const { maxIterations = 10, maxError = 0.1, padding = 1 } = options;
|
|
34
34
|
return (labels: DisplayObject[]) => {
|
|
35
35
|
const n = labels.length;
|
|
36
36
|
if (n <= 1) return labels;
|
|
@@ -51,7 +51,7 @@ export const DodgeY: LLC<DodgeYOptions> = (options) => {
|
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
// Offsets position Y.
|
|
54
|
-
for (let iter = 0; iter <
|
|
54
|
+
for (let iter = 0; iter < maxIterations; iter++) {
|
|
55
55
|
labels.sort((a, b) => ascending(y(a), y(b)));
|
|
56
56
|
let error = 0;
|
|
57
57
|
for (let i = 0; i < n - 1; i++) {
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { DisplayObject } from '@antv/g';
|
|
2
|
+
import { LabelTransformComponent as LLC } from '../runtime';
|
|
3
|
+
import { OverlapHideTransform } from '../spec';
|
|
4
|
+
import { isOverlap, parseAABB } from '../utils/bounds';
|
|
5
|
+
|
|
6
|
+
export type OverlapHideOptions = Omit<OverlapHideTransform, 'type'>;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Hide the label when overlap.
|
|
10
|
+
*/
|
|
11
|
+
export const OverlapHide: LLC<OverlapHideOptions> = (options) => {
|
|
12
|
+
const { priority } = options;
|
|
13
|
+
return (labels: DisplayObject[], coordinate) => {
|
|
14
|
+
const displayLabels = [];
|
|
15
|
+
// When overlap, will hide the next label.
|
|
16
|
+
if (priority) labels.sort(priority);
|
|
17
|
+
|
|
18
|
+
labels.forEach((l) => {
|
|
19
|
+
l.attr('visibility', 'visible');
|
|
20
|
+
|
|
21
|
+
const b1 = l.getLocalBounds();
|
|
22
|
+
const overlaping = displayLabels.some((dl) =>
|
|
23
|
+
isOverlap(parseAABB(b1), parseAABB(dl.getLocalBounds())),
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
if (overlaping) l.attr('visibility', 'hidden');
|
|
27
|
+
else displayLabels.push(l);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
return labels;
|
|
31
|
+
};
|
|
32
|
+
};
|
package/src/mark/area.ts
CHANGED