@antv/g2 5.0.18 → 5.0.20
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 +3 -3
- package/esm/api/chart.d.ts +175 -85
- package/esm/api/chart.js +3 -259
- package/esm/api/chart.js.map +1 -1
- package/esm/api/composition.d.ts +37 -0
- package/esm/api/{composition/base.js → composition.js} +17 -5
- package/esm/api/composition.js.map +1 -0
- package/esm/api/define.d.ts +14 -0
- package/esm/api/define.js +92 -0
- package/esm/api/define.js.map +1 -0
- package/esm/api/extend.d.ts +10 -0
- package/esm/api/extend.js +9 -0
- package/esm/api/extend.js.map +1 -0
- 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/library.d.ts +171 -1
- package/esm/api/library.js +2 -2
- package/esm/api/library.js.map +1 -1
- package/esm/api/mark.d.ts +29 -0
- package/esm/api/{mark/base.js → mark.js} +16 -4
- package/esm/api/mark.js.map +1 -0
- package/esm/api/node.d.ts +2 -2
- package/esm/api/node.js.map +1 -1
- package/esm/api/props.d.ts +170 -12
- package/esm/api/props.js +21 -102
- package/esm/api/props.js.map +1 -1
- package/esm/api/runtime.d.ts +66 -0
- package/esm/api/runtime.js +294 -0
- package/esm/api/runtime.js.map +1 -0
- package/esm/api/types.d.ts +60 -5
- package/esm/api/utils.d.ts +1 -1
- package/esm/api/utils.js +11 -13
- package/esm/api/utils.js.map +1 -1
- package/esm/component/axis.js +7 -4
- package/esm/component/axis.js.map +1 -1
- package/esm/component/legendCategory.js +4 -5
- package/esm/component/legendCategory.js.map +1 -1
- package/esm/composition/d3Projection.js.map +1 -0
- package/esm/composition/geoPath.js.map +1 -0
- package/esm/{geo → composition}/geoView.js +1 -1
- package/esm/composition/geoView.js.map +1 -0
- package/esm/composition/index.d.ts +2 -0
- package/esm/composition/index.js +2 -0
- package/esm/composition/index.js.map +1 -1
- package/esm/data/index.d.ts +2 -0
- package/esm/data/index.js +1 -0
- package/esm/data/index.js.map +1 -1
- package/esm/data/log.d.ts +7 -0
- package/esm/data/log.js +11 -0
- package/esm/data/log.js.map +1 -0
- package/esm/index.d.ts +4 -3
- package/esm/index.js +3 -2
- package/esm/index.js.map +1 -1
- package/esm/interaction/brushFilter.js +18 -16
- package/esm/interaction/brushFilter.js.map +1 -1
- package/esm/interaction/chartIndex.js +25 -22
- package/esm/interaction/chartIndex.js.map +1 -1
- package/esm/interaction/fisheye.js +17 -13
- package/esm/interaction/fisheye.js.map +1 -1
- package/esm/interaction/legendFilter.js +32 -26
- package/esm/interaction/legendFilter.js.map +1 -1
- package/esm/interaction/sliderFilter.js +8 -9
- package/esm/interaction/sliderFilter.js.map +1 -1
- package/esm/interaction/tooltip.d.ts +1 -1
- package/esm/interaction/tooltip.js +39 -4
- package/esm/interaction/tooltip.js.map +1 -1
- package/esm/label-transform/overlapDodgeY.js.map +1 -1
- package/esm/lib/core.d.ts +159 -0
- package/esm/lib/core.js +175 -0
- package/esm/lib/core.js.map +1 -0
- package/esm/lib/geo.d.ts +4 -0
- package/esm/lib/geo.js +9 -0
- package/esm/lib/geo.js.map +1 -0
- package/esm/lib/graph.d.ts +4 -0
- package/esm/lib/graph.js +8 -0
- package/esm/lib/graph.js.map +1 -0
- package/esm/lib/index.d.ts +6 -0
- package/esm/lib/index.js +7 -0
- package/esm/lib/index.js.map +1 -0
- package/esm/lib/lite.d.ts +64 -0
- package/esm/lib/lite.js +78 -0
- package/esm/lib/lite.js.map +1 -0
- package/esm/lib/plot.d.ts +11 -0
- package/esm/lib/plot.js +16 -0
- package/esm/lib/plot.js.map +1 -0
- package/esm/lib/std.d.ts +171 -0
- package/esm/lib/std.js +8 -0
- package/esm/lib/std.js.map +1 -0
- package/esm/mark/area.js +14 -5
- package/esm/mark/area.js.map +1 -1
- package/esm/mark/box.js +9 -2
- package/esm/mark/box.js.map +1 -1
- package/esm/mark/cell.js +11 -5
- package/esm/mark/cell.js.map +1 -1
- package/esm/mark/connector.js +6 -2
- package/esm/mark/connector.js.map +1 -1
- package/esm/mark/density.js +10 -7
- package/esm/mark/density.js.map +1 -1
- package/esm/mark/forceGraph.js +0 -3
- package/esm/mark/forceGraph.js.map +1 -1
- package/esm/mark/heatmap.js +9 -4
- package/esm/mark/heatmap.js.map +1 -1
- package/esm/mark/image.js +9 -4
- package/esm/mark/image.js.map +1 -1
- package/esm/mark/interval.js +13 -7
- package/esm/mark/interval.js.map +1 -1
- package/esm/mark/line.js +15 -4
- package/esm/mark/line.js.map +1 -1
- package/esm/mark/lineX.js +8 -3
- package/esm/mark/lineX.js.map +1 -1
- package/esm/mark/lineY.js +8 -3
- package/esm/mark/lineY.js.map +1 -1
- package/esm/mark/link.js +12 -4
- package/esm/mark/link.js.map +1 -1
- package/esm/mark/path.js +7 -2
- package/esm/mark/path.js.map +1 -1
- package/esm/mark/point.js +28 -29
- package/esm/mark/point.js.map +1 -1
- package/esm/mark/polygon.js +7 -2
- package/esm/mark/polygon.js.map +1 -1
- package/esm/mark/range.js +4 -2
- package/esm/mark/range.js.map +1 -1
- package/esm/mark/rangeX.js +6 -2
- package/esm/mark/rangeX.js.map +1 -1
- package/esm/mark/rangeY.js +6 -2
- package/esm/mark/rangeY.js.map +1 -1
- package/esm/mark/rect.js +9 -3
- package/esm/mark/rect.js.map +1 -1
- package/esm/mark/shape.js +9 -3
- package/esm/mark/shape.js.map +1 -1
- package/esm/mark/text.js +10 -4
- package/esm/mark/text.js.map +1 -1
- package/esm/mark/treemap.js.map +1 -1
- package/esm/mark/utils.d.ts +11 -8
- package/esm/mark/utils.js +8 -7
- package/esm/mark/utils.js.map +1 -1
- package/esm/mark/vector.js +6 -2
- package/esm/mark/vector.js.map +1 -1
- package/esm/runtime/index.d.ts +1 -1
- package/esm/runtime/index.js +1 -1
- package/esm/runtime/index.js.map +1 -1
- package/esm/runtime/plot.js +32 -13
- package/esm/runtime/plot.js.map +1 -1
- package/esm/runtime/render.js +3 -6
- package/esm/runtime/render.js.map +1 -1
- package/esm/runtime/types/component.d.ts +1 -1
- package/esm/runtime/types/mark.d.ts +4 -0
- package/esm/runtime/types/options.d.ts +4 -1
- package/esm/shape/index.d.ts +106 -101
- package/esm/shape/index.js +58 -53
- package/esm/shape/index.js.map +1 -1
- package/esm/shape/text/advance.js +3 -3
- package/esm/shape/text/advance.js.map +1 -1
- package/esm/spec/composition.d.ts +7 -0
- package/esm/spec/dataTransform.d.ts +3 -2
- package/esm/spec/index.d.ts +1 -0
- package/esm/spec/index.js.map +1 -1
- package/esm/spec/interaction.d.ts +4 -1
- package/esm/theme/academy.js +6 -6
- package/esm/theme/classic.js +6 -7
- package/esm/theme/classic.js.map +1 -1
- package/esm/theme/classicDark.js +6 -6
- package/esm/utils/coordinate.d.ts +2 -2
- package/esm/utils/scale.d.ts +1 -1
- package/esm/utils/scale.js +1 -1
- package/esm/utils/scale.js.map +1 -1
- package/lib/api/chart.d.ts +175 -85
- package/lib/api/chart.js +4 -263
- package/lib/api/chart.js.map +1 -1
- package/lib/api/composition.d.ts +37 -0
- package/lib/api/{composition/base.js → composition.js} +16 -5
- package/lib/api/composition.js.map +1 -0
- package/lib/api/define.d.ts +14 -0
- package/lib/api/define.js +97 -0
- package/lib/api/define.js.map +1 -0
- package/lib/api/extend.d.ts +10 -0
- package/lib/api/extend.js +13 -0
- package/lib/api/extend.js.map +1 -0
- 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/library.d.ts +171 -1
- package/lib/api/library.js +2 -2
- package/lib/api/library.js.map +1 -1
- package/lib/api/mark.d.ts +29 -0
- package/lib/api/{mark/base.js → mark.js} +15 -4
- package/lib/api/mark.js.map +1 -0
- package/lib/api/node.d.ts +2 -2
- package/lib/api/node.js.map +1 -1
- package/lib/api/props.d.ts +170 -12
- package/lib/api/props.js +22 -106
- package/lib/api/props.js.map +1 -1
- package/lib/api/runtime.d.ts +66 -0
- package/lib/api/runtime.js +301 -0
- package/lib/api/runtime.js.map +1 -0
- package/lib/api/types.d.ts +60 -5
- package/lib/api/utils.d.ts +1 -1
- package/lib/api/utils.js +14 -16
- package/lib/api/utils.js.map +1 -1
- package/lib/component/axis.js +7 -4
- package/lib/component/axis.js.map +1 -1
- package/lib/component/legendCategory.js +4 -5
- package/lib/component/legendCategory.js.map +1 -1
- package/lib/composition/d3Projection.js.map +1 -0
- package/lib/composition/geoPath.js.map +1 -0
- package/lib/{geo → composition}/geoView.js +1 -1
- package/lib/composition/geoView.js.map +1 -0
- package/lib/composition/index.d.ts +2 -0
- package/lib/composition/index.js +5 -1
- package/lib/composition/index.js.map +1 -1
- package/lib/data/index.d.ts +2 -0
- package/lib/data/index.js +3 -1
- package/lib/data/index.js.map +1 -1
- package/lib/data/log.d.ts +7 -0
- package/lib/data/log.js +15 -0
- package/lib/data/log.js.map +1 -0
- package/lib/index.d.ts +4 -3
- package/lib/index.js +8 -3
- package/lib/index.js.map +1 -1
- package/lib/interaction/brushFilter.js +18 -16
- package/lib/interaction/brushFilter.js.map +1 -1
- package/lib/interaction/chartIndex.js +25 -22
- package/lib/interaction/chartIndex.js.map +1 -1
- package/lib/interaction/fisheye.js +17 -13
- package/lib/interaction/fisheye.js.map +1 -1
- package/lib/interaction/legendFilter.js +32 -26
- package/lib/interaction/legendFilter.js.map +1 -1
- package/lib/interaction/sliderFilter.js +8 -9
- package/lib/interaction/sliderFilter.js.map +1 -1
- package/lib/interaction/tooltip.d.ts +1 -1
- package/lib/interaction/tooltip.js +38 -3
- package/lib/interaction/tooltip.js.map +1 -1
- package/lib/label-transform/overlapDodgeY.js.map +1 -1
- package/lib/lib/core.d.ts +159 -0
- package/lib/lib/core.js +179 -0
- package/lib/lib/core.js.map +1 -0
- package/lib/lib/geo.d.ts +4 -0
- package/lib/lib/geo.js +13 -0
- package/lib/lib/geo.js.map +1 -0
- package/lib/lib/graph.d.ts +4 -0
- package/lib/lib/graph.js +12 -0
- package/lib/lib/graph.js.map +1 -0
- package/lib/lib/index.d.ts +6 -0
- package/lib/lib/index.js +16 -0
- package/lib/lib/index.js.map +1 -0
- package/lib/lib/lite.d.ts +64 -0
- package/lib/lib/lite.js +82 -0
- package/lib/lib/lite.js.map +1 -0
- package/lib/lib/plot.d.ts +11 -0
- package/lib/lib/plot.js +20 -0
- package/lib/lib/plot.js.map +1 -0
- package/lib/lib/std.d.ts +171 -0
- package/lib/lib/std.js +12 -0
- package/lib/lib/std.js.map +1 -0
- package/lib/mark/area.js +14 -5
- package/lib/mark/area.js.map +1 -1
- package/lib/mark/box.js +9 -2
- package/lib/mark/box.js.map +1 -1
- package/lib/mark/cell.js +11 -5
- package/lib/mark/cell.js.map +1 -1
- package/lib/mark/connector.js +6 -2
- package/lib/mark/connector.js.map +1 -1
- package/lib/mark/density.js +10 -7
- package/lib/mark/density.js.map +1 -1
- package/lib/mark/forceGraph.js +0 -3
- package/lib/mark/forceGraph.js.map +1 -1
- package/lib/mark/heatmap.js +9 -4
- package/lib/mark/heatmap.js.map +1 -1
- package/lib/mark/image.js +9 -4
- package/lib/mark/image.js.map +1 -1
- package/lib/mark/interval.js +13 -7
- package/lib/mark/interval.js.map +1 -1
- package/lib/mark/line.js +15 -4
- package/lib/mark/line.js.map +1 -1
- package/lib/mark/lineX.js +8 -3
- package/lib/mark/lineX.js.map +1 -1
- package/lib/mark/lineY.js +8 -3
- package/lib/mark/lineY.js.map +1 -1
- package/lib/mark/link.js +12 -4
- package/lib/mark/link.js.map +1 -1
- package/lib/mark/path.js +7 -2
- package/lib/mark/path.js.map +1 -1
- package/lib/mark/point.js +28 -29
- package/lib/mark/point.js.map +1 -1
- package/lib/mark/polygon.js +7 -2
- package/lib/mark/polygon.js.map +1 -1
- package/lib/mark/range.js +4 -2
- package/lib/mark/range.js.map +1 -1
- package/lib/mark/rangeX.js +6 -2
- package/lib/mark/rangeX.js.map +1 -1
- package/lib/mark/rangeY.js +6 -2
- package/lib/mark/rangeY.js.map +1 -1
- package/lib/mark/rect.js +9 -3
- package/lib/mark/rect.js.map +1 -1
- package/lib/mark/shape.js +9 -3
- package/lib/mark/shape.js.map +1 -1
- package/lib/mark/text.js +10 -4
- package/lib/mark/text.js.map +1 -1
- package/lib/mark/treemap.js.map +1 -1
- package/lib/mark/utils.d.ts +11 -8
- package/lib/mark/utils.js +8 -7
- package/lib/mark/utils.js.map +1 -1
- package/lib/mark/vector.js +6 -2
- package/lib/mark/vector.js.map +1 -1
- package/lib/runtime/index.d.ts +1 -1
- package/lib/runtime/index.js +4 -4
- package/lib/runtime/index.js.map +1 -1
- package/lib/runtime/plot.js +32 -13
- package/lib/runtime/plot.js.map +1 -1
- package/lib/runtime/render.js +3 -6
- package/lib/runtime/render.js.map +1 -1
- package/lib/runtime/types/component.d.ts +1 -1
- package/lib/runtime/types/mark.d.ts +4 -0
- package/lib/runtime/types/options.d.ts +4 -1
- package/lib/shape/index.d.ts +106 -101
- package/lib/shape/index.js +71 -61
- package/lib/shape/index.js.map +1 -1
- package/lib/shape/text/advance.js +3 -3
- package/lib/shape/text/advance.js.map +1 -1
- package/lib/spec/composition.d.ts +7 -0
- package/lib/spec/dataTransform.d.ts +3 -2
- package/lib/spec/index.d.ts +1 -0
- package/lib/spec/index.js.map +1 -1
- package/lib/spec/interaction.d.ts +4 -1
- package/lib/theme/academy.js +6 -6
- package/lib/theme/classic.js +6 -7
- package/lib/theme/classic.js.map +1 -1
- package/lib/theme/classicDark.js +6 -6
- package/lib/utils/coordinate.d.ts +2 -2
- package/lib/utils/scale.d.ts +1 -1
- package/lib/utils/scale.js +1 -1
- package/lib/utils/scale.js.map +1 -1
- package/package.json +8 -7
- package/src/api/chart.ts +5 -341
- package/src/api/{composition/base.ts → composition.ts} +16 -8
- package/src/api/define.ts +128 -0
- package/src/api/extend.ts +36 -0
- package/src/api/index.ts +2 -0
- package/src/api/library.ts +2 -2
- package/src/api/{mark/base.ts → mark.ts} +10 -7
- package/src/api/node.ts +3 -3
- package/src/api/props.ts +30 -114
- package/src/api/runtime.ts +366 -0
- package/src/api/types.ts +95 -17
- package/src/api/utils.ts +28 -11
- package/src/component/axis.ts +10 -5
- package/src/component/legendCategory.ts +4 -6
- package/src/{geo → composition}/geoView.ts +1 -1
- package/src/composition/index.ts +2 -0
- package/src/data/index.ts +2 -0
- package/src/data/log.ts +16 -0
- package/src/index.ts +12 -3
- package/src/interaction/brushFilter.ts +31 -28
- package/src/interaction/chartIndex.ts +26 -23
- package/src/interaction/fisheye.ts +16 -12
- package/src/interaction/legendFilter.ts +45 -40
- package/src/interaction/sliderFilter.ts +15 -16
- package/src/interaction/tooltip.ts +47 -3
- package/src/label-transform/overlapDodgeY.ts +0 -1
- package/src/{stdlib/index.ts → lib/core.ts} +76 -258
- package/src/lib/geo.ts +9 -0
- package/src/lib/graph.ts +8 -0
- package/src/lib/index.ts +6 -0
- package/src/lib/lite.ts +127 -0
- package/src/lib/plot.ts +16 -0
- package/src/lib/std.ts +13 -0
- package/src/mark/area.ts +15 -6
- package/src/mark/box.ts +10 -2
- package/src/mark/cell.ts +12 -6
- package/src/mark/connector.ts +7 -3
- package/src/mark/density.ts +11 -8
- package/src/mark/forceGraph.ts +0 -3
- package/src/mark/heatmap.ts +10 -5
- package/src/mark/image.ts +10 -5
- package/src/mark/interval.ts +22 -10
- package/src/mark/line.ts +23 -5
- package/src/mark/lineX.ts +9 -4
- package/src/mark/lineY.ts +9 -4
- package/src/mark/link.ts +13 -5
- package/src/mark/path.ts +8 -3
- package/src/mark/point.ts +49 -30
- package/src/mark/polygon.ts +8 -3
- package/src/mark/range.ts +5 -3
- package/src/mark/rangeX.ts +7 -3
- package/src/mark/rangeY.ts +7 -3
- package/src/mark/rect.ts +10 -4
- package/src/mark/shape.ts +14 -3
- package/src/mark/text.ts +11 -5
- package/src/mark/treemap.ts +0 -1
- package/src/mark/utils.ts +9 -8
- package/src/mark/vector.ts +7 -3
- package/src/runtime/index.ts +1 -1
- package/src/runtime/plot.ts +41 -17
- package/src/runtime/render.ts +3 -6
- package/src/runtime/types/component.ts +1 -2
- package/src/runtime/types/mark.ts +4 -0
- package/src/runtime/types/options.ts +4 -1
- package/src/shape/index.ts +106 -110
- package/src/shape/text/advance.ts +1 -2
- package/src/spec/composition.ts +7 -0
- package/src/spec/dataTransform.ts +5 -0
- package/src/spec/index.ts +1 -0
- package/src/spec/interaction.ts +5 -1
- package/src/theme/academy.ts +6 -6
- package/src/theme/classic.ts +6 -7
- package/src/theme/classicDark.ts +6 -6
- package/src/utils/scale.ts +1 -1
- package/esm/api/composition/base.d.ts +0 -28
- package/esm/api/composition/base.js.map +0 -1
- package/esm/api/composition/facetCircle.d.ts +0 -17
- package/esm/api/composition/facetCircle.js +0 -27
- package/esm/api/composition/facetCircle.js.map +0 -1
- package/esm/api/composition/facetRect.d.ts +0 -17
- package/esm/api/composition/facetRect.js +0 -27
- package/esm/api/composition/facetRect.js.map +0 -1
- package/esm/api/composition/geoPath.d.ts +0 -20
- package/esm/api/composition/geoPath.js +0 -30
- package/esm/api/composition/geoPath.js.map +0 -1
- package/esm/api/composition/geoView.d.ts +0 -19
- package/esm/api/composition/geoView.js +0 -28
- package/esm/api/composition/geoView.js.map +0 -1
- package/esm/api/composition/index.d.ts +0 -33
- package/esm/api/composition/index.js +0 -32
- package/esm/api/composition/index.js.map +0 -1
- package/esm/api/composition/repeatMatrix.d.ts +0 -17
- package/esm/api/composition/repeatMatrix.js +0 -27
- package/esm/api/composition/repeatMatrix.js.map +0 -1
- package/esm/api/composition/spaceFlex.d.ts +0 -12
- package/esm/api/composition/spaceFlex.js +0 -19
- package/esm/api/composition/spaceFlex.js.map +0 -1
- package/esm/api/composition/spaceLayer.d.ts +0 -12
- package/esm/api/composition/spaceLayer.js +0 -19
- package/esm/api/composition/spaceLayer.js.map +0 -1
- package/esm/api/composition/timingKeyframe.d.ts +0 -11
- package/esm/api/composition/timingKeyframe.js +0 -19
- package/esm/api/composition/timingKeyframe.js.map +0 -1
- package/esm/api/composition/view.d.ts +0 -19
- package/esm/api/composition/view.js +0 -29
- package/esm/api/composition/view.js.map +0 -1
- package/esm/api/mark/base.d.ts +0 -22
- package/esm/api/mark/base.js.map +0 -1
- package/esm/api/mark/index.d.ts +0 -75
- package/esm/api/mark/index.js +0 -39
- package/esm/api/mark/index.js.map +0 -1
- package/esm/api/mark/mark.d.ts +0 -212
- package/esm/api/mark/mark.js +0 -339
- package/esm/api/mark/mark.js.map +0 -1
- package/esm/api/mark/types.d.ts +0 -26
- package/esm/api/mark/types.js +0 -2
- package/esm/api/mark/types.js.map +0 -1
- package/esm/geo/d3Projection.js.map +0 -1
- package/esm/geo/geoPath.js.map +0 -1
- package/esm/geo/geoView.js.map +0 -1
- package/esm/geo/index.d.ts +0 -9
- package/esm/geo/index.js +0 -8
- package/esm/geo/index.js.map +0 -1
- package/esm/stdlib/index.d.ts +0 -2
- package/esm/stdlib/index.js +0 -21
- package/esm/stdlib/index.js.map +0 -1
- package/lib/api/composition/base.d.ts +0 -28
- package/lib/api/composition/base.js.map +0 -1
- package/lib/api/composition/facetCircle.d.ts +0 -17
- package/lib/api/composition/facetCircle.js +0 -30
- package/lib/api/composition/facetCircle.js.map +0 -1
- package/lib/api/composition/facetRect.d.ts +0 -17
- package/lib/api/composition/facetRect.js +0 -30
- package/lib/api/composition/facetRect.js.map +0 -1
- package/lib/api/composition/geoPath.d.ts +0 -20
- package/lib/api/composition/geoPath.js +0 -33
- package/lib/api/composition/geoPath.js.map +0 -1
- package/lib/api/composition/geoView.d.ts +0 -19
- package/lib/api/composition/geoView.js +0 -31
- package/lib/api/composition/geoView.js.map +0 -1
- package/lib/api/composition/index.d.ts +0 -33
- package/lib/api/composition/index.js +0 -44
- package/lib/api/composition/index.js.map +0 -1
- package/lib/api/composition/repeatMatrix.d.ts +0 -17
- package/lib/api/composition/repeatMatrix.js +0 -30
- package/lib/api/composition/repeatMatrix.js.map +0 -1
- package/lib/api/composition/spaceFlex.d.ts +0 -12
- package/lib/api/composition/spaceFlex.js +0 -22
- package/lib/api/composition/spaceFlex.js.map +0 -1
- package/lib/api/composition/spaceLayer.d.ts +0 -12
- package/lib/api/composition/spaceLayer.js +0 -22
- package/lib/api/composition/spaceLayer.js.map +0 -1
- package/lib/api/composition/timingKeyframe.d.ts +0 -11
- package/lib/api/composition/timingKeyframe.js +0 -22
- package/lib/api/composition/timingKeyframe.js.map +0 -1
- package/lib/api/composition/view.d.ts +0 -19
- package/lib/api/composition/view.js +0 -32
- package/lib/api/composition/view.js.map +0 -1
- package/lib/api/mark/base.d.ts +0 -22
- package/lib/api/mark/base.js.map +0 -1
- package/lib/api/mark/index.d.ts +0 -75
- package/lib/api/mark/index.js +0 -43
- package/lib/api/mark/index.js.map +0 -1
- package/lib/api/mark/mark.d.ts +0 -212
- package/lib/api/mark/mark.js +0 -342
- package/lib/api/mark/mark.js.map +0 -1
- package/lib/api/mark/types.d.ts +0 -26
- package/lib/api/mark/types.js +0 -3
- package/lib/api/mark/types.js.map +0 -1
- package/lib/geo/d3Projection.js.map +0 -1
- package/lib/geo/geoPath.js.map +0 -1
- package/lib/geo/geoView.js.map +0 -1
- package/lib/geo/index.d.ts +0 -9
- package/lib/geo/index.js +0 -12
- package/lib/geo/index.js.map +0 -1
- package/lib/stdlib/index.d.ts +0 -2
- package/lib/stdlib/index.js +0 -25
- package/lib/stdlib/index.js.map +0 -1
- package/src/api/composition/facetCircle.ts +0 -36
- package/src/api/composition/facetRect.ts +0 -36
- package/src/api/composition/geoPath.ts +0 -37
- package/src/api/composition/geoView.ts +0 -39
- package/src/api/composition/index.ts +0 -57
- package/src/api/composition/repeatMatrix.ts +0 -36
- package/src/api/composition/spaceFlex.ts +0 -18
- package/src/api/composition/spaceLayer.ts +0 -18
- package/src/api/composition/timingKeyframe.ts +0 -16
- package/src/api/composition/view.ts +0 -42
- package/src/api/mark/index.ts +0 -113
- package/src/api/mark/mark.ts +0 -439
- package/src/api/mark/types.ts +0 -31
- package/src/geo/index.ts +0 -12
- /package/esm/{geo → composition}/d3Projection.d.ts +0 -0
- /package/esm/{geo → composition}/d3Projection.js +0 -0
- /package/esm/{geo → composition}/geoPath.d.ts +0 -0
- /package/esm/{geo → composition}/geoPath.js +0 -0
- /package/esm/{geo → composition}/geoView.d.ts +0 -0
- /package/lib/{geo → composition}/d3Projection.d.ts +0 -0
- /package/lib/{geo → composition}/d3Projection.js +0 -0
- /package/lib/{geo → composition}/geoPath.d.ts +0 -0
- /package/lib/{geo → composition}/geoPath.js +0 -0
- /package/lib/{geo → composition}/geoView.d.ts +0 -0
- /package/src/{geo → composition}/d3Projection.ts +0 -0
- /package/src/{geo → composition}/geoPath.ts +0 -0
package/src/api/props.ts
CHANGED
|
@@ -1,114 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
if (arguments.length === 0) return this.attr(k);
|
|
32
|
-
if (arguments.length === 1 && typeof key !== 'string') {
|
|
33
|
-
return this.attr(k, key);
|
|
34
|
-
}
|
|
35
|
-
const obj = this.attr(k) || {};
|
|
36
|
-
obj[key] = arguments.length === 1 ? true : value;
|
|
37
|
-
return this.attr(k, obj);
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function defineMixProp(Node, { name }: NodePropertyDescriptor) {
|
|
42
|
-
Node.prototype[name] = function (key) {
|
|
43
|
-
if (arguments.length === 0) return this.attr(name);
|
|
44
|
-
if (Array.isArray(key)) return this.attr(name, { items: key });
|
|
45
|
-
if (
|
|
46
|
-
isStrictObject(key) &&
|
|
47
|
-
(key.title !== undefined || key.items !== undefined)
|
|
48
|
-
) {
|
|
49
|
-
return this.attr(name, key);
|
|
50
|
-
}
|
|
51
|
-
if (key === null || key === false) return this.attr(name, key);
|
|
52
|
-
const obj = this.attr(name) || {};
|
|
53
|
-
const { items = [] } = obj;
|
|
54
|
-
items.push(key);
|
|
55
|
-
obj.items = items;
|
|
56
|
-
return this.attr(name, obj);
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
function defineNodeProp(Node, { name, ctor }: NodePropertyDescriptor) {
|
|
61
|
-
Node.prototype[name] = function (hocMark?) {
|
|
62
|
-
const node = this.append(ctor);
|
|
63
|
-
if (name === 'mark') {
|
|
64
|
-
node.type = hocMark;
|
|
65
|
-
}
|
|
66
|
-
return node;
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
function defineContainerProp(Node, { name, ctor }: NodePropertyDescriptor) {
|
|
71
|
-
Node.prototype[name] = function () {
|
|
72
|
-
this.type = null;
|
|
73
|
-
return this.append(ctor);
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* A decorator to define different type of attribute setter or
|
|
79
|
-
* getter for current node.
|
|
80
|
-
*/
|
|
81
|
-
export function defineProps(descriptors: NodePropertyDescriptor[]) {
|
|
82
|
-
return (Node) => {
|
|
83
|
-
for (const descriptor of descriptors) {
|
|
84
|
-
const { type } = descriptor;
|
|
85
|
-
if (type === 'value') defineValueProp(Node, descriptor);
|
|
86
|
-
else if (type === 'array') defineArrayProp(Node, descriptor);
|
|
87
|
-
else if (type === 'object') defineObjectProp(Node, descriptor);
|
|
88
|
-
else if (type === 'node') defineNodeProp(Node, descriptor);
|
|
89
|
-
else if (type === 'container') defineContainerProp(Node, descriptor);
|
|
90
|
-
else if (type === 'mix') defineMixProp(Node, descriptor);
|
|
91
|
-
}
|
|
92
|
-
return Node;
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
export function nodeProps(
|
|
97
|
-
node: Record<string, new (...args: any[]) => any>,
|
|
98
|
-
): NodePropertyDescriptor[] {
|
|
99
|
-
return Object.entries(node).map(([name, ctor]) => ({
|
|
100
|
-
type: 'node',
|
|
101
|
-
name,
|
|
102
|
-
ctor,
|
|
103
|
-
}));
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
export function containerProps(
|
|
107
|
-
node: Record<string, new (...args: any[]) => any>,
|
|
108
|
-
): NodePropertyDescriptor[] {
|
|
109
|
-
return Object.entries(node).map(([name, ctor]) => ({
|
|
110
|
-
type: 'container',
|
|
111
|
-
name,
|
|
112
|
-
ctor,
|
|
113
|
-
}));
|
|
114
|
-
}
|
|
1
|
+
export const commonProps = {
|
|
2
|
+
encode: { type: 'object' },
|
|
3
|
+
scale: { type: 'object' },
|
|
4
|
+
data: { type: 'value' },
|
|
5
|
+
transform: { type: 'array' },
|
|
6
|
+
style: { type: 'object' },
|
|
7
|
+
animate: { type: 'object' },
|
|
8
|
+
coordinate: { type: 'object' },
|
|
9
|
+
interaction: { type: 'object' },
|
|
10
|
+
label: { type: 'array', key: 'labels' },
|
|
11
|
+
axis: { type: 'object' },
|
|
12
|
+
legend: { type: 'object' },
|
|
13
|
+
slider: { type: 'object' },
|
|
14
|
+
scrollbar: { type: 'object' },
|
|
15
|
+
state: { type: 'object' },
|
|
16
|
+
layout: { type: 'object' },
|
|
17
|
+
theme: { type: 'object' },
|
|
18
|
+
title: { type: 'value' },
|
|
19
|
+
} as const;
|
|
20
|
+
|
|
21
|
+
export const markProps = {
|
|
22
|
+
...commonProps,
|
|
23
|
+
tooltip: { type: 'mix' },
|
|
24
|
+
viewStyle: { type: 'object' },
|
|
25
|
+
} as const;
|
|
26
|
+
|
|
27
|
+
export const compositionProps = {
|
|
28
|
+
...commonProps,
|
|
29
|
+
labelTransform: { type: 'array' },
|
|
30
|
+
} as const;
|
|
@@ -0,0 +1,366 @@
|
|
|
1
|
+
import { IRenderer, RendererPlugin, Canvas as GCanvas } from '@antv/g';
|
|
2
|
+
import { Renderer as CanvasRenderer } from '@antv/g-canvas';
|
|
3
|
+
import { Plugin as DragAndDropPlugin } from '@antv/g-plugin-dragndrop';
|
|
4
|
+
import { debounce } from '@antv/util';
|
|
5
|
+
import EventEmitter from '@antv/event-emitter';
|
|
6
|
+
import { G2Context, render, destroy } from '../runtime';
|
|
7
|
+
import { G2Spec, ViewComposition } from '../spec';
|
|
8
|
+
import { ChartEvent } from '../utils/event';
|
|
9
|
+
import { G2Library } from '../runtime/types/options';
|
|
10
|
+
import {
|
|
11
|
+
normalizeContainer,
|
|
12
|
+
removeContainer,
|
|
13
|
+
sizeOf,
|
|
14
|
+
optionsOf,
|
|
15
|
+
updateRoot,
|
|
16
|
+
createEmptyPromise,
|
|
17
|
+
} from './utils';
|
|
18
|
+
import { CompositionNode } from './composition';
|
|
19
|
+
import { Node } from './node';
|
|
20
|
+
import { defineProps, nodeProps } from './define';
|
|
21
|
+
import { MarkNode } from './mark';
|
|
22
|
+
|
|
23
|
+
export const G2_CHART_KEY = 'G2_CHART_KEY';
|
|
24
|
+
|
|
25
|
+
export type RuntimeOptions = ViewComposition & {
|
|
26
|
+
container?: string | HTMLElement;
|
|
27
|
+
canvas?: GCanvas;
|
|
28
|
+
autoFit?: boolean;
|
|
29
|
+
renderer?: IRenderer;
|
|
30
|
+
plugins?: RendererPlugin[];
|
|
31
|
+
theme?: string;
|
|
32
|
+
lib?: G2Library;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export class Runtime<Spec extends G2Spec = G2Spec> extends CompositionNode {
|
|
36
|
+
private _container: HTMLElement;
|
|
37
|
+
private _context: G2Context;
|
|
38
|
+
private _emitter: EventEmitter;
|
|
39
|
+
private _width: number;
|
|
40
|
+
private _height: number;
|
|
41
|
+
private _renderer: IRenderer;
|
|
42
|
+
private _plugins: RendererPlugin[];
|
|
43
|
+
// Identifies whether bindAutoFit.
|
|
44
|
+
private _hasBindAutoFit = false;
|
|
45
|
+
private _rendering = false;
|
|
46
|
+
private _trailing = false;
|
|
47
|
+
private _trailingResolve = null;
|
|
48
|
+
private _trailingReject = null;
|
|
49
|
+
private _previousDefinedType = null;
|
|
50
|
+
private _marks: Record<string, new () => Node>;
|
|
51
|
+
private _compositions: Record<string, new () => Node>;
|
|
52
|
+
|
|
53
|
+
constructor(options: RuntimeOptions) {
|
|
54
|
+
const { container, canvas, renderer, plugins, lib, ...rest } = options;
|
|
55
|
+
super(rest, 'view');
|
|
56
|
+
this._renderer = renderer || new CanvasRenderer();
|
|
57
|
+
this._plugins = plugins || [];
|
|
58
|
+
this._container = normalizeContainer(container);
|
|
59
|
+
this._emitter = new EventEmitter();
|
|
60
|
+
this._context = { library: lib, emitter: this._emitter, canvas };
|
|
61
|
+
this._create();
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
render(): Promise<Runtime<Spec>> {
|
|
65
|
+
if (this._rendering) return this._addToTrailing();
|
|
66
|
+
if (!this._context.canvas) this._createCanvas();
|
|
67
|
+
this._bindAutoFit();
|
|
68
|
+
this._rendering = true;
|
|
69
|
+
const finished = new Promise<Runtime<Spec>>((resolve, reject) =>
|
|
70
|
+
render(
|
|
71
|
+
this._computedOptions(),
|
|
72
|
+
this._context,
|
|
73
|
+
this._createResolve(resolve),
|
|
74
|
+
this._createReject(reject),
|
|
75
|
+
),
|
|
76
|
+
);
|
|
77
|
+
const [finished1, resolve, reject] = createEmptyPromise<Runtime<Spec>>();
|
|
78
|
+
finished
|
|
79
|
+
.then(resolve)
|
|
80
|
+
.catch(reject)
|
|
81
|
+
.then(() => this._renderTrailing());
|
|
82
|
+
return finished1;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* @overload
|
|
87
|
+
* @returns {Spec}
|
|
88
|
+
*/
|
|
89
|
+
options(): Spec;
|
|
90
|
+
/**
|
|
91
|
+
* @overload
|
|
92
|
+
* @param {G2ViewTree} options
|
|
93
|
+
* @returns {Runtime}
|
|
94
|
+
*/
|
|
95
|
+
options(options: Spec): Runtime<Spec>;
|
|
96
|
+
/**
|
|
97
|
+
* @overload
|
|
98
|
+
* @param {G2ViewTree} [options]
|
|
99
|
+
* @returns {Runtime|Spec}
|
|
100
|
+
*/
|
|
101
|
+
options(options?: Spec): Runtime<Spec> | Spec {
|
|
102
|
+
if (arguments.length === 0) return optionsOf(this) as Spec;
|
|
103
|
+
const { type } = options;
|
|
104
|
+
if (type) this._previousDefinedType = type;
|
|
105
|
+
updateRoot(
|
|
106
|
+
this,
|
|
107
|
+
options,
|
|
108
|
+
this._previousDefinedType,
|
|
109
|
+
this._marks,
|
|
110
|
+
this._compositions,
|
|
111
|
+
);
|
|
112
|
+
return this;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
getContainer(): HTMLElement {
|
|
116
|
+
return this._container;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
getContext(): G2Context {
|
|
120
|
+
return this._context;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
on(event: string, callback: (...args: any[]) => any, once?: boolean): this {
|
|
124
|
+
this._emitter.on(event, callback, once);
|
|
125
|
+
return this;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
once(event: string, callback: (...args: any[]) => any): this {
|
|
129
|
+
this._emitter.once(event, callback);
|
|
130
|
+
return this;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
emit(event: string, ...args: any[]): this {
|
|
134
|
+
this._emitter.emit(event, ...args);
|
|
135
|
+
return this;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
off(event?: string, callback?: (...args: any[]) => any) {
|
|
139
|
+
this._emitter.off(event, callback);
|
|
140
|
+
return this;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
clear() {
|
|
144
|
+
const options = this.options();
|
|
145
|
+
this.emit(ChartEvent.BEFORE_CLEAR);
|
|
146
|
+
this._reset();
|
|
147
|
+
destroy(options, this._context, false);
|
|
148
|
+
this.emit(ChartEvent.AFTER_CLEAR);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
destroy() {
|
|
152
|
+
const options = this.options();
|
|
153
|
+
this.emit(ChartEvent.BEFORE_DESTROY);
|
|
154
|
+
this._unbindAutoFit();
|
|
155
|
+
this._reset();
|
|
156
|
+
destroy(options, this._context, true);
|
|
157
|
+
removeContainer(this._container);
|
|
158
|
+
this.emit(ChartEvent.AFTER_DESTROY);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
forceFit() {
|
|
162
|
+
// Don't fit if size do not change.
|
|
163
|
+
this.options['autoFit'] = true;
|
|
164
|
+
const { width, height } = sizeOf(this.options(), this._container);
|
|
165
|
+
if (width === this._width && height === this._height) {
|
|
166
|
+
return Promise.resolve(this);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// Don't call changeSize to prevent update width and height of options.
|
|
170
|
+
this.emit(ChartEvent.BEFORE_CHANGE_SIZE);
|
|
171
|
+
const finished = this.render();
|
|
172
|
+
finished.then(() => {
|
|
173
|
+
this.emit(ChartEvent.AFTER_CHANGE_SIZE);
|
|
174
|
+
});
|
|
175
|
+
return finished;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
changeSize(width: number, height: number): Promise<Runtime<Spec>> {
|
|
179
|
+
if (width === this._width && height === this._height) {
|
|
180
|
+
return Promise.resolve(this);
|
|
181
|
+
}
|
|
182
|
+
this.emit(ChartEvent.BEFORE_CHANGE_SIZE);
|
|
183
|
+
this.attr('width', width);
|
|
184
|
+
this.attr('height', height);
|
|
185
|
+
const finished = this.render();
|
|
186
|
+
finished.then(() => {
|
|
187
|
+
this.emit(ChartEvent.AFTER_CHANGE_SIZE);
|
|
188
|
+
});
|
|
189
|
+
return finished;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
private _create() {
|
|
193
|
+
const { library } = this._context;
|
|
194
|
+
|
|
195
|
+
// @todo After refactor component as mark, remove this.
|
|
196
|
+
const isMark = (key) =>
|
|
197
|
+
key.startsWith('mark.') ||
|
|
198
|
+
key === 'component.axisX' ||
|
|
199
|
+
key === 'component.axisY' ||
|
|
200
|
+
key === 'component.legends';
|
|
201
|
+
|
|
202
|
+
const marks = [
|
|
203
|
+
'mark.mark', // chart.mark(composite)
|
|
204
|
+
...Object.keys(library).filter(isMark),
|
|
205
|
+
];
|
|
206
|
+
|
|
207
|
+
// Create mark generators.
|
|
208
|
+
this._marks = {};
|
|
209
|
+
for (const key of marks) {
|
|
210
|
+
const name = key.split('.').pop();
|
|
211
|
+
class Mark extends MarkNode {
|
|
212
|
+
constructor() {
|
|
213
|
+
super({}, name);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
this._marks[name] = Mark;
|
|
217
|
+
this[name] = function (composite) {
|
|
218
|
+
const node = this.append(Mark);
|
|
219
|
+
if (name === 'mark') node.type = composite;
|
|
220
|
+
return node;
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
// Create composition generators.
|
|
225
|
+
const compositions = Object.keys(library).filter(
|
|
226
|
+
(key) => key.startsWith('composition.') && key !== 'composition.mark',
|
|
227
|
+
);
|
|
228
|
+
this._compositions = Object.fromEntries(
|
|
229
|
+
compositions.map((key) => {
|
|
230
|
+
const name = key.split('.').pop();
|
|
231
|
+
@defineProps(nodeProps(this._marks))
|
|
232
|
+
class Composition extends CompositionNode {
|
|
233
|
+
constructor() {
|
|
234
|
+
super({}, name);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
return [name, Composition];
|
|
238
|
+
}),
|
|
239
|
+
);
|
|
240
|
+
|
|
241
|
+
for (const Ctor of Object.values(this._compositions)) {
|
|
242
|
+
defineProps(nodeProps(this._compositions))(Ctor);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
for (const key of compositions) {
|
|
246
|
+
const name = key.split('.').pop();
|
|
247
|
+
this[name] = function () {
|
|
248
|
+
const Composition = this._compositions[name];
|
|
249
|
+
this.type = null;
|
|
250
|
+
return this.append(Composition);
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
private _reset() {
|
|
256
|
+
const KEYS = ['theme', 'type', 'width', 'height', 'autoFit'];
|
|
257
|
+
this.type = 'view';
|
|
258
|
+
this.value = Object.fromEntries(
|
|
259
|
+
Object.entries(this.value).filter(
|
|
260
|
+
([key]) =>
|
|
261
|
+
key.startsWith('margin') ||
|
|
262
|
+
key.startsWith('padding') ||
|
|
263
|
+
key.startsWith('inset') ||
|
|
264
|
+
KEYS.includes(key),
|
|
265
|
+
),
|
|
266
|
+
);
|
|
267
|
+
this.children = [];
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
private _renderTrailing() {
|
|
271
|
+
if (!this._trailing) return;
|
|
272
|
+
this._trailing = false;
|
|
273
|
+
this.render()
|
|
274
|
+
.then(() => {
|
|
275
|
+
const trailingResolve = this._trailingResolve.bind(this);
|
|
276
|
+
this._trailingResolve = null;
|
|
277
|
+
trailingResolve(this);
|
|
278
|
+
})
|
|
279
|
+
.catch((error) => {
|
|
280
|
+
const trailingReject = this._trailingReject.bind(this);
|
|
281
|
+
this._trailingReject = null;
|
|
282
|
+
trailingReject(error);
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
private _createResolve(resolve: (chart: Runtime<Spec>) => void) {
|
|
287
|
+
return () => {
|
|
288
|
+
this._rendering = false;
|
|
289
|
+
resolve(this);
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
private _createReject(reject: (error: Error) => void) {
|
|
294
|
+
return (error: Error) => {
|
|
295
|
+
this._rendering = false;
|
|
296
|
+
reject(error);
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
// Update actual size and key.
|
|
301
|
+
private _computedOptions() {
|
|
302
|
+
const options = this.options();
|
|
303
|
+
const { key = G2_CHART_KEY } = options;
|
|
304
|
+
const { width, height } = sizeOf(options, this._container);
|
|
305
|
+
this._width = width;
|
|
306
|
+
this._height = height;
|
|
307
|
+
this._key = key;
|
|
308
|
+
return { key: this._key, ...options, width, height };
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
// Create canvas if it does not exist.
|
|
312
|
+
// DragAndDropPlugin is for interaction.
|
|
313
|
+
// It is OK to register more than one time, G will handle this.
|
|
314
|
+
private _createCanvas() {
|
|
315
|
+
const { width, height } = sizeOf(this.options(), this._container);
|
|
316
|
+
this._plugins.push(new DragAndDropPlugin());
|
|
317
|
+
this._plugins.forEach((d) => this._renderer.registerPlugin(d));
|
|
318
|
+
this._context.canvas = new GCanvas({
|
|
319
|
+
container: this._container,
|
|
320
|
+
width,
|
|
321
|
+
height,
|
|
322
|
+
renderer: this._renderer,
|
|
323
|
+
});
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
private _addToTrailing(): Promise<Runtime<Spec>> {
|
|
327
|
+
// Resolve previous promise, and give up this task.
|
|
328
|
+
this._trailingResolve?.(this);
|
|
329
|
+
|
|
330
|
+
// Create new task.
|
|
331
|
+
this._trailing = true;
|
|
332
|
+
const promise = new Promise<Runtime<Spec>>((resolve, reject) => {
|
|
333
|
+
this._trailingResolve = resolve;
|
|
334
|
+
this._trailingReject = reject;
|
|
335
|
+
});
|
|
336
|
+
|
|
337
|
+
return promise;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
private _onResize = debounce(() => {
|
|
341
|
+
this.forceFit();
|
|
342
|
+
}, 300);
|
|
343
|
+
|
|
344
|
+
private _bindAutoFit() {
|
|
345
|
+
const options = this.options();
|
|
346
|
+
const { autoFit } = options;
|
|
347
|
+
|
|
348
|
+
if (this._hasBindAutoFit) {
|
|
349
|
+
// If it was bind before, unbind it now.
|
|
350
|
+
if (!autoFit) this._unbindAutoFit();
|
|
351
|
+
return;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
if (autoFit) {
|
|
355
|
+
this._hasBindAutoFit = true;
|
|
356
|
+
window.addEventListener('resize', this._onResize);
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
private _unbindAutoFit() {
|
|
361
|
+
if (this._hasBindAutoFit) {
|
|
362
|
+
this._hasBindAutoFit = false;
|
|
363
|
+
window.removeEventListener('resize', this._onResize);
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
}
|
package/src/api/types.ts
CHANGED
|
@@ -1,24 +1,102 @@
|
|
|
1
|
+
type ElementOf<T> = T extends Array<any> ? T[number] : never;
|
|
2
|
+
|
|
1
3
|
type ValueOf<T> = T[keyof T];
|
|
2
4
|
|
|
3
|
-
type
|
|
5
|
+
export type Concrete<T> = { [Key in keyof T]-?: T[Key] };
|
|
4
6
|
|
|
5
|
-
|
|
7
|
+
/**
|
|
8
|
+
* If typeof `Value` is value, returns `Node`.
|
|
9
|
+
* Otherwise returns the value.
|
|
10
|
+
*/
|
|
11
|
+
export type ValueAttribute<Value, Node> = (() => Value) &
|
|
12
|
+
((value: Value) => Node);
|
|
6
13
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
14
|
+
/**
|
|
15
|
+
* If no params, returns `Value`.
|
|
16
|
+
* Otherwise returns the `Node`.
|
|
17
|
+
*/
|
|
18
|
+
export type ObjectAttribute<Value, Node> = (() => Value) &
|
|
19
|
+
(<K extends Value extends Record<string, any> ? Value : never>(
|
|
20
|
+
key: K | keyof K | boolean,
|
|
21
|
+
) => Node) &
|
|
22
|
+
(<
|
|
23
|
+
K extends Value extends Record<string, any> ? keyof Value : never,
|
|
24
|
+
V extends Value extends Record<string, any> ? ValueOf<Value> : never,
|
|
25
|
+
>(
|
|
26
|
+
key: K,
|
|
27
|
+
value: V | boolean,
|
|
28
|
+
) => Node);
|
|
10
29
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
? Chainable<V, V, N> // For mark.axis({ x: {} }) and mark.axis(false)
|
|
18
|
-
: Chainable<T, V, N>; // For mark.axis('x', {})
|
|
30
|
+
/**
|
|
31
|
+
* If typeof `Value` is an array or an element of array, returns `Node`.
|
|
32
|
+
* Otherwise returns the array.
|
|
33
|
+
*/
|
|
34
|
+
export type ArrayAttribute<Value, Node> = (() => Value) &
|
|
35
|
+
((value: Value | ElementOf<Value>) => Node);
|
|
19
36
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
37
|
+
/**
|
|
38
|
+
* Filter Object keys with the specified prefix.
|
|
39
|
+
* @example
|
|
40
|
+
* type A = { 'mark.a': number, 'composition.b': number }
|
|
41
|
+
* type B = FilterKey<A, 'mark'>; // { 'a': number }
|
|
42
|
+
*/
|
|
43
|
+
export type FilterKey<
|
|
44
|
+
T extends string | symbol | number,
|
|
45
|
+
Prefix extends string,
|
|
46
|
+
> = T extends `${Prefix}.${infer Key}` ? Key : never;
|
|
23
47
|
|
|
24
|
-
|
|
48
|
+
/**
|
|
49
|
+
* Filter Object keys with `mark` as prefix.
|
|
50
|
+
* @example
|
|
51
|
+
* type A = { 'mark.a': number, 'composition.b': number }
|
|
52
|
+
* type B = FilterKey<A, 'mark'>; // { 'a': number }
|
|
53
|
+
* @todo Remove component.xxxx
|
|
54
|
+
*/
|
|
55
|
+
export type FilterMark<T extends string | symbol | number> =
|
|
56
|
+
T extends 'component.axisX'
|
|
57
|
+
? 'axisX'
|
|
58
|
+
: T extends 'component.axisY'
|
|
59
|
+
? 'axisY'
|
|
60
|
+
: T extends 'component.legends'
|
|
61
|
+
? 'legends'
|
|
62
|
+
: FilterKey<T, 'mark'>;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Filter Object keys with `composition` as prefix.
|
|
66
|
+
* @example
|
|
67
|
+
* type A = { 'mark.a': number, 'composition.b': number }
|
|
68
|
+
* type B = FilterComposition<A>; // { 'b': number }
|
|
69
|
+
*/
|
|
70
|
+
export type FilterComposition<T extends string | symbol | number> = FilterKey<
|
|
71
|
+
T,
|
|
72
|
+
'composition'
|
|
73
|
+
>;
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Map marks of library to Nodes.
|
|
77
|
+
*/
|
|
78
|
+
export type MarkOf<Library extends Record<string, any>, Node> = {
|
|
79
|
+
[Key in keyof Library as FilterMark<Key>]: Node;
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Map compositions of library to Nodes.
|
|
84
|
+
*/
|
|
85
|
+
export type CompositionOf<Library extends Record<string, any>, Node> = {
|
|
86
|
+
[Key in keyof Library as FilterComposition<Key>]: Node;
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Map descriptors to props of Nodes.
|
|
91
|
+
*/
|
|
92
|
+
export type PropsOf<
|
|
93
|
+
Descriptor extends Record<string, any>,
|
|
94
|
+
Spec extends Record<any, any>,
|
|
95
|
+
Node,
|
|
96
|
+
> = {
|
|
97
|
+
[Key in keyof Descriptor]: Descriptor[Key] extends { type: 'object' }
|
|
98
|
+
? ObjectAttribute<Spec[Key], Node>
|
|
99
|
+
: Descriptor[Key] extends { type: 'value' }
|
|
100
|
+
? ValueAttribute<Spec[Key], Node>
|
|
101
|
+
: ArrayAttribute<Spec[Key], Node>;
|
|
102
|
+
};
|