billboard.js 3.6.0-next.1 → 3.6.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 (49) hide show
  1. package/dist/billboard.css +1 -1
  2. package/dist/billboard.js +454 -244
  3. package/dist/billboard.min.css +1 -1
  4. package/dist/billboard.min.js +2 -2
  5. package/dist/billboard.pkgd.js +2382 -2153
  6. package/dist/billboard.pkgd.min.js +3 -3
  7. package/dist/plugin/billboardjs-plugin-bubblecompare.js +2 -2
  8. package/dist/plugin/billboardjs-plugin-bubblecompare.min.js +2 -2
  9. package/dist/plugin/billboardjs-plugin-sparkline.js +7 -3
  10. package/dist/plugin/billboardjs-plugin-sparkline.min.js +2 -2
  11. package/dist/plugin/billboardjs-plugin-stanford.js +7 -3
  12. package/dist/plugin/billboardjs-plugin-stanford.min.js +2 -2
  13. package/dist/plugin/billboardjs-plugin-tableview.js +7 -3
  14. package/dist/plugin/billboardjs-plugin-tableview.min.js +2 -2
  15. package/dist/plugin/billboardjs-plugin-textoverlap.js +7 -3
  16. package/dist/plugin/billboardjs-plugin-textoverlap.min.js +2 -2
  17. package/dist/plugin/pkgd/billboardjs-plugin-bubblecompare.js +1926 -1907
  18. package/dist/plugin/pkgd/billboardjs-plugin-sparkline.js +1932 -1909
  19. package/dist/plugin/pkgd/billboardjs-plugin-stanford.js +1933 -1910
  20. package/dist/plugin/pkgd/billboardjs-plugin-tableview.js +1933 -1910
  21. package/dist/plugin/pkgd/billboardjs-plugin-textoverlap.js +1933 -1910
  22. package/dist/theme/datalab.css +1 -1
  23. package/dist/theme/datalab.min.css +1 -1
  24. package/dist/theme/graph.css +1 -1
  25. package/dist/theme/graph.min.css +1 -1
  26. package/dist/theme/insight.css +1 -1
  27. package/dist/theme/insight.min.css +1 -1
  28. package/dist-esm/billboard.js +377 -178
  29. package/dist-esm/plugin/billboardjs-plugin-bubblecompare.js +2 -2
  30. package/dist-esm/plugin/billboardjs-plugin-sparkline.js +6 -2
  31. package/dist-esm/plugin/billboardjs-plugin-stanford.js +6 -2
  32. package/dist-esm/plugin/billboardjs-plugin-tableview.js +6 -2
  33. package/dist-esm/plugin/billboardjs-plugin-textoverlap.js +6 -2
  34. package/package.json +11 -11
  35. package/src/Chart/api/chart.ts +11 -3
  36. package/src/ChartInternal/ChartInternal.ts +3 -2
  37. package/src/ChartInternal/internals/color.ts +50 -0
  38. package/src/ChartInternal/internals/legend.ts +246 -145
  39. package/src/ChartInternal/shape/area.ts +9 -38
  40. package/src/ChartInternal/shape/bar.ts +22 -4
  41. package/src/ChartInternal/shape/candlestick.ts +4 -3
  42. package/src/ChartInternal/shape/shape.ts +22 -9
  43. package/src/config/Options/common/legend.ts +18 -3
  44. package/src/config/Options/shape/bar.ts +38 -0
  45. package/src/config/Store/State.ts +1 -0
  46. package/src/config/config.ts +7 -1
  47. package/types/axis.d.ts +1 -1
  48. package/types/chart.d.ts +3 -1
  49. package/types/options.d.ts +28 -4
@@ -5,8 +5,9 @@
5
5
  import {select as d3Select} from "d3-selection";
6
6
  import {$CANDLESTICK, $COMMON} from "../../config/classes";
7
7
  import {getRandom, isArray, isNumber, isObject} from "../../module/util";
8
+ import type {IOffset} from "./shape";
8
9
 
