@orbcharts/plugins-basic 3.0.0-alpha.79 → 3.0.0-beta.10

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 (216) hide show
  1. package/LICENSE +200 -200
  2. package/dist/{src → orbcharts-plugins-basic/src}/base/BaseBars.d.ts +2 -2
  3. package/dist/{src → orbcharts-plugins-basic/src}/base/BaseBarsTriangle.d.ts +2 -2
  4. package/dist/{src → orbcharts-plugins-basic/src}/base/BaseDots.d.ts +2 -2
  5. package/dist/{src → orbcharts-plugins-basic/src}/base/BaseGroupAxis.d.ts +2 -2
  6. package/dist/{src → orbcharts-plugins-basic/src}/base/BaseLegend.d.ts +1 -1
  7. package/dist/{src → orbcharts-plugins-basic/src}/base/BaseLineAreas.d.ts +3 -3
  8. package/dist/{src → orbcharts-plugins-basic/src}/base/BaseLines.d.ts +3 -3
  9. package/dist/{src/base/BaseBarStack.d.ts → orbcharts-plugins-basic/src/base/BaseStackedBar.d.ts} +6 -6
  10. package/dist/orbcharts-plugins-basic/src/base/BaseTooltip.d.ts +14 -0
  11. package/dist/{src → orbcharts-plugins-basic/src}/base/BaseValueAxis.d.ts +3 -2
  12. package/dist/{src → orbcharts-plugins-basic/src}/grid/defaults.d.ts +6 -5
  13. package/dist/{src → orbcharts-plugins-basic/src}/grid/gridObservables.d.ts +5 -5
  14. package/dist/{src → orbcharts-plugins-basic/src}/grid/index.d.ts +4 -3
  15. package/dist/orbcharts-plugins-basic/src/grid/plugins/GridTooltip.d.ts +1 -0
  16. package/dist/orbcharts-plugins-basic/src/grid/plugins/GridZoom.d.ts +1 -0
  17. package/dist/orbcharts-plugins-basic/src/grid/plugins/StackedBar.d.ts +1 -0
  18. package/dist/orbcharts-plugins-basic/src/grid/plugins/StackedValueAxis.d.ts +1 -0
  19. package/dist/orbcharts-plugins-basic/src/index.d.ts +7 -0
  20. package/dist/orbcharts-plugins-basic/src/multiGrid/defaults.d.ts +15 -0
  21. package/dist/{src → orbcharts-plugins-basic/src}/multiGrid/index.d.ts +4 -3
  22. package/dist/orbcharts-plugins-basic/src/multiGrid/plugins/MultiGridTooltip.d.ts +1 -0
  23. package/dist/orbcharts-plugins-basic/src/multiGrid/plugins/MultiStackedBar.d.ts +1 -0
  24. package/dist/orbcharts-plugins-basic/src/multiGrid/plugins/MultiStackedValueAxis.d.ts +1 -0
  25. package/dist/orbcharts-plugins-basic/src/multiGrid/plugins/OverlappingStackedValueAxes.d.ts +1 -0
  26. package/dist/orbcharts-plugins-basic/src/multiValue/defaults.d.ts +9 -0
  27. package/dist/orbcharts-plugins-basic/src/multiValue/index.d.ts +8 -0
  28. package/dist/orbcharts-plugins-basic/src/multiValue/multiValueObservables.d.ts +33 -0
  29. package/dist/orbcharts-plugins-basic/src/multiValue/plugins/MultiValueLegend.d.ts +1 -0
  30. package/dist/orbcharts-plugins-basic/src/multiValue/plugins/MultiValueTooltip.d.ts +1 -0
  31. package/dist/orbcharts-plugins-basic/src/multiValue/plugins/Scatter.d.ts +3 -0
  32. package/dist/orbcharts-plugins-basic/src/multiValue/plugins/ScatterBubbles.d.ts +3 -0
  33. package/dist/orbcharts-plugins-basic/src/multiValue/plugins/XYAux.d.ts +3 -0
  34. package/dist/orbcharts-plugins-basic/src/multiValue/plugins/XYAxes.d.ts +3 -0
  35. package/dist/orbcharts-plugins-basic/src/multiValue/plugins/XYZoom.d.ts +1 -0
  36. package/dist/orbcharts-plugins-basic/src/noneData/index.d.ts +1 -0
  37. package/dist/orbcharts-plugins-basic/src/relationship/defaults.d.ts +6 -0
  38. package/dist/orbcharts-plugins-basic/src/relationship/index.d.ts +5 -0
  39. package/dist/orbcharts-plugins-basic/src/relationship/plugins/ForceDirected.d.ts +3 -0
  40. package/dist/orbcharts-plugins-basic/src/relationship/plugins/ForceDirectedBubbles.d.ts +3 -0
  41. package/dist/orbcharts-plugins-basic/src/relationship/plugins/RelationshipLegend.d.ts +1 -0
  42. package/dist/orbcharts-plugins-basic/src/relationship/plugins/RelationshipTooltip.d.ts +1 -0
  43. package/dist/orbcharts-plugins-basic/src/relationship/relationshipObservables.d.ts +1 -0
  44. package/dist/{src → orbcharts-plugins-basic/src}/series/defaults.d.ts +2 -1
  45. package/dist/{src → orbcharts-plugins-basic/src}/series/index.d.ts +1 -0
  46. package/dist/orbcharts-plugins-basic/src/series/plugins/SeriesTooltip.d.ts +1 -0
  47. package/dist/{src → orbcharts-plugins-basic/src}/series/seriesObservables.d.ts +3 -3
  48. package/dist/orbcharts-plugins-basic/src/tree/defaults.d.ts +5 -0
  49. package/dist/{src → orbcharts-plugins-basic/src}/tree/index.d.ts +1 -0
  50. package/dist/orbcharts-plugins-basic/src/tree/plugins/TreeTooltip.d.ts +1 -0
  51. package/dist/{src → orbcharts-plugins-basic/src}/utils/commonUtils.d.ts +1 -1
  52. package/dist/{src → orbcharts-plugins-basic/src}/utils/d3Utils.d.ts +2 -2
  53. package/dist/{src → orbcharts-plugins-basic/src}/utils/observables.d.ts +1 -1
  54. package/dist/{src → orbcharts-plugins-basic/src}/utils/orbchartsUtils.d.ts +3 -3
  55. package/dist/orbcharts-plugins-basic.es.js +13490 -10057
  56. package/dist/orbcharts-plugins-basic.umd.js +179 -24
  57. package/dist/src/index.d.ts +1 -5
  58. package/lib/core-types.ts +7 -7
  59. package/lib/core.ts +6 -6
  60. package/lib/plugins-basic-types.ts +6 -6
  61. package/package.json +44 -44
  62. package/src/base/BaseBars.ts +765 -765
  63. package/src/base/BaseBarsTriangle.ts +676 -674
  64. package/src/base/BaseDots.ts +464 -515
  65. package/src/base/BaseGroupAxis.ts +679 -679
  66. package/src/base/BaseLegend.ts +684 -644
  67. package/src/base/BaseLineAreas.ts +629 -629
  68. package/src/base/BaseLines.ts +706 -706
  69. package/src/base/{BaseBarStack.ts → BaseStackedBar.ts} +782 -780
  70. package/src/base/BaseTooltip.ts +386 -0
  71. package/src/base/BaseValueAxis.ts +583 -580
  72. package/src/base/types.ts +2 -2
  73. package/src/const.ts +30 -30
  74. package/src/grid/defaults.ts +247 -128
  75. package/src/grid/gridObservables.ts +554 -545
  76. package/src/grid/index.ts +16 -15
  77. package/src/grid/plugins/Bars.ts +69 -69
  78. package/src/grid/plugins/BarsPN.ts +66 -66
  79. package/src/grid/plugins/BarsTriangle.ts +73 -73
  80. package/src/grid/plugins/Dots.ts +68 -68
  81. package/src/grid/plugins/GridLegend.ts +107 -96
  82. package/src/grid/plugins/GridTooltip.ts +66 -0
  83. package/src/grid/plugins/{ScalingArea.ts → GridZoom.ts} +218 -218
  84. package/src/grid/plugins/GroupAux.ts +1103 -1098
  85. package/src/grid/plugins/GroupAxis.ts +97 -97
  86. package/src/grid/plugins/LineAreas.ts +65 -65
  87. package/src/grid/plugins/Lines.ts +59 -59
  88. package/src/grid/plugins/{BarStack.ts → StackedBar.ts} +64 -64
  89. package/src/grid/plugins/{ValueStackAxis.ts → StackedValueAxis.ts} +96 -95
  90. package/src/grid/plugins/ValueAxis.ts +94 -93
  91. package/src/index.ts +6 -9
  92. package/src/multiGrid/defaults.ts +225 -159
  93. package/src/multiGrid/index.ts +15 -14
  94. package/src/multiGrid/multiGridObservables.ts +49 -49
  95. package/src/multiGrid/plugins/MultiBars.ts +108 -108
  96. package/src/multiGrid/plugins/MultiBarsTriangle.ts +114 -114
  97. package/src/multiGrid/plugins/MultiDots.ts +102 -102
  98. package/src/multiGrid/plugins/MultiGridLegend.ts +159 -148
  99. package/src/multiGrid/plugins/MultiGridTooltip.ts +66 -0
  100. package/src/multiGrid/plugins/MultiGroupAxis.ts +137 -137
  101. package/src/multiGrid/plugins/MultiLineAreas.ts +107 -107
  102. package/src/multiGrid/plugins/MultiLines.ts +101 -101
  103. package/src/multiGrid/plugins/{MultiBarStack.ts → MultiStackedBar.ts} +106 -106
  104. package/src/multiGrid/plugins/{MultiValueStackAxis.ts → MultiStackedValueAxis.ts} +134 -133
  105. package/src/multiGrid/plugins/MultiValueAxis.ts +134 -133
  106. package/src/multiGrid/plugins/{OverlappingValueStackAxes.ts → OverlappingStackedValueAxes.ts} +299 -298
  107. package/src/multiGrid/plugins/OverlappingValueAxes.ts +300 -299
  108. package/src/multiValue/defaults.ts +167 -0
  109. package/src/multiValue/index.ts +9 -0
  110. package/src/multiValue/multiValueObservables.ts +297 -0
  111. package/src/multiValue/plugins/MultiValueLegend.ts +107 -0
  112. package/src/multiValue/plugins/MultiValueTooltip.ts +66 -0
  113. package/src/multiValue/plugins/Scatter.ts +426 -0
  114. package/src/multiValue/plugins/ScatterBubbles.ts +554 -0
  115. package/src/multiValue/plugins/XYAux.ts +682 -0
  116. package/src/multiValue/plugins/XYAxes.ts +685 -0
  117. package/src/multiValue/plugins/XYZoom.ts +300 -0
  118. package/src/noneData/defaults.ts +102 -102
  119. package/src/noneData/index.ts +4 -4
  120. package/src/noneData/plugins/Container.ts +28 -28
  121. package/src/noneData/plugins/Tooltip.ts +374 -374
  122. package/src/relationship/defaults.ts +196 -0
  123. package/src/relationship/index.ts +5 -0
  124. package/src/relationship/plugins/ForceDirected.ts +1167 -0
  125. package/src/relationship/plugins/ForceDirectedBubbles.ts +1391 -0
  126. package/src/relationship/plugins/RelationshipLegend.ts +100 -0
  127. package/src/relationship/plugins/RelationshipTooltip.ts +66 -0
  128. package/src/relationship/relationshipObservables.ts +50 -0
  129. package/src/series/defaults.ts +207 -149
  130. package/src/series/index.ts +10 -9
  131. package/src/series/plugins/Bubbles.ts +606 -603
  132. package/src/series/plugins/Pie.ts +623 -623
  133. package/src/series/plugins/PieEventTexts.ts +284 -283
  134. package/src/series/plugins/PieLabels.ts +640 -640
  135. package/src/series/plugins/Rose.ts +516 -516
  136. package/src/series/plugins/RoseLabels.ts +600 -600
  137. package/src/series/plugins/SeriesLegend.ts +107 -96
  138. package/src/series/plugins/SeriesTooltip.ts +66 -0
  139. package/src/series/seriesObservables.ts +145 -145
  140. package/src/series/seriesUtils.ts +51 -51
  141. package/src/tree/defaults.ts +79 -23
  142. package/src/tree/index.ts +5 -4
  143. package/src/tree/plugins/TreeLegend.ts +100 -96
  144. package/src/tree/plugins/TreeMap.ts +333 -333
  145. package/src/tree/plugins/TreeTooltip.ts +66 -0
  146. package/src/utils/commonUtils.ts +21 -21
  147. package/src/utils/d3Graphics.ts +174 -174
  148. package/src/utils/d3Utils.ts +74 -73
  149. package/src/utils/observables.ts +14 -14
  150. package/src/utils/orbchartsUtils.ts +116 -100
  151. package/tsconfig.base.json +13 -13
  152. package/tsconfig.json +2 -2
  153. package/vite.config.js +22 -22
  154. package/dist/src/grid/plugins/BarStack.d.ts +0 -1
  155. package/dist/src/grid/plugins/ScalingArea.d.ts +0 -1
  156. package/dist/src/grid/plugins/ValueStackAxis.d.ts +0 -1
  157. package/dist/src/multiGrid/defaults.d.ts +0 -14
  158. package/dist/src/multiGrid/plugins/MultiBarStack.d.ts +0 -1
  159. package/dist/src/multiGrid/plugins/MultiValueStackAxis.d.ts +0 -1
  160. package/dist/src/multiGrid/plugins/OverlappingValueStackAxes.d.ts +0 -1
  161. package/dist/src/multiValue/plugins/Scatter.d.ts +0 -0
  162. package/dist/src/multiValue/plugins/ScatterAxes.d.ts +0 -0
  163. package/dist/src/noneData/index.d.ts +0 -2
  164. package/dist/src/noneData/plugins/Container.d.ts +0 -1
  165. package/dist/src/noneData/plugins/Tooltip.d.ts +0 -3
  166. package/dist/src/relationship/index.d.ts +0 -0
  167. package/dist/src/relationship/plugins/Relationship.d.ts +0 -0
  168. package/dist/src/tree/defaults.d.ts +0 -4
  169. package/src/base/BaseGroupArea.ts +0 -0
  170. package/src/multiValue/plugins/ScatterAxes.ts +0 -0
  171. package/src/relationship/plugins/Relationship.ts +0 -0
  172. /package/dist/{lib → orbcharts-plugins-basic/lib}/core-types.d.ts +0 -0
  173. /package/dist/{lib → orbcharts-plugins-basic/lib}/core.d.ts +0 -0
  174. /package/dist/{lib → orbcharts-plugins-basic/lib}/plugins-basic-types.d.ts +0 -0
  175. /package/dist/{src → orbcharts-plugins-basic/src}/base/types.d.ts +0 -0
  176. /package/dist/{src → orbcharts-plugins-basic/src}/const.d.ts +0 -0
  177. /package/dist/{src → orbcharts-plugins-basic/src}/grid/plugins/Bars.d.ts +0 -0
  178. /package/dist/{src → orbcharts-plugins-basic/src}/grid/plugins/BarsPN.d.ts +0 -0
  179. /package/dist/{src → orbcharts-plugins-basic/src}/grid/plugins/BarsTriangle.d.ts +0 -0
  180. /package/dist/{src → orbcharts-plugins-basic/src}/grid/plugins/Dots.d.ts +0 -0
  181. /package/dist/{src → orbcharts-plugins-basic/src}/grid/plugins/GridLegend.d.ts +0 -0
  182. /package/dist/{src → orbcharts-plugins-basic/src}/grid/plugins/GroupAux.d.ts +0 -0
  183. /package/dist/{src → orbcharts-plugins-basic/src}/grid/plugins/GroupAxis.d.ts +0 -0
  184. /package/dist/{src → orbcharts-plugins-basic/src}/grid/plugins/LineAreas.d.ts +0 -0
  185. /package/dist/{src → orbcharts-plugins-basic/src}/grid/plugins/Lines.d.ts +0 -0
  186. /package/dist/{src → orbcharts-plugins-basic/src}/grid/plugins/ValueAxis.d.ts +0 -0
  187. /package/dist/{src → orbcharts-plugins-basic/src}/multiGrid/multiGridObservables.d.ts +0 -0
  188. /package/dist/{src → orbcharts-plugins-basic/src}/multiGrid/plugins/MultiBars.d.ts +0 -0
  189. /package/dist/{src → orbcharts-plugins-basic/src}/multiGrid/plugins/MultiBarsTriangle.d.ts +0 -0
  190. /package/dist/{src → orbcharts-plugins-basic/src}/multiGrid/plugins/MultiDots.d.ts +0 -0
  191. /package/dist/{src → orbcharts-plugins-basic/src}/multiGrid/plugins/MultiGridLegend.d.ts +0 -0
  192. /package/dist/{src → orbcharts-plugins-basic/src}/multiGrid/plugins/MultiGroupAxis.d.ts +0 -0
  193. /package/dist/{src → orbcharts-plugins-basic/src}/multiGrid/plugins/MultiLineAreas.d.ts +0 -0
  194. /package/dist/{src → orbcharts-plugins-basic/src}/multiGrid/plugins/MultiLines.d.ts +0 -0
  195. /package/dist/{src → orbcharts-plugins-basic/src}/multiGrid/plugins/MultiValueAxis.d.ts +0 -0
  196. /package/dist/{src → orbcharts-plugins-basic/src}/multiGrid/plugins/OverlappingValueAxes.d.ts +0 -0
  197. /package/dist/{src/grid → orbcharts-plugins-basic/src/multiValue}/plugins/Ranking.d.ts +0 -0
  198. /package/dist/{src/grid → orbcharts-plugins-basic/src/multiValue}/plugins/RankingAxis.d.ts +0 -0
  199. /package/dist/{src → orbcharts-plugins-basic/src}/noneData/defaults.d.ts +0 -0
  200. /package/dist/{src/base/BaseGroupArea.d.ts → orbcharts-plugins-basic/src/noneData/plugins/Container.d.ts} +0 -0
  201. /package/dist/{src/multiValue/index.d.ts → orbcharts-plugins-basic/src/noneData/plugins/Tooltip.d.ts} +0 -0
  202. /package/dist/{src → orbcharts-plugins-basic/src}/series/plugins/Bubbles.d.ts +0 -0
  203. /package/dist/{src → orbcharts-plugins-basic/src}/series/plugins/Pie.d.ts +0 -0
  204. /package/dist/{src → orbcharts-plugins-basic/src}/series/plugins/PieEventTexts.d.ts +0 -0
  205. /package/dist/{src → orbcharts-plugins-basic/src}/series/plugins/PieLabels.d.ts +0 -0
  206. /package/dist/{src → orbcharts-plugins-basic/src}/series/plugins/Rose.d.ts +0 -0
  207. /package/dist/{src → orbcharts-plugins-basic/src}/series/plugins/RoseLabels.d.ts +0 -0
  208. /package/dist/{src → orbcharts-plugins-basic/src}/series/plugins/SeriesLegend.d.ts +0 -0
  209. /package/dist/{src → orbcharts-plugins-basic/src}/series/plugins/Waffle.d.ts +0 -0
  210. /package/dist/{src → orbcharts-plugins-basic/src}/series/seriesUtils.d.ts +0 -0
  211. /package/dist/{src → orbcharts-plugins-basic/src}/tree/plugins/TreeLegend.d.ts +0 -0
  212. /package/dist/{src → orbcharts-plugins-basic/src}/tree/plugins/TreeMap.d.ts +0 -0
  213. /package/dist/{src → orbcharts-plugins-basic/src}/utils/d3Graphics.d.ts +0 -0
  214. /package/dist/{vite.config.d.ts → orbcharts-plugins-basic/vite.config.d.ts} +0 -0
  215. /package/src/{grid → multiValue}/plugins/Ranking.ts +0 -0
  216. /package/src/{grid → multiValue}/plugins/RankingAxis.ts +0 -0
