@antv/g2 5.1.8 → 5.1.9

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.
Files changed (79) hide show
  1. package/CHANGELOG.md +471 -0
  2. package/README.md +7 -0
  3. package/README.zh-CN.md +7 -0
  4. package/dist/g2.lite.min.js +1 -1
  5. package/dist/g2.min.js +1 -1
  6. package/esm/component/slider.js +1 -1
  7. package/esm/component/slider.js.map +1 -1
  8. package/esm/data/utils/arc/arc.js +4 -4
  9. package/esm/data/utils/arc/arc.js.map +1 -1
  10. package/esm/index.d.ts +2 -0
  11. package/esm/interaction/tooltip.js +2 -2
  12. package/esm/interaction/tooltip.js.map +1 -1
  13. package/esm/interaction/utils.d.ts +1 -0
  14. package/esm/interaction/utils.js +7 -1
  15. package/esm/interaction/utils.js.map +1 -1
  16. package/esm/lib/graph.d.ts +1 -0
  17. package/esm/lib/graph.js +2 -1
  18. package/esm/lib/graph.js.map +1 -1
  19. package/esm/lib/std.d.ts +1 -0
  20. package/esm/mark/chord.d.ts +4 -0
  21. package/esm/mark/chord.js +119 -0
  22. package/esm/mark/chord.js.map +1 -0
  23. package/esm/mark/index.d.ts +2 -0
  24. package/esm/mark/index.js +1 -0
  25. package/esm/mark/index.js.map +1 -1
  26. package/esm/runtime/scale.js +11 -18
  27. package/esm/runtime/scale.js.map +1 -1
  28. package/esm/shape/area/curve.js +5 -2
  29. package/esm/shape/area/curve.js.map +1 -1
  30. package/esm/shape/line/curve.js +4 -3
  31. package/esm/shape/line/curve.js.map +1 -1
  32. package/esm/shape/utils.d.ts +1 -1
  33. package/esm/shape/utils.js +21 -2
  34. package/esm/shape/utils.js.map +1 -1
  35. package/esm/spec/mark.d.ts +17 -2
  36. package/lib/component/slider.js +1 -1
  37. package/lib/component/slider.js.map +1 -1
  38. package/lib/data/utils/arc/arc.js +4 -4
  39. package/lib/data/utils/arc/arc.js.map +1 -1
  40. package/lib/index.d.ts +2 -0
  41. package/lib/interaction/tooltip.js +1 -1
  42. package/lib/interaction/tooltip.js.map +1 -1
  43. package/lib/interaction/utils.d.ts +1 -0
  44. package/lib/interaction/utils.js +9 -2
  45. package/lib/interaction/utils.js.map +1 -1
  46. package/lib/lib/graph.d.ts +1 -0
  47. package/lib/lib/graph.js +1 -0
  48. package/lib/lib/graph.js.map +1 -1
  49. package/lib/lib/std.d.ts +1 -0
  50. package/lib/mark/chord.d.ts +4 -0
  51. package/lib/mark/chord.js +123 -0
  52. package/lib/mark/chord.js.map +1 -0
  53. package/lib/mark/index.d.ts +2 -0
  54. package/lib/mark/index.js +3 -1
  55. package/lib/mark/index.js.map +1 -1
  56. package/lib/runtime/scale.js +11 -18
  57. package/lib/runtime/scale.js.map +1 -1
  58. package/lib/shape/area/curve.js +5 -2
  59. package/lib/shape/area/curve.js.map +1 -1
  60. package/lib/shape/line/curve.js +3 -2
  61. package/lib/shape/line/curve.js.map +1 -1
  62. package/lib/shape/utils.d.ts +1 -1
  63. package/lib/shape/utils.js +21 -2
  64. package/lib/shape/utils.js.map +1 -1
  65. package/lib/spec/mark.d.ts +17 -2
  66. package/package.json +4 -7
  67. package/src/component/slider.ts +1 -1
  68. package/src/data/utils/arc/arc.ts +4 -4
  69. package/src/interaction/tooltip.ts +2 -1
  70. package/src/interaction/utils.ts +7 -1
  71. package/src/lib/graph.ts +2 -1
  72. package/src/mark/chord.ts +159 -0
  73. package/src/mark/index.ts +2 -0
  74. package/src/runtime/scale.ts +11 -16
  75. package/src/shape/area/curve.ts +6 -2
  76. package/src/shape/line/curve.ts +6 -3
  77. package/src/shape/utils.ts +20 -1
  78. package/src/spec/mark.ts +31 -0
  79. package/dist/g2.full.min.js +0 -1
