@orbcharts/plugins-basic 3.0.0-beta.15 → 3.0.0-beta.17

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