@antv/gpt-vis 1.0.0 → 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.
Files changed (92) hide show
  1. package/README.md +66 -1
  2. package/README.zh-CN.md +66 -1
  3. package/dist/cjs/types/index.d.ts +2 -1
  4. package/dist/cjs/util/animation.d.ts +2 -0
  5. package/dist/cjs/util/animation.js +38 -0
  6. package/dist/cjs/util/components.d.ts +15 -0
  7. package/dist/cjs/util/components.js +94 -0
  8. package/dist/cjs/util/crosshair-axis-labels.d.ts +9 -0
  9. package/dist/cjs/util/crosshair-axis-labels.js +304 -0
  10. package/dist/cjs/util/index.d.ts +6 -0
  11. package/dist/cjs/util/index.js +33 -0
  12. package/dist/cjs/util/interaction.d.ts +14 -0
  13. package/dist/cjs/util/interaction.js +89 -0
  14. package/dist/cjs/util/theme.d.ts +18 -24
  15. package/dist/cjs/util/theme.js +303 -120
  16. package/dist/cjs/util/tokens.d.ts +31 -0
  17. package/dist/cjs/util/tokens.js +98 -0
  18. package/dist/cjs/vis/area/index.d.ts +2 -2
  19. package/dist/cjs/vis/area/index.js +76 -31
  20. package/dist/cjs/vis/bar/index.d.ts +2 -2
  21. package/dist/cjs/vis/bar/index.js +22 -19
  22. package/dist/cjs/vis/boxplot/index.js +1 -4
  23. package/dist/cjs/vis/column/index.d.ts +2 -2
  24. package/dist/cjs/vis/column/index.js +28 -18
  25. package/dist/cjs/vis/dual-axes/index.d.ts +2 -2
  26. package/dist/cjs/vis/dual-axes/index.js +89 -34
  27. package/dist/cjs/vis/funnel/index.d.ts +4 -2
  28. package/dist/cjs/vis/funnel/index.js +171 -92
  29. package/dist/cjs/vis/histogram/index.js +1 -4
  30. package/dist/cjs/vis/line/index.d.ts +2 -2
  31. package/dist/cjs/vis/line/index.js +71 -31
  32. package/dist/cjs/vis/liquid/index.d.ts +2 -2
  33. package/dist/cjs/vis/liquid/index.js +41 -16
  34. package/dist/cjs/vis/pie/index.d.ts +2 -2
  35. package/dist/cjs/vis/pie/index.js +26 -16
  36. package/dist/cjs/vis/radar/index.d.ts +2 -2
  37. package/dist/cjs/vis/radar/index.js +21 -29
  38. package/dist/cjs/vis/sankey/index.js +1 -4
  39. package/dist/cjs/vis/scatter/index.d.ts +2 -2
  40. package/dist/cjs/vis/scatter/index.js +40 -17
  41. package/dist/cjs/vis/treemap/index.js +1 -4
  42. package/dist/cjs/vis/venn/index.js +1 -4
  43. package/dist/cjs/vis/violin/index.js +1 -1
  44. package/dist/cjs/vis/waterfall/index.js +1 -1
  45. package/dist/cjs/vis/word-cloud/index.d.ts +3 -2
  46. package/dist/cjs/vis/word-cloud/index.js +125 -10
  47. package/dist/esm/types/index.d.ts +2 -1
  48. package/dist/esm/util/animation.d.ts +2 -0
  49. package/dist/esm/util/animation.js +17 -0
  50. package/dist/esm/util/components.d.ts +15 -0
  51. package/dist/esm/util/components.js +67 -0
  52. package/dist/esm/util/crosshair-axis-labels.d.ts +9 -0
  53. package/dist/esm/util/crosshair-axis-labels.js +328 -0
  54. package/dist/esm/util/index.d.ts +6 -0
  55. package/dist/esm/util/index.js +6 -0
  56. package/dist/esm/util/interaction.d.ts +14 -0
  57. package/dist/esm/util/interaction.js +73 -0
  58. package/dist/esm/util/theme.d.ts +18 -24
  59. package/dist/esm/util/theme.js +302 -126
  60. package/dist/esm/util/tokens.d.ts +31 -0
  61. package/dist/esm/util/tokens.js +64 -0
  62. package/dist/esm/vis/area/index.d.ts +2 -2
  63. package/dist/esm/vis/area/index.js +91 -41
  64. package/dist/esm/vis/bar/index.d.ts +2 -2
  65. package/dist/esm/vis/bar/index.js +28 -29
  66. package/dist/esm/vis/boxplot/index.js +4 -5
  67. package/dist/esm/vis/column/index.d.ts +2 -2
  68. package/dist/esm/vis/column/index.js +36 -29
  69. package/dist/esm/vis/dual-axes/index.d.ts +2 -2
  70. package/dist/esm/vis/dual-axes/index.js +115 -42
  71. package/dist/esm/vis/funnel/index.d.ts +4 -2
  72. package/dist/esm/vis/funnel/index.js +156 -83
  73. package/dist/esm/vis/histogram/index.js +4 -5
  74. package/dist/esm/vis/line/index.d.ts +2 -2
  75. package/dist/esm/vis/line/index.js +80 -37
  76. package/dist/esm/vis/liquid/index.d.ts +2 -2
  77. package/dist/esm/vis/liquid/index.js +41 -14
  78. package/dist/esm/vis/pie/index.d.ts +2 -2
  79. package/dist/esm/vis/pie/index.js +36 -16
  80. package/dist/esm/vis/radar/index.d.ts +2 -2
  81. package/dist/esm/vis/radar/index.js +21 -34
  82. package/dist/esm/vis/sankey/index.js +4 -5
  83. package/dist/esm/vis/scatter/index.d.ts +2 -2
  84. package/dist/esm/vis/scatter/index.js +41 -25
  85. package/dist/esm/vis/treemap/index.js +4 -5
  86. package/dist/esm/vis/venn/index.js +4 -5
  87. package/dist/esm/vis/violin/index.js +5 -13
  88. package/dist/esm/vis/waterfall/index.js +5 -7
  89. package/dist/esm/vis/word-cloud/index.d.ts +3 -2
  90. package/dist/esm/vis/word-cloud/index.js +158 -10
  91. package/dist/umd/index.min.js +1 -1
  92. package/package.json +18 -15
