billboard.js 3.4.1 → 3.5.0

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 (75) hide show
  1. package/README.md +4 -1
  2. package/dist/billboard.css +1 -1
  3. package/dist/billboard.js +3942 -1467
  4. package/dist/billboard.min.css +1 -1
  5. package/dist/billboard.min.js +2 -2
  6. package/dist/billboard.pkgd.js +8372 -5306
  7. package/dist/billboard.pkgd.min.js +3 -2
  8. package/dist/plugin/billboardjs-plugin-bubblecompare.js +29 -13
  9. package/dist/plugin/billboardjs-plugin-bubblecompare.min.js +2 -2
  10. package/dist/plugin/billboardjs-plugin-sparkline.js +375 -91
  11. package/dist/plugin/billboardjs-plugin-sparkline.min.js +2 -2
  12. package/dist/plugin/billboardjs-plugin-stanford.js +445 -108
  13. package/dist/plugin/billboardjs-plugin-stanford.min.js +2 -2
  14. package/dist/plugin/billboardjs-plugin-tableview.js +339 -73
  15. package/dist/plugin/billboardjs-plugin-tableview.min.js +2 -2
  16. package/dist/plugin/billboardjs-plugin-textoverlap.js +335 -74
  17. package/dist/plugin/billboardjs-plugin-textoverlap.min.js +2 -2
  18. package/dist/plugin/pkgd/billboardjs-plugin-bubblecompare.js +4236 -3792
  19. package/dist/plugin/pkgd/billboardjs-plugin-sparkline.js +4637 -3889
  20. package/dist/plugin/pkgd/billboardjs-plugin-stanford.js +4804 -3931
  21. package/dist/plugin/pkgd/billboardjs-plugin-tableview.js +4595 -3865
  22. package/dist/plugin/pkgd/billboardjs-plugin-textoverlap.js +4607 -3873
  23. package/dist/theme/datalab.css +1 -1
  24. package/dist/theme/datalab.min.css +1 -1
  25. package/dist/theme/graph.css +1 -1
  26. package/dist/theme/graph.min.css +1 -1
  27. package/dist/theme/insight.css +1 -1
  28. package/dist/theme/insight.min.css +1 -1
  29. package/dist-esm/billboard.js +837 -403
  30. package/dist-esm/plugin/billboardjs-plugin-bubblecompare.js +47 -75
  31. package/dist-esm/plugin/billboardjs-plugin-sparkline.js +68 -86
  32. package/dist-esm/plugin/billboardjs-plugin-stanford.js +52 -77
  33. package/dist-esm/plugin/billboardjs-plugin-tableview.js +49 -76
  34. package/dist-esm/plugin/billboardjs-plugin-textoverlap.js +49 -76
  35. package/package.json +39 -39
  36. package/src/Chart/api/chart.ts +4 -1
  37. package/src/Chart/api/data.ts +2 -2
  38. package/src/Chart/api/flow.ts +125 -115
  39. package/src/ChartInternal/Axis/AxisRenderer.ts +29 -3
  40. package/src/ChartInternal/ChartInternal.ts +46 -18
  41. package/src/ChartInternal/data/IData.ts +2 -2
  42. package/src/ChartInternal/data/convert.helper.ts +226 -0
  43. package/src/ChartInternal/data/convert.ts +43 -210
  44. package/src/ChartInternal/data/load.ts +5 -4
  45. package/src/ChartInternal/interactions/zoom.ts +17 -4
  46. package/src/ChartInternal/internals/class.ts +1 -1
  47. package/src/ChartInternal/internals/color.ts +41 -42
  48. package/src/ChartInternal/internals/grid.ts +5 -3
  49. package/src/ChartInternal/internals/legend.ts +21 -6
  50. package/src/ChartInternal/internals/redraw.ts +5 -2
  51. package/src/ChartInternal/internals/scale.ts +3 -1
  52. package/src/ChartInternal/internals/size.axis.ts +5 -2
  53. package/src/ChartInternal/internals/style.ts +54 -0
  54. package/src/ChartInternal/internals/text.ts +118 -18
  55. package/src/ChartInternal/shape/arc.ts +4 -3
  56. package/src/ChartInternal/shape/area.ts +14 -7
  57. package/src/ChartInternal/shape/bar.ts +22 -12
  58. package/src/ChartInternal/shape/line.ts +3 -2
  59. package/src/ChartInternal/shape/point.ts +15 -9
  60. package/src/ChartInternal/shape/polar.ts +1 -1
  61. package/src/Plugin/sparkline/index.ts +22 -11
  62. package/src/Plugin/stanford/index.ts +10 -7
  63. package/src/Plugin/textoverlap/index.ts +4 -1
  64. package/src/config/Options/Options.ts +2 -0
  65. package/src/config/Options/common/boost.ts +31 -0
  66. package/src/config/Options/common/main.ts +15 -1
  67. package/src/config/Options/common/tooltip.ts +1 -1
  68. package/src/config/Options/data/data.ts +11 -3
  69. package/src/config/Options/shape/area.ts +6 -1
  70. package/src/config/Store/State.ts +3 -0
  71. package/src/module/browser.ts +2 -1
  72. package/src/module/generator.ts +18 -16
  73. package/src/module/util.ts +113 -0
  74. package/types/chart.d.ts +2 -2
  75. package/types/options.d.ts +45 -8
