@antv/g2 5.0.0-beta.6 → 5.0.0-beta.8
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 +8 -4
- package/esm/api/chart.js +33 -17
- package/esm/api/chart.js.map +1 -1
- package/esm/api/composition/base.d.ts +21 -0
- package/esm/api/composition/base.js +59 -0
- package/esm/api/composition/base.js.map +1 -0
- package/esm/api/composition/facetCircle.d.ts +2 -3
- 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 -3
- 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 -3
- 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 -3
- 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 -1
- package/esm/api/composition/index.js +2 -1
- package/esm/api/composition/index.js.map +1 -1
- package/esm/api/composition/repeatMatrix.d.ts +2 -3
- 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 -3
- 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 -3
- 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 -3
- package/esm/api/composition/timingKeyframe.js +2 -2
- package/esm/api/composition/timingKeyframe.js.map +1 -1
- package/esm/api/composition/view.d.ts +3 -3
- package/esm/api/composition/view.js +4 -4
- package/esm/api/composition/view.js.map +1 -1
- package/esm/api/mark/base.d.ts +22 -0
- package/esm/api/mark/base.js +54 -0
- package/esm/api/mark/base.js.map +1 -0
- package/esm/api/mark/mark.d.ts +29 -29
- package/esm/api/mark/mark.js +27 -27
- package/esm/api/mark/mark.js.map +1 -1
- package/esm/api/node.d.ts +2 -1
- package/esm/api/node.js +8 -9
- package/esm/api/node.js.map +1 -1
- package/esm/api/props.js +0 -20
- package/esm/api/props.js.map +1 -1
- package/esm/component/axis.js +4 -0
- package/esm/component/axis.js.map +1 -1
- package/esm/component/legendContinuous.d.ts +1 -0
- package/esm/component/legendContinuous.js +14 -16
- package/esm/component/legendContinuous.js.map +1 -1
- package/esm/component/slider.js +3 -13
- package/esm/component/slider.js.map +1 -1
- package/esm/geo/{d3-projection.d.ts → d3Projection.d.ts} +0 -0
- package/esm/geo/{d3-projection.js → d3Projection.js} +1 -1
- package/esm/geo/d3Projection.js.map +1 -0
- package/esm/geo/geoView.js +1 -1
- package/esm/geo/geoView.js.map +1 -1
- package/esm/interaction/builtin/elementHighlight.d.ts +2 -0
- package/esm/interaction/builtin/elementHighlightByColor.d.ts +2 -0
- package/esm/interaction/builtin/elementHighlightByX.d.ts +2 -0
- package/esm/interaction/index.d.ts +2 -0
- package/esm/interaction/index.js +2 -0
- package/esm/interaction/index.js.map +1 -1
- package/esm/interaction/native/brushFilter.d.ts +3 -1
- package/esm/interaction/native/brushFilter.js +7 -32
- package/esm/interaction/native/brushFilter.js.map +1 -1
- package/esm/interaction/native/brushXFilter.js +1 -1
- package/esm/interaction/native/brushXFilter.js.map +1 -1
- package/esm/interaction/native/brushYFilter.js +1 -1
- package/esm/interaction/native/brushYFilter.js.map +1 -1
- package/esm/interaction/native/elementHighlight.d.ts +7 -2
- package/esm/interaction/native/elementHighlight.js +72 -18
- package/esm/interaction/native/elementHighlight.js.map +1 -1
- package/esm/interaction/native/elementHighlightByColor.d.ts +4 -1
- package/esm/interaction/native/elementHighlightByColor.js +19 -3
- package/esm/interaction/native/elementHighlightByColor.js.map +1 -1
- package/esm/interaction/native/elementHighlightByX.d.ts +3 -3
- package/esm/interaction/native/elementHighlightByX.js +19 -3
- package/esm/interaction/native/elementHighlightByX.js.map +1 -1
- package/esm/interaction/native/elementSelect.d.ts +1 -1
- package/esm/interaction/native/elementSelect.js +42 -20
- package/esm/interaction/native/elementSelect.js.map +1 -1
- package/esm/interaction/native/elementSelectByColor.js +3 -2
- package/esm/interaction/native/elementSelectByColor.js.map +1 -1
- package/esm/interaction/native/elementSelectByX.js +3 -2
- package/esm/interaction/native/elementSelectByX.js.map +1 -1
- package/esm/interaction/native/legendFilter.d.ts +4 -0
- package/esm/interaction/native/legendFilter.js +7 -4
- package/esm/interaction/native/legendFilter.js.map +1 -1
- package/esm/interaction/native/legendHighlight.d.ts +4 -0
- package/esm/interaction/native/legendHighlight.js +94 -0
- package/esm/interaction/native/legendHighlight.js.map +1 -0
- package/esm/interaction/native/sliderFilter.d.ts +5 -0
- package/esm/interaction/native/sliderFilter.js +87 -0
- package/esm/interaction/native/sliderFilter.js.map +1 -0
- package/esm/interaction/native/tooltip.js +11 -0
- package/esm/interaction/native/tooltip.js.map +1 -1
- package/esm/interaction/native/utils.d.ts +13 -2
- package/esm/interaction/native/utils.js +151 -26
- package/esm/interaction/native/utils.js.map +1 -1
- package/esm/label-transform/overlapDodgeY.js.map +1 -1
- package/esm/mark/area.js +1 -1
- package/esm/mark/area.js.map +1 -1
- package/esm/runtime/component.d.ts +1 -1
- package/esm/runtime/component.js +5 -3
- package/esm/runtime/component.js.map +1 -1
- package/esm/runtime/plot.d.ts +1 -1
- package/esm/runtime/plot.js +68 -29
- package/esm/runtime/plot.js.map +1 -1
- package/esm/runtime/render.js +18 -13
- package/esm/runtime/render.js.map +1 -1
- package/esm/runtime/scale.d.ts +2 -1
- package/esm/runtime/scale.js +7 -0
- package/esm/runtime/scale.js.map +1 -1
- package/esm/runtime/types/options.d.ts +4 -2
- package/esm/shape/area/hv.d.ts +3 -0
- package/esm/shape/area/hv.js +9 -0
- package/esm/shape/area/hv.js.map +1 -0
- package/esm/shape/area/hvh.d.ts +3 -0
- package/esm/shape/area/{step.js → hvh.js} +3 -3
- package/esm/shape/area/hvh.js.map +1 -0
- package/esm/shape/area/vh.d.ts +3 -0
- package/esm/shape/area/vh.js +9 -0
- package/esm/shape/area/vh.js.map +1 -0
- package/esm/shape/index.d.ts +6 -2
- package/esm/shape/index.js +3 -1
- package/esm/shape/index.js.map +1 -1
- package/esm/shape/interval/color.d.ts +1 -0
- package/esm/shape/interval/color.js +65 -53
- package/esm/shape/interval/color.js.map +1 -1
- package/esm/spec/composition.d.ts +0 -3
- package/esm/spec/geometry.d.ts +1 -0
- package/esm/spec/interaction.d.ts +30 -11
- package/esm/spec/transform.d.ts +15 -5
- package/esm/stdlib/index.js +3 -8
- package/esm/stdlib/index.js.map +1 -1
- package/esm/transform/sample.js +42 -26
- package/esm/transform/sample.js.map +1 -1
- package/esm/transform/select.js +1 -13
- package/esm/transform/select.js.map +1 -1
- package/esm/transform/selectX.js +1 -1
- package/esm/transform/selectX.js.map +1 -1
- package/esm/transform/selectY.js +1 -1
- package/esm/transform/selectY.js.map +1 -1
- package/esm/transform/utils/lttb.d.ts +5 -0
- package/esm/transform/utils/lttb.js +56 -0
- package/esm/transform/utils/lttb.js.map +1 -0
- package/esm/utils/event.d.ts +0 -2
- package/esm/utils/event.js +0 -18
- package/esm/utils/event.js.map +1 -1
- package/esm/utils/scale.d.ts +3 -0
- package/esm/utils/scale.js +30 -0
- package/esm/utils/scale.js.map +1 -0
- package/esm/utils/vector.d.ts +1 -1
- package/esm/utils/vector.js +1 -1
- package/lib/api/chart.d.ts +8 -4
- package/lib/api/chart.js +34 -15
- package/lib/api/chart.js.map +1 -1
- package/lib/api/composition/base.d.ts +21 -0
- package/lib/api/composition/base.js +62 -0
- package/lib/api/composition/base.js.map +1 -0
- package/lib/api/composition/facetCircle.d.ts +2 -3
- package/lib/api/composition/facetCircle.js +2 -2
- package/lib/api/composition/facetCircle.js.map +1 -1
- package/lib/api/composition/facetRect.d.ts +2 -3
- package/lib/api/composition/facetRect.js +2 -2
- package/lib/api/composition/facetRect.js.map +1 -1
- package/lib/api/composition/geoPath.d.ts +2 -3
- package/lib/api/composition/geoPath.js +2 -2
- package/lib/api/composition/geoPath.js.map +1 -1
- package/lib/api/composition/geoView.d.ts +2 -3
- package/lib/api/composition/geoView.js +2 -2
- package/lib/api/composition/geoView.js.map +1 -1
- package/lib/api/composition/index.d.ts +2 -1
- package/lib/api/composition/index.js +3 -1
- package/lib/api/composition/index.js.map +1 -1
- package/lib/api/composition/repeatMatrix.d.ts +2 -3
- package/lib/api/composition/repeatMatrix.js +2 -2
- package/lib/api/composition/repeatMatrix.js.map +1 -1
- package/lib/api/composition/spaceFlex.d.ts +2 -3
- package/lib/api/composition/spaceFlex.js +2 -2
- package/lib/api/composition/spaceFlex.js.map +1 -1
- package/lib/api/composition/spaceLayer.d.ts +2 -3
- package/lib/api/composition/spaceLayer.js +2 -2
- package/lib/api/composition/spaceLayer.js.map +1 -1
- package/lib/api/composition/timingKeyframe.d.ts +2 -3
- package/lib/api/composition/timingKeyframe.js +2 -2
- package/lib/api/composition/timingKeyframe.js.map +1 -1
- package/lib/api/composition/view.d.ts +3 -3
- package/lib/api/composition/view.js +4 -4
- package/lib/api/composition/view.js.map +1 -1
- package/lib/api/mark/base.d.ts +22 -0
- package/lib/api/mark/base.js +58 -0
- package/lib/api/mark/base.js.map +1 -0
- package/lib/api/mark/mark.d.ts +29 -29
- package/lib/api/mark/mark.js +27 -27
- package/lib/api/mark/mark.js.map +1 -1
- package/lib/api/node.d.ts +2 -1
- package/lib/api/node.js +8 -9
- package/lib/api/node.js.map +1 -1
- package/lib/api/props.js +0 -20
- package/lib/api/props.js.map +1 -1
- package/lib/component/axis.js +4 -0
- package/lib/component/axis.js.map +1 -1
- package/lib/component/legendContinuous.d.ts +1 -0
- package/lib/component/legendContinuous.js +14 -16
- package/lib/component/legendContinuous.js.map +1 -1
- package/lib/component/slider.js +3 -13
- package/lib/component/slider.js.map +1 -1
- package/lib/geo/{d3-projection.d.ts → d3Projection.d.ts} +0 -0
- package/lib/geo/{d3-projection.js → d3Projection.js} +1 -1
- package/lib/geo/d3Projection.js.map +1 -0
- package/lib/geo/geoView.js +1 -1
- package/lib/geo/geoView.js.map +1 -1
- package/lib/interaction/builtin/elementHighlight.d.ts +2 -0
- package/lib/interaction/builtin/elementHighlightByColor.d.ts +2 -0
- package/lib/interaction/builtin/elementHighlightByX.d.ts +2 -0
- package/lib/interaction/index.d.ts +2 -0
- package/lib/interaction/index.js +5 -1
- package/lib/interaction/index.js.map +1 -1
- package/lib/interaction/native/brushFilter.d.ts +3 -1
- package/lib/interaction/native/brushFilter.js +10 -35
- package/lib/interaction/native/brushFilter.js.map +1 -1
- package/lib/interaction/native/brushXFilter.js +1 -1
- package/lib/interaction/native/brushXFilter.js.map +1 -1
- package/lib/interaction/native/brushYFilter.js +1 -1
- package/lib/interaction/native/brushYFilter.js.map +1 -1
- package/lib/interaction/native/elementHighlight.d.ts +7 -2
- package/lib/interaction/native/elementHighlight.js +71 -17
- package/lib/interaction/native/elementHighlight.js.map +1 -1
- package/lib/interaction/native/elementHighlightByColor.d.ts +4 -1
- package/lib/interaction/native/elementHighlightByColor.js +18 -2
- package/lib/interaction/native/elementHighlightByColor.js.map +1 -1
- package/lib/interaction/native/elementHighlightByX.d.ts +3 -3
- package/lib/interaction/native/elementHighlightByX.js +18 -2
- package/lib/interaction/native/elementHighlightByX.js.map +1 -1
- package/lib/interaction/native/elementSelect.d.ts +1 -1
- package/lib/interaction/native/elementSelect.js +41 -19
- package/lib/interaction/native/elementSelect.js.map +1 -1
- package/lib/interaction/native/elementSelectByColor.js +2 -1
- package/lib/interaction/native/elementSelectByColor.js.map +1 -1
- package/lib/interaction/native/elementSelectByX.js +2 -1
- package/lib/interaction/native/elementSelectByX.js.map +1 -1
- package/lib/interaction/native/legendFilter.d.ts +4 -0
- package/lib/interaction/native/legendFilter.js +10 -3
- package/lib/interaction/native/legendFilter.js.map +1 -1
- package/lib/interaction/native/legendHighlight.d.ts +4 -0
- package/lib/interaction/native/legendHighlight.js +98 -0
- package/lib/interaction/native/legendHighlight.js.map +1 -0
- package/lib/interaction/native/sliderFilter.d.ts +5 -0
- package/lib/interaction/native/sliderFilter.js +91 -0
- package/lib/interaction/native/sliderFilter.js.map +1 -0
- package/lib/interaction/native/tooltip.js +11 -0
- package/lib/interaction/native/tooltip.js.map +1 -1
- package/lib/interaction/native/utils.d.ts +13 -2
- package/lib/interaction/native/utils.js +154 -27
- package/lib/interaction/native/utils.js.map +1 -1
- package/lib/label-transform/overlapDodgeY.js.map +1 -1
- package/lib/mark/area.js +1 -1
- package/lib/mark/area.js.map +1 -1
- package/lib/runtime/component.d.ts +1 -1
- package/lib/runtime/component.js +4 -2
- package/lib/runtime/component.js.map +1 -1
- package/lib/runtime/plot.d.ts +1 -1
- package/lib/runtime/plot.js +65 -26
- package/lib/runtime/plot.js.map +1 -1
- package/lib/runtime/render.js +20 -12
- package/lib/runtime/render.js.map +1 -1
- package/lib/runtime/scale.d.ts +2 -1
- package/lib/runtime/scale.js +9 -1
- package/lib/runtime/scale.js.map +1 -1
- package/lib/runtime/types/options.d.ts +4 -2
- package/lib/shape/area/hv.d.ts +3 -0
- package/lib/shape/area/hv.js +13 -0
- package/lib/shape/area/hv.js.map +1 -0
- package/lib/shape/area/hvh.d.ts +3 -0
- package/lib/shape/area/{step.js → hvh.js} +5 -5
- package/lib/shape/area/hvh.js.map +1 -0
- package/lib/shape/area/vh.d.ts +3 -0
- package/lib/shape/area/vh.js +13 -0
- package/lib/shape/area/vh.js.map +1 -0
- package/lib/shape/index.d.ts +6 -2
- package/lib/shape/index.js +7 -3
- package/lib/shape/index.js.map +1 -1
- package/lib/shape/interval/color.d.ts +1 -0
- package/lib/shape/interval/color.js +67 -54
- package/lib/shape/interval/color.js.map +1 -1
- package/lib/spec/composition.d.ts +0 -3
- package/lib/spec/geometry.d.ts +1 -0
- package/lib/spec/interaction.d.ts +30 -11
- package/lib/spec/transform.d.ts +15 -5
- package/lib/stdlib/index.js +1 -1
- package/lib/stdlib/index.js.map +1 -1
- package/lib/transform/sample.js +42 -26
- package/lib/transform/sample.js.map +1 -1
- package/lib/transform/select.js +1 -13
- package/lib/transform/select.js.map +1 -1
- package/lib/transform/selectX.js +1 -1
- package/lib/transform/selectX.js.map +1 -1
- package/lib/transform/selectY.js +1 -1
- package/lib/transform/selectY.js.map +1 -1
- package/lib/transform/utils/lttb.d.ts +5 -0
- package/lib/transform/utils/lttb.js +60 -0
- package/lib/transform/utils/lttb.js.map +1 -0
- package/lib/utils/event.d.ts +0 -2
- package/lib/utils/event.js +1 -21
- package/lib/utils/event.js.map +1 -1
- package/lib/utils/scale.d.ts +3 -0
- package/lib/utils/scale.js +36 -0
- package/lib/utils/scale.js.map +1 -0
- package/lib/utils/vector.d.ts +1 -1
- package/lib/utils/vector.js +1 -1
- package/package.json +4 -3
- package/src/.DS_Store +0 -0
- package/src/api/chart.ts +39 -18
- package/src/api/composition/base.ts +56 -0
- package/src/api/composition/facetCircle.ts +2 -3
- package/src/api/composition/facetRect.ts +2 -3
- package/src/api/composition/geoPath.ts +2 -3
- package/src/api/composition/geoView.ts +2 -3
- package/src/api/composition/index.ts +2 -0
- package/src/api/composition/repeatMatrix.ts +2 -3
- package/src/api/composition/spaceFlex.ts +2 -3
- package/src/api/composition/spaceLayer.ts +2 -3
- package/src/api/composition/timingKeyframe.ts +2 -3
- package/src/api/composition/view.ts +6 -4
- package/src/api/mark/base.ts +58 -0
- package/src/api/mark/mark.ts +29 -28
- package/src/api/node.ts +9 -11
- package/src/api/props.ts +0 -23
- package/src/component/axis.ts +7 -0
- package/src/component/legendContinuous.ts +15 -5
- package/src/component/slider.ts +3 -12
- package/src/data/.DS_Store +0 -0
- package/src/geo/{d3-projection.ts → d3Projection.ts} +0 -0
- package/src/geo/geoView.ts +1 -1
- package/src/interaction/index.ts +2 -0
- package/src/interaction/native/brushFilter.ts +18 -38
- package/src/interaction/native/brushXFilter.ts +1 -0
- package/src/interaction/native/brushYFilter.ts +1 -0
- package/src/interaction/native/elementHighlight.ts +78 -11
- package/src/interaction/native/elementHighlightByColor.ts +9 -4
- package/src/interaction/native/elementHighlightByX.ts +9 -5
- package/src/interaction/native/elementSelect.ts +58 -14
- package/src/interaction/native/elementSelectByColor.ts +4 -1
- package/src/interaction/native/elementSelectByX.ts +4 -1
- package/src/interaction/native/legendFilter.ts +8 -4
- package/src/interaction/native/legendHighlight.ts +87 -0
- package/src/interaction/native/sliderFilter.ts +112 -0
- package/src/interaction/native/tooltip.ts +11 -0
- package/src/interaction/native/utils.ts +183 -26
- package/src/label-transform/overlapDodgeY.ts +1 -1
- package/src/mark/area.ts +1 -1
- package/src/runtime/component.ts +18 -25
- package/src/runtime/plot.ts +123 -75
- package/src/runtime/render.ts +26 -13
- package/src/runtime/scale.ts +14 -0
- package/src/runtime/types/options.ts +10 -2
- package/src/shape/.DS_Store +0 -0
- package/src/shape/area/hv.ts +20 -0
- package/src/shape/area/{step.ts → hvh.ts} +3 -3
- package/src/shape/area/vh.ts +20 -0
- package/src/shape/index.ts +7 -2
- package/src/shape/interval/color.ts +86 -54
- package/src/spec/composition.ts +0 -1
- package/src/spec/geometry.ts +1 -0
- package/src/spec/interaction.ts +45 -12
- package/src/spec/transform.ts +30 -3
- package/src/stdlib/index.ts +10 -6
- package/src/transform/sample.ts +54 -18
- package/src/transform/select.ts +1 -2
- package/src/transform/selectX.ts +1 -1
- package/src/transform/selectY.ts +1 -1
- package/src/transform/utils/lttb.ts +73 -0
- package/src/utils/event.ts +0 -26
- package/src/utils/scale.ts +31 -0
- package/src/utils/vector.ts +1 -1
- package/esm/geo/d3-projection.js.map +0 -1
- package/esm/shape/area/step.d.ts +0 -3
- package/esm/shape/area/step.js.map +0 -1
- package/lib/geo/d3-projection.js.map +0 -1
- package/lib/shape/area/step.d.ts +0 -3
- package/lib/shape/area/step.js.map +0 -1
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.lttb = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Sample data with lttb(Largest-Triangle-Three-Buckets) algo (https://github.com/pingec/downsample-lttb).
|
|
6
|
+
* Return the sampled index array.
|
|
7
|
+
*/
|
|
8
|
+
function lttb(I, X, Y, thresholds) {
|
|
9
|
+
const length = I.length;
|
|
10
|
+
if (thresholds >= length || thresholds === 0) {
|
|
11
|
+
return I;
|
|
12
|
+
}
|
|
13
|
+
const x = (i) => X[I[i]] * 1;
|
|
14
|
+
const y = (i) => Y[I[i]] * 1;
|
|
15
|
+
const sampled = [];
|
|
16
|
+
// Bucket size. Leave room for start and end data points.
|
|
17
|
+
const every = (length - 2) / (thresholds - 2);
|
|
18
|
+
let a = 0; // Initially a is the first point in the triangle.
|
|
19
|
+
let maxArea;
|
|
20
|
+
let area;
|
|
21
|
+
let nextA;
|
|
22
|
+
sampled.push(a); // Always add the first point.
|
|
23
|
+
for (let i = 0; i < thresholds - 2; i++) {
|
|
24
|
+
// Calculate point average for next bucket (containing c).
|
|
25
|
+
let avgX = 0;
|
|
26
|
+
let avgY = 0;
|
|
27
|
+
let start = Math.floor((i + 1) * every) + 1;
|
|
28
|
+
let end = Math.floor((i + 2) * every) + 1;
|
|
29
|
+
end = Math.min(end, length);
|
|
30
|
+
const size = end - start;
|
|
31
|
+
for (; start < end; start++) {
|
|
32
|
+
avgX += x(start);
|
|
33
|
+
avgY += y(start);
|
|
34
|
+
}
|
|
35
|
+
avgX /= size;
|
|
36
|
+
avgY /= size;
|
|
37
|
+
// Get the range for this bucket.
|
|
38
|
+
let frameStart = Math.floor((i + 0) * every) + 1;
|
|
39
|
+
const frameEnd = Math.floor((i + 1) * every) + 1;
|
|
40
|
+
// Point a.
|
|
41
|
+
const pointA = [x(a), y(a)];
|
|
42
|
+
maxArea = area = -1;
|
|
43
|
+
for (; frameStart < frameEnd; frameStart++) {
|
|
44
|
+
// Calculate triangle area over three buckets.
|
|
45
|
+
area =
|
|
46
|
+
Math.abs((pointA[0] - avgX) * (x(frameStart) - pointA[1]) -
|
|
47
|
+
(pointA[0] - y(frameStart)) * (avgY - pointA[0])) * 0.5;
|
|
48
|
+
if (area > maxArea) {
|
|
49
|
+
maxArea = area;
|
|
50
|
+
nextA = frameStart; // Next a is this b.
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
sampled.push(nextA); // Pick this point from the bucket.
|
|
54
|
+
a = nextA; // This a is the next a (chosen b).
|
|
55
|
+
}
|
|
56
|
+
sampled.push(length - 1); // Always add last.
|
|
57
|
+
return sampled.map((a) => I[a]);
|
|
58
|
+
}
|
|
59
|
+
exports.lttb = lttb;
|
|
60
|
+
//# sourceMappingURL=lttb.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lttb.js","sourceRoot":"src/","sources":["transform/utils/lttb.ts"],"names":[],"mappings":"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"}
|
package/lib/utils/event.d.ts
CHANGED
|
@@ -12,5 +12,3 @@ export declare enum CHART_LIFE_CIRCLE {
|
|
|
12
12
|
BEFORE_CHANGE_SIZE = "beforechangesize",
|
|
13
13
|
AFTER_CHANGE_SIZE = "afterchangesize"
|
|
14
14
|
}
|
|
15
|
-
export declare function emitEvent(event: Record<string, EventListener[]>, eventName: string, ...args: any[]): void;
|
|
16
|
-
export declare function offEvent(event: Record<string, EventListener[]>, eventName?: string): void;
|
package/lib/utils/event.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.CHART_LIFE_CIRCLE = void 0;
|
|
4
4
|
// Life cycle stage.
|
|
5
5
|
var CHART_LIFE_CIRCLE;
|
|
6
6
|
(function (CHART_LIFE_CIRCLE) {
|
|
@@ -17,24 +17,4 @@ var CHART_LIFE_CIRCLE;
|
|
|
17
17
|
CHART_LIFE_CIRCLE["BEFORE_CHANGE_SIZE"] = "beforechangesize";
|
|
18
18
|
CHART_LIFE_CIRCLE["AFTER_CHANGE_SIZE"] = "afterchangesize";
|
|
19
19
|
})(CHART_LIFE_CIRCLE = exports.CHART_LIFE_CIRCLE || (exports.CHART_LIFE_CIRCLE = {}));
|
|
20
|
-
function emitEvent(event, eventName, ...args) {
|
|
21
|
-
if (!event)
|
|
22
|
-
return;
|
|
23
|
-
const listeners = event[eventName] || [];
|
|
24
|
-
listeners.forEach((listener) => {
|
|
25
|
-
listener.apply(this, args);
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
exports.emitEvent = emitEvent;
|
|
29
|
-
function offEvent(event, eventName) {
|
|
30
|
-
if (!event)
|
|
31
|
-
return;
|
|
32
|
-
// Unbind all event.
|
|
33
|
-
if (!eventName) {
|
|
34
|
-
event = {};
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
delete event[eventName];
|
|
38
|
-
}
|
|
39
|
-
exports.offEvent = offEvent;
|
|
40
20
|
//# sourceMappingURL=event.js.map
|
package/lib/utils/event.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event.js","sourceRoot":"src/","sources":["utils/event.ts"],"names":[],"mappings":";;;AAAA,oBAAoB;AACpB,IAAY,iBAkBX;AAlBD,WAAY,iBAAiB;IAC3B,mDAA8B,CAAA;IAC9B,iDAA4B,CAAA;IAE5B,iDAA4B,CAAA;IAC5B,+CAA0B,CAAA;IAE1B,4DAAuC,CAAA;IACvC,0DAAqC,CAAA;IAErC,iDAA4B,CAAA;IAC5B,+CAA0B,CAAA;IAE1B,qDAAgC,CAAA;IAChC,mDAA8B,CAAA;IAE9B,4DAAuC,CAAA;IACvC,0DAAqC,CAAA;AACvC,CAAC,EAlBW,iBAAiB,GAAjB,yBAAiB,KAAjB,yBAAiB,QAkB5B
|
|
1
|
+
{"version":3,"file":"event.js","sourceRoot":"src/","sources":["utils/event.ts"],"names":[],"mappings":";;;AAAA,oBAAoB;AACpB,IAAY,iBAkBX;AAlBD,WAAY,iBAAiB;IAC3B,mDAA8B,CAAA;IAC9B,iDAA4B,CAAA;IAE5B,iDAA4B,CAAA;IAC5B,+CAA0B,CAAA;IAE1B,4DAAuC,CAAA;IACvC,0DAAqC,CAAA;IAErC,iDAA4B,CAAA;IAC5B,+CAA0B,CAAA;IAE1B,qDAAgC,CAAA;IAChC,mDAA8B,CAAA;IAE9B,4DAAuC,CAAA;IACvC,0DAAqC,CAAA;AACvC,CAAC,EAlBW,iBAAiB,GAAjB,yBAAiB,KAAjB,yBAAiB,QAkB5B"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.domainOf = exports.invert = exports.isOrdinalScale = void 0;
|
|
4
|
+
const d3_array_1 = require("d3-array");
|
|
5
|
+
function constrain(x, lo, hi) {
|
|
6
|
+
return Math.min(hi, Math.max(lo, x));
|
|
7
|
+
}
|
|
8
|
+
function isOrdinalScale(scale) {
|
|
9
|
+
return scale.getBandWidth;
|
|
10
|
+
}
|
|
11
|
+
exports.isOrdinalScale = isOrdinalScale;
|
|
12
|
+
function invert(scale, x, start) {
|
|
13
|
+
if (!isOrdinalScale(scale))
|
|
14
|
+
return scale.invert(x);
|
|
15
|
+
const { adjustedRange } = scale;
|
|
16
|
+
const { domain } = scale.getOptions();
|
|
17
|
+
const offset = start ? -1 : 0;
|
|
18
|
+
const step = scale.getStep();
|
|
19
|
+
const range = start ? adjustedRange : adjustedRange.map((d) => d + step);
|
|
20
|
+
// R[i0 - 1] < x <= R[i0]
|
|
21
|
+
const i0 = (0, d3_array_1.bisectLeft)(range, x);
|
|
22
|
+
const i1 = constrain(i0 + offset, 0, domain.length - 1);
|
|
23
|
+
return domain[i1];
|
|
24
|
+
}
|
|
25
|
+
exports.invert = invert;
|
|
26
|
+
function domainOf(scale, values) {
|
|
27
|
+
if (!isOrdinalScale(scale))
|
|
28
|
+
return (0, d3_array_1.sort)(values);
|
|
29
|
+
const { domain } = scale.getOptions();
|
|
30
|
+
const [v1, v2] = values;
|
|
31
|
+
const start = domain.indexOf(v1);
|
|
32
|
+
const end = domain.indexOf(v2);
|
|
33
|
+
return domain.slice(start, end + 1);
|
|
34
|
+
}
|
|
35
|
+
exports.domainOf = domainOf;
|
|
36
|
+
//# sourceMappingURL=scale.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scale.js","sourceRoot":"src/","sources":["utils/scale.ts"],"names":[],"mappings":";;;AAAA,uCAA4C;AAE5C,SAAS,SAAS,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE;IAC1B,OAAO,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC;AACvC,CAAC;AAED,SAAgB,cAAc,CAAC,KAAK;IAClC,OAAO,KAAK,CAAC,YAAY,CAAC;AAC5B,CAAC;AAFD,wCAEC;AAED,SAAgB,MAAM,CAAC,KAAK,EAAE,CAAC,EAAE,KAAK;IACpC,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IACnD,MAAM,EAAE,aAAa,EAAE,GAAG,KAAK,CAAC;IAChC,MAAM,EAAE,MAAM,EAAE,GAAG,KAAK,CAAC,UAAU,EAAE,CAAC;IACtC,MAAM,MAAM,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAC9B,MAAM,IAAI,GAAG,KAAK,CAAC,OAAO,EAAE,CAAC;IAC7B,MAAM,KAAK,GAAG,KAAK,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;IACzE,yBAAyB;IACzB,MAAM,EAAE,GAAG,IAAA,qBAAU,EAAC,KAAK,EAAE,CAAC,CAAC,CAAC;IAChC,MAAM,EAAE,GAAG,SAAS,CAAC,EAAE,GAAG,MAAM,EAAE,CAAC,EAAE,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IACxD,OAAO,MAAM,CAAC,EAAE,CAAC,CAAC;AACpB,CAAC;AAXD,wBAWC;AAED,SAAgB,QAAQ,CAAC,KAAK,EAAE,MAAM;IACpC,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC;QAAE,OAAO,IAAA,eAAI,EAAC,MAAM,CAAC,CAAC;IAChD,MAAM,EAAE,MAAM,EAAE,GAAG,KAAK,CAAC,UAAU,EAAE,CAAC;IACtC,MAAM,CAAC,EAAE,EAAE,EAAE,CAAC,GAAG,MAAM,CAAC;IACxB,MAAM,KAAK,GAAG,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;IACjC,MAAM,GAAG,GAAG,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;IAC/B,OAAO,MAAM,CAAC,KAAK,CAAC,KAAK,EAAE,GAAG,GAAG,CAAC,CAAC,CAAC;AACtC,CAAC;AAPD,4BAOC"}
|
package/lib/utils/vector.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ export declare function dist([x0, y0]: Vector2, [x1, y1]: Vector2): number;
|
|
|
6
6
|
*/
|
|
7
7
|
export declare function angle([x, y]: Vector2): number;
|
|
8
8
|
/**
|
|
9
|
-
* Calculate angle of [x, y]then + Math.PI / 2.
|
|
9
|
+
* Calculate angle of [x, y], then + Math.PI / 2.
|
|
10
10
|
* Because of the difference between `Geometric coordinate system` and `Visualization coordinate system`.
|
|
11
11
|
* @returns
|
|
12
12
|
*/
|
package/lib/utils/vector.js
CHANGED
|
@@ -17,7 +17,7 @@ function angle([x, y]) {
|
|
|
17
17
|
}
|
|
18
18
|
exports.angle = angle;
|
|
19
19
|
/**
|
|
20
|
-
* Calculate angle of [x, y]then + Math.PI / 2.
|
|
20
|
+
* Calculate angle of [x, y], then + Math.PI / 2.
|
|
21
21
|
* Because of the difference between `Geometric coordinate system` and `Visualization coordinate system`.
|
|
22
22
|
* @returns
|
|
23
23
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@antv/g2",
|
|
3
|
-
"version": "5.0.0-beta.
|
|
3
|
+
"version": "5.0.0-beta.8",
|
|
4
4
|
"description": "the Grammar of Graphics in Javascript",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -121,14 +121,15 @@
|
|
|
121
121
|
},
|
|
122
122
|
"dependencies": {
|
|
123
123
|
"@antv/coord": "^0.4.1",
|
|
124
|
+
"@antv/event-emitter": "^0.1.3",
|
|
124
125
|
"@antv/g": "^5.7.4",
|
|
125
126
|
"@antv/g-canvas": "^1.7.4",
|
|
126
127
|
"@antv/g-plugin-dragndrop": "^1.6.1",
|
|
127
|
-
"@antv/gui": "^0.4.3-alpha.
|
|
128
|
+
"@antv/gui": "^0.4.3-alpha.65",
|
|
128
129
|
"@antv/path-util": "^3.0.1",
|
|
129
130
|
"@antv/scale": "^0.4.7",
|
|
130
131
|
"@antv/util": "^2.0.17",
|
|
131
|
-
"d3-array": "^3.
|
|
132
|
+
"d3-array": "^3.2.2",
|
|
132
133
|
"d3-dsv": "^3.0.1",
|
|
133
134
|
"d3-force": "^3.0.0",
|
|
134
135
|
"d3-format": "^3.1.0",
|
package/src/.DS_Store
ADDED
|
Binary file
|
package/src/api/chart.ts
CHANGED
|
@@ -2,10 +2,11 @@ import { RendererPlugin, Canvas as GCanvas } from '@antv/g';
|
|
|
2
2
|
import { Renderer as CanvasRenderer } from '@antv/g-canvas';
|
|
3
3
|
import { Plugin as DragAndDropPlugin } from '@antv/g-plugin-dragndrop';
|
|
4
4
|
import { debounce } from '@antv/util';
|
|
5
|
+
import EventEmitter from '@antv/event-emitter';
|
|
5
6
|
import { G2Context, render, destroy } from '../runtime';
|
|
6
7
|
import { ViewComposition } from '../spec';
|
|
7
8
|
import { getChartSize } from '../utils/size';
|
|
8
|
-
import { CHART_LIFE_CIRCLE
|
|
9
|
+
import { CHART_LIFE_CIRCLE } from '../utils/event';
|
|
9
10
|
import { Node } from './node';
|
|
10
11
|
import {
|
|
11
12
|
defineProps,
|
|
@@ -20,7 +21,7 @@ import {
|
|
|
20
21
|
ObjectAttribute,
|
|
21
22
|
} from './types';
|
|
22
23
|
import { mark, Mark } from './mark';
|
|
23
|
-
import { composition, Composition } from './composition';
|
|
24
|
+
import { composition, Composition, View } from './composition';
|
|
24
25
|
import { library } from './library';
|
|
25
26
|
|
|
26
27
|
function normalizeContainer(container: string | HTMLElement): HTMLElement {
|
|
@@ -133,7 +134,6 @@ export interface Chart extends Composition, Mark {
|
|
|
133
134
|
transform: ArrayAttribute<ChartProps['transform'], Chart>;
|
|
134
135
|
theme: ObjectAttribute<ChartProps['theme'], Chart>;
|
|
135
136
|
title: ObjectAttribute<ChartProps['title'], Chart>;
|
|
136
|
-
on: ObjectAttribute<ChartProps['on'], Chart>;
|
|
137
137
|
scale: ObjectAttribute<ChartOptions['scale'], Chart>;
|
|
138
138
|
axis: ObjectAttribute<ChartOptions['axis'], Chart>;
|
|
139
139
|
legend: ObjectAttribute<ChartOptions['legend'], Chart>;
|
|
@@ -151,7 +151,6 @@ export const props: NodePropertyDescriptor[] = [
|
|
|
151
151
|
{ name: 'key', type: 'value' },
|
|
152
152
|
{ name: 'transform', type: 'array' },
|
|
153
153
|
{ name: 'theme', type: 'object' },
|
|
154
|
-
{ name: 'on', type: 'event' },
|
|
155
154
|
{ name: 'scale', type: 'object' },
|
|
156
155
|
{ name: 'axis', type: 'object' },
|
|
157
156
|
{ name: 'legend', type: 'object' },
|
|
@@ -161,19 +160,21 @@ export const props: NodePropertyDescriptor[] = [
|
|
|
161
160
|
];
|
|
162
161
|
|
|
163
162
|
@defineProps(props)
|
|
164
|
-
export class Chart extends
|
|
163
|
+
export class Chart extends View<ChartOptions> {
|
|
165
164
|
private _container: HTMLElement;
|
|
166
165
|
private _context: G2Context;
|
|
166
|
+
private _emitter: EventEmitter;
|
|
167
167
|
|
|
168
168
|
constructor(options: ChartOptions = {}) {
|
|
169
169
|
const { container, ...rest } = options;
|
|
170
170
|
super(rest, 'view');
|
|
171
171
|
this._container = normalizeContainer(container);
|
|
172
|
-
this.
|
|
172
|
+
this._emitter = new EventEmitter();
|
|
173
|
+
this._context = { library, emitter: this._emitter };
|
|
173
174
|
this.bindAutoFit();
|
|
174
175
|
}
|
|
175
176
|
|
|
176
|
-
render(): Chart {
|
|
177
|
+
render(): Promise<Chart> {
|
|
177
178
|
if (!this._context.canvas) {
|
|
178
179
|
// Init width and height.
|
|
179
180
|
const {
|
|
@@ -201,9 +202,10 @@ export class Chart extends Node<ChartOptions> {
|
|
|
201
202
|
plugins,
|
|
202
203
|
);
|
|
203
204
|
}
|
|
204
|
-
render(this.options(), this._context);
|
|
205
205
|
|
|
206
|
-
return
|
|
206
|
+
return new Promise((resolve) => {
|
|
207
|
+
render(this.options(), this._context, () => resolve(this));
|
|
208
|
+
});
|
|
207
209
|
}
|
|
208
210
|
|
|
209
211
|
options() {
|
|
@@ -218,23 +220,41 @@ export class Chart extends Node<ChartOptions> {
|
|
|
218
220
|
return this._context;
|
|
219
221
|
}
|
|
220
222
|
|
|
223
|
+
on(event: string, callback: (...args: any[]) => any, once?: boolean): this {
|
|
224
|
+
this._emitter.on(event, callback, once);
|
|
225
|
+
return this;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
once(event: string, callback: (...args: any[]) => any): this {
|
|
229
|
+
this._emitter.once(event, callback);
|
|
230
|
+
return this;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
emit(event: string, ...args: any[]): this {
|
|
234
|
+
this._emitter.emit(event, ...args);
|
|
235
|
+
return this;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
off(event?: string, callback?: (...args: any[]) => any) {
|
|
239
|
+
this._emitter.off(event, callback);
|
|
240
|
+
return this;
|
|
241
|
+
}
|
|
242
|
+
|
|
221
243
|
destroy() {
|
|
222
244
|
const options = this.options();
|
|
223
|
-
|
|
224
|
-
emitEvent(on, CHART_LIFE_CIRCLE.BEFORE_DESTROY);
|
|
245
|
+
this.emit(CHART_LIFE_CIRCLE.BEFORE_DESTROY);
|
|
225
246
|
this.unbindAutoFit();
|
|
226
247
|
destroy(options, this._context);
|
|
227
248
|
// Remove the container.
|
|
228
249
|
removeContainer(this._container);
|
|
229
|
-
|
|
250
|
+
this.emit(CHART_LIFE_CIRCLE.AFTER_DESTROY);
|
|
230
251
|
}
|
|
231
252
|
|
|
232
253
|
clear() {
|
|
233
254
|
const options = this.options();
|
|
234
|
-
|
|
235
|
-
emitEvent(on, CHART_LIFE_CIRCLE.BEFORE_CLEAR);
|
|
255
|
+
this.emit(CHART_LIFE_CIRCLE.BEFORE_CLEAR);
|
|
236
256
|
destroy(options, this._context);
|
|
237
|
-
|
|
257
|
+
this.emit(CHART_LIFE_CIRCLE.AFTER_CLEAR);
|
|
238
258
|
}
|
|
239
259
|
|
|
240
260
|
forceFit() {
|
|
@@ -256,11 +276,12 @@ export class Chart extends Node<ChartOptions> {
|
|
|
256
276
|
return this;
|
|
257
277
|
}
|
|
258
278
|
|
|
259
|
-
|
|
279
|
+
this.emit(CHART_LIFE_CIRCLE.BEFORE_CHANGE_SIZE);
|
|
260
280
|
this.width(adjustedWidth);
|
|
261
281
|
this.height(adjustedHeight);
|
|
262
|
-
this.render()
|
|
263
|
-
|
|
282
|
+
return this.render().then(() => {
|
|
283
|
+
this.emit(CHART_LIFE_CIRCLE.AFTER_CHANGE_SIZE);
|
|
284
|
+
});
|
|
264
285
|
}
|
|
265
286
|
|
|
266
287
|
private onResize = debounce(() => {
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { DisplayObject } from '@antv/g';
|
|
2
|
+
import { Coordinate } from '@antv/coord';
|
|
3
|
+
import { defineProps } from '../props';
|
|
4
|
+
import { Node } from '../node';
|
|
5
|
+
import { G2Theme, G2ViewDescriptor } from '../../runtime';
|
|
6
|
+
|
|
7
|
+
@defineProps([{ name: 'on', type: 'event' }])
|
|
8
|
+
export class Base<
|
|
9
|
+
Value extends Record<string, any> = Record<string, any>,
|
|
10
|
+
ParentValue extends Record<string, any> = Record<string, any>,
|
|
11
|
+
ChildValue extends Record<string, any> = Record<string, any>,
|
|
12
|
+
> extends Node<Value, ParentValue, ChildValue> {
|
|
13
|
+
/**
|
|
14
|
+
* Get view instance by key.
|
|
15
|
+
*/
|
|
16
|
+
getView(): G2ViewDescriptor {
|
|
17
|
+
const chart = this.root();
|
|
18
|
+
const { views } = chart.context();
|
|
19
|
+
if (!views?.length) return undefined;
|
|
20
|
+
return views.find((view) => view.key === this.attr('key'));
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
getCoordinate(): Coordinate {
|
|
24
|
+
return this.getView()?.coordinate;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
getTheme(): G2Theme {
|
|
28
|
+
return this.getView()?.theme;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
getGroup(): DisplayObject {
|
|
32
|
+
const key = this.attr('key');
|
|
33
|
+
if (!key) return undefined;
|
|
34
|
+
const chart = this.root();
|
|
35
|
+
const chartGroup = chart.context().canvas.getRoot();
|
|
36
|
+
return chartGroup.getElementById(key);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Show the view.
|
|
41
|
+
*/
|
|
42
|
+
show() {
|
|
43
|
+
const group = this.getGroup();
|
|
44
|
+
if (!group) return;
|
|
45
|
+
!group.isVisible() && group.setAttribute('visibility', 'visible');
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Hide the view.
|
|
50
|
+
*/
|
|
51
|
+
hide() {
|
|
52
|
+
const group = this.getGroup();
|
|
53
|
+
if (!group) return;
|
|
54
|
+
group.isVisible() && group.setAttribute('visibility', 'hidden');
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -6,9 +6,8 @@ import {
|
|
|
6
6
|
ArrayAttribute,
|
|
7
7
|
ObjectAttribute,
|
|
8
8
|
} from '../types';
|
|
9
|
-
import { Node } from '../node';
|
|
10
9
|
import { mark, Mark } from '../mark';
|
|
11
|
-
import { Composition } from './index';
|
|
10
|
+
import { Composition, Base } from './index';
|
|
12
11
|
|
|
13
12
|
type FacetCircleSpec = Concrete<FacetCircleComposition>;
|
|
14
13
|
|
|
@@ -30,7 +29,7 @@ export interface FacetCircle extends Composition, Mark {
|
|
|
30
29
|
{ type: 'object', name: 'axis' },
|
|
31
30
|
...nodeProps(mark),
|
|
32
31
|
])
|
|
33
|
-
export class FacetCircle extends
|
|
32
|
+
export class FacetCircle extends Base<FacetCircleComposition> {
|
|
34
33
|
constructor() {
|
|
35
34
|
super({}, 'facetCircle');
|
|
36
35
|
}
|
|
@@ -6,9 +6,8 @@ import {
|
|
|
6
6
|
ArrayAttribute,
|
|
7
7
|
ObjectAttribute,
|
|
8
8
|
} from '../types';
|
|
9
|
-
import { Node } from '../node';
|
|
10
9
|
import { mark, Mark } from '../mark';
|
|
11
|
-
import { Composition } from './index';
|
|
10
|
+
import { Composition, Base } from './index';
|
|
12
11
|
|
|
13
12
|
type FacetRectSpec = Concrete<FacetRectComposition>;
|
|
14
13
|
|
|
@@ -30,7 +29,7 @@ export interface FacetRect extends Composition, Mark {
|
|
|
30
29
|
{ type: 'object', name: 'axis' },
|
|
31
30
|
...nodeProps(mark),
|
|
32
31
|
])
|
|
33
|
-
export class FacetRect extends
|
|
32
|
+
export class FacetRect extends Base<FacetRectComposition> {
|
|
34
33
|
constructor() {
|
|
35
34
|
super({}, 'facetRect');
|
|
36
35
|
}
|
|
@@ -6,9 +6,8 @@ import {
|
|
|
6
6
|
ArrayAttribute,
|
|
7
7
|
Concrete,
|
|
8
8
|
} from '../types';
|
|
9
|
-
import { Node } from '../node';
|
|
10
9
|
import { mark, Mark } from '../mark';
|
|
11
|
-
import { Composition } from './index';
|
|
10
|
+
import { Composition, Base } from './index';
|
|
12
11
|
|
|
13
12
|
type GeoPathSpec = Concrete<GeoPathComposition>;
|
|
14
13
|
|
|
@@ -36,7 +35,7 @@ export interface GeoPath extends Mark, Composition {
|
|
|
36
35
|
{ type: 'object', name: 'legend' },
|
|
37
36
|
...nodeProps(mark),
|
|
38
37
|
])
|
|
39
|
-
export class GeoPath extends
|
|
38
|
+
export class GeoPath extends Base<GeoPathComposition> {
|
|
40
39
|
constructor() {
|
|
41
40
|
super({}, 'geoPath');
|
|
42
41
|
}
|
|
@@ -6,9 +6,8 @@ import {
|
|
|
6
6
|
ArrayAttribute,
|
|
7
7
|
Concrete,
|
|
8
8
|
} from '../types';
|
|
9
|
-
import { Node } from '../node';
|
|
10
9
|
import { mark, Mark } from '../mark';
|
|
11
|
-
import { Composition } from './index';
|
|
10
|
+
import { Composition, Base } from './index';
|
|
12
11
|
|
|
13
12
|
type GeoViewSpec = Concrete<GeoViewComposition>;
|
|
14
13
|
|
|
@@ -35,7 +34,7 @@ export interface GeoView extends Mark, Composition {
|
|
|
35
34
|
{ type: 'object', name: 'legend' },
|
|
36
35
|
...nodeProps(mark),
|
|
37
36
|
])
|
|
38
|
-
export class GeoView extends
|
|
37
|
+
export class GeoView extends Base<GeoViewComposition> {
|
|
39
38
|
constructor() {
|
|
40
39
|
super({}, 'geoView');
|
|
41
40
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { defineProps, nodeProps } from '../props';
|
|
2
|
+
import { Base } from './base';
|
|
2
3
|
import { View } from './view';
|
|
3
4
|
import { SpaceLayer } from './spaceLayer';
|
|
4
5
|
import { SpaceFlex } from './spaceFlex';
|
|
@@ -34,6 +35,7 @@ export interface Composition {
|
|
|
34
35
|
}
|
|
35
36
|
|
|
36
37
|
export {
|
|
38
|
+
Base,
|
|
37
39
|
View,
|
|
38
40
|
SpaceLayer,
|
|
39
41
|
SpaceFlex,
|
|
@@ -6,9 +6,8 @@ import {
|
|
|
6
6
|
ArrayAttribute,
|
|
7
7
|
ObjectAttribute,
|
|
8
8
|
} from '../types';
|
|
9
|
-
import { Node } from '../node';
|
|
10
9
|
import { mark, Mark } from '../mark';
|
|
11
|
-
import { Composition } from './index';
|
|
10
|
+
import { Composition, Base } from './index';
|
|
12
11
|
|
|
13
12
|
type RepeatMatrixSpec = Concrete<RepeatMatrixComposition>;
|
|
14
13
|
|
|
@@ -30,7 +29,7 @@ export interface RepeatMatrix extends Composition, Mark {
|
|
|
30
29
|
{ type: 'object', name: 'legend' },
|
|
31
30
|
...nodeProps(mark),
|
|
32
31
|
])
|
|
33
|
-
export class RepeatMatrix extends
|
|
32
|
+
export class RepeatMatrix extends Base<RepeatMatrixComposition> {
|
|
34
33
|
constructor() {
|
|
35
34
|
super({}, 'repeatMatrix');
|
|
36
35
|
}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { SpaceFlexComposition } from '../../spec';
|
|
2
2
|
import { defineProps, nodeProps } from '../props';
|
|
3
3
|
import { ValueAttribute, Concrete } from '../types';
|
|
4
|
-
import { Node } from '../node';
|
|
5
4
|
import { mark, Mark } from '../mark';
|
|
6
|
-
import { Composition } from './index';
|
|
5
|
+
import { Composition, Base } from './index';
|
|
7
6
|
|
|
8
7
|
type SpaceFlexSpec = Concrete<SpaceFlexComposition>;
|
|
9
8
|
|
|
@@ -12,7 +11,7 @@ export interface SpaceFlex extends Composition, Mark {
|
|
|
12
11
|
}
|
|
13
12
|
|
|
14
13
|
@defineProps([{ type: 'value', name: 'data' }, ...nodeProps(mark)])
|
|
15
|
-
export class SpaceFlex extends
|
|
14
|
+
export class SpaceFlex extends Base<SpaceFlexSpec> {
|
|
16
15
|
constructor() {
|
|
17
16
|
super({}, 'spaceFlex');
|
|
18
17
|
}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { SpaceLayerComposition } from '../../spec';
|
|
2
2
|
import { defineProps, nodeProps } from '../props';
|
|
3
3
|
import { ValueAttribute, Concrete } from '../types';
|
|
4
|
-
import { Node } from '../node';
|
|
5
4
|
import { mark, Mark } from '../mark';
|
|
6
|
-
import { Composition } from './index';
|
|
5
|
+
import { Composition, Base } from './index';
|
|
7
6
|
|
|
8
7
|
type SpaceLayerSpec = Concrete<SpaceLayerComposition>;
|
|
9
8
|
|
|
@@ -12,7 +11,7 @@ export interface SpaceLayer extends Composition, Mark {
|
|
|
12
11
|
}
|
|
13
12
|
|
|
14
13
|
@defineProps([{ type: 'value', name: 'data' }, ...nodeProps(mark)])
|
|
15
|
-
export class SpaceLayer extends
|
|
14
|
+
export class SpaceLayer extends Base<SpaceLayerComposition> {
|
|
16
15
|
constructor() {
|
|
17
16
|
super({}, 'spaceLayer');
|
|
18
17
|
}
|
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
import { TimingKeyframeComposition } from '../../spec';
|
|
2
2
|
import { defineProps, nodeProps } from '../props';
|
|
3
3
|
import { Concrete } from '../types';
|
|
4
|
-
import { Node } from '../node';
|
|
5
4
|
import { mark, Mark } from '../mark';
|
|
6
|
-
import { Composition } from './index';
|
|
5
|
+
import { Composition, Base } from './index';
|
|
7
6
|
|
|
8
7
|
type TimingKeyframeSpec = Concrete<TimingKeyframeComposition>;
|
|
9
8
|
|
|
10
9
|
export interface TimingKeyframe extends Composition, Mark {}
|
|
11
10
|
|
|
12
11
|
@defineProps([...nodeProps(mark)])
|
|
13
|
-
export class TimingKeyframe extends
|
|
12
|
+
export class TimingKeyframe extends Base<TimingKeyframeSpec> {
|
|
14
13
|
constructor() {
|
|
15
14
|
super({}, 'timingKeyframe');
|
|
16
15
|
}
|
|
@@ -6,8 +6,8 @@ import {
|
|
|
6
6
|
ArrayAttribute,
|
|
7
7
|
Concrete,
|
|
8
8
|
} from '../types';
|
|
9
|
-
import { Node } from '../node';
|
|
10
9
|
import { mark, Mark } from '../mark';
|
|
10
|
+
import { Base } from './base';
|
|
11
11
|
|
|
12
12
|
type ViewSpec = Concrete<ViewComposition>;
|
|
13
13
|
|
|
@@ -33,8 +33,10 @@ export interface View extends Mark {
|
|
|
33
33
|
{ type: 'object', name: 'legend' },
|
|
34
34
|
...nodeProps(mark),
|
|
35
35
|
])
|
|
36
|
-
export class View
|
|
37
|
-
|
|
38
|
-
|
|
36
|
+
export class View<
|
|
37
|
+
ViewProps extends ViewComposition = ViewComposition,
|
|
38
|
+
> extends Base<ViewProps> {
|
|
39
|
+
constructor(options = {}, type = 'view') {
|
|
40
|
+
super(options, type);
|
|
39
41
|
}
|
|
40
42
|
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { DisplayObject } from '@antv/g';
|
|
2
|
+
import { Node } from '../node';
|
|
3
|
+
import { G2MarkState, Scale } from '../../runtime';
|
|
4
|
+
|
|
5
|
+
export class MarkBase<
|
|
6
|
+
Value extends Record<string, any> = Record<string, any>,
|
|
7
|
+
ParentValue extends Record<string, any> = Record<string, any>,
|
|
8
|
+
ChildValue extends Record<string, any> = Record<string, any>,
|
|
9
|
+
> extends Node<Value, ParentValue, ChildValue> {
|
|
10
|
+
changeData(data: any) {
|
|
11
|
+
const chart = this.root();
|
|
12
|
+
if (!chart) return;
|
|
13
|
+
this.attr('data', data);
|
|
14
|
+
chart?.render();
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Get mark from chart views.
|
|
19
|
+
*/
|
|
20
|
+
getMark(): G2MarkState {
|
|
21
|
+
const chartView = this.root()?.getView();
|
|
22
|
+
if (!chartView) return undefined;
|
|
23
|
+
const { markState } = chartView;
|
|
24
|
+
const markKey = Array.from(markState.keys()).find(
|
|
25
|
+
(item) => item.key === this.attr('key'),
|
|
26
|
+
);
|
|
27
|
+
return markState.get(markKey);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Get all scales instance.
|
|
32
|
+
*/
|
|
33
|
+
getScale(): Record<string, Scale> {
|
|
34
|
+
const chartView = this.root()?.getView();
|
|
35
|
+
if (!chartView) return undefined;
|
|
36
|
+
return chartView?.scale;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Get the scale instance by channel.
|
|
41
|
+
*/
|
|
42
|
+
getScaleByChannel(channel: string): Scale {
|
|
43
|
+
const chartView = this.root()?.getView();
|
|
44
|
+
if (!chartView) return undefined;
|
|
45
|
+
return chartView?.scale?.[channel];
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Get canvas group.
|
|
50
|
+
*/
|
|
51
|
+
getGroup(): DisplayObject {
|
|
52
|
+
const key = this.attr('key');
|
|
53
|
+
if (!key) return undefined;
|
|
54
|
+
const chart = this.root();
|
|
55
|
+
const chartGroup = chart.context().canvas.getRoot();
|
|
56
|
+
return chartGroup.getElementById(key);
|
|
57
|
+
}
|
|
58
|
+
}
|