9
- type CandlestickData = {
10
+ interface ICandlestickData {
10
11
  open: number;
11
12
  high: number;
12
13
  low: number;
@@ -160,7 +161,7 @@ export default {
160
161
 
161
162
  const axis = isSub ? $$.axis.subX : $$.axis.x;
162
163
  const targetsNum = $$.getIndicesMax(indices) + 1;
163
- const barW = $$.getBarW("candlestick", axis, targetsNum);
164
+ const barW: IOffset = $$.getBarW("candlestick", axis, targetsNum);
164
165
  const x = $$.getShapeX(barW, indices, !!isSub);
165
166
  const y = $$.getShapeY(!!isSub);
166
167
  const shapeOffset = $$.getShapeOffset($$.isBarType, indices, !!isSub);
@@ -244,7 +245,7 @@ export default {
244
245
  * @returns {object|null} Converted data object
245
246
  * @private
246
247
  */
247
- getCandlestickData({value}): CandlestickData | null {
248
+ getCandlestickData({value}): ICandlestickData | null {
248
249
  let d;
249
250
 
250
251
  if (isArray(value)) {
@@ -28,6 +28,11 @@ import CLASS from "../../config/classes";
28
28
  import {capitalize, getPointer, getRectSegList, getUnique, isObjectType, isNumber, isValue, isUndefined, notEmpty} from "../../module/util";
29
29
  import type {IDataRow, IDataIndice, TIndices} from "../data/IData";
30
30
 
31
+ export interface IOffset {
32
+ _$width: number;
33
+ _$total: number[]
34
+ }
35
+
31
36
  export default {
32
37
  /**
33
38
  * Get the shape draw function
@@ -35,7 +40,7 @@ export default {
35
40
  * @private
36
41
  */
37
42
  getDrawShape() {
38
- type SHAPE = {
43
+ type TShape = {
39
44
  area?: any;
40
45
  bar?: any;
41
46
  line?: any;
@@ -44,7 +49,7 @@ export default {
44
49
  const $$ = this;
45
50
  const isRotated = $$.config.axis_rotated;
46
51
  const {hasRadar} = $$.state;
47
- const shape = {type: <SHAPE> {}, indices: <SHAPE> {}, pos: {}};
52
+ const shape = {type: <TShape>{}, indices: <TShape>{}, pos: {}};
48
53
 
49
54
  ["bar", "candlestick", "line", "area"].forEach(v => {
50
55
  const name = capitalize(/^(bubble|scatter)$/.test(v) ? "line" : v);
@@ -176,12 +181,15 @@ export default {
176
181
  .reduce((acc, curr) => acc + curr) : (indices as IDataIndice).__max__;
177
182
  },
178
183
 
179
- getShapeX(offset, indices, isSub?: boolean): (d) => number {
184
+ getShapeX(offset: IOffset, indices, isSub?: boolean): (d) => number {
180
185
  const $$ = this;
181
186
  const {config, scale} = $$;
182
187
  const currScale = isSub ? scale.subX : (scale.zoom || scale.x);
188
+ const barOverlap = config.bar_overlap;
183
189
  const barPadding = config.bar_padding;
184
190
  const sum = (p, c) => p + c;
191
+
192
+ // total shapes half width
185
193
  const halfWidth = isObjectType(offset) && (
186
194
  offset._$total.length ? offset._$total.reduce(sum) / 2 : 0
187
195
  );
@@ -196,15 +204,20 @@ export default {
196
204
  const xPos = currScale(d.x, true);
197
205
 
198
206
  if (halfWidth) {
199
- x = xPos - (offset[d.id] || offset._$width) +
200
- offset._$total.slice(0, index + 1).reduce(sum) -
201
- halfWidth;
207
+ const offsetWidth = offset[d.id] || offset._$width;
208
+
209
+ x = barOverlap ?
210
+ xPos - offsetWidth / 2 :
211
+ xPos - offsetWidth + offset._$total.slice(0, index + 1).reduce(sum) - halfWidth;
202
212
  } else {
203
- x = xPos - (isNumber(offset) ? offset : offset._$width) * (targetsNum / 2 - index);
213
+ x = xPos - (isNumber(offset) ? offset : offset._$width) *
214
+ (targetsNum / 2 - (
215
+ barOverlap ? 1 : index
216
+ ));
204
217
  }
205
218
  }
206
219
 
207
- // adjust x position for bar.padding optionq
220
+ // adjust x position for bar.padding option
208
221
  if (offset && x && targetsNum > 1 && barPadding) {
209
222
  if (index) {
210
223
  x += barPadding * index;
@@ -353,7 +366,7 @@ export default {
353
366
  };
354
367
  },
355
368
 
356
- getBarW(type, axis, targetsNum: number): number {
369
+ getBarW(type, axis, targetsNum: number): number | IOffset {
357
370
  const $$ = this;
358
371
  const {config, org, scale} = $$;
359
372
  const maxDataCount = $$.getMaxDataCount();
@@ -43,9 +43,15 @@ export default {
43
43
  * @property {Function} [legend.item.onclick=undefined] Set click event handler to the legend item.
44
44
  * @property {Function} [legend.item.onover=undefined] Set mouse/touch over event handler to the legend item.
45
45
  * @property {Function} [legend.item.onout=undefined] Set mouse/touch out event handler to the legend item.
46
- * @property {number} [legend.item.tile.width=10] Set width of item tile element
47
- * @property {number} [legend.item.tile.height=10] Set height of item tile element
46
+ * @property {number} [legend.item.tile.width=10] Set width for 'rectangle' legend item tile element.
47
+ * @property {number} [legend.item.tile.height=10] ㄹ
48
+ * @property {number} [legend.item.tile.r=5] Set the radius for 'circle' legend item tile type.
49
+ * @property {string} [legend.item.tile.type="rectangle"] Set legend item shape type.<br>
50
+ * - **Available Values:**
51
+ * - circle
52
+ * - rectangle
48
53
  * @property {boolean} [legend.usePoint=false] Whether to use custom points in legend.
54
+ * @see [Demo: item.tile.type](https://naver.github.io/billboard.js/demo/#Legend.LegendItemTileType)
49
55
  * @see [Demo: position](https://naver.github.io/billboard.js/demo/#Legend.LegendPosition)
50
56
  * @see [Demo: contents.template](https://naver.github.io/billboard.js/demo/#Legend.LegendTemplate1)
51
57
  * @see [Demo: usePoint](https://naver.github.io/billboard.js/demo/#Legend.usePoint)
@@ -85,8 +91,15 @@ export default {
85
91
  *
86
92
  * // set tile's size
87
93
  * tile: {
88
- * width: 20,
94
+ * // set tile type
95
+ * type: "circle" // or "rectangle" (default)
96
+ *
97
+ * // width & height, are only applicable for 'rectangle' legend type
98
+ * width: 15,
89
99
  * height: 15
100
+ *
101
+ * // radis is only applicable for 'circle' legend type
102
+ * r: 10
90
103
  * }
91
104
  * },
92
105
  * usePoint: true
@@ -108,5 +121,7 @@ export default {
108
121
  legend_padding: 0,
109
122
  legend_item_tile_width: 10,
110
123
  legend_item_tile_height: 10,
124
+ legend_item_tile_r: 5,
125
+ legend_item_tile_type: <"rectangle"|"circle"> "rectangle",
111
126
  legend_usePoint: false
112
127
  };
@@ -14,6 +14,12 @@ export default {
14
14
  * @property {object} bar Bar object
15
15
  * @property {number} [bar.indices.removeNull=false] Remove nullish data on bar indices positions.
16
16
  * @property {number} [bar.label.threshold=0] Set threshold ratio to show/hide labels.
17
+ * @property {boolean|object} [bar.linearGradient=false] Set the linear gradient on bar.<br><br>
18
+ * Or customize by giving below object value:
19
+ * - x {Array}: `x1`, `x2` value
20
+ * - y {Array}: `y1`, `y2` value
21
+ * - stops {Array}: Each item should be having `[offset, stop-color, stop-opacity]` values.
22
+ * @property {boolean} [bar.overlap=false] Bars will be rendered at same position, which will be overlapped each other. (for non-grouped bars only)
17
23
  * @property {number} [bar.padding=0] The padding pixel value between each bar.
18
24
  * @property {number} [bar.radius] Set the radius of bar edge in pixel.
19
25
  * @property {number} [bar.radius.ratio] Set the radius ratio of bar edge in relative the bar's width.
@@ -29,6 +35,7 @@ export default {
29
35
  * @property {number} [bar.width.dataname.max] The maximum width value for ratio.
30
36
  * @property {boolean} [bar.zerobased=true] Set if min or max value will be 0 on bar chart.
31
37
  * @see [Demo: bar indices](https://naver.github.io/billboard.js/demo/#BarChartOptions.BarIndices)
38
+ * @see [Demo: bar overlap](https://naver.github.io/billboard.js/demo/#BarChartOptions.BarOverlap)
32
39
  * @see [Demo: bar padding](https://naver.github.io/billboard.js/demo/#BarChartOptions.BarPadding)
33
40
  * @see [Demo: bar radius](https://naver.github.io/billboard.js/demo/#BarChartOptions.BarRadius)
34
41
  * @see [Demo: bar width](https://naver.github.io/billboard.js/demo/#BarChartOptions.BarWidth)
@@ -40,6 +47,33 @@ export default {
40
47
  * removeNull: true
41
48
  * },
42
49
  *
50
+ * // will generate follwing linearGradient:
51
+ * // <linearGradient x1="0" x2="0" y1="0" y2="1">
52
+ * // <stop offset="0" stop-color="$DATA_COLOR" stop-opacity="1"></stop>
53
+ * // <stop offset="1" stop-color="$DATA_COLOR" stop-opacity="0"></stop>
54
+ * // </linearGradient>
55
+ * linearGradient: true,
56
+ *
57
+ * // Or customized gradient
58
+ * linearGradient: {
59
+ * x: [0, 0], // x1, x2 attributes
60
+ * y: [0, 0], // y1, y2 attributes
61
+ * stops: [
62
+ * // offset, stop-color, stop-opacity
63
+ * [0, "#7cb5ec", 1],
64
+ *
65
+ * // setting 'null' for stop-color, will set its original data color
66
+ * [0.5, null, 0],
67
+ *
68
+ * // setting 'function' for stop-color, will pass data id as argument.
69
+ * // It should return color string or null value
70
+ * [1, function(id) { return id === "data1" ? "red" : "blue"; }, 0],
71
+ * ]
72
+ * },
73
+ *
74
+ * // remove nullish da
75
+ * overlap: true,
76
+ *
43
77
  * padding: 1,
44
78
  *
45
79
  * // bar radius
@@ -79,7 +113,11 @@ export default {
79
113
  * }
80
114
  */
81
115
  bar_label_threshold: 0,
116
+ bar_linearGradient: <
117
+ boolean|{x?: number[]; y?: number[]; stops?: [number, string|Function|null, number]}
118
+ > false,
82
119
  bar_indices_removeNull: false,
120
+ bar_overlap: false,
83
121
  bar_padding: 0,
84
122
  bar_radius: <number|{ratio: number}|undefined> undefined,
85
123
  bar_radius_ratio: <number|undefined> undefined,
@@ -127,6 +127,7 @@ export default class State {
127
127
  hasPositiveValue: true,
128
128
 
129
129
  orgAreaOpacity: "0.2",
130
+ orgConfig: {}, // user original genration config
130
131
 
131
132
  // ID strings
132
133
  hiddenTargetIds: <string[]> [],
@@ -4,13 +4,14 @@
4
4
  */
5
5
  import {isDefined, isObjectType} from "../module/util";
6
6
  import Options from "./Options/Options";
7
+ import type {ChartOptions} from "../../types/options";
7
8
 
8
9
  /**
9
10
  * Load configuration option
10
11
  * @param {object} config User's generation config value
11
12
  * @private
12
13
  */
13
- export function loadConfig(config: Options): void {
14
+ export function loadConfig(config: ChartOptions): void {
14
15
  const thisConfig: Options = this.config;
15
16
  let target;
16
17
  let keys;
@@ -38,4 +39,9 @@ export function loadConfig(config: Options): void {
38
39
  thisConfig[key] = read;
39
40
  }
40
41
  });
42
+
43
+ // only should run in the ChartInternal context
44
+ if (this.api) {
45
+ this.state.orgConfig = config;
46
+ }
41
47
  }
package/types/axis.d.ts CHANGED
@@ -352,7 +352,7 @@ export interface YTickConfiguration {
352
352
  * Set formatter for y axis tick text.
353
353
  * This option accepts d3.format object as well as a function you define.
354
354
  */
355
- format?: (this: Chart, x: number | Date) => string | number;
355
+ format?: ((this: Chart, x: number) => string | number) | ((this: Chart, x: Date) => string | number);
356
356
 
357
357
  /**
358
358
  * Setting for culling ticks.
package/types/chart.d.ts CHANGED
@@ -515,11 +515,13 @@ export interface Chart {
515
515
 
516
516
  /**
517
517
  * Get or set single config option value.
518
+ * - **NOTE:**
519
+ * - without parameter, will return all specified generation options object only. (will exclude any other options not specified at the initialization)
518
520
  * @param optionName The option key name.
519
521
  * @param value The value accepted for indicated option.
520
522
  * @param redraw Set to redraw with the new option changes. (NOTE: Doesn't guarantee work in all circumstances. It can be applied for limited options only)
521
523
  */
522
- config(optionName: string, value?: any, redraw?: boolean): any;
524
+ config(optionName?: string, value?: any, redraw?: boolean): any;
523
525
  }
524
526
 
525
527
  export interface GridOperations {
@@ -298,7 +298,7 @@ export interface ChartOptions {
298
298
  * - y {Array}: `y1`, `y2` value
299
299
  * - stops {Array}: Each item should be having `[offset, stop-color, stop-opacity]` values.
300
300
  */
301
- linearGradient?: boolean | AreaLinearGradientOptions;
301
+ linearGradient?: boolean | LinearGradientOptions;
302
302
 
303
303
  /**
304
304
  * Set if min or max value will be 0 on area chart.
@@ -321,6 +321,20 @@ export interface ChartOptions {
321
321
  removeNull?: boolean;
322
322
  }
323
323
 
324
+ /**
325
+ * Set the linear gradient on bar.<br><br>
326
+ * Or customize by giving below object value:
327
+ * - x {Array}: `x1`, `x2` value
328
+ * - y {Array}: `y1`, `y2` value
329
+ * - stops {Array}: Each item should be having `[offset, stop-color, stop-opacity]` values.
330
+ */
331
+ linearGradient?: boolean | LinearGradientOptions;
332
+
333
+ /**
334
+ * Bars will be rendered at same position, which will be overlapped each other. (for non-grouped bars only)
335
+ */
336
+ orverlap?: boolean;
337
+
324
338
  /**
325
339
  * The padding pixel value between each bar.
326
340
  */
@@ -925,7 +939,7 @@ export interface ChartOptions {
925
939
  };
926
940
  }
927
941
 
928
- export interface AreaLinearGradientOptions {
942
+ export interface LinearGradientOptions {
929
943
  /**
930
944
  * x1, x2 attributes
931
945
  */
@@ -995,14 +1009,24 @@ export interface LegendOptions {
995
1009
  */
996
1010
  tile?: {
997
1011
  /**
998
- * Tile width.
1012
+ * Set width for 'rectangle' legend item tile element.
999
1013
  */
1000
1014
  width?: number;
1001
1015
 
1002
1016
  /**
1003
- * Tile height
1017
+ * Set height for 'rectangle' legend item tile element.
1004
1018
  */
1005
1019
  height?: number;
1020
+
1021
+ /**
1022
+ * Set legend item shape type.
1023
+ */
1024
+ type?: "circle" | "rectangle";
1025
+
1026
+ /**
1027
+ * Set the radius for 'circle' legend item tile type.
1028
+ */
1029
+ r?: number;
1006
1030
  };
1007
1031
  /**
1008
1032
  * Set click event handler to the legend item.