@antv/g2 5.0.0-beta.10 → 5.0.0-beta.12
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/api/chart.d.ts +2 -1
- package/esm/api/chart.js +2 -2
- package/esm/api/chart.js.map +1 -1
- package/esm/api/composition/base.d.ts +1 -1
- package/esm/api/composition/base.js +6 -17
- package/esm/api/composition/base.js.map +1 -1
- package/esm/api/composition/facetCircle.d.ts +2 -2
- package/esm/api/composition/facetCircle.js +2 -2
- package/esm/api/composition/facetCircle.js.map +1 -1
- package/esm/api/composition/facetRect.d.ts +2 -2
- package/esm/api/composition/facetRect.js +2 -2
- package/esm/api/composition/facetRect.js.map +1 -1
- package/esm/api/composition/geoPath.d.ts +2 -2
- package/esm/api/composition/geoPath.js +2 -2
- package/esm/api/composition/geoPath.js.map +1 -1
- package/esm/api/composition/geoView.d.ts +2 -2
- package/esm/api/composition/geoView.js +2 -2
- package/esm/api/composition/geoView.js.map +1 -1
- package/esm/api/composition/index.d.ts +2 -2
- package/esm/api/composition/index.js +2 -2
- package/esm/api/composition/index.js.map +1 -1
- package/esm/api/composition/repeatMatrix.d.ts +2 -2
- package/esm/api/composition/repeatMatrix.js +2 -2
- package/esm/api/composition/repeatMatrix.js.map +1 -1
- package/esm/api/composition/spaceFlex.d.ts +2 -2
- package/esm/api/composition/spaceFlex.js +2 -2
- package/esm/api/composition/spaceFlex.js.map +1 -1
- package/esm/api/composition/spaceLayer.d.ts +2 -2
- package/esm/api/composition/spaceLayer.js +2 -2
- package/esm/api/composition/spaceLayer.js.map +1 -1
- package/esm/api/composition/timingKeyframe.d.ts +2 -2
- package/esm/api/composition/timingKeyframe.js +2 -2
- package/esm/api/composition/timingKeyframe.js.map +1 -1
- package/esm/api/composition/view.d.ts +2 -2
- package/esm/api/composition/view.js +2 -2
- package/esm/api/composition/view.js.map +1 -1
- package/esm/api/index.d.ts +2 -0
- package/esm/api/index.js +2 -0
- package/esm/api/index.js.map +1 -1
- package/esm/api/mark/base.d.ts +1 -1
- package/esm/api/mark/base.js +7 -7
- package/esm/api/mark/base.js.map +1 -1
- package/esm/api/mark/index.d.ts +1 -0
- package/esm/api/mark/index.js +1 -0
- package/esm/api/mark/index.js.map +1 -1
- package/esm/api/mark/mark.d.ts +27 -27
- package/esm/api/mark/mark.js +28 -27
- package/esm/api/mark/mark.js.map +1 -1
- package/esm/api/mark/types.d.ts +1 -0
- package/esm/api/node.d.ts +1 -1
- package/esm/api/node.js +1 -1
- package/esm/api/node.js.map +1 -1
- package/esm/api/props.d.ts +1 -1
- package/esm/api/props.js +20 -0
- package/esm/api/props.js.map +1 -1
- package/esm/composition/timingKeyframe.js +13 -7
- package/esm/composition/timingKeyframe.js.map +1 -1
- package/esm/composition/view.js +2 -6
- package/esm/composition/view.js.map +1 -1
- package/esm/index.d.ts +1 -1
- package/esm/index.js +1 -1
- package/esm/index.js.map +1 -1
- package/esm/interaction/builtin/tooltip.d.ts +10 -2
- package/esm/interaction/index.d.ts +1 -0
- package/esm/interaction/index.js +1 -0
- package/esm/interaction/index.js.map +1 -1
- package/esm/interaction/native/event.d.ts +1 -0
- package/esm/interaction/native/event.js +42 -0
- package/esm/interaction/native/event.js.map +1 -0
- package/esm/interaction/native/tooltip.d.ts +2 -3
- package/esm/interaction/native/tooltip.js +78 -76
- package/esm/interaction/native/tooltip.js.map +1 -1
- package/esm/mark/area.js +1 -0
- package/esm/mark/area.js.map +1 -1
- package/esm/mark/box.js +1 -0
- package/esm/mark/box.js.map +1 -1
- package/esm/mark/boxplot.js +1 -3
- package/esm/mark/boxplot.js.map +1 -1
- package/esm/mark/cell.js +1 -0
- package/esm/mark/cell.js.map +1 -1
- package/esm/mark/connector.js +1 -0
- package/esm/mark/connector.js.map +1 -1
- package/esm/mark/forceGraph.js +1 -1
- package/esm/mark/forceGraph.js.map +1 -1
- package/esm/mark/image.js +1 -0
- package/esm/mark/image.js.map +1 -1
- package/esm/mark/interval.js +1 -0
- package/esm/mark/interval.js.map +1 -1
- package/esm/mark/line.js +1 -0
- package/esm/mark/line.js.map +1 -1
- package/esm/mark/lineX.js +1 -0
- package/esm/mark/lineX.js.map +1 -1
- package/esm/mark/lineY.js +1 -0
- package/esm/mark/lineY.js.map +1 -1
- package/esm/mark/link.js +1 -0
- package/esm/mark/link.js.map +1 -1
- package/esm/mark/pack.js +1 -1
- package/esm/mark/pack.js.map +1 -1
- package/esm/mark/path.js +1 -0
- package/esm/mark/path.js.map +1 -1
- package/esm/mark/point.js +1 -0
- package/esm/mark/point.js.map +1 -1
- package/esm/mark/polygon.js +1 -0
- package/esm/mark/polygon.js.map +1 -1
- package/esm/mark/range.js +1 -0
- package/esm/mark/range.js.map +1 -1
- package/esm/mark/rangeX.js +1 -0
- package/esm/mark/rangeX.js.map +1 -1
- package/esm/mark/rangeY.js +1 -0
- package/esm/mark/rangeY.js.map +1 -1
- package/esm/mark/rect.js +1 -0
- package/esm/mark/rect.js.map +1 -1
- package/esm/mark/sankey.js +1 -1
- package/esm/mark/sankey.js.map +1 -1
- package/esm/mark/shape.js +1 -0
- package/esm/mark/shape.js.map +1 -1
- package/esm/mark/text.js +1 -0
- package/esm/mark/text.js.map +1 -1
- package/esm/mark/tree.js +1 -1
- package/esm/mark/tree.js.map +1 -1
- package/esm/mark/treemap.js +1 -1
- package/esm/mark/treemap.js.map +1 -1
- package/esm/mark/utils.js +1 -5
- package/esm/mark/utils.js.map +1 -1
- package/esm/mark/vector.js +1 -0
- package/esm/mark/vector.js.map +1 -1
- package/esm/mark/wordCloud.js +1 -1
- package/esm/mark/wordCloud.js.map +1 -1
- package/esm/runtime/mark.js +12 -7
- package/esm/runtime/mark.js.map +1 -1
- package/esm/runtime/plot.js +81 -39
- package/esm/runtime/plot.js.map +1 -1
- package/esm/runtime/scale.js +2 -0
- package/esm/runtime/scale.js.map +1 -1
- package/esm/runtime/transform.d.ts +5 -0
- package/esm/runtime/transform.js +63 -6
- package/esm/runtime/transform.js.map +1 -1
- package/esm/runtime/types/common.d.ts +1 -0
- package/esm/runtime/types/component.d.ts +2 -1
- package/esm/runtime/types/mark.d.ts +3 -3
- package/esm/runtime/types/options.d.ts +8 -1
- package/esm/scale/constant.d.ts +4 -0
- package/esm/scale/constant.js +6 -0
- package/esm/scale/constant.js.map +1 -0
- package/esm/scale/index.d.ts +2 -0
- package/esm/scale/index.js +1 -0
- package/esm/scale/index.js.map +1 -1
- package/esm/shape/interval/color.js +6 -4
- package/esm/shape/interval/color.js.map +1 -1
- package/esm/spec/geometry.d.ts +33 -17
- package/esm/spec/interaction.d.ts +6 -1
- package/esm/spec/scale.d.ts +4 -3
- package/esm/stdlib/index.js +3 -3
- package/esm/stdlib/index.js.map +1 -1
- package/esm/transform/groupN.js +2 -2
- package/esm/transform/groupN.js.map +1 -1
- package/esm/transform/maybeTitle.js +13 -3
- package/esm/transform/maybeTitle.js.map +1 -1
- package/esm/transform/maybeTooltip.js +20 -20
- package/esm/transform/maybeTooltip.js.map +1 -1
- package/esm/transform/maybeZeroX.js +2 -2
- package/esm/transform/maybeZeroX.js.map +1 -1
- package/esm/transform/maybeZeroY.js +2 -2
- package/esm/transform/maybeZeroY.js.map +1 -1
- package/esm/transform/maybeZeroY1.js +2 -2
- package/esm/transform/maybeZeroY1.js.map +1 -1
- package/esm/transform/utils/helper.d.ts +12 -0
- package/esm/transform/utils/helper.js +8 -0
- package/esm/transform/utils/helper.js.map +1 -1
- package/esm/utils/helper.js +4 -1
- package/esm/utils/helper.js.map +1 -1
- package/lib/api/chart.d.ts +2 -1
- package/lib/api/chart.js +2 -2
- package/lib/api/chart.js.map +1 -1
- package/lib/api/composition/base.d.ts +1 -1
- package/lib/api/composition/base.js +8 -18
- package/lib/api/composition/base.js.map +1 -1
- package/lib/api/composition/facetCircle.d.ts +2 -2
- package/lib/api/composition/facetCircle.js +1 -1
- package/lib/api/composition/facetCircle.js.map +1 -1
- package/lib/api/composition/facetRect.d.ts +2 -2
- package/lib/api/composition/facetRect.js +1 -1
- package/lib/api/composition/facetRect.js.map +1 -1
- package/lib/api/composition/geoPath.d.ts +2 -2
- package/lib/api/composition/geoPath.js +1 -1
- package/lib/api/composition/geoPath.js.map +1 -1
- package/lib/api/composition/geoView.d.ts +2 -2
- package/lib/api/composition/geoView.js +1 -1
- package/lib/api/composition/geoView.js.map +1 -1
- package/lib/api/composition/index.d.ts +2 -2
- package/lib/api/composition/index.js +2 -2
- package/lib/api/composition/index.js.map +1 -1
- package/lib/api/composition/repeatMatrix.d.ts +2 -2
- package/lib/api/composition/repeatMatrix.js +1 -1
- package/lib/api/composition/repeatMatrix.js.map +1 -1
- package/lib/api/composition/spaceFlex.d.ts +2 -2
- package/lib/api/composition/spaceFlex.js +1 -1
- package/lib/api/composition/spaceFlex.js.map +1 -1
- package/lib/api/composition/spaceLayer.d.ts +2 -2
- package/lib/api/composition/spaceLayer.js +1 -1
- package/lib/api/composition/spaceLayer.js.map +1 -1
- package/lib/api/composition/timingKeyframe.d.ts +2 -2
- package/lib/api/composition/timingKeyframe.js +1 -1
- package/lib/api/composition/timingKeyframe.js.map +1 -1
- package/lib/api/composition/view.d.ts +2 -2
- package/lib/api/composition/view.js +1 -1
- package/lib/api/composition/view.js.map +1 -1
- package/lib/api/index.d.ts +2 -0
- package/lib/api/index.js +5 -1
- package/lib/api/index.js.map +1 -1
- package/lib/api/mark/base.d.ts +1 -1
- package/lib/api/mark/base.js +9 -9
- package/lib/api/mark/base.js.map +1 -1
- package/lib/api/mark/index.d.ts +1 -0
- package/lib/api/mark/index.js +3 -1
- package/lib/api/mark/index.js.map +1 -1
- package/lib/api/mark/mark.d.ts +27 -27
- package/lib/api/mark/mark.js +27 -26
- package/lib/api/mark/mark.js.map +1 -1
- package/lib/api/mark/types.d.ts +1 -0
- package/lib/api/node.d.ts +1 -1
- package/lib/api/node.js +1 -1
- package/lib/api/node.js.map +1 -1
- package/lib/api/props.d.ts +1 -1
- package/lib/api/props.js +20 -0
- package/lib/api/props.js.map +1 -1
- package/lib/composition/timingKeyframe.js +13 -7
- package/lib/composition/timingKeyframe.js.map +1 -1
- package/lib/composition/view.js +2 -6
- package/lib/composition/view.js.map +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.js +3 -1
- package/lib/index.js.map +1 -1
- package/lib/interaction/builtin/tooltip.d.ts +10 -2
- package/lib/interaction/index.d.ts +1 -0
- package/lib/interaction/index.js +3 -1
- package/lib/interaction/index.js.map +1 -1
- package/lib/interaction/native/event.d.ts +1 -0
- package/lib/interaction/native/event.js +46 -0
- package/lib/interaction/native/event.js.map +1 -0
- package/lib/interaction/native/tooltip.d.ts +2 -3
- package/lib/interaction/native/tooltip.js +76 -74
- package/lib/interaction/native/tooltip.js.map +1 -1
- package/lib/mark/area.js +1 -0
- package/lib/mark/area.js.map +1 -1
- package/lib/mark/box.js +1 -0
- package/lib/mark/box.js.map +1 -1
- package/lib/mark/boxplot.js +1 -3
- package/lib/mark/boxplot.js.map +1 -1
- package/lib/mark/cell.js +1 -0
- package/lib/mark/cell.js.map +1 -1
- package/lib/mark/connector.js +1 -0
- package/lib/mark/connector.js.map +1 -1
- package/lib/mark/forceGraph.js +1 -1
- package/lib/mark/forceGraph.js.map +1 -1
- package/lib/mark/image.js +1 -0
- package/lib/mark/image.js.map +1 -1
- package/lib/mark/interval.js +1 -0
- package/lib/mark/interval.js.map +1 -1
- package/lib/mark/line.js +1 -0
- package/lib/mark/line.js.map +1 -1
- package/lib/mark/lineX.js +1 -0
- package/lib/mark/lineX.js.map +1 -1
- package/lib/mark/lineY.js +1 -0
- package/lib/mark/lineY.js.map +1 -1
- package/lib/mark/link.js +1 -0
- package/lib/mark/link.js.map +1 -1
- package/lib/mark/pack.js +1 -1
- package/lib/mark/pack.js.map +1 -1
- package/lib/mark/path.js +1 -0
- package/lib/mark/path.js.map +1 -1
- package/lib/mark/point.js +1 -0
- package/lib/mark/point.js.map +1 -1
- package/lib/mark/polygon.js +1 -0
- package/lib/mark/polygon.js.map +1 -1
- package/lib/mark/range.js +1 -0
- package/lib/mark/range.js.map +1 -1
- package/lib/mark/rangeX.js +1 -0
- package/lib/mark/rangeX.js.map +1 -1
- package/lib/mark/rangeY.js +1 -0
- package/lib/mark/rangeY.js.map +1 -1
- package/lib/mark/rect.js +1 -0
- package/lib/mark/rect.js.map +1 -1
- package/lib/mark/sankey.js +1 -1
- package/lib/mark/sankey.js.map +1 -1
- package/lib/mark/shape.js +1 -0
- package/lib/mark/shape.js.map +1 -1
- package/lib/mark/text.js +1 -0
- package/lib/mark/text.js.map +1 -1
- package/lib/mark/tree.js +1 -1
- package/lib/mark/tree.js.map +1 -1
- package/lib/mark/treemap.js +1 -1
- package/lib/mark/treemap.js.map +1 -1
- package/lib/mark/utils.js +1 -5
- package/lib/mark/utils.js.map +1 -1
- package/lib/mark/vector.js +1 -0
- package/lib/mark/vector.js.map +1 -1
- package/lib/mark/wordCloud.js +1 -1
- package/lib/mark/wordCloud.js.map +1 -1
- package/lib/runtime/mark.js +11 -6
- package/lib/runtime/mark.js.map +1 -1
- package/lib/runtime/plot.js +81 -39
- package/lib/runtime/plot.js.map +1 -1
- package/lib/runtime/scale.js +2 -0
- package/lib/runtime/scale.js.map +1 -1
- package/lib/runtime/transform.d.ts +5 -0
- package/lib/runtime/transform.js +65 -6
- package/lib/runtime/transform.js.map +1 -1
- package/lib/runtime/types/common.d.ts +1 -0
- package/lib/runtime/types/component.d.ts +2 -1
- package/lib/runtime/types/mark.d.ts +3 -3
- package/lib/runtime/types/options.d.ts +8 -1
- package/lib/scale/constant.d.ts +4 -0
- package/lib/scale/constant.js +10 -0
- package/lib/scale/constant.js.map +1 -0
- package/lib/scale/index.d.ts +2 -0
- package/lib/scale/index.js +3 -1
- package/lib/scale/index.js.map +1 -1
- package/lib/shape/interval/color.js +6 -4
- package/lib/shape/interval/color.js.map +1 -1
- package/lib/spec/geometry.d.ts +33 -17
- package/lib/spec/interaction.d.ts +6 -1
- package/lib/spec/scale.d.ts +4 -3
- package/lib/stdlib/index.js +1 -1
- package/lib/stdlib/index.js.map +1 -1
- package/lib/transform/groupN.js +1 -1
- package/lib/transform/groupN.js.map +1 -1
- package/lib/transform/maybeTitle.js +12 -2
- package/lib/transform/maybeTitle.js.map +1 -1
- package/lib/transform/maybeTooltip.js +20 -20
- package/lib/transform/maybeTooltip.js.map +1 -1
- package/lib/transform/maybeZeroX.js +1 -1
- package/lib/transform/maybeZeroX.js.map +1 -1
- package/lib/transform/maybeZeroY.js +1 -1
- package/lib/transform/maybeZeroY.js.map +1 -1
- package/lib/transform/maybeZeroY1.js +1 -1
- package/lib/transform/maybeZeroY1.js.map +1 -1
- package/lib/transform/utils/helper.d.ts +12 -0
- package/lib/transform/utils/helper.js +11 -1
- package/lib/transform/utils/helper.js.map +1 -1
- package/lib/utils/helper.js +4 -1
- package/lib/utils/helper.js.map +1 -1
- package/package.json +4 -4
- package/src/api/chart.ts +2 -2
- package/src/api/composition/base.ts +5 -7
- package/src/api/composition/facetCircle.ts +2 -2
- package/src/api/composition/facetRect.ts +2 -2
- package/src/api/composition/geoPath.ts +2 -2
- package/src/api/composition/geoView.ts +2 -2
- package/src/api/composition/index.ts +2 -2
- package/src/api/composition/repeatMatrix.ts +2 -2
- package/src/api/composition/spaceFlex.ts +2 -2
- package/src/api/composition/spaceLayer.ts +2 -2
- package/src/api/composition/timingKeyframe.ts +2 -2
- package/src/api/composition/view.ts +2 -2
- package/src/api/index.ts +2 -0
- package/src/api/mark/base.ts +7 -7
- package/src/api/mark/index.ts +2 -0
- package/src/api/mark/mark.ts +28 -27
- package/src/api/mark/types.ts +1 -0
- package/src/api/node.ts +1 -1
- package/src/api/props.ts +22 -1
- package/src/composition/timingKeyframe.ts +13 -7
- package/src/composition/view.ts +1 -9
- package/src/index.ts +1 -1
- package/src/interaction/index.ts +1 -0
- package/src/interaction/native/event.ts +44 -0
- package/src/interaction/native/tooltip.ts +78 -95
- package/src/mark/area.ts +1 -0
- package/src/mark/box.ts +1 -0
- package/src/mark/boxplot.ts +1 -3
- package/src/mark/cell.ts +1 -0
- package/src/mark/connector.ts +1 -0
- package/src/mark/forceGraph.ts +1 -1
- package/src/mark/image.ts +1 -0
- package/src/mark/interval.ts +1 -0
- package/src/mark/line.ts +1 -0
- package/src/mark/lineX.ts +1 -0
- package/src/mark/lineY.ts +1 -0
- package/src/mark/link.ts +1 -0
- package/src/mark/pack.ts +1 -1
- package/src/mark/path.ts +1 -0
- package/src/mark/point.ts +1 -0
- package/src/mark/polygon.ts +1 -0
- package/src/mark/range.ts +1 -0
- package/src/mark/rangeX.ts +1 -0
- package/src/mark/rangeY.ts +1 -0
- package/src/mark/rect.ts +1 -0
- package/src/mark/sankey.ts +1 -1
- package/src/mark/shape.ts +1 -0
- package/src/mark/text.ts +1 -0
- package/src/mark/tree.ts +1 -1
- package/src/mark/treemap.ts +1 -1
- package/src/mark/utils.ts +1 -5
- package/src/mark/vector.ts +1 -0
- package/src/mark/wordCloud.ts +1 -1
- package/src/runtime/mark.ts +13 -5
- package/src/runtime/plot.ts +117 -50
- package/src/runtime/scale.ts +2 -0
- package/src/runtime/transform.ts +72 -6
- package/src/runtime/types/common.ts +1 -0
- package/src/runtime/types/component.ts +2 -0
- package/src/runtime/types/mark.ts +3 -3
- package/src/runtime/types/options.ts +8 -1
- package/src/scale/constant.ts +11 -0
- package/src/scale/index.ts +2 -0
- package/src/shape/interval/color.ts +11 -7
- package/src/spec/geometry.ts +38 -30
- package/src/spec/interaction.ts +5 -1
- package/src/spec/scale.ts +6 -1
- package/src/stdlib/index.ts +4 -0
- package/src/transform/groupN.ts +2 -2
- package/src/transform/maybeTitle.ts +11 -3
- package/src/transform/maybeTooltip.ts +17 -21
- package/src/transform/maybeZeroX.ts +2 -2
- package/src/transform/maybeZeroY.ts +2 -2
- package/src/transform/maybeZeroY1.ts +2 -2
- package/src/transform/utils/helper.ts +10 -0
- package/src/utils/helper.ts +6 -1
|
@@ -2,7 +2,7 @@ import { DisplayObject, IElement, Line } from '@antv/g';
|
|
|
2
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 { Identity } from '@antv/scale';
|
|
5
|
+
import { Constant, Identity } from '@antv/scale';
|
|
6
6
|
import { defined, subObject, isStrictObject } from '../../utils/helper';
|
|
7
7
|
import {
|
|
8
8
|
selectG2Elements,
|
|
@@ -55,7 +55,7 @@ function createTooltip(root, x0, y0) {
|
|
|
55
55
|
return tooltipElement;
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
function showTooltip(root, data, x, y) {
|
|
58
|
+
function showTooltip(root, data, x, y, render, event) {
|
|
59
59
|
const { tooltipElement = createTooltip(root, x, y) } = root;
|
|
60
60
|
const { items, title } = data;
|
|
61
61
|
tooltipElement.show();
|
|
@@ -63,6 +63,9 @@ function showTooltip(root, data, x, y) {
|
|
|
63
63
|
tooltipElement.update({
|
|
64
64
|
items,
|
|
65
65
|
title,
|
|
66
|
+
...(render !== undefined && {
|
|
67
|
+
customContent: render(event, { items, title }),
|
|
68
|
+
}),
|
|
66
69
|
});
|
|
67
70
|
root.tooltipElement = tooltipElement;
|
|
68
71
|
}
|
|
@@ -80,39 +83,16 @@ function destroyTooltip(root) {
|
|
|
80
83
|
}
|
|
81
84
|
}
|
|
82
85
|
|
|
83
|
-
function
|
|
84
|
-
return Object.fromEntries(
|
|
85
|
-
Object.entries(obj).filter(([, value]) => defined(value)),
|
|
86
|
-
);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
function singleItem(element, item, scale) {
|
|
86
|
+
function singleItem(element) {
|
|
90
87
|
const { __data__: datum } = element;
|
|
91
|
-
const { title,
|
|
92
|
-
const
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
const { field: f, title = f } = scale[key].getOptions();
|
|
97
|
-
const {
|
|
98
|
-
field = undefined,
|
|
99
|
-
color = defaultColor,
|
|
100
|
-
name = field || title,
|
|
101
|
-
value,
|
|
102
|
-
...rest
|
|
103
|
-
} = normalizeTooltip(d);
|
|
104
|
-
return {
|
|
105
|
-
...rest,
|
|
106
|
-
color,
|
|
107
|
-
name,
|
|
108
|
-
value,
|
|
109
|
-
...filterDefined(item({ channel: key, value })),
|
|
110
|
-
};
|
|
111
|
-
})
|
|
112
|
-
.filter(({ value }) => value !== undefined);
|
|
88
|
+
const { title, items = [] } = datum;
|
|
89
|
+
const newItems = items.map(({ color = itemColorOf(element), ...item }) => ({
|
|
90
|
+
...item,
|
|
91
|
+
color,
|
|
92
|
+
}));
|
|
113
93
|
return {
|
|
114
94
|
...(title && { title }),
|
|
115
|
-
items,
|
|
95
|
+
items: newItems,
|
|
116
96
|
};
|
|
117
97
|
}
|
|
118
98
|
|
|
@@ -120,7 +100,12 @@ function groupNameOf(scale, datum) {
|
|
|
120
100
|
const { color: scaleColor, series: scaleSeries } = scale;
|
|
121
101
|
const { color, series } = datum;
|
|
122
102
|
const invertAble = (scale) => {
|
|
123
|
-
return
|
|
103
|
+
return (
|
|
104
|
+
scale &&
|
|
105
|
+
scale.invert &&
|
|
106
|
+
!(scale instanceof Identity) &&
|
|
107
|
+
!(scale instanceof Constant)
|
|
108
|
+
);
|
|
124
109
|
};
|
|
125
110
|
if (invertAble(scaleColor)) return scaleColor.invert(color);
|
|
126
111
|
if (invertAble(scaleSeries)) return scaleSeries.invert(series);
|
|
@@ -136,7 +121,11 @@ function itemColorOf(element) {
|
|
|
136
121
|
}
|
|
137
122
|
|
|
138
123
|
function normalizeTooltip(d) {
|
|
139
|
-
return isStrictObject(d)
|
|
124
|
+
return isStrictObject(d)
|
|
125
|
+
? d
|
|
126
|
+
: d === null || d === undefined
|
|
127
|
+
? { value: d }
|
|
128
|
+
: { value: `${d}` };
|
|
140
129
|
}
|
|
141
130
|
|
|
142
131
|
function uniqueTitles(titles) {
|
|
@@ -148,39 +137,22 @@ function uniqueTitles(titles) {
|
|
|
148
137
|
|
|
149
138
|
function groupItems(
|
|
150
139
|
elements,
|
|
151
|
-
item,
|
|
152
140
|
scale,
|
|
153
141
|
data = elements.map((d) => d['__data__']),
|
|
154
142
|
) {
|
|
155
143
|
const T = uniqueTitles(data.map((d) => d.title)).filter(defined);
|
|
156
|
-
const
|
|
144
|
+
const newItems = data.flatMap((datum, i) => {
|
|
157
145
|
const element = elements[i];
|
|
158
|
-
const {
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
const {
|
|
165
|
-
field = undefined,
|
|
166
|
-
color = defaultColor,
|
|
167
|
-
name = groupNameOf(scale, datum) || field || title,
|
|
168
|
-
value,
|
|
169
|
-
...rest
|
|
170
|
-
} = normalizeTooltip(d);
|
|
171
|
-
return {
|
|
172
|
-
...rest,
|
|
173
|
-
name,
|
|
174
|
-
color,
|
|
175
|
-
value,
|
|
176
|
-
...filterDefined(item({ channel: key, value })),
|
|
177
|
-
};
|
|
178
|
-
})
|
|
179
|
-
.filter(({ value }) => value !== undefined);
|
|
146
|
+
const { items = [], title } = datum;
|
|
147
|
+
return items.map(({ color = itemColorOf(element), name, ...item }) => ({
|
|
148
|
+
...item,
|
|
149
|
+
color,
|
|
150
|
+
name: groupNameOf(scale, datum) || name || title,
|
|
151
|
+
}));
|
|
180
152
|
});
|
|
181
153
|
return {
|
|
182
154
|
...(T.length > 0 && { title: T.join(',') }),
|
|
183
|
-
items,
|
|
155
|
+
items: newItems,
|
|
184
156
|
};
|
|
185
157
|
}
|
|
186
158
|
|
|
@@ -256,6 +228,7 @@ export function seriesTooltip(
|
|
|
256
228
|
coordinate,
|
|
257
229
|
crosshairs,
|
|
258
230
|
item,
|
|
231
|
+
render,
|
|
259
232
|
startX = 0,
|
|
260
233
|
startY = 0,
|
|
261
234
|
...rest
|
|
@@ -274,6 +247,12 @@ export function seriesTooltip(
|
|
|
274
247
|
else itemElements.push(element);
|
|
275
248
|
}
|
|
276
249
|
|
|
250
|
+
// Sorted elements from top to bottom visually.
|
|
251
|
+
seriesElements.sort((a, b) => {
|
|
252
|
+
const minY = (d) => d.getBounds().min[1];
|
|
253
|
+
return minY(a) - minY(b);
|
|
254
|
+
});
|
|
255
|
+
|
|
277
256
|
// Get sortedIndex and X for each series elements
|
|
278
257
|
const elementSortedX = new Map(
|
|
279
258
|
seriesElements.map((element) => {
|
|
@@ -301,32 +280,32 @@ export function seriesTooltip(
|
|
|
301
280
|
|
|
302
281
|
const indexByFocus = (focus, I, X) => {
|
|
303
282
|
const [normalizedX] = coordinate.invert(focus);
|
|
283
|
+
const finalX = normalizedX - offsetX;
|
|
284
|
+
const [minX, maxX] = sort([X[0], X[X.length - 1]]);
|
|
285
|
+
// Skip x out of range.
|
|
286
|
+
if (finalX < minX || finalX > maxX) return null;
|
|
304
287
|
const search = bisector((i) => X[+i]).center;
|
|
305
|
-
const i = search(I,
|
|
288
|
+
const i = search(I, finalX);
|
|
306
289
|
return I[i];
|
|
307
290
|
};
|
|
308
291
|
|
|
309
|
-
const
|
|
310
|
-
const
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
let right = center;
|
|
320
|
-
while (left - 1 > 0 && X[I[left - 1]] == X[I[center]]) left--;
|
|
321
|
-
while (right + 1 < len && X[I[right + 1]] === X[I[center]]) right++;
|
|
322
|
-
return range(left, right + 1).map((i) => I[i]);
|
|
292
|
+
const elementsByFocus = (focus, elements) => {
|
|
293
|
+
const x = focus[0];
|
|
294
|
+
const extent = (d) => {
|
|
295
|
+
const { min, max } = d.getLocalBounds();
|
|
296
|
+
return sort([min[0], max[0]]);
|
|
297
|
+
};
|
|
298
|
+
return elements.filter((element) => {
|
|
299
|
+
const [min, max] = extent(element);
|
|
300
|
+
return x >= min && x <= max;
|
|
301
|
+
});
|
|
323
302
|
};
|
|
324
303
|
|
|
325
304
|
const seriesData = (element, index) => {
|
|
326
305
|
const { __data__: data } = element;
|
|
327
306
|
return Object.fromEntries(
|
|
328
307
|
Object.entries(data)
|
|
329
|
-
.filter(([key]) => key.startsWith('series'))
|
|
308
|
+
.filter(([key]) => key.startsWith('series') && key !== 'series')
|
|
330
309
|
.map(([key, V]) => {
|
|
331
310
|
const d = V[index];
|
|
332
311
|
return [lowerFirst(key.replace('series', '')), d];
|
|
@@ -344,32 +323,38 @@ export function seriesTooltip(
|
|
|
344
323
|
const focus = [mouse[0] - startX, mouse[1] - startY];
|
|
345
324
|
if (!focus) return;
|
|
346
325
|
// Get selected item element.
|
|
347
|
-
const
|
|
348
|
-
const selectedItems = selectedItemIndices.map((i) => itemElements[i]);
|
|
326
|
+
const selectedItems = elementsByFocus(focus, itemElements);
|
|
349
327
|
|
|
350
328
|
// Get selected data item from both series element and item element.
|
|
351
|
-
const
|
|
329
|
+
const selectedSeriesElements = [];
|
|
330
|
+
const selectedSeriesData = [];
|
|
331
|
+
for (const element of seriesElements) {
|
|
352
332
|
const [sortedIndex, X] = elementSortedX.get(element);
|
|
353
333
|
const index = indexByFocus(focus, sortedIndex, X);
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
334
|
+
if (index !== null) {
|
|
335
|
+
selectedSeriesElements.push(element);
|
|
336
|
+
const d = seriesData(element, index);
|
|
337
|
+
const { x, y } = d;
|
|
338
|
+
const p = coordinate.map([x + offsetX, y]);
|
|
339
|
+
selectedSeriesData.push([d, p] as const);
|
|
340
|
+
}
|
|
341
|
+
}
|
|
358
342
|
const selectedData = [
|
|
359
343
|
...selectedSeriesData.map((d) => d[0]),
|
|
360
344
|
...selectedItems.map((d) => d.__data__),
|
|
361
345
|
];
|
|
362
346
|
|
|
363
347
|
// Get the displayed tooltip data.
|
|
364
|
-
const selectedElements = [...
|
|
365
|
-
const tooltipData = groupItems(
|
|
366
|
-
selectedElements,
|
|
367
|
-
item,
|
|
368
|
-
scale,
|
|
369
|
-
selectedData,
|
|
370
|
-
);
|
|
348
|
+
const selectedElements = [...selectedSeriesElements, ...selectedItems];
|
|
349
|
+
const tooltipData = groupItems(selectedElements, scale, selectedData);
|
|
371
350
|
|
|
372
|
-
|
|
351
|
+
// Hide tooltip with no selected tooltip.
|
|
352
|
+
if (selectedElements.length === 0) {
|
|
353
|
+
hide();
|
|
354
|
+
return;
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
showTooltip(root, tooltipData, mouse[0] + x, mouse[1] + y, render, event);
|
|
373
358
|
if (crosshairs) {
|
|
374
359
|
const points = selectedSeriesData.map((d) => d[1]);
|
|
375
360
|
updateRuleY(root, points, { ...ruleStyle, height, startX, startY });
|
|
@@ -405,11 +390,11 @@ export function tooltip(
|
|
|
405
390
|
{
|
|
406
391
|
elements: elementsof,
|
|
407
392
|
scale,
|
|
393
|
+
render,
|
|
408
394
|
wait = 50,
|
|
409
395
|
leading = true,
|
|
410
396
|
trailing = false,
|
|
411
397
|
groupKey = (d) => d, // group elements by specified key
|
|
412
|
-
item,
|
|
413
398
|
}: Record<string, any>,
|
|
414
399
|
) {
|
|
415
400
|
const elements = elementsof(root);
|
|
@@ -423,11 +408,9 @@ export function tooltip(
|
|
|
423
408
|
const k = groupKey(element);
|
|
424
409
|
const group = keyGroup.get(k);
|
|
425
410
|
const data =
|
|
426
|
-
group.length === 1
|
|
427
|
-
? singleItem(group[0], item, scale)
|
|
428
|
-
: groupItems(group, item, scale);
|
|
411
|
+
group.length === 1 ? singleItem(group[0]) : groupItems(group, scale);
|
|
429
412
|
const { offsetX, offsetY } = event;
|
|
430
|
-
showTooltip(root, data, offsetX, offsetY);
|
|
413
|
+
showTooltip(root, data, offsetX, offsetY, render, event);
|
|
431
414
|
},
|
|
432
415
|
wait,
|
|
433
416
|
{ leading, trailing },
|
package/src/mark/area.ts
CHANGED
package/src/mark/box.ts
CHANGED
package/src/mark/boxplot.ts
CHANGED
package/src/mark/cell.ts
CHANGED
package/src/mark/connector.ts
CHANGED
package/src/mark/forceGraph.ts
CHANGED
package/src/mark/image.ts
CHANGED
package/src/mark/interval.ts
CHANGED
package/src/mark/line.ts
CHANGED
package/src/mark/lineX.ts
CHANGED
package/src/mark/lineY.ts
CHANGED
package/src/mark/link.ts
CHANGED
package/src/mark/pack.ts
CHANGED
package/src/mark/path.ts
CHANGED
package/src/mark/point.ts
CHANGED
package/src/mark/polygon.ts
CHANGED
package/src/mark/range.ts
CHANGED
package/src/mark/rangeX.ts
CHANGED
package/src/mark/rangeY.ts
CHANGED
package/src/mark/rect.ts
CHANGED
package/src/mark/sankey.ts
CHANGED
package/src/mark/shape.ts
CHANGED
package/src/mark/text.ts
CHANGED
package/src/mark/tree.ts
CHANGED
package/src/mark/treemap.ts
CHANGED
package/src/mark/utils.ts
CHANGED
|
@@ -26,11 +26,7 @@ export function baseChannels(options: ChannelOptions = {}): Channel[] {
|
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
export function baseGeometryChannels(options: ChannelOptions = {}): Channel[] {
|
|
29
|
-
return [
|
|
30
|
-
...baseChannels(options),
|
|
31
|
-
{ name: 'title', scale: 'identity' },
|
|
32
|
-
{ name: 'tooltip', scale: 'identity', independent: true },
|
|
33
|
-
];
|
|
29
|
+
return [...baseChannels(options), { name: 'title', scale: 'identity' }];
|
|
34
30
|
}
|
|
35
31
|
|
|
36
32
|
export function tooltip2d() {
|
package/src/mark/vector.ts
CHANGED
package/src/mark/wordCloud.ts
CHANGED
package/src/runtime/mark.ts
CHANGED
|
@@ -26,6 +26,8 @@ import {
|
|
|
26
26
|
maybeVisualChannel,
|
|
27
27
|
addGuideToScale,
|
|
28
28
|
maybeNonAnimate,
|
|
29
|
+
normalizeTooltip,
|
|
30
|
+
extractTooltip,
|
|
29
31
|
} from './transform';
|
|
30
32
|
|
|
31
33
|
export async function initializeMark(
|
|
@@ -41,7 +43,7 @@ export async function initializeMark(
|
|
|
41
43
|
context,
|
|
42
44
|
);
|
|
43
45
|
|
|
44
|
-
const { encode, scale, data } = transformedMark;
|
|
46
|
+
const { encode, scale, data, tooltip } = transformedMark;
|
|
45
47
|
|
|
46
48
|
// Skip mark with non-tabular data. Do not skip empty
|
|
47
49
|
// data, they are useful for facet to display axes.
|
|
@@ -82,30 +84,34 @@ export async function initializeMark(
|
|
|
82
84
|
);
|
|
83
85
|
return valuesArray.map(([channel, values], i) => {
|
|
84
86
|
const visual = values.some((d) => d.visual);
|
|
87
|
+
const constant = values.some((d) => d.constant);
|
|
85
88
|
const {
|
|
86
89
|
independent = false,
|
|
87
90
|
// Use channel name as default scale key.
|
|
88
91
|
key = scaleKey || channel,
|
|
89
92
|
// Visual channel use identity scale.
|
|
90
|
-
type = visual ? 'identity' : scaleType,
|
|
93
|
+
type = constant ? 'constant' : visual ? 'identity' : scaleType,
|
|
91
94
|
...scaleOptions
|
|
92
95
|
} = scale[channel] || {};
|
|
96
|
+
// For constant scale, infer range from data.
|
|
97
|
+
const isConstant = type === 'constant';
|
|
98
|
+
const finalRange = isConstant ? undefined : range;
|
|
93
99
|
return {
|
|
94
100
|
name: channel,
|
|
95
101
|
values,
|
|
96
102
|
// Generate a unique key for independent channel,
|
|
97
103
|
// which will not group with any other channels.
|
|
98
|
-
scaleKey: independent ? Symbol('independent') : key,
|
|
104
|
+
scaleKey: independent || isConstant ? Symbol('independent') : key,
|
|
99
105
|
scale: {
|
|
100
106
|
type,
|
|
101
|
-
range,
|
|
107
|
+
range: finalRange,
|
|
102
108
|
...scaleOptions,
|
|
103
109
|
},
|
|
104
110
|
};
|
|
105
111
|
});
|
|
106
112
|
});
|
|
107
113
|
|
|
108
|
-
return [transformedMark, { ...partialProps, index: I, channels }];
|
|
114
|
+
return [transformedMark, { ...partialProps, index: I, channels, tooltip }];
|
|
109
115
|
}
|
|
110
116
|
|
|
111
117
|
export function createColumnOf(library: G2Library): ColumnOf {
|
|
@@ -148,9 +154,11 @@ async function applyMarkTransform(
|
|
|
148
154
|
maybeArrayField,
|
|
149
155
|
maybeNonAnimate,
|
|
150
156
|
addGuideToScale,
|
|
157
|
+
normalizeTooltip,
|
|
151
158
|
...preInference.map(useTransform),
|
|
152
159
|
...transform.map(useTransform),
|
|
153
160
|
...postInference.map(useTransform),
|
|
161
|
+
extractTooltip,
|
|
154
162
|
];
|
|
155
163
|
let index = [];
|
|
156
164
|
let transformedMark = mark;
|