@@ -9,8 +9,8 @@ import { Theme } from './theme';
9
9
  import { Data } from './data';
10
10
  import { AxisComponent, LegendComponent, ScrollbarComponent, SliderComponent, TitleComponent, TooltipComponent } from './component';
11
11
  import { Closeable, Literal2Object, Padding } from './utils';
12
- export type Mark = IntervalMark | RectMark | LineMark | PointMark | TextMark | CellMark | AreaMark | NodeMark | EdgeMark | ImageMark | PolygonMark | BoxMark | VectorMark | LineXMark | LineYMark | RangeMark | RangeXMark | RangeYMark | ConnectorMark | SankeyMark | PathMark | TreemapMark | PackMark | BoxPlotMark | ShapeMark | ForceGraphMark | TreeMark | WordCloudMark | DensityMark | CustomMark | CompositeMark;
13
- export type MarkTypes = 'auto' | 'interval' | 'rect' | 'line' | 'point' | 'text' | 'cell' | 'area' | 'node' | 'edge' | 'link' | 'image' | 'polygon' | 'box' | 'vector' | 'lineX' | 'lineY' | 'connector' | 'range' | 'rangeX' | 'rangeY' | 'sankey' | 'path' | 'treemap' | 'pack' | 'boxplot' | 'shape' | 'forceGraph' | 'tree' | 'wordCloud' | 'gauge' | 'density' | 'heatmap' | 'liquid' | MarkComponent | CompositeMarkType;
12
+ export type Mark = IntervalMark | RectMark | LineMark | PointMark | TextMark | CellMark | AreaMark | NodeMark | EdgeMark | ImageMark | PolygonMark | BoxMark | VectorMark | LineXMark | LineYMark | RangeMark | RangeXMark | RangeYMark | ConnectorMark | SankeyMark | ChordMark | PathMark | TreemapMark | PackMark | BoxPlotMark | ShapeMark | ForceGraphMark | TreeMark | WordCloudMark | DensityMark | CustomMark | CompositeMark;
13
+ export type MarkTypes = 'auto' | 'interval' | 'rect' | 'line' | 'point' | 'text' | 'cell' | 'area' | 'node' | 'edge' | 'link' | 'image' | 'polygon' | 'box' | 'vector' | 'lineX' | 'lineY' | 'connector' | 'range' | 'rangeX' | 'rangeY' | 'sankey' | 'chord' | 'path' | 'treemap' | 'pack' | 'boxplot' | 'shape' | 'forceGraph' | 'tree' | 'wordCloud' | 'gauge' | 'density' | 'heatmap' | 'liquid' | MarkComponent | CompositeMarkType;
14
14
  export type ChannelTypes = 'x' | 'y' | 'z' | 'x1' | 'y1' | 'series' | 'color' | 'opacity' | 'shape' | 'size' | 'key' | 'groupKey' | 'position' | 'series' | 'enterType' | 'enterEasing' | 'enterDuration' | 'enterDelay' | 'updateType' | 'updateEasing' | 'updateDuration' | 'updateDelay' | 'exitType' | 'exitEasing' | 'exitDuration' | 'exitDelay' | `position${number}`;
15
15
  export type PositionChannelTypes = 'x' | 'y' | 'z' | 'position' | `position${number}`;
16
16
  export type AtheisticChanelTypes = 'size' | 'color' | 'shape' | 'opacity';
