@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
package/src/transform/sample.ts
CHANGED
|
@@ -1,14 +1,46 @@
|
|
|
1
|
+
// @ts-ignore medianIndex exist in d3-array@3.2.0, but @types/d3-array Expired.
|
|
2
|
+
import { maxIndex, minIndex, medianIndex } from 'd3-array';
|
|
1
3
|
import { TransformComponent as TC, Primitive } from '../runtime';
|
|
2
|
-
import { SampleTransform } from '../spec';
|
|
4
|
+
import { SampleTransform, SampleFunction } from '../spec';
|
|
3
5
|
import { createGroups } from './utils/order';
|
|
4
|
-
import {
|
|
6
|
+
import { columnOf } from './utils/helper';
|
|
7
|
+
import { lttb } from './utils/lttb';
|
|
5
8
|
|
|
6
9
|
export type SampleOptions = Omit<SampleTransform, 'type'>;
|
|
7
10
|
|
|
11
|
+
function normalizeSample(
|
|
12
|
+
strategy: SampleTransform['strategy'],
|
|
13
|
+
): SampleFunction {
|
|
14
|
+
if (typeof strategy === 'function') return strategy;
|
|
15
|
+
if (strategy === 'lttb') return lttb;
|
|
16
|
+
|
|
17
|
+
const strategies = {
|
|
18
|
+
first: (f: number[]) => [f[0]],
|
|
19
|
+
last: (f: number[]) => [f[f.length - 1]],
|
|
20
|
+
min: (f: number[], X: number[], Y: number[]) => [
|
|
21
|
+
f[minIndex(f, (i) => Y[i])],
|
|
22
|
+
],
|
|
23
|
+
max: (f: number[], X: number[], Y: number[]) => [
|
|
24
|
+
f[maxIndex(f, (i) => Y[i])],
|
|
25
|
+
],
|
|
26
|
+
median: (f: number[], X: number[], Y: number[]) => [
|
|
27
|
+
f[medianIndex(f, (i) => Y[i])],
|
|
28
|
+
],
|
|
29
|
+
};
|
|
30
|
+
const sampleFunction = strategies[strategy] || strategies.median;
|
|
31
|
+
return (I: number[], X: number[], Y: number[], thresholds: number) => {
|
|
32
|
+
// Sepreate group to frames, then sample each frame.
|
|
33
|
+
// Keep more data as possible.
|
|
34
|
+
const frameSize = Math.max(1, Math.floor(I.length / thresholds));
|
|
35
|
+
const frames = getFrames(I, frameSize);
|
|
36
|
+
return frames.flatMap((frame) => sampleFunction(frame, X, Y));
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
8
40
|
/**
|
|
9
41
|
* Split the array into frame with each frameSize.
|
|
10
42
|
*/
|
|
11
|
-
function getFrames(I: Primitive[], frameSize: number) {
|
|
43
|
+
function getFrames(I: Primitive[], frameSize: number): number[][] {
|
|
12
44
|
const size = I.length;
|
|
13
45
|
const frames = [];
|
|
14
46
|
let i = 0;
|
|
@@ -23,22 +55,26 @@ function getFrames(I: Primitive[], frameSize: number) {
|
|
|
23
55
|
* sample data for each group when data.length >= threshold(default = 2000).
|
|
24
56
|
*/
|
|
25
57
|
export const Sample: TC<SampleOptions> = (options = {}) => {
|
|
26
|
-
const {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
58
|
+
const {
|
|
59
|
+
strategy = 'median',
|
|
60
|
+
thresholds = 2000,
|
|
61
|
+
groupBy = 'series',
|
|
62
|
+
} = options;
|
|
63
|
+
const sampleFunction = normalizeSample(strategy);
|
|
64
|
+
|
|
65
|
+
return (I, mark) => {
|
|
66
|
+
const { encode } = mark;
|
|
67
|
+
const groups = createGroups(groupBy, I, mark);
|
|
68
|
+
const [X] = columnOf(encode, 'x');
|
|
69
|
+
const [Y] = columnOf(encode, 'y');
|
|
70
|
+
|
|
71
|
+
return [
|
|
72
|
+
groups.flatMap((g) =>
|
|
73
|
+
sampleFunction(g, X as number[], Y as number[], thresholds),
|
|
74
|
+
),
|
|
75
|
+
mark,
|
|
76
|
+
];
|
|
40
77
|
};
|
|
41
|
-
return GroupN({ ...rest, groupBy });
|
|
42
78
|
};
|
|
43
79
|
|
|
44
80
|
Sample.props = {};
|
package/src/transform/select.ts
CHANGED
|
@@ -39,11 +39,10 @@ function normalizeSelector(selector: Selector): SelectorFunction {
|
|
|
39
39
|
* pull a single or multiple values out of each series.
|
|
40
40
|
*/
|
|
41
41
|
export const Select: TC<SelectOptions> = (options = {}) => {
|
|
42
|
-
const { groupBy = 'series',
|
|
42
|
+
const { groupBy = 'series', channel, selector } = options;
|
|
43
43
|
return (I, mark) => {
|
|
44
44
|
const { encode } = mark;
|
|
45
45
|
const groups = createGroups(groupBy, I, mark);
|
|
46
|
-
const [channel, selector] = Object.entries(rest)[0];
|
|
47
46
|
const [V] = columnOf(encode, channel);
|
|
48
47
|
const selectFunction = normalizeSelector(selector);
|
|
49
48
|
return [groups.flatMap((GI) => selectFunction(GI, V as number[])), mark];
|
package/src/transform/selectX.ts
CHANGED
|
@@ -9,7 +9,7 @@ export type SelectXOptions = Omit<SelectXTransform, 'type'>;
|
|
|
9
9
|
*/
|
|
10
10
|
export const SelectX: TC<SelectXOptions> = (options = {}) => {
|
|
11
11
|
const { selector, ...rest } = options;
|
|
12
|
-
return Select({
|
|
12
|
+
return Select({ channel: 'x', selector, ...rest });
|
|
13
13
|
};
|
|
14
14
|
|
|
15
15
|
SelectX.props = {};
|
package/src/transform/selectY.ts
CHANGED
|
@@ -9,7 +9,7 @@ export type SelectYOptions = Omit<SelectYTransform, 'type'>;
|
|
|
9
9
|
*/
|
|
10
10
|
export const SelectY: TC<SelectYOptions> = (options = {}) => {
|
|
11
11
|
const { selector, ...rest } = options;
|
|
12
|
-
return Select({
|
|
12
|
+
return Select({ channel: 'y', selector, ...rest });
|
|
13
13
|
};
|
|
14
14
|
|
|
15
15
|
SelectY.props = {};
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sample data with lttb(Largest-Triangle-Three-Buckets) algo (https://github.com/pingec/downsample-lttb).
|
|
3
|
+
* Return the sampled index array.
|
|
4
|
+
*/
|
|
5
|
+
export function lttb(
|
|
6
|
+
I: number[],
|
|
7
|
+
X: number[],
|
|
8
|
+
Y: number[],
|
|
9
|
+
thresholds: number,
|
|
10
|
+
): number[] {
|
|
11
|
+
const length = I.length;
|
|
12
|
+
if (thresholds >= length || thresholds === 0) {
|
|
13
|
+
return I;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const x = (i: number) => X[I[i]] * 1;
|
|
17
|
+
const y = (i: number) => Y[I[i]] * 1;
|
|
18
|
+
const sampled = [];
|
|
19
|
+
|
|
20
|
+
// Bucket size. Leave room for start and end data points.
|
|
21
|
+
const every = (length - 2) / (thresholds - 2);
|
|
22
|
+
|
|
23
|
+
let a = 0; // Initially a is the first point in the triangle.
|
|
24
|
+
let maxArea;
|
|
25
|
+
let area;
|
|
26
|
+
let nextA;
|
|
27
|
+
|
|
28
|
+
sampled.push(a); // Always add the first point.
|
|
29
|
+
|
|
30
|
+
for (let i = 0; i < thresholds - 2; i++) {
|
|
31
|
+
// Calculate point average for next bucket (containing c).
|
|
32
|
+
let avgX = 0;
|
|
33
|
+
let avgY = 0;
|
|
34
|
+
let start = Math.floor((i + 1) * every) + 1;
|
|
35
|
+
let end = Math.floor((i + 2) * every) + 1;
|
|
36
|
+
end = Math.min(end, length);
|
|
37
|
+
const size = end - start;
|
|
38
|
+
|
|
39
|
+
for (; start < end; start++) {
|
|
40
|
+
avgX += x(start);
|
|
41
|
+
avgY += y(start);
|
|
42
|
+
}
|
|
43
|
+
avgX /= size;
|
|
44
|
+
avgY /= size;
|
|
45
|
+
|
|
46
|
+
// Get the range for this bucket.
|
|
47
|
+
let frameStart = Math.floor((i + 0) * every) + 1;
|
|
48
|
+
const frameEnd = Math.floor((i + 1) * every) + 1;
|
|
49
|
+
|
|
50
|
+
// Point a.
|
|
51
|
+
const pointA = [x(a), y(a)];
|
|
52
|
+
maxArea = area = -1;
|
|
53
|
+
for (; frameStart < frameEnd; frameStart++) {
|
|
54
|
+
// Calculate triangle area over three buckets.
|
|
55
|
+
area =
|
|
56
|
+
Math.abs(
|
|
57
|
+
(pointA[0] - avgX) * (x(frameStart) - pointA[1]) -
|
|
58
|
+
(pointA[0] - y(frameStart)) * (avgY - pointA[0]),
|
|
59
|
+
) * 0.5;
|
|
60
|
+
if (area > maxArea) {
|
|
61
|
+
maxArea = area;
|
|
62
|
+
nextA = frameStart; // Next a is this b.
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
sampled.push(nextA); // Pick this point from the bucket.
|
|
67
|
+
a = nextA; // This a is the next a (chosen b).
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
sampled.push(length - 1); // Always add last.
|
|
71
|
+
|
|
72
|
+
return sampled.map((a) => I[a]);
|
|
73
|
+
}
|
package/src/utils/event.ts
CHANGED
|
@@ -18,29 +18,3 @@ export enum CHART_LIFE_CIRCLE {
|
|
|
18
18
|
BEFORE_CHANGE_SIZE = 'beforechangesize',
|
|
19
19
|
AFTER_CHANGE_SIZE = 'afterchangesize',
|
|
20
20
|
}
|
|
21
|
-
|
|
22
|
-
export function emitEvent(
|
|
23
|
-
event: Record<string, EventListener[]>,
|
|
24
|
-
eventName: string,
|
|
25
|
-
...args: any[]
|
|
26
|
-
) {
|
|
27
|
-
if (!event) return;
|
|
28
|
-
const listeners = event[eventName] || [];
|
|
29
|
-
listeners.forEach((listener) => {
|
|
30
|
-
listener.apply(this, args);
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export function offEvent(
|
|
35
|
-
event: Record<string, EventListener[]>,
|
|
36
|
-
eventName?: string,
|
|
37
|
-
) {
|
|
38
|
-
if (!event) return;
|
|
39
|
-
// Unbind all event.
|
|
40
|
-
if (!eventName) {
|
|
41
|
-
event = {};
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
delete event[eventName];
|
|
46
|
-
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { bisectLeft, sort } from 'd3-array';
|
|
2
|
+
|
|
3
|
+
function constrain(x, lo, hi) {
|
|
4
|
+
return Math.min(hi, Math.max(lo, x));
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export function isOrdinalScale(scale) {
|
|
8
|
+
return scale.getBandWidth;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function invert(scale, x, start) {
|
|
12
|
+
if (!isOrdinalScale(scale)) return scale.invert(x);
|
|
13
|
+
const { adjustedRange } = scale;
|
|
14
|
+
const { domain } = scale.getOptions();
|
|
15
|
+
const offset = start ? -1 : 0;
|
|
16
|
+
const step = scale.getStep();
|
|
17
|
+
const range = start ? adjustedRange : adjustedRange.map((d) => d + step);
|
|
18
|
+
// R[i0 - 1] < x <= R[i0]
|
|
19
|
+
const i0 = bisectLeft(range, x);
|
|
20
|
+
const i1 = constrain(i0 + offset, 0, domain.length - 1);
|
|
21
|
+
return domain[i1];
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function domainOf(scale, values) {
|
|
25
|
+
if (!isOrdinalScale(scale)) return sort(values);
|
|
26
|
+
const { domain } = scale.getOptions();
|
|
27
|
+
const [v1, v2] = values;
|
|
28
|
+
const start = domain.indexOf(v1);
|
|
29
|
+
const end = domain.indexOf(v2);
|
|
30
|
+
return domain.slice(start, end + 1);
|
|
31
|
+
}
|
package/src/utils/vector.ts
CHANGED
|
@@ -16,7 +16,7 @@ export function angle([x, y]: Vector2): number {
|
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
|
-
* Calculate angle of [x, y]then + Math.PI / 2.
|
|
19
|
+
* Calculate angle of [x, y], then + Math.PI / 2.
|
|
20
20
|
* Because of the difference between `Geometric coordinate system` and `Visualization coordinate system`.
|
|
21
21
|
* @returns
|
|
22
22
|
*/
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"d3-projection.js","sourceRoot":"src/","sources":["geo/d3-projection.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,SAAS,EACT,qBAAqB,EACrB,wBAAwB,EACxB,uBAAuB,EACvB,0BAA0B,EAC1B,iBAAiB,EACjB,oBAAoB,EACpB,iBAAiB,EACjB,oBAAoB,EACpB,mBAAmB,EACnB,sBAAsB,EACtB,aAAa,EACb,gBAAgB,EAChB,kBAAkB,EAClB,qBAAqB,EACrB,WAAW,EACX,cAAc,EACd,WAAW,EACX,aAAa,EACb,oBAAoB,EACpB,WAAW,EACX,cAAc,EACd,gBAAgB,EAChB,mBAAmB,EACnB,eAAe,EACf,kBAAkB,EAClB,gBAAgB,EAChB,mBAAmB,EACnB,qBAAqB,EACrB,wBAAwB,GACzB,MAAM,QAAQ,CAAC"}
|
package/esm/shape/area/step.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"step.js","sourceRoot":"src/","sources":["shape/area/step.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAErC,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAIhC,MAAM,CAAC,MAAM,IAAI,GAAoB,CAAC,OAAO,EAAE,EAAE;IAC/C,OAAO,CAAC,CAAC,EAAE,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,EAAE;QACrC,OAAO,KAAK,iBAAG,KAAK,EAAE,SAAS,IAAK,OAAO,EAAG,CAAC,CAAC,EAAE,KAAK,EAAE,UAAU,EAAE,KAAK,CAAC,CAAC;IAC9E,CAAC,CAAC;AACJ,CAAC,CAAC;AAEF,IAAI,CAAC,KAAK,qBACL,KAAK,CAAC,KAAK,CACf,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"d3-projection.js","sourceRoot":"src/","sources":["geo/d3-projection.ts"],"names":[],"mappings":";;;AAAA,iCAgCgB;AA/Bd,sGAAA,YAAY,OAAA;AACZ,mGAAA,SAAS,OAAA;AACT,+GAAA,qBAAqB,OAAA;AACrB,kHAAA,wBAAwB,OAAA;AACxB,iHAAA,uBAAuB,OAAA;AACvB,oHAAA,0BAA0B,OAAA;AAC1B,2GAAA,iBAAiB,OAAA;AACjB,8GAAA,oBAAoB,OAAA;AACpB,2GAAA,iBAAiB,OAAA;AACjB,8GAAA,oBAAoB,OAAA;AACpB,6GAAA,mBAAmB,OAAA;AACnB,gHAAA,sBAAsB,OAAA;AACtB,uGAAA,aAAa,OAAA;AACb,0GAAA,gBAAgB,OAAA;AAChB,4GAAA,kBAAkB,OAAA;AAClB,+GAAA,qBAAqB,OAAA;AACrB,qGAAA,WAAW,OAAA;AACX,wGAAA,cAAc,OAAA;AACd,qGAAA,WAAW,OAAA;AACX,uGAAA,aAAa,OAAA;AACb,8GAAA,oBAAoB,OAAA;AACpB,qGAAA,WAAW,OAAA;AACX,wGAAA,cAAc,OAAA;AACd,0GAAA,gBAAgB,OAAA;AAChB,6GAAA,mBAAmB,OAAA;AACnB,yGAAA,eAAe,OAAA;AACf,4GAAA,kBAAkB,OAAA;AAClB,0GAAA,gBAAgB,OAAA;AAChB,6GAAA,mBAAmB,OAAA;AACnB,+GAAA,qBAAqB,OAAA;AACrB,kHAAA,wBAAwB,OAAA"}
|
package/lib/shape/area/step.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"step.js","sourceRoot":"src/","sources":["shape/area/step.ts"],"names":[],"mappings":";;;AAAA,uCAAqC;AAErC,mCAAgC;AAIzB,MAAM,IAAI,GAAoB,CAAC,OAAO,EAAE,EAAE;IAC/C,OAAO,CAAC,CAAC,EAAE,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,EAAE;QACrC,OAAO,IAAA,aAAK,kBAAG,KAAK,EAAE,oBAAS,IAAK,OAAO,EAAG,CAAC,CAAC,EAAE,KAAK,EAAE,UAAU,EAAE,KAAK,CAAC,CAAC;IAC9E,CAAC,CAAC;AACJ,CAAC,CAAC;AAJW,QAAA,IAAI,QAIf;AAEF,YAAI,CAAC,KAAK,qBACL,aAAK,CAAC,KAAK,CACf,CAAC"}
|