@@ -1,630 +1,630 @@
1
- import * as d3 from 'd3'
2
- import {
3
- combineLatest,
4
- map,
5
- filter,
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
- GridContainerPosition,
20
- ChartParams,
21
- Layout,
22
- TransformData
23
- } from '../../lib/core-types'
24
- import type { BaseLineAreasParams } from '../../lib/plugins-basic-types'
25
- import { getD3TransitionEase } from '../utils/d3Utils'
26
- import { getClassName, getUniID, getMinAndMaxValue } from '../utils/orbchartsUtils'
27
- import { gridGroupPositionFnObservable } from '../grid/gridObservables'
28
- import { gridSelectionsObservable } from '../grid/gridObservables'
29
-
30
- // export interface BaseLineAreasParams {
31
- // lineCurve: string
32
- // // lineWidth: number
33
- // linearGradientOpacity: [number, number]
34
- // }
35
-
36
- interface BaseLineAreasContext {
37
- selection: d3.Selection<any, unknown, any, unknown>
38
- computedData$: Observable<ComputedDataGrid>
39
- computedLayoutData$: Observable<ComputedLayoutDataGrid>
40
- visibleComputedData$: Observable<ComputedDatumGrid[][]>
41
- visibleComputedLayoutData$: Observable<ComputedLayoutDataGrid>
42
- seriesLabels$: Observable<string[]>
43
- SeriesDataMap$: Observable<Map<string, ComputedDatumGrid[]>>
44
- GroupDataMap$: Observable<Map<string, ComputedDatumGrid[]>>
45
- fullDataFormatter$: Observable<DataFormatterGrid>
46
- fullParams$: Observable<BaseLineAreasParams>
47
- fullChartParams$: Observable<ChartParams>
48
- gridAxesTransform$: Observable<TransformData>
49
- gridGraphicTransform$: Observable<TransformData>
50
- gridAxesSize$: Observable<{
51
- width: number;
52
- height: number;
53
- }>
54
- gridHighlight$: Observable<ComputedDatumGrid[]>
55
- gridContainerPosition$: Observable<GridContainerPosition[]>
56
- allContainerPosition$: Observable<GridContainerPosition[]>
57
- layout$: Observable<Layout>
58
- event$: Subject<EventGrid>
59
- }
60
-
61
- type ClipPathDatum = {
62
- id: string;
63
- // x: number;
64
- // y: number;
65
- width: number;
66
- height: number;
67
- }
68
-
69
- // const pluginName = 'Lines'
70
- // const pathClassName = getClassName(pluginName, 'path')
71
-
72
-
73
- function createAreaPath (lineCurve: string = 'curveLinear', valueAxisStart: number): d3.Line<ComputedLayoutDatumGrid> {
74
- return d3.area<ComputedLayoutDatumGrid>()
75
- .x((d) => d.axisX)
76
- .y0(d => valueAxisStart)
77
- .y1((d) => d.axisY)
78
- .curve((d3 as any)[lineCurve])
79
-
80
- }
81
-
82
- // 依無值的資料分段
83
- function makeSegmentData (data: ComputedLayoutDatumGrid[]): ComputedLayoutDatumGrid[][] {
84
- let segmentData: ComputedLayoutDatumGrid[][] = [[]]
85
-
86
- let currentIndex = 0
87
- for (let i in data) {
88
- if (data[i].visible == false || data[i].value === undefined || data[i].value === null) {
89
- // 換下一段的 index
90
- if (segmentData[currentIndex].length) {
91
- currentIndex ++
92
- segmentData[currentIndex] = []
93
- }
94
- continue
95
- }
96
- segmentData[currentIndex].push(data[i])
97
- }
98
-
99
- return segmentData
100
- }
101
-
102
-
103
- function renderLineAreas ({ selection, pathClassName, segmentData, areaPath, linearGradientIds, params }: {
104
- selection: d3.Selection<SVGGElement, unknown, any, unknown>
105
- pathClassName: string
106
- segmentData: ComputedLayoutDatumGrid[][]
107
- areaPath: d3.Line<ComputedLayoutDatumGrid>
108
- linearGradientIds: string[]
109
- params: BaseLineAreasParams
110
- }): d3.Selection<SVGPathElement, ComputedLayoutDatumGrid[], any, any> {
111
- // if (!data[0]) {
112
- // return undefined
113
- // }
114
-
115
- const lineAreas = selection
116
- .selectAll<SVGPathElement, ComputedLayoutDatumGrid[]>('path')
117
- .data(segmentData, (d, i) => d.length ? `${d[0].id}_${d[d.length - 1].id}` : i) // 以線段起迄id結合為線段id
118
- .join(
119
- enter => {
120
- return enter
121
- .append<SVGPathElement>('path')
122
- .classed(pathClassName, true)
123
- .attr("fill","none")
124
- // .attr('pointer-events', 'visibleStroke') // 只對線條產生事件
125
- .style('vector-effect', 'non-scaling-stroke')
126
- .style('cursor', 'pointer')
127
- },
128
- update => update,
129
- exit => exit.remove()
130
- )
131
- // .attr("stroke-width", params.lineWidth)
132
- // .attr("stroke", (d, i) => d[0] && d[0].color)
133
- .attr("fill", (d, i) => d[0] ? `url(#${linearGradientIds[d[0].seriesIndex]})` : '')
134
- .attr("d", (d) => {
135
- return areaPath(d)
136
- })
137
-
138
- return lineAreas
139
- }
140
-
141
- function highlightLineAreas ({ selection, seriesLabel, fullChartParams }: {
142
- selection: d3.Selection<any, string, any, any>
143
- seriesLabel: string | null
144
- fullChartParams: ChartParams
145
- }) {
146
- selection.interrupt('highlight')
147
- if (!seriesLabel) {
148
- // remove highlight
149
- selection
150
- .transition('highlight')
151
- .duration(200)
152
- .style('opacity', 1)
153
- return
154
- }
155
-
156
- selection
157
- .each((currentSeriesLabel, i, n) => {
158
- // const currentSeriesLabel = d[0] ? d[0].seriesLabel : ''
159
-
160
- if (currentSeriesLabel === seriesLabel) {
161
- d3.select(n[i])
162
- .style('opacity', 1)
163
- } else {
164
- d3.select(n[i])
165
- .style('opacity', fullChartParams.styles.unhighlightedOpacity)
166
- }
167
- })
168
- }
169
-
170
- function renderLinearGradient ({ defsSelection, computedData, linearGradientIds, params }: {
171
- defsSelection: d3.Selection<SVGDefsElement, any, any, any>
172
- computedData: ComputedDataGrid
173
- linearGradientIds: string[]
174
- params: BaseLineAreasParams
175
- }) {
176
- defsSelection!
177
- .selectAll<SVGLinearGradientElement, ComputedDatumGrid>('linearGradient')
178
- .data(computedData ?? [])
179
- .join(
180
- enter => {
181
- return enter
182
- .append('linearGradient')
183
- .attr('x1', '0%')
184
- .attr('x2', '0%')
185
- .attr('y1', '100%')
186
- .attr('y2', '0%')
187
- .attr('spreadMethod', 'pad')
188
- },
189
- update => update,
190
- exit => exit.remove()
191
- )
192
- .attr('id', (d, i) => {
193
- return d[0] ? linearGradientIds[d[0].seriesIndex] : ''
194
- })
195
- .html((d, i) => {
196
- const color = d[0] ? d[0].color : ''
197
- return `
198
- <stop offset="0%" stop-color="${color}" stop-opacity="${params.linearGradientOpacity[0]}"/>
199
- <stop offset="100%" stop-color="${color}" stop-opacity="${params.linearGradientOpacity[1]}"/>
200
- `
201
- })
202
-
203
- }
204
-
205
- function renderClipPath ({ defsSelection, clipPathData, transitionDuration, transitionEase }: {
206
- defsSelection: d3.Selection<SVGDefsElement, any, any, any>
207
- clipPathData: ClipPathDatum[]
208
- transitionDuration: number
209
- transitionEase: string
210
- }) {
211
- const clipPath = defsSelection
212
- .selectAll<SVGClipPathElement, Layout>('clipPath')
213
- .data(clipPathData)
214
- .join(
215
- enter => {
216
- return enter
217
- .append('clipPath')
218
- },
219
- update => update,
220
- exit => exit.remove()
221
- )
222
- .attr('id', d => d.id)
223
- .each((d, i, g) => {
224
- const rect = d3.select(g[i])
225
- .selectAll<SVGRectElement, typeof d>('rect')
226
- .data([d])
227
- .join(
228
- enter => {
229
- const enterSelection = enter
230
- .append('rect')
231
- enterSelection
232
- .transition()
233
- .duration(transitionDuration)
234
- .ease(getD3TransitionEase(transitionEase))
235
- // .delay(100) // @Q@ 不知為何如果沒加 delay位置會有點跑掉
236
- .tween('tween', (_d, _i, _g) => {
237
- return (t) => {
238
- const transitionWidth = _d.width * t
239
-
240
- enterSelection
241
- .attr('x', 0)
242
- .attr('y', 0)
243
- .attr('width', _d => transitionWidth)
244
- .attr('height', _d => _d.height)
245
- }
246
- })
247
- return enterSelection
248
- },
249
- update => {
250
- return update
251
- .attr('x', 0)
252
- .attr('y', 0)
253
- .attr('width', _d => _d.width)
254
- .attr('height', _d => _d.height)
255
- },
256
- exit => exit.remove()
257
- )
258
- })
259
-
260
- }
261
-
262
- export const createBaseLineAreas: BasePluginFn<BaseLineAreasContext> = (pluginName: string, {
263
- selection,
264
- computedData$,
265
- computedLayoutData$,
266
- visibleComputedData$,
267
- visibleComputedLayoutData$,
268
- seriesLabels$,
269
- SeriesDataMap$,
270
- GroupDataMap$,
271
- fullParams$,
272
- fullDataFormatter$,
273
- fullChartParams$,
274
- gridAxesTransform$,
275
- gridGraphicTransform$,
276
- gridAxesSize$,
277
- gridHighlight$,
278
- gridContainerPosition$,
279
- layout$,
280
- event$
281
- }) => {
282
-
283
- const destroy$ = new Subject()
284
-
285
- const clipPathID = getUniID(pluginName, 'clipPath-box')
286
- const pathClassName = getClassName(pluginName, 'path')
287
-
288
- const {
289
- seriesSelection$,
290
- axesSelection$,
291
- defsSelection$,
292
- graphicGSelection$
293
- } = gridSelectionsObservable({
294
- selection,
295
- pluginName,
296
- clipPathID,
297
- seriesLabels$,
298
- gridContainerPosition$,
299
- gridAxesTransform$,
300
- gridGraphicTransform$
301
- })
302
-
303
- // valueAxis 的起始座標
304
- const valueAxisStart$: Observable<number> = gridGraphicTransform$.pipe(
305
- takeUntil(destroy$),
306
- map(data => {
307
- // 抵消掉外層的變型
308
- return - data.translate[1] / data.scale[1]
309
- })
310
- )
311
-
312
- const areaPath$: Observable<d3.Line<ComputedLayoutDatumGrid>> = new Observable(subscriber => {
313
- const paramsSubscription = combineLatest({
314
- fullParams: fullParams$,
315
- valueAxisStart: valueAxisStart$
316
- }).pipe(
317
- takeUntil(destroy$)
318
- )
319
- .subscribe(d => {
320
- const areaPath = createAreaPath(d.fullParams.lineCurve, d.valueAxisStart)
321
- subscriber.next(areaPath)
322
- })
323
- return () => {
324
- paramsSubscription.unsubscribe()
325
- }
326
- })
327
-
328
- // // 顯示範圍內的series labels
329
- // const seriesLabels$: Observable<string[]> = new Observable(subscriber => {
330
- // computedData$.pipe(
331
- // takeUntil(destroy$),
332
- // switchMap(async (d) => d),
333
- // ).subscribe(data => {
334
- // const labels = data[0] && data[0][0]
335
- // ? data.map(d => d[0].seriesLabel)
336
- // : []
337
- // subscriber.next(labels)
338
- // })
339
- // })
340
-
341
- // const axisSize$ = gridAxisSizeObservable({
342
- // fullDataFormatter$,
343
- // computedLayout$
344
- // })
345
-
346
- const transitionDuration$ = fullChartParams$
347
- .pipe(
348
- map(d => d.transitionDuration),
349
- distinctUntilChanged()
350
- )
351
-
352
- const transitionEase$ = fullChartParams$
353
- .pipe(
354
- map(d => d.transitionEase),
355
- distinctUntilChanged()
356
- )
357
-
358
- const clipPathSubscription = combineLatest({
359
- defsSelection: defsSelection$,
360
- seriesLabels: seriesLabels$,
361
- axisSize: gridAxesSize$,
362
- transitionDuration: transitionDuration$,
363
- transitionEase: transitionEase$
364
- }).pipe(
365
- takeUntil(destroy$),
366
- switchMap(async (d) => d),
367
- ).subscribe(data => {
368
- // 外層的遮罩
369
- const clipPathBox = [{
370
- id: clipPathID,
371
- width: data.axisSize.width,
372
- height: data.axisSize.height
373
- }]
374
- // 各別線條的遮罩(各別動畫)
375
- const clipPathData = clipPathBox.concat(
376
- data.seriesLabels.map(d => {
377
- return {
378
- id: `orbcharts__clipPath_${d}`,
379
- width: data.axisSize.width,
380
- height: data.axisSize.height
381
- }
382
- })
383
- )
384
- renderClipPath({
385
- defsSelection: data.defsSelection,
386
- clipPathData,
387
- transitionDuration: data.transitionDuration,
388
- transitionEase: data.transitionEase
389
- })
390
- })
391
-
392
- // const SeriesDataMap$ = computedData$.pipe(
393
- // map(d => makeGridSeriesDataMap(d))
394
- // )
395
-
396
- // const GroupDataMap$ = computedData$.pipe(
397
- // map(d => makeGridGroupDataMap(d))
398
- // )
399
-
400
- const DataMap$ = computedData$.pipe(
401
- map(d => {
402
- const DataMap: Map<string, ComputedDatumGrid> = new Map()
403
- d.flat().forEach(_d => DataMap.set(_d.id, _d))
404
- return DataMap
405
- })
406
- )
407
-
408
- // 取得事件座標的group資料
409
- const gridGroupPositionFn$ = gridGroupPositionFnObservable({
410
- fullDataFormatter$,
411
- gridAxesSize$: gridAxesSize$,
412
- computedData$: computedData$,
413
- fullChartParams$: fullChartParams$,
414
- gridContainerPosition$: gridContainerPosition$,
415
- layout$: layout$
416
- })
417
-
418
- const highlightTarget$ = fullChartParams$.pipe(
419
- takeUntil(destroy$),
420
- map(d => d.highlightTarget),
421
- distinctUntilChanged()
422
- )
423
-
424
- const linearGradientIds$ = seriesLabels$.pipe(
425
- takeUntil(destroy$),
426
- map(d => d.map((d, i) => {
427
- return getUniID(pluginName, `lineargradient-${d}`)
428
- }))
429
- )
430
-
431
- const pathSelectionArr$ = combineLatest({
432
- graphicGSelection: graphicGSelection$,
433
- defsSelection: defsSelection$,
434
- visibleComputedLayoutData: visibleComputedLayoutData$,
435
- linearGradientIds: linearGradientIds$,
436
- areaPath: areaPath$,
437
- params: fullParams$,
438
- }).pipe(
439
- takeUntil(destroy$),
440
- switchMap(async (d) => d),
441
- map(data => {
442
- // const updateGraphic = data.graphicGSelection
443
- // .selectAll<SVGGElement, number>('g')
444
- // .data(data.seriesLabels, (d, i) => d)
445
- // const enterGraphic = updateGraphic.enter()
446
- // .append('g')
447
- // .classed(graphicClassName, true)
448
- // updateGraphic.exit().remove()
449
- // const graphicSelection = updateGraphic.merge(enterGraphic)
450
- // .attr('clip-path', (d, i) => `url(#orbcharts__clipPath_${d})`)
451
- let pathSelectionArr: d3.Selection<SVGPathElement, ComputedLayoutDatumGrid[], any, any>[] = []
452
-
453
- // 繪圖
454
- data.graphicGSelection.each((d, i, all) => {
455
- // 將資料分段
456
- const segmentData = makeSegmentData(data.visibleComputedLayoutData[i] ?? [])
457
-
458
- pathSelectionArr[i] = renderLineAreas({
459
- selection: d3.select(all[i]),
460
- pathClassName,
461
- areaPath: data.areaPath,
462
- segmentData: segmentData,
463
- linearGradientIds: data.linearGradientIds,
464
- params: data.params
465
- })
466
- renderLinearGradient({
467
- defsSelection: data.defsSelection,
468
- computedData: data.visibleComputedLayoutData,
469
- linearGradientIds: data.linearGradientIds,
470
- params: data.params
471
- })
472
- })
473
-
474
- return pathSelectionArr
475
- })
476
- )
477
-
478
- combineLatest({
479
- pathSelectionArr: pathSelectionArr$,
480
- computedData: computedData$,
481
- SeriesDataMap: SeriesDataMap$,
482
- GroupDataMap: GroupDataMap$,
483
- highlightTarget: highlightTarget$,
484
- gridGroupPositionFn: gridGroupPositionFn$,
485
- }).pipe(
486
- takeUntil(destroy$),
487
- switchMap(async (d) => d),
488
- ).subscribe(data => {
489
- data.pathSelectionArr.forEach(pathSelection => {
490
- pathSelection
491
- .on('mouseover', (event, datum) => {
492
- // event.stopPropagation()
493
-
494
- const seriesLabel = datum[0] ? datum[0].seriesLabel : ''
495
- const { groupIndex, groupLabel } = data.gridGroupPositionFn(event)
496
- const groupData = data.GroupDataMap.get(groupLabel)!
497
- const targetDatum = groupData.find(d => d.seriesLabel === seriesLabel)
498
- const _datum = targetDatum ?? datum[0]
499
-
500
- event$.next({
501
- type: 'grid',
502
- eventName: 'mouseover',
503
- pluginName,
504
- highlightTarget: data.highlightTarget,
505
- datum: _datum,
506
- gridIndex: _datum.gridIndex,
507
- series: data.SeriesDataMap.get(_datum.seriesLabel)!,
508
- seriesIndex: _datum.seriesIndex,
509
- seriesLabel: _datum.seriesLabel,
510
- groups: data.GroupDataMap.get(_datum.groupLabel)!,
511
- groupIndex: _datum.groupIndex,
512
- groupLabel: _datum.groupLabel,
513
- event,
514
- data: data.computedData
515
- })
516
- })
517
- .on('mousemove', (event, datum) => {
518
- // event.stopPropagation()
519
-
520
- const seriesLabel = datum[0] ? datum[0].seriesLabel : ''
521
- const { groupIndex, groupLabel } = data.gridGroupPositionFn(event)
522
- const groupData = data.GroupDataMap.get(groupLabel)!
523
- const targetDatum = groupData.find(d => d.seriesLabel === seriesLabel)
524
- const _datum = targetDatum ?? datum[0]
525
-
526
- event$.next({
527
- type: 'grid',
528
- eventName: 'mousemove',
529
- pluginName,
530
- highlightTarget: data.highlightTarget,
531
- datum: _datum,
532
- gridIndex: _datum.gridIndex,
533
- series: data.SeriesDataMap.get(_datum.seriesLabel)!,
534
- seriesIndex: _datum.seriesIndex,
535
- seriesLabel: _datum.seriesLabel,
536
- groups: data.GroupDataMap.get(_datum.groupLabel)!,
537
- groupIndex: _datum.groupIndex,
538
- groupLabel: _datum.groupLabel,
539
- event,
540
- data: data.computedData
541
- })
542
- })
543
- .on('mouseout', (event, datum) => {
544
- // event.stopPropagation()
545
-
546
- const seriesLabel = datum[0] ? datum[0].seriesLabel : ''
547
- const { groupIndex, groupLabel } = data.gridGroupPositionFn(event)
548
- const groupData = data.GroupDataMap.get(groupLabel)!
549
- const targetDatum = groupData.find(d => d.seriesLabel === seriesLabel)
550
- const _datum = targetDatum ?? datum[0]
551
-
552
- event$.next({
553
- type: 'grid',
554
- eventName: 'mouseout',
555
- pluginName,
556
- highlightTarget: data.highlightTarget,
557
- datum: _datum,
558
- gridIndex: _datum.gridIndex,
559
- series: data.SeriesDataMap.get(_datum.seriesLabel)!,
560
- seriesIndex: _datum.seriesIndex,
561
- seriesLabel: _datum.seriesLabel,
562
- groups: data.GroupDataMap.get(_datum.groupLabel)!,
563
- groupIndex: _datum.groupIndex,
564
- groupLabel: _datum.groupLabel,
565
- event,
566
- data: data.computedData
567
- })
568
- })
569
- .on('click', (event, datum) => {
570
- // event.stopPropagation()
571
-
572
- const seriesLabel = datum[0] ? datum[0].seriesLabel : ''
573
- const { groupIndex, groupLabel } = data.gridGroupPositionFn(event)
574
- const groupData = data.GroupDataMap.get(groupLabel)!
575
- const targetDatum = groupData.find(d => d.seriesLabel === seriesLabel)
576
- const _datum = targetDatum ?? datum[0]
577
-
578
- event$.next({
579
- type: 'grid',
580
- eventName: 'click',
581
- pluginName,
582
- highlightTarget: data.highlightTarget,
583
- datum: _datum,
584
- gridIndex: _datum.gridIndex,
585
- series: data.SeriesDataMap.get(_datum.seriesLabel)!,
586
- seriesIndex: _datum.seriesIndex,
587
- seriesLabel: _datum.seriesLabel,
588
- groups: data.GroupDataMap.get(_datum.groupLabel)!,
589
- groupIndex: _datum.groupIndex,
590
- groupLabel: _datum.groupLabel,
591
- event,
592
- data: data.computedData
593
- })
594
- })
595
- })
596
- })
597
-
598
- // const datumList$ = computedData$.pipe(
599
- // takeUntil(destroy$),
600
- // map(d => d.flat())
601
- // )
602
- // const highlight$ = highlightObservable({ datumList$, fullChartParams$, event$: store.event$ })
603
- // const highlightSubscription = gridHighlight$.subscribe()
604
-
605
- fullChartParams$.pipe(
606
- takeUntil(destroy$),
607
- filter(d => d.highlightTarget === 'series'),
608
- switchMap(d => combineLatest({
609
- graphicGSelection: graphicGSelection$,
610
- gridHighlight: gridHighlight$,
611
- DataMap: DataMap$,
612
- fullChartParams: fullChartParams$
613
- }).pipe(
614
- takeUntil(destroy$),
615
- switchMap(async d => d)
616
- ))
617
- ).subscribe(data => {
618
- const seriesLabel = data.gridHighlight[0] ? data.gridHighlight[0].seriesLabel : null
619
- highlightLineAreas({
620
- selection: data.graphicGSelection,
621
- seriesLabel,
622
- fullChartParams: data.fullChartParams
623
- })
624
- })
625
-
626
- return () => {
627
- destroy$.next(undefined)
628
- // highlightSubscription.unsubscribe()
629
- }
1
+ import * as d3 from 'd3'
2
+ import {
3
+ combineLatest,
4
+ map,
5
+ filter,
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
+ ContainerPositionScaled,
20
+ ChartParams,
21
+ Layout,
22
+ TransformData
23
+ } from '../../lib/core-types'
24
+ import type { BaseLineAreasParams } from '../../lib/plugins-basic-types'
25
+ import { getD3TransitionEase } from '../utils/d3Utils'
26
+ import { getClassName, getUniID, getMinMaxValue } from '../utils/orbchartsUtils'
27
+ import { gridGroupPositionFnObservable } from '../grid/gridObservables'
28
+ import { gridSelectionsObservable } from '../grid/gridObservables'
29
+
30
+ // export interface BaseLineAreasParams {
31
+ // lineCurve: string
32
+ // // lineWidth: number
33
+ // linearGradientOpacity: [number, number]
34
+ // }
35
+
36
+ interface BaseLineAreasContext {
37
+ selection: d3.Selection<any, unknown, any, unknown>
38
+ computedData$: Observable<ComputedDataGrid>
39
+ computedLayoutData$: Observable<ComputedLayoutDataGrid>
40
+ visibleComputedData$: Observable<ComputedDatumGrid[][]>
41
+ visibleComputedLayoutData$: Observable<ComputedLayoutDataGrid>
42
+ seriesLabels$: Observable<string[]>
43
+ SeriesDataMap$: Observable<Map<string, ComputedDatumGrid[]>>
44
+ GroupDataMap$: Observable<Map<string, ComputedDatumGrid[]>>
45
+ fullDataFormatter$: Observable<DataFormatterGrid>
46
+ fullParams$: Observable<BaseLineAreasParams>
47
+ fullChartParams$: Observable<ChartParams>
48
+ gridAxesTransform$: Observable<TransformData>
49
+ gridGraphicTransform$: Observable<TransformData>
50
+ gridAxesSize$: Observable<{
51
+ width: number;
52
+ height: number;
53
+ }>
54
+ gridHighlight$: Observable<ComputedDatumGrid[]>
55
+ gridContainerPosition$: Observable<ContainerPositionScaled[]>
56
+ allContainerPosition$: Observable<ContainerPositionScaled[]>
57
+ layout$: Observable<Layout>
58
+ event$: Subject<EventGrid>
59
+ }
60
+
61
+ type ClipPathDatum = {
62
+ id: string;
63
+ // x: number;
64
+ // y: number;
65
+ width: number;
66
+ height: number;
67
+ }
68
+
69
+ // const pluginName = 'Lines'
70
+ // const pathClassName = getClassName(pluginName, 'path')
71
+
72
+
73
+ function createAreaPath (lineCurve: string = 'curveLinear', valueAxisStart: number): d3.Line<ComputedLayoutDatumGrid> {
74
+ return d3.area<ComputedLayoutDatumGrid>()
75
+ .x((d) => d.axisX)
76
+ .y0(d => valueAxisStart)
77
+ .y1((d) => d.axisY)
78
+ .curve((d3 as any)[lineCurve])
79
+
80
+ }
81
+
82
+ // 依無值的資料分段
83
+ function makeSegmentData (data: ComputedLayoutDatumGrid[]): ComputedLayoutDatumGrid[][] {
84
+ let segmentData: ComputedLayoutDatumGrid[][] = [[]]
85
+
86
+ let currentIndex = 0
87
+ for (let i in data) {
88
+ if (data[i].visible == false || data[i].value === undefined || data[i].value === null) {
89
+ // 換下一段的 index
90
+ if (segmentData[currentIndex].length) {
91
+ currentIndex ++
92
+ segmentData[currentIndex] = []
93
+ }
94
+ continue
95
+ }
96
+ segmentData[currentIndex].push(data[i])
97
+ }
98
+
99
+ return segmentData
100
+ }
101
+
102
+
103
+ function renderLineAreas ({ selection, pathClassName, segmentData, areaPath, linearGradientIds, params }: {
104
+ selection: d3.Selection<SVGGElement, unknown, any, unknown>
105
+ pathClassName: string
106
+ segmentData: ComputedLayoutDatumGrid[][]
107
+ areaPath: d3.Line<ComputedLayoutDatumGrid>
108
+ linearGradientIds: string[]
109
+ params: BaseLineAreasParams
110
+ }): d3.Selection<SVGPathElement, ComputedLayoutDatumGrid[], any, any> {
111
+ // if (!data[0]) {
112
+ // return undefined
113
+ // }
114
+
115
+ const lineAreas = selection
116
+ .selectAll<SVGPathElement, ComputedLayoutDatumGrid[]>('path')
117
+ .data(segmentData, (d, i) => d.length ? `${d[0].id}_${d[d.length - 1].id}` : i) // 以線段起迄id結合為線段id
118
+ .join(
119
+ enter => {
120
+ return enter
121
+ .append<SVGPathElement>('path')
122
+ .classed(pathClassName, true)
123
+ .attr("fill","none")
124
+ // .attr('pointer-events', 'visibleStroke') // 只對線條產生事件
125
+ .style('vector-effect', 'non-scaling-stroke')
126
+ .style('cursor', 'pointer')
127
+ },
128
+ update => update,
129
+ exit => exit.remove()
130
+ )
131
+ // .attr("stroke-width", params.lineWidth)
132
+ // .attr("stroke", (d, i) => d[0] && d[0].color)
133
+ .attr("fill", (d, i) => d[0] ? `url(#${linearGradientIds[d[0].seriesIndex]})` : '')
134
+ .attr("d", (d) => {
135
+ return areaPath(d)
136
+ })
137
+
138
+ return lineAreas
139
+ }
140
+
141
+ function highlightLineAreas ({ selection, seriesLabel, fullChartParams }: {
142
+ selection: d3.Selection<any, string, any, any>
143
+ seriesLabel: string | null
144
+ fullChartParams: ChartParams
145
+ }) {
146
+ selection.interrupt('highlight')
147
+ if (!seriesLabel) {
148
+ // remove highlight
149
+ selection
150
+ .transition('highlight')
151
+ .duration(200)
152
+ .style('opacity', 1)
153
+ return
154
+ }
155
+
156
+ selection
157
+ .each((currentSeriesLabel, i, n) => {
158
+ // const currentSeriesLabel = d[0] ? d[0].seriesLabel : ''
159
+
160
+ if (currentSeriesLabel === seriesLabel) {
161
+ d3.select(n[i])
162
+ .style('opacity', 1)
163
+ } else {
164
+ d3.select(n[i])
165
+ .style('opacity', fullChartParams.styles.unhighlightedOpacity)
166
+ }
167
+ })
168
+ }
169
+
170
+ function renderLinearGradient ({ defsSelection, computedData, linearGradientIds, params }: {
171
+ defsSelection: d3.Selection<SVGDefsElement, any, any, any>
172
+ computedData: ComputedDataGrid
173
+ linearGradientIds: string[]
174
+ params: BaseLineAreasParams
175
+ }) {
176
+ defsSelection!
177
+ .selectAll<SVGLinearGradientElement, ComputedDatumGrid>('linearGradient')
178
+ .data(computedData ?? [])
179
+ .join(
180
+ enter => {
181
+ return enter
182
+ .append('linearGradient')
183
+ .attr('x1', '0%')
184
+ .attr('x2', '0%')
185
+ .attr('y1', '100%')
186
+ .attr('y2', '0%')
187
+ .attr('spreadMethod', 'pad')
188
+ },
189
+ update => update,
190
+ exit => exit.remove()
191
+ )
192
+ .attr('id', (d, i) => {
193
+ return d[0] ? linearGradientIds[d[0].seriesIndex] : ''
194
+ })
195
+ .html((d, i) => {
196
+ const color = d[0] ? d[0].color : ''
197
+ return `
198
+ <stop offset="0%" stop-color="${color}" stop-opacity="${params.linearGradientOpacity[0]}"/>
199
+ <stop offset="100%" stop-color="${color}" stop-opacity="${params.linearGradientOpacity[1]}"/>
200
+ `
201
+ })
202
+
203
+ }
204
+
205
+ function renderClipPath ({ defsSelection, clipPathData, transitionDuration, transitionEase }: {
206
+ defsSelection: d3.Selection<SVGDefsElement, any, any, any>
207
+ clipPathData: ClipPathDatum[]
208
+ transitionDuration: number
209
+ transitionEase: string
210
+ }) {
211
+ const clipPath = defsSelection
212
+ .selectAll<SVGClipPathElement, Layout>('clipPath')
213
+ .data(clipPathData)
214
+ .join(
215
+ enter => {
216
+ return enter
217
+ .append('clipPath')
218
+ },
219
+ update => update,
220
+ exit => exit.remove()
221
+ )
222
+ .attr('id', d => d.id)
223
+ .each((d, i, g) => {
224
+ const rect = d3.select(g[i])
225
+ .selectAll<SVGRectElement, typeof d>('rect')
226
+ .data([d])
227
+ .join(
228
+ enter => {
229
+ const enterSelection = enter
230
+ .append('rect')
231
+ enterSelection
232
+ .transition()
233
+ .duration(transitionDuration)
234
+ .ease(getD3TransitionEase(transitionEase))
235
+ // .delay(100) // @Q@ 不知為何如果沒加 delay位置會有點跑掉
236
+ .tween('tween', (_d, _i, _g) => {
237
+ return (t) => {
238
+ const transitionWidth = _d.width * t
239
+
240
+ enterSelection
241
+ .attr('x', 0)
242
+ .attr('y', 0)
243
+ .attr('width', _d => transitionWidth)
244
+ .attr('height', _d => _d.height)
245
+ }
246
+ })
247
+ return enterSelection
248
+ },
249
+ update => {
250
+ return update
251
+ .attr('x', 0)
252
+ .attr('y', 0)
253
+ .attr('width', _d => _d.width)
254
+ .attr('height', _d => _d.height)
255
+ },
256
+ exit => exit.remove()
257
+ )
258
+ })
259
+
260
+ }
261
+
262
+ export const createBaseLineAreas: BasePluginFn<BaseLineAreasContext> = (pluginName: string, {
263
+ selection,
264
+ computedData$,
265
+ computedLayoutData$,
266
+ visibleComputedData$,
267
+ visibleComputedLayoutData$,
268
+ seriesLabels$,
269
+ SeriesDataMap$,
270
+ GroupDataMap$,
271
+ fullParams$,
272
+ fullDataFormatter$,
273
+ fullChartParams$,
274
+ gridAxesTransform$,
275
+ gridGraphicTransform$,
276
+ gridAxesSize$,
277
+ gridHighlight$,
278
+ gridContainerPosition$,
279
+ layout$,
280
+ event$
281
+ }) => {
282
+
283
+ const destroy$ = new Subject()
284
+
285
+ const clipPathID = getUniID(pluginName, 'clipPath-box')
286
+ const pathClassName = getClassName(pluginName, 'path')
287
+
288
+ const {
289
+ seriesSelection$,
290
+ axesSelection$,
291
+ defsSelection$,
292
+ graphicGSelection$
293
+ } = gridSelectionsObservable({
294
+ selection,
295
+ pluginName,
296
+ clipPathID,
297
+ seriesLabels$,
298
+ gridContainerPosition$,
299
+ gridAxesTransform$,
300
+ gridGraphicTransform$
301
+ })
302
+
303
+ // valueAxis 的起始座標
304
+ const valueAxisStart$: Observable<number> = gridGraphicTransform$.pipe(
305
+ takeUntil(destroy$),
306
+ map(data => {
307
+ // 抵消掉外層的變型
308
+ return - data.translate[1] / data.scale[1]
309
+ })
310
+ )
311
+
312
+ const areaPath$: Observable<d3.Line<ComputedLayoutDatumGrid>> = new Observable(subscriber => {
313
+ const paramsSubscription = combineLatest({
314
+ fullParams: fullParams$,
315
+ valueAxisStart: valueAxisStart$
316
+ }).pipe(
317
+ takeUntil(destroy$)
318
+ )
319
+ .subscribe(d => {
320
+ const areaPath = createAreaPath(d.fullParams.lineCurve, d.valueAxisStart)
321
+ subscriber.next(areaPath)
322
+ })
323
+ return () => {
324
+ paramsSubscription.unsubscribe()
325
+ }
326
+ })
327
+
328
+ // // 顯示範圍內的series labels
329
+ // const seriesLabels$: Observable<string[]> = new Observable(subscriber => {
330
+ // computedData$.pipe(
331
+ // takeUntil(destroy$),
332
+ // switchMap(async (d) => d),
333
+ // ).subscribe(data => {
334
+ // const labels = data[0] && data[0][0]
335
+ // ? data.map(d => d[0].seriesLabel)
336
+ // : []
337
+ // subscriber.next(labels)
338
+ // })
339
+ // })
340
+
341
+ // const axisSize$ = gridAxisSizeObservable({
342
+ // fullDataFormatter$,
343
+ // computedLayout$
344
+ // })
345
+
346
+ const transitionDuration$ = fullChartParams$
347
+ .pipe(
348
+ map(d => d.transitionDuration),
349
+ distinctUntilChanged()
350
+ )
351
+
352
+ const transitionEase$ = fullChartParams$
353
+ .pipe(
354
+ map(d => d.transitionEase),
355
+ distinctUntilChanged()
356
+ )
357
+
358
+ const clipPathSubscription = combineLatest({
359
+ defsSelection: defsSelection$,
360
+ seriesLabels: seriesLabels$,
361
+ axisSize: gridAxesSize$,
362
+ transitionDuration: transitionDuration$,
363
+ transitionEase: transitionEase$
364
+ }).pipe(
365
+ takeUntil(destroy$),
366
+ switchMap(async (d) => d),
367
+ ).subscribe(data => {
368
+ // 外層的遮罩
369
+ const clipPathBox = [{
370
+ id: clipPathID,
371
+ width: data.axisSize.width,
372
+ height: data.axisSize.height
373
+ }]
374
+ // 各別線條的遮罩(各別動畫)
375
+ const clipPathData = clipPathBox.concat(
376
+ data.seriesLabels.map(d => {
377
+ return {
378
+ id: `orbcharts__clipPath_${d}`,
379
+ width: data.axisSize.width,
380
+ height: data.axisSize.height
381
+ }
382
+ })
383
+ )
384
+ renderClipPath({
385
+ defsSelection: data.defsSelection,
386
+ clipPathData,
387
+ transitionDuration: data.transitionDuration,
388
+ transitionEase: data.transitionEase
389
+ })
390
+ })
391
+
392
+ // const SeriesDataMap$ = computedData$.pipe(
393
+ // map(d => makeGridSeriesDataMap(d))
394
+ // )
395
+
396
+ // const GroupDataMap$ = computedData$.pipe(
397
+ // map(d => makeGridGroupDataMap(d))
398
+ // )
399
+
400
+ const DataMap$ = computedData$.pipe(
401
+ map(d => {
402
+ const DataMap: Map<string, ComputedDatumGrid> = new Map()
403
+ d.flat().forEach(_d => DataMap.set(_d.id, _d))
404
+ return DataMap
405
+ })
406
+ )
407
+
408
+ // 取得事件座標的group資料
409
+ const gridGroupPositionFn$ = gridGroupPositionFnObservable({
410
+ fullDataFormatter$,
411
+ gridAxesSize$: gridAxesSize$,
412
+ computedData$: computedData$,
413
+ fullChartParams$: fullChartParams$,
414
+ gridContainerPosition$: gridContainerPosition$,
415
+ layout$: layout$
416
+ })
417
+
418
+ const highlightTarget$ = fullChartParams$.pipe(
419
+ takeUntil(destroy$),
420
+ map(d => d.highlightTarget),
421
+ distinctUntilChanged()
422
+ )
423
+
424
+ const linearGradientIds$ = seriesLabels$.pipe(
425
+ takeUntil(destroy$),
426
+ map(d => d.map((d, i) => {
427
+ return getUniID(pluginName, `lineargradient-${d}`)
428
+ }))
429
+ )
430
+
431
+ const pathSelectionArr$ = combineLatest({
432
+ graphicGSelection: graphicGSelection$,
433
+ defsSelection: defsSelection$,
434
+ visibleComputedLayoutData: visibleComputedLayoutData$,
435
+ linearGradientIds: linearGradientIds$,
436
+ areaPath: areaPath$,
437
+ params: fullParams$,
438
+ }).pipe(
439
+ takeUntil(destroy$),
440
+ switchMap(async (d) => d),
441
+ map(data => {
442
+ // const updateGraphic = data.graphicGSelection
443
+ // .selectAll<SVGGElement, number>('g')
444
+ // .data(data.seriesLabels, (d, i) => d)
445
+ // const enterGraphic = updateGraphic.enter()
446
+ // .append('g')
447
+ // .classed(graphicClassName, true)
448
+ // updateGraphic.exit().remove()
449
+ // const graphicSelection = updateGraphic.merge(enterGraphic)
450
+ // .attr('clip-path', (d, i) => `url(#orbcharts__clipPath_${d})`)
451
+ let pathSelectionArr: d3.Selection<SVGPathElement, ComputedLayoutDatumGrid[], any, any>[] = []
452
+
453
+ // 繪圖
454
+ data.graphicGSelection.each((d, i, all) => {
455
+ // 將資料分段
456
+ const segmentData = makeSegmentData(data.visibleComputedLayoutData[i] ?? [])
457
+
458
+ pathSelectionArr[i] = renderLineAreas({
459
+ selection: d3.select(all[i]),
460
+ pathClassName,
461
+ areaPath: data.areaPath,
462
+ segmentData: segmentData,
463
+ linearGradientIds: data.linearGradientIds,
464
+ params: data.params
465
+ })
466
+ renderLinearGradient({
467
+ defsSelection: data.defsSelection,
468
+ computedData: data.visibleComputedLayoutData,
469
+ linearGradientIds: data.linearGradientIds,
470
+ params: data.params
471
+ })
472
+ })
473
+
474
+ return pathSelectionArr
475
+ })
476
+ )
477
+
478
+ combineLatest({
479
+ pathSelectionArr: pathSelectionArr$,
480
+ computedData: computedData$,
481
+ SeriesDataMap: SeriesDataMap$,
482
+ GroupDataMap: GroupDataMap$,
483
+ highlightTarget: highlightTarget$,
484
+ gridGroupPositionFn: gridGroupPositionFn$,
485
+ }).pipe(
486
+ takeUntil(destroy$),
487
+ switchMap(async (d) => d),
488
+ ).subscribe(data => {
489
+ data.pathSelectionArr.forEach(pathSelection => {
490
+ pathSelection
491
+ .on('mouseover', (event, datum) => {
492
+ // event.stopPropagation()
493
+
494
+ const seriesLabel = datum[0] ? datum[0].seriesLabel : ''
495
+ const { groupIndex, groupLabel } = data.gridGroupPositionFn(event)
496
+ const groupData = data.GroupDataMap.get(groupLabel)!
497
+ const targetDatum = groupData.find(d => d.seriesLabel === seriesLabel)
498
+ const _datum = targetDatum ?? datum[0]
499
+
500
+ event$.next({
501
+ type: 'grid',
502
+ eventName: 'mouseover',
503
+ pluginName,
504
+ highlightTarget: data.highlightTarget,
505
+ datum: _datum,
506
+ gridIndex: _datum.gridIndex,
507
+ series: data.SeriesDataMap.get(_datum.seriesLabel)!,
508
+ seriesIndex: _datum.seriesIndex,
509
+ seriesLabel: _datum.seriesLabel,
510
+ groups: data.GroupDataMap.get(_datum.groupLabel)!,
511
+ groupIndex: _datum.groupIndex,
512
+ groupLabel: _datum.groupLabel,
513
+ event,
514
+ data: data.computedData
515
+ })
516
+ })
517
+ .on('mousemove', (event, datum) => {
518
+ // event.stopPropagation()
519
+
520
+ const seriesLabel = datum[0] ? datum[0].seriesLabel : ''
521
+ const { groupIndex, groupLabel } = data.gridGroupPositionFn(event)
522
+ const groupData = data.GroupDataMap.get(groupLabel)!
523
+ const targetDatum = groupData.find(d => d.seriesLabel === seriesLabel)
524
+ const _datum = targetDatum ?? datum[0]
525
+
526
+ event$.next({
527
+ type: 'grid',
528
+ eventName: 'mousemove',
529
+ pluginName,
530
+ highlightTarget: data.highlightTarget,
531
+ datum: _datum,
532
+ gridIndex: _datum.gridIndex,
533
+ series: data.SeriesDataMap.get(_datum.seriesLabel)!,
534
+ seriesIndex: _datum.seriesIndex,
535
+ seriesLabel: _datum.seriesLabel,
536
+ groups: data.GroupDataMap.get(_datum.groupLabel)!,
537
+ groupIndex: _datum.groupIndex,
538
+ groupLabel: _datum.groupLabel,
539
+ event,
540
+ data: data.computedData
541
+ })
542
+ })
543
+ .on('mouseout', (event, datum) => {
544
+ // event.stopPropagation()
545
+
546
+ const seriesLabel = datum[0] ? datum[0].seriesLabel : ''
547
+ const { groupIndex, groupLabel } = data.gridGroupPositionFn(event)
548
+ const groupData = data.GroupDataMap.get(groupLabel)!
549
+ const targetDatum = groupData.find(d => d.seriesLabel === seriesLabel)
550
+ const _datum = targetDatum ?? datum[0]
551
+
552
+ event$.next({
553
+ type: 'grid',
554
+ eventName: 'mouseout',
555
+ pluginName,
556
+ highlightTarget: data.highlightTarget,
557
+ datum: _datum,
558
+ gridIndex: _datum.gridIndex,
559
+ series: data.SeriesDataMap.get(_datum.seriesLabel)!,
560
+ seriesIndex: _datum.seriesIndex,
561
+ seriesLabel: _datum.seriesLabel,
562
+ groups: data.GroupDataMap.get(_datum.groupLabel)!,
563
+ groupIndex: _datum.groupIndex,
564
+ groupLabel: _datum.groupLabel,
565
+ event,
566
+ data: data.computedData
567
+ })
568
+ })
569
+ .on('click', (event, datum) => {
570
+ // event.stopPropagation()
571
+
572
+ const seriesLabel = datum[0] ? datum[0].seriesLabel : ''
573
+ const { groupIndex, groupLabel } = data.gridGroupPositionFn(event)
574
+ const groupData = data.GroupDataMap.get(groupLabel)!
575
+ const targetDatum = groupData.find(d => d.seriesLabel === seriesLabel)
576
+ const _datum = targetDatum ?? datum[0]
577
+
578
+ event$.next({
579
+ type: 'grid',
580
+ eventName: 'click',
581
+ pluginName,
582
+ highlightTarget: data.highlightTarget,
583
+ datum: _datum,
584
+ gridIndex: _datum.gridIndex,
585
+ series: data.SeriesDataMap.get(_datum.seriesLabel)!,
586
+ seriesIndex: _datum.seriesIndex,
587
+ seriesLabel: _datum.seriesLabel,
588
+ groups: data.GroupDataMap.get(_datum.groupLabel)!,
589
+ groupIndex: _datum.groupIndex,
590
+ groupLabel: _datum.groupLabel,
591
+ event,
592
+ data: data.computedData
593
+ })
594
+ })
595
+ })
596
+ })
597
+
598
+ // const datumList$ = computedData$.pipe(
599
+ // takeUntil(destroy$),
600
+ // map(d => d.flat())
601
+ // )
602
+ // const highlight$ = highlightObservable({ datumList$, fullChartParams$, event$: store.event$ })
603
+ // const highlightSubscription = gridHighlight$.subscribe()
604
+
605
+ fullChartParams$.pipe(
606
+ takeUntil(destroy$),
607
+ filter(d => d.highlightTarget === 'series'),
608
+ switchMap(d => combineLatest({
609
+ graphicGSelection: graphicGSelection$,
610
+ gridHighlight: gridHighlight$,
611
+ DataMap: DataMap$,
612
+ fullChartParams: fullChartParams$
613
+ }).pipe(
614
+ takeUntil(destroy$),
615
+ switchMap(async d => d)
616
+ ))
617
+ ).subscribe(data => {
618
+ const seriesLabel = data.gridHighlight[0] ? data.gridHighlight[0].seriesLabel : null
619
+ highlightLineAreas({
620
+ selection: data.graphicGSelection,
621
+ seriesLabel,
622
+ fullChartParams: data.fullChartParams
623
+ })
624
+ })
625
+
626
+ return () => {
627
+ destroy$.next(undefined)
628
+ // highlightSubscription.unsubscribe()
629
+ }
630
630
  }