@antv/g2 5.1.0 → 5.1.2
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/CHANGELOG.md +35 -0
- package/README.md +3 -3
- package/README.zh-CN.md +2 -2
- package/dist/g2-lite.min.js +1 -10
- package/dist/g2.min.js +1 -10
- package/esm/api/chart.d.ts +7 -1
- package/esm/api/chart.js.map +1 -1
- package/esm/api/extend.d.ts +2 -1
- package/esm/api/index.d.ts +1 -3
- package/esm/api/index.js +1 -3
- package/esm/api/index.js.map +1 -1
- package/esm/api/library.d.ts +1 -0
- package/esm/api/runtime.js +1 -0
- package/esm/api/runtime.js.map +1 -1
- package/esm/component/axis.js +1 -1
- package/esm/component/axis.js.map +1 -1
- package/esm/index.d.ts +2 -2
- package/esm/index.js +2 -2
- package/esm/index.js.map +1 -1
- package/esm/interaction/brushHighlight.d.ts +1 -1
- package/esm/interaction/brushHighlight.js +15 -5
- package/esm/interaction/brushHighlight.js.map +1 -1
- package/esm/interaction/tooltip.d.ts +1 -1
- package/esm/interaction/tooltip.js +88 -42
- package/esm/interaction/tooltip.js.map +1 -1
- package/esm/lib/plot.d.ts +1 -0
- package/esm/lib/plot.js +2 -1
- package/esm/lib/plot.js.map +1 -1
- package/esm/lib/std.d.ts +1 -0
- package/esm/mark/area.js +1 -1
- package/esm/mark/area.js.map +1 -1
- package/esm/mark/gauge.d.ts +1 -1
- package/esm/mark/gauge.js +14 -2
- package/esm/mark/gauge.js.map +1 -1
- package/esm/mark/index.d.ts +2 -0
- package/esm/mark/index.js +1 -0
- package/esm/mark/index.js.map +1 -1
- package/esm/mark/line.js +1 -1
- package/esm/mark/line.js.map +1 -1
- package/esm/mark/liquid.d.ts +7 -0
- package/esm/mark/liquid.js +83 -0
- package/esm/mark/liquid.js.map +1 -0
- package/esm/runtime/constant.d.ts +1 -0
- package/esm/runtime/constant.js +1 -0
- package/esm/runtime/constant.js.map +1 -1
- package/esm/runtime/plot.js +7 -1
- package/esm/runtime/plot.js.map +1 -1
- package/esm/runtime/transform.js +4 -1
- package/esm/runtime/transform.js.map +1 -1
- package/esm/shape/index.d.ts +2 -0
- package/esm/shape/index.js +1 -0
- package/esm/shape/index.js.map +1 -1
- package/esm/shape/liquid/liquid.d.ts +3 -0
- package/esm/shape/liquid/liquid.js +79 -0
- package/esm/shape/liquid/liquid.js.map +1 -0
- package/esm/shape/liquid/shapes.d.ts +38 -0
- package/esm/shape/liquid/shapes.js +93 -0
- package/esm/shape/liquid/shapes.js.map +1 -0
- package/esm/shape/liquid/wave.d.ts +16 -0
- package/esm/shape/liquid/wave.js +192 -0
- package/esm/shape/liquid/wave.js.map +1 -0
- package/esm/spec/mark.d.ts +2 -1
- package/esm/theme/light.js +2 -1
- package/esm/theme/light.js.map +1 -1
- package/esm/utils/helper.js +10 -2
- package/esm/utils/helper.js.map +1 -1
- package/lib/api/chart.d.ts +7 -1
- package/lib/api/chart.js.map +1 -1
- package/lib/api/extend.d.ts +2 -1
- package/lib/api/index.d.ts +1 -3
- package/lib/api/index.js +1 -5
- package/lib/api/index.js.map +1 -1
- package/lib/api/library.d.ts +1 -0
- package/lib/api/runtime.js +1 -0
- package/lib/api/runtime.js.map +1 -1
- package/lib/component/axis.js +1 -1
- package/lib/component/axis.js.map +1 -1
- package/lib/index.d.ts +2 -2
- package/lib/index.js +2 -3
- package/lib/index.js.map +1 -1
- package/lib/interaction/brushHighlight.d.ts +1 -1
- package/lib/interaction/brushHighlight.js +15 -5
- package/lib/interaction/brushHighlight.js.map +1 -1
- package/lib/interaction/tooltip.d.ts +1 -1
- package/lib/interaction/tooltip.js +87 -41
- package/lib/interaction/tooltip.js.map +1 -1
- package/lib/lib/plot.d.ts +1 -0
- package/lib/lib/plot.js +1 -0
- package/lib/lib/plot.js.map +1 -1
- package/lib/lib/std.d.ts +1 -0
- package/lib/mark/area.js +1 -1
- package/lib/mark/area.js.map +1 -1
- package/lib/mark/gauge.d.ts +1 -1
- package/lib/mark/gauge.js +13 -1
- package/lib/mark/gauge.js.map +1 -1
- package/lib/mark/index.d.ts +2 -0
- package/lib/mark/index.js +3 -1
- package/lib/mark/index.js.map +1 -1
- package/lib/mark/line.js +1 -1
- package/lib/mark/line.js.map +1 -1
- package/lib/mark/liquid.d.ts +7 -0
- package/lib/mark/liquid.js +87 -0
- package/lib/mark/liquid.js.map +1 -0
- package/lib/runtime/constant.d.ts +1 -0
- package/lib/runtime/constant.js +2 -1
- package/lib/runtime/constant.js.map +1 -1
- package/lib/runtime/plot.js +7 -1
- package/lib/runtime/plot.js.map +1 -1
- package/lib/runtime/transform.js +3 -0
- package/lib/runtime/transform.js.map +1 -1
- package/lib/shape/index.d.ts +2 -0
- package/lib/shape/index.js +3 -1
- package/lib/shape/index.js.map +1 -1
- package/lib/shape/liquid/liquid.d.ts +3 -0
- package/lib/shape/liquid/liquid.js +83 -0
- package/lib/shape/liquid/liquid.js.map +1 -0
- package/lib/shape/liquid/shapes.d.ts +38 -0
- package/lib/shape/liquid/shapes.js +96 -0
- package/lib/shape/liquid/shapes.js.map +1 -0
- package/lib/shape/liquid/wave.d.ts +16 -0
- package/lib/shape/liquid/wave.js +196 -0
- package/lib/shape/liquid/wave.js.map +1 -0
- package/lib/spec/mark.d.ts +2 -1
- package/lib/theme/light.js +2 -1
- package/lib/theme/light.js.map +1 -1
- package/lib/utils/helper.js +10 -2
- package/lib/utils/helper.js.map +1 -1
- package/package.json +5 -5
- package/src/api/chart.ts +6 -1
- package/src/api/extend.ts +11 -11
- package/src/api/index.ts +6 -3
- package/src/api/runtime.ts +1 -0
- package/src/component/axis.ts +1 -1
- package/src/index.ts +3 -2
- package/src/interaction/brushHighlight.ts +26 -3
- package/src/interaction/tooltip.ts +95 -38
- package/src/lib/plot.ts +2 -1
- package/src/mark/area.ts +1 -1
- package/src/mark/gauge.ts +30 -9
- package/src/mark/index.ts +2 -0
- package/src/mark/line.ts +1 -1
- package/src/mark/liquid.ts +100 -0
- package/src/runtime/constant.ts +1 -0
- package/src/runtime/plot.ts +10 -2
- package/src/runtime/transform.ts +3 -1
- package/src/shape/index.ts +2 -0
- package/src/shape/liquid/liquid.ts +116 -0
- package/src/shape/liquid/shapes.ts +101 -0
- package/src/shape/liquid/wave.ts +245 -0
- package/src/spec/mark.ts +2 -0
- package/src/theme/light.ts +2 -1
- package/src/utils/helper.ts +9 -1
|
@@ -2,7 +2,7 @@ import { Circle, DisplayObject, IElement, Line } from '@antv/g';
|
|
|
2
2
|
import { sort, group, mean, bisector, minIndex } from 'd3-array';
|
|
3
3
|
import { deepMix, lowerFirst, throttle } from '@antv/util';
|
|
4
4
|
import { Tooltip as TooltipComponent } from '@antv/gui';
|
|
5
|
-
import { Constant, Identity } from '@antv/scale';
|
|
5
|
+
import { Constant, Identity, Band } from '@antv/scale';
|
|
6
6
|
import { defined, subObject } from '../utils/helper';
|
|
7
7
|
import { isTranspose, isPolar } from '../utils/coordinate';
|
|
8
8
|
import { angle, sub } from '../utils/vector';
|
|
@@ -140,7 +140,7 @@ function showTooltip({
|
|
|
140
140
|
parent.tooltipElement = tooltipElement;
|
|
141
141
|
}
|
|
142
142
|
|
|
143
|
-
function hideTooltip({ root, single, emitter, nativeEvent = true
|
|
143
|
+
function hideTooltip({ root, single, emitter, nativeEvent = true }) {
|
|
144
144
|
if (nativeEvent) {
|
|
145
145
|
emitter.emit('tooltip:hide', { nativeEvent });
|
|
146
146
|
}
|
|
@@ -152,11 +152,14 @@ function hideTooltip({ root, single, emitter, nativeEvent = true, mount }) {
|
|
|
152
152
|
}
|
|
153
153
|
}
|
|
154
154
|
|
|
155
|
-
function destroyTooltip(root) {
|
|
156
|
-
const
|
|
155
|
+
function destroyTooltip({ root, single }) {
|
|
156
|
+
const canvasContainer = root.getRootNode().defaultView.getConfig().container;
|
|
157
|
+
const parent = single ? canvasContainer : root;
|
|
158
|
+
if (!parent) return;
|
|
159
|
+
const { tooltipElement } = parent;
|
|
157
160
|
if (tooltipElement) {
|
|
158
161
|
tooltipElement.destroy();
|
|
159
|
-
|
|
162
|
+
parent.tooltipElement = undefined;
|
|
160
163
|
}
|
|
161
164
|
}
|
|
162
165
|
|
|
@@ -182,19 +185,26 @@ function singleItem(element) {
|
|
|
182
185
|
}
|
|
183
186
|
|
|
184
187
|
function groupNameOf(scale, datum) {
|
|
185
|
-
const { color: scaleColor, series: scaleSeries } = scale;
|
|
188
|
+
const { color: scaleColor, series: scaleSeries, facet = false } = scale;
|
|
186
189
|
const { color, series } = datum;
|
|
187
190
|
const invertAble = (scale) => {
|
|
188
191
|
return (
|
|
189
192
|
scale &&
|
|
190
193
|
scale.invert &&
|
|
191
|
-
!(scale instanceof
|
|
194
|
+
!(scale instanceof Band) &&
|
|
192
195
|
!(scale instanceof Constant)
|
|
193
196
|
);
|
|
194
197
|
};
|
|
195
198
|
// For non constant color channel.
|
|
196
199
|
if (invertAble(scaleSeries)) return scaleSeries.invert(series);
|
|
197
|
-
if (
|
|
200
|
+
if (
|
|
201
|
+
series &&
|
|
202
|
+
scaleSeries instanceof Band &&
|
|
203
|
+
scaleSeries.invert(series) !== color &&
|
|
204
|
+
!facet
|
|
205
|
+
) {
|
|
206
|
+
return scaleSeries.invert(series);
|
|
207
|
+
}
|
|
198
208
|
if (invertAble(scaleColor)) {
|
|
199
209
|
const name = scaleColor.invert(color);
|
|
200
210
|
// For threshold scale.
|
|
@@ -627,7 +637,13 @@ export function seriesTooltip(
|
|
|
627
637
|
) as (...args: any[]) => void;
|
|
628
638
|
|
|
629
639
|
const hide = () => {
|
|
630
|
-
hideTooltip({ root, single, emitter
|
|
640
|
+
hideTooltip({ root, single, emitter });
|
|
641
|
+
if (crosshairs) hideRuleY(root);
|
|
642
|
+
if (marker) hideMarker(root);
|
|
643
|
+
};
|
|
644
|
+
|
|
645
|
+
const destroy = () => {
|
|
646
|
+
destroyTooltip({ root, single });
|
|
631
647
|
if (crosshairs) hideRuleY(root);
|
|
632
648
|
if (marker) hideMarker(root);
|
|
633
649
|
};
|
|
@@ -645,29 +661,48 @@ export function seriesTooltip(
|
|
|
645
661
|
};
|
|
646
662
|
|
|
647
663
|
const onTooltipHide = () => {
|
|
648
|
-
hideTooltip({ root, single, emitter, nativeEvent: false
|
|
664
|
+
hideTooltip({ root, single, emitter, nativeEvent: false });
|
|
649
665
|
};
|
|
650
666
|
|
|
651
|
-
|
|
652
|
-
|
|
667
|
+
const onTooltipDisable = () => {
|
|
668
|
+
removeEventListeners();
|
|
669
|
+
destroy();
|
|
670
|
+
};
|
|
653
671
|
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
root.addEventListener('pointerleave', hide);
|
|
658
|
-
}
|
|
672
|
+
const onTooltipEnable = () => {
|
|
673
|
+
addEventListeners();
|
|
674
|
+
};
|
|
659
675
|
|
|
660
|
-
|
|
676
|
+
const addEventListeners = () => {
|
|
677
|
+
if (!disableNative) {
|
|
678
|
+
root.addEventListener('pointerenter', update);
|
|
679
|
+
root.addEventListener('pointermove', update);
|
|
680
|
+
root.addEventListener('pointerleave', hide);
|
|
681
|
+
}
|
|
682
|
+
};
|
|
683
|
+
|
|
684
|
+
const removeEventListeners = () => {
|
|
661
685
|
if (!disableNative) {
|
|
662
686
|
root.removeEventListener('pointerenter', update);
|
|
663
687
|
root.removeEventListener('pointermove', update);
|
|
664
688
|
root.removeEventListener('pointerleave', hide);
|
|
665
689
|
}
|
|
690
|
+
};
|
|
691
|
+
|
|
692
|
+
addEventListeners();
|
|
693
|
+
|
|
694
|
+
emitter.on('tooltip:show', onTooltipShow);
|
|
695
|
+
emitter.on('tooltip:hide', onTooltipHide);
|
|
696
|
+
emitter.on('tooltip:disable', onTooltipDisable);
|
|
697
|
+
emitter.on('tooltip:enable', onTooltipEnable);
|
|
698
|
+
|
|
699
|
+
return () => {
|
|
700
|
+
removeEventListeners();
|
|
666
701
|
emitter.off('tooltip:show', onTooltipShow);
|
|
667
702
|
emitter.off('tooltip:hide', onTooltipHide);
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
703
|
+
emitter.off('tooltip:disable', onTooltipDisable);
|
|
704
|
+
emitter.off('tooltip:enable', onTooltipEnable);
|
|
705
|
+
destroy();
|
|
671
706
|
};
|
|
672
707
|
}
|
|
673
708
|
|
|
@@ -695,6 +730,7 @@ export function tooltip(
|
|
|
695
730
|
view,
|
|
696
731
|
mount,
|
|
697
732
|
bounding,
|
|
733
|
+
shared = false,
|
|
698
734
|
body = true,
|
|
699
735
|
disableNative = false,
|
|
700
736
|
}: Record<string, any>,
|
|
@@ -707,13 +743,13 @@ export function tooltip(
|
|
|
707
743
|
(event) => {
|
|
708
744
|
const { target: element } = event;
|
|
709
745
|
if (!elementSet.has(element)) {
|
|
710
|
-
hideTooltip({ root, single, emitter
|
|
746
|
+
hideTooltip({ root, single, emitter });
|
|
711
747
|
return;
|
|
712
748
|
}
|
|
713
749
|
const k = groupKey(element);
|
|
714
750
|
const group = keyGroup.get(k);
|
|
715
751
|
const data =
|
|
716
|
-
group.length === 1
|
|
752
|
+
group.length === 1 && !shared
|
|
717
753
|
? singleItem(group[0])
|
|
718
754
|
: groupItems(group, scale, groupName);
|
|
719
755
|
|
|
@@ -726,7 +762,7 @@ export function tooltip(
|
|
|
726
762
|
}
|
|
727
763
|
|
|
728
764
|
if (isEmptyTooltipData(data)) {
|
|
729
|
-
hideTooltip({ root, single, emitter
|
|
765
|
+
hideTooltip({ root, single, emitter });
|
|
730
766
|
return;
|
|
731
767
|
}
|
|
732
768
|
|
|
@@ -762,7 +798,24 @@ export function tooltip(
|
|
|
762
798
|
const pointerout = (event) => {
|
|
763
799
|
const { target: element } = event;
|
|
764
800
|
if (!elementSet.has(element)) return;
|
|
765
|
-
hideTooltip({ root, single, emitter
|
|
801
|
+
hideTooltip({ root, single, emitter });
|
|
802
|
+
};
|
|
803
|
+
|
|
804
|
+
const addEventListeners = () => {
|
|
805
|
+
if (!disableNative) {
|
|
806
|
+
root.addEventListener('pointerover', pointerover);
|
|
807
|
+
root.addEventListener('pointermove', pointerover);
|
|
808
|
+
root.addEventListener('pointerout', pointerout);
|
|
809
|
+
}
|
|
810
|
+
};
|
|
811
|
+
|
|
812
|
+
const removeEventListeners = () => {
|
|
813
|
+
if (!disableNative) {
|
|
814
|
+
root.removeEventListener('pointerover', pointerover);
|
|
815
|
+
root.removeEventListener('pointermove', pointerover);
|
|
816
|
+
root.removeEventListener('pointerout', pointerout);
|
|
817
|
+
}
|
|
818
|
+
destroyTooltip({ root, single });
|
|
766
819
|
};
|
|
767
820
|
|
|
768
821
|
const onTooltipShow = ({ nativeEvent, data }) => {
|
|
@@ -780,28 +833,30 @@ export function tooltip(
|
|
|
780
833
|
|
|
781
834
|
const onTooltipHide = ({ nativeEvent }: any = {}) => {
|
|
782
835
|
if (nativeEvent) return;
|
|
783
|
-
hideTooltip({ root, single, emitter, nativeEvent: false
|
|
836
|
+
hideTooltip({ root, single, emitter, nativeEvent: false });
|
|
837
|
+
};
|
|
838
|
+
|
|
839
|
+
const onTooltipDisable = () => {
|
|
840
|
+
removeEventListeners();
|
|
841
|
+
destroyTooltip({ root, single });
|
|
842
|
+
};
|
|
843
|
+
|
|
844
|
+
const onTooltipEnable = () => {
|
|
845
|
+
addEventListeners();
|
|
784
846
|
};
|
|
785
847
|
|
|
786
848
|
emitter.on('tooltip:show', onTooltipShow);
|
|
787
849
|
emitter.on('tooltip:hide', onTooltipHide);
|
|
850
|
+
emitter.on('tooltip:enable', onTooltipEnable);
|
|
851
|
+
emitter.on('tooltip:disable', onTooltipDisable);
|
|
788
852
|
|
|
789
|
-
|
|
790
|
-
root.addEventListener('pointerover', pointerover);
|
|
791
|
-
root.addEventListener('pointermove', pointerover);
|
|
792
|
-
root.addEventListener('pointerout', pointerout);
|
|
793
|
-
}
|
|
853
|
+
addEventListeners();
|
|
794
854
|
|
|
795
855
|
return () => {
|
|
796
|
-
|
|
797
|
-
root.removeEventListener('pointerover', pointerover);
|
|
798
|
-
root.removeEventListener('pointermove', pointerover);
|
|
799
|
-
root.removeEventListener('pointerout', pointerout);
|
|
800
|
-
}
|
|
801
|
-
|
|
856
|
+
removeEventListeners();
|
|
802
857
|
emitter.off('tooltip:show', onTooltipShow);
|
|
803
858
|
emitter.off('tooltip:hide', onTooltipHide);
|
|
804
|
-
destroyTooltip(root);
|
|
859
|
+
destroyTooltip({ root, single });
|
|
805
860
|
};
|
|
806
861
|
}
|
|
807
862
|
|
|
@@ -849,6 +904,7 @@ export function Tooltip(options) {
|
|
|
849
904
|
const bbox = plotArea.getBounds();
|
|
850
905
|
const startX = bbox.min[0];
|
|
851
906
|
const startY = bbox.min[1];
|
|
907
|
+
Object.assign(scale, { facet: true });
|
|
852
908
|
|
|
853
909
|
// @todo Nested structure rather than flat structure for facet?
|
|
854
910
|
// Add listener to the root area.
|
|
@@ -876,6 +932,7 @@ export function Tooltip(options) {
|
|
|
876
932
|
item,
|
|
877
933
|
emitter,
|
|
878
934
|
view,
|
|
935
|
+
shared,
|
|
879
936
|
});
|
|
880
937
|
};
|
|
881
938
|
}
|
package/src/lib/plot.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Boxplot, WordCloud, Gauge } from '../mark';
|
|
1
|
+
import { Boxplot, WordCloud, Gauge, Liquid } from '../mark';
|
|
2
2
|
import { Venn } from '../data';
|
|
3
3
|
|
|
4
4
|
export function plotlib() {
|
|
@@ -7,5 +7,6 @@ export function plotlib() {
|
|
|
7
7
|
'mark.boxplot': Boxplot,
|
|
8
8
|
'mark.gauge': Gauge,
|
|
9
9
|
'mark.wordCloud': WordCloud,
|
|
10
|
+
'mark.liquid': Liquid,
|
|
10
11
|
} as const;
|
|
11
12
|
}
|
package/src/mark/area.ts
CHANGED
package/src/mark/gauge.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { deepMix } from '@antv/util';
|
|
1
|
+
import { deepMix, isNumber } from '@antv/util';
|
|
2
2
|
import { Vector2 } from '@antv/coord';
|
|
3
3
|
import { Group } from '@antv/g';
|
|
4
4
|
import { filterPrefixObject, isUnset, subObject } from '../utils/helper';
|
|
@@ -124,16 +124,37 @@ const DEFAULT_TEXT_OPTIONS = {
|
|
|
124
124
|
},
|
|
125
125
|
};
|
|
126
126
|
|
|
127
|
-
export type GaugeData =
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
127
|
+
export type GaugeData =
|
|
128
|
+
| {
|
|
129
|
+
target?: number;
|
|
130
|
+
total?: number;
|
|
131
|
+
percent?: number;
|
|
132
|
+
name?: string;
|
|
133
|
+
thresholds?: number[];
|
|
134
|
+
}
|
|
135
|
+
| number;
|
|
136
|
+
|
|
137
|
+
function getGaugeData(data: GaugeData) {
|
|
138
|
+
if (isNumber(data)) {
|
|
139
|
+
// Percent range [0, 1].
|
|
140
|
+
const percent = Math.max(0, Math.min(data, 1));
|
|
141
|
+
return {
|
|
142
|
+
percent,
|
|
143
|
+
target: percent,
|
|
144
|
+
total: 1,
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
return data;
|
|
148
|
+
}
|
|
134
149
|
|
|
135
150
|
function dataTransform(data: GaugeData, scale) {
|
|
136
|
-
const {
|
|
151
|
+
const {
|
|
152
|
+
name = 'score',
|
|
153
|
+
target,
|
|
154
|
+
total,
|
|
155
|
+
percent,
|
|
156
|
+
thresholds = [],
|
|
157
|
+
} = getGaugeData(data);
|
|
137
158
|
const _target = percent || target;
|
|
138
159
|
const _total = percent ? 1 : total;
|
|
139
160
|
const newScale = {
|
package/src/mark/index.ts
CHANGED
|
@@ -30,6 +30,7 @@ export { WordCloud } from './wordCloud';
|
|
|
30
30
|
export { Gauge } from './gauge';
|
|
31
31
|
export { Density } from './density';
|
|
32
32
|
export { Heatmap } from './heatmap';
|
|
33
|
+
export { Liquid } from './liquid';
|
|
33
34
|
|
|
34
35
|
export type { IntervalOptions } from './interval';
|
|
35
36
|
export type { RectOptions } from './rect';
|
|
@@ -59,3 +60,4 @@ export type { WordCloudOptions } from './wordCloud';
|
|
|
59
60
|
export type { GaugeOptions } from './gauge';
|
|
60
61
|
export type { DensityOptions } from './density';
|
|
61
62
|
export type { HeatmapOptions } from './heatmap';
|
|
63
|
+
export type { LiquidOptions } from './liquid';
|
package/src/mark/line.ts
CHANGED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { deepMix, isNumber } from '@antv/util';
|
|
2
|
+
import { subObject } from '../utils/helper';
|
|
3
|
+
import { CompositeMarkComponent as CC } from '../runtime';
|
|
4
|
+
import { LiquidMark } from '../spec';
|
|
5
|
+
import { LiquidShape } from '../shape';
|
|
6
|
+
|
|
7
|
+
const DEFAULT_OPTIONS = {
|
|
8
|
+
axis: {
|
|
9
|
+
x: false,
|
|
10
|
+
y: false,
|
|
11
|
+
},
|
|
12
|
+
legend: false,
|
|
13
|
+
tooltip: false,
|
|
14
|
+
encode: {
|
|
15
|
+
x: 'type',
|
|
16
|
+
y: 'percent',
|
|
17
|
+
},
|
|
18
|
+
scale: {
|
|
19
|
+
y: {
|
|
20
|
+
domain: [0, 1],
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
style: {
|
|
24
|
+
shape: LiquidShape,
|
|
25
|
+
},
|
|
26
|
+
animate: {
|
|
27
|
+
enter: {
|
|
28
|
+
type: 'fadeIn',
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const DEFAULT_TEXT_OPTIONS = {
|
|
34
|
+
type: 'text',
|
|
35
|
+
style: {
|
|
36
|
+
x: '50%',
|
|
37
|
+
y: '50%',
|
|
38
|
+
textAlign: 'center',
|
|
39
|
+
textBaseline: 'middle',
|
|
40
|
+
fontSize: 20,
|
|
41
|
+
fontWeight: 800,
|
|
42
|
+
fill: '#888',
|
|
43
|
+
},
|
|
44
|
+
animate: {
|
|
45
|
+
enter: {
|
|
46
|
+
type: 'fadeIn',
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export type LiquidData =
|
|
52
|
+
| {
|
|
53
|
+
percent?: number;
|
|
54
|
+
}
|
|
55
|
+
| number;
|
|
56
|
+
|
|
57
|
+
export type LiquidOptions = Omit<LiquidMark, 'type'>;
|
|
58
|
+
|
|
59
|
+
export const Liquid: CC<LiquidOptions> = (options) => {
|
|
60
|
+
const { data = {}, style = {}, animate, ...resOptions } = options;
|
|
61
|
+
// Compatible with old data structures: { percent: number } and percent >= 0.
|
|
62
|
+
const percent = Math.max(0, isNumber(data) ? data : data?.percent);
|
|
63
|
+
|
|
64
|
+
const newData = [{ percent, type: 'liquid' }];
|
|
65
|
+
|
|
66
|
+
const textStyle = subObject(style, 'text');
|
|
67
|
+
const outline = subObject(style, 'outline');
|
|
68
|
+
const wave = subObject(style, 'wave');
|
|
69
|
+
const background = subObject(style, 'background');
|
|
70
|
+
|
|
71
|
+
return [
|
|
72
|
+
deepMix({}, DEFAULT_OPTIONS, {
|
|
73
|
+
type: 'interval',
|
|
74
|
+
data: newData,
|
|
75
|
+
style: {
|
|
76
|
+
liquidOptions: {
|
|
77
|
+
percent,
|
|
78
|
+
liquidShape: style?.shape,
|
|
79
|
+
},
|
|
80
|
+
styleOptions: {
|
|
81
|
+
...style,
|
|
82
|
+
outline,
|
|
83
|
+
wave,
|
|
84
|
+
background,
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
animate,
|
|
88
|
+
...resOptions,
|
|
89
|
+
}),
|
|
90
|
+
deepMix({}, DEFAULT_TEXT_OPTIONS, {
|
|
91
|
+
style: {
|
|
92
|
+
text: `${percent * 100} %`,
|
|
93
|
+
...textStyle,
|
|
94
|
+
},
|
|
95
|
+
animate,
|
|
96
|
+
}),
|
|
97
|
+
];
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
Liquid.props = {};
|
package/src/runtime/constant.ts
CHANGED
package/src/runtime/plot.ts
CHANGED
|
@@ -422,11 +422,14 @@ async function initializeView(
|
|
|
422
422
|
const flattenOptions = await transformMarks(options, library);
|
|
423
423
|
|
|
424
424
|
const mergedOptions = bubbleOptions(flattenOptions);
|
|
425
|
+
|
|
425
426
|
// @todo Remove this.
|
|
426
427
|
// !!! NOTE: Mute original view options.
|
|
427
428
|
// Update interaction and coordinate for this view.
|
|
428
429
|
options.interaction = mergedOptions.interaction;
|
|
429
430
|
options.coordinate = mergedOptions.coordinate;
|
|
431
|
+
// @ts-ignore
|
|
432
|
+
options.marks = [...mergedOptions.marks, ...mergedOptions.components];
|
|
430
433
|
|
|
431
434
|
const transformedOptions = coordinate2Transform(mergedOptions, library);
|
|
432
435
|
const state = await initializeMarks(transformedOptions, library);
|
|
@@ -961,13 +964,18 @@ async function plotView(
|
|
|
961
964
|
const node = shapeFunction(data, index);
|
|
962
965
|
const animation = updateFunction(data, [element], [node]);
|
|
963
966
|
if (animation !== null) return animation;
|
|
964
|
-
if (
|
|
967
|
+
if (
|
|
968
|
+
element.nodeName === node.nodeName &&
|
|
969
|
+
node.nodeName !== 'g'
|
|
970
|
+
) {
|
|
965
971
|
copyAttributes(element, node);
|
|
966
|
-
else {
|
|
972
|
+
} else {
|
|
967
973
|
element.parentNode.replaceChild(node, element);
|
|
968
974
|
node.className = ELEMENT_CLASS_NAME;
|
|
969
975
|
// @ts-ignore
|
|
970
976
|
node.markType = type;
|
|
977
|
+
// @ts-ignore
|
|
978
|
+
node.__data__ = element.__data__;
|
|
971
979
|
}
|
|
972
980
|
return animation;
|
|
973
981
|
})
|
package/src/runtime/transform.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Primitive } from 'd3-array';
|
|
2
|
-
import { deepMix } from '@antv/util';
|
|
2
|
+
import { deepMix, isNumber } from '@antv/util';
|
|
3
3
|
import { format } from 'd3-format';
|
|
4
4
|
import { indexOf, mapObject } from '../utils/array';
|
|
5
5
|
import {
|
|
@@ -336,6 +336,8 @@ function isField(data: Record<string, Primitive>[], value: string): boolean {
|
|
|
336
336
|
}
|
|
337
337
|
|
|
338
338
|
function normalizedDataSource(data) {
|
|
339
|
+
// Liquid、Gauge need number data.
|
|
340
|
+
if (isNumber(data)) return { type: 'inline', value: data };
|
|
339
341
|
// Return null as a placeholder.
|
|
340
342
|
if (!data) return { type: 'inline', value: null };
|
|
341
343
|
if (Array.isArray(data)) return { type: 'inline', value: data };
|
package/src/shape/index.ts
CHANGED
|
@@ -60,6 +60,7 @@ export { Rect as RangeShape } from './interval/rect';
|
|
|
60
60
|
export { Rect as RectShape } from './interval/rect';
|
|
61
61
|
export { Hollow as RectHollow } from './interval/hollow';
|
|
62
62
|
export { Shape as ShapeShape } from './shape/shape';
|
|
63
|
+
export { Liquid as LiquidShape } from './liquid/liquid';
|
|
63
64
|
|
|
64
65
|
export type { RectOptions as IntervalShapeOptions } from './interval/rect';
|
|
65
66
|
export type { HollowOptions as IntervalHollowOptions } from './interval/hollow';
|
|
@@ -109,3 +110,4 @@ export type { ConnectorOptions as ConnectorShapeOptions } from './connector/conn
|
|
|
109
110
|
export type { LabelOptions as LabelShapeOptions } from './label/label';
|
|
110
111
|
export type { DensityOptions as DensityShapeOptions } from './density/density';
|
|
111
112
|
export type { ShapeOptions as ShapeShapeOptions } from './shape/shape';
|
|
113
|
+
export type { LiquidOptions } from './liquid/liquid';
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { isFunction } from '@antv/util';
|
|
2
|
+
import type { PathStyleProps } from '@antv/g';
|
|
3
|
+
import type { ShapeComponent as SC } from '../../runtime';
|
|
4
|
+
import { addWave } from './wave';
|
|
5
|
+
import { LiquidShapesPath } from './shapes';
|
|
6
|
+
|
|
7
|
+
const getLiquidShape = (shape = 'circle') =>
|
|
8
|
+
LiquidShapesPath[shape] || LiquidShapesPath.circle;
|
|
9
|
+
|
|
10
|
+
export type LiquidOptions = Record<string, any>;
|
|
11
|
+
|
|
12
|
+
export const Liquid: SC<LiquidOptions> = (options, context) => {
|
|
13
|
+
if (!context) return;
|
|
14
|
+
const { coordinate } = context;
|
|
15
|
+
const { liquidOptions, styleOptions } = options;
|
|
16
|
+
const { liquidShape, percent } = liquidOptions;
|
|
17
|
+
const {
|
|
18
|
+
background: backgroundStyle,
|
|
19
|
+
outline = {},
|
|
20
|
+
wave = {},
|
|
21
|
+
...attr
|
|
22
|
+
} = styleOptions;
|
|
23
|
+
const { border = 2, distance = 0, ...outlineStyle } = outline;
|
|
24
|
+
const { length = 192, count = 3 } = wave;
|
|
25
|
+
|
|
26
|
+
return (points, cfg, defaultAttr) => {
|
|
27
|
+
const { document } = context.canvas;
|
|
28
|
+
const { color, fillOpacity } = defaultAttr;
|
|
29
|
+
const attrs = { fill: color, ...defaultAttr, ...attr } as PathStyleProps;
|
|
30
|
+
|
|
31
|
+
const g = document.createElement('g', {});
|
|
32
|
+
|
|
33
|
+
// Center x/y.
|
|
34
|
+
const [centerX, centerY] = coordinate.getCenter();
|
|
35
|
+
// [width,height].
|
|
36
|
+
const size = coordinate.getSize();
|
|
37
|
+
const radius = Math.min(...size) / 2;
|
|
38
|
+
|
|
39
|
+
// 1、Gets the path of the overall shape.
|
|
40
|
+
const buildPath = isFunction(liquidShape)
|
|
41
|
+
? liquidShape
|
|
42
|
+
: getLiquidShape(liquidShape);
|
|
43
|
+
const shapePath = buildPath(centerX, centerY, radius, ...size);
|
|
44
|
+
|
|
45
|
+
// 2、Background create.
|
|
46
|
+
if (Object.keys(backgroundStyle).length) {
|
|
47
|
+
const backgroundShape = document.createElement('path', {
|
|
48
|
+
style: {
|
|
49
|
+
path: shapePath,
|
|
50
|
+
fill: '#fff',
|
|
51
|
+
...backgroundStyle,
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
g.appendChild(backgroundShape);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// Percent > 0 Mapping water waves.
|
|
59
|
+
if (percent > 0) {
|
|
60
|
+
// 3. Clip create.
|
|
61
|
+
const clipShape = document.createElement('path', {
|
|
62
|
+
style: {
|
|
63
|
+
path: shapePath,
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
g.appendChild(clipShape);
|
|
68
|
+
g.style.clipPath = clipShape;
|
|
69
|
+
|
|
70
|
+
// 4. Wave create.
|
|
71
|
+
addWave(
|
|
72
|
+
centerX,
|
|
73
|
+
centerY,
|
|
74
|
+
1 - percent,
|
|
75
|
+
count,
|
|
76
|
+
attrs,
|
|
77
|
+
g,
|
|
78
|
+
clipShape.getBBox().y,
|
|
79
|
+
radius * 2,
|
|
80
|
+
length,
|
|
81
|
+
true,
|
|
82
|
+
document,
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// 5. Draw distance.
|
|
87
|
+
const distanceShape = document.createElement('path', {
|
|
88
|
+
style: {
|
|
89
|
+
path: shapePath,
|
|
90
|
+
fill: 'transparent',
|
|
91
|
+
lineWidth: border + 2 * distance,
|
|
92
|
+
stroke: '#fff',
|
|
93
|
+
},
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
// 6. Draw border.
|
|
97
|
+
const borderShape = document.createElement('path', {
|
|
98
|
+
style: {
|
|
99
|
+
path: shapePath,
|
|
100
|
+
stroke: color,
|
|
101
|
+
strokeOpacity: fillOpacity,
|
|
102
|
+
lineWidth: border,
|
|
103
|
+
...attrs,
|
|
104
|
+
...outlineStyle,
|
|
105
|
+
fill: 'transparent',
|
|
106
|
+
},
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
g.appendChild(distanceShape);
|
|
110
|
+
g.appendChild(borderShape);
|
|
111
|
+
|
|
112
|
+
return g;
|
|
113
|
+
};
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
Liquid.props = {};
|