@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,680 +1,692 @@
1
- import * as d3 from 'd3'
2
- import {
3
- combineLatest,
4
- switchMap,
5
- distinctUntilChanged,
6
- of,
7
- first,
8
- map,
9
- takeUntil,
10
- shareReplay,
11
- Observable,
12
- Subject } from 'rxjs'
13
- import type {
14
- ColorType,
15
- ComputedDataGrid,
16
- ContainerPositionScaled,
17
- ComputedDatumGrid,
18
- DataFormatterGrid,
19
- ChartParams,
20
- TransformData
21
- } from '../../lib/core-types'
22
- import type { BaseGroupAxisParams } from '../../lib/plugins-basic-types'
23
- import type { BasePluginFn } from './types'
24
- import { parseTickFormatValue } from '../utils/d3Utils'
25
- import { getColor, getClassName } from '../utils/orbchartsUtils'
26
- import { renderTspansOnAxis } from '../utils/d3Graphics'
27
-
28
- // export interface BaseGroupAxisParams {
29
- // // xLabel: string
30
- // // labelAnchor: 'start' | 'end'
31
- // labelOffset: [number, number]
32
- // labelColorType: ColorType
33
- // axisLineVisible: boolean
34
- // axisLineColorType: ColorType
35
- // ticks: number | null | 'all'
36
- // tickFormat: string | ((text: any) => string)
37
- // tickLineVisible: boolean
38
- // tickPadding: number
39
- // tickFullLine: boolean
40
- // tickFullLineDasharray: string
41
- // tickColorType: ColorType
42
- // // axisLineColor: string
43
- // // axisLabelColor: string
44
- // tickTextRotate: number
45
- // tickTextColorType: ColorType
46
- // }
47
-
48
- interface BaseGroupAxisContext {
49
- selection: d3.Selection<any, unknown, any, unknown>
50
- computedData$: Observable<ComputedDataGrid>
51
- fullParams$: Observable<BaseGroupAxisParams>
52
- fullDataFormatter$: Observable<DataFormatterGrid>
53
- fullChartParams$: Observable<ChartParams>
54
- gridAxesTransform$: Observable<TransformData>
55
- gridAxesReverseTransform$: Observable<TransformData>
56
- gridAxesSize$: Observable<{
57
- width: number;
58
- height: number;
59
- }>
60
- gridContainerPosition$: Observable<ContainerPositionScaled[]>
61
- isSeriesSeprate$: Observable<boolean>
62
- textSizePx$: Observable<number>
63
- }
64
-
65
- interface TextAlign {
66
- textAnchor: "start" | "middle" | "end"
67
- dominantBaseline: "middle" | "auto" | "hanging"
68
- }
69
-
70
- interface GroupLabelData {
71
- text: string
72
- textArr: string[]
73
- }
74
-
75
- // const pluginName = 'GroupAxis'
76
- // const containerClassName = getClassName(pluginName, 'container')
77
- // const xAxisGClassName = getClassName(pluginName, 'xAxisG')
78
- // const xAxisClassName = getClassName(pluginName, 'xAxis')
79
- // const groupingLabelClassName = getClassName(pluginName, 'groupingLabel')
80
- const defaultTickSize = 6
81
-
82
- function createGroupLabelData (groupLabels: string[], tickFormat: string | ((text: any) => string | d3.NumberValue)): GroupLabelData[] {
83
- return groupLabels.map((_text, i) => {
84
- const text = parseTickFormatValue(_text, tickFormat)
85
- const textArr = typeof text === 'string' ? text.split('\n') : [text]
86
-
87
- return {
88
- text,
89
- textArr
90
- }
91
- })
92
- }
93
-
94
- function renderAxisLabel ({ selection, groupingLabelClassName, fullParams, axisLabelAlign, gridAxesSize, fullDataFormatter, chartParams, textReverseTransform }: {
95
- selection: d3.Selection<SVGGElement, any, any, any>,
96
- groupingLabelClassName: string
97
- fullParams: BaseGroupAxisParams
98
- axisLabelAlign: TextAlign
99
- gridAxesSize: { width: number, height: number }
100
- fullDataFormatter: DataFormatterGrid,
101
- chartParams: ChartParams
102
- textReverseTransform: string
103
- }) {
104
-
105
- const offsetX = fullParams.tickPadding + fullParams.labelOffset[0]
106
- const offsetY = fullParams.tickPadding + fullParams.labelOffset[1]
107
- let labelX = 0
108
- let labelY = 0
109
- if (fullDataFormatter.groupAxis.position === 'bottom') {
110
- labelY = offsetY
111
- if (fullDataFormatter.valueAxis.position === 'left') {
112
- labelX = offsetX
113
- } else if (fullDataFormatter.valueAxis.position === 'right') {
114
- labelX = - offsetX
115
- }
116
- } else if (fullDataFormatter.groupAxis.position === 'top') {
117
- labelY = - offsetY
118
- if (fullDataFormatter.valueAxis.position === 'left') {
119
- labelX = offsetX
120
- } else if (fullDataFormatter.valueAxis.position === 'right') {
121
- labelX = - offsetX
122
- }
123
- } else if (fullDataFormatter.groupAxis.position === 'left') {
124
- labelX = - offsetX
125
- if (fullDataFormatter.valueAxis.position === 'bottom') {
126
- labelY = - offsetY
127
- } else if (fullDataFormatter.valueAxis.position === 'top') {
128
- labelY = offsetY
129
- }
130
- } else if (fullDataFormatter.groupAxis.position === 'right') {
131
- labelX = offsetX
132
- if (fullDataFormatter.valueAxis.position === 'bottom') {
133
- labelY = - offsetY
134
- } else if (fullDataFormatter.valueAxis.position === 'top') {
135
- labelY = offsetY
136
- }
137
- }
138
-
139
- const axisLabelSelection = selection
140
- .selectAll<SVGGElement, BaseGroupAxisParams>(`g.${groupingLabelClassName}`)
141
- .data([fullParams])
142
- .join('g')
143
- .classed(groupingLabelClassName, true)
144
- .each((d, i, g) => {
145
- const text = d3.select(g[i])
146
- .selectAll<SVGTextElement, BaseGroupAxisParams>('text')
147
- .data([d])
148
- .join(
149
- enter => {
150
- return enter
151
- .append('text')
152
- .style('font-weight', 'bold')
153
- },
154
- update => update,
155
- exit => exit.remove()
156
- )
157
- .attr('text-anchor', axisLabelAlign.textAnchor)
158
- .attr('dominant-baseline', axisLabelAlign.dominantBaseline)
159
- .attr('font-size', chartParams.styles.textSize)
160
- .style('fill', getColor(fullParams.labelColorType, chartParams))
161
- .style('transform', textReverseTransform)
162
- // 偏移使用 x, y 而非 transform 才不會受到外層 scale 變形影響
163
- .attr('x', labelX)
164
- .attr('y', labelY)
165
- .text(d => fullDataFormatter.groupAxis.label)
166
- })
167
- .attr('transform', d => `translate(${gridAxesSize.width}, 0)`)
168
- // .attr('transform', d => `translate(${gridAxesSize.width + d.tickPadding + fullParams.labelOffset[0]}, ${- d.tickPadding - fullParams.labelOffset[1]})`)
169
-
170
- }
171
-
172
- function renderAxis ({ selection, xAxisClassName, fullParams, tickTextAlign, gridAxesSize, fullDataFormatter, chartParams, groupScale, groupScaleDomain, groupLabelData, textReverseTransformWithRotate, textSizePx }: {
173
- selection: d3.Selection<SVGGElement, any, any, any>,
174
- xAxisClassName: string
175
- fullParams: BaseGroupAxisParams
176
- tickTextAlign: TextAlign
177
- gridAxesSize: { width: number, height: number }
178
- fullDataFormatter: DataFormatterGrid,
179
- chartParams: ChartParams
180
- groupScale: d3.ScaleLinear<number, number>
181
- groupScaleDomain: number[]
182
- // groupLabels: string[]
183
- groupLabelData: GroupLabelData[]
184
- textReverseTransformWithRotate: string
185
- textSizePx: number
186
- }) {
187
-
188
- const xAxisSelection = selection
189
- .selectAll<SVGGElement, BaseGroupAxisParams>(`g.${xAxisClassName}`)
190
- .data([fullParams])
191
- .join('g')
192
- .classed(xAxisClassName, true)
193
-
194
- // 計算所有範圍內groupLabels數量(顯示所有刻度)
195
- const allTicksAmount = Math.floor(groupScaleDomain[1]) - Math.ceil(groupScaleDomain[0]) + 1
196
-
197
- // 刻度文字偏移
198
- let tickPadding = 0
199
- let textX = 0
200
- if (fullDataFormatter.groupAxis.position === 'left') {
201
- tickPadding = 0
202
- textX = - fullParams.tickPadding
203
- } else if (fullDataFormatter.groupAxis.position === 'right') {
204
- tickPadding = 0
205
- textX = fullParams.tickPadding
206
- } else if (fullDataFormatter.groupAxis.position === 'bottom') {
207
- tickPadding = fullParams.tickPadding
208
- textX = 0
209
- } else if (fullDataFormatter.groupAxis.position === 'top') {
210
- tickPadding = - fullParams.tickPadding
211
- textX = - 0
212
- }
213
-
214
- // 設定X軸刻度
215
- const xAxis = d3.axisBottom(groupScale)
216
- .scale(groupScale)
217
- .ticks(fullParams.ticks === 'all'
218
- ? allTicksAmount
219
- : fullParams.ticks > allTicksAmount
220
- ? allTicksAmount // 不顯示超過groupLabels數量的刻度
221
- : fullParams.ticks)
222
- .tickSize(fullParams.tickFullLine == true
223
- ? gridAxesSize.height
224
- : - defaultTickSize)
225
- .tickSizeOuter(0)
226
- .tickFormat((groupIndex: number) => {
227
- // 用index對應到groupLabel
228
- // const groupLabel = groupLabels[groupIndex] ?? '' // 非整數index不顯示
229
- // return parseTickFormatValue(groupLabel, fullParams.tickFormat)
230
- return groupLabelData[groupIndex]?.text ?? ''
231
- })
232
- .tickPadding(tickPadding)
233
-
234
- const xAxisEl = xAxisSelection
235
- .transition()
236
- .duration(100)
237
- .call(xAxis)
238
- .on('end', (self, t) => {
239
- // 先等transition結束再處理文字,否則會被原本的文字覆蓋
240
- xAxisSelection
241
- .selectAll('.tick text')
242
- .each((groupIndex: number, i, n) => {
243
- // const groupLabel = groupLabels[groupIndex] ?? '' // 非整數index不顯示
244
- // const groupLabelText = parseTickFormatValue(groupLabel, fullParams.tickFormat)
245
- const textArr = groupLabelData[groupIndex]?.textArr ?? []
246
-
247
- // 將原本單行文字改為多行文字
248
- renderTspansOnAxis(d3.select(n[i]), {
249
- textArr,
250
- textSizePx,
251
- groupAxisPosition: fullDataFormatter.groupAxis.position
252
- })
253
- })
254
- })
255
-
256
- xAxisEl.selectAll('line')
257
- .style('fill', 'none')
258
- .style('stroke', fullParams.tickLineVisible == true ? getColor(fullParams.tickColorType, chartParams) : 'none')
259
- .style('stroke-dasharray', fullParams.tickFullLineDasharray)
260
- .attr('pointer-events', 'none')
261
-
262
- xAxisEl.selectAll('path')
263
- .style('fill', 'none')
264
- .style('stroke', fullParams.axisLineVisible == true ? getColor(fullParams.axisLineColorType, chartParams) : 'none')
265
- .style('shape-rendering', 'crispEdges')
266
-
267
- const xText = xAxisSelection.selectAll<SVGTextElement, BaseGroupAxisParams>('text')
268
- // .style('font-family', 'sans-serif')
269
- .attr('font-size', chartParams.styles.textSize)
270
- // .style('font-weight', 'bold')
271
- .attr('fill', getColor(fullParams.tickTextColorType, chartParams))
272
- .attr('text-anchor', tickTextAlign.textAnchor)
273
- .attr('dominant-baseline', tickTextAlign.dominantBaseline)
274
- .attr('x', textX)
275
- .style('transform', textReverseTransformWithRotate)
276
-
277
- // 抵消掉預設的偏移
278
- // if (fullDataFormatter.groupAxis.position === 'left' || fullDataFormatter.groupAxis.position === 'right') {
279
- xText.attr('dy', 0)
280
- // }
281
-
282
- return xAxisSelection
283
- }
284
-
285
-
286
- export const createBaseGroupAxis: BasePluginFn<BaseGroupAxisContext> = ((pluginName: string, {
287
- selection,
288
- computedData$,
289
- fullParams$,
290
- fullDataFormatter$,
291
- fullChartParams$,
292
- gridAxesTransform$,
293
- gridAxesReverseTransform$,
294
- gridAxesSize$,
295
- gridContainerPosition$,
296
- isSeriesSeprate$,
297
- textSizePx$,
298
- }) => {
299
-
300
- const destroy$ = new Subject()
301
-
302
- const containerClassName = getClassName(pluginName, 'container')
303
- const xAxisGClassName = getClassName(pluginName, 'xAxisG')
304
- const xAxisClassName = getClassName(pluginName, 'xAxis')
305
- const groupingLabelClassName = getClassName(pluginName, 'groupingLabel')
306
-
307
- const containerSelection$ = combineLatest({
308
- computedData: computedData$.pipe(
309
- distinctUntilChanged((a, b) => {
310
- // 只有當series的數量改變時,才重新計算
311
- return a.length === b.length
312
- }),
313
- ),
314
- isSeriesSeprate: isSeriesSeprate$
315
- }).pipe(
316
- takeUntil(destroy$),
317
- switchMap(async (d) => d),
318
- map(data => {
319
- return data.isSeriesSeprate
320
- // series分開的時候顯示各別axis
321
- ? data.computedData
322
- // series合併的時候只顯示第一個axis
323
- : [data.computedData[0]]
324
- }),
325
- map((computedData, i) => {
326
- return selection
327
- .selectAll<SVGGElement, ComputedDatumGrid[]>(`g.${containerClassName}`)
328
- .data(computedData, d => d[0] ? d[0].seriesIndex : i)
329
- .join('g')
330
- .classed(containerClassName, true)
331
- })
332
- )
333
-
334
- const axisSelection$ = containerSelection$.pipe(
335
- takeUntil(destroy$),
336
- map((containerSelection, i) => {
337
- return containerSelection
338
- .selectAll<SVGGElement, ComputedDatumGrid[]>(`g.${xAxisGClassName}`)
339
- .data([xAxisGClassName])
340
- .join('g')
341
- .classed(xAxisGClassName, true)
342
- })
343
- )
344
-
345
- combineLatest({
346
- containerSelection: containerSelection$,
347
- gridContainerPosition: gridContainerPosition$
348
- }).pipe(
349
- takeUntil(destroy$),
350
- switchMap(async d => d)
351
- ).subscribe(data => {
352
- data.containerSelection
353
- .attr('transform', (d, i) => {
354
- const gridContainerPosition = data.gridContainerPosition[i] ?? data.gridContainerPosition[0]
355
- const translate = gridContainerPosition.translate
356
- const scale = gridContainerPosition.scale
357
- return `translate(${translate[0]}, ${translate[1]}) scale(${scale[0]}, ${scale[1]})`
358
- })
359
- // .attr('opacity', 0)
360
- // .transition()
361
- // .attr('opacity', 1)
362
- })
363
-
364
- combineLatest({
365
- axisSelection: axisSelection$,
366
- gridAxesTransform: gridAxesTransform$,
367
- }).pipe(
368
- takeUntil(destroy$),
369
- switchMap(async d => d)
370
- ).subscribe(data => {
371
- data.axisSelection
372
- .style('transform', data.gridAxesTransform.value)
373
- // .attr('opacity', 0)
374
- // .transition()
375
- // .attr('opacity', 1)
376
-
377
- })
378
-
379
-
380
- // const gridAxesSize$ = gridAxisSizeObservable({
381
- // fullDataFormatter$,
382
- // layout$
383
- // })
384
-
385
-
386
- // const tickTextFormatter$ = fullDataFormatter$
387
- // .pipe(
388
- // map(d => {
389
- // return d.seriesDirection === 'row' ? d.columnLabelFormat : d.rowLabelFormat
390
- // })
391
- // )
392
-
393
- // const textReverseTransform$: Observable<string> = new Observable(subscriber => {
394
- // combineLatest({
395
- // params: fullParams$,
396
- // gridAxesTransform: gridAxesTransform$
397
- // }).pipe(
398
- // takeUntil(destroy$),
399
- // // 轉換後會退訂前一個未完成的訂閱事件,因此可以取到「同時間」最後一次的訂閱事件
400
- // switchMap(async (d) => d),
401
- // ).subscribe(data => {
402
-
403
- // const transformData = Object.assign({}, data.gridAxesTransform)
404
-
405
- // const value = getAxesTransformValue({
406
- // translate: [0, 0],
407
- // scale: [transformData.scale[0] * -1, transformData.scale[1] * -1],
408
- // rotate: transformData.rotate * -1 + data.params.tickTextRotate,
409
- // rotateX: transformData.rotateX * -1,
410
- // rotateY: transformData.rotateY * -1
411
- // })
412
-
413
- // subscriber.next(value)
414
- // })
415
- // })
416
- // const reverseTransform$: Observable<TransformData> = gridAxesTransform$.pipe(
417
- // takeUntil(destroy$),
418
- // map(d => {
419
- // const translate: [number, number] = [d.translate[0] * -1, d.translate[1] * -1]
420
- // const scale: [number, number] = [d.scale[0] * -1, d.scale[1] * -1]
421
- // const rotate = d.rotate * -1
422
- // const rotateX = d.rotateX * -1
423
- // const rotateY = d.rotateY * -1
424
- // return {
425
- // translate,
426
- // scale,
427
- // rotate,
428
- // rotateX,
429
- // rotateY,
430
- // value: ''
431
- // }
432
- // }),
433
- // )
434
- const textReverseTransform$ = combineLatest({
435
- gridAxesReverseTransform: gridAxesReverseTransform$,
436
- gridContainerPosition: gridContainerPosition$
437
- }).pipe(
438
- takeUntil(destroy$),
439
- switchMap(async (d) => d),
440
- map(data => {
441
- // const axisReverseTranslateValue = `translate(${data.gridAxesReverseTransform.translate[0]}px, ${data.gridAxesReverseTransform.translate[1]}px)`
442
- const axesRotateXYReverseValue = `rotateX(${data.gridAxesReverseTransform.rotateX}deg) rotateY(${data.gridAxesReverseTransform.rotateY}deg)`
443
- const axesRotateReverseValue = `rotate(${data.gridAxesReverseTransform.rotate}deg)`
444
- const containerScaleReverseValue = `scale(${1 / data.gridContainerPosition[0].scale[0]}, ${1 / data.gridContainerPosition[0].scale[1]})`
445
- // 必須按照順序(先抵消外層rotate,再抵消最外層scale)
446
- return `${axesRotateXYReverseValue} ${axesRotateReverseValue} ${containerScaleReverseValue}`
447
- }),
448
- distinctUntilChanged()
449
- )
450
-
451
- const textReverseTransformWithRotate$ = combineLatest({
452
- textReverseTransform: textReverseTransform$,
453
- fullParams: fullParams$,
454
- }).pipe(
455
- takeUntil(destroy$),
456
- switchMap(async (d) => d),
457
- map(data => {
458
- // 必須按照順序(先抵消外層rotate,再抵消最外層scale,最後再做本身的rotate)
459
- return `${data.textReverseTransform} rotate(${data.fullParams.tickTextRotate}deg)`
460
- })
461
- )
462
-
463
- // 使用pointScale計算非連續性比例尺
464
- // const groupScale$: Observable<d3.ScalePoint<string>> = new Observable(subscriber => {
465
- // combineLatest({
466
- // fullDataFormatter: fullDataFormatter$,
467
- // gridAxesSize: gridAxesSize$,
468
- // computedData: computedData$
469
- // }).pipe(
470
- // takeUntil(destroy$),
471
- // switchMap(async (d) => d),
472
- // ).subscribe(data => {
473
- // const groupMin = 0
474
- // const groupMax = data.computedData[0] ? data.computedData[0].length - 1 : 0
475
- // const groupScaleDomainMin = data.fullDataFormatter.groupAxis.scaleDomain[0] === 'auto'
476
- // ? groupMin - data.fullDataFormatter.groupAxis.scalePadding
477
- // : data.fullDataFormatter.groupAxis.scaleDomain[0] as number - data.fullDataFormatter.groupAxis.scalePadding
478
- // const groupScaleDomainMax = data.fullDataFormatter.groupAxis.scaleDomain[1] === 'auto'
479
- // ? groupMax + data.fullDataFormatter.groupAxis.scalePadding
480
- // : data.fullDataFormatter.groupAxis.scaleDomain[1] as number + data.fullDataFormatter.groupAxis.scalePadding
481
-
482
- // const groupingLength = data.computedData[0]
483
- // ? data.computedData[0].length
484
- // : 0
485
-
486
- // let _labels = (data.computedData[0] ?? []).map(d => d.groupLabel)
487
-
488
- // const axisLabels = new Array(groupingLength).fill(0)
489
- // .map((d, i) => {
490
- // return _labels[i] != null
491
- // ? _labels[i]
492
- // : String(i) // 沒有label則用序列號填充
493
- // })
494
- // .filter((d, i) => {
495
- // return i >= groupScaleDomainMin && i <= groupScaleDomainMax
496
- // })
497
-
498
-
499
- // const padding = data.fullDataFormatter.groupAxis.scalePadding
500
-
501
- // const groupScale = createLabelToAxisScale({
502
- // axisLabels,
503
- // axisWidth: data.gridAxesSize.width,
504
- // padding
505
- // })
506
-
507
- // subscriber.next(groupScale)
508
- // })
509
- // })
510
-
511
- const groupScaleDomain$ = combineLatest({
512
- fullDataFormatter: fullDataFormatter$,
513
- gridAxesSize: gridAxesSize$,
514
- computedData: computedData$
515
- }).pipe(
516
- takeUntil(destroy$),
517
- switchMap(async (d) => d),
518
- map(data => {
519
- const groupMin = 0
520
- const groupMax = data.computedData[0] ? data.computedData[0].length - 1 : 0
521
- // const groupScaleDomainMin = data.fullDataFormatter.groupAxis.scaleDomain[0] === 'auto'
522
- // ? groupMin - data.fullDataFormatter.groupAxis.scalePadding
523
- // : data.fullDataFormatter.groupAxis.scaleDomain[0] as number - data.fullDataFormatter.groupAxis.scalePadding
524
- const groupScaleDomainMin = data.fullDataFormatter.groupAxis.scaleDomain[0] - data.fullDataFormatter.groupAxis.scalePadding
525
- const groupScaleDomainMax = data.fullDataFormatter.groupAxis.scaleDomain[1] === 'max'
526
- ? groupMax + data.fullDataFormatter.groupAxis.scalePadding
527
- : data.fullDataFormatter.groupAxis.scaleDomain[1] as number + data.fullDataFormatter.groupAxis.scalePadding
528
-
529
- return [groupScaleDomainMin, groupScaleDomainMax]
530
- }),
531
- shareReplay(1)
532
- )
533
-
534
- const groupScale$ = combineLatest({
535
- groupScaleDomain: groupScaleDomain$,
536
- gridAxesSize: gridAxesSize$
537
- }).pipe(
538
- takeUntil(destroy$),
539
- switchMap(async (d) => d),
540
- map(data => {
541
- const groupScale: d3.ScaleLinear<number, number> = d3.scaleLinear()
542
- .domain(data.groupScaleDomain)
543
- .range([0, data.gridAxesSize.width])
544
- return groupScale
545
- })
546
- )
547
-
548
- const groupLabels$ = computedData$.pipe(
549
- map(computedData => (computedData[0] ?? []).map(d => d.groupLabel))
550
- )
551
-
552
- const tickTextAlign$: Observable<TextAlign> = combineLatest({
553
- fullDataFormatter: fullDataFormatter$,
554
- fullParams: fullParams$
555
- }).pipe(
556
- takeUntil(destroy$),
557
- switchMap(async (d) => d),
558
- map(data => {
559
- let textAnchor: 'start' | 'middle' | 'end' = 'middle'
560
- let dominantBaseline: 'auto' | 'middle' | 'hanging' = 'hanging'
561
-
562
- if (data.fullDataFormatter.groupAxis.position === 'bottom') {
563
- textAnchor = data.fullParams.tickTextRotate
564
- ? 'end'
565
- : 'middle'
566
- dominantBaseline = 'hanging'
567
- } else if (data.fullDataFormatter.groupAxis.position === 'top') {
568
- textAnchor = data.fullParams.tickTextRotate
569
- ? 'start'
570
- : 'middle'
571
- dominantBaseline = 'auto'
572
- } else if (data.fullDataFormatter.groupAxis.position === 'left') {
573
- textAnchor = 'end'
574
- dominantBaseline = 'middle'
575
- } else if (data.fullDataFormatter.groupAxis.position === 'right') {
576
- textAnchor = 'start'
577
- dominantBaseline = 'middle'
578
- }
579
- return {
580
- textAnchor,
581
- dominantBaseline
582
- }
583
- })
584
- )
585
-
586
- const axisLabelAlign$: Observable<TextAlign> = fullDataFormatter$.pipe(
587
- takeUntil(destroy$),
588
- map(d => {
589
- let textAnchor: 'start' | 'middle' | 'end' = 'start'
590
- let dominantBaseline: 'auto' | 'middle' | 'hanging' = 'hanging'
591
-
592
- if (d.groupAxis.position === 'bottom') {
593
- dominantBaseline = 'hanging'
594
- } else if (d.groupAxis.position === 'top') {
595
- dominantBaseline = 'auto'
596
- } else if (d.groupAxis.position === 'left') {
597
- textAnchor = 'end'
598
- } else if (d.groupAxis.position === 'right') {
599
- textAnchor = 'start'
600
- }
601
- if (d.valueAxis.position === 'left') {
602
- textAnchor = 'start'
603
- } else if (d.valueAxis.position === 'right') {
604
- textAnchor = 'end'
605
- } else if (d.valueAxis.position === 'bottom') {
606
- dominantBaseline = 'auto'
607
- } else if (d.valueAxis.position === 'top') {
608
- dominantBaseline = 'hanging'
609
- }
610
- return {
611
- textAnchor,
612
- dominantBaseline
613
- }
614
- })
615
- )
616
-
617
- const groupLabelData$ = combineLatest({
618
- groupLabels: groupLabels$,
619
- fullParams: fullParams$
620
- }).pipe(
621
- takeUntil(destroy$),
622
- switchMap(async (d) => d),
623
- map(data => {
624
- return createGroupLabelData(data.groupLabels, data.fullParams.tickFormat)
625
- })
626
- )
627
-
628
- combineLatest({
629
- axisSelection: axisSelection$,
630
- fullParams: fullParams$,
631
- tickTextAlign: tickTextAlign$,
632
- axisLabelAlign: axisLabelAlign$,
633
- gridAxesSize: gridAxesSize$,
634
- fullDataFormatter: fullDataFormatter$,
635
- chartParams: fullChartParams$,
636
- groupScale: groupScale$,
637
- groupScaleDomain: groupScaleDomain$,
638
- // groupLabels: groupLabels$,
639
- groupLabelData: groupLabelData$,
640
- textReverseTransform: textReverseTransform$,
641
- textReverseTransformWithRotate: textReverseTransformWithRotate$,
642
- textSizePx: textSizePx$
643
- // tickTextFormatter: tickTextFormatter$
644
- }).pipe(
645
- takeUntil(destroy$),
646
- switchMap(async (d) => d),
647
- ).subscribe(data => {
648
-
649
- renderAxis({
650
- selection: data.axisSelection,
651
- xAxisClassName,
652
- fullParams: data.fullParams,
653
- tickTextAlign: data.tickTextAlign,
654
- gridAxesSize: data.gridAxesSize,
655
- fullDataFormatter: data.fullDataFormatter,
656
- chartParams: data.chartParams,
657
- groupScale: data.groupScale,
658
- groupScaleDomain: data.groupScaleDomain,
659
- // groupLabels: data.groupLabels,
660
- groupLabelData: data.groupLabelData,
661
- textReverseTransformWithRotate: data.textReverseTransformWithRotate,
662
- textSizePx: data.textSizePx
663
- })
664
-
665
- renderAxisLabel({
666
- selection: data.axisSelection,
667
- groupingLabelClassName,
668
- fullParams: data.fullParams,
669
- axisLabelAlign: data.axisLabelAlign,
670
- gridAxesSize: data.gridAxesSize,
671
- fullDataFormatter: data.fullDataFormatter,
672
- chartParams: data.chartParams,
673
- textReverseTransform: data.textReverseTransform,
674
- })
675
- })
676
-
677
- return () => {
678
- destroy$.next(undefined)
679
- }
1
+ import * as d3 from 'd3'
2
+ import {
3
+ combineLatest,
4
+ switchMap,
5
+ distinctUntilChanged,
6
+ of,
7
+ first,
8
+ map,
9
+ takeUntil,
10
+ shareReplay,
11
+ Observable,
12
+ Subject } from 'rxjs'
13
+ import type {
14
+ ColorType,
15
+ ComputedDataGrid,
16
+ ContainerPositionScaled,
17
+ ComputedDatumGrid,
18
+ DataFormatterGrid,
19
+ ChartParams,
20
+ TransformData
21
+ } from '../../lib/core-types'
22
+ import type { BaseGroupAxisParams } from '../../lib/plugins-basic-types'
23
+ import type { BasePluginFn } from './types'
24
+ import { parseTickFormatValue } from '../utils/d3Utils'
25
+ import { getColor, getClassName } from '../utils/orbchartsUtils'
26
+ import { renderTspansOnAxis } from '../utils/d3Graphics'
27
+
28
+ // export interface BaseGroupAxisParams {
29
+ // // xLabel: string
30
+ // // labelAnchor: 'start' | 'end'
31
+ // labelOffset: [number, number]
32
+ // labelColorType: ColorType
33
+ // axisLineVisible: boolean
34
+ // axisLineColorType: ColorType
35
+ // ticks: number | null | 'all'
36
+ // tickFormat: string | ((text: any) => string)
37
+ // tickLineVisible: boolean
38
+ // tickPadding: number
39
+ // tickFullLine: boolean
40
+ // tickFullLineDasharray: string
41
+ // tickColorType: ColorType
42
+ // // axisLineColor: string
43
+ // // axisLabelColor: string
44
+ // tickTextRotate: number
45
+ // tickTextColorType: ColorType
46
+ // }
47
+
48
+ interface BaseGroupAxisContext {
49
+ selection: d3.Selection<any, unknown, any, unknown>
50
+ computedData$: Observable<ComputedDataGrid>
51
+ fullParams$: Observable<BaseGroupAxisParams>
52
+ fullDataFormatter$: Observable<DataFormatterGrid>
53
+ fullChartParams$: Observable<ChartParams>
54
+ gridAxesTransform$: Observable<TransformData>
55
+ gridAxesReverseTransform$: Observable<TransformData>
56
+ gridAxesSize$: Observable<{
57
+ width: number;
58
+ height: number;
59
+ }>
60
+ gridContainerPosition$: Observable<ContainerPositionScaled[]>
61
+ isSeriesSeprate$: Observable<boolean>
62
+ textSizePx$: Observable<number>
63
+ }
64
+
65
+ interface TextAlign {
66
+ textAnchor: "start" | "middle" | "end"
67
+ dominantBaseline: "middle" | "auto" | "hanging"
68
+ }
69
+
70
+ interface GroupLabelData {
71
+ text: string
72
+ textArr: string[]
73
+ }
74
+
75
+ // const pluginName = 'GroupAxis'
76
+ // const containerClassName = getClassName(pluginName, 'container')
77
+ // const xAxisGClassName = getClassName(pluginName, 'xAxisG')
78
+ // const xAxisClassName = getClassName(pluginName, 'xAxis')
79
+ // const groupingLabelClassName = getClassName(pluginName, 'groupingLabel')
80
+ const defaultTickSize = 6
81
+
82
+ function createGroupLabelData (groupLabels: string[], tickFormat: string | ((text: any) => string | d3.NumberValue)): GroupLabelData[] {
83
+ return groupLabels.map((_text, i) => {
84
+ const text = parseTickFormatValue(_text, tickFormat)
85
+ const textArr = typeof text === 'string' ? text.split('\n') : [text]
86
+
87
+ return {
88
+ text,
89
+ textArr
90
+ }
91
+ })
92
+ }
93
+
94
+ function renderAxisLabel ({ selection, groupingLabelClassName, fullParams, axisLabelAlign, gridAxesSize, fullDataFormatter, chartParams, textReverseTransform }: {
95
+ selection: d3.Selection<SVGGElement, any, any, any>,
96
+ groupingLabelClassName: string
97
+ fullParams: BaseGroupAxisParams
98
+ axisLabelAlign: TextAlign
99
+ gridAxesSize: { width: number, height: number }
100
+ fullDataFormatter: DataFormatterGrid,
101
+ chartParams: ChartParams
102
+ textReverseTransform: string
103
+ }) {
104
+
105
+ const offsetX = fullParams.tickPadding + fullParams.labelOffset[0]
106
+ const offsetY = fullParams.tickPadding + fullParams.labelOffset[1]
107
+ let labelX = 0
108
+ let labelY = 0
109
+ if (fullDataFormatter.groupAxis.position === 'bottom') {
110
+ labelY = offsetY
111
+ if (fullDataFormatter.valueAxis.position === 'left') {
112
+ labelX = offsetX
113
+ } else if (fullDataFormatter.valueAxis.position === 'right') {
114
+ labelX = - offsetX
115
+ }
116
+ } else if (fullDataFormatter.groupAxis.position === 'top') {
117
+ labelY = - offsetY
118
+ if (fullDataFormatter.valueAxis.position === 'left') {
119
+ labelX = offsetX
120
+ } else if (fullDataFormatter.valueAxis.position === 'right') {
121
+ labelX = - offsetX
122
+ }
123
+ } else if (fullDataFormatter.groupAxis.position === 'left') {
124
+ labelX = - offsetX
125
+ if (fullDataFormatter.valueAxis.position === 'bottom') {
126
+ labelY = - offsetY
127
+ } else if (fullDataFormatter.valueAxis.position === 'top') {
128
+ labelY = offsetY
129
+ }
130
+ } else if (fullDataFormatter.groupAxis.position === 'right') {
131
+ labelX = offsetX
132
+ if (fullDataFormatter.valueAxis.position === 'bottom') {
133
+ labelY = - offsetY
134
+ } else if (fullDataFormatter.valueAxis.position === 'top') {
135
+ labelY = offsetY
136
+ }
137
+ }
138
+
139
+ const axisLabelSelection = selection
140
+ .selectAll<SVGGElement, BaseGroupAxisParams>(`g.${groupingLabelClassName}`)
141
+ .data([fullParams])
142
+ .join('g')
143
+ .classed(groupingLabelClassName, true)
144
+ .each((d, i, g) => {
145
+ const text = d3.select(g[i])
146
+ .selectAll<SVGTextElement, BaseGroupAxisParams>('text')
147
+ .data([d])
148
+ .join(
149
+ enter => {
150
+ return enter
151
+ .append('text')
152
+ .style('font-weight', 'bold')
153
+ },
154
+ update => update,
155
+ exit => exit.remove()
156
+ )
157
+ .attr('text-anchor', axisLabelAlign.textAnchor)
158
+ .attr('dominant-baseline', axisLabelAlign.dominantBaseline)
159
+ .attr('font-size', chartParams.styles.textSize)
160
+ .style('fill', getColor(fullParams.labelColorType, chartParams))
161
+ .style('transform', textReverseTransform)
162
+ // 偏移使用 x, y 而非 transform 才不會受到外層 scale 變形影響
163
+ .attr('x', labelX)
164
+ .attr('y', labelY)
165
+ .text(d => fullDataFormatter.groupAxis.label)
166
+ })
167
+ .attr('transform', d => `translate(${gridAxesSize.width}, 0)`)
168
+ // .attr('transform', d => `translate(${gridAxesSize.width + d.tickPadding + fullParams.labelOffset[0]}, ${- d.tickPadding - fullParams.labelOffset[1]})`)
169
+
170
+ }
171
+
172
+ function renderAxis ({ selection, xAxisClassName, fullParams, tickTextAlign, gridAxesSize, fullDataFormatter, chartParams, groupScale, groupScaleDomain, groupLabelData, textReverseTransformWithRotate, textSizePx }: {
173
+ selection: d3.Selection<SVGGElement, any, any, any>,
174
+ xAxisClassName: string
175
+ fullParams: BaseGroupAxisParams
176
+ tickTextAlign: TextAlign
177
+ gridAxesSize: { width: number, height: number }
178
+ fullDataFormatter: DataFormatterGrid,
179
+ chartParams: ChartParams
180
+ groupScale: d3.ScaleLinear<number, number>
181
+ groupScaleDomain: number[]
182
+ // groupLabels: string[]
183
+ groupLabelData: GroupLabelData[]
184
+ textReverseTransformWithRotate: string
185
+ textSizePx: number
186
+ }) {
187
+
188
+ const xAxisSelection = selection
189
+ .selectAll<SVGGElement, BaseGroupAxisParams>(`g.${xAxisClassName}`)
190
+ .data([fullParams])
191
+ .join('g')
192
+ .classed(xAxisClassName, true)
193
+
194
+ // 計算所有範圍內groupLabels數量(顯示所有刻度)
195
+ const allTicksAmount = Math.floor(groupScaleDomain[1]) - Math.ceil(groupScaleDomain[0]) + 1
196
+
197
+ // 刻度文字偏移
198
+ let tickPadding = 0
199
+ let textX = 0
200
+ if (fullDataFormatter.groupAxis.position === 'left') {
201
+ tickPadding = 0
202
+ textX = - fullParams.tickPadding
203
+ } else if (fullDataFormatter.groupAxis.position === 'right') {
204
+ tickPadding = 0
205
+ textX = fullParams.tickPadding
206
+ } else if (fullDataFormatter.groupAxis.position === 'bottom') {
207
+ if (fullParams.tickFullLine == true) {
208
+ tickPadding = - fullParams.tickPadding
209
+ } else {
210
+ tickPadding = - fullParams.tickPadding - defaultTickSize
211
+ }
212
+ textX = 0
213
+ } else if (fullDataFormatter.groupAxis.position === 'top') {
214
+ if (fullParams.tickFullLine == true) {
215
+ tickPadding = fullParams.tickPadding
216
+ } else {
217
+ tickPadding = fullParams.tickPadding - defaultTickSize
218
+ }
219
+ textX = - 0
220
+ }
221
+
222
+ // 設定X軸刻度
223
+ const xAxis = d3.axisTop(groupScale)
224
+ .scale(groupScale)
225
+ .ticks(fullParams.ticks === 'all'
226
+ ? allTicksAmount
227
+ : fullParams.ticks > allTicksAmount
228
+ ? allTicksAmount // 不顯示超過groupLabels數量的刻度
229
+ : fullParams.ticks)
230
+ .tickSize(fullParams.tickFullLine == true
231
+ ? - gridAxesSize.height
232
+ : defaultTickSize)
233
+ .tickSizeOuter(0)
234
+ .tickFormat((groupIndex: number) => {
235
+ // 用index對應到groupLabel
236
+ // const groupLabel = groupLabels[groupIndex] ?? '' // 非整數index不顯示
237
+ // return parseTickFormatValue(groupLabel, fullParams.tickFormat)
238
+ return groupLabelData[groupIndex]?.text ?? ''
239
+ })
240
+ .tickPadding(tickPadding)
241
+
242
+ const xAxisEl = xAxisSelection
243
+ .transition()
244
+ .duration(100)
245
+ .ease(d3.easeLinear) // 線性的 - 當托曳或快速變動的時候比較滑順
246
+ .call(xAxis)
247
+
248
+ .on('end', (self, t) => {
249
+ // 先等transition結束再處理文字,否則會被原本的文字覆蓋
250
+ xAxisSelection
251
+ .selectAll('.tick text')
252
+ .each((groupIndex: number, i, n) => {
253
+ // const groupLabel = groupLabels[groupIndex] ?? '' // 非整數index不顯示
254
+ // const groupLabelText = parseTickFormatValue(groupLabel, fullParams.tickFormat)
255
+ const textArr = groupLabelData[groupIndex]?.textArr ?? []
256
+
257
+ // 將原本單行文字改為多行文字
258
+ renderTspansOnAxis(d3.select(n[i]), {
259
+ textArr,
260
+ textSizePx,
261
+ groupAxisPosition: fullDataFormatter.groupAxis.position,
262
+ isContainerRotated: true
263
+ })
264
+ })
265
+ })
266
+
267
+ xAxisEl.selectAll('line')
268
+ .style('fill', 'none')
269
+ .style('stroke', fullParams.tickLineVisible == true ? getColor(fullParams.tickColorType, chartParams) : 'none')
270
+ .style('stroke-dasharray', fullParams.tickFullLineDasharray)
271
+ .style('vector-effect', 'non-scaling-stroke') // 避免 scale 導致線條變形
272
+ .attr('pointer-events', 'none')
273
+
274
+ xAxisEl.selectAll('path')
275
+ .style('fill', 'none')
276
+ .style('stroke', fullParams.axisLineVisible == true ? getColor(fullParams.axisLineColorType, chartParams) : 'none')
277
+ .style('shape-rendering', 'crispEdges')
278
+
279
+ const xText = xAxisSelection.selectAll<SVGTextElement, BaseGroupAxisParams>('text')
280
+ // .style('font-family', 'sans-serif')
281
+ .attr('font-size', chartParams.styles.textSize)
282
+ // .style('font-weight', 'bold')
283
+ .attr('fill', getColor(fullParams.tickTextColorType, chartParams))
284
+ .attr('text-anchor', tickTextAlign.textAnchor)
285
+ .attr('dominant-baseline', tickTextAlign.dominantBaseline)
286
+ .attr('x', textX)
287
+ .style('transform', textReverseTransformWithRotate)
288
+
289
+ // 抵消掉預設的偏移
290
+ // if (fullDataFormatter.groupAxis.position === 'left' || fullDataFormatter.groupAxis.position === 'right') {
291
+ xText.attr('dy', 0)
292
+ // }
293
+
294
+ return xAxisSelection
295
+ }
296
+
297
+
298
+ export const createBaseGroupAxis: BasePluginFn<BaseGroupAxisContext> = ((pluginName: string, {
299
+ selection,
300
+ computedData$,
301
+ fullParams$,
302
+ fullDataFormatter$,
303
+ fullChartParams$,
304
+ gridAxesTransform$,
305
+ gridAxesReverseTransform$,
306
+ gridAxesSize$,
307
+ gridContainerPosition$,
308
+ isSeriesSeprate$,
309
+ textSizePx$,
310
+ }) => {
311
+
312
+ const destroy$ = new Subject()
313
+
314
+ const containerClassName = getClassName(pluginName, 'container')
315
+ const xAxisGClassName = getClassName(pluginName, 'xAxisG')
316
+ const xAxisClassName = getClassName(pluginName, 'xAxis')
317
+ const groupingLabelClassName = getClassName(pluginName, 'groupingLabel')
318
+
319
+ const containerSelection$ = combineLatest({
320
+ computedData: computedData$.pipe(
321
+ distinctUntilChanged((a, b) => {
322
+ // 只有當series的數量改變時,才重新計算
323
+ return a.length === b.length
324
+ }),
325
+ ),
326
+ isSeriesSeprate: isSeriesSeprate$
327
+ }).pipe(
328
+ takeUntil(destroy$),
329
+ switchMap(async (d) => d),
330
+ map(data => {
331
+ return data.isSeriesSeprate
332
+ // series分開的時候顯示各別axis
333
+ ? data.computedData
334
+ // series合併的時候只顯示第一個axis
335
+ : [data.computedData[0]]
336
+ }),
337
+ map((computedData, i) => {
338
+ return selection
339
+ .selectAll<SVGGElement, ComputedDatumGrid[]>(`g.${containerClassName}`)
340
+ .data(computedData, d => d[0] ? d[0].seriesIndex : i)
341
+ .join('g')
342
+ .classed(containerClassName, true)
343
+ })
344
+ )
345
+
346
+ const axisSelection$ = containerSelection$.pipe(
347
+ takeUntil(destroy$),
348
+ map((containerSelection, i) => {
349
+ return containerSelection
350
+ .selectAll<SVGGElement, ComputedDatumGrid[]>(`g.${xAxisGClassName}`)
351
+ .data([xAxisGClassName])
352
+ .join('g')
353
+ .classed(xAxisGClassName, true)
354
+ })
355
+ )
356
+
357
+ combineLatest({
358
+ containerSelection: containerSelection$,
359
+ gridContainerPosition: gridContainerPosition$
360
+ }).pipe(
361
+ takeUntil(destroy$),
362
+ switchMap(async d => d)
363
+ ).subscribe(data => {
364
+ data.containerSelection
365
+ .attr('transform', (d, i) => {
366
+ const gridContainerPosition = data.gridContainerPosition[i] ?? data.gridContainerPosition[0]
367
+ const translate = gridContainerPosition.translate
368
+ const scale = gridContainerPosition.scale
369
+ return `translate(${translate[0]}, ${translate[1]}) scale(${scale[0]}, ${scale[1]})`
370
+ })
371
+ // .attr('opacity', 0)
372
+ // .transition()
373
+ // .attr('opacity', 1)
374
+ })
375
+
376
+ combineLatest({
377
+ axisSelection: axisSelection$,
378
+ gridAxesTransform: gridAxesTransform$,
379
+ }).pipe(
380
+ takeUntil(destroy$),
381
+ switchMap(async d => d)
382
+ ).subscribe(data => {
383
+ data.axisSelection
384
+ .style('transform', data.gridAxesTransform.value)
385
+ // .attr('opacity', 0)
386
+ // .transition()
387
+ // .attr('opacity', 1)
388
+
389
+ })
390
+
391
+
392
+ // const gridAxesSize$ = gridAxisSizeObservable({
393
+ // fullDataFormatter$,
394
+ // layout$
395
+ // })
396
+
397
+
398
+ // const tickTextFormatter$ = fullDataFormatter$
399
+ // .pipe(
400
+ // map(d => {
401
+ // return d.seriesDirection === 'row' ? d.columnLabelFormat : d.rowLabelFormat
402
+ // })
403
+ // )
404
+
405
+ // const textReverseTransform$: Observable<string> = new Observable(subscriber => {
406
+ // combineLatest({
407
+ // params: fullParams$,
408
+ // gridAxesTransform: gridAxesTransform$
409
+ // }).pipe(
410
+ // takeUntil(destroy$),
411
+ // // 轉換後會退訂前一個未完成的訂閱事件,因此可以取到「同時間」最後一次的訂閱事件
412
+ // switchMap(async (d) => d),
413
+ // ).subscribe(data => {
414
+
415
+ // const transformData = Object.assign({}, data.gridAxesTransform)
416
+
417
+ // const value = getAxesTransformValue({
418
+ // translate: [0, 0],
419
+ // scale: [transformData.scale[0] * -1, transformData.scale[1] * -1],
420
+ // rotate: transformData.rotate * -1 + data.params.tickTextRotate,
421
+ // rotateX: transformData.rotateX * -1,
422
+ // rotateY: transformData.rotateY * -1
423
+ // })
424
+
425
+ // subscriber.next(value)
426
+ // })
427
+ // })
428
+ // const reverseTransform$: Observable<TransformData> = gridAxesTransform$.pipe(
429
+ // takeUntil(destroy$),
430
+ // map(d => {
431
+ // const translate: [number, number] = [d.translate[0] * -1, d.translate[1] * -1]
432
+ // const scale: [number, number] = [d.scale[0] * -1, d.scale[1] * -1]
433
+ // const rotate = d.rotate * -1
434
+ // const rotateX = d.rotateX * -1
435
+ // const rotateY = d.rotateY * -1
436
+ // return {
437
+ // translate,
438
+ // scale,
439
+ // rotate,
440
+ // rotateX,
441
+ // rotateY,
442
+ // value: ''
443
+ // }
444
+ // }),
445
+ // )
446
+ const textReverseTransform$ = combineLatest({
447
+ gridAxesReverseTransform: gridAxesReverseTransform$,
448
+ gridContainerPosition: gridContainerPosition$
449
+ }).pipe(
450
+ takeUntil(destroy$),
451
+ switchMap(async (d) => d),
452
+ map(data => {
453
+ // const axisReverseTranslateValue = `translate(${data.gridAxesReverseTransform.translate[0]}px, ${data.gridAxesReverseTransform.translate[1]}px)`
454
+ const axesRotateXYReverseValue = `rotateX(${data.gridAxesReverseTransform.rotateX}deg) rotateY(${data.gridAxesReverseTransform.rotateY}deg)`
455
+ const axesRotateReverseValue = `rotate(${data.gridAxesReverseTransform.rotate}deg)`
456
+ const containerScaleReverseValue = `scale(${1 / data.gridContainerPosition[0].scale[0]}, ${1 / data.gridContainerPosition[0].scale[1]})`
457
+ // 必須按照順序(先抵消外層rotate,再抵消最外層scale)
458
+ return `${axesRotateXYReverseValue} ${axesRotateReverseValue} ${containerScaleReverseValue}`
459
+ }),
460
+ distinctUntilChanged()
461
+ )
462
+
463
+ const textReverseTransformWithRotate$ = combineLatest({
464
+ textReverseTransform: textReverseTransform$,
465
+ fullParams: fullParams$,
466
+ }).pipe(
467
+ takeUntil(destroy$),
468
+ switchMap(async (d) => d),
469
+ map(data => {
470
+ // 必須按照順序(先抵消外層rotate,再抵消最外層scale,最後再做本身的rotate)
471
+ return `${data.textReverseTransform} rotate(${data.fullParams.tickTextRotate}deg)`
472
+ })
473
+ )
474
+
475
+ // 使用pointScale計算非連續性比例尺
476
+ // const groupScale$: Observable<d3.ScalePoint<string>> = new Observable(subscriber => {
477
+ // combineLatest({
478
+ // fullDataFormatter: fullDataFormatter$,
479
+ // gridAxesSize: gridAxesSize$,
480
+ // computedData: computedData$
481
+ // }).pipe(
482
+ // takeUntil(destroy$),
483
+ // switchMap(async (d) => d),
484
+ // ).subscribe(data => {
485
+ // const groupMin = 0
486
+ // const groupMax = data.computedData[0] ? data.computedData[0].length - 1 : 0
487
+ // const groupScaleDomainMin = data.fullDataFormatter.groupAxis.scaleDomain[0] === 'auto'
488
+ // ? groupMin - data.fullDataFormatter.groupAxis.scalePadding
489
+ // : data.fullDataFormatter.groupAxis.scaleDomain[0] as number - data.fullDataFormatter.groupAxis.scalePadding
490
+ // const groupScaleDomainMax = data.fullDataFormatter.groupAxis.scaleDomain[1] === 'auto'
491
+ // ? groupMax + data.fullDataFormatter.groupAxis.scalePadding
492
+ // : data.fullDataFormatter.groupAxis.scaleDomain[1] as number + data.fullDataFormatter.groupAxis.scalePadding
493
+
494
+ // const groupingLength = data.computedData[0]
495
+ // ? data.computedData[0].length
496
+ // : 0
497
+
498
+ // let _labels = (data.computedData[0] ?? []).map(d => d.groupLabel)
499
+
500
+ // const axisLabels = new Array(groupingLength).fill(0)
501
+ // .map((d, i) => {
502
+ // return _labels[i] != null
503
+ // ? _labels[i]
504
+ // : String(i) // 沒有label則用序列號填充
505
+ // })
506
+ // .filter((d, i) => {
507
+ // return i >= groupScaleDomainMin && i <= groupScaleDomainMax
508
+ // })
509
+
510
+
511
+ // const padding = data.fullDataFormatter.groupAxis.scalePadding
512
+
513
+ // const groupScale = createLabelToAxisScale({
514
+ // axisLabels,
515
+ // axisWidth: data.gridAxesSize.width,
516
+ // padding
517
+ // })
518
+
519
+ // subscriber.next(groupScale)
520
+ // })
521
+ // })
522
+
523
+ const groupScaleDomain$ = combineLatest({
524
+ fullDataFormatter: fullDataFormatter$,
525
+ gridAxesSize: gridAxesSize$,
526
+ computedData: computedData$
527
+ }).pipe(
528
+ takeUntil(destroy$),
529
+ switchMap(async (d) => d),
530
+ map(data => {
531
+ const groupMin = 0
532
+ const groupMax = data.computedData[0] ? data.computedData[0].length - 1 : 0
533
+ // const groupScaleDomainMin = data.fullDataFormatter.groupAxis.scaleDomain[0] === 'auto'
534
+ // ? groupMin - data.fullDataFormatter.groupAxis.scalePadding
535
+ // : data.fullDataFormatter.groupAxis.scaleDomain[0] as number - data.fullDataFormatter.groupAxis.scalePadding
536
+ const groupScaleDomainMin = data.fullDataFormatter.groupAxis.scaleDomain[0] - data.fullDataFormatter.groupAxis.scalePadding
537
+ const groupScaleDomainMax = data.fullDataFormatter.groupAxis.scaleDomain[1] === 'max'
538
+ ? groupMax + data.fullDataFormatter.groupAxis.scalePadding
539
+ : data.fullDataFormatter.groupAxis.scaleDomain[1] as number + data.fullDataFormatter.groupAxis.scalePadding
540
+
541
+ return [groupScaleDomainMin, groupScaleDomainMax]
542
+ }),
543
+ shareReplay(1)
544
+ )
545
+
546
+ const groupScale$ = combineLatest({
547
+ groupScaleDomain: groupScaleDomain$,
548
+ gridAxesSize: gridAxesSize$
549
+ }).pipe(
550
+ takeUntil(destroy$),
551
+ switchMap(async (d) => d),
552
+ map(data => {
553
+ const groupScale: d3.ScaleLinear<number, number> = d3.scaleLinear()
554
+ .domain(data.groupScaleDomain)
555
+ .range([0, data.gridAxesSize.width])
556
+ return groupScale
557
+ })
558
+ )
559
+
560
+ const groupLabels$ = computedData$.pipe(
561
+ map(computedData => (computedData[0] ?? []).map(d => d.groupLabel))
562
+ )
563
+
564
+ const tickTextAlign$: Observable<TextAlign> = combineLatest({
565
+ fullDataFormatter: fullDataFormatter$,
566
+ fullParams: fullParams$
567
+ }).pipe(
568
+ takeUntil(destroy$),
569
+ switchMap(async (d) => d),
570
+ map(data => {
571
+ let textAnchor: 'start' | 'middle' | 'end' = 'middle'
572
+ let dominantBaseline: 'auto' | 'middle' | 'hanging' = 'hanging'
573
+
574
+ if (data.fullDataFormatter.groupAxis.position === 'bottom') {
575
+ textAnchor = data.fullParams.tickTextRotate
576
+ ? 'end'
577
+ : 'middle'
578
+ dominantBaseline = 'hanging'
579
+ } else if (data.fullDataFormatter.groupAxis.position === 'top') {
580
+ textAnchor = data.fullParams.tickTextRotate
581
+ ? 'start'
582
+ : 'middle'
583
+ dominantBaseline = 'auto'
584
+ } else if (data.fullDataFormatter.groupAxis.position === 'left') {
585
+ textAnchor = 'end'
586
+ dominantBaseline = 'middle'
587
+ } else if (data.fullDataFormatter.groupAxis.position === 'right') {
588
+ textAnchor = 'start'
589
+ dominantBaseline = 'middle'
590
+ }
591
+ return {
592
+ textAnchor,
593
+ dominantBaseline
594
+ }
595
+ })
596
+ )
597
+
598
+ const axisLabelAlign$: Observable<TextAlign> = fullDataFormatter$.pipe(
599
+ takeUntil(destroy$),
600
+ map(d => {
601
+ let textAnchor: 'start' | 'middle' | 'end' = 'start'
602
+ let dominantBaseline: 'auto' | 'middle' | 'hanging' = 'hanging'
603
+
604
+ if (d.groupAxis.position === 'bottom') {
605
+ dominantBaseline = 'hanging'
606
+ } else if (d.groupAxis.position === 'top') {
607
+ dominantBaseline = 'auto'
608
+ } else if (d.groupAxis.position === 'left') {
609
+ textAnchor = 'end'
610
+ } else if (d.groupAxis.position === 'right') {
611
+ textAnchor = 'start'
612
+ }
613
+ if (d.valueAxis.position === 'left') {
614
+ textAnchor = 'start'
615
+ } else if (d.valueAxis.position === 'right') {
616
+ textAnchor = 'end'
617
+ } else if (d.valueAxis.position === 'bottom') {
618
+ dominantBaseline = 'auto'
619
+ } else if (d.valueAxis.position === 'top') {
620
+ dominantBaseline = 'hanging'
621
+ }
622
+ return {
623
+ textAnchor,
624
+ dominantBaseline
625
+ }
626
+ })
627
+ )
628
+
629
+ const groupLabelData$ = combineLatest({
630
+ groupLabels: groupLabels$,
631
+ fullParams: fullParams$
632
+ }).pipe(
633
+ takeUntil(destroy$),
634
+ switchMap(async (d) => d),
635
+ map(data => {
636
+ return createGroupLabelData(data.groupLabels, data.fullParams.tickFormat)
637
+ })
638
+ )
639
+
640
+ combineLatest({
641
+ axisSelection: axisSelection$,
642
+ fullParams: fullParams$,
643
+ tickTextAlign: tickTextAlign$,
644
+ axisLabelAlign: axisLabelAlign$,
645
+ gridAxesSize: gridAxesSize$,
646
+ fullDataFormatter: fullDataFormatter$,
647
+ chartParams: fullChartParams$,
648
+ groupScale: groupScale$,
649
+ groupScaleDomain: groupScaleDomain$,
650
+ // groupLabels: groupLabels$,
651
+ groupLabelData: groupLabelData$,
652
+ textReverseTransform: textReverseTransform$,
653
+ textReverseTransformWithRotate: textReverseTransformWithRotate$,
654
+ textSizePx: textSizePx$
655
+ // tickTextFormatter: tickTextFormatter$
656
+ }).pipe(
657
+ takeUntil(destroy$),
658
+ switchMap(async (d) => d),
659
+ ).subscribe(data => {
660
+
661
+ renderAxis({
662
+ selection: data.axisSelection,
663
+ xAxisClassName,
664
+ fullParams: data.fullParams,
665
+ tickTextAlign: data.tickTextAlign,
666
+ gridAxesSize: data.gridAxesSize,
667
+ fullDataFormatter: data.fullDataFormatter,
668
+ chartParams: data.chartParams,
669
+ groupScale: data.groupScale,
670
+ groupScaleDomain: data.groupScaleDomain,
671
+ // groupLabels: data.groupLabels,
672
+ groupLabelData: data.groupLabelData,
673
+ textReverseTransformWithRotate: data.textReverseTransformWithRotate,
674
+ textSizePx: data.textSizePx
675
+ })
676
+
677
+ renderAxisLabel({
678
+ selection: data.axisSelection,
679
+ groupingLabelClassName,
680
+ fullParams: data.fullParams,
681
+ axisLabelAlign: data.axisLabelAlign,
682
+ gridAxesSize: data.gridAxesSize,
683
+ fullDataFormatter: data.fullDataFormatter,
684
+ chartParams: data.chartParams,
685
+ textReverseTransform: data.textReverseTransform,
686
+ })
687
+ })
688
+
689
+ return () => {
690
+ destroy$.next(undefined)
691
+ }
680
692
  })