@antv/g2plot 2.3.31 → 2.3.35
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 +1270 -0
- package/{README.zh-CN.md → README.en-US.md} +33 -42
- package/README.md +43 -32
- package/dist/g2plot.min.js +3 -18
- package/dist/g2plot.min.js.map +1 -1
- package/esm/adaptor/common.d.ts +1 -0
- package/esm/adaptor/common.js +1 -0
- package/esm/adaptor/common.js.map +1 -1
- package/esm/adaptor/pattern.d.ts +10 -0
- package/esm/adaptor/pattern.js +54 -0
- package/esm/adaptor/pattern.js.map +1 -0
- package/esm/core/plot.d.ts +11 -1
- package/esm/core/plot.js +42 -1
- package/esm/core/plot.js.map +1 -1
- package/esm/index.d.ts +5 -1
- package/esm/index.js +5 -1
- package/esm/index.js.map +1 -1
- package/esm/plots/area/adaptor.js +2 -2
- package/esm/plots/area/adaptor.js.map +1 -1
- package/esm/plots/circle-packing/adaptor.js +4 -4
- package/esm/plots/circle-packing/adaptor.js.map +1 -1
- package/esm/plots/circle-packing/utils.d.ts +0 -5
- package/esm/plots/circle-packing/utils.js +1 -20
- package/esm/plots/circle-packing/utils.js.map +1 -1
- package/esm/plots/column/adaptor.js +3 -2
- package/esm/plots/column/adaptor.js.map +1 -1
- package/esm/plots/dual-axes/adaptor.js +6 -4
- package/esm/plots/dual-axes/adaptor.js.map +1 -1
- package/esm/plots/dual-axes/types.d.ts +2 -1
- package/esm/plots/dual-axes/types.js.map +1 -1
- package/esm/plots/dual-axes/util/geometry.js +3 -2
- package/esm/plots/dual-axes/util/geometry.js.map +1 -1
- package/esm/plots/dual-axes/util/legend.js +4 -1
- package/esm/plots/dual-axes/util/legend.js.map +1 -1
- package/esm/plots/funnel/geometries/basic.js +2 -7
- package/esm/plots/funnel/geometries/basic.js.map +1 -1
- package/esm/plots/heatmap/adaptor.js +2 -2
- package/esm/plots/heatmap/adaptor.js.map +1 -1
- package/esm/plots/heatmap/types.d.ts +4 -2
- package/esm/plots/heatmap/types.js.map +1 -1
- package/esm/plots/histogram/adaptor.js +2 -1
- package/esm/plots/histogram/adaptor.js.map +1 -1
- package/esm/plots/liquid/adaptor.js +2 -2
- package/esm/plots/liquid/adaptor.js.map +1 -1
- package/esm/plots/pie/adaptor.js +2 -1
- package/esm/plots/pie/adaptor.js.map +1 -1
- package/esm/plots/radial-bar/adaptor.js +2 -1
- package/esm/plots/radial-bar/adaptor.js.map +1 -1
- package/esm/plots/rose/adaptor.js +2 -2
- package/esm/plots/rose/adaptor.js.map +1 -1
- package/esm/plots/sunburst/adaptor.js +2 -2
- package/esm/plots/sunburst/adaptor.js.map +1 -1
- package/esm/plots/tiny-area/adaptor.js +2 -2
- package/esm/plots/tiny-area/adaptor.js.map +1 -1
- package/esm/plots/tiny-column/adaptor.js +2 -2
- package/esm/plots/tiny-column/adaptor.js.map +1 -1
- package/esm/plots/treemap/adaptor.js +2 -1
- package/esm/plots/treemap/adaptor.js.map +1 -1
- package/esm/plots/venn/adaptor.d.ts +23 -0
- package/esm/plots/venn/adaptor.js +177 -0
- package/esm/plots/venn/adaptor.js.map +1 -0
- package/esm/plots/venn/constant.d.ts +7 -0
- package/esm/plots/venn/constant.js +33 -0
- package/esm/plots/venn/constant.js.map +1 -0
- package/esm/plots/venn/index.d.ts +24 -0
- package/esm/plots/venn/index.js +47 -0
- package/esm/plots/venn/index.js.map +1 -0
- package/esm/plots/venn/interaction/action.d.ts +18 -0
- package/esm/plots/venn/interaction/action.js +77 -0
- package/esm/plots/venn/interaction/action.js.map +1 -0
- package/esm/plots/venn/interaction/index.d.ts +1 -0
- package/esm/plots/venn/interaction/index.js +15 -0
- package/esm/plots/venn/interaction/index.js.map +1 -0
- package/esm/plots/venn/label.d.ts +1 -0
- package/esm/plots/venn/label.js +31 -0
- package/esm/plots/venn/label.js.map +1 -0
- package/esm/plots/venn/layout/circleintersection.d.ts +29 -0
- package/esm/plots/venn/layout/circleintersection.js +186 -0
- package/esm/plots/venn/layout/circleintersection.js.map +1 -0
- package/esm/plots/venn/layout/diagram.d.ts +17 -0
- package/esm/plots/venn/layout/diagram.js +193 -0
- package/esm/plots/venn/layout/diagram.js.map +1 -0
- package/esm/plots/venn/layout/layout.d.ts +27 -0
- package/esm/plots/venn/layout/layout.js +593 -0
- package/esm/plots/venn/layout/layout.js.map +1 -0
- package/esm/plots/venn/shape.d.ts +1 -0
- package/esm/plots/venn/shape.js +42 -0
- package/esm/plots/venn/shape.js.map +1 -0
- package/esm/plots/venn/types.d.ts +27 -0
- package/esm/plots/venn/types.js +2 -0
- package/esm/plots/venn/types.js.map +1 -0
- package/esm/plots/venn/utils.d.ts +28 -0
- package/esm/plots/venn/utils.js +93 -0
- package/esm/plots/venn/utils.js.map +1 -0
- package/esm/types/annotation.d.ts +5 -1
- package/esm/types/annotation.js.map +1 -1
- package/esm/types/attr.d.ts +4 -1
- package/esm/types/attr.js.map +1 -1
- package/esm/types/common.d.ts +3 -1
- package/esm/types/common.js.map +1 -1
- package/esm/types/index.d.ts +1 -0
- package/esm/types/index.js +1 -0
- package/esm/types/index.js.map +1 -1
- package/esm/types/pattern.d.ts +47 -0
- package/esm/types/pattern.js +1 -0
- package/esm/types/pattern.js.map +1 -0
- package/esm/utils/color/blend.d.ts +20 -0
- package/esm/utils/color/blend.js +92 -0
- package/esm/utils/color/blend.js.map +1 -0
- package/esm/utils/padding.d.ts +5 -0
- package/esm/utils/padding.js +19 -0
- package/esm/utils/padding.js.map +1 -1
- package/esm/utils/pattern/dot.d.ts +32 -0
- package/esm/utils/pattern/dot.js +69 -0
- package/esm/utils/pattern/dot.js.map +1 -0
- package/esm/utils/pattern/index.d.ts +17 -0
- package/esm/utils/pattern/index.js +27 -0
- package/esm/utils/pattern/index.js.map +1 -0
- package/esm/utils/pattern/line.d.ts +25 -0
- package/esm/utils/pattern/line.js +56 -0
- package/esm/utils/pattern/line.js.map +1 -0
- package/esm/utils/pattern/square.d.ts +28 -0
- package/esm/utils/pattern/square.js +61 -0
- package/esm/utils/pattern/square.js.map +1 -0
- package/esm/utils/pattern/util.d.ts +50 -0
- package/esm/utils/pattern/util.js +90 -0
- package/esm/utils/pattern/util.js.map +1 -0
- package/lib/adaptor/common.d.ts +1 -0
- package/lib/adaptor/common.js +2 -0
- package/lib/adaptor/common.js.map +1 -1
- package/lib/adaptor/pattern.d.ts +10 -0
- package/lib/adaptor/pattern.js +58 -0
- package/lib/adaptor/pattern.js.map +1 -0
- package/lib/core/plot.d.ts +11 -1
- package/lib/core/plot.js +41 -0
- package/lib/core/plot.js.map +1 -1
- package/lib/index.d.ts +5 -1
- package/lib/index.js +7 -1
- package/lib/index.js.map +1 -1
- package/lib/plots/area/adaptor.js +1 -1
- package/lib/plots/area/adaptor.js.map +1 -1
- package/lib/plots/circle-packing/adaptor.js +2 -2
- package/lib/plots/circle-packing/adaptor.js.map +1 -1
- package/lib/plots/circle-packing/utils.d.ts +0 -5
- package/lib/plots/circle-packing/utils.js +2 -22
- package/lib/plots/circle-packing/utils.js.map +1 -1
- package/lib/plots/column/adaptor.js +3 -2
- package/lib/plots/column/adaptor.js.map +1 -1
- package/lib/plots/dual-axes/adaptor.js +6 -4
- package/lib/plots/dual-axes/adaptor.js.map +1 -1
- package/lib/plots/dual-axes/types.d.ts +2 -1
- package/lib/plots/dual-axes/types.js.map +1 -1
- package/lib/plots/dual-axes/util/geometry.js +2 -1
- package/lib/plots/dual-axes/util/geometry.js.map +1 -1
- package/lib/plots/dual-axes/util/legend.js +4 -1
- package/lib/plots/dual-axes/util/legend.js.map +1 -1
- package/lib/plots/funnel/geometries/basic.js +1 -6
- package/lib/plots/funnel/geometries/basic.js.map +1 -1
- package/lib/plots/heatmap/adaptor.js +1 -1
- package/lib/plots/heatmap/adaptor.js.map +1 -1
- package/lib/plots/heatmap/types.d.ts +4 -2
- package/lib/plots/heatmap/types.js.map +1 -1
- package/lib/plots/histogram/adaptor.js +2 -1
- package/lib/plots/histogram/adaptor.js.map +1 -1
- package/lib/plots/liquid/adaptor.js +1 -1
- package/lib/plots/liquid/adaptor.js.map +1 -1
- package/lib/plots/pie/adaptor.js +2 -1
- package/lib/plots/pie/adaptor.js.map +1 -1
- package/lib/plots/radial-bar/adaptor.js +2 -1
- package/lib/plots/radial-bar/adaptor.js.map +1 -1
- package/lib/plots/rose/adaptor.js +1 -1
- package/lib/plots/rose/adaptor.js.map +1 -1
- package/lib/plots/sunburst/adaptor.js +1 -1
- package/lib/plots/sunburst/adaptor.js.map +1 -1
- package/lib/plots/tiny-area/adaptor.js +1 -1
- package/lib/plots/tiny-area/adaptor.js.map +1 -1
- package/lib/plots/tiny-column/adaptor.js +1 -1
- package/lib/plots/tiny-column/adaptor.js.map +1 -1
- package/lib/plots/treemap/adaptor.js +2 -1
- package/lib/plots/treemap/adaptor.js.map +1 -1
- package/lib/plots/venn/adaptor.d.ts +23 -0
- package/lib/plots/venn/adaptor.js +183 -0
- package/lib/plots/venn/adaptor.js.map +1 -0
- package/lib/plots/venn/constant.d.ts +7 -0
- package/lib/plots/venn/constant.js +36 -0
- package/lib/plots/venn/constant.js.map +1 -0
- package/lib/plots/venn/index.d.ts +24 -0
- package/lib/plots/venn/index.js +50 -0
- package/lib/plots/venn/index.js.map +1 -0
- package/lib/plots/venn/interaction/action.d.ts +18 -0
- package/lib/plots/venn/interaction/action.js +80 -0
- package/lib/plots/venn/interaction/action.js.map +1 -0
- package/lib/plots/venn/interaction/index.d.ts +1 -0
- package/lib/plots/venn/interaction/index.js +17 -0
- package/lib/plots/venn/interaction/index.js.map +1 -0
- package/lib/plots/venn/label.d.ts +1 -0
- package/lib/plots/venn/label.js +33 -0
- package/lib/plots/venn/label.js.map +1 -0
- package/lib/plots/venn/layout/circleintersection.d.ts +29 -0
- package/lib/plots/venn/layout/circleintersection.js +196 -0
- package/lib/plots/venn/layout/circleintersection.js.map +1 -0
- package/lib/plots/venn/layout/diagram.d.ts +17 -0
- package/lib/plots/venn/layout/diagram.js +201 -0
- package/lib/plots/venn/layout/diagram.js.map +1 -0
- package/lib/plots/venn/layout/layout.d.ts +27 -0
- package/lib/plots/venn/layout/layout.js +606 -0
- package/lib/plots/venn/layout/layout.js.map +1 -0
- package/lib/plots/venn/shape.d.ts +1 -0
- package/lib/plots/venn/shape.js +44 -0
- package/lib/plots/venn/shape.js.map +1 -0
- package/lib/plots/venn/types.d.ts +27 -0
- package/lib/plots/venn/types.js +4 -0
- package/lib/plots/venn/types.js.map +1 -0
- package/lib/plots/venn/utils.d.ts +28 -0
- package/lib/plots/venn/utils.js +98 -0
- package/lib/plots/venn/utils.js.map +1 -0
- package/lib/types/annotation.d.ts +5 -1
- package/lib/types/annotation.js.map +1 -1
- package/lib/types/attr.d.ts +4 -1
- package/lib/types/attr.js.map +1 -1
- package/lib/types/common.d.ts +3 -1
- package/lib/types/common.js.map +1 -1
- package/lib/types/index.d.ts +1 -0
- package/lib/types/index.js +1 -0
- package/lib/types/index.js.map +1 -1
- package/lib/types/pattern.d.ts +47 -0
- package/lib/types/pattern.js +3 -0
- package/lib/types/pattern.js.map +1 -0
- package/lib/utils/color/blend.d.ts +20 -0
- package/lib/utils/color/blend.js +98 -0
- package/lib/utils/color/blend.js.map +1 -0
- package/lib/utils/padding.d.ts +5 -0
- package/lib/utils/padding.js +21 -1
- package/lib/utils/padding.js.map +1 -1
- package/lib/utils/pattern/dot.d.ts +32 -0
- package/lib/utils/pattern/dot.js +74 -0
- package/lib/utils/pattern/dot.js.map +1 -0
- package/lib/utils/pattern/index.d.ts +17 -0
- package/lib/utils/pattern/index.js +31 -0
- package/lib/utils/pattern/index.js.map +1 -0
- package/lib/utils/pattern/line.d.ts +25 -0
- package/lib/utils/pattern/line.js +61 -0
- package/lib/utils/pattern/line.js.map +1 -0
- package/lib/utils/pattern/square.d.ts +28 -0
- package/lib/utils/pattern/square.js +66 -0
- package/lib/utils/pattern/square.js.map +1 -0
- package/lib/utils/pattern/util.d.ts +50 -0
- package/lib/utils/pattern/util.js +99 -0
- package/lib/utils/pattern/util.js.map +1 -0
- package/package.json +10 -8
- package/src/adaptor/common.ts +2 -0
- package/src/adaptor/pattern.ts +66 -0
- package/src/core/plot.ts +43 -1
- package/src/index.ts +8 -1
- package/src/plots/area/adaptor.ts +3 -2
- package/src/plots/circle-packing/adaptor.ts +12 -3
- package/src/plots/circle-packing/utils.ts +1 -21
- package/src/plots/column/adaptor.ts +3 -1
- package/src/plots/dual-axes/adaptor.ts +6 -4
- package/src/plots/dual-axes/types.ts +11 -1
- package/src/plots/dual-axes/util/geometry.ts +3 -2
- package/src/plots/dual-axes/util/legend.ts +4 -1
- package/src/plots/funnel/geometries/basic.ts +2 -10
- package/src/plots/heatmap/adaptor.ts +12 -1
- package/src/plots/heatmap/types.ts +6 -2
- package/src/plots/histogram/adaptor.ts +13 -1
- package/src/plots/liquid/adaptor.ts +2 -2
- package/src/plots/pie/adaptor.ts +2 -0
- package/src/plots/radial-bar/adaptor.ts +2 -0
- package/src/plots/rose/adaptor.ts +2 -1
- package/src/plots/sunburst/adaptor.ts +2 -1
- package/src/plots/tiny-area/adaptor.ts +2 -2
- package/src/plots/tiny-column/adaptor.ts +2 -2
- package/src/plots/treemap/adaptor.ts +13 -1
- package/src/plots/venn/adaptor.ts +227 -0
- package/src/plots/venn/constant.ts +35 -0
- package/src/plots/venn/index.ts +47 -0
- package/src/plots/venn/interaction/action.ts +67 -0
- package/src/plots/venn/interaction/index.ts +17 -0
- package/src/plots/venn/label.ts +26 -0
- package/src/plots/venn/layout/circleintersection.ts +223 -0
- package/src/plots/venn/layout/diagram.ts +219 -0
- package/src/plots/venn/layout/layout.ts +734 -0
- package/src/plots/venn/shape.ts +53 -0
- package/src/plots/venn/types.ts +25 -0
- package/src/plots/venn/utils.ts +100 -0
- package/src/types/annotation.ts +3 -1
- package/src/types/attr.ts +7 -1
- package/src/types/common.ts +3 -1
- package/src/types/index.ts +1 -0
- package/src/types/pattern.ts +50 -0
- package/src/utils/color/blend.ts +103 -0
- package/src/utils/padding.ts +20 -0
- package/src/utils/pattern/dot.ts +86 -0
- package/src/utils/pattern/index.ts +45 -0
- package/src/utils/pattern/line.ts +70 -0
- package/src/utils/pattern/square.ts +78 -0
- package/src/utils/pattern/util.ts +104 -0
package/src/plots/pie/adaptor.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { Params } from '../../core/adaptor';
|
|
|
3
3
|
import { legend, animation, theme, state, annotation } from '../../adaptor/common';
|
|
4
4
|
import { getMappingFunction } from '../../adaptor/geometries/base';
|
|
5
5
|
import { interval } from '../../adaptor/geometries';
|
|
6
|
+
import { pattern } from '../../adaptor/pattern';
|
|
6
7
|
import { getLocale } from '../../core/locale';
|
|
7
8
|
import { Interaction } from '../../types/interaction';
|
|
8
9
|
import { flow, template, transformLabel, deepAssign, renderStatistic, processIllegalData } from '../../utils';
|
|
@@ -315,6 +316,7 @@ export function interaction(params: Params<PieOptions>): Params<PieOptions> {
|
|
|
315
316
|
export function adaptor(params: Params<PieOptions>) {
|
|
316
317
|
// flow 的方式处理所有的配置到 G2 API
|
|
317
318
|
return flow<Params<PieOptions>>(
|
|
319
|
+
pattern('pieStyle'),
|
|
318
320
|
geometry,
|
|
319
321
|
meta,
|
|
320
322
|
theme,
|
|
@@ -2,6 +2,7 @@ import { interaction, animation, theme, scale, tooltip, legend, annotation } fro
|
|
|
2
2
|
import { Params } from '../../core/adaptor';
|
|
3
3
|
import { flow, deepAssign, findGeometry, transformLabel } from '../../utils';
|
|
4
4
|
import { interval, point } from '../../adaptor/geometries';
|
|
5
|
+
import { pattern } from '../../adaptor/pattern';
|
|
5
6
|
import { processIllegalData } from '../../utils';
|
|
6
7
|
import { RadialBarOptions } from './types';
|
|
7
8
|
import { getScaleMax, getStackedData } from './utils';
|
|
@@ -131,6 +132,7 @@ function label(params: Params<RadialBarOptions>): Params<RadialBarOptions> {
|
|
|
131
132
|
*/
|
|
132
133
|
export function adaptor(params: Params<RadialBarOptions>) {
|
|
133
134
|
return flow(
|
|
135
|
+
pattern('barStyle'),
|
|
134
136
|
geometry,
|
|
135
137
|
meta,
|
|
136
138
|
axis,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { filter, isObject, isArray } from '@antv/util';
|
|
2
2
|
import { Params } from '../../core/adaptor';
|
|
3
3
|
import { flow, findGeometry, log, LEVEL, transformLabel, deepAssign } from '../../utils';
|
|
4
|
-
import { tooltip, interaction, animation, theme, scale, annotation, state } from '../../adaptor/common';
|
|
4
|
+
import { tooltip, interaction, animation, theme, scale, annotation, state, pattern } from '../../adaptor/common';
|
|
5
5
|
import { interval } from '../../adaptor/geometries';
|
|
6
6
|
import { RoseOptions } from './types';
|
|
7
7
|
|
|
@@ -155,6 +155,7 @@ function axis(params: Params<RoseOptions>): Params<RoseOptions> {
|
|
|
155
155
|
export function adaptor(params: Params<RoseOptions>) {
|
|
156
156
|
// flow 的方式处理所有的配置到 G2 API
|
|
157
157
|
flow(
|
|
158
|
+
pattern('sectorStyle'),
|
|
158
159
|
geometry,
|
|
159
160
|
meta,
|
|
160
161
|
label,
|
|
@@ -2,7 +2,7 @@ import { isFunction, get, uniq } from '@antv/util';
|
|
|
2
2
|
import { Types } from '@antv/g2';
|
|
3
3
|
import { Params } from '../../core/adaptor';
|
|
4
4
|
import { polygon as polygonAdaptor } from '../../adaptor/geometries';
|
|
5
|
-
import { interaction as baseInteraction, animation, theme, annotation, scale } from '../../adaptor/common';
|
|
5
|
+
import { interaction as baseInteraction, animation, theme, annotation, scale, pattern } from '../../adaptor/common';
|
|
6
6
|
import { flow, findGeometry, transformLabel, deepAssign } from '../../utils';
|
|
7
7
|
import { getAdjustAppendPadding } from '../../utils/padding';
|
|
8
8
|
import { Datum } from '../../types';
|
|
@@ -227,6 +227,7 @@ export function adaptor(params: Params<SunburstOptions>) {
|
|
|
227
227
|
// flow 的方式处理所有的配置到 G2 API
|
|
228
228
|
return flow(
|
|
229
229
|
theme,
|
|
230
|
+
pattern('sunburstStyle'),
|
|
230
231
|
geometry,
|
|
231
232
|
axis,
|
|
232
233
|
meta,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { theme, scale, animation, annotation, tooltip } from '../../adaptor/common';
|
|
1
|
+
import { theme, scale, animation, annotation, tooltip, pattern } from '../../adaptor/common';
|
|
2
2
|
import { Params } from '../../core/adaptor';
|
|
3
3
|
import { flow, deepAssign } from '../../utils';
|
|
4
4
|
import { area, line, point } from '../../adaptor/geometries';
|
|
@@ -74,5 +74,5 @@ export function meta(params: Params<TinyAreaOptions>): Params<TinyAreaOptions> {
|
|
|
74
74
|
* @param options
|
|
75
75
|
*/
|
|
76
76
|
export function adaptor(params: Params<TinyAreaOptions>) {
|
|
77
|
-
return flow(geometry, meta, tooltip, theme, animation, annotation())(params);
|
|
77
|
+
return flow(pattern('areaStyle'), geometry, meta, tooltip, theme, animation, annotation())(params);
|
|
78
78
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { theme, animation, annotation, tooltip } from '../../adaptor/common';
|
|
1
|
+
import { theme, animation, annotation, tooltip, pattern } from '../../adaptor/common';
|
|
2
2
|
import { Params } from '../../core/adaptor';
|
|
3
3
|
import { flow, deepAssign } from '../../utils';
|
|
4
4
|
import { interval } from '../../adaptor/geometries';
|
|
@@ -46,5 +46,5 @@ function geometry(params: Params<TinyColumnOptions>): Params<TinyColumnOptions>
|
|
|
46
46
|
* @param options
|
|
47
47
|
*/
|
|
48
48
|
export function adaptor(params: Params<TinyColumnOptions>) {
|
|
49
|
-
return flow(geometry, meta, tooltip,
|
|
49
|
+
return flow(theme, pattern('columnStyle'), geometry, meta, tooltip, animation, annotation())(params);
|
|
50
50
|
}
|
|
@@ -2,6 +2,7 @@ import { get } from '@antv/util';
|
|
|
2
2
|
import { polygon as basePolygon } from '../../adaptor/geometries/polygon';
|
|
3
3
|
import { Params } from '../../core/adaptor';
|
|
4
4
|
import { interaction as commonInteraction, animation, theme, legend, annotation, tooltip } from '../../adaptor/common';
|
|
5
|
+
import { pattern } from '../../adaptor/pattern';
|
|
5
6
|
import { flow, deepAssign } from '../../utils';
|
|
6
7
|
import { getAdjustAppendPadding } from '../../utils/padding';
|
|
7
8
|
import { transformData, findInteraction, enableDrillInteraction } from './utils';
|
|
@@ -145,5 +146,16 @@ export function interaction(params: Params<TreemapOptions>): Params<TreemapOptio
|
|
|
145
146
|
* @param options
|
|
146
147
|
*/
|
|
147
148
|
export function adaptor(params: Params<TreemapOptions>) {
|
|
148
|
-
return flow(
|
|
149
|
+
return flow(
|
|
150
|
+
defaultOptions,
|
|
151
|
+
theme,
|
|
152
|
+
pattern('rectStyle'),
|
|
153
|
+
geometry,
|
|
154
|
+
axis,
|
|
155
|
+
legend,
|
|
156
|
+
tooltip,
|
|
157
|
+
interaction,
|
|
158
|
+
animation,
|
|
159
|
+
annotation()
|
|
160
|
+
)(params);
|
|
149
161
|
}
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
import { Geometry } from '@antv/g2';
|
|
2
|
+
import { isArray, get, deepMix, isEqual } from '@antv/util';
|
|
3
|
+
import { interaction, animation, theme, tooltip, scale } from '../../adaptor/common';
|
|
4
|
+
import { Params } from '../../core/adaptor';
|
|
5
|
+
import { schema as schemaGeometry } from '../../adaptor/geometries';
|
|
6
|
+
import {
|
|
7
|
+
deepAssign,
|
|
8
|
+
flow,
|
|
9
|
+
findGeometry,
|
|
10
|
+
transformLabel,
|
|
11
|
+
getAdjustAppendPadding,
|
|
12
|
+
normalPadding,
|
|
13
|
+
resolveAllPadding,
|
|
14
|
+
} from '../../utils';
|
|
15
|
+
import { Datum } from '../../types';
|
|
16
|
+
import { log, LEVEL } from '../../utils';
|
|
17
|
+
import { getColorMap, layoutVennData, islegalSets } from './utils';
|
|
18
|
+
import { CustomInfo, VennData, VennOptions } from './types';
|
|
19
|
+
import { ID_FIELD } from './constant';
|
|
20
|
+
import './shape';
|
|
21
|
+
import './label';
|
|
22
|
+
import './interaction';
|
|
23
|
+
|
|
24
|
+
/** 图例默认预留空间 */
|
|
25
|
+
export const LEGEND_SPACE = 40;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* color options 转换
|
|
29
|
+
*/
|
|
30
|
+
function transformColor(params: Params<VennOptions>, data: VennData): VennOptions['color'] {
|
|
31
|
+
const { chart, options } = params;
|
|
32
|
+
const { color, setsField } = options;
|
|
33
|
+
|
|
34
|
+
if (typeof color !== 'function') {
|
|
35
|
+
let colorPalette = typeof color === 'string' ? [color] : color;
|
|
36
|
+
if (!isArray(colorPalette)) {
|
|
37
|
+
const { colors10, colors20 } = chart.getTheme();
|
|
38
|
+
colorPalette = data.filter((d) => d[setsField].length === 1).length <= 10 ? colors10 : colors20;
|
|
39
|
+
}
|
|
40
|
+
const colorMap = getColorMap(colorPalette, data, options);
|
|
41
|
+
return (datum: Datum) => colorMap.get(datum[ID_FIELD]) || colorPalette[0];
|
|
42
|
+
}
|
|
43
|
+
return color;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* 处理 padding
|
|
48
|
+
*/
|
|
49
|
+
function padding(params: Params<VennOptions>): Params<VennOptions> {
|
|
50
|
+
const { chart, options } = params;
|
|
51
|
+
const { legend, appendPadding, padding } = options;
|
|
52
|
+
|
|
53
|
+
// 处理 legend 的位置. 默认预留 40px, 业务上可以通过 appendPadding 增加
|
|
54
|
+
let tempPadding: number[] = normalPadding(appendPadding);
|
|
55
|
+
if (legend !== false) {
|
|
56
|
+
tempPadding = getAdjustAppendPadding(appendPadding, get(legend, 'position'), LEGEND_SPACE);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
chart.appendPadding = resolveAllPadding([tempPadding, padding]);
|
|
60
|
+
|
|
61
|
+
return params;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* 处理非法数据
|
|
66
|
+
* @param params
|
|
67
|
+
*/
|
|
68
|
+
function data(params: Params<VennOptions>): Params<VennOptions> {
|
|
69
|
+
const { options } = params;
|
|
70
|
+
|
|
71
|
+
/* 如遇到 交集 中存在 非法元素 的情况,就过滤掉
|
|
72
|
+
* 如:
|
|
73
|
+
* data = [
|
|
74
|
+
* { sets: ['A'], size: 3 }, // 集合
|
|
75
|
+
* { sets: ['B'], size: 4 }, // 集合
|
|
76
|
+
* { sets: ['A', 'B'], size: 2 }, // 交集
|
|
77
|
+
* { sets: ['A', 'B', 'C'], size: 2 }, // 交集 (存在非法 C,过滤该条数据)
|
|
78
|
+
* ...
|
|
79
|
+
* ]
|
|
80
|
+
*/
|
|
81
|
+
|
|
82
|
+
let data = options['data'];
|
|
83
|
+
if (!data) {
|
|
84
|
+
log(LEVEL.WARN, false, 'warn: %s', '数据不能为空');
|
|
85
|
+
data = [];
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// 合法元素的集合:['A', 'B']
|
|
89
|
+
const currSets = data.filter((datum) => datum.sets.length === 1).map((datum) => datum.sets[0]);
|
|
90
|
+
// 过滤 data
|
|
91
|
+
const filterSets = data.filter((datum) => {
|
|
92
|
+
const sets = datum.sets;
|
|
93
|
+
// 存在非法元素,就过滤这条数据
|
|
94
|
+
return islegalSets(currSets, sets);
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
if (!isEqual(filterSets, data)) log(LEVEL.WARN, false, 'warn: %s', '交集中不能出现不存在的集合, 请输入合法数据');
|
|
98
|
+
|
|
99
|
+
return deepMix({}, params, {
|
|
100
|
+
options: {
|
|
101
|
+
data: filterSets,
|
|
102
|
+
},
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* geometry 处理
|
|
108
|
+
* @param params
|
|
109
|
+
*/
|
|
110
|
+
function geometry(params: Params<VennOptions>): Params<VennOptions> {
|
|
111
|
+
const { chart, options } = params;
|
|
112
|
+
const { pointStyle, setsField, sizeField } = options;
|
|
113
|
+
|
|
114
|
+
// 获取容器大小
|
|
115
|
+
const [t, r, b, l] = normalPadding(chart.appendPadding);
|
|
116
|
+
// 处理 legend 的位置. 默认预留 40px, 业务上可以通过 appendPadding 增加
|
|
117
|
+
const customInfo: CustomInfo = { offsetX: l, offsetY: t };
|
|
118
|
+
// coordinateBBox + appendPadding = viewBBox, 不需要再计算 appendPadding 部分,因此直接使用 viewBBox
|
|
119
|
+
const { width, height } = chart.viewBBox;
|
|
120
|
+
// 处理padding输入不合理的情况, w 和 h 不能为负数
|
|
121
|
+
const vennData: VennData = layoutVennData(options, Math.max(width - (r + l), 0), Math.max(height - (t + b), 0), 0);
|
|
122
|
+
chart.data(vennData);
|
|
123
|
+
|
|
124
|
+
const { ext } = schemaGeometry(
|
|
125
|
+
deepAssign({}, params, {
|
|
126
|
+
options: {
|
|
127
|
+
xField: 'x',
|
|
128
|
+
yField: 'y',
|
|
129
|
+
sizeField: sizeField,
|
|
130
|
+
seriesField: ID_FIELD,
|
|
131
|
+
rawFields: [setsField, sizeField],
|
|
132
|
+
schema: {
|
|
133
|
+
shape: 'venn',
|
|
134
|
+
style: pointStyle,
|
|
135
|
+
color: transformColor(params, vennData),
|
|
136
|
+
},
|
|
137
|
+
},
|
|
138
|
+
})
|
|
139
|
+
);
|
|
140
|
+
|
|
141
|
+
const geometry = ext.geometry as Geometry;
|
|
142
|
+
geometry.customInfo(customInfo);
|
|
143
|
+
|
|
144
|
+
return params;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* 处理 label
|
|
149
|
+
* @param params
|
|
150
|
+
*/
|
|
151
|
+
function label(params: Params<VennOptions>): Params<VennOptions> {
|
|
152
|
+
const { chart, options } = params;
|
|
153
|
+
const { label } = options;
|
|
154
|
+
|
|
155
|
+
// 获取容器大小
|
|
156
|
+
const [t, r, b, l] = normalPadding(chart.appendPadding);
|
|
157
|
+
// 传入 label 布局函数所需的 自定义参数
|
|
158
|
+
const customLabelInfo = { offsetX: l, offsetY: t };
|
|
159
|
+
|
|
160
|
+
const geometry = findGeometry(chart, 'schema');
|
|
161
|
+
|
|
162
|
+
if (!label) {
|
|
163
|
+
geometry.label(false);
|
|
164
|
+
} else {
|
|
165
|
+
const { callback, ...cfg } = label;
|
|
166
|
+
geometry.label({
|
|
167
|
+
fields: ['id'],
|
|
168
|
+
callback,
|
|
169
|
+
cfg: deepMix({}, transformLabel(cfg), {
|
|
170
|
+
// 使用 G2 的 自定义label 修改位置
|
|
171
|
+
type: 'venn',
|
|
172
|
+
customLabelInfo,
|
|
173
|
+
}),
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
return params;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* legend 配置
|
|
182
|
+
* @param params
|
|
183
|
+
*/
|
|
184
|
+
export function legend(params: Params<VennOptions>): Params<VennOptions> {
|
|
185
|
+
const { chart, options } = params;
|
|
186
|
+
const { legend, sizeField } = options;
|
|
187
|
+
|
|
188
|
+
chart.legend(ID_FIELD, legend);
|
|
189
|
+
// 强制不开启 连续图例
|
|
190
|
+
chart.legend(sizeField, false);
|
|
191
|
+
|
|
192
|
+
return params;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* 默认关闭坐标轴
|
|
197
|
+
* @param params
|
|
198
|
+
*/
|
|
199
|
+
export function axis(params: Params<VennOptions>): Params<VennOptions> {
|
|
200
|
+
const { chart } = params;
|
|
201
|
+
chart.axis(false);
|
|
202
|
+
|
|
203
|
+
return params;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* 图适配器
|
|
208
|
+
* @param chart
|
|
209
|
+
* @param options
|
|
210
|
+
*/
|
|
211
|
+
export function adaptor(params: Params<VennOptions>) {
|
|
212
|
+
// flow 的方式处理所有的配置到 G2 API
|
|
213
|
+
return flow(
|
|
214
|
+
padding,
|
|
215
|
+
theme,
|
|
216
|
+
data,
|
|
217
|
+
geometry,
|
|
218
|
+
label,
|
|
219
|
+
scale({}),
|
|
220
|
+
legend,
|
|
221
|
+
axis,
|
|
222
|
+
tooltip,
|
|
223
|
+
interaction,
|
|
224
|
+
animation
|
|
225
|
+
// ... 其他的 adaptor flow
|
|
226
|
+
)(params);
|
|
227
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { VennOptions } from './types';
|
|
2
|
+
|
|
3
|
+
// 一些字段常量定义,需要在文档初告知用户
|
|
4
|
+
export const ID_FIELD = 'id';
|
|
5
|
+
export const PATH_FIELD = 'path';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* 韦恩图 默认配置项
|
|
9
|
+
*/
|
|
10
|
+
export const DEFAULT_OPTIONS: Partial<VennOptions> = {
|
|
11
|
+
appendPadding: [10, 0, 20, 0],
|
|
12
|
+
blendMode: 'multiply',
|
|
13
|
+
tooltip: {
|
|
14
|
+
showTitle: false,
|
|
15
|
+
showMarkers: false,
|
|
16
|
+
fields: ['id', 'size'],
|
|
17
|
+
formatter: (datum) => {
|
|
18
|
+
return { name: datum.id, value: datum.size };
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
legend: { position: 'top-left' },
|
|
22
|
+
label: {
|
|
23
|
+
style: {
|
|
24
|
+
textAlign: 'center',
|
|
25
|
+
fill: '#fff',
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
// 默认不开启 图例筛选交互
|
|
29
|
+
interactions: [
|
|
30
|
+
{ type: 'legend-filter', enable: false },
|
|
31
|
+
// hover 激活的时候,元素的层级展示不太好 先移除该交互
|
|
32
|
+
{ type: 'legend-highlight', enable: false },
|
|
33
|
+
{ type: 'legend-active', enable: false },
|
|
34
|
+
],
|
|
35
|
+
};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Plot } from '../../core/plot';
|
|
2
|
+
import { Adaptor } from '../../core/adaptor';
|
|
3
|
+
import { VennOptions } from './types';
|
|
4
|
+
import { adaptor } from './adaptor';
|
|
5
|
+
import { DEFAULT_OPTIONS } from './constant';
|
|
6
|
+
|
|
7
|
+
export type { VennOptions };
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* 这个是一个图表开发的 模板代码!
|
|
11
|
+
*/
|
|
12
|
+
export class Venn extends Plot<VennOptions> {
|
|
13
|
+
/** 图表类型 */
|
|
14
|
+
public type: string = 'venn';
|
|
15
|
+
|
|
16
|
+
static getDefaultOptions() {
|
|
17
|
+
return DEFAULT_OPTIONS;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* 获取 韦恩图 默认配置
|
|
22
|
+
*/
|
|
23
|
+
protected getDefaultOptions() {
|
|
24
|
+
return Venn.getDefaultOptions();
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* 获取适配器
|
|
29
|
+
*/
|
|
30
|
+
protected getSchemaAdaptor(): Adaptor<VennOptions> {
|
|
31
|
+
return adaptor;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* 覆写父类的方法
|
|
36
|
+
*/
|
|
37
|
+
protected triggerResize() {
|
|
38
|
+
if (!this.chart.destroyed) {
|
|
39
|
+
// 首先自适应容器的宽高
|
|
40
|
+
this.chart.forceFit(); // g2 内部执行 changeSize,changeSize 中执行 render(true)
|
|
41
|
+
this.chart.clear();
|
|
42
|
+
this.execAdaptor(); // 核心:宽高更新之后计算布局
|
|
43
|
+
// 渲染
|
|
44
|
+
this.chart.render(true);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { InteractionAction } from '@antv/g2';
|
|
2
|
+
|
|
3
|
+
class VennElementState extends InteractionAction {
|
|
4
|
+
/** tofront: 同步所有元素的位置 */
|
|
5
|
+
protected syncElementsPos() {
|
|
6
|
+
const elements = this.context.view.geometries[0].elements;
|
|
7
|
+
elements.forEach((elem) => {
|
|
8
|
+
elem.shape.toFront();
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export class VennElementActive extends VennElementState {
|
|
14
|
+
/** hover */
|
|
15
|
+
public active() {
|
|
16
|
+
const { data } = this.context.event.data;
|
|
17
|
+
const elements = this.context.view.geometries[0].elements;
|
|
18
|
+
|
|
19
|
+
elements.forEach((elem) => {
|
|
20
|
+
const activeState = data === elem.getData();
|
|
21
|
+
elem.setState('active', activeState);
|
|
22
|
+
});
|
|
23
|
+
// tofront: 同步所有元素的位置
|
|
24
|
+
this.syncElementsPos();
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** 重置 */
|
|
28
|
+
public reset() {
|
|
29
|
+
const elements = this.context.view.geometries[0].elements;
|
|
30
|
+
|
|
31
|
+
elements.forEach((elem) => {
|
|
32
|
+
// 所有元素的 state 统一 false
|
|
33
|
+
elem.setState('active', false);
|
|
34
|
+
});
|
|
35
|
+
// tofront: 同步所有元素的位置
|
|
36
|
+
this.syncElementsPos();
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export class VennElementSelected extends VennElementState {
|
|
41
|
+
/** 切换 */
|
|
42
|
+
public toggle() {
|
|
43
|
+
const { data } = this.context.event.data;
|
|
44
|
+
const elements = this.context.view.geometries[0].elements;
|
|
45
|
+
|
|
46
|
+
elements.forEach((elem) => {
|
|
47
|
+
if (data === elem.getData()) {
|
|
48
|
+
const selectedState = elem.getStates().includes('selected');
|
|
49
|
+
elem.setState('selected', !selectedState);
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
// tofront: 同步所有元素的位置
|
|
53
|
+
this.syncElementsPos();
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** 重置 */
|
|
57
|
+
public reset() {
|
|
58
|
+
const elements = this.context.view.geometries[0].elements;
|
|
59
|
+
|
|
60
|
+
elements.forEach((elem) => {
|
|
61
|
+
// 所有元素的 state 统一 false
|
|
62
|
+
elem.setState('selected', false);
|
|
63
|
+
});
|
|
64
|
+
// tofront: 同步所有元素的位置
|
|
65
|
+
this.syncElementsPos();
|
|
66
|
+
}
|
|
67
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { registerInteraction, registerAction } from '@antv/g2';
|
|
2
|
+
import { VennElementActive, VennElementSelected } from './action';
|
|
3
|
+
|
|
4
|
+
registerAction('venn-element-active', VennElementActive);
|
|
5
|
+
registerAction('venn-element-selected', VennElementSelected);
|
|
6
|
+
|
|
7
|
+
// 移动到 venn elment 上的 active
|
|
8
|
+
registerInteraction('venn-element-active', {
|
|
9
|
+
start: [{ trigger: 'element:mouseenter', action: 'venn-element-active:active' }],
|
|
10
|
+
end: [{ trigger: 'element:mouseleave', action: 'venn-element-active:reset' }],
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
// 点击 venn element (可多选)
|
|
14
|
+
registerInteraction('venn-element-selected', {
|
|
15
|
+
start: [{ trigger: 'element:click', action: 'venn-element-selected:toggle' }],
|
|
16
|
+
rollback: [{ trigger: 'dblclick', action: ['venn-element-selected:reset'] }],
|
|
17
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { registerGeometryLabel, GeometryLabel } from '@antv/g2';
|
|
2
|
+
|
|
3
|
+
// Step 1
|
|
4
|
+
// 自定义 Label 类
|
|
5
|
+
// 需要继承 GeometryLabel 基类
|
|
6
|
+
class VennLabel extends GeometryLabel {
|
|
7
|
+
/**
|
|
8
|
+
* 获取每个 label 的位置
|
|
9
|
+
* @param labelCfg
|
|
10
|
+
* @param mappingData
|
|
11
|
+
* @param index
|
|
12
|
+
* @returns label point
|
|
13
|
+
*/
|
|
14
|
+
protected getLabelPoint(labelCfg, mappingData, index: number) {
|
|
15
|
+
const { x, y } = labelCfg.data;
|
|
16
|
+
const { offsetX, offsetY } = labelCfg.customLabelInfo;
|
|
17
|
+
return {
|
|
18
|
+
content: labelCfg.content[index],
|
|
19
|
+
x: x + offsetX,
|
|
20
|
+
y: y + offsetY,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// Step 2: 注册 CustomLabel
|
|
26
|
+
registerGeometryLabel('venn', VennLabel);
|