@@ -112,6 +112,21 @@ export type SankeyMark = BaseMark<'sankey', 'source' | 'target' | 'value' | `nod
112
112
  nodeLabels: Record<string, any>[];
113
113
  linkLabels: Record<string, any>[];
114
114
  };
115
+ export type ChordMark = BaseMark<'chord', 'source' | 'target' | 'value' | `node${Capitalize<ChannelTypes>}` | `link${Capitalize<ChannelTypes>}` | ChannelTypes> & {
116
+ layout?: {
117
+ nodes?: (graph: any) => any;
118
+ links?: (graph: any) => any;
119
+ y?: number;
120
+ id?: (node: any) => any;
121
+ sortBy?: 'id' | 'weight' | 'frequency' | null | ((a: any, b: any) => number);
122
+ nodeWidthRatio?: number;
123
+ nodePaddingRatio?: number;
124
+ sourceWeight?(edge: any): number;
125
+ targetWeight?(edge: any): number;
126
+ };
127
+ nodeLabels: Record<string, any>[];
128
+ linkLabels: Record<string, any>[];
129
+ };
115
130
  export type PathMark = BaseMark<'path', ChannelTypes | 'd'>;
116
131
  export type TreemapMark = BaseMark<'treemap', 'value' | ChannelTypes> & {
117
132
  layout?: Record<string, any>;
package/package.json CHANGED
@@ -1,11 +1,12 @@
1
1
  {
2
2
  "name": "@antv/g2",
3
- "version": "5.1.8",
3
+ "version": "5.1.9",
4
4
  "description": "the Grammar of Graphics in Javascript",
5
5
  "license": "MIT",
6
6
  "main": "lib/index.js",
7
7
  "module": "esm/index.js",
8
8
  "types": "lib/index.d.ts",
9
+ "unpkg": "dist/g2.min.js",
9
10
  "exports": {
10
11
  ".": {
11
12
  "types": "./lib/index.d.ts",
@@ -40,6 +41,7 @@
40
41
  "build": "run-p build:*",
41
42
  "bundle-vis": "cross-env BUNDLE_VIS=1 run-p build:umd",
42
43
  "ci": "run-s lint test build",
44
+ "prepublishOnly": "npm run ci",
43
45
  "prepare": "husky install",
44
46
  "upload": "node scripts/upload/snapshot.js",
45
47
  "changelog": "conventional-changelog -p angular -i CHANGELOG.md -s",
@@ -87,7 +89,7 @@
87
89
  "@antv/g-plugin-rough-svg-renderer": "^1.9.22",
88
90
  "@antv/g-svg": "^1.10.21",
89
91
  "@antv/g-webgl": "^1.9.29",
90
- "@antv/g2-extension-3d": "0.1.1",
92
+ "@antv/g2-extension-3d": "^0.1.3",
91
93
  "@antv/g2-extension-ava": "^0.1.1",
92
94
  "@antv/translator": "^1.0.1",
93
95
  "@commitlint/cli": "^11.0.0",
@@ -161,11 +163,6 @@
161
163
  "path": "dist/g2.lite.min.js",
162
164
  "limit": "240 Kb",
163
165
  "gzip": true
164
- },
165
- {
166
- "path": "dist/g2.full.min.js",
167
- "limit": "350 Kb",
168
- "gzip": true
169
166
  }
170
167
  ],
171
168
  "author": {
@@ -37,7 +37,7 @@ export const Slider: GCC<SliderOptions> = (options) => {
37
37
 
38
38
  const { width, height } = bbox;
39
39
  const { slider: sliderTheme = {} } = theme;
40
- const defaultFormatter = scale.getFormatter?.() || ((v) => v.toString());
40
+ const defaultFormatter = scale.getFormatter?.() || ((v) => v + '');
41
41
  const formatter =
42
42
  typeof labelFormatter === 'string'
43
43
  ? format(labelFormatter)
@@ -190,16 +190,16 @@ export function Arc(options?: ArcOptions) {
190
190
  */
191
191
  sourceEdges.map((edge) => {
192
192
  const w = (edge.sourceWeight / value) * width;
193
- edge.x[0] = node.x[0] + offset;
194
- edge.x[1] = node.x[0] + offset + w;
193
+ edge.x[0] = x[0] + offset;
194
+ edge.x[1] = x[0] + offset + w;
195
195
 
196
196
  offset += w;
197
197
  });
198
198
 
199
199
  targetEdges.forEach((edge) => {
200
200
  const w = (edge.targetWeight / value) * width;
201
- edge.x[3] = node.x[0] + offset;
202
- edge.x[2] = node.x[0] + offset + w;
201
+ edge.x[3] = x[0] + offset;
202
+ edge.x[2] = x[0] + offset + w;
203
203
 
204
204
  offset += w;
205
205
  });
@@ -16,6 +16,7 @@ import {
16
16
  selectFacetG2Elements,
17
17
  createDatumof,
18
18
  selectElementByData,
19
+ bboxOf,
19
20
  } from './utils';
20
21
  import { dataOf } from './event';
21
22
 
@@ -563,7 +564,7 @@ export function seriesTooltip(
563
564
  (event) => {
564
565
  const mouse = mousePosition(root, event);
565
566
  if (!mouse) return;
566
- const bbox = root.getRenderBounds();
567
+ const bbox = bboxOf(root);
567
568
  const x = bbox.min[0];
568
569
  const y = bbox.min[1];
569
570
  const focus = [mouse[0] - startX, mouse[1] - startY];
@@ -42,9 +42,15 @@ export function selectPlotArea(root: DisplayObject): DisplayObject {
42
42
  return select(root).select(`.${PLOT_CLASS_NAME}`).node();
43
43
  }
44
44
 
45
+ export function bboxOf(node) {
46
+ if (node.nodeName !== 'rect') return node.getRenderBounds();
47
+ const { x, y, width, height } = node.style;
48
+ return { min: [x, y], max: [x + width, y + height] };
49
+ }
50
+
45
51
  export function mousePosition(target, event) {
46
52
  const { offsetX, offsetY } = event;
47
- const bbox = target.getRenderBounds();
53
+ const bbox = bboxOf(target);
48
54
  const {
49
55
  min: [x, y],
50
56
  max: [x1, y1],
package/src/lib/graph.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Sankey, Treemap, Pack, ForceGraph, Tree } from '../mark';
1
+ import { Sankey, Treemap, Pack, ForceGraph, Tree, Chord } from '../mark';
2
2
  import { Arc, Cluster } from '../data';
3
3
 
4
4
  export function graphlib() {
@@ -9,6 +9,7 @@ export function graphlib() {
9
9
  'mark.tree': Tree,
10
10
  'mark.pack': Pack,
11
11
  'mark.sankey': Sankey,
12
+ 'mark.chord': Chord,
12
13
  'mark.treemap': Treemap,
13
14
  } as const;
14
15
  }
@@ -0,0 +1,159 @@
1
+ import { deepMix } from '@antv/util';
2
+ import { CompositeMarkComponent as CC, MarkOptions } from '../runtime';
3
+ import { ChordMark } from '../spec';
4
+ import { subObject } from '../utils/helper';
5
+ import { subTooltip, maybeAnimation } from '../utils/mark';
6
+ import { Arc } from '../data/arc';
7
+ import { ArcOptions } from '../data/utils/arc/types';
8
+ import { field, initializeData } from './utils';
9
+
10
+ const DEFAULT_LAYOUT_OPTIONS: ArcOptions = {
11
+ y: 0,
12
+ thickness: 0.05, // width of the node, (0, 1)
13
+ marginRatio: 0.1, // margin ratio, [0, 1)
14
+ id: (node) => node.key,
15
+ source: (edge) => edge.source,
16
+ target: (edge) => edge.target,
17
+ sourceWeight: (edge) => edge.value || 1,
18
+ targetWeight: (edge) => edge.value || 1,
19
+ sortBy: null, // optional, id | weight | frequency | {function}
20
+ };
21
+
22
+ const DEFAULT_NODE_OPTIONS = {
23
+ type: 'polygon',
24
+ axis: false,
25
+ legend: false,
26
+ encode: {
27
+ shape: 'polygon',
28
+ x: 'x',
29
+ y: 'y',
30
+ },
31
+ scale: {
32
+ x: { type: 'identity' },
33
+ y: { type: 'identity' },
34
+ },
35
+ style: {
36
+ opacity: 1,
37
+ fillOpacity: 1,
38
+ lineWidth: 1,
39
+ },
40
+ };
41
+
42
+ const DEFAULT_LINK_OPTIONS = {
43
+ type: 'polygon',
44
+ axis: false,
45
+ legend: false,
46
+ encode: {
47
+ shape: 'ribbon',
48
+ x: 'x',
49
+ y: 'y',
50
+ },
51
+ style: {
52
+ opacity: 0.5,
53
+ lineWidth: 1,
54
+ strokeWidth: 1,
55
+ },
56
+ };
57
+
58
+ const DEFAULT_LABEL_OPTIONS = {
59
+ position: 'outside',
60
+ fontSize: 10,
61
+ };
62
+
63
+ export type ChordOptions = Omit<ChordMark, 'type'>;
64
+
65
+ export const Chord: CC<ChordOptions> = (options, context) => {
66
+ const {
67
+ data,
68
+ encode = {},
69
+ scale,
70
+ style = {},
71
+ layout = {},
72
+ nodeLabels = [],
73
+ linkLabels = [],
74
+ animate = {},
75
+ tooltip = {},
76
+ } = options;
77
+
78
+ // Initialize data, generating nodes by link if is not specified.
79
+ const { nodes, links } = initializeData(data, encode);
80
+
81
+ // Extract encode for node and link.
82
+ const nodeEncode = subObject(encode, 'node');
83
+ const linkEncode = subObject(encode, 'link');
84
+ const { key: nodeKey = (d) => d.key, color = nodeKey } = nodeEncode;
85
+ const { linkEncodeColor = (d) => d.source } = linkEncode;
86
+ const {
87
+ nodeWidthRatio = DEFAULT_LAYOUT_OPTIONS.thickness,
88
+ nodePaddingRatio = DEFAULT_LAYOUT_OPTIONS.marginRatio,
89
+ ...restLayout
90
+ } = layout;
91
+
92
+ const { nodes: nodeData, edges: linkData } = Arc({
93
+ ...DEFAULT_LAYOUT_OPTIONS,
94
+ id: field(nodeKey),
95
+ thickness: nodeWidthRatio,
96
+ marginRatio: nodePaddingRatio,
97
+ ...restLayout,
98
+ weight: true,
99
+ })({ nodes, edges: links });
100
+
101
+ // Extract label style and apply defaults.
102
+ const { text = nodeKey, ...labelStyle } = subObject(style, 'label');
103
+
104
+ const nodeTooltip = subTooltip(
105
+ tooltip,
106
+ 'node',
107
+ {
108
+ title: '',
109
+ items: [(d) => ({ name: d.key, value: d.value })],
110
+ },
111
+ true,
112
+ );
113
+ const linkTooltip = subTooltip(tooltip, 'link', {
114
+ title: '',
115
+ items: [(d) => ({ name: `${d.source} -> ${d.target}`, value: d.value })],
116
+ });
117
+
118
+ const { height, width } = context;
119
+
120
+ const minimumLen = Math.min(height, width);
121
+
122
+ return [
123
+ deepMix({}, DEFAULT_LINK_OPTIONS, {
124
+ data: linkData,
125
+ encode: { ...linkEncode, color: linkEncodeColor },
126
+ labels: linkLabels,
127
+ style: {
128
+ fill: linkEncodeColor ? undefined : '#aaa',
129
+ ...subObject(style, 'link'),
130
+ },
131
+ tooltip: linkTooltip,
132
+ animate: maybeAnimation(animate, 'link'),
133
+ }),
134
+ deepMix({}, DEFAULT_NODE_OPTIONS, {
135
+ data: nodeData,
136
+ encode: { ...nodeEncode, color },
137
+ scale,
138
+ style: subObject(style, 'node'),
139
+ coordinate: {
140
+ type: 'polar',
141
+ // Leave enough rendering space for the label.
142
+ outerRadius: (minimumLen - 20) / minimumLen,
143
+ },
144
+ labels: [
145
+ {
146
+ ...DEFAULT_LABEL_OPTIONS,
147
+ text,
148
+ ...labelStyle,
149
+ },
150
+ ...nodeLabels,
151
+ ],
152
+ tooltip: nodeTooltip,
153
+ animate: maybeAnimation(animate, 'node'),
154
+ axis: false,
155
+ }),
156
+ ] as MarkOptions[];
157
+ };
158
+
159
+ Chord.props = {};
package/src/mark/index.ts CHANGED
@@ -17,6 +17,7 @@ export { Range } from './range';
17
17
  export { RangeX } from './rangeX';
18
18
  export { RangeY } from './rangeY';
19
19
  export { Sankey } from './sankey';
20
+ export { Chord } from './chord';
20
21
  export { Path } from './path';
21
22
  export { Treemap } from './treemap';
22
23
  export { Pack } from './pack';
@@ -49,6 +50,7 @@ export type { RangeOptions } from './range';
49
50
  export type { RangeXOptions } from './rangeX';
50
51
  export type { RangeYOptions } from './rangeY';
51
52
  export type { SankeyOptions } from './sankey';
53
+ export type { ChordOptions } from './chord';
52
54
  export type { TreemapOptions } from './treemap';
53
55
  export type { PackOptions } from './pack';
54
56
  export type { ShapeOptions } from './shape';
@@ -174,22 +174,17 @@ export function assignScale(
174
174
  ): Record<string, Scale> {
175
175
  const keys = Object.keys(target);
176
176
  for (const scale of Object.values(source)) {
177
- const { name, key } = scale.getOptions();
178
- if (typeof key === 'string') {
179
- if (!(key in target)) target[key] = scale;
180
- } else {
181
- // For scale.key = Symbol('independent')
182
- if (!(name in target)) target[name] = scale;
183
- else {
184
- const I = keys
185
- .filter((d) => d.startsWith(name))
186
- // Reg is for extract `1` from `x1`;
187
- .map((d) => +(d.replace(name, '') || 0));
188
- const index = max(I) + 1;
189
- const newKey = `${name}${index}`;
190
- target[newKey] = scale;
191
- scale.getOptions().key = newKey;
192
- }
177
+ const { name } = scale.getOptions();
178
+ if (!(name in target)) target[name] = scale;
179
+ else {
180
+ const I = keys
181
+ .filter((d) => d.startsWith(name))
182
+ // Reg is for extract `1` from `x1`;
183
+ .map((d) => +(d.replace(name, '') || 0));
184
+ const index = max(I) + 1;
185
+ const newKey = `${name}${index}`;
186
+ target[newKey] = scale;
187
+ scale.getOptions().key = newKey;
193
188
  }
194
189
  }
195
190
  return target;
@@ -89,8 +89,12 @@ export const Curve: SC<CurveOptions> = (options, context) => {
89
89
  seriesX: sx,
90
90
  seriesY: sy,
91
91
  } = value;
92
+ const tpShape = isTranspose(coordinate);
92
93
  const transform = getTransform(coordinate, value);
93
- const fill = gradient && sc ? computeGradient(sc, sx, sy, gradient) : color;
94
+ const fill =
95
+ gradient && sc
96
+ ? computeGradient(sc, sx, sy, gradient, undefined, tpShape)
97
+ : color;
94
98
 
95
99
  const finalStyle = {
96
100
  ...defaults,
@@ -119,7 +123,7 @@ export const Curve: SC<CurveOptions> = (options, context) => {
119
123
  const areaPath = (points) => {
120
124
  const Y1 = points.slice(0, points.length / 2);
121
125
  const Y0 = points.slice(points.length / 2);
122
- return isTranspose(coordinate)
126
+ return tpShape
123
127
  ? area()
124
128
  .y((_, idx) => Y1[idx][1])
125
129
  .x1((_, idx) => Y1[idx][0])
@@ -1,6 +1,6 @@
1
1
  import { line, lineRadial, CurveFactory, CurveFactoryLineOnly } from 'd3-shape';
2
2
  import { Vector2 } from '@antv/coord';
3
- import { isPolar } from '../../utils/coordinate';
3
+ import { isPolar, isTranspose } from '../../utils/coordinate';
4
4
  import { select } from '../../utils/selection';
5
5
  import { ShapeComponent as SC } from '../../runtime';
6
6
  import { applyStyle, computeGradient, getTransform } from '../utils';
@@ -89,11 +89,14 @@ export const Curve: SC<CurveOptions> = (options, context) => {
89
89
  seriesX: sx,
90
90
  seriesY: sy,
91
91
  } = value;
92
+
93
+ const transform = getTransform(coordinate, value);
94
+ const tpShape = isTranspose(coordinate);
92
95
  const stroke =
93
96
  gradient && sc
94
- ? computeGradient(sc, sx, sy, gradient, gradientColor)
97
+ ? computeGradient(sc, sx, sy, gradient, gradientColor, tpShape)
95
98
  : color;
96
- const transform = getTransform(coordinate, value);
99
+
97
100
  const finalStyle = {
98
101
  ...rest,
99
102
  ...(stroke && { stroke }),
@@ -118,10 +118,29 @@ export function computeGradient(
118
118
  Y: number[],
119
119
  from: string | boolean = 'y',
120
120
  mode: 'between' | 'start' | 'end' = 'between',
121
+ tpShape = false,
121
122
  ): string {
123
+ // The angles of gradients rendering are varies when 'from' and 'tpShape' are different.
124
+ const getTheta = (from: string | boolean, tpShape: boolean) => {
125
+ if (from === 'y' || from === true) {
126
+ if (tpShape) {
127
+ return 180;
128
+ } else {
129
+ return 90;
130
+ }
131
+ } else {
132
+ if (tpShape) {
133
+ return 90;
134
+ } else {
135
+ return 0;
136
+ }
137
+ }
138
+ };
139
+
122
140
  const P = from === 'y' || from === true ? Y : X;
123
- const theta = from === 'y' || from === true ? 90 : 0;
141
+ const theta = getTheta(from, tpShape);
124
142
  const I = indexOf(P);
143
+
125
144
  const [min, max] = extent(I, (i) => P[i]);
126
145
  // This need to improve for non-uniform distributed colors.
127
146
  const p = new Linear({
package/src/spec/mark.ts CHANGED
@@ -38,6 +38,7 @@ export type Mark =
38
38
  | RangeYMark
39
39
  | ConnectorMark
40
40
  | SankeyMark
41
+ | ChordMark
41
42
  | PathMark
42
43
  | TreemapMark
43
44
  | PackMark
@@ -73,6 +74,7 @@ export type MarkTypes =
73
74
  | 'rangeX'
74
75
  | 'rangeY'
75
76
  | 'sankey'
77
+ | 'chord'
76
78
  | 'path'
77
79
  | 'treemap'
78
80
  | 'pack'
@@ -288,6 +290,35 @@ export type SankeyMark = BaseMark<
288
290
  linkLabels: Record<string, any>[];
289
291
  };
290
292
 
293
+ export type ChordMark = BaseMark<
294
+ 'chord',
295
+ | 'source'
296
+ | 'target'
297
+ | 'value'
298
+ | `node${Capitalize<ChannelTypes>}`
299
+ | `link${Capitalize<ChannelTypes>}`
300
+ | ChannelTypes
301
+ > & {
302
+ layout?: {
303
+ nodes?: (graph: any) => any;
304
+ links?: (graph: any) => any;
305
+ y?: number;
306
+ id?: (node: any) => any;
307
+ sortBy?:
308
+ | 'id'
309
+ | 'weight'
310
+ | 'frequency'
311
+ | null
312
+ | ((a: any, b: any) => number);
313
+ nodeWidthRatio?: number;
314
+ nodePaddingRatio?: number;
315
+ sourceWeight?(edge: any): number;
316
+ targetWeight?(edge: any): number;
317
+ };
318
+ nodeLabels: Record<string, any>[];
319
+ linkLabels: Record<string, any>[];
320
+ };
321
+
291
322
  export type PathMark = BaseMark<'path', ChannelTypes | 'd'>;
292
323
 
293
324
  export type TreemapMark = BaseMark<'treemap', 'value' | ChannelTypes> & {