@plotdb/chart 3.1.0 → 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.
- package/CHANGELOG.md +52 -0
- package/package.json +1 -1
- package/utils/axis.js +174 -123
- package/utils/axis.min.js +1 -1
- package/utils/config.js +19 -0
- package/utils/config.min.js +1 -1
- package/utils/legend.js +71 -3
- package/utils/legend.min.js +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,57 @@
|
|
|
1
1
|
# Change Logs
|
|
2
2
|
|
|
3
|
+
## v3.5.0
|
|
4
|
+
|
|
5
|
+
- legend: "select all / select none" text is now translated instead of hard-coded Chinese.
|
|
6
|
+
it uses the `i18n` / `t` constructor options if given, otherwise `block.i18n.module` from
|
|
7
|
+
`@plotdb/block`, so existing blocks follow the page language without changes. built-in
|
|
8
|
+
resources ( `en`, `zh-TW`, `zh-CN`, `ja` ) are in `chart.utils.legend.i18n` and are added under
|
|
9
|
+
the `@plotdb/chart.legend` namespace. legend re-renders on `languageChanged`.
|
|
10
|
+
- legend: add `destroy()` to stop listening to language change.
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
## v3.4.0
|
|
14
|
+
|
|
15
|
+
- axis: `label.strategy: ends` no longer insists on perfectly equal gaps. keeping both ends
|
|
16
|
+
and keeping every gap identical is only possible when the stride divides ( tick count - 1 ),
|
|
17
|
+
which on a twelve-month axis left nothing but the two ends. it now cuts the axis into p
|
|
18
|
+
equal spans and takes the tick nearest each cut — by coordinate, not by index, so ticks that
|
|
19
|
+
are themselves unevenly spaced still come out visually even — and accepts the result when
|
|
20
|
+
every gap is within `label.tolerance` of the average.
|
|
21
|
+
- axis: add `label.tolerance` ( default 0.2, i.e. ±20% ). 0 means only perfectly equal gaps
|
|
22
|
+
are accepted, which is the previous behaviour. on a twelve-month axis too narrow for all
|
|
23
|
+
twelve labels: 0 gives 01 / 12, 0.2 gives 01 / 05 / 08 / 12, and 0.4 gives
|
|
24
|
+
01 / 03 / 05 / 08 / 10 / 12.
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
## v3.3.0
|
|
28
|
+
|
|
29
|
+
- axis: add `label.strategy` ( `stride`, the default, or `ends` ). `stride` shows every k-th
|
|
30
|
+
label counting from the first — the most labels that fit, at the cost of the last one not
|
|
31
|
+
being guaranteed. `ends` always shows the first and the last, which is the original idea
|
|
32
|
+
the old bisecting code was after; what the old code got wrong was the spacing, not the
|
|
33
|
+
goal. keeping both ends and keeping every gap identical is only possible when the stride
|
|
34
|
+
divides ( tick count - 1 ), so `ends` picks the smallest such stride that fits. note the
|
|
35
|
+
consequence: with 12 ticks the only strides available are 1 and 11, so an axis too narrow
|
|
36
|
+
for all twelve falls straight to just the two ends. the tick pre-thinning follows the same
|
|
37
|
+
rule, so the last tick survives it under `ends`.
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
## v3.2.0
|
|
41
|
+
|
|
42
|
+
- axis: labels are thinned at a fixed stride now. the old version placed the two ends first
|
|
43
|
+
and then recursed on midpoints, keeping whatever fit — the surviving gaps came out uneven,
|
|
44
|
+
which reads as dropped labels rather than as sampling. the axis now shows every k-th label,
|
|
45
|
+
k being the smallest stride where consecutive labels still have `label.gap` between them.
|
|
46
|
+
the cost is that the last label is no longer forced on ( it used to be kept regardless,
|
|
47
|
+
which was itself a source of uneven gaps ).
|
|
48
|
+
- axis: add `label.gap` ( default 1.5, in em ). two labels count as overlapping unless this
|
|
49
|
+
much space is left between them, so labels no longer sit shoulder to shoulder.
|
|
50
|
+
- axis: implement `label.direction: vertical` for horizontal axes — labels are rotated to
|
|
51
|
+
read bottom-to-top, which usually lets every label be shown instead of thinning. the
|
|
52
|
+
config option was already declared but did nothing.
|
|
53
|
+
|
|
54
|
+
|
|
3
55
|
## v3.1.0
|
|
4
56
|
|
|
5
57
|
- add subset channel. a host ( a dashboard, say ) often has two results for the same query:
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"author":"zbryikt","name":"@plotdb/chart","license":"MIT","description":"plotdb charts","style":"index.min.css","browser":"index.min.js","main":"index.min.js","version":"3.
|
|
1
|
+
{"author":"zbryikt","name":"@plotdb/chart","license":"MIT","description":"plotdb charts","style":"index.min.css","browser":"index.min.js","main":"index.min.js","version":"3.5.0","homepage":"https://github.com/plotdb/chart","repository":{"type":"git","url":"https://github.com/plotdb/chart"},"engines":{"node":">=10.14.1","npm":">=6.4.1"},"scripts":{"start":"npx server -r web -o true -p 3457"},"devDependencies":{"@loadingio/bootstrap.ext":"^0.0.12","@loadingio/ldquery":"^3.0.6","@loadingio/loading.css":"^3.2.1","@loadingio/vscroll":"^0.0.11","@plotdb/layout":"^0.0.12","@plotdb/pdmap-world":"^0.0.5","@plotdb/semver":"^0.0.3","@plotdb/sheet":"^0.7.0","@xlfont/choose":"^0.0.32","@xlfont/load":"^2.1.5","@zbryikt/template":"^2.4.3","bootstrap":"^4.6.1","bootstrap.native":"^3.0.15","fedep":"^1.9.0","jsdom":"^22.1.0","ldbutton":"^2.0.5","ldfile":"^2.0.1","ldiconfont":"^0.2.8","ldloader":"^3.0.3","ldview":"^1.5.1","livescript":"^1.6.0","pdmaptw":"2.2.1","uglify-js":"^3.13.1","uglifycss":"^0.0.29","zmgr":"^2.2.3"},"frontendDependencies":{"root":"web/static/assets/lib","modules":["bootstrap","bootstrap.native","@loadingio/bootstrap.ext","@loadingio/ldquery","@loadingio/loading.css","@loadingio/ldcolorpicker","@loadingio/debounce.js","@loadingio/vscroll","@plotdb/pdmap-world","@plotdb/block","@plotdb/csscope","@plotdb/rescope","@plotdb/layout","@plotdb/sheet","@plotdb/konfig","@plotdb/semver","@xlfont/choose","@xlfont/load","@zbryikt/voronoijs","d3","d3-array","d3-axis","d3-brush","d3-color","d3-dispatch","d3-drag","d3-ease","d3-force","d3-force-boundary","d3-format","d3-hierarchy","d3-interpolate","d3-path","d3-quadtree","d3-random","d3-scale-chromatic","d3-selection","d3-shape","d3-timer","d3-transition","choosefont.js","pdmaptw","proxise","ldiconfont","ldloader","ldbutton","ldcover","ldcolor","ldfile","ldslider","wrap-svg-text","ldpalettepicker","zmgr","ldview"]},"dependencies":{"@loadingio/debounce.js":"^1.0.1","@loadingio/ldcolorpicker":"^3.0.5","@plotdb/block":"^5.2.2","@plotdb/csscope":"^5.0.3","@plotdb/konfig":"^4.8.12","@plotdb/rescope":"^5.0.9","@zbryikt/voronoijs":"^1.0.0","choosefont.js":"^0.0.1","d3":"^7.9.0","d3-force-boundary":"^0.0.2","ldcolor":"^1.1.3","ldcover":"^3.5.1","ldpalettepicker":"^4.0.4","ldslider":"^3.1.1","proxise":"^1.0.1","wrap-svg-text":"^0.0.7"}}
|
package/utils/axis.js
CHANGED
|
@@ -83,7 +83,11 @@
|
|
|
83
83
|
},
|
|
84
84
|
baseline: {},
|
|
85
85
|
label: {
|
|
86
|
-
padding: 1
|
|
86
|
+
padding: 1,
|
|
87
|
+
direction: 'horizontal',
|
|
88
|
+
gap: 1.5,
|
|
89
|
+
strategy: 'stride',
|
|
90
|
+
tolerance: 0.2
|
|
87
91
|
},
|
|
88
92
|
caption: {
|
|
89
93
|
padding: 1
|
|
@@ -140,13 +144,15 @@
|
|
|
140
144
|
update: function(){},
|
|
141
145
|
ticks: function(ticks){
|
|
142
146
|
/* (v)alue -> (c)oordinate -> (t)ext -> (n)odes: { g(group), p(path), t(text) } */
|
|
143
|
-
var map, size, count, itr, ref$, k, v, this$ = this;
|
|
147
|
+
var map, size, unit, count, itr, ref$, ends, k, v, this$ = this;
|
|
144
148
|
map = {};
|
|
145
149
|
size = this._n.layout.getBoundingClientRect()[this.dir < 2 ? 'width' : 'height'];
|
|
146
|
-
|
|
150
|
+
unit = this.dir < 2 && this.cfg.label.direction === 'vertical' ? 12 : 25;
|
|
151
|
+
count = Math.round(size / unit);
|
|
147
152
|
itr = (ref$ = Math.round(ticks.length / (count > 1 ? count : 1))) > 1 ? ref$ : 1;
|
|
153
|
+
ends = this.cfg.label.strategy === 'ends';
|
|
148
154
|
this._ticks = ticks.filter(function(d, i){
|
|
149
|
-
return !(i % itr) || i === ticks.length - 1;
|
|
155
|
+
return !(i % itr) || (ends && i === ticks.length - 1);
|
|
150
156
|
}).map(function(o){
|
|
151
157
|
var ref$, key$;
|
|
152
158
|
if (typeof o !== 'object') {
|
|
@@ -284,21 +290,17 @@
|
|
|
284
290
|
return this.adjust();
|
|
285
291
|
},
|
|
286
292
|
adjust: function(){
|
|
287
|
-
var ticks, isHorizon,
|
|
293
|
+
var ticks, isHorizon, vertical, em, place, gap, fits, sel, k, i, res$, i$, to$, tol, ref$, lo, hi, pick, even, p, idx, picked, shown, mm3, md3, size, delta, box, xoff, yoff, this$ = this;
|
|
288
294
|
ticks = this._ticks;
|
|
289
295
|
isHorizon = this.dir < 2;
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
} else {
|
|
295
|
-
lc.checked[idx] = true;
|
|
296
|
-
}
|
|
297
|
-
tick = ticks[idx];
|
|
296
|
+
vertical = isHorizon && this.cfg.label.direction === 'vertical';
|
|
297
|
+
em = parseFloat(getComputedStyle(this._n.wrap).fontSize) || 16;
|
|
298
|
+
place = function(tick, idx){
|
|
299
|
+
var pos, coord, box, offset, doOffset, r, toff;
|
|
298
300
|
pos = !idx
|
|
299
301
|
? 0
|
|
300
302
|
: idx === ticks.length - 1 ? 2 : 1;
|
|
301
|
-
|
|
303
|
+
coord = tick._c;
|
|
302
304
|
box = tick.box;
|
|
303
305
|
offset = {
|
|
304
306
|
x: -box.x,
|
|
@@ -309,136 +311,185 @@
|
|
|
309
311
|
: this$.cfg.tick.boundaryOffset != null
|
|
310
312
|
? !!this$.cfg.tick.boundaryOffset
|
|
311
313
|
: this$.dir < 2 ? true : false;
|
|
312
|
-
r =
|
|
313
|
-
?
|
|
314
|
-
:
|
|
315
|
-
|
|
314
|
+
r = vertical
|
|
315
|
+
? 1 / 2
|
|
316
|
+
: doOffset
|
|
317
|
+
? pos / 2
|
|
318
|
+
: 1 / 2;
|
|
319
|
+
if (vertical) {
|
|
320
|
+
offset.x -= box.width;
|
|
321
|
+
offset.y -= box.height * r;
|
|
322
|
+
} else if (isHorizon) {
|
|
316
323
|
offset.x -= box.width * r;
|
|
317
324
|
} else {
|
|
318
325
|
offset.y -= box.height * r;
|
|
319
326
|
}
|
|
320
327
|
tick.n.tt.setAttribute('transform', "translate(" + offset.x + "," + offset.y + ")");
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
box.coord = coord - box.size * r;
|
|
328
|
+
tick._size = vertical
|
|
329
|
+
? box.height
|
|
330
|
+
: box[isHorizon ? 'width' : 'height'];
|
|
331
|
+
tick._sizeAlt = vertical
|
|
332
|
+
? box.width
|
|
333
|
+
: box[isHorizon ? 'height' : 'width'];
|
|
334
|
+
tick._start = coord - tick._size * r;
|
|
329
335
|
if (isHorizon) {
|
|
330
336
|
tick.n.g.setAttribute('transform', "translate(" + coord + ",0)");
|
|
331
337
|
tick.n.p.setAttribute('d', "M0 0L0 " + this$.cfg.tick.inner);
|
|
332
|
-
|
|
338
|
+
toff = this$.cfg.tick.inner + this$.cfg.label.padding;
|
|
339
|
+
tick.n.t.setAttribute('transform', ("translate(0," + toff + ")") + (vertical ? " rotate(-90)" : ""));
|
|
333
340
|
} else {
|
|
334
341
|
tick.n.g.setAttribute('transform', "translate(0," + coord + ")");
|
|
335
342
|
tick.n.p.setAttribute('d', "M0 0L-" + this$.cfg.tick.inner + " 0");
|
|
336
|
-
tick.n.t.setAttribute('transform', "translate(" + (-this$.cfg.tick.inner -
|
|
343
|
+
tick.n.t.setAttribute('transform', "translate(" + (-this$.cfg.tick.inner - tick._sizeAlt - 1 - this$.cfg.label.padding) + ",0)");
|
|
337
344
|
}
|
|
338
|
-
|
|
339
|
-
ref$ = [box.coord, box.coord + box.size], ip1 = ref$[0], ip2 = ref$[1];
|
|
340
|
-
ref$ = [ip1 - m, ip2 + m], op1 = ref$[0], op2 = ref$[1];
|
|
341
|
-
overlap = lc.picked.filter(function(b){
|
|
342
|
-
var ref$, iq1, iq2, oq1, oq2;
|
|
343
|
-
ref$ = [b.coord, b.coord + b.size], iq1 = ref$[0], iq2 = ref$[1];
|
|
344
|
-
ref$ = [iq1 - m, iq2 + m], oq1 = ref$[0], oq2 = ref$[1];
|
|
345
|
-
return (ip1 > oq1 && ip1 < oq2) || (iq1 > op1 && iq1 < op2);
|
|
346
|
-
}).length;
|
|
347
|
-
tick.n.t.style.opacity = overlap ? 0 : 1;
|
|
348
|
-
tick.n.p.style.stroke = this$.cfg.tick.color || '';
|
|
349
|
-
lc.picked.push(box);
|
|
350
|
-
return !overlap;
|
|
345
|
+
return tick.n.p.style.stroke = this$.cfg.tick.color || '';
|
|
351
346
|
};
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
return it.n.t.style.opacity = 0;
|
|
365
|
-
});
|
|
366
|
-
if (ticks.length) {
|
|
367
|
-
fifo.push([0, ticks.length - 1, 0]);
|
|
368
|
-
[0, ticks.length - 1].map(function(it){
|
|
369
|
-
return insert(it, 0, lc);
|
|
370
|
-
});
|
|
347
|
+
ticks.map(place);
|
|
348
|
+
gap = em * (this.cfg.label.gap != null ? this.cfg.label.gap : 1.5);
|
|
349
|
+
fits = function(idx){
|
|
350
|
+
var prev, i$, len$, i, tick;
|
|
351
|
+
prev = null;
|
|
352
|
+
for (i$ = 0, len$ = idx.length; i$ < len$; ++i$) {
|
|
353
|
+
i = idx[i$];
|
|
354
|
+
tick = ticks[i];
|
|
355
|
+
if (prev != null && tick._start - (prev._start + prev._size) < gap) {
|
|
356
|
+
return false;
|
|
357
|
+
}
|
|
358
|
+
prev = tick;
|
|
371
359
|
}
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
360
|
+
return true;
|
|
361
|
+
};
|
|
362
|
+
sel = [0];
|
|
363
|
+
if (ticks.length > 1) {
|
|
364
|
+
if (this.cfg.label.strategy !== 'ends') {
|
|
365
|
+
k = 1;
|
|
366
|
+
while (k < ticks.length && !fits((fn$()))) {
|
|
367
|
+
k++;
|
|
376
368
|
}
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
369
|
+
res$ = [];
|
|
370
|
+
for (i$ = 0, to$ = ticks.length; k < 0 ? i$ > to$ : i$ < to$; i$ += k) {
|
|
371
|
+
i = i$;
|
|
372
|
+
res$.push(i);
|
|
381
373
|
}
|
|
382
|
-
|
|
383
|
-
|
|
374
|
+
sel = res$;
|
|
375
|
+
} else {
|
|
376
|
+
tol = this.cfg.label.tolerance != null ? this.cfg.label.tolerance : 0.2;
|
|
377
|
+
ref$ = [ticks[0]._c, ticks[ticks.length - 1]._c], lo = ref$[0], hi = ref$[1];
|
|
378
|
+
pick = function(p){
|
|
379
|
+
var ret, i$, i, target, best, j$, to$, j;
|
|
380
|
+
ret = [];
|
|
381
|
+
for (i$ = 0; i$ <= p; ++i$) {
|
|
382
|
+
i = i$;
|
|
383
|
+
target = lo + (hi - lo) * i / p;
|
|
384
|
+
best = 0;
|
|
385
|
+
for (j$ = 1, to$ = ticks.length; j$ < to$; ++j$) {
|
|
386
|
+
j = j$;
|
|
387
|
+
if (Math.abs(ticks[j]._c - target) < Math.abs(ticks[best]._c - target)) {
|
|
388
|
+
best = j;
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
if (ret[ret.length - 1] !== best) {
|
|
392
|
+
ret.push(best);
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
return ret;
|
|
396
|
+
};
|
|
397
|
+
even = function(idx){
|
|
398
|
+
var mean, i$, to$, i, d;
|
|
399
|
+
if (idx.length < 3) {
|
|
400
|
+
return true;
|
|
401
|
+
}
|
|
402
|
+
mean = (ticks[idx[idx.length - 1]]._c - ticks[idx[0]]._c) / (idx.length - 1);
|
|
403
|
+
if (!mean) {
|
|
404
|
+
return true;
|
|
405
|
+
}
|
|
406
|
+
for (i$ = 0, to$ = idx.length - 1; i$ < to$; ++i$) {
|
|
407
|
+
i = i$;
|
|
408
|
+
d = ticks[idx[i + 1]]._c - ticks[idx[i]]._c;
|
|
409
|
+
if (Math.abs(d - mean) > mean * tol + 0.5) {
|
|
410
|
+
return false;
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
return true;
|
|
414
|
+
};
|
|
415
|
+
for (i$ = ticks.length - 1; i$ >= 1; --i$) {
|
|
416
|
+
p = i$;
|
|
417
|
+
idx = pick(p);
|
|
418
|
+
if (idx.length > 1 && even(idx) && fits(idx)) {
|
|
419
|
+
sel = idx;
|
|
420
|
+
break;
|
|
421
|
+
}
|
|
384
422
|
}
|
|
385
423
|
}
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
424
|
+
}
|
|
425
|
+
picked = {};
|
|
426
|
+
sel.map(function(it){
|
|
427
|
+
return picked[it] = true;
|
|
428
|
+
});
|
|
429
|
+
ticks.map(function(tick, i){
|
|
430
|
+
return tick.n.t.style.opacity = picked[i] ? 1 : 0;
|
|
431
|
+
});
|
|
432
|
+
shown = ticks.filter(function(tick, i){
|
|
433
|
+
return picked[i];
|
|
434
|
+
});
|
|
435
|
+
this._n.label.style.fill = this.cfg.caption.color;
|
|
436
|
+
this._n.label.style.fontSize = this.cfg.caption.font.size ? this.cfg.caption.font.size + "" || '' : void 8;
|
|
437
|
+
this._n.label.setAttribute('class', (this.cfg.caption.font.family || {}).className || '');
|
|
438
|
+
this.caption();
|
|
439
|
+
this._n.sideNote.map(function(n, i){
|
|
440
|
+
var cfg, font;
|
|
441
|
+
cfg = this$.cfg[['sideNoteStart', 'sideNoteEnd'][i]] || {};
|
|
442
|
+
font = cfg.font || {};
|
|
443
|
+
n.textContent = !cfg.show
|
|
444
|
+
? ''
|
|
445
|
+
: cfg.text || '';
|
|
446
|
+
n.style.fill = cfg.color;
|
|
447
|
+
n.style.fontSize = font.size ? font.size + "" || '' : void 8;
|
|
448
|
+
return n.setAttribute('class', (font.family || {}).className || '');
|
|
449
|
+
});
|
|
450
|
+
mm3 = (this.cfg.caption.position || 0) % 3;
|
|
451
|
+
md3 = Math.floor((this.cfg.caption.position || 0) / 3);
|
|
452
|
+
size = Math.max.apply(Math, [0].concat(shown.map(function(it){
|
|
453
|
+
return it._sizeAlt;
|
|
454
|
+
})));
|
|
455
|
+
delta = this.cfg.tick.inner + this.cfg.label.padding + this.cfg.caption.padding + size;
|
|
456
|
+
if (this.dir < 2) {
|
|
457
|
+
this._n.label.setAttribute('y', [-2, delta][md3]);
|
|
458
|
+
this._n.layout.style.height = (delta + this._n.label.getBoundingClientRect().height) + "px";
|
|
459
|
+
box = this._n.layout.getBoundingClientRect();
|
|
460
|
+
return this._n.sideNote.map(function(n, i){
|
|
461
|
+
var cfg, pos;
|
|
396
462
|
cfg = this$.cfg[['sideNoteStart', 'sideNoteEnd'][i]] || {};
|
|
397
|
-
|
|
398
|
-
n.
|
|
399
|
-
|
|
400
|
-
: cfg.text || '';
|
|
401
|
-
n.style.fill = cfg.color;
|
|
402
|
-
n.style.fontSize = font.size ? font.size + "" || '' : void 8;
|
|
403
|
-
return n.setAttribute('class', (font.family || {}).className || '');
|
|
463
|
+
pos = cfg.position || 0;
|
|
464
|
+
n.setAttribute('x', [2, box.width - 2][i]);
|
|
465
|
+
return n.setAttribute('y', [-2 - cfg.padding, delta + cfg.padding][pos]);
|
|
404
466
|
});
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
yoff = [2, box.height / 2, box.height - 2][mm3];
|
|
429
|
-
this$._n.label.setAttribute('transform', "translate(" + xoff + "," + yoff + ") rotate(90)");
|
|
430
|
-
this$._n.root.setAttribute('transform', "translate(" + (box.width - 1) + ",0)");
|
|
431
|
-
return this$._n.sideNote.map(function(n, i){
|
|
432
|
-
var cfg, pos, xoff, yoff;
|
|
433
|
-
cfg = this$.cfg[['sideNoteStart', 'sideNoteEnd'][i]] || {};
|
|
434
|
-
pos = cfg.position || 0;
|
|
435
|
-
xoff = [2 + cfg.padding, -delta - 2 - cfg.padding][pos];
|
|
436
|
-
yoff = [2, box.height - 2][i];
|
|
437
|
-
return n.setAttribute('transform', "translate(" + xoff + "," + yoff + ") rotate(90)");
|
|
438
|
-
});
|
|
467
|
+
} else {
|
|
468
|
+
this._n.label.setAttribute('x', 0);
|
|
469
|
+
this._n.label.setAttribute('y', 0);
|
|
470
|
+
this._n.layout.style.width = (delta + this._n.label.getBoundingClientRect().width) + "px";
|
|
471
|
+
box = this._n.layout.getBoundingClientRect();
|
|
472
|
+
xoff = [2, -delta - 2][md3];
|
|
473
|
+
yoff = [2, box.height / 2, box.height - 2][mm3];
|
|
474
|
+
this._n.label.setAttribute('transform', "translate(" + xoff + "," + yoff + ") rotate(90)");
|
|
475
|
+
this._n.root.setAttribute('transform', "translate(" + (box.width - 1) + ",0)");
|
|
476
|
+
return this._n.sideNote.map(function(n, i){
|
|
477
|
+
var cfg, pos, xoff, yoff;
|
|
478
|
+
cfg = this$.cfg[['sideNoteStart', 'sideNoteEnd'][i]] || {};
|
|
479
|
+
pos = cfg.position || 0;
|
|
480
|
+
xoff = [2 + cfg.padding, -delta - 2 - cfg.padding][pos];
|
|
481
|
+
yoff = [2, box.height - 2][i];
|
|
482
|
+
return n.setAttribute('transform', "translate(" + xoff + "," + yoff + ") rotate(90)");
|
|
483
|
+
});
|
|
484
|
+
}
|
|
485
|
+
function fn$(){
|
|
486
|
+
var i$, step$, to$, results$ = [];
|
|
487
|
+
for (i$ = 0, to$ = ticks.length, step$ = k; step$ < 0 ? i$ > to$ : i$ < to$; i$ += step$) {
|
|
488
|
+
i = i$;
|
|
489
|
+
results$.push(i);
|
|
439
490
|
}
|
|
440
|
-
|
|
441
|
-
|
|
491
|
+
return results$;
|
|
492
|
+
}
|
|
442
493
|
}
|
|
443
494
|
});
|
|
444
495
|
if (typeof chart != 'undefined' && chart !== null) {
|
package/utils/axis.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(){var
|
|
1
|
+
!function(){var c,t;function d(t,e){var n,i={}.hasOwnProperty;for(n in e)i.call(e,n)&&(t[n]=e[n]);return t}c=function(t){return document.createElementNS("http://www.w3.org/2000/svg",t)},(t=function(t){var i,e=this;return this.dir={bottom:0,left:2}[(t=null==t?{}:t).direction||"bottom"],this.name=t.name||"axis",this.layout=t.layout||new layout({root:this.root}),this._ticks=[],this._scale=t.scale||function(t){return t},this._format=chart.utils.format.simple,this._config(t.cfg),this._map={},this._n=i={root:c("g"),layout:this.layout.getNode(this.name),render:this.layout.getGroup(this.name),wrap:null,domain:c("path")},i.render.appendChild(i.root),i.root.appendChild(i.domain),i.label=c("text"),i.label.textContent="",(t=i.label).setAttribute("dominant-baseline","hanging"),t.setAttribute("text-anchor","middle"),i.root.appendChild(i.label),i.sideNote=[0,1].map(function(t){var e,n=c("text");return n.textContent="",(e=n).setAttribute("dominant-baseline","hanging"),e.setAttribute("text-anchor",["start","end"][t]),i.root.appendChild(n)}),this.wrapper(),(t=this.layout).on("update",function(){return e.update()}),t.on("render",function(){return e.render()}),this}).prototype=d(Object.create(Object.prototype),{wrapper:function(){var t,e=this._n;return e.wrap&&e.wrap.parentNode&&e.wrap.parentNode.removeChild(e.wrap),e.wrap=document.createElement("div"),d(((t=e.wrap.style).visibility="hidden",t.position="absolute",t.top=0,t.left=0,t.pointerEvents="none",t.userSelect="none",t.zIndex=0,t.wordBreak="break-all",t.lineHeight=".95em",t),this.dir<2&&null!=this.cfg.textWidth?{whiteSpace:"wrap",width:(1<(t=this.cfg.textWidth)?t:1)+"em"}:{whiteSpace:"pre",width:"4em"}),e.layout.appendChild(e.wrap)},_config:function(e){var t,n=this;return null==e&&(e={}),this.cfg={tick:{inner:8},baseline:{},label:{padding:1,direction:"horizontal",gap:1.5,strategy:"stride",tolerance:.2},caption:{padding:1},enabled:e.enabled,sideNoteStart:{padding:1},sideNoteEnd:{padding:1}},["tick","baseline","label","caption","sideNoteStart","sideNoteEnd"].map(function(t){return d(n.cfg[t],e[t]||{})}),(t=this.cfg.label).font||(t.font={}),(t=this.cfg.caption).font||(t.font={}),(t=this.cfg.sideNoteStart).font||(t.font={}),(t=this.cfg.sideNoteEnd).font||(t.font={}),this.format(this.cfg.label.format)},config:function(t){return null==t?this.cfg:(this._config(t),this.wrapper())},format:function(t){return null==t?this._format:this._format="string"==typeof t?chart.utils.format.from(t):t||chart.utils.format.simple},scale:function(t){return null!=t?this._scale=t:this._scale},caption:function(t){return arguments.length&&(this._caption=t),!this.cfg.enabled||null!=this.cfg.caption.show&&!this.cfg.caption.show?this._n.label.textContent="":this._n.label.textContent=this.cfg.caption.text||this._caption||""},update:function(){},ticks:function(n){var t,e,i,a=this,r={},s=this._n.layout.getBoundingClientRect()[this.dir<2?"width":"height"],o=this.dir<2&&"vertical"===this.cfg.label.direction?12:25,s=Math.round(s/o),l=1<(t=Math.round(n.length/(1<s?s:1)))?t:1,h="ends"===this.cfg.label.strategy;for(e in this._ticks=n.filter(function(t,e){return!(e%l)||h&&e===n.length-1}).map(function(t){var e,n;return r[(t="object"!=typeof t?{v:t}:t).v]=d((e=a._map)[n=t.v]||(e[n]={}),t)}),t=this._map)i=t[e],r[e]||i.n.g.parentNode.removeChild(i.n.g);return this._map=r,this._ticks.filter(function(t){return!t.n}).map(function(t){if(t.n={g:c("g"),p:c("path"),t:c("g")},t.n.g.appendChild(t.n.p),t.n.g.appendChild(t.n.t),a._n.root.appendChild(t.n.g),isNaN(+t.v))return t.t=t.v})},render:function(){var i,t,a,e,n,r,s,o=this,l=this._n,h=this.dir<2,c=l.wrap;if(c.style.fontSize=this.cfg.label.font.size?this.cfg.label.font.size+""||"":void 0,c.setAttribute("class",(this.cfg.label.font.family||{}).className||""),i=this._ticks,null==this.cfg.enabled||this.cfg.enabled)return h?((t=l.layout.style).height="",t.paddingTop="",t.paddingBottom=""):((t=l.layout.style).width="",t.paddingLeft="",t.paddingRight=""),l.domain.style.display="",i.map(function(t){return t.n.g.style.display=""}),a=getComputedStyle(c).fontSize,e=l.layout.getBoundingClientRect(),(t=l.domain.style).strokeWidth=1,t.stroke="currentColor",t.fill="none",i.map(function(t,e){var n,e=e?e===i.length-1?2:1:0;return t._c=null!=t.c?t.c:o._scale(t.v)+(o._scale.bandwidth?o._scale.bandwidth()/2:0),t._t=null!=t.t?t.t:o._format(t.v),(n=t.n.p.style).strokeWidth=1,n.stroke="currentColor",n.fill="none",c.textContent=t._t,c.style.textAlign=h?["left","center","right"][e]:["right","left"][o.dir-2],t.n.tt=wrapSvgText({node:c}),t.n.t.style.fontSize=a,t.n.t.style.fill=o.cfg.label.color,t.n.t.textContent="",t.n.t.appendChild(t.n.tt),t.n.t.setAttribute("class",(o.cfg.label.font||{}).className||"")}),i.sort(function(t,e){return t._c-e._c}),l.domain.style.stroke=this.cfg.baseline.show?this.cfg.baseline.color:"none",n=(this.cfg.caption.position||0)%3,r=Math.floor((this.cfg.caption.position||0)/3),(s=l.label).setAttribute("text-anchor",["start","middle","end"][n]),s.setAttribute("dominant-baseline",["baseline","hanging"][r]),l.sideNote.map(function(t,e){e=(o.cfg[["sideNoteStart","sideNoteEnd"][e]]||{}).position||0;return t.setAttribute("dominant-baseline",["baseline","hanging"][e])}),h?(l.domain.setAttribute("d","M0 0L"+e.width+" 0Z"),l.label.setAttribute("x",e.width/2),l.label.setAttribute("x",[2,e.width/2,e.width-2][n])):(l.domain.setAttribute("d","M0 0L0 "+e.height+"Z"),s=[2,e.height/2,e.height-2][n],l.label.setAttribute("transform","translate(0,"+s+") rotate(90)")),i.map(function(t){return t.box=t.n.t.getBBox()}),this.adjust();h?((t=l.layout.style).height="0px",t.paddingTop="0",t.paddingBottom="0"):((t=l.layout.style).width="0px",t.paddingLeft="0",t.paddingRight="0"),l.domain.style.display="none",i.map(function(t){return t.n.g.style.display="none"})},adjust:function(){var r,t,e,a,s,n,i,o,l,h,c,d,f,u,g,p,b,m,y,_=this,w=this._ticks,v=this.dir<2,x=v&&"vertical"===this.cfg.label.direction,A=parseFloat(getComputedStyle(this._n.wrap).fontSize)||16;if(w.map(function(t,e){var e=e?e===w.length-1?2:1:0,n=t._c,i=t.box,a={x:-i.x,y:-i.y},r=!_._scale.bandwidth&&(null!=_.cfg.tick.boundaryOffset?!!_.cfg.tick.boundaryOffset:_.dir<2),r=!x&&r?e/2:.5;return x?(a.x-=i.width,a.y-=i.height*r):v?a.x-=i.width*r:a.y-=i.height*r,t.n.tt.setAttribute("transform","translate("+a.x+","+a.y+")"),t._size=x?i.height:i[v?"width":"height"],t._sizeAlt=x?i.width:i[v?"height":"width"],t._start=n-t._size*r,v?(t.n.g.setAttribute("transform","translate("+n+",0)"),t.n.p.setAttribute("d","M0 0L0 "+_.cfg.tick.inner),e=_.cfg.tick.inner+_.cfg.label.padding,t.n.t.setAttribute("transform","translate(0,"+e+")"+(x?" rotate(-90)":""))):(t.n.g.setAttribute("transform","translate(0,"+n+")"),t.n.p.setAttribute("d","M0 0L-"+_.cfg.tick.inner+" 0"),t.n.t.setAttribute("transform","translate("+(-_.cfg.tick.inner-t._sizeAlt-1-_.cfg.label.padding)+",0)")),t.n.p.style.stroke=_.cfg.tick.color||""}),r=A*(null!=this.cfg.label.gap?this.cfg.label.gap:1.5),t=function(t){for(var e,n=null,i=0,a=t.length;i<a;++i){if(e=t[i],e=w[e],null!=n&&e._start-(n._start+n._size)<r)return!1;n=e}return!0},e=[0],1<w.length)if("ends"!==this.cfg.label.strategy){for(a=1;a<w.length&&!t((()=>{var t,e,n,i=[];for(t=0,n=w.length,e=a;e<0?n<t:t<n;t+=e)s=t,i.push(s);return i})());)a++;for(n=[],i=0,o=w.length;a<0?o<i:i<o;i+=a)s=i,n.push(s);e=n}else for(l=null!=this.cfg.label.tolerance?this.cfg.label.tolerance:.2,A=[w[0]._c,w[w.length-1]._c],h=A[0],c=A[1],d=function(t){for(var e,n,i,a,r,s=[],o=0;o<=t;++o){for(e=h+(c-h)*o/t,n=0,i=1,a=w.length;i<a;++i)r=i,Math.abs(w[r]._c-e)<Math.abs(w[n]._c-e)&&(n=r);s[s.length-1]!==n&&s.push(n)}return s},f=function(t){var e,n,i,a;if(!(t.length<3)&&(e=(w[t[t.length-1]]._c-w[t[0]]._c)/(t.length-1)))for(n=0,i=t.length-1;n<i;++n)if(a=w[t[(a=n)+1]]._c-w[t[a]]._c,Math.abs(a-e)>e*l+.5)return!1;return!0},i=w.length-1;1<=i;--i)if(1<(u=d(i)).length&&f(u)&&t(u)){e=u;break}return g={},e.map(function(t){return g[t]=!0}),w.map(function(t,e){return t.n.t.style.opacity=g[e]?1:0}),A=w.filter(function(t,e){return g[e]}),this._n.label.style.fill=this.cfg.caption.color,this._n.label.style.fontSize=this.cfg.caption.font.size?this.cfg.caption.font.size+""||"":void 0,this._n.label.setAttribute("class",(this.cfg.caption.font.family||{}).className||""),this.caption(),this._n.sideNote.map(function(t,e){var e=_.cfg[["sideNoteStart","sideNoteEnd"][e]]||{},n=e.font||{};return t.textContent=e.show&&e.text||"",t.style.fill=e.color,t.style.fontSize=n.size?n.size+""||"":void 0,t.setAttribute("class",(n.family||{}).className||"")}),p=(this.cfg.caption.position||0)%3,b=Math.floor((this.cfg.caption.position||0)/3),A=Math.max.apply(Math,[0].concat(A.map(function(t){return t._sizeAlt}))),m=this.cfg.tick.inner+this.cfg.label.padding+this.cfg.caption.padding+A,this.dir<2?(this._n.label.setAttribute("y",[-2,m][b]),this._n.layout.style.height=m+this._n.label.getBoundingClientRect().height+"px",y=this._n.layout.getBoundingClientRect(),this._n.sideNote.map(function(t,e){var n=_.cfg[["sideNoteStart","sideNoteEnd"][e]]||{},i=n.position||0;return t.setAttribute("x",[2,y.width-2][e]),t.setAttribute("y",[-2-n.padding,m+n.padding][i])})):(this._n.label.setAttribute("x",0),this._n.label.setAttribute("y",0),this._n.layout.style.width=m+this._n.label.getBoundingClientRect().width+"px",A=[2,(y=this._n.layout.getBoundingClientRect()).height/2,y.height-2][p],this._n.label.setAttribute("transform","translate("+[2,-m-2][b]+","+A+") rotate(90)"),this._n.root.setAttribute("transform","translate("+(y.width-1)+",0)"),this._n.sideNote.map(function(t,e){var n=_.cfg[["sideNoteStart","sideNoteEnd"][e]]||{},i=n.position||0,e=[2,y.height-2][e];return t.setAttribute("transform","translate("+[2+n.padding,-m-2-n.padding][i]+","+e+") rotate(90)")}))}}),"undefined"!=typeof chart&&null!==chart&&((chart.utils||(chart.utils={})).axis=t)}.call(this);
|
package/utils/config.js
CHANGED
|
@@ -183,6 +183,25 @@
|
|
|
183
183
|
'default': 'horizontal',
|
|
184
184
|
values: ['horizontal', 'vertical']
|
|
185
185
|
},
|
|
186
|
+
gap: {
|
|
187
|
+
type: 'number',
|
|
188
|
+
'default': 1.5,
|
|
189
|
+
min: 0,
|
|
190
|
+
max: 10,
|
|
191
|
+
step: 0.1
|
|
192
|
+
},
|
|
193
|
+
strategy: {
|
|
194
|
+
type: 'choice',
|
|
195
|
+
'default': 'stride',
|
|
196
|
+
values: ['stride', 'ends']
|
|
197
|
+
},
|
|
198
|
+
tolerance: {
|
|
199
|
+
type: 'number',
|
|
200
|
+
'default': 0.2,
|
|
201
|
+
min: 0,
|
|
202
|
+
max: 1,
|
|
203
|
+
step: 0.05
|
|
204
|
+
},
|
|
186
205
|
padding: {
|
|
187
206
|
type: 'number',
|
|
188
207
|
'default': 1,
|
package/utils/config.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(){var e;e={from:function(e){var i=this,p=function(e,t){var a,o;if(t.preset){var l,n=e,r=JSON.parse(JSON.stringify(i.preset[t.preset])),u={}.hasOwnProperty;for(l in r)u.call(r,l)&&(n[l]=r[l])}for(a in t)o=t[a],"preset"!==a&&("string"==typeof o?e[a]=JSON.parse(JSON.stringify(i.preset[o]))||{}:p(e[a]||(e[a]={}),o));return e};return p({},e)},preset:{default:{margin:{type:"number"},font:e={family:{type:"font"},size:{type:"quantity",default:"1em",units:[{name:"em",max:10,step:.01,default:1},{name:"px",max:256,step:1,default:16}]}},color:{type:"color",default:"currentColor"},palette:{type:"palette"},background:{type:"color",default:"transparent"}},font:e,tip:{enabled:{type:"boolean",default:!0},format:{type:"format",default:".3s"}},label:{format:{type:"format",default:".3s"}},legend:{selectable:{type:"boolean",default:!0},enabled:{type:"boolean",default:!0},position:{type:"choice",values:["bottom","right"],default:"right"},sort:{direction:{type:"choice",values:["asc","desc"],default:"desc"},mode:{type:"choice",values:["label","value","none"],default:"value"}},subset:{mode:{type:"choice",values:["shrink","dim","partial"],default:"shrink"},opacity:{type:"number",default:.2,min:0,max:1,step:.05}},crossfilter:{type:"boolean",default:!1}},axis:{enabled:{type:"boolean",default:!0},center:{type:"boolean",default:!1},tick:{inner:{type:"number",name:"Inner Tick Size",default:8,min:0,max:40,step:.1},color:{type:"color",default:"currentColor"},count:{type:"number",default:4,min:1,max:40},boundaryOffset:{type:"boolean",default:!0}},baseline:{show:{type:"boolean",default:!0},color:{type:"color",default:"currentColor"}},label:{color:{type:"color",default:"currentColor"},format:{type:"format",default:".3s"},direction:{type:"choice",default:"horizontal",values:["horizontal","vertical"]},padding:{type:"number",default:1,min:0,max:100,step:.5},font:e},caption:{color:{type:"color",default:"currentColor"},text:{type:"text",default:""},show:{type:"boolean",default:!0},padding:{type:"number",default:1,min:0,max:100,step:.5},position:{type:"choice",default:4,values:[{name:"in / start",value:0},{name:"in / middle",value:1},{name:"in / end",value:2},{name:"out / start",value:3},{name:"out / middle",value:4},{name:"out / end",value:5}]},font:e},sideNoteStart:{show:{type:"boolean",default:!1},text:{type:"text",default:""},position:{type:"choice",default:0,values:[{name:"in",value:0},{name:"out",value:1}]},font:e,color:{type:"color",default:"currentColor"},padding:{type:"number",default:1,min:0,max:100,step:.5}},sideNoteEnd:{show:{type:"boolean",default:!1},text:{type:"text",default:""},position:{type:"choice",default:0,values:[{name:"in",value:0},{name:"out",value:1}]},font:e,color:{type:"color",default:"currentColor"},padding:{type:"number",default:1,min:0,max:100,step:.5}}}}},"undefined"!=typeof chart&&null!==chart&&((chart.utils||(chart.utils={})).config=e)}.call(this);
|
|
1
|
+
!function(){var e;e={from:function(e){var i=this,p=function(e,t){var a,o;if(t.preset){var l,n=e,r=JSON.parse(JSON.stringify(i.preset[t.preset])),u={}.hasOwnProperty;for(l in r)u.call(r,l)&&(n[l]=r[l])}for(a in t)o=t[a],"preset"!==a&&("string"==typeof o?e[a]=JSON.parse(JSON.stringify(i.preset[o]))||{}:p(e[a]||(e[a]={}),o));return e};return p({},e)},preset:{default:{margin:{type:"number"},font:e={family:{type:"font"},size:{type:"quantity",default:"1em",units:[{name:"em",max:10,step:.01,default:1},{name:"px",max:256,step:1,default:16}]}},color:{type:"color",default:"currentColor"},palette:{type:"palette"},background:{type:"color",default:"transparent"}},font:e,tip:{enabled:{type:"boolean",default:!0},format:{type:"format",default:".3s"}},label:{format:{type:"format",default:".3s"}},legend:{selectable:{type:"boolean",default:!0},enabled:{type:"boolean",default:!0},position:{type:"choice",values:["bottom","right"],default:"right"},sort:{direction:{type:"choice",values:["asc","desc"],default:"desc"},mode:{type:"choice",values:["label","value","none"],default:"value"}},subset:{mode:{type:"choice",values:["shrink","dim","partial"],default:"shrink"},opacity:{type:"number",default:.2,min:0,max:1,step:.05}},crossfilter:{type:"boolean",default:!1}},axis:{enabled:{type:"boolean",default:!0},center:{type:"boolean",default:!1},tick:{inner:{type:"number",name:"Inner Tick Size",default:8,min:0,max:40,step:.1},color:{type:"color",default:"currentColor"},count:{type:"number",default:4,min:1,max:40},boundaryOffset:{type:"boolean",default:!0}},baseline:{show:{type:"boolean",default:!0},color:{type:"color",default:"currentColor"}},label:{color:{type:"color",default:"currentColor"},format:{type:"format",default:".3s"},direction:{type:"choice",default:"horizontal",values:["horizontal","vertical"]},gap:{type:"number",default:1.5,min:0,max:10,step:.1},strategy:{type:"choice",default:"stride",values:["stride","ends"]},tolerance:{type:"number",default:.2,min:0,max:1,step:.05},padding:{type:"number",default:1,min:0,max:100,step:.5},font:e},caption:{color:{type:"color",default:"currentColor"},text:{type:"text",default:""},show:{type:"boolean",default:!0},padding:{type:"number",default:1,min:0,max:100,step:.5},position:{type:"choice",default:4,values:[{name:"in / start",value:0},{name:"in / middle",value:1},{name:"in / end",value:2},{name:"out / start",value:3},{name:"out / middle",value:4},{name:"out / end",value:5}]},font:e},sideNoteStart:{show:{type:"boolean",default:!1},text:{type:"text",default:""},position:{type:"choice",default:0,values:[{name:"in",value:0},{name:"out",value:1}]},font:e,color:{type:"color",default:"currentColor"},padding:{type:"number",default:1,min:0,max:100,step:.5}},sideNoteEnd:{show:{type:"boolean",default:!1},text:{type:"text",default:""},position:{type:"choice",default:0,values:[{name:"in",value:0},{name:"out",value:1}]},font:e,color:{type:"color",default:"currentColor"},padding:{type:"number",default:1,min:0,max:100,step:.5}}}}},"undefined"!=typeof chart&&null!==chart&&((chart.utils||(chart.utils={})).config=e)}.call(this);
|
package/utils/legend.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
var svgns, legend;
|
|
3
3
|
svgns = "http://www.w3.org/2000/svg";
|
|
4
4
|
legend = function(opt){
|
|
5
|
-
var x$, nodeLayout, nodeRender, gl, gs, gt, this$ = this;
|
|
5
|
+
var x$, nodeLayout, nodeRender, gl, gs, gt, add, lng, ref$, res, this$ = this;
|
|
6
6
|
opt == null && (opt = {});
|
|
7
7
|
this._data = opt.data || [];
|
|
8
8
|
this.name = opt.name || 'legend';
|
|
@@ -43,15 +43,32 @@
|
|
|
43
43
|
gl.appendChild(gt);
|
|
44
44
|
nodeRender.appendChild(gl);
|
|
45
45
|
}
|
|
46
|
+
this._i18n = opt.i18n || ((typeof block != 'undefined' && block !== null) && block.i18n && block.i18n.module ? block.i18n.module : null);
|
|
47
|
+
this._t = opt.t || null;
|
|
48
|
+
if (this._i18n) {
|
|
49
|
+
if (add = this._i18n.addResourceBundle) {
|
|
50
|
+
for (lng in ref$ = legend.i18n) {
|
|
51
|
+
res = ref$[lng];
|
|
52
|
+
try {
|
|
53
|
+
add.call(this._i18n, lng, legend.i18nNs, res, true, false);
|
|
54
|
+
} catch (e$) {}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
if (this._i18n.on) {
|
|
58
|
+
this._i18n.on('languageChanged', this._lngHandler = function(){
|
|
59
|
+
return this$._relocalize();
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
}
|
|
46
63
|
this._func = [
|
|
47
64
|
{
|
|
48
65
|
key: "all",
|
|
49
66
|
type: "func",
|
|
50
|
-
text:
|
|
67
|
+
text: this._text('all')
|
|
51
68
|
}, {
|
|
52
69
|
key: "none",
|
|
53
70
|
type: "func",
|
|
54
|
-
text:
|
|
71
|
+
text: this._text('none')
|
|
55
72
|
}
|
|
56
73
|
];
|
|
57
74
|
this.view = {
|
|
@@ -187,7 +204,58 @@
|
|
|
187
204
|
this.update();
|
|
188
205
|
return this;
|
|
189
206
|
};
|
|
207
|
+
legend.i18nNs = "@plotdb/chart.legend";
|
|
208
|
+
legend.i18n = {
|
|
209
|
+
en: {
|
|
210
|
+
all: "Select All",
|
|
211
|
+
none: "Select None"
|
|
212
|
+
},
|
|
213
|
+
"zh-TW": {
|
|
214
|
+
all: "全選",
|
|
215
|
+
none: "全不選"
|
|
216
|
+
},
|
|
217
|
+
"zh-CN": {
|
|
218
|
+
all: "全选",
|
|
219
|
+
none: "全不选"
|
|
220
|
+
},
|
|
221
|
+
ja: {
|
|
222
|
+
all: "すべて選択",
|
|
223
|
+
none: "すべて解除"
|
|
224
|
+
}
|
|
225
|
+
};
|
|
190
226
|
legend.prototype = import$(Object.create(Object.prototype), {
|
|
227
|
+
_text: function(key){
|
|
228
|
+
var r, k, lng, res;
|
|
229
|
+
if (this._t && (r = this._t("legend." + key)) && r !== "legend." + key) {
|
|
230
|
+
return r;
|
|
231
|
+
}
|
|
232
|
+
k = legend.i18nNs + ":" + key;
|
|
233
|
+
if (this._i18n && this._i18n.t && (r = this._i18n.t(k)) && r !== k && r !== key) {
|
|
234
|
+
return r;
|
|
235
|
+
}
|
|
236
|
+
lng = this._i18n ? this._i18n.language || this._i18n.lng : null;
|
|
237
|
+
lng = lng || (typeof document != 'undefined' && document !== null ? document.documentElement.lang : '') || 'en';
|
|
238
|
+
res = legend.i18n[lng] || legend.i18n[lng.split('-')[0]] || (/^zh/i.exec(lng) ? legend.i18n[/cn|hans|sg/i.exec(lng) ? 'zh-CN' : 'zh-TW'] : void 8) || legend.i18n.en;
|
|
239
|
+
return res[key];
|
|
240
|
+
},
|
|
241
|
+
_relocalize: function(){
|
|
242
|
+
var this$ = this;
|
|
243
|
+
this._func.map(function(f){
|
|
244
|
+
return f.text = this$._text(f.key);
|
|
245
|
+
});
|
|
246
|
+
if (!this.cfg.selectable) {
|
|
247
|
+
return;
|
|
248
|
+
}
|
|
249
|
+
this.view.layout.render('legend');
|
|
250
|
+
this.layout.update(false);
|
|
251
|
+
return this.view.render.render();
|
|
252
|
+
},
|
|
253
|
+
destroy: function(){
|
|
254
|
+
if (this._i18n && this._lngHandler && this._i18n.off) {
|
|
255
|
+
this._i18n.off('languageChanged', this._lngHandler);
|
|
256
|
+
}
|
|
257
|
+
return this._lngHandler = null;
|
|
258
|
+
},
|
|
191
259
|
_name: function(ctx, type){
|
|
192
260
|
type == null && (type = "s");
|
|
193
261
|
return "pdlg-" + type + "-" + this.id + "-" + (ctx.type || '') + "-" + ctx.key;
|
package/utils/legend.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(){var
|
|
1
|
+
!function(){var c,d;c="http://www.w3.org/2000/svg",(d=function(a){var t,e,n,i,r,l,s,o,u=this;if(null==a&&(a={}),this._data=a.data||[],this.name=a.name||"legend",this.cfg=a.cfg||{},this.root="string"==typeof a.root?document.querySelector(a.root):a.root,this.dir=a.direction||"vertical",this.evtHandler={},this._picked=Object.fromEntries(this._data.map(function(t){return[t.key,!0]})),this.layout=a.layout||new layout({root:this.root}),(e=this.layout).on("update",function(){return u.update()}),e.on("render",function(){return u.render()}),this.id=Math.random().toString(36).substring(2),e=this.layout.getNode(this.name),t=this.layout.getGroup(this.name),e.querySelector("[ld-each=legend]")||(e.innerHTML='<div class="pdlg '+this.dir+'">\n <div ld-each="legend">\n <div class="pdl-cell" ld="shape" data-only></div>\n <div class="pdl-cell" ld="text" data-only></div>\n </div>\n</div>'),t.querySelector("[ld-each=legend]")||(e=document.createElementNS(c,"g"),n=document.createElementNS(c,"g"),i=document.createElementNS(c,"g"),e.classList.add("pdlg-g"),e.setAttribute("ld-each","legend"),n.setAttribute("ld","shape"),i.setAttribute("ld","text"),e.appendChild(n),e.appendChild(i),t.appendChild(e)),this._i18n=a.i18n||("undefined"!=typeof block&&null!==block&&block.i18n&&block.i18n.module?block.i18n.module:null),this._t=a.t||null,this._i18n){if(r=this._i18n.addResourceBundle)for(l in s=d.i18n){o=s[l];try{r.call(this._i18n,l,d.i18nNs,o,!0,!1)}catch(t){}}this._i18n.on&&this._i18n.on("languageChanged",this._lngHandler=function(){return u._relocalize()})}return this._func=[{key:"all",type:"func",text:this._text("all")},{key:"none",type:"func",text:this._text("none")}],this.view={layout:new ldview({root:this.layout.getNode(this.name),initRender:!1,handler:{legend:{list:function(){var n,t=u._data.map(function(t){return t}),i=u.cfg.sort||{};return"none"!==i.mode&&(n="desc"===i.direction?1:-1,t.sort(function(t,e){return"value"===i.mode?n*(e.value-t.value):n*(t.text<e.text?1:t.text>e.text?-1:0)})),t.concat(u.cfg.selectable?u._func:[])},key:function(t){return t.key},view:{handler:{shape:function(t){return t.node.setAttribute("data-name",u._name(t.ctx,"shape"))},text:function(t){var e=t.node,t=t.ctx;return e.setAttribute("data-name",u._name(t,"text")),e.innerText=t.text}}}}}}),render:new ldview({root:this.layout.getGroup(this.name),initRender:!1,handler:{legend:{list:function(){return u._data.concat(u.cfg.selectable?u._func:[])},key:function(t){return t.key},view:{action:{click:{"@":function(t){t.node;var e,n=t.ctx;if(u.cfg.selectable){if("func"===n.type)for(e in u._picked)u._picked[e]="all"===n.key;else u._picked[n.key]=!u._picked[n.key];return u.view.render.render("legend"),u.fire("select",u._picked)}}}},handler:{"@":function(t){var e=t.node,t=t.ctx;return e.style.opacity=!u.cfg.selectable||"func"===t.type||u._picked[t.key]?1:.3},shape:function(t){var e,n,i,r=t.node,t=t.ctx;if("func"!==t.type)return r.querySelector("circle")||r.appendChild(document.createElementNS(c,"circle")),e=r.querySelector("circle"),n=u.layout.getBox(u._name(t,"shape")),i=u.layout.getBox(u.name),e.setAttribute("cx",".5em"),e.setAttribute("cy",".5em"),e.setAttribute("r",".5em"),e.setAttribute("transform","translate("+(n.x-i.x)+", "+(n.y-i.y)+")"),"function"==typeof a.shape?a.shape.call(e,t):void 0;r.style.display="none"},text:function(t){var e=t.node,t=t.ctx,n=u.layout.getNode(u._name(t,"text")),t=u.layout.getBox(u._name(t,"text")),i=u.layout.getBox(u.name);return e.setAttribute("transform","translate("+(t.x-i.x)+", "+(t.y-i.y)+")"),e.textContent="",t=wrapSvgText({node:n,useRange:!0}),e.appendChild(t)}}}}}})},this.update(),this}).i18nNs="@plotdb/chart.legend",d.i18n={en:{all:"Select All",none:"Select None"},"zh-TW":{all:"全選",none:"全不選"},"zh-CN":{all:"全选",none:"全不选"},ja:{all:"すべて選択",none:"すべて解除"}},d.prototype=((t,e)=>{var n,i={}.hasOwnProperty;for(n in e)i.call(e,n)&&(t[n]=e[n]);return t})(Object.create(Object.prototype),{_text:function(t){var e,n;return this._t&&(e=this._t("legend."+t))&&e!=="legend."+t||(n=d.i18nNs+":"+t,this._i18n&&this._i18n.t&&(e=this._i18n.t(n))&&e!==n&&e!==t)?e:(n=(n=this._i18n?this._i18n.language||this._i18n.lng:null)||("undefined"!=typeof document&&null!==document?document.documentElement.lang:"")||"en",(d.i18n[n]||d.i18n[n.split("-")[0]]||(/^zh/i.exec(n)?d.i18n[/cn|hans|sg/i.exec(n)?"zh-CN":"zh-TW"]:void 0)||d.i18n.en)[t])},_relocalize:function(){var e=this;if(this._func.map(function(t){return t.text=e._text(t.key)}),this.cfg.selectable)return this.view.layout.render("legend"),this.layout.update(!1),this.view.render.render()},destroy:function(){return this._i18n&&this._lngHandler&&this._i18n.off&&this._i18n.off("languageChanged",this._lngHandler),this._lngHandler=null},_name:function(t,e){return"pdlg-"+(e=null==e?"s":e)+"-"+this.id+"-"+(t.type||"")+"-"+t.key},enabled:function(){return this._data&&this._data.length&&(!(null!=this.cfg.enabled)||this.cfg.enabled)},update:function(){var t=this.enabled()?"":"0px",e=this.layout.getNode(this.name).style;return e.width=t,e.height=t,e.padding=t,e.margin=t,(e=this.layout.getNode(this.name).querySelector(".pdlg"))&&("vertical"===this.dir?(e.style.height="fit-content",e.style.height=getComputedStyle(e.parentNode).height):e.style.height=""),this.view.layout.render()},render:function(){var t=this.enabled();if(this.layout.getGroup(this.name).style.display=t?"":"none",t)return this.view.render.render()},config:function(t){var e,n=this;return null==t?this.cfg:(this.cfg.selectable!==t.selectable&&(this._picked=null,this._updatePicked()),this.cfg=t,this.dir="bottom"===this.cfg.position?"horizontal":"vertical",e=this.layout.getNode(this.name).querySelector(".pdlg"),["horizontal","vertical"].map(function(t){return e.classList.toggle(t,n.dir===t)}))},_updatePicked:function(){var e=this;return null==this._picked&&(this._picked=Object.fromEntries(this._data.map(function(t){return[t.key,!0]}))),this._data.map(function(t){if(null==e._picked[t.key])return e._picked[t.key]=!0})},data:function(t){var n;return arguments.length?(n={},t.map(function(t,e){return n[t.key]=e}),this._data=t.filter(function(t,e){return n[t.key]===e}),this._range=this._data.filter(function(t){return t.ext}),this._updatePicked(),this.update(),this.layout.update(!1),this.view.render.render()):this._data},on:function(t,n){var i=this;return(Array.isArray(t)?t:[t]).map(function(t){var e;return((e=i.evtHandler)[t]||(e[t]=[])).push(n)})},fire:function(t){for(var e,n,i,r,a=[],l=[],s=1,o=arguments.length;s<o;++s)l.push(arguments[s]);for(e=l,s=0,i=(n=this.evtHandler[t]||[]).length;s<i;++s)r=n[s],a.push(r.apply(this,e));return a},isSelected:function(e){var n=this;return this._range&&this._range.length?!!this._range.filter(function(t){return e>=t.ext[0]&&e<t.ext[1]&&n._picked[t.key]}).length:!!this._picked[e]},mode:function(){return"shrink"===((this.cfg.subset||{}).mode||"shrink")?"shrink":"dim"},opacity:function(){var t;return null!=(t=(this.cfg.subset||{}).opacity)?t:.2},isVisible:function(t){return"shrink"!==this.mode()||this.isSelected(t)},select:function(t){var e;return null==t?this._picked=Object.fromEntries(this._data.map(function(t){return[t.key,!0]})):(e=Object.fromEntries(t.map(function(t){return[t,!0]})),this._picked=Object.fromEntries(this._data.map(function(t){return[t.key,!!e[t.key]]}))),this.view.render.render("legend"),this},selected:function(){var e=this,t=this._data.filter(function(t){return!!e._picked[t.key]}).map(function(t){return t.key});return t.length===this._data.length?null:t}}),"undefined"!=typeof chart&&null!==chart&&((chart.utils||(chart.utils={})).legend=d)}.call(this);
|