billboard.js 3.5.1 → 3.6.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 (58) hide show
  1. package/README.md +11 -1
  2. package/dist/billboard.css +1 -1
  3. package/dist/billboard.js +87 -35
  4. package/dist/billboard.min.css +1 -1
  5. package/dist/billboard.min.js +2 -2
  6. package/dist/billboard.pkgd.js +2343 -2107
  7. package/dist/billboard.pkgd.min.js +3 -3
  8. package/dist/plugin/billboardjs-plugin-bubblecompare.js +2 -2
  9. package/dist/plugin/billboardjs-plugin-bubblecompare.min.js +2 -2
  10. package/dist/plugin/billboardjs-plugin-sparkline.js +7 -3
  11. package/dist/plugin/billboardjs-plugin-sparkline.min.js +2 -2
  12. package/dist/plugin/billboardjs-plugin-stanford.js +7 -3
  13. package/dist/plugin/billboardjs-plugin-stanford.min.js +2 -2
  14. package/dist/plugin/billboardjs-plugin-tableview.js +7 -3
  15. package/dist/plugin/billboardjs-plugin-tableview.min.js +2 -2
  16. package/dist/plugin/billboardjs-plugin-textoverlap.js +7 -3
  17. package/dist/plugin/billboardjs-plugin-textoverlap.min.js +2 -2
  18. package/dist/plugin/pkgd/billboardjs-plugin-bubblecompare.js +2258 -2074
  19. package/dist/plugin/pkgd/billboardjs-plugin-sparkline.js +2264 -2076
  20. package/dist/plugin/pkgd/billboardjs-plugin-stanford.js +2265 -2077
  21. package/dist/plugin/pkgd/billboardjs-plugin-tableview.js +2266 -2078
  22. package/dist/plugin/pkgd/billboardjs-plugin-textoverlap.js +2267 -2079
  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 +90 -35
  30. package/dist-esm/plugin/billboardjs-plugin-bubblecompare.js +2 -2
  31. package/dist-esm/plugin/billboardjs-plugin-sparkline.js +6 -2
  32. package/dist-esm/plugin/billboardjs-plugin-stanford.js +6 -2
  33. package/dist-esm/plugin/billboardjs-plugin-tableview.js +6 -2
  34. package/dist-esm/plugin/billboardjs-plugin-textoverlap.js +6 -2
  35. package/package.json +32 -30
  36. package/src/Chart/api/chart.ts +11 -3
  37. package/src/Chart/api/group.ts +1 -1
  38. package/src/ChartInternal/Axis/AxisRenderer.ts +2 -2
  39. package/src/ChartInternal/ChartInternal.ts +5 -4
  40. package/src/ChartInternal/data/convert.ts +1 -1
  41. package/src/ChartInternal/internals/color.ts +4 -1
  42. package/src/ChartInternal/internals/grid.ts +0 -1
  43. package/src/ChartInternal/internals/legend.ts +3 -2
  44. package/src/ChartInternal/shape/arc.ts +1 -1
  45. package/src/ChartInternal/shape/bar.ts +2 -1
  46. package/src/ChartInternal/shape/candlestick.ts +4 -3
  47. package/src/ChartInternal/shape/line.ts +5 -1
  48. package/src/ChartInternal/shape/shape.ts +36 -15
  49. package/src/config/Options/common/grid.ts +2 -2
  50. package/src/config/Options/common/legend.ts +3 -2
  51. package/src/config/Options/data/data.ts +18 -0
  52. package/src/config/Options/shape/bar.ts +6 -0
  53. package/src/config/Store/State.ts +1 -0
  54. package/src/config/config.ts +7 -1
  55. package/types/axis.d.ts +17 -2
  56. package/types/chart.d.ts +3 -1
  57. package/types/index.d.ts +1 -0
  58. package/types/options.d.ts +14 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "billboard.js",
3
- "version": "3.5.1",
3
+ "version": "3.6.0-next.2",
4
4
  "description": "Re-usable easy interface JavaScript chart library, based on D3 v4+",
5
5
  "homepage": "https://naver.github.io/billboard.js/",
