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.
- package/README.md +11 -4
- package/dist/billboard.css +1 -1
- package/dist/billboard.js +3901 -1451
- package/dist/billboard.min.css +1 -1
- package/dist/billboard.min.js +2 -2
- package/dist/billboard.pkgd.js +8350 -5297
- package/dist/billboard.pkgd.min.js +3 -2
- package/dist/plugin/billboardjs-plugin-bubblecompare.js +29 -13
- package/dist/plugin/billboardjs-plugin-bubblecompare.min.js +2 -2
- package/dist/plugin/billboardjs-plugin-sparkline.js +377 -92
- package/dist/plugin/billboardjs-plugin-sparkline.min.js +2 -2
- package/dist/plugin/billboardjs-plugin-stanford.js +447 -109
- package/dist/plugin/billboardjs-plugin-stanford.min.js +2 -2
- package/dist/plugin/billboardjs-plugin-tableview.js +341 -74
- package/dist/plugin/billboardjs-plugin-tableview.min.js +2 -2
- package/dist/plugin/billboardjs-plugin-textoverlap.js +337 -75
- package/dist/plugin/billboardjs-plugin-textoverlap.min.js +2 -2
- package/dist/plugin/pkgd/billboardjs-plugin-bubblecompare.js +4233 -3792
- package/dist/plugin/pkgd/billboardjs-plugin-sparkline.js +4635 -3889
- package/dist/plugin/pkgd/billboardjs-plugin-stanford.js +4823 -3937
- package/dist/plugin/pkgd/billboardjs-plugin-tableview.js +4594 -3866
- package/dist/plugin/pkgd/billboardjs-plugin-textoverlap.js +4606 -3874
- package/dist/theme/datalab.css +1 -1
- package/dist/theme/datalab.min.css +1 -1
- package/dist/theme/graph.css +1 -1
- package/dist/theme/graph.min.css +1 -1
- package/dist/theme/insight.css +1 -1
- package/dist/theme/insight.min.css +1 -1
- package/dist-esm/billboard.js +796 -387
- package/dist-esm/plugin/billboardjs-plugin-bubblecompare.js +47 -75
- package/dist-esm/plugin/billboardjs-plugin-sparkline.js +68 -86
- package/dist-esm/plugin/billboardjs-plugin-stanford.js +52 -77
- package/dist-esm/plugin/billboardjs-plugin-tableview.js +49 -76
- package/dist-esm/plugin/billboardjs-plugin-textoverlap.js +49 -76
- package/package.json +40 -40
- package/src/Chart/api/chart.ts +4 -1
- package/src/Chart/api/data.ts +2 -2
- package/src/Chart/api/flow.ts +125 -115
- package/src/ChartInternal/Axis/AxisRenderer.ts +29 -3
- package/src/ChartInternal/ChartInternal.ts +55 -18
- package/src/ChartInternal/data/IData.ts +2 -2
- package/src/ChartInternal/data/convert.helper.ts +226 -0
- package/src/ChartInternal/data/convert.ts +43 -210
- package/src/ChartInternal/data/load.ts +5 -4
- package/src/ChartInternal/interactions/zoom.ts +17 -4
- package/src/ChartInternal/internals/color.ts +59 -36
- package/src/ChartInternal/internals/grid.ts +5 -3
- package/src/ChartInternal/internals/redraw.ts +5 -2
- package/src/ChartInternal/internals/scale.ts +3 -1
- package/src/ChartInternal/internals/size.axis.ts +5 -2
- package/src/ChartInternal/internals/text.ts +118 -17
- package/src/ChartInternal/shape/area.ts +14 -7
- package/src/ChartInternal/shape/bar.ts +19 -10
- package/src/ChartInternal/shape/point.ts +15 -9
- package/src/ChartInternal/shape/polar.ts +1 -1
- package/src/Plugin/sparkline/index.ts +22 -11
- package/src/Plugin/stanford/index.ts +10 -7
- package/src/Plugin/textoverlap/index.ts +4 -1
- package/src/config/Options/Options.ts +2 -0
- package/src/config/Options/common/boost.ts +31 -0
- package/src/config/Options/common/main.ts +15 -1
- package/src/config/Options/common/tooltip.ts +1 -1
- package/src/config/Options/data/data.ts +11 -3
- package/src/config/Options/shape/area.ts +6 -1
- package/src/config/Store/State.ts +3 -0
- package/src/module/browser.ts +2 -1
- package/src/module/generator.ts +18 -16
- package/src/module/util.ts +115 -1
- package/types/chart.d.ts +2 -2
- package/types/options.d.ts +45 -8
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2017 ~ present NAVER Corp.
|
|
3
|
+
* billboard.js project is licensed under the MIT license
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/* eslint-disable */
|
|
7
|
+
import {
|
|
8
|
+
csvParse as d3CsvParse,
|
|
9
|
+
tsvParse as d3TsvParse,
|
|
10
|
+
csvParseRows as d3CsvParseRows,
|
|
11
|
+
tsvParseRows as d3TsvParseRows,
|
|
12
|
+
} from "d3-dsv";
|
|
13
|
+
|
|
14
|
+
export {columns, json, rows, url, csv, tsv};
|
|
15
|
+
|
|
16
|
+
/***** Functions to be executed on Web Worker *****
|
|
17
|
+
* NOTE: Don't allowed to use
|
|
18
|
+
* - arrow function syntax
|
|
19
|
+
* - Utils functions
|
|
20
|
+
*/
|
|
21
|
+
/**
|
|
22
|
+
* Convert Columns data
|
|
23
|
+
* @param {object} columns
|
|
24
|
+
* @returns {Array}
|
|
25
|
+
* @private
|
|
26
|
+
*/
|
|
27
|
+
function columns(columns) {
|
|
28
|
+
const newRows: any[] = [];
|
|
29
|
+
|
|
30
|
+
columns.forEach(function(col, i) {
|
|
31
|
+
const key = col[0];
|
|
32
|
+
|
|
33
|
+
col.forEach(function(v, j) {
|
|
34
|
+
if (j > 0) {
|
|
35
|
+
if (typeof newRows[j - 1] === "undefined") {
|
|
36
|
+
newRows[j - 1] = {};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (typeof v === "undefined") {
|
|
40
|
+
throw new Error(`Source data is missing a component at (${i}, ${j})!`);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
newRows[j - 1][key] = v;
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
return newRows;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Convert Rows data
|
|
53
|
+
* @param {object} columns
|
|
54
|
+
* @returns {Array}
|
|
55
|
+
* @private
|
|
56
|
+
*/
|
|
57
|
+
function rows(rows) {
|
|
58
|
+
const keys = rows[0];
|
|
59
|
+
const newRows: any[] = [];
|
|
60
|
+
|
|
61
|
+
rows.forEach(function(row, i) {
|
|
62
|
+
if (i > 0) {
|
|
63
|
+
const newRow = {};
|
|
64
|
+
|
|
65
|
+
row.forEach(function(v, j) {
|
|
66
|
+
if (typeof v === "undefined") {
|
|
67
|
+
throw new Error(`Source data is missing a component at (${i}, ${j})!`);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
newRow[keys[j]] = v;
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
newRows.push(newRow);
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
return newRows;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Convert JSON data
|
|
82
|
+
* @param {object} columns
|
|
83
|
+
* @returns {Array}
|
|
84
|
+
* @private
|
|
85
|
+
*/
|
|
86
|
+
function json(json, keysParam) {
|
|
87
|
+
const newRows: string[][] = [];
|
|
88
|
+
const findValueInJson = function(object, path) {
|
|
89
|
+
if (object[path] !== undefined) {
|
|
90
|
+
return object[path];
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const convertedPath = path.replace(/\[(\w+)\]/g, ".$1"); // convert indexes to properties (replace [] with .)
|
|
94
|
+
const pathArray = convertedPath.replace(/^\./, "").split("."); // strip a leading dot
|
|
95
|
+
let target = object;
|
|
96
|
+
|
|
97
|
+
pathArray.some(function(k) {
|
|
98
|
+
return !(
|
|
99
|
+
target = target && k in target ?
|
|
100
|
+
target[k] : undefined
|
|
101
|
+
);
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
return target;
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
let targetKeys: string[];
|
|
108
|
+
let data;
|
|
109
|
+
|
|
110
|
+
if (Array.isArray(json)) {
|
|
111
|
+
if (keysParam.x) {
|
|
112
|
+
targetKeys = keysParam.value.concat(keysParam.x);
|
|
113
|
+
} else {
|
|
114
|
+
targetKeys = keysParam.value;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
newRows.push(targetKeys);
|
|
118
|
+
|
|
119
|
+
json.forEach(function(o) {
|
|
120
|
+
const newRow = targetKeys.map(function(key) {
|
|
121
|
+
// convert undefined to null because undefined data will be removed in convertDataToTargets()
|
|
122
|
+
let v = findValueInJson(o, key);
|
|
123
|
+
|
|
124
|
+
if (typeof v === "undefined") {
|
|
125
|
+
v = null;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return v;
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
newRows.push(newRow);
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
data = rows(newRows);
|
|
135
|
+
} else {
|
|
136
|
+
Object.keys(json).forEach(function(key) {
|
|
137
|
+
const tmp = json[key].concat();
|
|
138
|
+
|
|
139
|
+
tmp.unshift(key);
|
|
140
|
+
newRows.push(tmp);
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
data = columns(newRows);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
return data;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/***** Functions can't be executed on Web Worker *****/
|
|
150
|
+
/**
|
|
151
|
+
* Convert URL data
|
|
152
|
+
* @param {string} url Remote URL
|
|
153
|
+
* @param {string} mimeType MIME type string: json | csv | tsv
|
|
154
|
+
* @param {object} headers Header object
|
|
155
|
+
* @param {object} keys Key object
|
|
156
|
+
* @param {Function} done Callback function
|
|
157
|
+
* @private
|
|
158
|
+
*/
|
|
159
|
+
function url(url: string, mimeType = "csv", headers: object, keys: object, done: Function): void {
|
|
160
|
+
const req = new XMLHttpRequest();
|
|
161
|
+
const converter = {csv, tsv, json};
|
|
162
|
+
|
|
163
|
+
req.open("GET", url);
|
|
164
|
+
|
|
165
|
+
if (headers) {
|
|
166
|
+
Object.keys(headers).forEach(function(key) {
|
|
167
|
+
req.setRequestHeader(key, headers[key]);
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
req.onreadystatechange = function() {
|
|
172
|
+
if (req.readyState === 4) {
|
|
173
|
+
if (req.status === 200) {
|
|
174
|
+
const response = req.responseText;
|
|
175
|
+
|
|
176
|
+
response && done.call(this,
|
|
177
|
+
converter[mimeType](
|
|
178
|
+
mimeType === "json" ? JSON.parse(response) : response,
|
|
179
|
+
keys
|
|
180
|
+
));
|
|
181
|
+
} else {
|
|
182
|
+
throw new Error(`${url}: Something went wrong loading!`);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
req.send();
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Convert CSV/TSV data
|
|
192
|
+
* @param {object} parser Parser object
|
|
193
|
+
* @param {object} xsv Data
|
|
194
|
+
* @returns {object}
|
|
195
|
+
* @private
|
|
196
|
+
*/
|
|
197
|
+
function convertCsvTsvToData(parser, xsv) {
|
|
198
|
+
const rows = parser.rows(xsv);
|
|
199
|
+
let d;
|
|
200
|
+
|
|
201
|
+
if (rows.length === 1) {
|
|
202
|
+
d = [{}];
|
|
203
|
+
|
|
204
|
+
rows[0].forEach(id => {
|
|
205
|
+
d[0][id] = null;
|
|
206
|
+
});
|
|
207
|
+
} else {
|
|
208
|
+
d = parser.parse(xsv);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
return d;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
function csv(xsv) {
|
|
215
|
+
return convertCsvTsvToData({
|
|
216
|
+
rows: d3CsvParseRows,
|
|
217
|
+
parse: d3CsvParse
|
|
218
|
+
}, xsv);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
function tsv(tsv) {
|
|
222
|
+
return convertCsvTsvToData({
|
|
223
|
+
rows: d3TsvParseRows,
|
|
224
|
+
parse: d3TsvParse
|
|
225
|
+
}, tsv);
|
|
226
|
+
}
|
|
@@ -2,13 +2,26 @@
|
|
|
2
2
|
* Copyright (c) 2017 ~ present NAVER Corp.
|
|
3
3
|
* billboard.js project is licensed under the MIT license
|
|
4
4
|
*/
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
5
|
+
import {runWorker, isUndefined, isDefined, isObject, isValue, notEmpty, isArray} from "../../module/util";
|
|
6
|
+
import {columns, json, rows, url} from "./convert.helper";
|
|
7
|
+
import {IData} from "../data/IData";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Get data key for JSON
|
|
11
|
+
* @param {string|object} keysParam Key params
|
|
12
|
+
* @param {object} config Config object
|
|
13
|
+
* @returns {string} Data key
|
|
14
|
+
* @private
|
|
15
|
+
*/
|
|
16
|
+
function getDataKeyForJson(keysParam, config) {
|
|
17
|
+
const keys = keysParam || config?.data_keys;
|
|
18
|
+
|
|
19
|
+
if (keys?.x) {
|
|
20
|
+
config.data_x = keys.x;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return keys;
|
|
24
|
+
}
|
|
12
25
|
|
|
13
26
|
/**
|
|
14
27
|
* Data convert
|
|
@@ -20,11 +33,12 @@ export default {
|
|
|
20
33
|
* Convert data according its type
|
|
21
34
|
* @param {object} args data object
|
|
22
35
|
* @param {Function} [callback] callback for url(XHR) type loading
|
|
23
|
-
* @returns {object}
|
|
24
36
|
* @private
|
|
25
37
|
*/
|
|
26
|
-
convertData(args, callback: Function):
|
|
27
|
-
|
|
38
|
+
convertData(args, callback: Function): void {
|
|
39
|
+
const {config} = this;
|
|
40
|
+
const useWorker = config.boost_useWorker;
|
|
41
|
+
let data = args;
|
|
28
42
|
|
|
29
43
|
if (args.bindto) {
|
|
30
44
|
data = {};
|
|
@@ -37,215 +51,28 @@ export default {
|
|
|
37
51
|
data[v] = args[key];
|
|
38
52
|
}
|
|
39
53
|
});
|
|
40
|
-
} else {
|
|
41
|
-
data = args;
|
|
42
54
|
}
|
|
43
55
|
|
|
44
56
|
if (data.url && callback) {
|
|
45
|
-
|
|
57
|
+
url(data.url, data.mimeType, data.headers,
|
|
58
|
+
getDataKeyForJson(data.keys, config),
|
|
59
|
+
callback
|
|
60
|
+
);
|
|
46
61
|
} else if (data.json) {
|
|
47
|
-
|
|
62
|
+
runWorker(useWorker, json, callback, [columns, rows])(
|
|
63
|
+
data.json,
|
|
64
|
+
getDataKeyForJson(data.keys, config)
|
|
65
|
+
);
|
|
48
66
|
} else if (data.rows) {
|
|
49
|
-
|
|
67
|
+
runWorker(useWorker, rows, callback)(data.rows);
|
|
50
68
|
} else if (data.columns) {
|
|
51
|
-
|
|
69
|
+
runWorker(useWorker, columns, callback)(data.columns);
|
|
52
70
|
} else if (args.bindto) {
|
|
53
71
|
throw Error("url or json or rows or columns is required.");
|
|
54
72
|
}
|
|
55
|
-
|
|
56
|
-
return isArray(data) && data;
|
|
57
|
-
},
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Convert URL data
|
|
61
|
-
* @param {string} url Remote URL
|
|
62
|
-
* @param {string} mimeType MIME type string: json | csv | tsv
|
|
63
|
-
* @param {object} headers Header object
|
|
64
|
-
* @param {object} keys Key object
|
|
65
|
-
* @param {Function} done Callback function
|
|
66
|
-
* @private
|
|
67
|
-
*/
|
|
68
|
-
convertUrlToData(url: string, mimeType = "csv", headers: object, keys: object, done: Function): void {
|
|
69
|
-
const req = new XMLHttpRequest();
|
|
70
|
-
|
|
71
|
-
req.open("GET", url);
|
|
72
|
-
|
|
73
|
-
if (headers) {
|
|
74
|
-
Object.keys(headers).forEach(key => {
|
|
75
|
-
req.setRequestHeader(key, headers[key]);
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
req.onreadystatechange = () => {
|
|
80
|
-
if (req.readyState === 4) {
|
|
81
|
-
if (req.status === 200) {
|
|
82
|
-
const response = req.responseText;
|
|
83
|
-
|
|
84
|
-
response && done.call(this,
|
|
85
|
-
this[`convert${capitalize(mimeType)}ToData`](
|
|
86
|
-
mimeType === "json" ? JSON.parse(response) : response,
|
|
87
|
-
keys
|
|
88
|
-
));
|
|
89
|
-
} else {
|
|
90
|
-
throw new Error(`${url}: Something went wrong loading!`);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
req.send();
|
|
96
|
-
},
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* Convert CSV/TSV data
|
|
100
|
-
* @param {object} parser Parser object
|
|
101
|
-
* @param {object} xsv Data
|
|
102
|
-
* @private
|
|
103
|
-
* @returns {object}
|
|
104
|
-
*/
|
|
105
|
-
convertCsvTsvToData(parser, xsv) {
|
|
106
|
-
const rows = parser.rows(xsv);
|
|
107
|
-
let d;
|
|
108
|
-
|
|
109
|
-
if (rows.length === 1) {
|
|
110
|
-
d = [{}];
|
|
111
|
-
|
|
112
|
-
rows[0].forEach(id => {
|
|
113
|
-
d[0][id] = null;
|
|
114
|
-
});
|
|
115
|
-
} else {
|
|
116
|
-
d = parser.parse(xsv);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
return d;
|
|
120
|
-
},
|
|
121
|
-
|
|
122
|
-
convertCsvToData(xsv) {
|
|
123
|
-
return this.convertCsvTsvToData({
|
|
124
|
-
rows: d3CsvParseRows,
|
|
125
|
-
parse: d3CsvParse
|
|
126
|
-
}, xsv);
|
|
127
|
-
},
|
|
128
|
-
|
|
129
|
-
convertTsvToData(tsv) {
|
|
130
|
-
return this.convertCsvTsvToData({
|
|
131
|
-
rows: d3TsvParseRows,
|
|
132
|
-
parse: d3TsvParse
|
|
133
|
-
}, tsv);
|
|
134
|
-
},
|
|
135
|
-
|
|
136
|
-
convertJsonToData(json, keysParam) {
|
|
137
|
-
const {config} = this;
|
|
138
|
-
const newRows: string[][] = [];
|
|
139
|
-
let targetKeys: string[];
|
|
140
|
-
let data;
|
|
141
|
-
|
|
142
|
-
if (isArray(json)) {
|
|
143
|
-
const keys = keysParam || config.data_keys;
|
|
144
|
-
|
|
145
|
-
if (keys.x) {
|
|
146
|
-
targetKeys = keys.value.concat(keys.x);
|
|
147
|
-
config.data_x = keys.x;
|
|
148
|
-
} else {
|
|
149
|
-
targetKeys = keys.value;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
newRows.push(targetKeys);
|
|
153
|
-
|
|
154
|
-
json.forEach(o => {
|
|
155
|
-
const newRow = targetKeys.map(key => {
|
|
156
|
-
// convert undefined to null because undefined data will be removed in convertDataToTargets()
|
|
157
|
-
let v = this.findValueInJson(o, key);
|
|
158
|
-
|
|
159
|
-
if (isUndefined(v)) {
|
|
160
|
-
v = null;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
return v;
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
newRows.push(newRow);
|
|
167
|
-
});
|
|
168
|
-
|
|
169
|
-
data = this.convertRowsToData(newRows);
|
|
170
|
-
} else {
|
|
171
|
-
Object.keys(json).forEach(key => {
|
|
172
|
-
const tmp = json[key].concat();
|
|
173
|
-
|
|
174
|
-
tmp.unshift(key);
|
|
175
|
-
newRows.push(tmp);
|
|
176
|
-
});
|
|
177
|
-
|
|
178
|
-
data = this.convertColumnsToData(newRows);
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
return data;
|
|
182
|
-
},
|
|
183
|
-
|
|
184
|
-
findValueInJson(object, path) {
|
|
185
|
-
if (object[path] !== undefined) {
|
|
186
|
-
return object[path];
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
const convertedPath = path.replace(/\[(\w+)\]/g, ".$1"); // convert indexes to properties (replace [] with .)
|
|
190
|
-
const pathArray = convertedPath.replace(/^\./, "").split("."); // strip a leading dot
|
|
191
|
-
let target = object;
|
|
192
|
-
|
|
193
|
-
pathArray.some(k => !(
|
|
194
|
-
target = target && k in target ?
|
|
195
|
-
target[k] : undefined
|
|
196
|
-
));
|
|
197
|
-
|
|
198
|
-
return target;
|
|
199
|
-
},
|
|
200
|
-
|
|
201
|
-
convertRowsToData(rows) {
|
|
202
|
-
const keys = rows[0];
|
|
203
|
-
const newRows: any[] = [];
|
|
204
|
-
|
|
205
|
-
rows.forEach((row, i) => {
|
|
206
|
-
if (i > 0) {
|
|
207
|
-
const newRow = {};
|
|
208
|
-
|
|
209
|
-
row.forEach((v, j) => {
|
|
210
|
-
if (isUndefined(v)) {
|
|
211
|
-
throw new Error(`Source data is missing a component at (${i}, ${j})!`);
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
newRow[keys[j]] = v;
|
|
215
|
-
});
|
|
216
|
-
|
|
217
|
-
newRows.push(newRow);
|
|
218
|
-
}
|
|
219
|
-
});
|
|
220
|
-
|
|
221
|
-
return newRows;
|
|
222
|
-
},
|
|
223
|
-
|
|
224
|
-
convertColumnsToData(columns) {
|
|
225
|
-
const newRows: any[] = [];
|
|
226
|
-
|
|
227
|
-
columns.forEach((col, i) => {
|
|
228
|
-
const key = col[0];
|
|
229
|
-
|
|
230
|
-
col.forEach((v, j) => {
|
|
231
|
-
if (j > 0) {
|
|
232
|
-
if (isUndefined(newRows[j - 1])) {
|
|
233
|
-
newRows[j - 1] = {};
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
if (isUndefined(v)) {
|
|
237
|
-
throw new Error(`Source data is missing a component at (${i}, ${j})!`);
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
newRows[j - 1][key] = v;
|
|
241
|
-
}
|
|
242
|
-
});
|
|
243
|
-
});
|
|
244
|
-
|
|
245
|
-
return newRows;
|
|
246
73
|
},
|
|
247
74
|
|
|
248
|
-
convertDataToTargets(data, appendXs) {
|
|
75
|
+
convertDataToTargets(data: {[key:string]: number|null}[], appendXs: boolean): IData[] {
|
|
249
76
|
const $$ = this;
|
|
250
77
|
const {axis, config, state} = $$;
|
|
251
78
|
let isCategorized = false;
|
|
@@ -308,6 +135,7 @@ export default {
|
|
|
308
135
|
.every(v => config.axis_x_categories.indexOf(v) > -1);
|
|
309
136
|
|
|
310
137
|
// when .load() with 'append' option is used for indexed axis
|
|
138
|
+
// @ts-ignore
|
|
311
139
|
const isDataAppend = data.__append__;
|
|
312
140
|
const xIndex = xKey === null && isDataAppend ?
|
|
313
141
|
$$.api.data.values(id).length : 0;
|
|
@@ -344,7 +172,12 @@ export default {
|
|
|
344
172
|
x = undefined;
|
|
345
173
|
}
|
|
346
174
|
|
|
347
|
-
return {
|
|
175
|
+
return {
|
|
176
|
+
x,
|
|
177
|
+
value,
|
|
178
|
+
id: convertedId,
|
|
179
|
+
index: -1
|
|
180
|
+
};
|
|
348
181
|
}).filter(v => isDefined(v.x))
|
|
349
182
|
};
|
|
350
183
|
});
|
|
@@ -381,6 +214,6 @@ export default {
|
|
|
381
214
|
// cache as original id keyed
|
|
382
215
|
targets.forEach(d => $$.cache.add(d.id_org, d, true));
|
|
383
216
|
|
|
384
|
-
return targets;
|
|
217
|
+
return targets as IData[];
|
|
385
218
|
}
|
|
386
219
|
};
|
|
@@ -69,11 +69,12 @@ export default {
|
|
|
69
69
|
// reset internally cached data
|
|
70
70
|
$$.cache.reset();
|
|
71
71
|
|
|
72
|
-
|
|
72
|
+
$$.convertData(args, d => {
|
|
73
|
+
const data = args.data || d;
|
|
73
74
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
75
|
+
args.append && (data.__append__ = true);
|
|
76
|
+
data && $$.load($$.convertDataToTargets(data), args);
|
|
77
|
+
});
|
|
77
78
|
},
|
|
78
79
|
|
|
79
80
|
unload(rawTargetIds, customDoneCb): void {
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* billboard.js project is licensed under the MIT license
|
|
4
4
|
*/
|
|
5
5
|
import {drag as d3Drag} from "d3-drag";
|
|
6
|
-
import {zoomIdentity as d3ZoomIdentity, zoom as d3Zoom} from "d3-zoom";
|
|
6
|
+
import {zoomIdentity as d3ZoomIdentity, zoom as d3Zoom, ZoomTransform as d3ZoomTransform} from "d3-zoom";
|
|
7
7
|
import {$COMMON, $ZOOM} from "../../config/classes";
|
|
8
8
|
import {callFn, diffDomain, getPointer, isFunction} from "../../module/util";
|
|
9
9
|
|
|
@@ -75,16 +75,19 @@ export default {
|
|
|
75
75
|
/**
|
|
76
76
|
* Update scale according zoom transform value
|
|
77
77
|
* @param {object} transform transform object
|
|
78
|
+
* @param {boolean} correctTransform if the d3 transform should be updated after rescaling
|
|
78
79
|
* @private
|
|
79
80
|
*/
|
|
80
81
|
// @ts-ignore
|
|
81
|
-
zoom.updateTransformScale = (transform:
|
|
82
|
+
zoom.updateTransformScale = (transform: d3ZoomTransform, correctTransform: boolean): void => {
|
|
83
|
+
const isRotated = config.axis_rotated;
|
|
84
|
+
|
|
82
85
|
// in case of resize, update range of orgXScale
|
|
83
86
|
org.xScale?.range(scale.x.range());
|
|
84
87
|
|
|
85
88
|
// rescale from the original scale
|
|
86
89
|
const newScale = transform[
|
|
87
|
-
|
|
90
|
+
isRotated ? "rescaleY" : "rescaleX"
|
|
88
91
|
](org.xScale || scale.x);
|
|
89
92
|
|
|
90
93
|
const domain = $$.trimXDomain(newScale.domain());
|
|
@@ -92,6 +95,16 @@ export default {
|
|
|
92
95
|
|
|
93
96
|
newScale.domain(domain, org.xDomain);
|
|
94
97
|
|
|
98
|
+
// prevent chart from panning off the edge and feeling "stuck"
|
|
99
|
+
// https://github.com/naver/billboard.js/issues/2588
|
|
100
|
+
if (correctTransform) {
|
|
101
|
+
const t = newScale(scale.x.domain()[0]);
|
|
102
|
+
const tX = isRotated ? transform.x : t;
|
|
103
|
+
const tY = isRotated ? t : transform.y;
|
|
104
|
+
|
|
105
|
+
$$.$el.eventRect.property("__zoom", d3ZoomIdentity.translate(tX, tY).scale(transform.k));
|
|
106
|
+
}
|
|
107
|
+
|
|
95
108
|
if (!$$.state.xTickOffset) {
|
|
96
109
|
$$.state.xTickOffset = $$.axis.x.tickOffset();
|
|
97
110
|
}
|
|
@@ -172,7 +185,7 @@ export default {
|
|
|
172
185
|
scale.x.domain(org.xDomain);
|
|
173
186
|
}
|
|
174
187
|
|
|
175
|
-
$$.zoom.updateTransformScale(transform);
|
|
188
|
+
$$.zoom.updateTransformScale(transform, config.zoom_type === "wheel" && sourceEvent);
|
|
176
189
|
|
|
177
190
|
// do zoom transiton when:
|
|
178
191
|
// - zoom type 'drag'
|