billboard.js 3.4.0 → 3.5.0-next.2

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 (70) hide show
  1. package/README.md +11 -4
  2. package/dist/billboard.css +1 -1
  3. package/dist/billboard.js +3901 -1451
  4. package/dist/billboard.min.css +1 -1
  5. package/dist/billboard.min.js +2 -2
  6. package/dist/billboard.pkgd.js +8350 -5297
  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 +377 -92
  11. package/dist/plugin/billboardjs-plugin-sparkline.min.js +2 -2
  12. package/dist/plugin/billboardjs-plugin-stanford.js +447 -109
  13. package/dist/plugin/billboardjs-plugin-stanford.min.js +2 -2
  14. package/dist/plugin/billboardjs-plugin-tableview.js +341 -74
  15. package/dist/plugin/billboardjs-plugin-tableview.min.js +2 -2
  16. package/dist/plugin/billboardjs-plugin-textoverlap.js +337 -75
  17. package/dist/plugin/billboardjs-plugin-textoverlap.min.js +2 -2
  18. package/dist/plugin/pkgd/billboardjs-plugin-bubblecompare.js +4233 -3792
  19. package/dist/plugin/pkgd/billboardjs-plugin-sparkline.js +4635 -3889
  20. package/dist/plugin/pkgd/billboardjs-plugin-stanford.js +4823 -3937
  21. package/dist/plugin/pkgd/billboardjs-plugin-tableview.js +4594 -3866
  22. package/dist/plugin/pkgd/billboardjs-plugin-textoverlap.js +4606 -3874
  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 +796 -387
  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 +40 -40
  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 +55 -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/color.ts +59 -36
  47. package/src/ChartInternal/internals/grid.ts +5 -3
  48. package/src/ChartInternal/internals/redraw.ts +5 -2
  49. package/src/ChartInternal/internals/scale.ts +3 -1
  50. package/src/ChartInternal/internals/size.axis.ts +5 -2
  51. package/src/ChartInternal/internals/text.ts +118 -17
  52. package/src/ChartInternal/shape/area.ts +14 -7
  53. package/src/ChartInternal/shape/bar.ts +19 -10
  54. package/src/ChartInternal/shape/point.ts +15 -9
  55. package/src/ChartInternal/shape/polar.ts +1 -1
  56. package/src/Plugin/sparkline/index.ts +22 -11
  57. package/src/Plugin/stanford/index.ts +10 -7
  58. package/src/Plugin/textoverlap/index.ts +4 -1
  59. package/src/config/Options/Options.ts +2 -0
  60. package/src/config/Options/common/boost.ts +31 -0
  61. package/src/config/Options/common/main.ts +15 -1
  62. package/src/config/Options/common/tooltip.ts +1 -1
  63. package/src/config/Options/data/data.ts +11 -3
  64. package/src/config/Options/shape/area.ts +6 -1
  65. package/src/config/Store/State.ts +3 -0
  66. package/src/module/browser.ts +2 -1
  67. package/src/module/generator.ts +18 -16
  68. package/src/module/util.ts +115 -1
  69. package/types/chart.d.ts +2 -2
  70. 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)) {
@@ -175,21 +175,32 @@ export default class ChartInternal {
175
175
  init(): void {
176
176
  const $$ = <any> this;
177
177
  const {config, state, $el} = $$;
178
+ const useCssRule = config.boost_useCssRule;
178
179
 
179
180
  checkModuleImport($$);
180
181
 
181
182
  state.hasAxis = !$$.hasArcType();
182
183
  state.hasRadar = !state.hasAxis && $$.hasType("radar");
183
184
 
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
- }
185
+ // datetime to be used for uniqueness
186
+ state.datetimeId = `bb-${+new Date() * (getRandom() as number)}`;
191
187
 
192
- $$.initParams();
188
+ if (useCssRule) {
189
+ // append style element
190
+ const styleEl = document.createElement("style");
191
+
192
+ // styleEl.id = styleId;
193
+ styleEl.type = "text/css";
194
+ document.head.appendChild(styleEl);
195
+
196
+ state.style = {
197
+ rootSelctor: `.${state.datetimeId}`,
198
+ sheet: styleEl.sheet
199
+ };
200
+
201
+ // used on .destroy()
202
+ $el.style = styleEl;
203
+ }
193
204
 
194
205
  const bindto = {
195
206
  element: config.bindto,
@@ -211,8 +222,10 @@ export default class ChartInternal {
211
222
 
212
223
  $el.chart.html("")
213
224
  .classed(bindto.classname, true)
225
+ .classed(state.datetimeId, useCssRule)
214
226
  .style("position", "relative");
215
227
 
228
+ $$.initParams();
216
229
  $$.initToRender();
217
230
  }
218
231
 
@@ -242,10 +255,10 @@ export default class ChartInternal {
242
255
  }
243
256
 
244
257
  if (!isLazy || forced) {
245
- const convertedData = $$.convertData(config, $$.initWithData);
246
-
247
- convertedData && $$.initWithData(convertedData);
248
- $$.afterInit();
258
+ $$.convertData(config, res => {
259
+ $$.initWithData(res);
260
+ $$.afterInit();
261
+ });
249
262
  }
250
263
  }
251
264
 
@@ -253,13 +266,30 @@ export default class ChartInternal {
253
266
  const $$ = <any> this;
254
267
  const {config, format, state} = $$;
255
268
  const isRotated = config.axis_rotated;
269
+ const useCssRule = config.boost_useCssRule;
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();
273
+ $$.colorByRule = $$.color;
274
+ $$.colorTextByRule = $$.updateTextColor.bind($$);
261
275
  $$.levelColor = $$.generateLevelColor();
262
276
 
277
+ if (useCssRule) {
278
+ state.colorRule = {};
279
+
280
+ // to not apply inline color setting
281
+ $$.colorByRule = null;
282
+ $$.colorTextByRule = null;
283
+ }
284
+
285
+ // when 'padding=false' is set, disable axes and subchart. Because they are useless.
286
+ if (config.padding === false) {
287
+ config.axis_x_show = false;
288
+ config.axis_y_show = false;
289
+ config.axis_y2_show = false;
290
+ config.subchart_show = false;
291
+ }
292
+
263
293
  if ($$.hasPointType()) {
264
294
  $$.point = $$.generatePoint();
265
295
  }
@@ -715,20 +745,27 @@ export default class ChartInternal {
715
745
  bindResize(): void {
716
746
  const $$ = <any> this;
717
747
  const {config, state} = $$;
718
- const resizeFunction = generateResize();
748
+ const resizeFunction = generateResize(config.resize_timer);
719
749
  const list: Function[] = [];
720
750
 
721
- list.push(() => callFn(config.onresize, $$, $$.api));
751
+ list.push(() => callFn(config.onresize, $$.api));
722
752
 
723
753
  if (config.resize_auto) {
724
754
  list.push(() => {
725
755
  state.resizing = true;
756
+
757
+ // https://github.com/naver/billboard.js/issues/2650
758
+ if (config.legend_show) {
759
+ $$.updateSizes();
760
+ $$.updateLegend();
761
+ }
762
+
726
763
  $$.api.flush(false);
727
764
  });
728
765
  }
729
766
 
730
767
  list.push(() => {
731
- callFn(config.onresized, $$, $$.api);
768
+ callFn(config.onresized, $$.api);
732
769
  state.resizing = false;
733
770
  });
734
771
 
@@ -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 {