@@ -57,153 +57,163 @@ export default {
57
57
  flow(args): void {
58
58
  const $$ = this.internal;
59
59
  let data;
60
- let domain;
61
- let length: number = 0;
62
- let tail = 0;
63
- let diff;
64
- let to;
65
60
 
66
61
  if (args.json || args.rows || args.columns) {
67
- data = $$.convertData(args);
62
+ $$.convertData(args, res => {
63
+ data = res;
64
+ _();
65
+ });
68
66
  }
69
67
 
70
- if ($$.state.redrawing || !data || !isTabVisible()) {
71
- return;
72
- }
68
+ /**
69
+ * Process flows
70
+ * @private
71
+ */
72
+ function _(): void {
73
+ let domain;
74
+ let length: number = 0;
75
+ let tail = 0;
76
+ let diff;
77
+ let to;
78
+
79
+ if ($$.state.redrawing || !data || !isTabVisible()) {
80
+ return;
81
+ }
73
82
 
74
- const notfoundIds: string[] = [];
75
- const orgDataCount = $$.getMaxDataCount();
76
- const targets = $$.convertDataToTargets(data, true);
77
- const isTimeSeries = $$.axis.isTimeSeries();
83
+ const notfoundIds: string[] = [];
84
+ const orgDataCount = $$.getMaxDataCount();
85
+ const targets = $$.convertDataToTargets(data, true);
86
+ const isTimeSeries = $$.axis.isTimeSeries();
78
87
 
79
- // Update/Add data
80
- $$.data.targets.forEach(t => {
81
- let found = false;
88
+ // Update/Add data
89
+ $$.data.targets.forEach(t => {
90
+ let found = false;
82
91
 
83
- for (let i = 0; i < targets.length; i++) {
84
- if (t.id === targets[i].id) {
85
- found = true;
92
+ for (let i = 0; i < targets.length; i++) {
93
+ if (t.id === targets[i].id) {
94
+ found = true;
86
95
 
87
- if (t.values[t.values.length - 1]) {
88
- tail = t.values[t.values.length - 1].index + 1;
89
- }
96
+ if (t.values[t.values.length - 1]) {
97
+ tail = t.values[t.values.length - 1].index + 1;
98
+ }
90
99
 
91
- length = targets[i].values.length;
100
+ length = targets[i].values.length;
92
101
 
93
- for (let j = 0; j < length; j++) {
94
- targets[i].values[j].index = tail + j;
102
+ for (let j = 0; j < length; j++) {
103
+ targets[i].values[j].index = tail + j;
95
104
 
96
- if (!isTimeSeries) {
97
- targets[i].values[j].x = tail + j;
105
+ if (!isTimeSeries) {
106
+ targets[i].values[j].x = tail + j;
107
+ }
98
108
  }
99
- }
100
109
 
101
- t.values = t.values.concat(targets[i].values);
102
- targets.splice(i, 1);
103
- break;
110
+ t.values = t.values.concat(targets[i].values);
111
+ targets.splice(i, 1);
112
+ break;
113
+ }
104
114
  }
105
- }
106
115
 
107
- !found && notfoundIds.push(t.id);
108
- });
116
+ !found && notfoundIds.push(t.id);
117
+ });
109
118
 
110
- // Append null for not found targets
111
- $$.data.targets.forEach(t => {
112
- for (let i = 0; i < notfoundIds.length; i++) {
113
- if (t.id === notfoundIds[i]) {
114
- tail = t.values[t.values.length - 1].index + 1;
119
+ // Append null for not found targets
120
+ $$.data.targets.forEach(t => {
121
+ for (let i = 0; i < notfoundIds.length; i++) {
122
+ if (t.id === notfoundIds[i]) {
123
+ tail = t.values[t.values.length - 1].index + 1;
115
124
 
116
- for (let j = 0; j < length; j++) {
117
- t.values.push({
125
+ for (let j = 0; j < length; j++) {
126
+ t.values.push({
127
+ id: t.id,
128
+ index: tail + j,
129
+ x: isTimeSeries ? $$.getOtherTargetX(tail + j) : tail + j,
130
+ value: null
131
+ });
132
+ }
133
+ }
134
+ }
135
+ });
136
+
137
+ // Generate null values for new target
138
+ if ($$.data.targets.length) {
139
+ targets.forEach(t => {
140
+ const missing: any[] = [];
141
+
142
+ for (let i = $$.data.targets[0].values[0].index; i < tail; i++) {
143
+ missing.push({
118
144
  id: t.id,
119
- index: tail + j,
120
- x: isTimeSeries ? $$.getOtherTargetX(tail + j) : tail + j,
145
+ index: i,
146
+ x: isTimeSeries ? $$.getOtherTargetX(i) : i,
121
147
  value: null
122
148
  });
123
149
  }
124
- }
125
- }
126
- });
127
-
128
- // Generate null values for new target
129
- if ($$.data.targets.length) {
130
- targets.forEach(t => {
131
- const missing: any[] = [];
132
-
133
- for (let i = $$.data.targets[0].values[0].index; i < tail; i++) {
134
- missing.push({
135
- id: t.id,
136
- index: i,
137
- x: isTimeSeries ? $$.getOtherTargetX(i) : i,
138
- value: null
139
- });
140
- }
141
150
 
142
- t.values.forEach(v => {
143
- v.index += tail;
151
+ t.values.forEach(v => {
152
+ v.index += tail;
144
153
 
145
- if (!isTimeSeries) {
146
- v.x += tail;
147
- }
154
+ if (!isTimeSeries) {
155
+ v.x += tail;
156
+ }
157
+ });
158
+
159
+ t.values = missing.concat(t.values);
148
160
  });
161
+ }
149
162
 
150
- t.values = missing.concat(t.values);
151
- });
152
- }
163
+ $$.data.targets = $$.data.targets.concat(targets); // add remained
153
164
 
154
- $$.data.targets = $$.data.targets.concat(targets); // add remained
165
+ // check data count because behavior needs to change when it"s only one
166
+ // const dataCount = $$.getMaxDataCount();
167
+ const baseTarget = $$.data.targets[0];
168
+ const baseValue = baseTarget.values[0];
155
169
 
156
- // check data count because behavior needs to change when it"s only one
157
- // const dataCount = $$.getMaxDataCount();
158
- const baseTarget = $$.data.targets[0];
159
- const baseValue = baseTarget.values[0];
170
+ // Update length to flow if needed
171
+ if (isDefined(args.to)) {
172
+ length = 0;
173
+ to = isTimeSeries ? parseDate.call($$, args.to) : args.to;
160
174
 
161
- // Update length to flow if needed
162
- if (isDefined(args.to)) {
163
- length = 0;
164
- to = isTimeSeries ? parseDate.call($$, args.to) : args.to;
175
+ baseTarget.values.forEach(v => {
176
+ v.x < to && length++;
177
+ });
178
+ } else if (isDefined(args.length)) {
179
+ length = args.length;
180
+ }
165
181
 
166
- baseTarget.values.forEach(v => {
167
- v.x < to && length++;
168
- });
169
- } else if (isDefined(args.length)) {
170
- length = args.length;
171
- }
182
+ // If only one data, update the domain to flow from left edge of the chart
183
+ if (!orgDataCount) {
184
+ if (isTimeSeries) {
185
+ diff = baseTarget.values.length > 1 ?
186
+ baseTarget.values[baseTarget.values.length - 1].x - baseValue.x :
187
+ baseValue.x - $$.getXDomain($$.data.targets)[0];
188
+ } else {
189
+ diff = 1;
190
+ }
172
191
 
173
- // If only one data, update the domain to flow from left edge of the chart
174
- if (!orgDataCount) {
175
- if (isTimeSeries) {
176
- diff = baseTarget.values.length > 1 ?
177
- baseTarget.values[baseTarget.values.length - 1].x - baseValue.x :
178
- baseValue.x - $$.getXDomain($$.data.targets)[0];
179
- } else {
180
- diff = 1;
192
+ domain = [baseValue.x - diff, baseValue.x];
193
+ } else if (orgDataCount === 1 && isTimeSeries) {
194
+ diff = (baseTarget.values[baseTarget.values.length - 1].x - baseValue.x) / 2;
195
+ domain = [new Date(+baseValue.x - diff), new Date(+baseValue.x + diff)];
181
196
  }
182
197
 
183
- domain = [baseValue.x - diff, baseValue.x];
184
- } else if (orgDataCount === 1 && isTimeSeries) {
185
- diff = (baseTarget.values[baseTarget.values.length - 1].x - baseValue.x) / 2;
186
- domain = [new Date(+baseValue.x - diff), new Date(+baseValue.x + diff)];
198
+ domain && $$.updateXDomain(null, true, true, false, domain);
199
+
200
+ // Set targets
201
+ $$.updateTargets($$.data.targets);
202
+
203
+ // Redraw with new targets
204
+ $$.redraw({
205
+ flow: {
206
+ index: baseValue.index,
207
+ length: length,
208
+ duration: isValue(args.duration) ? args.duration : $$.config.transition_duration,
209
+ done: args.done,
210
+ orgDataCount: orgDataCount,
211
+ },
212
+ withLegend: true,
213
+ withTransition: orgDataCount > 1,
214
+ withTrimXDomain: false,
215
+ withUpdateXAxis: true
216
+ });
187
217
  }
188
-
189
- domain && $$.updateXDomain(null, true, true, false, domain);
190
-
191
- // Set targets
192
- $$.updateTargets($$.data.targets);
193
-
194
- // Redraw with new targets
195
- $$.redraw({
196
- flow: {
197
- index: baseValue.index,
198
- length: length,
199
- duration: isValue(args.duration) ? args.duration : $$.config.transition_duration,
200
- done: args.done,
201
- orgDataCount: orgDataCount,
202
- },
203
- withLegend: true,
204
- withTransition: orgDataCount > 1,
205
- withTrimXDomain: false,
206
- withUpdateXAxis: true
207
- });
208
218
  }
209
219
  };
@@ -13,6 +13,7 @@ export default class AxisRenderer {
13
13
  private config;
14
14
  private params;
15
15
  private g;
16
+ private generatedTicks: (Date|number)[];
16
17
 
17
18
  constructor(params: any = {}) {
18
19
  const config = {
@@ -46,10 +47,10 @@ export default class AxisRenderer {
46
47
  */
47
48
  create(g: d3Selection): void {
48
49
  const ctx = this;
49
- const {config, helper, params} = this;
50
+ const {config, helper, params} = ctx;
50
51
  const {scale} = helper;
51
52
  const {orient} = config;
52
- const splitTickText = this.splitTickText.bind(this);
53
+ const splitTickText = this.splitTickText.bind(ctx);
53
54
  const isLeftRight = /^(left|right)$/.test(orient);
54
55
  const isTopBottom = /^(top|bottom)$/.test(orient);
55
56
 
@@ -113,6 +114,9 @@ export default class AxisRenderer {
113
114
  // count of tick data in array
114
115
  const ticks = config.tickValues || helper.generateTicks(scale1, isLeftRight);
115
116
 
117
+ // set generated ticks
118
+ ctx.generatedTicks = ticks;
119
+
116
120
  // update selection
117
121
  let tick: d3Selection = g.selectAll(".tick")
118
122
  .data(ticks, scale1);
@@ -228,6 +232,28 @@ export default class AxisRenderer {
228
232
  this.g = $g;
229
233
  }
230
234
 
235
+ /**
236
+ * Get generated ticks
237
+ * @param {number} count Count of ticks
238
+ * @returns {Array} Generated ticks
239
+ * @private
240
+ */
241
+ getGeneratedTicks(count: number): (Date|number)[] {
242
+ const len = this.generatedTicks.length - 1;
243
+ let res = this.generatedTicks;
244
+
245
+ if (len > count) {
246
+ const interval = Math.round((len / count) - 0.1);
247
+
248
+ res = this.generatedTicks
249
+ .map((v, i) => (i % interval === 0 ? v : null))
250
+ .filter(v => v !== null)
251
+ .splice(0, count) as (Date|number)[];
252
+ }
253
+
254
+ return res;
255
+ }
256
+
231
257
  /**
232
258
  * Get tick x/y coordinate
233
259
  * @returns {{x: number, y: number}}
@@ -505,7 +531,7 @@ export default class AxisRenderer {
505
531
  return this;
506
532
  }
507
533
 
508
- tickValues(x?): AxisRenderer | (number|Date|string)[] {
534
+ tickValues(x?: (number|Date|string)[]|Function): AxisRenderer | (number|Date|string)[] {
509
535
  const {config} = this;
510
536
 
511
537
  if (isFunction(x)) {
@@ -39,6 +39,7 @@ import redraw from "./internals/redraw";
39
39
  import scale from "./internals/scale";
40
40
  import shape from "./shape/shape";
41
41
  import size from "./internals/size";
42
+ import style from "./internals/style";
42
43
  import text from "./internals/text";
43
44
  import title from "./internals/title";
44
45
  import tooltip from "./internals/tooltip";
@@ -175,21 +176,32 @@ export default class ChartInternal {
175
176
  init(): void {
176
177
  const $$ = <any> this;
177
178
  const {config, state, $el} = $$;
179
+ const useCssRule = config.boost_useCssRule;
178
180
 
179
181
  checkModuleImport($$);
180
182
 
181
183
  state.hasAxis = !$$.hasArcType();
182
184
  state.hasRadar = !state.hasAxis && $$.hasType("radar");
183
185
 
184
- // when 'padding=false' is set, disable axes and subchart. Because they are useless.
185
- if (config.padding === false) {
186
- config.axis_x_show = false;
187
- config.axis_y_show = false;
188
- config.axis_y2_show = false;
189
- config.subchart_show = false;
190
- }
186
+ // datetime to be used for uniqueness
187
+ state.datetimeId = `bb-${+new Date() * (getRandom() as number)}`;
191
188
 
192
- $$.initParams();
189
+ if (useCssRule) {
190
+ // append style element
191
+ const styleEl = document.createElement("style");
192
+
193
+ // styleEl.id = styleId;
194
+ styleEl.type = "text/css";
195
+ document.head.appendChild(styleEl);
196
+
197
+ state.style = {
198
+ rootSelctor: `.${state.datetimeId}`,
199
+ sheet: styleEl.sheet
200
+ };
201
+
202
+ // used on .destroy()
203
+ $el.style = styleEl;
204
+ }
193
205
 
194
206
  const bindto = {
195
207
  element: config.bindto,
@@ -211,8 +223,10 @@ export default class ChartInternal {
211
223
 
212
224
  $el.chart.html("")
213
225
  .classed(bindto.classname, true)
226
+ .classed(state.datetimeId, useCssRule)
214
227
  .style("position", "relative");
215
228
 
229
+ $$.initParams();
216
230
  $$.initToRender();
217
231
  }
218
232
 
@@ -242,10 +256,10 @@ export default class ChartInternal {
242
256
  }
243
257
 
244
258
  if (!isLazy || forced) {
245
- const convertedData = $$.convertData(config, $$.initWithData);
246
-
247
- convertedData && $$.initWithData(convertedData);
248
- $$.afterInit();
259
+ $$.convertData(config, res => {
260
+ $$.initWithData(res);
261
+ $$.afterInit();
262
+ });
249
263
  }
250
264
  }
251
265
 
@@ -254,12 +268,18 @@ export default class ChartInternal {
254
268
  const {config, format, state} = $$;
255
269
  const isRotated = config.axis_rotated;
256
270
 
257
- // datetime to be used for uniqueness
258
- state.datetimeId = `bb-${+new Date() * (getRandom() as number)}`;
259
-
271
+ // color settings
260
272
  $$.color = $$.generateColor();
261
273
  $$.levelColor = $$.generateLevelColor();
262
274
 
275
+ // when 'padding=false' is set, disable axes and subchart. Because they are useless.
276
+ if (config.padding === false) {
277
+ config.axis_x_show = false;
278
+ config.axis_y_show = false;
279
+ config.axis_y2_show = false;
280
+ config.subchart_show = false;
281
+ }
282
+
263
283
  if ($$.hasPointType()) {
264
284
  $$.point = $$.generatePoint();
265
285
  }
@@ -715,20 +735,27 @@ export default class ChartInternal {
715
735
  bindResize(): void {
716
736
  const $$ = <any> this;
717
737
  const {config, state} = $$;
718
- const resizeFunction = generateResize();
738
+ const resizeFunction = generateResize(config.resize_timer);
719
739
  const list: Function[] = [];
720
740
 
721
- list.push(() => callFn(config.onresize, $$, $$.api));
741
+ list.push(() => callFn(config.onresize, $$.api));
722
742
 
723
743
  if (config.resize_auto) {
724
744
  list.push(() => {
725
745
  state.resizing = true;
746
+
747
+ // https://github.com/naver/billboard.js/issues/2650
748
+ if (config.legend_show) {
749
+ $$.updateSizes();
750
+ $$.updateLegend();
751
+ }
752
+
726
753
  $$.api.flush(false);
727
754
  });
728
755
  }
729
756
 
730
757
  list.push(() => {
731
- callFn(config.onresized, $$, $$.api);
758
+ callFn(config.onresized, $$.api);
732
759
  state.resizing = false;
733
760
  });
734
761
 
@@ -775,6 +802,7 @@ extend(ChartInternal.prototype, [
775
802
  scale,
776
803
  shape,
777
804
  size,
805
+ style,
778
806
  text,
779
807
  title,
780
808
  tooltip,
@@ -4,7 +4,7 @@
4
4
  */
5
5
  export interface IDataRow {
6
6
  x: number;
7
- value: number;
7
+ value: number | null;
8
8
  id: string;
9
9
  index: number;
10
10
  name?: string;
@@ -22,7 +22,7 @@ export interface IArcData {
22
22
  padAngle: number;
23
23
  startAngle: number;
24
24
  endAngle: number;
25
- value: number;
25
+ value: number | null;
26
26
  }
27
27
 
28
28
  export interface IGridData {