@@ -1,5 +1,11 @@
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 { getBackgroundColor, getThemeObject, normalizePalette } from "../../util/theme";
8
+ import { CHART_STYLE_DEFAULTS, getBackgroundColor, getCartesianAxis, getChartAnimation, getColorLegend, getPointHighlightState, getThemeObject, normalizePalette } from "../../util";
3
9
 
4
10
  /**
5
11
  * ScatterDataItem is the type for each data item in the scatter chart.
@@ -44,6 +50,7 @@ export var Scatter = function Scatter(options) {
44
50
  _options$theme = options.theme,
45
51
  chartTheme = _options$theme === void 0 ? 'default' : _options$theme;
46
52
  var chart = null;
53
+ var hasRendered = false;
47
54
 
48
55
  /**
49
56
  * Render the scatter chart with the given configuration.
@@ -85,13 +92,18 @@ export var Scatter = function Scatter(options) {
85
92
  var scaleConfig = {
86
93
  y: {
87
94
  nice: true
95
+ },
96
+ x: {
97
+ nice: true
88
98
  }
89
99
  };
90
100
  if (hasGroupField) {
91
101
  encode = {
92
102
  x: 'x',
93
103
  y: 'y',
94
- color: 'group'
104
+ color: 'group',
105
+ shape: 'point',
106
+ size: CHART_STYLE_DEFAULTS.scatterPointSize
95
107
  };
96
108
  scaleConfig.color = {
97
109
  range: colors
@@ -100,9 +112,8 @@ export var Scatter = function Scatter(options) {
100
112
  encode = {
101
113
  x: 'x',
102
114
  y: 'y',
103
- color: function color() {
104
- return 'all';
105
- }
115
+ shape: 'point',
116
+ size: CHART_STYLE_DEFAULTS.scatterPointSize
106
117
  };
107
118
  }
108
119
 
@@ -110,28 +121,27 @@ export var Scatter = function Scatter(options) {
110
121
  // Note: Using 'any' type due to G2's complex type system with transformations
111
122
  // This is consistent with how G2 5.0 is used elsewhere in the codebase
112
123
  var chartOptions = {
113
- animate: false,
124
+ animate: getChartAnimation(hasRendered, 'fadeIn'),
114
125
  type: 'point',
115
126
  data: data,
116
- title: title !== null && title !== void 0 ? title : '',
127
+ title: title || '',
117
128
  encode: encode,
118
- legend: hasGroupField ? {
119
- color: {
120
- position: 'top'
121
- }
122
- } : false,
129
+ legend: getColorLegend(hasGroupField),
123
130
  scale: scaleConfig,
124
- axis: {
125
- x: {
126
- title: axisXTitle !== null && axisXTitle !== void 0 ? axisXTitle : 'x'
127
- },
128
- y: {
129
- title: axisYTitle !== null && axisYTitle !== void 0 ? axisYTitle : 'y'
130
- }
131
- },
132
- style: {
133
- lineWidth: 1
134
- },
131
+ axis: getCartesianAxis({
132
+ axisXTitle: axisXTitle,
133
+ axisYTitle: axisYTitle
134
+ }),
135
+ style: _objectSpread({
136
+ lineWidth: CHART_STYLE_DEFAULTS.pointLineWidth,
137
+ fillOpacity: 0.88,
138
+ stroke: backgroundColor
139
+ }, !hasGroupField ? {
140
+ fill: colors[0]
141
+ } : {}),
142
+ // A same-color stroke enlarges the rendered path without changing its transform or
143
+ // hit area, so repeated pointer events cannot accumulate scale.
144
+ state: getPointHighlightState(),
135
145
  tooltip: {
136
146
  title: function title(d) {
137
147
  return d !== null && d !== void 0 && d.group ? d.group : false;
@@ -144,13 +154,18 @@ export var Scatter = function Scatter(options) {
144
154
  name: axisYTitle !== null && axisYTitle !== void 0 ? axisYTitle : 'y'
145
155
  }]
146
156
  },
147
- viewStyle: {
148
- viewFill: backgroundColor
157
+ interaction: {
158
+ tooltip: true,
159
+ elementHighlight: true
149
160
  },
161
+ viewStyle: style.backgroundColor ? {
162
+ viewFill: backgroundColor
163
+ } : undefined,
150
164
  theme: getThemeObject(theme)
151
165
  };
152
166
  chart.options(chartOptions);
153
167
  chart.render();
168
+ hasRendered = true;
154
169
  };
155
170
 
156
171
  /**
@@ -161,6 +176,7 @@ export var Scatter = function Scatter(options) {
161
176
  chart.destroy();
162
177
  chart = null;
163
178
  }
179
+ hasRendered = false;
164
180
  };
165
181
  return {
166
182
  render: render,
@@ -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 { getBackgroundColor, getThemeObject, normalizePalette } from "../../util/theme";
8
+ import { getThemeObject, normalizePalette } from "../../util/theme";
9
9
 
10
10
  /**
11
11
  * TreemapDataItem is the type for each data item in the treemap chart.
@@ -84,7 +84,6 @@ export var Treemap = function Treemap(options) {
84
84
 
85
85
  // Get colors from style.palette or theme defaults
86
86
  var colors = normalizePalette(style.palette, theme);
87
- var backgroundColor = style.backgroundColor || getBackgroundColor(theme);
88
87
 
89
88
  // Create chart
90
89
  chart = new Chart({
@@ -129,9 +128,9 @@ export var Treemap = function Treemap(options) {
129
128
  };
130
129
  }]
131
130
  },
132
- viewStyle: {
133
- viewFill: backgroundColor
134
- },
131
+ viewStyle: style.backgroundColor ? {
132
+ viewFill: style.backgroundColor
133
+ } : undefined,
135
134
  theme: getThemeObject(theme),
136
135
  scale: _objectSpread({}, colors.length > 0 ? {
137
136
  color: {
@@ -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 { getBackgroundColor, getThemeObject, normalizePalette } from "../../util/theme";
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 = _objectSpread(_objectSpread({
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
- }, backgroundColor ? {
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 = _objectSpread(_objectSpread({
155
+ var chartOptions = {
156
156
  animate: false,
157
157
  type: 'view',
158
158
  data: transformedData,
@@ -237,14 +237,12 @@ export var Waterfall = function Waterfall(options) {
237
237
  },
238
238
  tooltip: false
239
239
  }],
240
- legend: false
241
- }, backgroundColor ? {
242
- viewStyle: {
240
+ legend: false,
241
+ viewStyle: style.backgroundColor ? {
243
242
  viewFill: backgroundColor
244
- }
245
- } : {}), {}, {
243
+ } : undefined,
246
244
  theme: getThemeObject(theme)
247
- });
245
+ };
248
246
  chart.options(chartOptions);
249
247
  chart.render();
250
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?: 'default' | 'academy' | 'dark';
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 { getBackgroundColor, getThemeObject, normalizePalette } from "../../util/theme";
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
- // Get colors from style.palette or theme defaults
66
- var colors = normalizePalette(style.palette, theme);
67
- var backgroundColor = style.backgroundColor || getBackgroundColor(theme);
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: data,
183
+ data: preparedData,
84
184
  title: title !== null && title !== void 0 ? title : '',
85
185
  layout: {
86
- fontSize: [8, 42]
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: d.text,
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
- viewStyle: {
108
- viewFill: backgroundColor
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);