6
6
  "main": "dist/billboard.js",
@@ -36,12 +36,13 @@
36
36
  "lint": "npm run lint:types && eslint src --ext .ts",
37
37
  "lint:types": "dtslint --onlyTestTsNext types",
38
38
  "loc": "cloc --by-file src",
39
- "test": "node --max-old-space-size=3072 ./node_modules/karma/bin/karma start",
39
+ "test": "node --max-old-space-size=3072 ./node_modules/karma/bin/karma start ./karma.conf.cjs",
40
40
  "test:chrome": "cross-env TEST_TYPE=chrome npm test",
41
41
  "coverage": "cross-env TEST_TYPE=coverage npm test",
42
42
  "coveralls": "cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js",
43
43
  "jsdoc": "node ./config/jsdoc.js",
44
44
  "jsdoc:cmd": "jsdoc -c jsdoc.json",
45
+ "lint-staged": "lint-staged --config ./config/.lintstagedrc.json",
45
46
  "prepare": "husky install"
46
47
  },
47
48
  "sideEffects": [
@@ -95,32 +96,32 @@
95
96
  "d3-zoom": "^3.0.0"
96
97
  },
97
98
  "devDependencies": {
98
- "@babel/core": "^7.18.6",
99
- "@babel/eslint-parser": "^7.17.0",
99
+ "@babel/core": "^7.19.1",
100
+ "@babel/eslint-parser": "^7.19.1",
100
101
  "@babel/plugin-proposal-class-properties": "^7.18.6",
101
- "@babel/plugin-proposal-object-rest-spread": "^7.18.6",
102
- "@babel/plugin-transform-runtime": "^7.18.6",
103
- "@babel/preset-env": "^7.18.6",
102
+ "@babel/plugin-proposal-object-rest-spread": "^7.18.9",
103
+ "@babel/plugin-transform-runtime": "^7.19.1",
104
+ "@babel/preset-env": "^7.19.1",
104
105
  "@babel/preset-typescript": "^7.18.6",
105
- "@babel/runtime": "^7.18.6",
106
- "@commitlint/cli": "15.0.0",
107
- "@commitlint/config-conventional": "^17.0.3",
106
+ "@babel/runtime": "^7.19.0",
107
+ "@commitlint/cli": "17.1.2",
108
+ "@commitlint/config-conventional": "^17.1.0",
108
109
  "@rollup/plugin-babel": "^5.3.1",
109
- "@rollup/plugin-node-resolve": "^13.2.1",
110
+ "@rollup/plugin-node-resolve": "^14.1.0",
110
111
  "@rollup/plugin-replace": "^4.0.0",
111
- "@rollup/plugin-typescript": "^8.3.3",
112
+ "@rollup/plugin-typescript": "^8.5.0",
112
113
  "@semantic-release/changelog": "^6.0.1",
113
114
  "@semantic-release/commit-analyzer": "^9.0.2",
114
115
  "@semantic-release/exec": "^6.0.3",
115
116
  "@semantic-release/git": "^10.0.1",
116
117
  "@semantic-release/npm": "^9.0.1",
117
118
  "@semantic-release/release-notes-generator": "^10.0.3",
118
- "@types/chai": "^4.3.1",
119
+ "@types/chai": "^4.3.3",
119
120
  "@types/d3": "^7.4.0",
120
121
  "@types/mocha": "^9.1.1",
121
- "@types/sinon": "^10.0.12",
122
- "@typescript-eslint/eslint-plugin": "^5.30.6",
123
- "@typescript-eslint/parser": "^5.30.6",
122
+ "@types/sinon": "^10.0.13",
123
+ "@typescript-eslint/eslint-plugin": "^5.38.0",
124
+ "@typescript-eslint/parser": "^5.38.0",
124
125
  "babel-helper-modules": "^6.0.0",
125
126
  "babel-loader": "^8.2.5",
126
127
  "babel-plugin-add-module-exports": "^1.0.4",
@@ -136,29 +137,29 @@
136
137
  "chai": "^4.3.4",
137
138
  "clean-webpack-plugin": "^4.0.0",
138
139
  "cloc": "^2.10.0",
139
- "core-js": "^3.23.4",
140
+ "core-js": "^3.25.2",
140
141
  "coveralls": "^3.1.1",
141
142
  "cross-env": "^7.0.3",
142
143
  "css-loader": "^6.7.1",
143
- "css-minimizer-webpack-plugin": "^4.0.0",
144
+ "css-minimizer-webpack-plugin": "^4.1.0",
144
145
  "d3-color": "^3.1.0",
145
146
  "d3-delaunay": "^6.0.2",
146
147
  "d3-format": "^3.1.0",
147
148
  "d3-polygon": "^3.0.1",
148
149
  "docdash": "^1.2.0",
149
150
  "dtslint": "^4.2.1",
150
- "eslint": "^8.19.0",
151
+ "eslint": "^8.23.1",
151
152
  "eslint-config-naver": "^2.1.0",
152
153
  "eslint-plugin-import": "^2.26.0",
153
- "eslint-plugin-jsdoc": "^39.3.3",
154
+ "eslint-plugin-jsdoc": "^39.3.6",
154
155
  "eslint-webpack-plugin": "^3.2.0",
155
156
  "exports-loader": "^4.0.0",
156
157
  "hammer-simulator": "0.0.1",
157
158
  "husky": "^8.0.1",
158
159
  "istanbul-instrumenter-loader": "^3.0.1",
159
160
  "istanbul-lib-instrument": "^5.2.0",
160
- "jsdoc": "^3.6.10",
161
- "karma": "^6.4.0",
161
+ "jsdoc": "^3.6.11",
162
+ "karma": "^6.4.1",
162
163
  "karma-chai": "^0.1.0",
163
164
  "karma-chrome-launcher": "^3.1.1",
164
165
  "karma-coverage-istanbul-reporter": "^3.0.3",
@@ -168,28 +169,29 @@
168
169
  "karma-sinon": "^1.0.5",
169
170
  "karma-sourcemap-loader": "^0.3.8",
170
171
  "karma-webpack": "^5.0.0",
172
+ "lint-staged": "^13.0.3",
171
173
  "lite-fixture": "^1.0.2",
172
174
  "mini-css-extract-plugin": "^2.6.1",
173
175
  "mocha": "^10.0.0",
174
- "node-sass": "^7.0.1",
176
+ "node-sass": "^7.0.3",
175
177
  "regenerator-runtime": "^0.13.7",
176
- "rollup": "^2.76.0",
178
+ "rollup": "^2.79.1",
177
179
  "rollup-plugin-delete": "^2.0.0",
178
180
  "sass-loader": "^13.0.2",
179
- "semantic-release": "^19.0.3",
181
+ "semantic-release": "^19.0.5",
180
182
  "simulant": "^0.2.2",
181
183
  "sinon": "^14.0.0",
182
184
  "string-replace-loader": "^3.1.0",
183
185
  "style-loader": "^3.3.1",
184
- "terser-webpack-plugin": "^5.3.3",
186
+ "terser-webpack-plugin": "^5.3.6",
185
187
  "tslib": "^2.4.0",
186
- "typescript": "4.6.2",
187
- "webpack": "^5.73.0",
188
- "webpack-bundle-analyzer": "^4.5.0",
188
+ "typescript": "4.8.3",
189
+ "webpack": "^5.74.0",
190
+ "webpack-bundle-analyzer": "^4.6.1",
189
191
  "webpack-clean": "^1.2.5",
190
192
  "webpack-cli": "^4.10.0",
191
193
  "webpack-common-shake": "^2.1.0",
192
- "webpack-dev-server": "^4.9.3",
194
+ "webpack-dev-server": "^4.11.1",
193
195
  "webpack-merge": "^5.8.0",
194
196
  "webpackbar": "^5.0.2",
195
197
  "write-file-webpack-plugin": "^4.5.1"
@@ -142,7 +142,9 @@ export default {
142
142
  },
143
143
 
144
144
  /**
145
- * Get or set single config option value.
145
+ * Get or set config option value.
146
+ * - **NOTE:** for without parameter occasion
147
+ * - will return all specified generation options object only. (will exclude any other options not specified at the initialization)
146
148
  * @function config
147
149
  * @instance
148
150
  * @memberof Chart
@@ -152,9 +154,13 @@ export default {
152
154
  * - **NOTE:** Doesn't guarantee work in all circumstances. It can be applied for limited options only.
153
155
  * @returns {*}
154
156
  * @example
157
+ *
155
158
  * // Getter
156
159
  * chart.config("gauge.max");
157
160
  *
161
+ * // without any arguments, it returns generation config object
162
+ * chart.config(); // {data: { ... }, axis: { ... }, ...}
163
+ *
158
164
  * // Setter
159
165
  * chart.config("gauge.max", 100);
160
166
  *
@@ -163,11 +169,11 @@ export default {
163
169
  */
164
170
  config(name: string, value?: any, redraw?: boolean): any {
165
171
  const $$ = this.internal;
166
- const {config} = $$;
172
+ const {config, state} = $$;
167
173
  const key = name?.replace(/\./g, "_");
168
174
  let res;
169
175
 
170
- if (key in config) {
176
+ if (name && key in config) {
171
177
  if (isDefined(value)) {
172
178
  config[key] = value;
173
179
  res = value;
@@ -176,6 +182,8 @@ export default {
176
182
  } else {
177
183
  res = config[key];
178
184
  }
185
+ } else {
186
+ res = state.orgConfig;
179
187
  }
180
188
 
181
189
  return res;
@@ -18,7 +18,7 @@ export default {
18
18
  * ["data1", "data2"]
19
19
  * ]);
20
20
  */
21
- groups(groups: string[][]): string[][] {
21
+ groups<T = string[][]>(groups: T): T {
22
22
  const $$ = this.internal;
23
23
  const {config} = $$;
24
24
 
@@ -239,11 +239,11 @@ export default class AxisRenderer {
239
239
  * @private
240
240
  */
241
241
  getGeneratedTicks(count: number): (Date|number)[] {
242
- const len = this.generatedTicks.length - 1;
242
+ const len = this.generatedTicks?.length - 1;
243
243
  let res = this.generatedTicks;
244
244
 
245
245
  if (len > count) {
246
- const interval = Math.round((len / count) - 0.1);
246
+ const interval = Math.round((len / count) + 0.1);
247
247
 
248
248
  res = this.generatedTicks
249
249
  .map((v, i) => (i % interval === 0 ? v : null))
@@ -44,7 +44,7 @@ import text from "./internals/text";
44
44
  import title from "./internals/title";
45
45
  import tooltip from "./internals/tooltip";
46
46
  import transform from "./internals/transform";
47
- import type from "./internals/type";
47
+ import typeInternals from "./internals/type";
48
48
 
49
49
  /**
50
50
  * Internal chart class.
@@ -468,8 +468,9 @@ export default class ChartInternal {
468
468
  }
469
469
 
470
470
  // Define g for chart area
471
- main.append("g").attr("class", $COMMON.chart)
472
- .attr("clip-path", state.clip.path);
471
+ main.append("g")
472
+ .classed($COMMON.chart, true)
473
+ .attr("clip-path", hasAxis ? state.clip.path : null);
473
474
 
474
475
  $$.callPluginHook("$init");
475
476
 
@@ -807,5 +808,5 @@ extend(ChartInternal.prototype, [
807
808
  title,
808
809
  tooltip,
809
810
  transform,
810
- type
811
+ typeInternals
811
812
  ]);
@@ -199,7 +199,7 @@ export default {
199
199
  t.values.forEach((v, i) => (v.index = i));
200
200
 
201
201
  // this needs to be sorted because its index and value.index is identical
202
- $$.data.xs[t.id].sort((v1, v2) => v1 - v2);
202
+ $$.data.xs[t.id]?.sort((v1, v2) => v1 - v2);
203
203
  });
204
204
 
205
205
  // cache information about values
@@ -103,7 +103,10 @@ export default {
103
103
  }
104
104
 
105
105
  return function(d: IDataRow | IArcData | string): string {
106
- const id: string = (d as IDataRow).id || (d as IArcData).data?.id || d as string;
106
+ const id: string = (d as IDataRow).id ||
107
+ (d as IArcData).data?.id ||
108
+ d as string;
109
+
107
110
  const isLine = $$.isTypeOf(id, ["line", "spline", "step"]) || !config.data_types[id];
108
111
  let color;
109
112
 
@@ -136,7 +136,6 @@ export default {
136
136
  const {axis, config, scale, state, $el: {grid, main}} = $$;
137
137
  const isRotated = config.axis_rotated;
138
138
  const pos = d => Math.ceil(scale.y(d));
139
-
140
139
  const gridValues =
141
140
  axis.y.getGeneratedTicks(config.grid_y_ticks) || $$.scale.y.ticks(config.grid_y_ticks);
142
141
 
@@ -606,10 +606,11 @@ export default {
606
606
 
607
607
  const getColor = id => {
608
608
  const data = $$.getDataById(id);
609
-
610
- return $$.levelColor ?
609
+ const color = $$.levelColor ?
611
610
  $$.levelColor(data.values[0].value) :
612
611
  $$.color(data);
612
+
613
+ return color;
613
614
  };
614
615
 
615
616
  const usePoint = config.legend_usePoint;
@@ -45,7 +45,7 @@ export default {
45
45
 
46
46
  // determine radius
47
47
  state.radiusExpanded = Math.min(state.arcWidth, state.arcHeight) / 2 * (
48
- $$.hasMultiArcGauge() ? 0.85 : 1
48
+ $$.hasMultiArcGauge() && config.gauge_label_show ? 0.85 : 1
49
49
  );
50
50
 
51
51
  state.radius = state.radiusExpanded * 0.95;
@@ -6,6 +6,7 @@ import type {DataRow} from "../../../types/types";
6
6
  import {$BAR, $COMMON} from "../../config/classes";
7
7
  import {getRandom, isNumber} from "../../module/util";
8
8
  import type {IDataRow} from "../data/IData";
9
+ import type {IOffset} from "./shape";
9
10
 
10
11
  type BarTypeDataRow = DataRow<number | number[]>;
11
12
 
@@ -234,7 +235,7 @@ export default {
234
235
  const {config} = $$;
235
236
  const axis = isSub ? $$.axis.subX : $$.axis.x;
236
237
  const barTargetsNum = $$.getIndicesMax(barIndices) + 1;
237
- const barW = $$.getBarW("bar", axis, barTargetsNum);
238
+ const barW: IOffset = $$.getBarW("bar", axis, barTargetsNum);
238
239
  const barX = $$.getShapeX(barW, barIndices, !!isSub);
239
240
  const barY = $$.getShapeY(!!isSub);
240
241
  const barOffset = $$.getShapeOffset($$.isBarType, barIndices, !!isSub);
@@ -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)) {
@@ -45,7 +45,11 @@ export default {
45
45
 
46
46
  // Areas
47
47
  if ($$.hasTypeOf("Area")) {
48
- $$.initArea(!area && mainLineEnter.empty() ? mainLineUpdate : mainLineEnter);
48
+ const mainLine = (
49
+ !area && mainLineEnter.empty() ? mainLineUpdate : mainLineEnter
50
+ ).filter($$.isAreaType.bind($$));
51
+
52
+ $$.initArea(mainLine);
49
53
  }
50
54
 
51
55
  $$.updateTargetForCircle(targets, mainLineEnter);
@@ -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;
@@ -305,6 +318,7 @@ export default {
305
318
  getShapeOffset(typeFilter, indices, isSub?: boolean): Function {
306
319
  const $$ = this;
307
320
  const {shapeOffsetTargets, indexMapByTargetId} = $$.getShapeOffsetData(typeFilter);
321
+ const groupsZeroAs = $$.config.data_groupsZeroAs;
308
322
 
309
323
  return (d, idx) => {
310
324
  const {id, value, x} = d;
@@ -316,18 +330,18 @@ export default {
316
330
  return scale(value[0]);
317
331
  }
318
332
 
319
- const y0 = scale($$.getShapeYMin(id));
320
-
321
333
  const dataXAsNumber = Number(x);
334
+ const y0 = scale(groupsZeroAs === "zero" ? 0 : $$.getShapeYMin(id));
322
335
  let offset = y0;
323
336
 
324
337
  shapeOffsetTargets
325
- .filter(t => t.id !== id)
338
+ .filter(t => t.id !== id && ind[t.id] === ind[id])
326
339
  .forEach(t => {
327
340
  const {id: tid, rowValueMapByXValue, rowValues, values: tvalues} = t;
328
341
 
329
342
  // for same stacked group (ind[tid] === ind[id])
330
- if (ind[tid] === ind[id] && indexMapByTargetId[tid] < indexMapByTargetId[id]) {
343
+ if (indexMapByTargetId[tid] < indexMapByTargetId[id]) {
344
+ const rValue = tvalues[dataXAsNumber];
331
345
  let row = rowValues[idx];
332
346
 
333
347
  // check if the x values line up
@@ -335,8 +349,15 @@ export default {
335
349
  row = rowValueMapByXValue[dataXAsNumber];
336
350
  }
337
351
 
338
- if (row?.value * value >= 0 && isNumber(tvalues[dataXAsNumber])) {
339
- offset += scale(tvalues[dataXAsNumber]) - y0;
352
+ if (row?.value * value >= 0 && isNumber(rValue)) {
353
+ const addOffset = value === 0 ? (
354
+ (groupsZeroAs === "positive" && rValue > 0) ||
355
+ (groupsZeroAs === "negative" && rValue < 0)
356
+ ) : true;
357
+
358
+ if (addOffset) {
359
+ offset += scale(rValue) - y0;
360
+ }
340
361
  }
341
362
  }
342
363
  });
@@ -345,7 +366,7 @@ export default {
345
366
  };
346
367
  },
347
368
 
348
- getBarW(type, axis, targetsNum: number): number {
369
+ getBarW(type, axis, targetsNum: number): number | IOffset {
349
370
  const $$ = this;
350
371
  const {config, org, scale} = $$;
351
372
  const maxDataCount = $$.getMaxDataCount();
@@ -23,7 +23,7 @@ export default {
23
23
  * @property {boolean} [y.show=false] Show grids along x axis.
24
24
  * @property {Array} [y.lines=[]] Show additional grid lines along y axis.<br>
25
25
  * This option accepts array including object that has value, text, position and class.
26
- * @property {number} [y.ticks=10] Number of y grids to be shown.
26
+ * @property {number} [y.ticks=undefined] Number of y grids to be shown.
27
27
  * @property {object} focus Grid focus object
28
28
  * @property {boolean} [focus.edge=false] Show edged focus grid line.<br>**NOTE:** Available when [`tooltip.grouped=false`](#.tooltip) option is set.
29
29
  * @property {boolean} [focus.show=true] Show grid line when focus.
@@ -71,7 +71,7 @@ export default {
71
71
  grid_x_lines: <Lines> [],
72
72
  grid_y_show: false,
73
73
  grid_y_lines: <Lines> [],
74
- grid_y_ticks: 10,
74
+ grid_y_ticks: <number|undefined> undefined,
75
75
  grid_focus_edge: false,
76
76
  grid_focus_show: true,
77
77
  grid_focus_y: false,
@@ -16,7 +16,8 @@ export default {
16
16
  * @property {boolean} [legend.hide=false] Hide legend
17
17
  * If true given, all legend will be hidden. If string or array given, only the legend that has the id will be hidden.
18
18
  * @property {string|HTMLElement} [legend.contents.bindto=undefined] Set CSS selector or element reference to bind legend items.
19
- * @property {string|Function} [legend.contents.template=undefined] Set item's template.<br>
19
+ * - **NOTE:** Should be used along with `legend.contents.template`.
20
+ * @property {string|Function} [legend.contents.template="<span style='color:#fff;padding:5px;background-color:{=COLOR}'>{=TITLE}</span>"] Set item's template.<br>
20
21
  * - If set `string` value, within template the 'color' and 'title' can be replaced using template-like syntax string:
21
22
  * - {=COLOR}: data color value
22
23
  * - {=TITLE}: data title value
@@ -94,7 +95,7 @@ export default {
94
95
  legend_show: true,
95
96
  legend_hide: false,
96
97
  legend_contents_bindto: <string|HTMLElement|undefined> undefined,
97
- legend_contents_template: <string|(() => string)|undefined>undefined,
98
+ legend_contents_template: <string|(() => string)|undefined> "<span style='color:#fff;padding:5px;background-color:{=COLOR}'>{=TITLE}</span>",
98
99
  legend_position: <"bottom"|"right"|"inset"> "bottom",
99
100
  legend_inset_anchor: <"top-left"|"top-right"|"bottom-left"|"bottom-right"> "top-left",
100
101
  legend_inset_x: 10,
@@ -257,6 +257,24 @@ export default {
257
257
  */
258
258
  data_groups: <string[][]> [],
259
259
 
260
+ /**
261
+ * Set how zero value will be treated on groups.<br>
262
+ * Possible values:
263
+ * - `zero`: 0 will be positioned at absolute axis zero point.
264
+ * - `positive`: 0 will be positioned at the top of a stack.
265
+ * - `negative`: 0 will be positioned at the bottom of a stack.
266
+ * @name data․groupsZeroAs
267
+ * @memberof Options
268
+ * @type {string}
269
+ * @default "positive"
270
+ * @see [Demo](https://naver.github.io/billboard.js/demo/#Data.Groups)
271
+ * @example
272
+ * data: {
273
+ * groupsZeroAs: "zero" // "positive" or "negative"
274
+ * }
275
+ */
276
+ data_groupsZeroAs: <"zero" | "positive" | "negative"> "positive",
277
+
260
278
  /**
261
279
  * Set color converter function.<br><br>
262
280
  * This option should a function and the specified function receives color (e.g. '#ff0000') and d that has data parameters like id, value, index, etc. And it must return a string that represents color (e.g. '#00ff00').
@@ -14,6 +14,7 @@ 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} [bar.overlap=false] Bars will be rendered at same position, which will be overlapped each other. (for non-grouped bars only)
17
18
  * @property {number} [bar.padding=0] The padding pixel value between each bar.
18
19
  * @property {number} [bar.radius] Set the radius of bar edge in pixel.
19
20
  * @property {number} [bar.radius.ratio] Set the radius ratio of bar edge in relative the bar's width.
@@ -29,6 +30,7 @@ export default {
29
30
  * @property {number} [bar.width.dataname.max] The maximum width value for ratio.
30
31
  * @property {boolean} [bar.zerobased=true] Set if min or max value will be 0 on bar chart.
31
32
  * @see [Demo: bar indices](https://naver.github.io/billboard.js/demo/#BarChartOptions.BarIndices)
33
+ * @see [Demo: bar overlap](https://naver.github.io/billboard.js/demo/#BarChartOptions.BarOverlap)
32
34
  * @see [Demo: bar padding](https://naver.github.io/billboard.js/demo/#BarChartOptions.BarPadding)
33
35
  * @see [Demo: bar radius](https://naver.github.io/billboard.js/demo/#BarChartOptions.BarRadius)
34
36
  * @see [Demo: bar width](https://naver.github.io/billboard.js/demo/#BarChartOptions.BarWidth)
@@ -40,6 +42,9 @@ export default {
40
42
  * removeNull: true
41
43
  * },
42
44
  *
45
+ * // remove nullish da
46
+ * overlap: true,
47
+ *
43
48
  * padding: 1,
44
49
  *
45
50
  * // bar radius
@@ -80,6 +85,7 @@ export default {
80
85
  */
81
86
  bar_label_threshold: 0,
82
87
  bar_indices_removeNull: false,
88
+ bar_overlap: false,
83
89
  bar_padding: 0,
84
90
  bar_radius: <number|{ratio: number}|undefined> undefined,
85
91
  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
  }