@antv/gpt-vis 1.0.0-beta.2 → 1.0.1
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.md +282 -43
- package/README.zh-CN.md +286 -47
- package/dist/cjs/gpt-vis/index.js +1 -1
- package/dist/cjs/types/index.d.ts +2 -1
- package/dist/cjs/util/animation.d.ts +2 -0
- package/dist/cjs/util/animation.js +38 -0
- package/dist/cjs/util/components.d.ts +15 -0
- package/dist/cjs/util/components.js +94 -0
- package/dist/cjs/util/crosshair-axis-labels.d.ts +9 -0
- package/dist/cjs/util/crosshair-axis-labels.js +304 -0
- package/dist/cjs/util/index.d.ts +6 -0
- package/dist/cjs/util/index.js +33 -0
- package/dist/cjs/util/interaction.d.ts +14 -0
- package/dist/cjs/util/interaction.js +89 -0
- package/dist/cjs/util/theme.d.ts +18 -24
- package/dist/cjs/util/theme.js +303 -120
- package/dist/cjs/util/tokens.d.ts +31 -0
- package/dist/cjs/util/tokens.js +98 -0
- package/dist/cjs/vis/area/index.d.ts +2 -2
- package/dist/cjs/vis/area/index.js +76 -31
- package/dist/cjs/vis/bar/index.d.ts +2 -2
- package/dist/cjs/vis/bar/index.js +22 -19
- package/dist/cjs/vis/boxplot/index.js +1 -4
- package/dist/cjs/vis/column/index.d.ts +2 -2
- package/dist/cjs/vis/column/index.js +28 -18
- package/dist/cjs/vis/dual-axes/index.d.ts +2 -2
- package/dist/cjs/vis/dual-axes/index.js +90 -36
- package/dist/cjs/vis/fishbone-diagram/index.js +12 -4
- package/dist/cjs/vis/flow-diagram/index.js +27 -11
- package/dist/cjs/vis/funnel/index.d.ts +4 -2
- package/dist/cjs/vis/funnel/index.js +171 -92
- package/dist/cjs/vis/histogram/index.js +1 -4
- package/dist/cjs/vis/indented-tree/index.js +13 -3
- package/dist/cjs/vis/line/index.d.ts +2 -2
- package/dist/cjs/vis/line/index.js +71 -31
- package/dist/cjs/vis/liquid/index.d.ts +2 -2
- package/dist/cjs/vis/liquid/index.js +41 -16
- package/dist/cjs/vis/mindmap/index.js +12 -4
- package/dist/cjs/vis/network-graph/index.js +11 -2
- package/dist/cjs/vis/organization-chart/index.js +12 -3
- package/dist/cjs/vis/pie/index.d.ts +2 -2
- package/dist/cjs/vis/pie/index.js +26 -16
- package/dist/cjs/vis/radar/index.d.ts +2 -2
- package/dist/cjs/vis/radar/index.js +21 -29
- package/dist/cjs/vis/sankey/index.js +1 -4
- package/dist/cjs/vis/scatter/index.d.ts +4 -2
- package/dist/cjs/vis/scatter/index.js +43 -16
- package/dist/cjs/vis/treemap/index.js +1 -4
- package/dist/cjs/vis/venn/index.js +1 -4
- package/dist/cjs/vis/violin/index.js +1 -1
- package/dist/cjs/vis/waterfall/index.js +2 -2
- package/dist/cjs/vis/word-cloud/index.d.ts +3 -2
- package/dist/cjs/vis/word-cloud/index.js +125 -10
- package/dist/esm/gpt-vis/index.js +1 -1
- package/dist/esm/types/index.d.ts +2 -1
- package/dist/esm/util/animation.d.ts +2 -0
- package/dist/esm/util/animation.js +17 -0
- package/dist/esm/util/components.d.ts +15 -0
- package/dist/esm/util/components.js +67 -0
- package/dist/esm/util/crosshair-axis-labels.d.ts +9 -0
- package/dist/esm/util/crosshair-axis-labels.js +328 -0
- package/dist/esm/util/index.d.ts +6 -0
- package/dist/esm/util/index.js +6 -0
- package/dist/esm/util/interaction.d.ts +14 -0
- package/dist/esm/util/interaction.js +73 -0
- package/dist/esm/util/theme.d.ts +18 -24
- package/dist/esm/util/theme.js +302 -126
- package/dist/esm/util/tokens.d.ts +31 -0
- package/dist/esm/util/tokens.js +64 -0
- package/dist/esm/vis/area/index.d.ts +2 -2
- package/dist/esm/vis/area/index.js +91 -41
- package/dist/esm/vis/bar/index.d.ts +2 -2
- package/dist/esm/vis/bar/index.js +28 -29
- package/dist/esm/vis/boxplot/index.js +4 -5
- package/dist/esm/vis/column/index.d.ts +2 -2
- package/dist/esm/vis/column/index.js +36 -29
- package/dist/esm/vis/dual-axes/index.d.ts +2 -2
- package/dist/esm/vis/dual-axes/index.js +123 -43
- package/dist/esm/vis/fishbone-diagram/index.js +6 -5
- package/dist/esm/vis/flow-diagram/index.js +17 -10
- package/dist/esm/vis/funnel/index.d.ts +4 -2
- package/dist/esm/vis/funnel/index.js +156 -83
- package/dist/esm/vis/histogram/index.js +4 -5
- package/dist/esm/vis/indented-tree/index.js +9 -4
- package/dist/esm/vis/line/index.d.ts +2 -2
- package/dist/esm/vis/line/index.js +80 -37
- package/dist/esm/vis/liquid/index.d.ts +2 -2
- package/dist/esm/vis/liquid/index.js +41 -14
- package/dist/esm/vis/mindmap/index.js +6 -5
- package/dist/esm/vis/network-graph/index.js +5 -3
- package/dist/esm/vis/organization-chart/index.js +6 -4
- package/dist/esm/vis/pie/index.d.ts +2 -2
- package/dist/esm/vis/pie/index.js +36 -16
- package/dist/esm/vis/radar/index.d.ts +2 -2
- package/dist/esm/vis/radar/index.js +21 -34
- package/dist/esm/vis/sankey/index.js +4 -5
- package/dist/esm/vis/scatter/index.d.ts +4 -2
- package/dist/esm/vis/scatter/index.js +45 -19
- package/dist/esm/vis/treemap/index.js +4 -5
- package/dist/esm/vis/venn/index.js +4 -5
- package/dist/esm/vis/violin/index.js +5 -13
- package/dist/esm/vis/waterfall/index.js +11 -11
- package/dist/esm/vis/word-cloud/index.d.ts +3 -2
- package/dist/esm/vis/word-cloud/index.js +158 -10
- package/dist/umd/index.min.js +1 -1
- package/package.json +18 -19
|
@@ -5,7 +5,7 @@ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key i
|
|
|
5
5
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
6
6
|
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
7
7
|
import { Chart } from '@antv/g2';
|
|
8
|
-
import {
|
|
8
|
+
import { getThemeObject, normalizePalette } from "../../util/theme";
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* VennDataItem is the type for each data item in the venn chart.
|
|
@@ -83,7 +83,6 @@ export var Venn = function Venn(options) {
|
|
|
83
83
|
|
|
84
84
|
// Get colors from style.palette or theme defaults
|
|
85
85
|
var colors = normalizePalette(style.palette, theme);
|
|
86
|
-
var backgroundColor = style.backgroundColor || getBackgroundColor(theme);
|
|
87
86
|
var normalizedData = data.map(function (d) {
|
|
88
87
|
return _objectSpread(_objectSpread({}, d), {}, {
|
|
89
88
|
sets: normalizeVennSets(d.sets)
|
|
@@ -139,9 +138,9 @@ export var Venn = function Venn(options) {
|
|
|
139
138
|
fillOpacity: 0.85,
|
|
140
139
|
fontSize: 10
|
|
141
140
|
}],
|
|
142
|
-
viewStyle: {
|
|
143
|
-
viewFill: backgroundColor
|
|
144
|
-
},
|
|
141
|
+
viewStyle: style.backgroundColor ? {
|
|
142
|
+
viewFill: style.backgroundColor
|
|
143
|
+
} : undefined,
|
|
145
144
|
theme: getThemeObject(theme),
|
|
146
145
|
legend: false,
|
|
147
146
|
axis: false,
|
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
-
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
3
|
-
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4
|
-
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
5
|
-
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
6
|
-
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
7
1
|
import { Chart } from '@antv/g2';
|
|
8
2
|
import { getBackgroundColor, getThemeObject, normalizePalette } from "../../util/theme";
|
|
9
3
|
|
|
@@ -194,7 +188,7 @@ export var Violin = function Violin(options) {
|
|
|
194
188
|
// Configure chart options
|
|
195
189
|
// Note: Using 'any' type due to G2's complex type system with transformations
|
|
196
190
|
// This is consistent with how G2 5.0 is used elsewhere in the codebase
|
|
197
|
-
var chartOptions =
|
|
191
|
+
var chartOptions = {
|
|
198
192
|
animate: false,
|
|
199
193
|
type: 'view',
|
|
200
194
|
data: data,
|
|
@@ -218,14 +212,12 @@ export var Violin = function Violin(options) {
|
|
|
218
212
|
color: hasGroupField ? {
|
|
219
213
|
position: 'top'
|
|
220
214
|
} : false
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
viewStyle: {
|
|
215
|
+
},
|
|
216
|
+
viewStyle: style.backgroundColor ? {
|
|
224
217
|
viewFill: backgroundColor
|
|
225
|
-
}
|
|
226
|
-
} : {}), {}, {
|
|
218
|
+
} : undefined,
|
|
227
219
|
theme: getThemeObject(theme)
|
|
228
|
-
}
|
|
220
|
+
};
|
|
229
221
|
chart.options(chartOptions);
|
|
230
222
|
chart.render();
|
|
231
223
|
};
|
|
@@ -152,7 +152,7 @@ export var Waterfall = function Waterfall(options) {
|
|
|
152
152
|
// Configure chart options
|
|
153
153
|
// Note: Using 'any' type due to G2's complex type system with transformations
|
|
154
154
|
// This is consistent with how G2 5.0 is used elsewhere in the codebase
|
|
155
|
-
var chartOptions =
|
|
155
|
+
var chartOptions = {
|
|
156
156
|
animate: false,
|
|
157
157
|
type: 'view',
|
|
158
158
|
data: transformedData,
|
|
@@ -181,14 +181,16 @@ export var Waterfall = function Waterfall(options) {
|
|
|
181
181
|
y: ['__start__', '__end__'],
|
|
182
182
|
color: 'category'
|
|
183
183
|
},
|
|
184
|
-
style: {
|
|
184
|
+
style: _objectSpread(_objectSpread({
|
|
185
185
|
maxWidth: 60,
|
|
186
|
-
stroke: '#666'
|
|
187
|
-
|
|
186
|
+
stroke: '#666'
|
|
187
|
+
}, theme !== 'academy' ? {
|
|
188
|
+
radius: 4
|
|
189
|
+
} : {}), {}, {
|
|
188
190
|
fill: function fill(d) {
|
|
189
191
|
return d.isTotal || d.isIntermediateTotal ? totalColor : d.__value__ > 0 ? positiveColor : negativeColor;
|
|
190
192
|
}
|
|
191
|
-
},
|
|
193
|
+
}),
|
|
192
194
|
labels: [{
|
|
193
195
|
text: '__value__',
|
|
194
196
|
position: 'inside',
|
|
@@ -235,14 +237,12 @@ export var Waterfall = function Waterfall(options) {
|
|
|
235
237
|
},
|
|
236
238
|
tooltip: false
|
|
237
239
|
}],
|
|
238
|
-
legend: false
|
|
239
|
-
|
|
240
|
-
viewStyle: {
|
|
240
|
+
legend: false,
|
|
241
|
+
viewStyle: style.backgroundColor ? {
|
|
241
242
|
viewFill: backgroundColor
|
|
242
|
-
}
|
|
243
|
-
} : {}), {}, {
|
|
243
|
+
} : undefined,
|
|
244
244
|
theme: getThemeObject(theme)
|
|
245
|
-
}
|
|
245
|
+
};
|
|
246
246
|
chart.options(chartOptions);
|
|
247
247
|
chart.render();
|
|
248
248
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { VisualizationOptions } from '../../types';
|
|
1
|
+
import type { VisualizationOptions, VisualizationTheme } from '../../types';
|
|
2
2
|
/**
|
|
3
3
|
* WordCloudDataItem is the type for each data item in the word cloud chart.
|
|
4
4
|
*/
|
|
@@ -12,8 +12,9 @@ export type WordCloudDataItem = {
|
|
|
12
12
|
export interface WordCloudConfig {
|
|
13
13
|
type?: 'word-cloud';
|
|
14
14
|
data: WordCloudDataItem[];
|
|
15
|
-
theme?:
|
|
15
|
+
theme?: VisualizationTheme;
|
|
16
16
|
title?: string;
|
|
17
|
+
locale?: string;
|
|
17
18
|
style?: {
|
|
18
19
|
backgroundColor?: string;
|
|
19
20
|
palette?: string[];
|
|
@@ -1,5 +1,91 @@
|
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
3
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
5
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
6
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
1
7
|
import { Chart } from '@antv/g2';
|
|
2
|
-
import {
|
|
8
|
+
import { resolveChartLocale } from "../../util/components";
|
|
9
|
+
import { getThemeObject, normalizePalette } from "../../util/theme";
|
|
10
|
+
var WORD_CLOUD_MAX_WORDS = 50;
|
|
11
|
+
var WORD_CLOUD_FONT_FAMILY = 'Impact';
|
|
12
|
+
var WORD_CLOUD_ROTATIONS = [-90, -60, -30, 0, 30, 60];
|
|
13
|
+
var WORD_CLOUD_LABELS = {
|
|
14
|
+
'en-US': {
|
|
15
|
+
rank: 'Rank',
|
|
16
|
+
share: 'Share of total weight',
|
|
17
|
+
weight: 'Weight / frequency'
|
|
18
|
+
},
|
|
19
|
+
'zh-CN': {
|
|
20
|
+
rank: '排名',
|
|
21
|
+
share: '占总权重',
|
|
22
|
+
weight: '权重 / 词频'
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
var hashWordCloudData = function hashWordCloudData(data) {
|
|
26
|
+
var hash = 2166136261;
|
|
27
|
+
data.forEach(function (_ref) {
|
|
28
|
+
var text = _ref.text,
|
|
29
|
+
value = _ref.value;
|
|
30
|
+
var input = "".concat(text, "\0").concat(value, "\x01");
|
|
31
|
+
for (var index = 0; index < input.length; index += 1) {
|
|
32
|
+
hash ^= input.charCodeAt(index);
|
|
33
|
+
hash = Math.imul(hash, 16777619);
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
return hash >>> 0;
|
|
37
|
+
};
|
|
38
|
+
var createSeededRandom = function createSeededRandom(seed) {
|
|
39
|
+
var state = seed || 1;
|
|
40
|
+
return function () {
|
|
41
|
+
state += 0x6d2b79f5;
|
|
42
|
+
var value = state;
|
|
43
|
+
value = Math.imul(value ^ value >>> 15, value | 1);
|
|
44
|
+
value ^= value + Math.imul(value ^ value >>> 7, value | 61);
|
|
45
|
+
return ((value ^ value >>> 14) >>> 0) / 4294967296;
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
var getWordCloudPalette = function getWordCloudPalette(palette, theme) {
|
|
49
|
+
return normalizePalette(palette, theme);
|
|
50
|
+
};
|
|
51
|
+
var prepareWordCloudData = function prepareWordCloudData(data, colors) {
|
|
52
|
+
var rankedData = data.map(function (item, index) {
|
|
53
|
+
return {
|
|
54
|
+
item: item,
|
|
55
|
+
index: index
|
|
56
|
+
};
|
|
57
|
+
}).filter(function (_ref2) {
|
|
58
|
+
var item = _ref2.item;
|
|
59
|
+
return item.text.trim().length > 0 && Number.isFinite(item.value) && item.value > 0;
|
|
60
|
+
}).sort(function (a, b) {
|
|
61
|
+
return b.item.value - a.item.value || a.index - b.index;
|
|
62
|
+
});
|
|
63
|
+
var totalWeight = rankedData.reduce(function (sum, _ref3) {
|
|
64
|
+
var item = _ref3.item;
|
|
65
|
+
return sum + item.value;
|
|
66
|
+
}, 0);
|
|
67
|
+
var visibleData = rankedData.slice(0, WORD_CLOUD_MAX_WORDS);
|
|
68
|
+
var lastVisibleIndex = Math.max(1, visibleData.length - 1);
|
|
69
|
+
var colorByText = new Map();
|
|
70
|
+
var nextColorIndex = 0;
|
|
71
|
+
return visibleData.map(function (_ref4, index) {
|
|
72
|
+
var item = _ref4.item;
|
|
73
|
+
var percentile = index / lastVisibleIndex;
|
|
74
|
+
var fontWeight = percentile <= 0.1 ? 700 : percentile <= 0.32 ? 600 : percentile <= 0.68 ? 500 : 400;
|
|
75
|
+
var wordColor = colorByText.get(item.text);
|
|
76
|
+
if (!wordColor) {
|
|
77
|
+
wordColor = colors[nextColorIndex % colors.length];
|
|
78
|
+
colorByText.set(item.text, wordColor);
|
|
79
|
+
nextColorIndex += 1;
|
|
80
|
+
}
|
|
81
|
+
return _objectSpread(_objectSpread({}, item), {}, {
|
|
82
|
+
rank: index + 1,
|
|
83
|
+
share: totalWeight > 0 ? item.value / totalWeight : 0,
|
|
84
|
+
fontWeight: fontWeight,
|
|
85
|
+
wordColor: wordColor
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
};
|
|
3
89
|
|
|
4
90
|
/**
|
|
5
91
|
* WordCloudDataItem is the type for each data item in the word cloud chart.
|
|
@@ -41,6 +127,7 @@ export var WordCloud = function WordCloud(options) {
|
|
|
41
127
|
var container = options.container,
|
|
42
128
|
width = options.width,
|
|
43
129
|
height = options.height,
|
|
130
|
+
locale = options.locale,
|
|
44
131
|
_options$theme = options.theme,
|
|
45
132
|
chartTheme = _options$theme === void 0 ? 'default' : _options$theme;
|
|
46
133
|
var chart = null;
|
|
@@ -54,17 +141,30 @@ export var WordCloud = function WordCloud(options) {
|
|
|
54
141
|
_config$theme = config.theme,
|
|
55
142
|
theme = _config$theme === void 0 ? chartTheme : _config$theme,
|
|
56
143
|
title = config.title,
|
|
144
|
+
_config$locale = config.locale,
|
|
145
|
+
renderLocale = _config$locale === void 0 ? locale : _config$locale,
|
|
57
146
|
_config$style = config.style,
|
|
58
147
|
style = _config$style === void 0 ? {} : _config$style;
|
|
148
|
+
var chartLocale = resolveChartLocale(renderLocale);
|
|
149
|
+
var labels = WORD_CLOUD_LABELS[chartLocale];
|
|
150
|
+
var valueFormatter = new Intl.NumberFormat(chartLocale, {
|
|
151
|
+
maximumFractionDigits: 2
|
|
152
|
+
});
|
|
153
|
+
var percentageFormatter = new Intl.NumberFormat(chartLocale, {
|
|
154
|
+
style: 'percent',
|
|
155
|
+
maximumFractionDigits: 2
|
|
156
|
+
});
|
|
59
157
|
|
|
60
158
|
// Clean up previous chart if exists
|
|
61
159
|
if (chart) {
|
|
62
160
|
chart.destroy();
|
|
63
161
|
}
|
|
64
162
|
|
|
65
|
-
//
|
|
66
|
-
var colors =
|
|
67
|
-
var
|
|
163
|
+
// Assign a stable categorical color to each word while preserving custom palettes.
|
|
164
|
+
var colors = getWordCloudPalette(style.palette, theme);
|
|
165
|
+
var preparedData = prepareWordCloudData(data, colors);
|
|
166
|
+
var layoutSeed = hashWordCloudData(preparedData);
|
|
167
|
+
var rotationRandom = createSeededRandom(layoutSeed ^ 0x9e3779b9);
|
|
68
168
|
|
|
69
169
|
// Create chart
|
|
70
170
|
chart = new Chart({
|
|
@@ -80,33 +180,81 @@ export var WordCloud = function WordCloud(options) {
|
|
|
80
180
|
var chartOptions = {
|
|
81
181
|
animate: false,
|
|
82
182
|
type: 'wordCloud',
|
|
83
|
-
data:
|
|
183
|
+
data: preparedData,
|
|
84
184
|
title: title !== null && title !== void 0 ? title : '',
|
|
85
185
|
layout: {
|
|
86
|
-
|
|
186
|
+
font: WORD_CLOUD_FONT_FAMILY,
|
|
187
|
+
fontSize: [11, 44],
|
|
188
|
+
fontWeight: function fontWeight(d) {
|
|
189
|
+
return d.fontWeight;
|
|
190
|
+
},
|
|
191
|
+
padding: 2,
|
|
192
|
+
random: createSeededRandom(layoutSeed),
|
|
193
|
+
rotate: function rotate() {
|
|
194
|
+
return WORD_CLOUD_ROTATIONS[Math.floor(rotationRandom() * WORD_CLOUD_ROTATIONS.length)];
|
|
195
|
+
}
|
|
87
196
|
},
|
|
88
197
|
encode: {
|
|
89
198
|
text: 'text',
|
|
90
199
|
color: 'text',
|
|
91
200
|
value: 'value'
|
|
92
201
|
},
|
|
202
|
+
style: {
|
|
203
|
+
fill: function fill(d) {
|
|
204
|
+
return d.wordColor;
|
|
205
|
+
},
|
|
206
|
+
fontFamily: WORD_CLOUD_FONT_FAMILY,
|
|
207
|
+
fontWeight: function fontWeight(d) {
|
|
208
|
+
var _d$weight;
|
|
209
|
+
return (_d$weight = d.weight) !== null && _d$weight !== void 0 ? _d$weight : d.fontWeight;
|
|
210
|
+
},
|
|
211
|
+
stroke: function stroke(d) {
|
|
212
|
+
return d.wordColor;
|
|
213
|
+
}
|
|
214
|
+
},
|
|
93
215
|
scale: {
|
|
94
216
|
color: {
|
|
95
217
|
range: colors
|
|
96
218
|
}
|
|
97
219
|
},
|
|
98
220
|
legend: false,
|
|
221
|
+
state: {
|
|
222
|
+
active: {
|
|
223
|
+
fillOpacity: 1,
|
|
224
|
+
strokeOpacity: 1
|
|
225
|
+
},
|
|
226
|
+
inactive: {
|
|
227
|
+
fillOpacity: 0.3,
|
|
228
|
+
strokeOpacity: 0.3
|
|
229
|
+
}
|
|
230
|
+
},
|
|
99
231
|
tooltip: {
|
|
232
|
+
title: 'text',
|
|
100
233
|
items: [function (d) {
|
|
101
234
|
return {
|
|
102
|
-
name:
|
|
103
|
-
value: d.value
|
|
235
|
+
name: labels.weight,
|
|
236
|
+
value: valueFormatter.format(d.value)
|
|
237
|
+
};
|
|
238
|
+
}, function (d) {
|
|
239
|
+
return {
|
|
240
|
+
name: labels.rank,
|
|
241
|
+
value: "#".concat(d.rank)
|
|
242
|
+
};
|
|
243
|
+
}, function (d) {
|
|
244
|
+
return {
|
|
245
|
+
name: labels.share,
|
|
246
|
+
value: percentageFormatter.format(d.share)
|
|
104
247
|
};
|
|
105
248
|
}]
|
|
106
249
|
},
|
|
107
|
-
|
|
108
|
-
|
|
250
|
+
interaction: {
|
|
251
|
+
tooltip: true,
|
|
252
|
+
elementHighlight: true,
|
|
253
|
+
elementHoverScale: true
|
|
109
254
|
},
|
|
255
|
+
viewStyle: style.backgroundColor ? {
|
|
256
|
+
viewFill: style.backgroundColor
|
|
257
|
+
} : undefined,
|
|
110
258
|
theme: getThemeObject(theme)
|
|
111
259
|
};
|
|
112
260
|
chart.options(chartOptions);
|