@orbcharts/plugins-basic 3.0.0-alpha.44 → 3.0.0-alpha.45
Sign up to get free protection for your applications and to get access to all the features.
- package/LICENSE +200 -200
- package/dist/{src → orbcharts-plugins-basic/src}/base/BaseBarStack.d.ts +6 -4
- package/dist/{src → orbcharts-plugins-basic/src}/base/BaseBars.d.ts +6 -4
- package/dist/{src → orbcharts-plugins-basic/src}/base/BaseBarsTriangle.d.ts +7 -4
- package/dist/{src → orbcharts-plugins-basic/src}/base/BaseDots.d.ts +5 -3
- package/dist/{src → orbcharts-plugins-basic/src}/base/BaseGroupAxis.d.ts +3 -3
- package/dist/{src → orbcharts-plugins-basic/src}/base/BaseLineAreas.d.ts +6 -3
- package/dist/{src → orbcharts-plugins-basic/src}/base/BaseLines.d.ts +6 -3
- package/dist/{src → orbcharts-plugins-basic/src}/base/BaseValueAxis.d.ts +3 -3
- package/dist/{src → orbcharts-plugins-basic/src}/grid/gridObservables.d.ts +4 -4
- package/dist/orbcharts-plugins-basic/src/index.d.ts +5 -0
- package/dist/orbcharts-plugins-basic/src/multiGrid/multiGridObservables.d.ts +8 -0
- package/dist/orbcharts-plugins-basic/src/series/plugins/PieEventTexts.d.ts +3 -0
- package/dist/orbcharts-plugins-basic/src/series/seriesObservables.d.ts +21 -0
- package/dist/{src → orbcharts-plugins-basic/src}/series/seriesUtils.d.ts +3 -3
- package/dist/orbcharts-plugins-basic.es.js +7696 -7529
- package/dist/orbcharts-plugins-basic.umd.js +8 -8
- package/dist/src/index.d.ts +1 -5
- package/package.json +42 -42
- package/src/base/BaseBarStack.ts +778 -881
- package/src/base/BaseBars.ts +764 -750
- package/src/base/BaseBarsTriangle.ts +672 -659
- package/src/base/BaseDots.ts +502 -639
- package/src/base/BaseGroupAxis.ts +496 -496
- package/src/base/BaseLegend.ts +641 -641
- package/src/base/BaseLineAreas.ts +625 -621
- package/src/base/BaseLines.ts +699 -692
- package/src/base/BaseValueAxis.ts +478 -479
- package/src/base/types.ts +2 -2
- package/src/grid/defaults.ts +121 -121
- package/src/grid/gridObservables.ts +247 -263
- package/src/grid/index.ts +15 -15
- package/src/grid/plugins/BarStack.ts +50 -37
- package/src/grid/plugins/Bars.ts +51 -37
- package/src/grid/plugins/BarsDiverging.ts +41 -39
- package/src/grid/plugins/BarsTriangle.ts +50 -34
- package/src/grid/plugins/Dots.ts +37 -35
- package/src/grid/plugins/GridLegend.ts +59 -59
- package/src/grid/plugins/GroupAux.ts +645 -646
- package/src/grid/plugins/GroupAxis.ts +42 -30
- package/src/grid/plugins/LineAreas.ts +39 -36
- package/src/grid/plugins/Lines.ts +38 -35
- package/src/grid/plugins/ScalingArea.ts +173 -174
- package/src/grid/plugins/ValueAxis.ts +43 -31
- package/src/grid/plugins/ValueStackAxis.ts +79 -70
- package/src/grid/types.ts +120 -120
- package/src/index.ts +9 -9
- package/src/multiGrid/defaults.ts +147 -147
- package/src/multiGrid/index.ts +11 -11
- package/src/multiGrid/multiGridObservables.ts +42 -289
- package/src/multiGrid/plugins/MultiBarStack.ts +74 -60
- package/src/multiGrid/plugins/MultiBars.ts +73 -59
- package/src/multiGrid/plugins/MultiBarsTriangle.ts +73 -58
- package/src/multiGrid/plugins/MultiDots.ts +60 -58
- package/src/multiGrid/plugins/MultiGridLegend.ts +89 -89
- package/src/multiGrid/plugins/MultiGroupAxis.ts +65 -53
- package/src/multiGrid/plugins/MultiLineAreas.ts +62 -59
- package/src/multiGrid/plugins/MultiLines.ts +61 -58
- package/src/multiGrid/plugins/MultiValueAxis.ts +65 -53
- package/src/multiGrid/plugins/OverlappingValueAxes.ts +169 -164
- package/src/multiGrid/types.ts +67 -67
- package/src/noneData/defaults.ts +64 -61
- package/src/noneData/index.ts +3 -3
- package/src/noneData/plugins/Container.ts +10 -10
- package/src/noneData/plugins/Tooltip.ts +310 -310
- package/src/noneData/types.ts +26 -26
- package/src/series/defaults.ts +109 -99
- package/src/series/index.ts +6 -6
- package/src/series/plugins/Bubbles.ts +571 -551
- package/src/series/plugins/Pie.ts +548 -600
- package/src/series/plugins/PieEventTexts.ts +258 -194
- package/src/series/plugins/PieLabels.ts +335 -288
- package/src/series/plugins/SeriesLegend.ts +59 -59
- package/src/series/seriesObservables.ts +145 -0
- package/src/series/seriesUtils.ts +50 -50
- package/src/series/types.ts +67 -67
- package/src/tree/defaults.ts +22 -22
- package/src/tree/index.ts +3 -3
- package/src/tree/plugins/TreeLegend.ts +59 -59
- package/src/tree/plugins/TreeMap.ts +305 -305
- package/src/tree/types.ts +23 -23
- package/src/utils/commonUtils.ts +21 -21
- package/src/utils/d3Graphics.ts +124 -124
- package/src/utils/d3Utils.ts +73 -73
- package/src/utils/observables.ts +14 -14
- package/src/utils/orbchartsUtils.ts +100 -100
- package/tsconfig.dev.json +16 -16
- package/tsconfig.json +16 -13
- package/tsconfig.prod.json +13 -13
- package/vite.config.js +49 -49
- package/dist/src/multiGrid/multiGridObservables.d.ts +0 -12
- package/dist/src/series/plugins/PieEventTexts.d.ts +0 -1
- /package/dist/{src → orbcharts-plugins-basic/src}/base/BaseGroupArea.d.ts +0 -0
- /package/dist/{src → orbcharts-plugins-basic/src}/base/BaseLegend.d.ts +0 -0
- /package/dist/{src → orbcharts-plugins-basic/src}/base/types.d.ts +0 -0
- /package/dist/{src → orbcharts-plugins-basic/src}/grid/defaults.d.ts +0 -0
- /package/dist/{src → orbcharts-plugins-basic/src}/grid/index.d.ts +0 -0
- /package/dist/{src → orbcharts-plugins-basic/src}/grid/plugins/BarStack.d.ts +0 -0
- /package/dist/{src → orbcharts-plugins-basic/src}/grid/plugins/Bars.d.ts +0 -0
- /package/dist/{src → orbcharts-plugins-basic/src}/grid/plugins/BarsDiverging.d.ts +0 -0
- /package/dist/{src → orbcharts-plugins-basic/src}/grid/plugins/BarsTriangle.d.ts +0 -0
- /package/dist/{src → orbcharts-plugins-basic/src}/grid/plugins/Dots.d.ts +0 -0
- /package/dist/{src → orbcharts-plugins-basic/src}/grid/plugins/GridLegend.d.ts +0 -0
- /package/dist/{src → orbcharts-plugins-basic/src}/grid/plugins/GroupAux.d.ts +0 -0
- /package/dist/{src → orbcharts-plugins-basic/src}/grid/plugins/GroupAxis.d.ts +0 -0
- /package/dist/{src → orbcharts-plugins-basic/src}/grid/plugins/LineAreas.d.ts +0 -0
- /package/dist/{src → orbcharts-plugins-basic/src}/grid/plugins/Lines.d.ts +0 -0
- /package/dist/{src → orbcharts-plugins-basic/src}/grid/plugins/Ranking.d.ts +0 -0
- /package/dist/{src → orbcharts-plugins-basic/src}/grid/plugins/RankingAxis.d.ts +0 -0
- /package/dist/{src → orbcharts-plugins-basic/src}/grid/plugins/ScalingArea.d.ts +0 -0
- /package/dist/{src → orbcharts-plugins-basic/src}/grid/plugins/ValueAxis.d.ts +0 -0
- /package/dist/{src → orbcharts-plugins-basic/src}/grid/plugins/ValueStackAxis.d.ts +0 -0
- /package/dist/{src → orbcharts-plugins-basic/src}/grid/types.d.ts +0 -0
- /package/dist/{src → orbcharts-plugins-basic/src}/multiGrid/defaults.d.ts +0 -0
- /package/dist/{src → orbcharts-plugins-basic/src}/multiGrid/index.d.ts +0 -0
- /package/dist/{src → orbcharts-plugins-basic/src}/multiGrid/plugins/MultiBarStack.d.ts +0 -0
- /package/dist/{src → orbcharts-plugins-basic/src}/multiGrid/plugins/MultiBars.d.ts +0 -0
- /package/dist/{src → orbcharts-plugins-basic/src}/multiGrid/plugins/MultiBarsTriangle.d.ts +0 -0
- /package/dist/{src → orbcharts-plugins-basic/src}/multiGrid/plugins/MultiDots.d.ts +0 -0
- /package/dist/{src → orbcharts-plugins-basic/src}/multiGrid/plugins/MultiGridLegend.d.ts +0 -0
- /package/dist/{src → orbcharts-plugins-basic/src}/multiGrid/plugins/MultiGroupAxis.d.ts +0 -0
- /package/dist/{src → orbcharts-plugins-basic/src}/multiGrid/plugins/MultiLineAreas.d.ts +0 -0
- /package/dist/{src → orbcharts-plugins-basic/src}/multiGrid/plugins/MultiLines.d.ts +0 -0
- /package/dist/{src → orbcharts-plugins-basic/src}/multiGrid/plugins/MultiValueAxis.d.ts +0 -0
- /package/dist/{src → orbcharts-plugins-basic/src}/multiGrid/plugins/OverlappingValueAxes.d.ts +0 -0
- /package/dist/{src → orbcharts-plugins-basic/src}/multiGrid/types.d.ts +0 -0
- /package/dist/{src → orbcharts-plugins-basic/src}/multiValue/index.d.ts +0 -0
- /package/dist/{src → orbcharts-plugins-basic/src}/multiValue/plugins/Scatter.d.ts +0 -0
- /package/dist/{src → orbcharts-plugins-basic/src}/multiValue/plugins/ScatterAxes.d.ts +0 -0
- /package/dist/{src → orbcharts-plugins-basic/src}/noneData/defaults.d.ts +0 -0
- /package/dist/{src → orbcharts-plugins-basic/src}/noneData/index.d.ts +0 -0
- /package/dist/{src → orbcharts-plugins-basic/src}/noneData/plugins/Container.d.ts +0 -0
- /package/dist/{src → orbcharts-plugins-basic/src}/noneData/plugins/Tooltip.d.ts +0 -0
- /package/dist/{src → orbcharts-plugins-basic/src}/noneData/types.d.ts +0 -0
- /package/dist/{src → orbcharts-plugins-basic/src}/relationship/index.d.ts +0 -0
- /package/dist/{src → orbcharts-plugins-basic/src}/relationship/plugins/Relationship.d.ts +0 -0
- /package/dist/{src → orbcharts-plugins-basic/src}/series/defaults.d.ts +0 -0
- /package/dist/{src → orbcharts-plugins-basic/src}/series/index.d.ts +0 -0
- /package/dist/{src → orbcharts-plugins-basic/src}/series/plugins/Bubbles.d.ts +0 -0
- /package/dist/{src → orbcharts-plugins-basic/src}/series/plugins/Pie.d.ts +0 -0
- /package/dist/{src → orbcharts-plugins-basic/src}/series/plugins/PieLabels.d.ts +0 -0
- /package/dist/{src → orbcharts-plugins-basic/src}/series/plugins/SeriesLegend.d.ts +0 -0
- /package/dist/{src → orbcharts-plugins-basic/src}/series/plugins/Waffle.d.ts +0 -0
- /package/dist/{src → orbcharts-plugins-basic/src}/series/types.d.ts +0 -0
- /package/dist/{src → orbcharts-plugins-basic/src}/tree/defaults.d.ts +0 -0
- /package/dist/{src → orbcharts-plugins-basic/src}/tree/index.d.ts +0 -0
- /package/dist/{src → orbcharts-plugins-basic/src}/tree/plugins/TreeLegend.d.ts +0 -0
- /package/dist/{src → orbcharts-plugins-basic/src}/tree/plugins/TreeMap.d.ts +0 -0
- /package/dist/{src → orbcharts-plugins-basic/src}/tree/types.d.ts +0 -0
- /package/dist/{src → orbcharts-plugins-basic/src}/utils/commonUtils.d.ts +0 -0
- /package/dist/{src → orbcharts-plugins-basic/src}/utils/d3Graphics.d.ts +0 -0
- /package/dist/{src → orbcharts-plugins-basic/src}/utils/d3Utils.d.ts +0 -0
- /package/dist/{src → orbcharts-plugins-basic/src}/utils/observables.d.ts +0 -0
- /package/dist/{src → orbcharts-plugins-basic/src}/utils/orbchartsUtils.d.ts +0 -0
- /package/dist/{vite.config.d.ts → orbcharts-plugins-basic/vite.config.d.ts} +0 -0
package/src/base/BaseBarStack.ts
CHANGED
@@ -1,882 +1,779 @@
|
|
1
|
-
import * as d3 from 'd3'
|
2
|
-
import {
|
3
|
-
iif,
|
4
|
-
combineLatest,
|
5
|
-
map,
|
6
|
-
switchMap,
|
7
|
-
takeUntil,
|
8
|
-
distinctUntilChanged,
|
9
|
-
Observable,
|
10
|
-
Subject } from 'rxjs'
|
11
|
-
import type { BasePluginFn } from './types'
|
12
|
-
import type {
|
13
|
-
ComputedDatumGrid,
|
14
|
-
ComputedDataGrid,
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
import {
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
}
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
interface
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
//
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
}
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
//
|
106
|
-
//
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
.attr('
|
151
|
-
.attr('
|
152
|
-
.
|
153
|
-
.
|
154
|
-
.
|
155
|
-
.
|
156
|
-
.attr('
|
157
|
-
.
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
//
|
166
|
-
//
|
167
|
-
//
|
168
|
-
//
|
169
|
-
//
|
170
|
-
//
|
171
|
-
//
|
172
|
-
//
|
173
|
-
//
|
174
|
-
//
|
175
|
-
//
|
176
|
-
//
|
177
|
-
//
|
178
|
-
//
|
179
|
-
//
|
180
|
-
//
|
181
|
-
//
|
182
|
-
//
|
183
|
-
//
|
184
|
-
//
|
185
|
-
//
|
186
|
-
//
|
187
|
-
//
|
188
|
-
//
|
189
|
-
//
|
190
|
-
//
|
191
|
-
//
|
192
|
-
//
|
193
|
-
//
|
194
|
-
//
|
195
|
-
//
|
196
|
-
//
|
197
|
-
//
|
198
|
-
//
|
199
|
-
//
|
200
|
-
//
|
201
|
-
//
|
202
|
-
//
|
203
|
-
//
|
204
|
-
//
|
205
|
-
//
|
206
|
-
// .attr('
|
207
|
-
// .
|
208
|
-
// .
|
209
|
-
// .
|
210
|
-
// .
|
211
|
-
// .attr('
|
212
|
-
// .
|
213
|
-
//
|
214
|
-
|
215
|
-
//
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
}
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
}
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
//
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
//
|
394
|
-
// takeUntil(destroy$),
|
395
|
-
//
|
396
|
-
//
|
397
|
-
//
|
398
|
-
//
|
399
|
-
//
|
400
|
-
//
|
401
|
-
//
|
402
|
-
//
|
403
|
-
//
|
404
|
-
//
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
)
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
|
589
|
-
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
}).pipe(
|
605
|
-
takeUntil(destroy$),
|
606
|
-
switchMap(async d => d)
|
607
|
-
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
|
613
|
-
|
614
|
-
|
615
|
-
|
616
|
-
|
617
|
-
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
|
629
|
-
|
630
|
-
|
631
|
-
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
|
636
|
-
|
637
|
-
|
638
|
-
|
639
|
-
|
640
|
-
|
641
|
-
|
642
|
-
|
643
|
-
|
644
|
-
|
645
|
-
|
646
|
-
|
647
|
-
|
648
|
-
|
649
|
-
|
650
|
-
|
651
|
-
|
652
|
-
|
653
|
-
|
654
|
-
|
655
|
-
:
|
656
|
-
|
657
|
-
|
658
|
-
|
659
|
-
|
660
|
-
|
661
|
-
|
662
|
-
|
663
|
-
|
664
|
-
|
665
|
-
|
666
|
-
|
667
|
-
|
668
|
-
|
669
|
-
|
670
|
-
|
671
|
-
|
672
|
-
|
673
|
-
|
674
|
-
|
675
|
-
|
676
|
-
|
677
|
-
|
678
|
-
|
679
|
-
|
680
|
-
|
681
|
-
|
682
|
-
|
683
|
-
|
684
|
-
|
685
|
-
|
686
|
-
|
687
|
-
|
688
|
-
|
689
|
-
|
690
|
-
|
691
|
-
|
692
|
-
|
693
|
-
|
694
|
-
|
695
|
-
|
696
|
-
|
697
|
-
|
698
|
-
|
699
|
-
|
700
|
-
|
701
|
-
|
702
|
-
|
703
|
-
|
704
|
-
|
705
|
-
|
706
|
-
|
707
|
-
|
708
|
-
|
709
|
-
|
710
|
-
|
711
|
-
|
712
|
-
|
713
|
-
|
714
|
-
|
715
|
-
|
716
|
-
|
717
|
-
|
718
|
-
|
719
|
-
|
720
|
-
|
721
|
-
|
722
|
-
|
723
|
-
|
724
|
-
|
725
|
-
|
726
|
-
|
727
|
-
|
728
|
-
|
729
|
-
|
730
|
-
|
731
|
-
|
732
|
-
|
733
|
-
|
734
|
-
|
735
|
-
|
736
|
-
|
737
|
-
|
738
|
-
|
739
|
-
|
740
|
-
|
741
|
-
|
742
|
-
|
743
|
-
|
744
|
-
|
745
|
-
|
746
|
-
|
747
|
-
|
748
|
-
|
749
|
-
|
750
|
-
|
751
|
-
})
|
752
|
-
|
753
|
-
|
754
|
-
)
|
755
|
-
|
756
|
-
|
757
|
-
|
758
|
-
|
759
|
-
|
760
|
-
|
761
|
-
|
762
|
-
|
763
|
-
|
764
|
-
|
765
|
-
|
766
|
-
|
767
|
-
|
768
|
-
|
769
|
-
|
770
|
-
|
771
|
-
|
772
|
-
.
|
773
|
-
|
774
|
-
|
775
|
-
|
776
|
-
|
777
|
-
|
778
|
-
|
779
|
-
highlightTarget: data.highlightTarget,
|
780
|
-
datum,
|
781
|
-
gridIndex: datum.gridIndex,
|
782
|
-
series: data.SeriesDataMap.get(datum.seriesLabel)!,
|
783
|
-
seriesIndex: datum.seriesIndex,
|
784
|
-
seriesLabel: datum.seriesLabel,
|
785
|
-
groups: data.GroupDataMap.get(datum.groupLabel)!,
|
786
|
-
groupIndex: datum.groupIndex,
|
787
|
-
groupLabel: datum.groupLabel,
|
788
|
-
event,
|
789
|
-
data: data.graphicData
|
790
|
-
})
|
791
|
-
})
|
792
|
-
.on('mousemove', (event, datum) => {
|
793
|
-
event.stopPropagation()
|
794
|
-
|
795
|
-
event$.next({
|
796
|
-
type: 'grid',
|
797
|
-
eventName: 'mousemove',
|
798
|
-
pluginName,
|
799
|
-
highlightTarget: data.highlightTarget,
|
800
|
-
datum,
|
801
|
-
gridIndex: datum.gridIndex,
|
802
|
-
series: data.SeriesDataMap.get(datum.seriesLabel)!,
|
803
|
-
seriesIndex: datum.seriesIndex,
|
804
|
-
seriesLabel: datum.seriesLabel,
|
805
|
-
groups: data.GroupDataMap.get(datum.groupLabel)!,
|
806
|
-
groupIndex: datum.groupIndex,
|
807
|
-
groupLabel: datum.groupLabel,
|
808
|
-
event,
|
809
|
-
data: data.graphicData
|
810
|
-
})
|
811
|
-
})
|
812
|
-
.on('mouseout', (event, datum) => {
|
813
|
-
event.stopPropagation()
|
814
|
-
|
815
|
-
event$.next({
|
816
|
-
type: 'grid',
|
817
|
-
eventName: 'mouseout',
|
818
|
-
pluginName,
|
819
|
-
highlightTarget: data.highlightTarget,
|
820
|
-
datum,
|
821
|
-
gridIndex: datum.gridIndex,
|
822
|
-
series: data.SeriesDataMap.get(datum.seriesLabel)!,
|
823
|
-
seriesIndex: datum.seriesIndex,
|
824
|
-
seriesLabel: datum.seriesLabel,
|
825
|
-
groups: data.GroupDataMap.get(datum.groupLabel)!,
|
826
|
-
groupIndex: datum.groupIndex,
|
827
|
-
groupLabel: datum.groupLabel,
|
828
|
-
event,
|
829
|
-
data: data.graphicData
|
830
|
-
})
|
831
|
-
})
|
832
|
-
.on('click', (event, datum) => {
|
833
|
-
event.stopPropagation()
|
834
|
-
|
835
|
-
event$.next({
|
836
|
-
type: 'grid',
|
837
|
-
eventName: 'click',
|
838
|
-
pluginName,
|
839
|
-
highlightTarget: data.highlightTarget,
|
840
|
-
datum,
|
841
|
-
gridIndex: datum.gridIndex,
|
842
|
-
series: data.SeriesDataMap.get(datum.seriesLabel)!,
|
843
|
-
seriesIndex: datum.seriesIndex,
|
844
|
-
seriesLabel: datum.seriesLabel,
|
845
|
-
groups: data.GroupDataMap.get(datum.groupLabel)!,
|
846
|
-
groupIndex: datum.groupIndex,
|
847
|
-
groupLabel: datum.groupLabel,
|
848
|
-
event,
|
849
|
-
data: data.graphicData
|
850
|
-
})
|
851
|
-
})
|
852
|
-
|
853
|
-
barSelection$.next(barSelection!)
|
854
|
-
})
|
855
|
-
|
856
|
-
// const datumList$ = computedData$.pipe(
|
857
|
-
// takeUntil(destroy$),
|
858
|
-
// map(d => d.flat())
|
859
|
-
// )
|
860
|
-
// const highlight$ = highlightObservable({ datumList$, chartParams$, event$: store.event$ })
|
861
|
-
|
862
|
-
combineLatest({
|
863
|
-
barSelection: barSelection$,
|
864
|
-
highlight: gridHighlight$.pipe(
|
865
|
-
map(data => data.map(d => d.id))
|
866
|
-
),
|
867
|
-
fullChartParams: fullChartParams$
|
868
|
-
}).pipe(
|
869
|
-
takeUntil(destroy$),
|
870
|
-
switchMap(async d => d)
|
871
|
-
).subscribe(data => {
|
872
|
-
highlight({
|
873
|
-
selection: data.barSelection,
|
874
|
-
ids: data.highlight,
|
875
|
-
fullChartParams: data.fullChartParams
|
876
|
-
})
|
877
|
-
})
|
878
|
-
|
879
|
-
return () => {
|
880
|
-
destroy$.next(undefined)
|
881
|
-
}
|
1
|
+
import * as d3 from 'd3'
|
2
|
+
import {
|
3
|
+
iif,
|
4
|
+
combineLatest,
|
5
|
+
map,
|
6
|
+
switchMap,
|
7
|
+
takeUntil,
|
8
|
+
distinctUntilChanged,
|
9
|
+
Observable,
|
10
|
+
Subject } from 'rxjs'
|
11
|
+
import type { BasePluginFn } from './types'
|
12
|
+
import type {
|
13
|
+
ComputedDatumGrid,
|
14
|
+
ComputedDataGrid,
|
15
|
+
ComputedLayoutDatumGrid,
|
16
|
+
ComputedLayoutDataGrid,
|
17
|
+
DataFormatterGrid,
|
18
|
+
EventGrid,
|
19
|
+
ChartParams,
|
20
|
+
GridContainerPosition,
|
21
|
+
Layout,
|
22
|
+
TransformData } from '@orbcharts/core'
|
23
|
+
import { getD3TransitionEase } from '../utils/d3Utils'
|
24
|
+
import { getClassName, getUniID } from '../utils/orbchartsUtils'
|
25
|
+
import { gridSelectionsObservable } from '../grid/gridObservables'
|
26
|
+
import { shareReplay } from 'rxjs/operators'
|
27
|
+
|
28
|
+
export interface BaseBarStackParams {
|
29
|
+
barWidth: number
|
30
|
+
barGroupPadding: number
|
31
|
+
barRadius: number | boolean
|
32
|
+
}
|
33
|
+
|
34
|
+
interface BaseBarStackContext {
|
35
|
+
selection: d3.Selection<any, unknown, any, unknown>
|
36
|
+
computedData$: Observable<ComputedDataGrid>
|
37
|
+
computedLayoutData$: Observable<ComputedLayoutDataGrid>
|
38
|
+
visibleComputedData$: Observable<ComputedDatumGrid[][]>
|
39
|
+
visibleComputedLayoutData$: Observable<ComputedLayoutDataGrid>
|
40
|
+
seriesLabels$: Observable<string[]>
|
41
|
+
SeriesDataMap$: Observable<Map<string, ComputedDatumGrid[]>>
|
42
|
+
GroupDataMap$: Observable<Map<string, ComputedDatumGrid[]>>
|
43
|
+
fullParams$: Observable<BaseBarStackParams>
|
44
|
+
fullDataFormatter$: Observable<DataFormatterGrid>
|
45
|
+
fullChartParams$: Observable<ChartParams>
|
46
|
+
gridAxesTransform$: Observable<TransformData>
|
47
|
+
gridGraphicTransform$: Observable<TransformData>
|
48
|
+
gridGraphicReverseScale$: Observable<[number, number][]>
|
49
|
+
gridAxesSize$: Observable<{
|
50
|
+
width: number;
|
51
|
+
height: number;
|
52
|
+
}>
|
53
|
+
gridHighlight$: Observable<ComputedDatumGrid[]>
|
54
|
+
gridContainerPosition$: Observable<GridContainerPosition[]>
|
55
|
+
isSeriesSeprate$: Observable<boolean>
|
56
|
+
event$: Subject<EventGrid>
|
57
|
+
}
|
58
|
+
|
59
|
+
|
60
|
+
interface GraphicDatum extends ComputedLayoutDatumGrid {
|
61
|
+
_barStartY: number // bar的起點y座標
|
62
|
+
_barHeight: number // bar的高度
|
63
|
+
}
|
64
|
+
|
65
|
+
interface RenderBarParams {
|
66
|
+
graphicGSelection: d3.Selection<SVGGElement, unknown, any, any>
|
67
|
+
rectClassName: string
|
68
|
+
barData: GraphicDatum[][]
|
69
|
+
zeroY: number
|
70
|
+
groupLabels: string[]
|
71
|
+
// barScale: d3.ScalePoint<string>
|
72
|
+
params: BaseBarStackParams
|
73
|
+
chartParams: ChartParams
|
74
|
+
barWidth: number
|
75
|
+
transformedBarRadius: [number, number][]
|
76
|
+
delayGroup: number
|
77
|
+
transitionItem: number
|
78
|
+
isSeriesSeprate: boolean
|
79
|
+
}
|
80
|
+
|
81
|
+
type ClipPathDatum = {
|
82
|
+
id: string;
|
83
|
+
// x: number;
|
84
|
+
// y: number;
|
85
|
+
width: number;
|
86
|
+
height: number;
|
87
|
+
}
|
88
|
+
|
89
|
+
// const pluginName = 'BarStack'
|
90
|
+
// const rectClassName = getClassName(pluginName, 'rect')
|
91
|
+
// group的delay在動畫中的佔比(剩餘部份的時間為圖形本身的動畫時間,因為delay時間和最後一個group的動畫時間加總為1)
|
92
|
+
const groupDelayProportionOfDuration = 0.3
|
93
|
+
|
94
|
+
function calcBarWidth ({ axisWidth, groupAmount, barGroupPadding = 0 }: {
|
95
|
+
axisWidth: number
|
96
|
+
groupAmount: number
|
97
|
+
barGroupPadding: number
|
98
|
+
}) {
|
99
|
+
const eachGroupWidth = axisWidth / (groupAmount - 1)
|
100
|
+
const width = eachGroupWidth - barGroupPadding
|
101
|
+
return width > 1 ? width : 1
|
102
|
+
|
103
|
+
}
|
104
|
+
|
105
|
+
// function makeBarScale (barWidth: number, seriesLabels: string[], params: BarStackParams) {
|
106
|
+
// const barHalfWidth = barWidth! / 2
|
107
|
+
// const barGroupWidth = barWidth * seriesLabels.length + params.barPadding! * seriesLabels.length
|
108
|
+
// return d3.scalePoint()
|
109
|
+
// .domain(seriesLabels)
|
110
|
+
// .range([-barGroupWidth / 2 + barHalfWidth, barGroupWidth / 2 - barHalfWidth])
|
111
|
+
// }
|
112
|
+
|
113
|
+
function calcDelayGroup (barGroupAmount: number, totalDuration: number) {
|
114
|
+
if (barGroupAmount <= 1) {
|
115
|
+
// 一筆內計算會出錯所以不算
|
116
|
+
return 0
|
117
|
+
}
|
118
|
+
return totalDuration / (barGroupAmount - 1) * groupDelayProportionOfDuration // 依group數量計算
|
119
|
+
}
|
120
|
+
|
121
|
+
function calctransitionItem (barGroupAmount: number, totalDuration: number) {
|
122
|
+
if (barGroupAmount <= 1) {
|
123
|
+
// 一筆內不會有delay
|
124
|
+
return totalDuration
|
125
|
+
}
|
126
|
+
return totalDuration * (1 - groupDelayProportionOfDuration) // delay後剩餘的時間
|
127
|
+
}
|
128
|
+
|
129
|
+
function renderRectBars ({ graphicGSelection, rectClassName, barData, zeroY, groupLabels, params, chartParams, barWidth, transformedBarRadius, delayGroup, transitionItem, isSeriesSeprate }: RenderBarParams) {
|
130
|
+
|
131
|
+
const barHalfWidth = barWidth! / 2
|
132
|
+
|
133
|
+
graphicGSelection
|
134
|
+
.each((seriesData, seriesIndex, g) => {
|
135
|
+
d3.select(g[seriesIndex])
|
136
|
+
.selectAll<SVGGElement, ComputedDatumGrid>(`rect.${rectClassName}`)
|
137
|
+
.data(barData[seriesIndex] ?? [], d => d.id)
|
138
|
+
.join(
|
139
|
+
enter => {
|
140
|
+
// console.log('enter')
|
141
|
+
return enter
|
142
|
+
.append('rect')
|
143
|
+
.classed(rectClassName, true)
|
144
|
+
.attr('cursor', 'pointer')
|
145
|
+
.attr('height', d => 0)
|
146
|
+
},
|
147
|
+
update => update,
|
148
|
+
exit => exit.remove()
|
149
|
+
)
|
150
|
+
.attr('transform', (d, i) => `translate(${(d ? d.axisX : 0) - barHalfWidth}, ${0})`)
|
151
|
+
.attr('fill', d => d.color)
|
152
|
+
.attr('y', d => zeroY)
|
153
|
+
.attr('x', d =>0)
|
154
|
+
.attr('width', barWidth!)
|
155
|
+
.attr('rx', transformedBarRadius[seriesIndex][0] ?? 1)
|
156
|
+
.attr('ry', transformedBarRadius[seriesIndex][1] ?? 1)
|
157
|
+
.transition()
|
158
|
+
.duration(transitionItem)
|
159
|
+
.ease(getD3TransitionEase(chartParams.transitionEase))
|
160
|
+
.delay((d, i) => d.groupIndex * delayGroup)
|
161
|
+
.attr('y', d => d._barStartY)
|
162
|
+
.attr('height', d => Math.abs(d._barHeight))
|
163
|
+
})
|
164
|
+
|
165
|
+
// const barGroup = graphicGSelection
|
166
|
+
// .selectAll<SVGGElement, ComputedDatumGrid[]>(`g.${gClassName}`)
|
167
|
+
// .data(data, (d, i) => groupLabels[i])
|
168
|
+
// .join(
|
169
|
+
// enter => {
|
170
|
+
// return enter
|
171
|
+
// .append('g')
|
172
|
+
// .classed(gClassName, true)
|
173
|
+
// .attr('cursor', 'pointer')
|
174
|
+
// },
|
175
|
+
// update => update,
|
176
|
+
// exit => exit.remove()
|
177
|
+
// )
|
178
|
+
// .attr('transform', (d, i) => `translate(${d[0] ? d[0].axisX : 0}, ${0})`)
|
179
|
+
// .each((d, i, g) => {
|
180
|
+
// const bars = d3.select(g[i])
|
181
|
+
// .selectAll<SVGGElement, ComputedDatumGrid>('g')
|
182
|
+
// .data(d, _d => _d.id)
|
183
|
+
// .join(
|
184
|
+
// enter => {
|
185
|
+
// return enter
|
186
|
+
// .append('g')
|
187
|
+
// .classed(gContentClassName, true)
|
188
|
+
// },
|
189
|
+
// update => update,
|
190
|
+
// exit => exit.remove()
|
191
|
+
// )
|
192
|
+
// .each((_d, _i, _g) => {
|
193
|
+
// const rect = d3.select(_g[_i])
|
194
|
+
// .selectAll<SVGRectElement, ComputedDatumGrid>('rect')
|
195
|
+
// .data([_d], _d => _d.id)
|
196
|
+
// .join(
|
197
|
+
// enter => {
|
198
|
+
// return enter
|
199
|
+
// .append('rect')
|
200
|
+
// .attr('y', d => zeroY)
|
201
|
+
// .attr('height', d => 0)
|
202
|
+
// },
|
203
|
+
// update => update,
|
204
|
+
// exit => exit.remove()
|
205
|
+
// )
|
206
|
+
// .attr('rx', transformedBarRadius[0])
|
207
|
+
// .attr('ry', transformedBarRadius[1])
|
208
|
+
// .attr('fill', d => d.color)
|
209
|
+
// .attr('transform', `translate(${-barHalfWidth}, 0)`)
|
210
|
+
// .attr('x', d => 0)
|
211
|
+
// .attr('width', barWidth!)
|
212
|
+
// .transition()
|
213
|
+
// .duration(transitionItem)
|
214
|
+
// .ease(getD3TransitionEase(chartParams.transitionEase))
|
215
|
+
// .delay((d, i) => d.groupIndex * delayGroup)
|
216
|
+
// .attr('y', d => d._barStartY)
|
217
|
+
// .attr('height', d => Math.abs(d._barHeight))
|
218
|
+
// })
|
219
|
+
|
220
|
+
// })
|
221
|
+
|
222
|
+
const graphicBarSelection: d3.Selection<SVGRectElement, ComputedDatumGrid, SVGGElement, unknown> = graphicGSelection.selectAll(`rect.${rectClassName}`)
|
223
|
+
|
224
|
+
|
225
|
+
return graphicBarSelection
|
226
|
+
}
|
227
|
+
|
228
|
+
function renderClipPath ({ defsSelection, clipPathData }: {
|
229
|
+
defsSelection: d3.Selection<SVGDefsElement, any, any, any>
|
230
|
+
clipPathData: ClipPathDatum[]
|
231
|
+
}) {
|
232
|
+
const clipPath = defsSelection
|
233
|
+
.selectAll<SVGClipPathElement, Layout>('clipPath')
|
234
|
+
.data(clipPathData)
|
235
|
+
.join(
|
236
|
+
enter => {
|
237
|
+
return enter
|
238
|
+
.append('clipPath')
|
239
|
+
},
|
240
|
+
update => update,
|
241
|
+
exit => exit.remove()
|
242
|
+
)
|
243
|
+
.attr('id', d => d.id)
|
244
|
+
.each((d, i, g) => {
|
245
|
+
const rect = d3.select(g[i])
|
246
|
+
.selectAll<SVGRectElement, typeof d>('rect')
|
247
|
+
.data([d])
|
248
|
+
.join(
|
249
|
+
enter => {
|
250
|
+
return enter
|
251
|
+
.append('rect')
|
252
|
+
},
|
253
|
+
update => update,
|
254
|
+
exit => exit.remove()
|
255
|
+
)
|
256
|
+
.attr('x', 0)
|
257
|
+
.attr('y', 0)
|
258
|
+
.attr('width', _d => _d.width)
|
259
|
+
.attr('height', _d => _d.height)
|
260
|
+
})
|
261
|
+
}
|
262
|
+
|
263
|
+
function highlight ({ selection, ids, fullChartParams }: {
|
264
|
+
selection: d3.Selection<any, ComputedDatumGrid, any, any>
|
265
|
+
ids: string[]
|
266
|
+
fullChartParams: ChartParams
|
267
|
+
}) {
|
268
|
+
selection.interrupt('highlight')
|
269
|
+
|
270
|
+
if (!ids.length) {
|
271
|
+
// remove highlight
|
272
|
+
selection
|
273
|
+
.transition('highlight')
|
274
|
+
.duration(200)
|
275
|
+
.style('opacity', 1)
|
276
|
+
return
|
277
|
+
}
|
278
|
+
|
279
|
+
selection
|
280
|
+
.each((d, i, n) => {
|
281
|
+
if (ids.includes(d.id)) {
|
282
|
+
d3.select(n[i])
|
283
|
+
.style('opacity', 1)
|
284
|
+
} else {
|
285
|
+
d3.select(n[i])
|
286
|
+
.style('opacity', fullChartParams.styles.unhighlightedOpacity)
|
287
|
+
}
|
288
|
+
})
|
289
|
+
}
|
290
|
+
|
291
|
+
|
292
|
+
export const createBaseBarStack: BasePluginFn<BaseBarStackContext> = (pluginName: string, {
|
293
|
+
selection,
|
294
|
+
computedData$,
|
295
|
+
computedLayoutData$,
|
296
|
+
visibleComputedData$,
|
297
|
+
visibleComputedLayoutData$,
|
298
|
+
seriesLabels$,
|
299
|
+
SeriesDataMap$,
|
300
|
+
GroupDataMap$,
|
301
|
+
fullParams$,
|
302
|
+
fullDataFormatter$,
|
303
|
+
fullChartParams$,
|
304
|
+
gridAxesTransform$,
|
305
|
+
gridGraphicTransform$,
|
306
|
+
gridGraphicReverseScale$,
|
307
|
+
gridAxesSize$,
|
308
|
+
gridHighlight$,
|
309
|
+
gridContainerPosition$,
|
310
|
+
isSeriesSeprate$,
|
311
|
+
event$
|
312
|
+
}) => {
|
313
|
+
|
314
|
+
const destroy$ = new Subject()
|
315
|
+
|
316
|
+
const clipPathID = getUniID(pluginName, 'clipPath-box')
|
317
|
+
const rectClassName = getClassName(pluginName, 'rect')
|
318
|
+
|
319
|
+
const {
|
320
|
+
seriesSelection$,
|
321
|
+
axesSelection$,
|
322
|
+
defsSelection$,
|
323
|
+
graphicGSelection$
|
324
|
+
} = gridSelectionsObservable({
|
325
|
+
selection,
|
326
|
+
pluginName,
|
327
|
+
clipPathID,
|
328
|
+
seriesLabels$,
|
329
|
+
gridContainerPosition$,
|
330
|
+
gridAxesTransform$,
|
331
|
+
gridGraphicTransform$
|
332
|
+
})
|
333
|
+
|
334
|
+
|
335
|
+
const zeroY$ = visibleComputedLayoutData$.pipe(
|
336
|
+
takeUntil(destroy$),
|
337
|
+
map(d => d[0] && d[0][0]
|
338
|
+
? d[0][0].axisY - d[0][0].axisYFromZero
|
339
|
+
: 0),
|
340
|
+
distinctUntilChanged()
|
341
|
+
)
|
342
|
+
|
343
|
+
const barWidth$ = combineLatest({
|
344
|
+
computedData: computedData$,
|
345
|
+
// visibleComputedData: visibleComputedData$,
|
346
|
+
params: fullParams$,
|
347
|
+
axisSize: gridAxesSize$,
|
348
|
+
isSeriesSeprate: isSeriesSeprate$
|
349
|
+
}).pipe(
|
350
|
+
takeUntil(destroy$),
|
351
|
+
switchMap(async d => d),
|
352
|
+
map(data => {
|
353
|
+
const barWidth = data.params.barWidth
|
354
|
+
? data.params.barWidth
|
355
|
+
: calcBarWidth({
|
356
|
+
axisWidth: data.axisSize.width,
|
357
|
+
groupAmount: data.computedData[0] ? data.computedData[0].length : 0,
|
358
|
+
barGroupPadding: data.params.barGroupPadding
|
359
|
+
})
|
360
|
+
return barWidth
|
361
|
+
}),
|
362
|
+
distinctUntilChanged()
|
363
|
+
)
|
364
|
+
|
365
|
+
// 圓角的值 [rx, ry]
|
366
|
+
const transformedBarRadius$: Observable<[number, number][]> = combineLatest({
|
367
|
+
computedData: computedData$,
|
368
|
+
// gridGraphicTransform: gridGraphicTransform$,
|
369
|
+
barWidth: barWidth$,
|
370
|
+
params: fullParams$,
|
371
|
+
gridGraphicReverseScale: gridGraphicReverseScale$
|
372
|
+
}).pipe(
|
373
|
+
takeUntil(destroy$),
|
374
|
+
switchMap(async data => data),
|
375
|
+
map(data => {
|
376
|
+
const barHalfWidth = data.barWidth! / 2
|
377
|
+
const radius = data.params.barRadius === true ? barHalfWidth
|
378
|
+
: data.params.barRadius === false ? 0
|
379
|
+
: typeof data.params.barRadius == 'number' ? data.params.barRadius
|
380
|
+
: 0
|
381
|
+
|
382
|
+
return data.computedData.map((series, seriesIndex) => {
|
383
|
+
const gridGraphicReverseScale = data.gridGraphicReverseScale[seriesIndex] ?? data.gridGraphicReverseScale[0]
|
384
|
+
|
385
|
+
const transformedRx = radius * gridGraphicReverseScale[0]
|
386
|
+
const transformedRy = radius * gridGraphicReverseScale[1]
|
387
|
+
|
388
|
+
return [transformedRx, transformedRy]
|
389
|
+
})
|
390
|
+
})
|
391
|
+
)
|
392
|
+
|
393
|
+
// const seriesLabels$ = visibleComputedData$.pipe(
|
394
|
+
// takeUntil(destroy$),
|
395
|
+
// map(data => {
|
396
|
+
// const SeriesLabelSet: Set<string> = new Set()
|
397
|
+
// data.forEach(d => {
|
398
|
+
// d.forEach(_d => {
|
399
|
+
// SeriesLabelSet.add(_d.seriesLabel)
|
400
|
+
// })
|
401
|
+
// })
|
402
|
+
// return Array.from(SeriesLabelSet)
|
403
|
+
// })
|
404
|
+
// )
|
405
|
+
|
406
|
+
const groupLabels$ = visibleComputedData$.pipe(
|
407
|
+
takeUntil(destroy$),
|
408
|
+
map(data => {
|
409
|
+
const GroupLabelSet: Set<string> = new Set()
|
410
|
+
data.forEach(d => {
|
411
|
+
d.forEach(_d => {
|
412
|
+
GroupLabelSet.add(_d.groupLabel)
|
413
|
+
})
|
414
|
+
})
|
415
|
+
return Array.from(GroupLabelSet)
|
416
|
+
}),
|
417
|
+
shareReplay(1)
|
418
|
+
)
|
419
|
+
|
420
|
+
const transitionDuration$ = fullChartParams$.pipe(
|
421
|
+
takeUntil(destroy$),
|
422
|
+
map(d => d.transitionDuration),
|
423
|
+
distinctUntilChanged()
|
424
|
+
)
|
425
|
+
|
426
|
+
const delayGroup$ = new Observable<number>(subscriber => {
|
427
|
+
combineLatest({
|
428
|
+
groupLabels: groupLabels$,
|
429
|
+
transitionDuration: transitionDuration$,
|
430
|
+
}).pipe(
|
431
|
+
switchMap(async d => d)
|
432
|
+
).subscribe(data => {
|
433
|
+
const delay = calcDelayGroup(data.groupLabels.length, data.transitionDuration)
|
434
|
+
subscriber.next(delay)
|
435
|
+
})
|
436
|
+
}).pipe(
|
437
|
+
takeUntil(destroy$),
|
438
|
+
distinctUntilChanged()
|
439
|
+
)
|
440
|
+
|
441
|
+
const transitionItem$ = new Observable<number>(subscriber => {
|
442
|
+
combineLatest({
|
443
|
+
groupLabels: groupLabels$,
|
444
|
+
transitionDuration: transitionDuration$
|
445
|
+
}).pipe(
|
446
|
+
switchMap(async d => d)
|
447
|
+
).subscribe(data => {
|
448
|
+
const transition = calctransitionItem(data.groupLabels.length, data.transitionDuration)
|
449
|
+
subscriber.next(transition)
|
450
|
+
})
|
451
|
+
}).pipe(
|
452
|
+
takeUntil(destroy$),
|
453
|
+
distinctUntilChanged()
|
454
|
+
)
|
455
|
+
|
456
|
+
// const transposedVisibleData$: Observable<ComputedDataGrid> = visibleComputedData$.pipe(
|
457
|
+
// takeUntil(destroy$),
|
458
|
+
// map(data => {
|
459
|
+
// console.log('visibleComputedData', data)
|
460
|
+
// // 取得原始陣列的維度
|
461
|
+
// const rows = data.length;
|
462
|
+
// const cols = data.reduce((prev, current) => {
|
463
|
+
// return Math.max(prev, current.length)
|
464
|
+
// }, 0)
|
465
|
+
|
466
|
+
// // 初始化轉換後的陣列
|
467
|
+
// const transposedArray = new Array(cols).fill(null).map(() => new Array(rows).fill(null))
|
468
|
+
|
469
|
+
// // 遍歷原始陣列,進行轉換
|
470
|
+
// for (let i = 0; i < rows; i++) {
|
471
|
+
// for (let j = 0; j < cols; j++) {
|
472
|
+
// transposedArray[j][i] = data[i][j]
|
473
|
+
// }
|
474
|
+
// }
|
475
|
+
// return transposedArray
|
476
|
+
// })
|
477
|
+
// )
|
478
|
+
|
479
|
+
const groupScaleDomain$ = combineLatest({
|
480
|
+
computedData: computedData$,
|
481
|
+
dataFormatter: fullDataFormatter$,
|
482
|
+
}).pipe(
|
483
|
+
takeUntil(destroy$),
|
484
|
+
switchMap(async d => d),
|
485
|
+
map(data => {
|
486
|
+
const groupMin = 0
|
487
|
+
const groupMax = data.computedData[0] ? data.computedData[0].length - 1 : 0
|
488
|
+
const groupScaleDomainMin = data.dataFormatter.grid.groupAxis.scaleDomain[0] === 'auto'
|
489
|
+
? groupMin // - data.dataFormatter.grid.groupAxis.scalePadding
|
490
|
+
: data.dataFormatter.grid.groupAxis.scaleDomain[0] as number // - data.dataFormatter.grid.groupAxis.scalePadding
|
491
|
+
const groupScaleDomainMax = data.dataFormatter.grid.groupAxis.scaleDomain[1] === 'auto'
|
492
|
+
? groupMax // + data.dataFormatter.grid.groupAxis.scalePadding
|
493
|
+
: data.dataFormatter.grid.groupAxis.scaleDomain[1] as number // + data.dataFormatter.grid.groupAxis.scalePadding
|
494
|
+
|
495
|
+
return [groupScaleDomainMin, groupScaleDomainMax]
|
496
|
+
})
|
497
|
+
)
|
498
|
+
|
499
|
+
// 堆疊後的高度對應圖軸的比例(最大值/最大值所在group的總和)
|
500
|
+
const yRatio$ = combineLatest({
|
501
|
+
visibleComputedLayoutData: visibleComputedLayoutData$,
|
502
|
+
groupScaleDomain: groupScaleDomain$
|
503
|
+
}).pipe(
|
504
|
+
takeUntil(destroy$),
|
505
|
+
switchMap(async d => d),
|
506
|
+
map(data => {
|
507
|
+
const groupScaleDomainMin = data.groupScaleDomain[0]
|
508
|
+
const groupScaleDomainMax = data.groupScaleDomain[1]
|
509
|
+
// 只選取group篩選範圍內的資料
|
510
|
+
const filteredData = data.visibleComputedLayoutData
|
511
|
+
.map(d => {
|
512
|
+
return d.filter((_d, i) => {
|
513
|
+
return _d.groupIndex >= groupScaleDomainMin && _d.groupIndex <= groupScaleDomainMax
|
514
|
+
})
|
515
|
+
})
|
516
|
+
|
517
|
+
const filteredDataList = filteredData.flat()
|
518
|
+
if (filteredDataList.length <= 1) {
|
519
|
+
return 1
|
520
|
+
}
|
521
|
+
|
522
|
+
const maxValueDatum = filteredDataList.reduce((max, current) => {
|
523
|
+
return current.value > max.value ? current : max;
|
524
|
+
}, filteredDataList[0])
|
525
|
+
const maxValueGroupIndex = maxValueDatum.groupIndex
|
526
|
+
const maxValueGroupSum = filteredDataList
|
527
|
+
.filter(d => d.groupIndex === maxValueGroupIndex)
|
528
|
+
.reduce((sum, current) => {
|
529
|
+
return sum + current.value
|
530
|
+
}, 0)
|
531
|
+
return maxValueDatum.value / maxValueGroupSum
|
532
|
+
})
|
533
|
+
)
|
534
|
+
|
535
|
+
const stackedData$ = combineLatest({
|
536
|
+
computedLayoutData: computedLayoutData$,
|
537
|
+
yRatio: yRatio$,
|
538
|
+
zeroY: zeroY$
|
539
|
+
}).pipe(
|
540
|
+
takeUntil(destroy$),
|
541
|
+
map(data => {
|
542
|
+
let accYArr: number[] = data.computedLayoutData[0]
|
543
|
+
? data.computedLayoutData[0].map(() => data.zeroY)
|
544
|
+
: []
|
545
|
+
return data.computedLayoutData.map((series, seriesIndex) => {
|
546
|
+
return series.map((datum, groupIndex) => {
|
547
|
+
const _barStartY = accYArr[groupIndex] // 前一次的累加高度
|
548
|
+
let _barHeight = 0
|
549
|
+
if (datum.visible) {
|
550
|
+
_barHeight = datum.axisYFromZero * data.yRatio
|
551
|
+
accYArr[groupIndex] = accYArr[groupIndex] + _barHeight // 累加高度
|
552
|
+
}
|
553
|
+
return <GraphicDatum>{
|
554
|
+
...datum,
|
555
|
+
_barStartY,
|
556
|
+
_barHeight
|
557
|
+
}
|
558
|
+
})
|
559
|
+
})
|
560
|
+
// return data.computedData.map(d => {
|
561
|
+
// let accY = data.zeroY
|
562
|
+
// return d.map(_d => {
|
563
|
+
// const _barStartY = accY
|
564
|
+
// const _barHeight = _d.axisYFromZero * data.yRatio
|
565
|
+
// accY = accY + _barHeight
|
566
|
+
// return <GraphicDatum>{
|
567
|
+
// ..._d,
|
568
|
+
// _barStartY,
|
569
|
+
// _barHeight
|
570
|
+
// }
|
571
|
+
// })
|
572
|
+
// })
|
573
|
+
})
|
574
|
+
)
|
575
|
+
|
576
|
+
const noneStackedData$ = combineLatest({
|
577
|
+
computedLayoutData: computedLayoutData$,
|
578
|
+
// yRatio: yRatio$,
|
579
|
+
zeroY: zeroY$
|
580
|
+
}).pipe(
|
581
|
+
takeUntil(destroy$),
|
582
|
+
map(data => {
|
583
|
+
return data.computedLayoutData.map((series, seriesIndex) => {
|
584
|
+
return series.map((datum, groupIndex) => {
|
585
|
+
return <GraphicDatum>{
|
586
|
+
...datum,
|
587
|
+
_barStartY: data.zeroY,
|
588
|
+
_barHeight: datum.axisYFromZero
|
589
|
+
}
|
590
|
+
})
|
591
|
+
})
|
592
|
+
})
|
593
|
+
)
|
594
|
+
|
595
|
+
const graphicData$ = isSeriesSeprate$.pipe(
|
596
|
+
switchMap(isSeriesSeprate => {
|
597
|
+
return iif(() => isSeriesSeprate, noneStackedData$, stackedData$)
|
598
|
+
})
|
599
|
+
)
|
600
|
+
|
601
|
+
combineLatest({
|
602
|
+
defsSelection: defsSelection$,
|
603
|
+
gridAxesSize: gridAxesSize$,
|
604
|
+
}).pipe(
|
605
|
+
takeUntil(destroy$),
|
606
|
+
switchMap(async d => d)
|
607
|
+
).subscribe(data => {
|
608
|
+
const clipPathData = [{
|
609
|
+
id: clipPathID,
|
610
|
+
width: data.gridAxesSize.width,
|
611
|
+
height: data.gridAxesSize.height
|
612
|
+
}]
|
613
|
+
renderClipPath({
|
614
|
+
defsSelection: data.defsSelection,
|
615
|
+
clipPathData
|
616
|
+
})
|
617
|
+
})
|
618
|
+
|
619
|
+
const highlightTarget$ = fullChartParams$.pipe(
|
620
|
+
takeUntil(destroy$),
|
621
|
+
map(d => d.highlightTarget),
|
622
|
+
distinctUntilChanged()
|
623
|
+
)
|
624
|
+
|
625
|
+
const barSelection$ = combineLatest({
|
626
|
+
graphicGSelection: graphicGSelection$,
|
627
|
+
graphicData: graphicData$,
|
628
|
+
zeroY: zeroY$,
|
629
|
+
groupLabels: groupLabels$,
|
630
|
+
// barScale: barScale$,
|
631
|
+
params: fullParams$,
|
632
|
+
chartParams: fullChartParams$,
|
633
|
+
highlightTarget: highlightTarget$,
|
634
|
+
barWidth: barWidth$,
|
635
|
+
transformedBarRadius: transformedBarRadius$,
|
636
|
+
delayGroup: delayGroup$,
|
637
|
+
transitionItem: transitionItem$,
|
638
|
+
isSeriesSeprate: isSeriesSeprate$
|
639
|
+
}).pipe(
|
640
|
+
takeUntil(destroy$),
|
641
|
+
switchMap(async (d) => d),
|
642
|
+
map(data => {
|
643
|
+
return renderRectBars({
|
644
|
+
graphicGSelection: data.graphicGSelection,
|
645
|
+
rectClassName,
|
646
|
+
barData: data.graphicData,
|
647
|
+
zeroY: data.zeroY,
|
648
|
+
groupLabels: data.groupLabels,
|
649
|
+
// barScale: data.barScale,
|
650
|
+
params: data.params,
|
651
|
+
chartParams: data.chartParams,
|
652
|
+
barWidth: data.barWidth,
|
653
|
+
transformedBarRadius: data.transformedBarRadius,
|
654
|
+
delayGroup: data.delayGroup,
|
655
|
+
transitionItem: data.transitionItem,
|
656
|
+
isSeriesSeprate: data.isSeriesSeprate
|
657
|
+
})
|
658
|
+
})
|
659
|
+
)
|
660
|
+
|
661
|
+
combineLatest({
|
662
|
+
barSelection: barSelection$,
|
663
|
+
computedData: computedData$,
|
664
|
+
highlightTarget: highlightTarget$,
|
665
|
+
SeriesDataMap: SeriesDataMap$,
|
666
|
+
GroupDataMap: GroupDataMap$,
|
667
|
+
}).subscribe(data => {
|
668
|
+
|
669
|
+
data.barSelection!
|
670
|
+
.on('mouseover', (event, datum) => {
|
671
|
+
event.stopPropagation()
|
672
|
+
|
673
|
+
event$.next({
|
674
|
+
type: 'grid',
|
675
|
+
eventName: 'mouseover',
|
676
|
+
pluginName,
|
677
|
+
highlightTarget: data.highlightTarget,
|
678
|
+
datum,
|
679
|
+
gridIndex: datum.gridIndex,
|
680
|
+
series: data.SeriesDataMap.get(datum.seriesLabel)!,
|
681
|
+
seriesIndex: datum.seriesIndex,
|
682
|
+
seriesLabel: datum.seriesLabel,
|
683
|
+
groups: data.GroupDataMap.get(datum.groupLabel)!,
|
684
|
+
groupIndex: datum.groupIndex,
|
685
|
+
groupLabel: datum.groupLabel,
|
686
|
+
event,
|
687
|
+
data: data.computedData
|
688
|
+
})
|
689
|
+
})
|
690
|
+
.on('mousemove', (event, datum) => {
|
691
|
+
event.stopPropagation()
|
692
|
+
|
693
|
+
event$.next({
|
694
|
+
type: 'grid',
|
695
|
+
eventName: 'mousemove',
|
696
|
+
pluginName,
|
697
|
+
highlightTarget: data.highlightTarget,
|
698
|
+
datum,
|
699
|
+
gridIndex: datum.gridIndex,
|
700
|
+
series: data.SeriesDataMap.get(datum.seriesLabel)!,
|
701
|
+
seriesIndex: datum.seriesIndex,
|
702
|
+
seriesLabel: datum.seriesLabel,
|
703
|
+
groups: data.GroupDataMap.get(datum.groupLabel)!,
|
704
|
+
groupIndex: datum.groupIndex,
|
705
|
+
groupLabel: datum.groupLabel,
|
706
|
+
event,
|
707
|
+
data: data.computedData
|
708
|
+
})
|
709
|
+
})
|
710
|
+
.on('mouseout', (event, datum) => {
|
711
|
+
event.stopPropagation()
|
712
|
+
|
713
|
+
event$.next({
|
714
|
+
type: 'grid',
|
715
|
+
eventName: 'mouseout',
|
716
|
+
pluginName,
|
717
|
+
highlightTarget: data.highlightTarget,
|
718
|
+
datum,
|
719
|
+
gridIndex: datum.gridIndex,
|
720
|
+
series: data.SeriesDataMap.get(datum.seriesLabel)!,
|
721
|
+
seriesIndex: datum.seriesIndex,
|
722
|
+
seriesLabel: datum.seriesLabel,
|
723
|
+
groups: data.GroupDataMap.get(datum.groupLabel)!,
|
724
|
+
groupIndex: datum.groupIndex,
|
725
|
+
groupLabel: datum.groupLabel,
|
726
|
+
event,
|
727
|
+
data: data.computedData
|
728
|
+
})
|
729
|
+
})
|
730
|
+
.on('click', (event, datum) => {
|
731
|
+
event.stopPropagation()
|
732
|
+
|
733
|
+
event$.next({
|
734
|
+
type: 'grid',
|
735
|
+
eventName: 'click',
|
736
|
+
pluginName,
|
737
|
+
highlightTarget: data.highlightTarget,
|
738
|
+
datum,
|
739
|
+
gridIndex: datum.gridIndex,
|
740
|
+
series: data.SeriesDataMap.get(datum.seriesLabel)!,
|
741
|
+
seriesIndex: datum.seriesIndex,
|
742
|
+
seriesLabel: datum.seriesLabel,
|
743
|
+
groups: data.GroupDataMap.get(datum.groupLabel)!,
|
744
|
+
groupIndex: datum.groupIndex,
|
745
|
+
groupLabel: datum.groupLabel,
|
746
|
+
event,
|
747
|
+
data: data.computedData
|
748
|
+
})
|
749
|
+
})
|
750
|
+
|
751
|
+
})
|
752
|
+
|
753
|
+
// const datumList$ = computedData$.pipe(
|
754
|
+
// takeUntil(destroy$),
|
755
|
+
// map(d => d.flat())
|
756
|
+
// )
|
757
|
+
// const highlight$ = highlightObservable({ datumList$, chartParams$, event$: store.event$ })
|
758
|
+
|
759
|
+
combineLatest({
|
760
|
+
barSelection: barSelection$,
|
761
|
+
highlight: gridHighlight$.pipe(
|
762
|
+
map(data => data.map(d => d.id))
|
763
|
+
),
|
764
|
+
fullChartParams: fullChartParams$
|
765
|
+
}).pipe(
|
766
|
+
takeUntil(destroy$),
|
767
|
+
switchMap(async d => d)
|
768
|
+
).subscribe(data => {
|
769
|
+
highlight({
|
770
|
+
selection: data.barSelection,
|
771
|
+
ids: data.highlight,
|
772
|
+
fullChartParams: data.fullChartParams
|
773
|
+
})
|
774
|
+
})
|
775
|
+
|
776
|
+
return () => {
|
777
|
+
destroy$.next(undefined)
|
778
|
+
}
|
882
779
|
}
|