@antv/g2 5.0.0-rc.1 → 5.0.0-rc.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/README.en-US.md +4 -1
- package/README.md +3 -2
- package/dist/g2-lite.min.js +3 -3
- package/dist/g2.min.js +3 -3
- package/esm/animation/fadeIn.js +1 -1
- package/esm/animation/fadeIn.js.map +1 -1
- package/esm/animation/fadeOut.js +1 -1
- package/esm/animation/fadeOut.js.map +1 -1
- package/esm/animation/morphing.js +1 -1
- package/esm/animation/morphing.js.map +1 -1
- package/esm/animation/scaleInX.js +1 -1
- package/esm/animation/scaleInX.js.map +1 -1
- package/esm/animation/scaleInY.js +1 -1
- package/esm/animation/scaleInY.js.map +1 -1
- package/esm/animation/scaleOutX.js +1 -1
- package/esm/animation/scaleOutX.js.map +1 -1
- package/esm/animation/scaleOutY.js +1 -1
- package/esm/animation/scaleOutY.js.map +1 -1
- package/esm/animation/waveIn.js +2 -2
- package/esm/animation/waveIn.js.map +1 -1
- package/esm/animation/zoomIn.js +1 -1
- package/esm/animation/zoomIn.js.map +1 -1
- package/esm/animation/zoomOut.js +1 -1
- package/esm/animation/zoomOut.js.map +1 -1
- package/esm/api/chart.d.ts +1 -0
- package/esm/api/chart.js +16 -11
- package/esm/api/chart.js.map +1 -1
- package/esm/api/composition/base.d.ts +2 -2
- package/esm/api/composition/base.js +3 -2
- package/esm/api/composition/base.js.map +1 -1
- package/esm/component/axis.js +7 -5
- package/esm/component/axis.js.map +1 -1
- package/esm/component/legendCategory.js +20 -5
- package/esm/component/legendCategory.js.map +1 -1
- package/esm/component/legendContinuous.js +2 -2
- package/esm/component/legendContinuous.js.map +1 -1
- package/esm/component/legendContinuousBlockSize.js +1 -1
- package/esm/component/legendContinuousBlockSize.js.map +1 -1
- package/esm/component/legendContinuousSize.js +1 -1
- package/esm/component/legendContinuousSize.js.map +1 -1
- package/esm/component/scrollbar.d.ts +1 -1
- package/esm/component/scrollbar.js +3 -3
- package/esm/component/scrollbar.js.map +1 -1
- package/esm/component/scrollbarX.js +1 -1
- package/esm/component/scrollbarX.js.map +1 -1
- package/esm/component/scrollbarY.js +1 -1
- package/esm/component/scrollbarY.js.map +1 -1
- package/esm/component/slider.d.ts +1 -1
- package/esm/component/slider.js +3 -3
- package/esm/component/slider.js.map +1 -1
- package/esm/component/sliderX.js +1 -1
- package/esm/component/sliderX.js.map +1 -1
- package/esm/component/sliderY.js +1 -1
- package/esm/component/sliderY.js.map +1 -1
- package/esm/component/utils.d.ts +1 -1
- package/esm/component/utils.js +2 -2
- package/esm/component/utils.js.map +1 -1
- package/esm/geo/geoView.js +1 -1
- package/esm/geo/geoView.js.map +1 -1
- package/esm/index.d.ts +1 -0
- package/esm/index.js +1 -0
- package/esm/index.js.map +1 -1
- package/esm/interaction/brushFilter.js +1 -1
- package/esm/interaction/brushFilter.js.map +1 -1
- package/esm/interaction/brushHighlight.js +6 -3
- package/esm/interaction/brushHighlight.js.map +1 -1
- package/esm/interaction/elementHighlight.js +1 -1
- package/esm/interaction/elementHighlight.js.map +1 -1
- package/esm/interaction/event.js +20 -20
- package/esm/interaction/event.js.map +1 -1
- package/esm/interaction/legendFilter.d.ts +1 -4
- package/esm/interaction/legendFilter.js +45 -73
- package/esm/interaction/legendFilter.js.map +1 -1
- package/esm/interaction/sliderFilter.js +6 -6
- package/esm/interaction/sliderFilter.js.map +1 -1
- package/esm/interaction/tooltip.d.ts +2 -2
- package/esm/interaction/tooltip.js +40 -18
- package/esm/interaction/tooltip.js.map +1 -1
- package/esm/interaction/utils.js +7 -5
- package/esm/interaction/utils.js.map +1 -1
- package/esm/label-transform/overflowHide.js +3 -2
- package/esm/label-transform/overflowHide.js.map +1 -1
- package/esm/label-transform/overlapHide.js +3 -2
- package/esm/label-transform/overlapHide.js.map +1 -1
- package/esm/mark/gauge.js +2 -2
- package/esm/mark/gauge.js.map +1 -1
- package/esm/mark/sankey.js +2 -2
- package/esm/mark/sankey.js.map +1 -1
- package/esm/mark/utils.d.ts +2 -2
- package/esm/mark/utils.js +2 -2
- package/esm/mark/utils.js.map +1 -1
- package/esm/runtime/component.js +18 -3
- package/esm/runtime/component.js.map +1 -1
- package/esm/runtime/plot.js +56 -22
- package/esm/runtime/plot.js.map +1 -1
- package/esm/runtime/render.d.ts +1 -1
- package/esm/runtime/render.js +15 -8
- package/esm/runtime/render.js.map +1 -1
- package/esm/shape/interval/color.js +18 -9
- package/esm/shape/interval/color.js.map +1 -1
- package/esm/shape/label/label.js +1 -1
- package/esm/shape/label/label.js.map +1 -1
- package/esm/shape/label/position/area.js +1 -1
- package/esm/shape/label/position/area.js.map +1 -1
- package/esm/shape/line/curve.js +1 -1
- package/esm/shape/line/curve.js.map +1 -1
- package/esm/shape/text/advance.js +3 -1
- package/esm/shape/text/advance.js.map +1 -1
- package/esm/shape/text/text.js +1 -1
- package/esm/shape/text/text.js.map +1 -1
- package/esm/spec/interaction.d.ts +2 -0
- package/esm/spec/scale.d.ts +3 -2
- package/esm/stdlib/index.js +1 -1
- package/esm/stdlib/index.js.map +1 -1
- package/esm/theme/academy.js +5 -5
- package/esm/theme/academy.js.map +1 -1
- package/esm/theme/dark.js +5 -5
- package/esm/theme/dark.js.map +1 -1
- package/esm/theme/light.js +6 -8
- package/esm/theme/light.js.map +1 -1
- package/esm/transform/filter.js +4 -1
- package/esm/transform/filter.js.map +1 -1
- package/esm/utils/event.d.ts +33 -14
- package/esm/utils/event.js +43 -16
- package/esm/utils/event.js.map +1 -1
- package/esm/utils/helper.js +2 -1
- package/esm/utils/helper.js.map +1 -1
- package/esm/utils/style.d.ts +5 -0
- package/esm/utils/style.js +23 -0
- package/esm/utils/style.js.map +1 -0
- package/lib/animation/fadeIn.js +1 -1
- package/lib/animation/fadeIn.js.map +1 -1
- package/lib/animation/fadeOut.js +1 -1
- package/lib/animation/fadeOut.js.map +1 -1
- package/lib/animation/morphing.js +1 -1
- package/lib/animation/morphing.js.map +1 -1
- package/lib/animation/scaleInX.js +1 -1
- package/lib/animation/scaleInX.js.map +1 -1
- package/lib/animation/scaleInY.js +1 -1
- package/lib/animation/scaleInY.js.map +1 -1
- package/lib/animation/scaleOutX.js +1 -1
- package/lib/animation/scaleOutX.js.map +1 -1
- package/lib/animation/scaleOutY.js +1 -1
- package/lib/animation/scaleOutY.js.map +1 -1
- package/lib/animation/waveIn.js +2 -2
- package/lib/animation/waveIn.js.map +1 -1
- package/lib/animation/zoomIn.js +1 -1
- package/lib/animation/zoomIn.js.map +1 -1
- package/lib/animation/zoomOut.js +1 -1
- package/lib/animation/zoomOut.js.map +1 -1
- package/lib/api/chart.d.ts +1 -0
- package/lib/api/chart.js +15 -10
- package/lib/api/chart.js.map +1 -1
- package/lib/api/composition/base.d.ts +2 -2
- package/lib/api/composition/base.js +3 -2
- package/lib/api/composition/base.js.map +1 -1
- package/lib/component/axis.js +7 -5
- package/lib/component/axis.js.map +1 -1
- package/lib/component/legendCategory.js +20 -5
- package/lib/component/legendCategory.js.map +1 -1
- package/lib/component/legendContinuous.js +2 -2
- package/lib/component/legendContinuous.js.map +1 -1
- package/lib/component/legendContinuousBlockSize.js +1 -1
- package/lib/component/legendContinuousBlockSize.js.map +1 -1
- package/lib/component/legendContinuousSize.js +1 -1
- package/lib/component/legendContinuousSize.js.map +1 -1
- package/lib/component/scrollbar.d.ts +1 -1
- package/lib/component/scrollbar.js +3 -3
- package/lib/component/scrollbar.js.map +1 -1
- package/lib/component/scrollbarX.js +1 -1
- package/lib/component/scrollbarX.js.map +1 -1
- package/lib/component/scrollbarY.js +1 -1
- package/lib/component/scrollbarY.js.map +1 -1
- package/lib/component/slider.d.ts +1 -1
- package/lib/component/slider.js +3 -3
- package/lib/component/slider.js.map +1 -1
- package/lib/component/sliderX.js +1 -1
- package/lib/component/sliderX.js.map +1 -1
- package/lib/component/sliderY.js +1 -1
- package/lib/component/sliderY.js.map +1 -1
- package/lib/component/utils.d.ts +1 -1
- package/lib/component/utils.js +2 -2
- package/lib/component/utils.js.map +1 -1
- package/lib/geo/geoView.js +1 -1
- package/lib/geo/geoView.js.map +1 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.js +3 -1
- package/lib/index.js.map +1 -1
- package/lib/interaction/brushFilter.js +1 -1
- package/lib/interaction/brushFilter.js.map +1 -1
- package/lib/interaction/brushHighlight.js +6 -3
- package/lib/interaction/brushHighlight.js.map +1 -1
- package/lib/interaction/event.js +20 -20
- package/lib/interaction/event.js.map +1 -1
- package/lib/interaction/legendFilter.d.ts +1 -4
- package/lib/interaction/legendFilter.js +45 -73
- package/lib/interaction/legendFilter.js.map +1 -1
- package/lib/interaction/sliderFilter.js +6 -6
- package/lib/interaction/sliderFilter.js.map +1 -1
- package/lib/interaction/tooltip.d.ts +2 -2
- package/lib/interaction/tooltip.js +40 -18
- package/lib/interaction/tooltip.js.map +1 -1
- package/lib/interaction/utils.js +7 -5
- package/lib/interaction/utils.js.map +1 -1
- package/lib/label-transform/overflowHide.js +3 -2
- package/lib/label-transform/overflowHide.js.map +1 -1
- package/lib/label-transform/overlapHide.js +3 -2
- package/lib/label-transform/overlapHide.js.map +1 -1
- package/lib/mark/gauge.js +2 -2
- package/lib/mark/gauge.js.map +1 -1
- package/lib/mark/sankey.js +2 -2
- package/lib/mark/sankey.js.map +1 -1
- package/lib/mark/utils.d.ts +2 -2
- package/lib/mark/utils.js +2 -2
- package/lib/mark/utils.js.map +1 -1
- package/lib/runtime/component.js +18 -3
- package/lib/runtime/component.js.map +1 -1
- package/lib/runtime/plot.js +55 -21
- package/lib/runtime/plot.js.map +1 -1
- package/lib/runtime/render.d.ts +1 -1
- package/lib/runtime/render.js +14 -7
- package/lib/runtime/render.js.map +1 -1
- package/lib/shape/interval/color.js +18 -9
- package/lib/shape/interval/color.js.map +1 -1
- package/lib/shape/label/label.js +1 -1
- package/lib/shape/label/label.js.map +1 -1
- package/lib/shape/label/position/area.js +1 -1
- package/lib/shape/label/position/area.js.map +1 -1
- package/lib/shape/line/curve.js +1 -1
- package/lib/shape/line/curve.js.map +1 -1
- package/lib/shape/text/advance.js +3 -1
- package/lib/shape/text/advance.js.map +1 -1
- package/lib/shape/text/text.js +1 -1
- package/lib/shape/text/text.js.map +1 -1
- package/lib/spec/interaction.d.ts +2 -0
- package/lib/spec/scale.d.ts +3 -2
- package/lib/stdlib/index.js +1 -1
- package/lib/stdlib/index.js.map +1 -1
- package/lib/theme/academy.js +5 -5
- package/lib/theme/academy.js.map +1 -1
- package/lib/theme/dark.js +5 -5
- package/lib/theme/dark.js.map +1 -1
- package/lib/theme/light.js +6 -8
- package/lib/theme/light.js.map +1 -1
- package/lib/transform/filter.js +4 -1
- package/lib/transform/filter.js.map +1 -1
- package/lib/utils/event.d.ts +33 -14
- package/lib/utils/event.js +44 -17
- package/lib/utils/event.js.map +1 -1
- package/lib/utils/helper.js +2 -1
- package/lib/utils/helper.js.map +1 -1
- package/lib/utils/style.d.ts +5 -0
- package/lib/utils/style.js +30 -0
- package/lib/utils/style.js.map +1 -0
- package/package.json +2 -2
- package/src/animation/fadeIn.ts +1 -1
- package/src/animation/fadeOut.ts +1 -1
- package/src/animation/morphing.ts +1 -1
- package/src/animation/scaleInX.ts +4 -4
- package/src/animation/scaleInY.ts +4 -4
- package/src/animation/scaleOutX.ts +4 -4
- package/src/animation/scaleOutY.ts +4 -4
- package/src/animation/waveIn.ts +4 -4
- package/src/animation/zoomIn.ts +4 -4
- package/src/animation/zoomOut.ts +4 -4
- package/src/api/chart.ts +16 -12
- package/src/api/composition/base.ts +5 -4
- package/src/component/axis.ts +8 -6
- package/src/component/legendCategory.ts +19 -11
- package/src/component/legendContinuous.ts +2 -2
- package/src/component/legendContinuousBlockSize.ts +1 -5
- package/src/component/legendContinuousSize.ts +1 -1
- package/src/component/scrollbar.ts +5 -5
- package/src/component/scrollbarX.ts +1 -1
- package/src/component/scrollbarY.ts +1 -1
- package/src/component/slider.ts +6 -7
- package/src/component/sliderX.ts +1 -1
- package/src/component/sliderY.ts +1 -1
- package/src/component/utils.ts +2 -2
- package/src/geo/geoView.ts +1 -1
- package/src/index.ts +1 -0
- package/src/interaction/brushFilter.ts +2 -2
- package/src/interaction/brushHighlight.ts +8 -3
- package/src/interaction/elementHighlight.ts +6 -6
- package/src/interaction/event.ts +30 -20
- package/src/interaction/legendFilter.ts +45 -70
- package/src/interaction/sliderFilter.ts +6 -6
- package/src/interaction/tooltip.ts +51 -21
- package/src/interaction/utils.ts +6 -3
- package/src/label-transform/overflowHide.ts +3 -3
- package/src/label-transform/overlapHide.ts +3 -2
- package/src/mark/gauge.ts +2 -1
- package/src/mark/sankey.ts +2 -1
- package/src/mark/utils.ts +2 -4
- package/src/runtime/component.ts +27 -10
- package/src/runtime/plot.ts +70 -20
- package/src/runtime/render.ts +16 -8
- package/src/shape/interval/color.ts +19 -4
- package/src/shape/label/label.ts +1 -1
- package/src/shape/label/position/area.ts +1 -1
- package/src/shape/line/curve.ts +1 -1
- package/src/shape/text/advance.ts +3 -2
- package/src/shape/text/text.ts +1 -1
- package/src/spec/interaction.ts +3 -0
- package/src/spec/scale.ts +3 -2
- package/src/stdlib/index.ts +2 -2
- package/src/theme/academy.ts +5 -5
- package/src/theme/dark.ts +5 -5
- package/src/theme/light.ts +6 -8
- package/src/transform/filter.ts +4 -1
- package/src/utils/event.ts +47 -15
- package/src/utils/helper.ts +2 -1
- package/src/utils/style.ts +34 -0
package/src/runtime/plot.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { deepMix, upperFirst } from '@antv/util';
|
|
|
4
4
|
import { group } from 'd3-array';
|
|
5
5
|
import { format } from 'd3-format';
|
|
6
6
|
import { mapObject } from '../utils/array';
|
|
7
|
-
import {
|
|
7
|
+
import { ChartEvent } from '../utils/event';
|
|
8
8
|
import {
|
|
9
9
|
appendTransform,
|
|
10
10
|
copyAttributes,
|
|
@@ -171,7 +171,7 @@ export async function plot<T extends G2ViewTree>(
|
|
|
171
171
|
}
|
|
172
172
|
}
|
|
173
173
|
|
|
174
|
-
context.emitter.emit(
|
|
174
|
+
context.emitter.emit(ChartEvent.BEFORE_PAINT);
|
|
175
175
|
|
|
176
176
|
// Plot chart.
|
|
177
177
|
const enterContainer = new Map<G2ViewDescriptor, DisplayObject>();
|
|
@@ -245,7 +245,7 @@ export async function plot<T extends G2ViewTree>(
|
|
|
245
245
|
for (const option of inferInteraction(options)) {
|
|
246
246
|
// Remove interaction for existed views.
|
|
247
247
|
const prevInteraction = nameInteraction.get(option.type);
|
|
248
|
-
if (prevInteraction) prevInteraction.destroy();
|
|
248
|
+
if (prevInteraction) prevInteraction.destroy?.();
|
|
249
249
|
|
|
250
250
|
// Apply new interaction.
|
|
251
251
|
const interaction = useInteraction(option);
|
|
@@ -274,7 +274,7 @@ export async function plot<T extends G2ViewTree>(
|
|
|
274
274
|
context.views = views;
|
|
275
275
|
context.animations = transitions;
|
|
276
276
|
|
|
277
|
-
context.emitter.emit(
|
|
277
|
+
context.emitter.emit(ChartEvent.AFTER_PAINT);
|
|
278
278
|
|
|
279
279
|
// Note!!!
|
|
280
280
|
// The returned promise will never resolved if one of nodeGenerator
|
|
@@ -303,14 +303,43 @@ function createUpdateView(
|
|
|
303
303
|
const transitions = [];
|
|
304
304
|
const [newView, newChildren] = await initializeView(newOptions, library);
|
|
305
305
|
plotView(newView, selection, transitions, library);
|
|
306
|
+
updateTooltip(selection, newOptions, newView, library, context);
|
|
306
307
|
for (const child of newChildren) {
|
|
307
308
|
plot(child, selection, library, context);
|
|
308
309
|
}
|
|
309
|
-
return {
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
310
|
+
return { options: newOptions, view: newView };
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
function updateTooltip(selection, options, view, library, context) {
|
|
315
|
+
const [useInteraction] = useLibrary<
|
|
316
|
+
G2InteractionOptions,
|
|
317
|
+
InteractionComponent,
|
|
318
|
+
Interaction
|
|
319
|
+
>('interaction', library);
|
|
320
|
+
|
|
321
|
+
// Instances for tooltip.
|
|
322
|
+
const container = selection.node();
|
|
323
|
+
const nameInteraction = container['nameInteraction'];
|
|
324
|
+
const { interaction } = options;
|
|
325
|
+
const tooltipOptions = inferInteraction(interaction).find(
|
|
326
|
+
(d) => d.type === 'tooltip',
|
|
327
|
+
);
|
|
328
|
+
|
|
329
|
+
// Destroy older tooltip.
|
|
330
|
+
const tooltip = nameInteraction.get('tooltip');
|
|
331
|
+
if (!tooltip) return;
|
|
332
|
+
tooltip.destroy?.();
|
|
333
|
+
|
|
334
|
+
// Apply new tooltip interaction.
|
|
335
|
+
const applyTooltip = useInteraction(tooltipOptions);
|
|
336
|
+
const target = {
|
|
337
|
+
options,
|
|
338
|
+
view,
|
|
339
|
+
container: selection.node(),
|
|
340
|
+
update: (options) => Promise.resolve(options),
|
|
313
341
|
};
|
|
342
|
+
applyTooltip(target, [], context.emitter);
|
|
314
343
|
}
|
|
315
344
|
|
|
316
345
|
async function initializeView(
|
|
@@ -726,7 +755,7 @@ async function plotView(
|
|
|
726
755
|
enter
|
|
727
756
|
// Make this layer interactive, such as click and mousemove events.
|
|
728
757
|
.append('rect')
|
|
729
|
-
|
|
758
|
+
.style('zIndex', 0)
|
|
730
759
|
.style('fill', 'transparent')
|
|
731
760
|
.attr('className', PLOT_CLASS_NAME)
|
|
732
761
|
.call(updateBBox)
|
|
@@ -749,15 +778,18 @@ async function plotView(
|
|
|
749
778
|
for (const [mark, state] of markState.entries()) {
|
|
750
779
|
const { data } = state;
|
|
751
780
|
const { key, class: cls, type } = mark;
|
|
781
|
+
const viewNode = selection.select(`#${key}`);
|
|
752
782
|
const shapeFunction = createMarkShapeFunction(mark, state, view, library);
|
|
753
783
|
const enterFunction = createEnterFunction(mark, state, view, library);
|
|
754
784
|
const updateFunction = createUpdateFunction(mark, state, view, library);
|
|
755
785
|
const exitFunction = createExitFunction(mark, state, view, library);
|
|
756
|
-
const facetElements = selectFacetElements(
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
786
|
+
const facetElements = selectFacetElements(
|
|
787
|
+
selection,
|
|
788
|
+
viewNode,
|
|
789
|
+
cls,
|
|
790
|
+
'element',
|
|
791
|
+
);
|
|
792
|
+
const T = viewNode
|
|
761
793
|
.selectAll(className(ELEMENT_CLASS_NAME))
|
|
762
794
|
.selectFacetAll(facetElements)
|
|
763
795
|
.data(
|
|
@@ -769,7 +801,10 @@ async function plotView(
|
|
|
769
801
|
(enter) =>
|
|
770
802
|
enter
|
|
771
803
|
.append(shapeFunction)
|
|
772
|
-
|
|
804
|
+
// Note!!! Only one className can be set.
|
|
805
|
+
// Using attribute as alternative for other classNames.
|
|
806
|
+
.attr('className', ELEMENT_CLASS_NAME)
|
|
807
|
+
.attr('markType', type)
|
|
773
808
|
.transition(function (data) {
|
|
774
809
|
return enterFunction(data, [this]);
|
|
775
810
|
}),
|
|
@@ -803,6 +838,7 @@ async function plotView(
|
|
|
803
838
|
// Append elements to be merged.
|
|
804
839
|
.append(shapeFunction)
|
|
805
840
|
.attr('className', ELEMENT_CLASS_NAME)
|
|
841
|
+
.attr('markType', type)
|
|
806
842
|
.transition(function (data) {
|
|
807
843
|
// Remove merged elements after animation finishing.
|
|
808
844
|
const { __fromElements__: fromElements } = this;
|
|
@@ -819,6 +855,7 @@ async function plotView(
|
|
|
819
855
|
const toElements = enter
|
|
820
856
|
.append(shapeFunction)
|
|
821
857
|
.attr('className', ELEMENT_CLASS_NAME)
|
|
858
|
+
.attr('markType', type)
|
|
822
859
|
.nodes();
|
|
823
860
|
return updateFunction(data, [this], toElements);
|
|
824
861
|
})
|
|
@@ -1114,12 +1151,18 @@ function computeAnimationExtent(markState): [number, number] {
|
|
|
1114
1151
|
|
|
1115
1152
|
function selectFacetElements(
|
|
1116
1153
|
selection: Selection,
|
|
1154
|
+
current: Selection,
|
|
1117
1155
|
facetClassName: string,
|
|
1118
1156
|
elementClassName: string,
|
|
1119
1157
|
): DisplayObject[] {
|
|
1120
1158
|
const group = selection.node().parentElement;
|
|
1121
1159
|
return group
|
|
1122
|
-
.findAll(
|
|
1160
|
+
.findAll(
|
|
1161
|
+
(node) =>
|
|
1162
|
+
node.style.facet !== undefined &&
|
|
1163
|
+
node.style.facet === facetClassName &&
|
|
1164
|
+
node !== current.node(), // Exclude current view.
|
|
1165
|
+
)
|
|
1123
1166
|
.flatMap((node) => node.getElementsByClassName(elementClassName));
|
|
1124
1167
|
}
|
|
1125
1168
|
|
|
@@ -1292,9 +1335,10 @@ function createExitFunction(
|
|
|
1292
1335
|
return createAnimationFunction('exit', mark, state, view, library);
|
|
1293
1336
|
}
|
|
1294
1337
|
|
|
1295
|
-
function inferTheme(theme: G2ThemeOptions = {
|
|
1296
|
-
|
|
1297
|
-
|
|
1338
|
+
function inferTheme(theme: G2ThemeOptions = {}): G2ThemeOptions {
|
|
1339
|
+
if (typeof theme === 'string') return { type: theme };
|
|
1340
|
+
const { type = 'classic', ...rest } = theme;
|
|
1341
|
+
return { ...rest, type };
|
|
1298
1342
|
}
|
|
1299
1343
|
|
|
1300
1344
|
/**
|
|
@@ -1304,6 +1348,9 @@ function inferInteraction(view: G2View): G2InteractionOptions[] {
|
|
|
1304
1348
|
const defaults = {
|
|
1305
1349
|
event: true,
|
|
1306
1350
|
tooltip: true,
|
|
1351
|
+
// @todo Inferred by slider self.
|
|
1352
|
+
sliderFilter: true,
|
|
1353
|
+
legendFilter: true,
|
|
1307
1354
|
};
|
|
1308
1355
|
const { interaction = {} } = view;
|
|
1309
1356
|
return Object.entries(deepMix(defaults, interaction))
|
|
@@ -1395,7 +1442,10 @@ function updateLayers(selection: Selection, marks: G2Mark[]) {
|
|
|
1395
1442
|
|
|
1396
1443
|
const labelLayer = selection.select(className(LABEL_LAYER_CLASS_NAME)).node();
|
|
1397
1444
|
if (labelLayer) return;
|
|
1398
|
-
selection
|
|
1445
|
+
selection
|
|
1446
|
+
.append('g')
|
|
1447
|
+
.attr('className', LABEL_LAYER_CLASS_NAME)
|
|
1448
|
+
.style('zIndex', 0);
|
|
1399
1449
|
}
|
|
1400
1450
|
|
|
1401
1451
|
function className(...names: string[]): string {
|
package/src/runtime/render.ts
CHANGED
|
@@ -5,7 +5,8 @@ import { deepMix } from '@antv/util';
|
|
|
5
5
|
import EventEmitter from '@antv/event-emitter';
|
|
6
6
|
import { createLibrary } from '../stdlib';
|
|
7
7
|
import { select } from '../utils/selection';
|
|
8
|
-
import {
|
|
8
|
+
import { ChartEvent } from '../utils/event';
|
|
9
|
+
import { error } from '../utils/helper';
|
|
9
10
|
import { G2Context, G2ViewTree } from './types/options';
|
|
10
11
|
import { plot } from './plot';
|
|
11
12
|
|
|
@@ -61,10 +62,14 @@ function Canvas(width: number, height: number): GCanvas {
|
|
|
61
62
|
export function render<T extends G2ViewTree = G2ViewTree>(
|
|
62
63
|
options: T,
|
|
63
64
|
context: G2Context = {},
|
|
64
|
-
|
|
65
|
+
resolve?: () => void,
|
|
66
|
+
reject?: (e: Error) => void,
|
|
65
67
|
): HTMLElement {
|
|
66
68
|
// Initialize the context if it is not provided.
|
|
67
|
-
const { width = 640, height = 480,
|
|
69
|
+
const { width = 640, height = 480, theme } = options;
|
|
70
|
+
if (!theme) {
|
|
71
|
+
error('ChartOptions.theme is required, such as classic.');
|
|
72
|
+
}
|
|
68
73
|
const keyed = inferKeys(options);
|
|
69
74
|
const {
|
|
70
75
|
canvas = Canvas(width, height),
|
|
@@ -76,7 +81,7 @@ export function render<T extends G2ViewTree = G2ViewTree>(
|
|
|
76
81
|
context.emitter = emitter;
|
|
77
82
|
canvas.resize(width, height);
|
|
78
83
|
|
|
79
|
-
emitter.emit(
|
|
84
|
+
emitter.emit(ChartEvent.BEFORE_RENDER);
|
|
80
85
|
|
|
81
86
|
// Plot the chart and mutate context.
|
|
82
87
|
// Make sure that plot chart after container is ready for every time.
|
|
@@ -86,8 +91,11 @@ export function render<T extends G2ViewTree = G2ViewTree>(
|
|
|
86
91
|
plot<T>({ ...keyed, width, height }, selection, library, context),
|
|
87
92
|
)
|
|
88
93
|
.then(() => {
|
|
89
|
-
emitter.emit(
|
|
90
|
-
|
|
94
|
+
emitter.emit(ChartEvent.AFTER_RENDER);
|
|
95
|
+
resolve?.();
|
|
96
|
+
})
|
|
97
|
+
.catch((e) => {
|
|
98
|
+
reject?.(e);
|
|
91
99
|
});
|
|
92
100
|
|
|
93
101
|
// Return the container HTML element wraps the canvas or svg element.
|
|
@@ -119,11 +127,11 @@ export function renderToMountedElement<T extends G2ViewTree = G2ViewTree>(
|
|
|
119
127
|
context.library = library;
|
|
120
128
|
context.emitter = emitter;
|
|
121
129
|
|
|
122
|
-
emitter.emit(
|
|
130
|
+
emitter.emit(ChartEvent.BEFORE_RENDER);
|
|
123
131
|
// Plot the chart and mutate context.
|
|
124
132
|
// Make sure that plot chart after container is ready for every time.
|
|
125
133
|
plot<T>({ ...keyed, width, height }, selection, library, context).then(() => {
|
|
126
|
-
emitter.emit(
|
|
134
|
+
emitter.emit(ChartEvent.AFTER_RENDER);
|
|
127
135
|
callback?.();
|
|
128
136
|
});
|
|
129
137
|
|
|
@@ -134,12 +134,27 @@ export const Color: SC<ColorOptions> = (options) => {
|
|
|
134
134
|
|
|
135
135
|
// Extended style, which is not supported by native g shape,
|
|
136
136
|
// should apply at first.
|
|
137
|
+
const standardDirRadius = [
|
|
138
|
+
first ? radiusTopLeft : innerRadiusTopLeft,
|
|
139
|
+
first ? radiusTopRight : innerRadiusTopRight,
|
|
140
|
+
last ? radiusBottomRight : innerRadiusBottomRight,
|
|
141
|
+
last ? radiusBottomLeft : innerRadiusBottomLeft,
|
|
142
|
+
];
|
|
143
|
+
const standardDir = [
|
|
144
|
+
'radiusTopLeft',
|
|
145
|
+
'radiusTopRight',
|
|
146
|
+
'radiusBottomRight',
|
|
147
|
+
'radiusBottomLeft',
|
|
148
|
+
];
|
|
149
|
+
// Transpose: rotate it clockwise by 90.
|
|
150
|
+
if (isTranspose(coordinate)) {
|
|
151
|
+
standardDir.push(standardDir.shift());
|
|
152
|
+
}
|
|
137
153
|
const extendedStyle = {
|
|
138
154
|
radius,
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
radiusBottomLeft: last ? radiusBottomLeft : innerRadiusBottomLeft,
|
|
155
|
+
...Object.fromEntries(
|
|
156
|
+
standardDir.map((d, i) => [d, standardDirRadius[i]]),
|
|
157
|
+
),
|
|
143
158
|
inset,
|
|
144
159
|
insetLeft,
|
|
145
160
|
insetRight,
|
package/src/shape/label/label.ts
CHANGED
|
@@ -56,7 +56,7 @@ export const Label: SC<LabelOptions> = (options) => {
|
|
|
56
56
|
return select(new Advance())
|
|
57
57
|
.call(applyStyle, defaultStyle)
|
|
58
58
|
.style('text', `${text}`)
|
|
59
|
-
.style('transform', `${transform}rotate(${+rotate}
|
|
59
|
+
.style('transform', `${transform}rotate(${+rotate})`)
|
|
60
60
|
.style('coordCenter', coordinate.getCenter())
|
|
61
61
|
.call(applyStyle, overrideStyle)
|
|
62
62
|
.node();
|
package/src/shape/line/curve.ts
CHANGED
|
@@ -135,7 +135,7 @@ export const Curve: SC<CurveOptions> = (options) => {
|
|
|
135
135
|
// Draw one path of connected defined points.
|
|
136
136
|
if (!missing || (connectNulls && !Object.keys(connectStyle).length)) {
|
|
137
137
|
return select(new Path({}))
|
|
138
|
-
.style('d', linePath(DP))
|
|
138
|
+
.style('d', linePath(DP) || [])
|
|
139
139
|
.call(applyStyle, finalStyle)
|
|
140
140
|
.node();
|
|
141
141
|
}
|
|
@@ -144,10 +144,10 @@ export const Advance = createElement((g) => {
|
|
|
144
144
|
[+x0, +y0],
|
|
145
145
|
[+x, +y],
|
|
146
146
|
];
|
|
147
|
-
|
|
148
147
|
const shape1 = select(g)
|
|
149
148
|
.maybeAppend('text', 'text')
|
|
150
|
-
.
|
|
149
|
+
.style('zIndex', 0)
|
|
150
|
+
.call(applyStyle, { textBaseline: 'middle', ...rest })
|
|
151
151
|
.node();
|
|
152
152
|
|
|
153
153
|
const shape2 = select(g)
|
|
@@ -177,6 +177,7 @@ export const Advance = createElement((g) => {
|
|
|
177
177
|
});
|
|
178
178
|
select(g)
|
|
179
179
|
.maybeAppend('connector', 'path')
|
|
180
|
+
.style('zIndex', 0)
|
|
180
181
|
.style('path', connectorPath)
|
|
181
182
|
.style('markerStart', markerStart)
|
|
182
183
|
.style('markerEnd', markerEnd)
|
package/src/shape/text/text.ts
CHANGED
|
@@ -28,7 +28,7 @@ export const Text: SC<TextOptions> = (options) => {
|
|
|
28
28
|
.style('x', x0)
|
|
29
29
|
.style('y', y0)
|
|
30
30
|
.call(applyStyle, shapeTheme)
|
|
31
|
-
.style('transform', `${transform}rotate(${+rotate}
|
|
31
|
+
.style('transform', `${transform}rotate(${+rotate})`)
|
|
32
32
|
.style('coordCenter', coordinate.getCenter())
|
|
33
33
|
.call(applyStyle, textStyle)
|
|
34
34
|
.call(applyStyle, style)
|
package/src/spec/interaction.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { TooltipStyleProps } from '@antv/gui';
|
|
1
2
|
import { InteractionComponent } from '../runtime';
|
|
2
3
|
import { FisheyeCoordinate } from './coordinateTransform';
|
|
3
4
|
import { TooltipItemValue } from './component';
|
|
@@ -198,6 +199,8 @@ export type TooltipInteraction = {
|
|
|
198
199
|
body?: boolean;
|
|
199
200
|
crosshairs?: boolean;
|
|
200
201
|
groupName?: boolean;
|
|
202
|
+
position?: TooltipStyleProps['position'];
|
|
203
|
+
// enterable?: boolean;
|
|
201
204
|
sort?: (d: TooltipItemValue) => any;
|
|
202
205
|
filter?: (d: TooltipItemValue) => any;
|
|
203
206
|
render?: (
|
package/src/spec/scale.ts
CHANGED
|
@@ -57,8 +57,9 @@ export type BaseScale<T extends ScaleTypes, O> = {
|
|
|
57
57
|
rangeMax?: number;
|
|
58
58
|
rangeMin?: number;
|
|
59
59
|
domainMax?: number;
|
|
60
|
-
|
|
61
|
-
|
|
60
|
+
domainMin?: number;
|
|
61
|
+
key?: string;
|
|
62
|
+
facet?: boolean;
|
|
62
63
|
independent?: boolean;
|
|
63
64
|
zero?: boolean;
|
|
64
65
|
offset?: (t: number) => number;
|
package/src/stdlib/index.ts
CHANGED
|
@@ -424,8 +424,8 @@ export function createLibrary(): G2Library {
|
|
|
424
424
|
'shape.rangeY.range': RectShape,
|
|
425
425
|
'shape.path.path': PathShape,
|
|
426
426
|
'shape.path.hollow': HollowPath,
|
|
427
|
-
'theme.
|
|
428
|
-
'theme.
|
|
427
|
+
'theme.classic': Light,
|
|
428
|
+
'theme.classicDark': Dark,
|
|
429
429
|
'theme.academy': Academy,
|
|
430
430
|
'component.axisX': AxisX,
|
|
431
431
|
'component.axisY': AxisY,
|
package/src/theme/academy.ts
CHANGED
|
@@ -228,7 +228,7 @@ export const Academy: TC<AcademyOptions> = (options) => {
|
|
|
228
228
|
lineStroke: '#888',
|
|
229
229
|
lineStrokeOpacity: 1,
|
|
230
230
|
lineLineWidth: 1,
|
|
231
|
-
|
|
231
|
+
showArrow: false,
|
|
232
232
|
tickStroke: COLORS.STROKE,
|
|
233
233
|
tickStrokeOpacity: 1,
|
|
234
234
|
tickLineWidth: 1,
|
|
@@ -356,7 +356,7 @@ export const Academy: TC<AcademyOptions> = (options) => {
|
|
|
356
356
|
fillOpacity: 0.65,
|
|
357
357
|
fontSize: 10,
|
|
358
358
|
fontWeight: 'normal',
|
|
359
|
-
stroke:
|
|
359
|
+
stroke: undefined,
|
|
360
360
|
offset: 12,
|
|
361
361
|
connectorStroke: COLORS.BLACK,
|
|
362
362
|
connectorStrokeOpacity: 0.45,
|
|
@@ -370,13 +370,13 @@ export const Academy: TC<AcademyOptions> = (options) => {
|
|
|
370
370
|
fontSize: 10,
|
|
371
371
|
fillOpacity: 0.85,
|
|
372
372
|
fontWeight: 'normal',
|
|
373
|
-
stroke:
|
|
373
|
+
stroke: undefined,
|
|
374
374
|
offset: 0,
|
|
375
375
|
},
|
|
376
376
|
slider: {
|
|
377
377
|
trackSize: 16,
|
|
378
|
-
|
|
379
|
-
|
|
378
|
+
trackFill: COLORS.STROKE,
|
|
379
|
+
trackFillOpacity: 0.05,
|
|
380
380
|
selectionFill: DEFAULT_COLOR,
|
|
381
381
|
selectionFillOpacity: 0.15,
|
|
382
382
|
handleIconSize: 10,
|
package/src/theme/dark.ts
CHANGED
|
@@ -230,7 +230,7 @@ export const Dark: TC<DarkOptions> = (options) => {
|
|
|
230
230
|
lineStroke: COLORS.BLACK,
|
|
231
231
|
lineStrokeOpacity: 0.45,
|
|
232
232
|
lineLineWidth: 0.5,
|
|
233
|
-
|
|
233
|
+
showArrow: false,
|
|
234
234
|
// axis tick line
|
|
235
235
|
tickStroke: COLORS.BLACK,
|
|
236
236
|
tickStrokeOpacity: 0.25,
|
|
@@ -360,7 +360,7 @@ export const Dark: TC<DarkOptions> = (options) => {
|
|
|
360
360
|
fillOpacity: 0.65,
|
|
361
361
|
fontSize: 12,
|
|
362
362
|
fontWeight: 'normal',
|
|
363
|
-
stroke:
|
|
363
|
+
stroke: undefined,
|
|
364
364
|
offset: 12,
|
|
365
365
|
connectorStroke: COLORS.BLACK,
|
|
366
366
|
connectorStrokeOpacity: 0.45,
|
|
@@ -374,13 +374,13 @@ export const Dark: TC<DarkOptions> = (options) => {
|
|
|
374
374
|
fontSize: 12,
|
|
375
375
|
fillOpacity: 0.85,
|
|
376
376
|
fontWeight: 'normal',
|
|
377
|
-
stroke:
|
|
377
|
+
stroke: undefined,
|
|
378
378
|
offset: 0,
|
|
379
379
|
},
|
|
380
380
|
slider: {
|
|
381
381
|
trackSize: 16,
|
|
382
|
-
|
|
383
|
-
|
|
382
|
+
trackFill: COLORS.STROKE,
|
|
383
|
+
trackFillOpacity: 1,
|
|
384
384
|
selectionFill: DEFAULT_COLOR,
|
|
385
385
|
selectionFillOpacity: 0.15,
|
|
386
386
|
handleIconSize: 10,
|
package/src/theme/light.ts
CHANGED
|
@@ -230,7 +230,7 @@ export const Light: TC<LightOptions> = (options) => {
|
|
|
230
230
|
lineStroke: COLORS.BLACK,
|
|
231
231
|
lineStrokeOpacity: 0.45,
|
|
232
232
|
lineLineWidth: 0.5,
|
|
233
|
-
|
|
233
|
+
showArrow: false,
|
|
234
234
|
// axis tick line
|
|
235
235
|
tickStroke: COLORS.BLACK,
|
|
236
236
|
tickStrokeOpacity: 0.25,
|
|
@@ -354,7 +354,7 @@ export const Light: TC<LightOptions> = (options) => {
|
|
|
354
354
|
handleLabelFillOpacity: 0.45,
|
|
355
355
|
handleLabelFontSize: 12,
|
|
356
356
|
handleLabelFontWeight: 'normal',
|
|
357
|
-
|
|
357
|
+
showTick: true,
|
|
358
358
|
labelSpacing: 8,
|
|
359
359
|
// [todo] legend rail
|
|
360
360
|
},
|
|
@@ -363,7 +363,7 @@ export const Light: TC<LightOptions> = (options) => {
|
|
|
363
363
|
fillOpacity: 0.65,
|
|
364
364
|
fontSize: 12,
|
|
365
365
|
fontWeight: 'normal',
|
|
366
|
-
stroke:
|
|
366
|
+
stroke: undefined,
|
|
367
367
|
offset: 12,
|
|
368
368
|
connectorStroke: COLORS.BLACK,
|
|
369
369
|
connectorStrokeOpacity: 0.45,
|
|
@@ -377,13 +377,13 @@ export const Light: TC<LightOptions> = (options) => {
|
|
|
377
377
|
fontSize: 12,
|
|
378
378
|
fillOpacity: 0.85,
|
|
379
379
|
fontWeight: 'normal',
|
|
380
|
-
stroke:
|
|
380
|
+
stroke: undefined,
|
|
381
381
|
offset: 0,
|
|
382
382
|
},
|
|
383
383
|
slider: {
|
|
384
384
|
trackSize: 16,
|
|
385
|
-
|
|
386
|
-
|
|
385
|
+
trackFill: COLORS.STROKE,
|
|
386
|
+
trackFillOpacity: 1,
|
|
387
387
|
selectionFill: DEFAULT_COLOR,
|
|
388
388
|
selectionFillOpacity: 0.15,
|
|
389
389
|
handleIconSize: 10,
|
|
@@ -406,10 +406,8 @@ export const Light: TC<LightOptions> = (options) => {
|
|
|
406
406
|
scrollable: true,
|
|
407
407
|
trackFill: '#e5e5e5',
|
|
408
408
|
trackFillOpacity: 0,
|
|
409
|
-
trackStroke: 'none',
|
|
410
409
|
thumbFill: '#000',
|
|
411
410
|
thumbFillOpacity: 0.15,
|
|
412
|
-
thumbStroke: 'none',
|
|
413
411
|
thumbHighlightedFillOpacity: 0.2,
|
|
414
412
|
},
|
|
415
413
|
title: {
|
package/src/transform/filter.ts
CHANGED
|
@@ -41,7 +41,10 @@ export const Filter: TC<FilterOptions> = (options = {}) => {
|
|
|
41
41
|
},
|
|
42
42
|
];
|
|
43
43
|
});
|
|
44
|
-
return [
|
|
44
|
+
return [
|
|
45
|
+
newIndex,
|
|
46
|
+
deepMix({}, mark, { encode: Object.fromEntries(newEncodes) }),
|
|
47
|
+
];
|
|
45
48
|
};
|
|
46
49
|
};
|
|
47
50
|
|
package/src/utils/event.ts
CHANGED
|
@@ -1,20 +1,52 @@
|
|
|
1
|
-
//
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
// to prevent users from tampering with internal values.
|
|
2
|
+
const ChartEvent = new Proxy(
|
|
3
|
+
{
|
|
4
|
+
BEFORE_RENDER: 'beforerender',
|
|
5
|
+
AFTER_RENDER: 'afterrender',
|
|
5
6
|
|
|
6
|
-
|
|
7
|
-
|
|
7
|
+
BEFORE_PAINT: 'beforepaint',
|
|
8
|
+
AFTER_PAINT: 'afterpaint',
|
|
8
9
|
|
|
9
|
-
|
|
10
|
-
|
|
10
|
+
BEFORE_CHANGE_DATA: 'beforechangedata',
|
|
11
|
+
AFTER_CHANGE_DATA: 'afterchangedata',
|
|
11
12
|
|
|
12
|
-
|
|
13
|
-
|
|
13
|
+
BEFORE_CLEAR: 'beforeclear',
|
|
14
|
+
AFTER_CLEAR: 'afterclear',
|
|
14
15
|
|
|
15
|
-
|
|
16
|
-
|
|
16
|
+
BEFORE_DESTROY: 'beforedestroy',
|
|
17
|
+
AFTER_DESTROY: 'afterdestroy',
|
|
17
18
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
BEFORE_CHANGE_SIZE: 'beforechangesize',
|
|
20
|
+
AFTER_CHANGE_SIZE: 'afterchangesize',
|
|
21
|
+
|
|
22
|
+
POINTER_TAP: 'pointertap',
|
|
23
|
+
POINTER_DOWN: 'pointerdown',
|
|
24
|
+
POINTER_UP: 'pointerup',
|
|
25
|
+
POINTER_OVER: 'pointerover',
|
|
26
|
+
POINTER_OUT: 'pointerout',
|
|
27
|
+
POINTER_MOVE: 'pointermove',
|
|
28
|
+
POINTER_ENTER: 'pointerenter',
|
|
29
|
+
POINTER_LEAVE: 'pointerleave',
|
|
30
|
+
POINTER_UPOUTSIDE: 'pointerupoutside',
|
|
31
|
+
DRAG_START: 'dragstart',
|
|
32
|
+
DRAG: 'drag',
|
|
33
|
+
DRAG_END: 'dragend',
|
|
34
|
+
DRAG_ENTER: 'dragenter',
|
|
35
|
+
DRAG_LEAVE: 'dragleave',
|
|
36
|
+
DRAG_OVER: 'dragover',
|
|
37
|
+
DROP: 'DROP',
|
|
38
|
+
CLICK: 'click',
|
|
39
|
+
DBLCLICK: 'dblclick',
|
|
40
|
+
} as const,
|
|
41
|
+
{
|
|
42
|
+
get(target, prop) {
|
|
43
|
+
if (prop in target) return target[prop];
|
|
44
|
+
return undefined;
|
|
45
|
+
},
|
|
46
|
+
set() {
|
|
47
|
+
return true;
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
export { ChartEvent };
|
package/src/utils/helper.ts
CHANGED
|
@@ -71,7 +71,8 @@ export function useMemo<T = unknown, U = unknown>(
|
|
|
71
71
|
|
|
72
72
|
export function appendTransform(node: DisplayObject, transform: any) {
|
|
73
73
|
const { transform: preTransform } = node.style;
|
|
74
|
-
const
|
|
74
|
+
const unset = (d) => d === 'none' || d === undefined;
|
|
75
|
+
const prefix = unset(preTransform) ? '' : preTransform;
|
|
75
76
|
node.style.transform = `${prefix} ${transform}`.trimStart();
|
|
76
77
|
}
|
|
77
78
|
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { DisplayObject, BaseStyleProps } from '@antv/g';
|
|
2
|
+
|
|
3
|
+
const defaultStyle: BaseStyleProps = {
|
|
4
|
+
visibility: 'visible',
|
|
5
|
+
opacity: 1,
|
|
6
|
+
fillOpacity: 1,
|
|
7
|
+
strokeOpacity: 1,
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export function getStyle(element: DisplayObject, key: string) {
|
|
11
|
+
return element.style[key] ?? defaultStyle[key];
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function setStyle(
|
|
15
|
+
element: DisplayObject,
|
|
16
|
+
key: string,
|
|
17
|
+
value: any,
|
|
18
|
+
recursive: boolean,
|
|
19
|
+
) {
|
|
20
|
+
element.style[key] = value;
|
|
21
|
+
if (recursive) {
|
|
22
|
+
element.children.forEach((child: DisplayObject) =>
|
|
23
|
+
setStyle(child, key, value, recursive),
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function hide(element: DisplayObject) {
|
|
29
|
+
setStyle(element, 'visibility', 'hidden', true);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function show(element: DisplayObject) {
|
|
33
|
+
setStyle(element, 'visibility', 'visible', true);
|
|
34
|
+
}
|