@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,583 +1,600 @@
1
- import * as d3 from 'd3'
2
- import {
3
- combineLatest,
4
- switchMap,
5
- distinctUntilChanged,
6
- first,
7
- map,
8
- takeUntil,
9
- Observable,
10
- Subject } from 'rxjs'
11
- import { createValueToAxisScale } from '../../lib/core'
12
- import type { BasePluginFn } from './types'
13
- import type {
14
- ComputedDataGrid,
15
- DataFormatterGrid,
16
- ChartParams,
17
- ComputedDatumGrid,
18
- ContainerPositionScaled,
19
- TransformData,
20
- EventGrid,
21
- ColorType
22
- } from '../../lib/core-types'
23
- import type { BaseValueAxisParams } from '../../lib/plugins-basic-types'
24
- import { parseTickFormatValue } from '../utils/d3Utils'
25
- import { getColor, getMinMaxValue, getClassName, getUniID } from '../utils/orbchartsUtils'
26
-
27
- // export interface BaseValueAxisParams {
28
- // labelOffset: [number, number]
29
- // labelColorType: ColorType
30
- // axisLineVisible: boolean
31
- // axisLineColorType: ColorType
32
- // ticks: number
33
- // tickFormat: string | ((text: d3.NumberValue) => string)
34
- // tickLineVisible: boolean
35
- // tickPadding: number
36
- // tickFullLine: boolean
37
- // tickFullLineDasharray: string
38
- // tickColorType: ColorType
39
- // tickTextRotate: number
40
- // tickTextColorType: ColorType
41
- // }
42
-
43
- interface BaseLinesContext {
44
- selection: d3.Selection<any, unknown, any, unknown>
45
- computedData$: Observable<ComputedDataGrid>
46
- filteredMinMaxValue$: Observable<[number, number]>
47
- fullParams$: Observable<BaseValueAxisParams>
48
- fullDataFormatter$: Observable<DataFormatterGrid>
49
- fullChartParams$: Observable<ChartParams>
50
- gridAxesTransform$: Observable<TransformData>
51
- gridAxesReverseTransform$: Observable<TransformData>
52
- gridAxesSize$: Observable<{
53
- width: number;
54
- height: number;
55
- }>
56
- gridContainerPosition$: Observable<ContainerPositionScaled[]>
57
- isSeriesSeprate$: Observable<boolean>
58
- }
59
-
60
- interface TextAlign {
61
- textAnchor: "start" | "middle" | "end"
62
- dominantBaseline: "middle" | "auto" | "hanging"
63
- }
64
-
65
- // const pluginName = 'ValueAxis'
66
- // const containerClassName = getClassName(pluginName, 'container')
67
- // const yAxisGClassName = getClassName(pluginName, 'yAxisG')
68
- // const yAxisClassName = getClassName(pluginName, 'yAxis')
69
- // const textClassName = getClassName(pluginName, 'text')
70
- const defaultTickSize = 6
71
-
72
- function renderAxisLabel ({ selection, textClassName, fullParams, axisLabelAlign, gridAxesSize, fullDataFormatter, fullChartParams, textReverseTransform }: {
73
- selection: d3.Selection<SVGGElement, any, any, any>,
74
- textClassName: string
75
- fullParams: BaseValueAxisParams
76
- axisLabelAlign: TextAlign
77
- gridAxesSize: { width: number, height: number }
78
- fullDataFormatter: DataFormatterGrid,
79
- fullChartParams: ChartParams
80
- textReverseTransform: string,
81
- }) {
82
- const offsetX = fullParams.tickPadding - fullParams.labelOffset[0]
83
- const offsetY = fullParams.tickPadding + fullParams.labelOffset[1]
84
- let labelX = 0
85
- let labelY = 0
86
- if (fullDataFormatter.groupAxis.position === 'bottom') {
87
- // labelY = - gridAxesSize.height - offsetY
88
- labelY = - offsetY
89
- if (fullDataFormatter.valueAxis.position === 'left') {
90
- labelX = - offsetX
91
- } else if (fullDataFormatter.valueAxis.position === 'right') {
92
- labelX = offsetX
93
- }
94
- } else if (fullDataFormatter.groupAxis.position === 'top') {
95
- // labelY = gridAxesSize.height + offsetY
96
- labelY = offsetY
97
- if (fullDataFormatter.valueAxis.position === 'left') {
98
- labelX = - offsetX
99
- } else if (fullDataFormatter.valueAxis.position === 'right') {
100
- labelX = offsetX
101
- }
102
- } else if (fullDataFormatter.groupAxis.position === 'left') {
103
- // labelX = gridAxesSize.width + offsetX
104
- labelX = offsetX
105
- if (fullDataFormatter.valueAxis.position === 'bottom') {
106
- labelY = offsetY
107
- } else if (fullDataFormatter.valueAxis.position === 'top') {
108
- labelY = - offsetY
109
- }
110
- } else if (fullDataFormatter.groupAxis.position === 'right') {
111
- labelX = - offsetX
112
- if (fullDataFormatter.valueAxis.position === 'bottom') {
113
- labelY = offsetY
114
- } else if (fullDataFormatter.valueAxis.position === 'top') {
115
- labelY = - offsetY
116
- }
117
- }
118
-
119
- const axisLabelSelection = selection
120
- .selectAll<SVGGElement, BaseValueAxisParams>(`g.${textClassName}`)
121
- .data([fullParams])
122
- .join('g')
123
- .classed(textClassName, true)
124
- .each((d, i, g) => {
125
- const text = d3.select(g[i])
126
- .selectAll<SVGTextElement, BaseValueAxisParams>(`text`)
127
- .data([d])
128
- .join(
129
- enter => {
130
- return enter
131
- .append('text')
132
- .style('font-weight', 'bold')
133
- },
134
- update => update,
135
- exit => exit.remove()
136
- )
137
- .attr('text-anchor', axisLabelAlign.textAnchor)
138
- .attr('dominant-baseline', axisLabelAlign.dominantBaseline)
139
- .attr('font-size', fullChartParams.styles.textSize)
140
- .style('fill', getColor(fullParams.labelColorType, fullChartParams))
141
- .style('transform', textReverseTransform)
142
- // 偏移使用 x, y 而非 transform 才不會受到外層 scale 變形影響
143
- .attr('x', labelX)
144
- .attr('y', labelY)
145
- .text(d => fullDataFormatter.valueAxis.label)
146
- })
147
- .attr('transform', d => `translate(0, ${gridAxesSize.height})`)
148
- // .attr('transform', d => `translate(${- fullParams.tickPadding + fullParams.labelOffset[0]}, ${gridAxesSize.height + fullParams.tickPadding + fullParams.labelOffset[1]})`)
149
-
150
-
151
- }
152
-
153
- function renderAxis ({ selection, yAxisClassName, fullParams, tickTextAlign, gridAxesSize, fullDataFormatter, fullChartParams, valueScale, textReverseTransformWithRotate, filteredMinMaxValue }: {
154
- selection: d3.Selection<SVGGElement, any, any, any>,
155
- yAxisClassName: string
156
- fullParams: BaseValueAxisParams
157
- tickTextAlign: TextAlign
158
- gridAxesSize: { width: number, height: number }
159
- fullDataFormatter: DataFormatterGrid,
160
- fullChartParams: ChartParams
161
- valueScale: d3.ScaleLinear<number, number>
162
- textReverseTransformWithRotate: string,
163
- filteredMinMaxValue: [number, number]
164
- }) {
165
-
166
- const yAxisSelection = selection
167
- .selectAll<SVGGElement, BaseValueAxisParams>(`g.${yAxisClassName}`)
168
- .data([fullParams])
169
- .join('g')
170
- .classed(yAxisClassName, true)
171
-
172
- // const _valueScale = d3.scaleLinear()
173
- // .domain([0, 150])
174
- // .range([416.5, 791.349])
175
-
176
- // 刻度文字偏移
177
- let tickPadding = 0
178
- let textY = 0
179
- if (fullDataFormatter.valueAxis.position === 'left') {
180
- tickPadding = fullParams.tickPadding
181
- textY = 0
182
- } else if (fullDataFormatter.valueAxis.position === 'right') {
183
- tickPadding = - fullParams.tickPadding
184
- textY = 0
185
- } else if (fullDataFormatter.valueAxis.position === 'bottom') {
186
- tickPadding = 0
187
- textY = fullParams.tickPadding
188
- } else if (fullDataFormatter.valueAxis.position === 'top') {
189
- tickPadding = 0
190
- textY = - fullParams.tickPadding
191
- }
192
-
193
- // 設定Y軸刻度
194
- const yAxis = d3.axisLeft(valueScale)
195
- .scale(valueScale)
196
- .ticks(fullParams.ticks) // 刻度分段數量
197
- .tickFormat(d => parseTickFormatValue(d, fullParams.tickFormat))
198
- .tickSize(fullParams.tickFullLine == true
199
- ? -gridAxesSize.width
200
- : defaultTickSize)
201
- .tickPadding(tickPadding)
202
-
203
- const yAxisEl = yAxisSelection
204
- .transition()
205
- .duration(100)
206
- .call(yAxis)
207
-
208
- yAxisEl.selectAll('line')
209
- .style('fill', 'none')
210
- .style('stroke', fullParams.tickLineVisible == true ? getColor(fullParams.tickColorType, fullChartParams) : 'none')
211
- .style('stroke-dasharray', fullParams.tickFullLineDasharray)
212
- .attr('pointer-events', 'none')
213
-
214
- yAxisEl.selectAll('path')
215
- .style('fill', 'none')
216
- // .style('stroke', this.fullParams.axisLineColor!)
217
- .style('stroke', fullParams.axisLineVisible == true ? getColor(fullParams.axisLineColorType, fullChartParams) : 'none')
218
- .style('shape-rendering', 'crispEdges')
219
-
220
- // const yText = yAxisEl.selectAll('text')
221
- const yText = yAxisSelection.selectAll('text')
222
- // .style('font-family', 'sans-serif')
223
- .attr('font-size', fullChartParams.styles.textSize)
224
- .style('color', getColor(fullParams.tickTextColorType, fullChartParams))
225
- .attr('text-anchor', tickTextAlign.textAnchor)
226
- .attr('dominant-baseline', tickTextAlign.dominantBaseline)
227
- // .attr('dy', 0)
228
- .attr('y', textY)
229
- .attr('dy', 0)
230
- yText.style('transform', textReverseTransformWithRotate)
231
-
232
- // 抵消掉預設的偏移
233
- if (fullDataFormatter.valueAxis.position === 'bottom' || fullDataFormatter.valueAxis.position === 'top') {
234
- yText.attr('dy', 0)
235
- }
236
-
237
- return yAxisSelection
238
- }
239
-
240
-
241
-
242
- export const createBaseValueAxis: BasePluginFn<BaseLinesContext> = (pluginName: string, {
243
- selection,
244
- computedData$,
245
- filteredMinMaxValue$,
246
- fullParams$,
247
- fullDataFormatter$,
248
- fullChartParams$,
249
- gridAxesTransform$,
250
- gridAxesReverseTransform$,
251
- gridAxesSize$,
252
- gridContainerPosition$,
253
- isSeriesSeprate$,
254
- }) => {
255
-
256
- const destroy$ = new Subject()
257
-
258
- const containerClassName = getClassName(pluginName, 'container')
259
- const yAxisGClassName = getClassName(pluginName, 'yAxisG')
260
- const yAxisClassName = getClassName(pluginName, 'yAxis')
261
- const textClassName = getClassName(pluginName, 'text')
262
-
263
- const containerSelection$ = combineLatest({
264
- computedData: computedData$.pipe(
265
- distinctUntilChanged((a, b) => {
266
- // 只有當series的數量改變時,才重新計算
267
- return a.length === b.length
268
- }),
269
- ),
270
- isSeriesSeprate: isSeriesSeprate$
271
- }).pipe(
272
- takeUntil(destroy$),
273
- switchMap(async (d) => d),
274
- map(data => {
275
- return data.isSeriesSeprate
276
- // series分開的時候顯示各別axis
277
- ? data.computedData
278
- // series合併的時候只顯示第一個axis
279
- : [data.computedData[0]]
280
- }),
281
- map((computedData, i) => {
282
- return selection
283
- .selectAll<SVGGElement, ComputedDatumGrid[]>(`g.${containerClassName}`)
284
- .data(computedData, d => d[0] ? d[0].seriesIndex : i)
285
- .join('g')
286
- .classed(containerClassName, true)
287
- })
288
- )
289
-
290
- const axisSelection$ = containerSelection$.pipe(
291
- takeUntil(destroy$),
292
- map((containerSelection, i) => {
293
- return containerSelection
294
- .selectAll<SVGGElement, ComputedDatumGrid[]>(`g.${yAxisGClassName}`)
295
- .data([yAxisGClassName])
296
- .join('g')
297
- .classed(yAxisGClassName, true)
298
- })
299
- )
300
-
301
- combineLatest({
302
- containerSelection: containerSelection$,
303
- gridContainerPosition: gridContainerPosition$
304
- }).pipe(
305
- takeUntil(destroy$),
306
- switchMap(async d => d)
307
- ).subscribe(data => {
308
- data.containerSelection
309
- .attr('transform', (d, i) => {
310
- const gridContainerPosition = data.gridContainerPosition[i] ?? data.gridContainerPosition[0]
311
- const translate = gridContainerPosition.translate
312
- const scale = gridContainerPosition.scale
313
- return `translate(${translate[0]}, ${translate[1]}) scale(${scale[0]}, ${scale[1]})`
314
- })
315
- // .attr('opacity', 0)
316
- // .transition()
317
- // .attr('opacity', 1)
318
- })
319
-
320
- combineLatest({
321
- axisSelection: axisSelection$,
322
- gridAxesTransform: gridAxesTransform$,
323
- }).pipe(
324
- takeUntil(destroy$),
325
- switchMap(async d => d)
326
- ).subscribe(data => {
327
- data.axisSelection
328
- .style('transform', data.gridAxesTransform.value)
329
- // .attr('opacity', 0)
330
- // .transition()
331
- // .attr('opacity', 1)
332
-
333
- })
334
-
335
- // const gridAxesSize$ = gridAxisSizeObservable({
336
- // fullDataFormatter$,
337
- // layout$
338
- // })
339
-
340
- // const textReverseTransform$: Observable<string> = new Observable(subscriber => {
341
- // combineLatest({
342
- // fullParams: fullParams$,
343
- // layout: layout$
344
- // }).pipe(
345
- // takeUntil(destroy$),
346
- // // 轉換後會退訂前一個未完成的訂閱事件,因此可以取到「同時間」最後一次的訂閱事件
347
- // switchMap(async (d) => d),
348
- // ).subscribe(data => {
349
-
350
- // const transformData = Object.assign({}, data.layout.content.axesTransformData)
351
-
352
- // const value = getAxesTransformValue({
353
- // translate: [0, 0],
354
- // scale: [transformData.scale[0] * -1, transformData.scale[1] * -1],
355
- // rotate: transformData.rotate * -1 + data.fullParams.tickTextRotate,
356
- // rotateX: transformData.rotateX * -1,
357
- // rotateY: transformData.rotateY * -1
358
- // })
359
-
360
- // subscriber.next(value)
361
- // })
362
- // })
363
- // const reverseTransform$: Observable<TransformData> = gridAxesTransform$.pipe(
364
- // takeUntil(destroy$),
365
- // map(d => {
366
- // const translate: [number, number] = [d.translate[0] * -1, d.translate[1] * -1]
367
- // const scale: [number, number] = [d.scale[0] * -1, d.scale[1] * -1]
368
- // const rotate = d.rotate * -1
369
- // const rotateX = d.rotateX * -1
370
- // const rotateY = d.rotateY * -1
371
- // return {
372
- // translate,
373
- // scale,
374
- // rotate,
375
- // rotateX,
376
- // rotateY,
377
- // value: ''
378
- // }
379
- // }),
380
- // )
381
- const textReverseTransform$ = combineLatest({
382
- gridAxesReverseTransform: gridAxesReverseTransform$,
383
- gridContainerPosition: gridContainerPosition$
384
- }).pipe(
385
- takeUntil(destroy$),
386
- switchMap(async (d) => d),
387
- map(data => {
388
- // const axisReverseTranslateValue = `translate(${data.gridAxesReverseTransform.translate[0]}px, ${data.gridAxesReverseTransform.translate[1]}px)`
389
- const axesRotateXYReverseValue = `rotateX(${data.gridAxesReverseTransform.rotateX}deg) rotateY(${data.gridAxesReverseTransform.rotateY}deg)`
390
- const axesRotateReverseValue = `rotate(${data.gridAxesReverseTransform.rotate}deg)`
391
- const containerScaleReverseValue = `scale(${1 / data.gridContainerPosition[0].scale[0]}, ${1 / data.gridContainerPosition[0].scale[1]})`
392
- // 必須按照順序(先抵消外層rotate,再抵消最外層scale)
393
- return `${axesRotateXYReverseValue} ${axesRotateReverseValue} ${containerScaleReverseValue}`
394
- }),
395
- distinctUntilChanged()
396
- )
397
-
398
- const textReverseTransformWithRotate$ = combineLatest({
399
- textReverseTransform: textReverseTransform$,
400
- fullParams: fullParams$,
401
- }).pipe(
402
- takeUntil(destroy$),
403
- switchMap(async (d) => d),
404
- map(data => {
405
- // 必須按照順序(先抵消外層rotate,再抵消最外層scale,最後再做本身的rotate)
406
- return `${data.textReverseTransform} rotate(${data.fullParams.tickTextRotate}deg)`
407
- })
408
- )
409
-
410
- // const minMax$: Observable<[number, number]> = new Observable(subscriber => {
411
- // combineLatest({
412
- // fullDataFormatter: fullDataFormatter$,
413
- // computedData: computedData$
414
- // }).pipe(
415
- // takeUntil(destroy$),
416
- // switchMap(async (d) => d),
417
- // ).subscribe(data => {
418
- // const groupMin = 0
419
- // const groupMax = data.computedData[0] ? data.computedData[0].length - 1 : 0
420
- // // const groupScaleDomainMin = data.fullDataFormatter.groupAxis.scaleDomain[0] === 'auto'
421
- // // ? groupMin - data.fullDataFormatter.groupAxis.scalePadding
422
- // // : data.fullDataFormatter.groupAxis.scaleDomain[0] as number - data.fullDataFormatter.groupAxis.scalePadding
423
- // const groupScaleDomainMin = data.fullDataFormatter.groupAxis.scaleDomain[0] - data.fullDataFormatter.groupAxis.scalePadding
424
- // const groupScaleDomainMax = data.fullDataFormatter.groupAxis.scaleDomain[1] === 'max'
425
- // ? groupMax + data.fullDataFormatter.groupAxis.scalePadding
426
- // : data.fullDataFormatter.groupAxis.scaleDomain[1] as number + data.fullDataFormatter.groupAxis.scalePadding
427
-
428
- // const filteredData = data.computedData.map((d, i) => {
429
- // return d.filter((_d, _i) => {
430
- // return _i >= groupScaleDomainMin && _i <= groupScaleDomainMax
431
- // })
432
- // })
433
-
434
- // const filteredMinMax = getMinMaxValue(filteredData.flat())
435
- // if (filteredMinMax[0] === filteredMinMax[1]) {
436
- // filteredMinMax[0] = filteredMinMax[1] - 1 // 避免最大及最小值相同造成無法計算scale
437
- // }
438
- // subscriber.next(filteredMinMax)
439
- // })
440
- // })
441
-
442
- const valueScale$: Observable<d3.ScaleLinear<number, number>> = new Observable(subscriber => {
443
- combineLatest({
444
- fullDataFormatter: fullDataFormatter$,
445
- gridAxesSize: gridAxesSize$,
446
- // minMax: minMax$
447
- filteredMinMaxValue: filteredMinMaxValue$
448
- }).pipe(
449
- takeUntil(destroy$),
450
- switchMap(async (d) => d),
451
- ).subscribe(data => {
452
- let maxValue = data.filteredMinMaxValue[1]
453
- let minValue = data.filteredMinMaxValue[0]
454
- if (maxValue === minValue && maxValue === 0) {
455
- // 避免最大及最小值同等於 0 造成無法計算scale
456
- maxValue = 1
457
- }
458
-
459
- const valueScale: d3.ScaleLinear<number, number> = createValueToAxisScale({
460
- maxValue,
461
- minValue,
462
- axisWidth: data.gridAxesSize.height,
463
- scaleDomain: data.fullDataFormatter.valueAxis.scaleDomain,
464
- scaleRange: data.fullDataFormatter.valueAxis.scaleRange
465
- })
466
-
467
- subscriber.next(valueScale)
468
- })
469
- })
470
-
471
- const tickTextAlign$: Observable<TextAlign> = combineLatest({
472
- fullDataFormatter: fullDataFormatter$,
473
- fullParams: fullParams$
474
- }).pipe(
475
- takeUntil(destroy$),
476
- switchMap(async (d) => d),
477
- map(data => {
478
- let textAnchor: 'start' | 'middle' | 'end' = 'start'
479
- let dominantBaseline: 'auto' | 'middle' | 'hanging' = 'hanging'
480
-
481
- if (data.fullDataFormatter.valueAxis.position === 'left') {
482
- textAnchor = 'end'
483
- dominantBaseline = 'middle'
484
- } else if (data.fullDataFormatter.valueAxis.position === 'right') {
485
- textAnchor = 'start'
486
- dominantBaseline = 'middle'
487
- } else if (data.fullDataFormatter.valueAxis.position === 'bottom') {
488
- textAnchor = data.fullParams.tickTextRotate
489
- ? 'end'
490
- : 'middle'
491
- dominantBaseline = 'hanging'
492
- } else if (data.fullDataFormatter.valueAxis.position === 'top') {
493
- textAnchor = data.fullParams.tickTextRotate
494
- ? 'start'
495
- : 'middle'
496
- dominantBaseline = 'auto'
497
- }
498
- return {
499
- textAnchor,
500
- dominantBaseline
501
- }
502
- })
503
- )
504
-
505
- const axisLabelAlign$: Observable<TextAlign> = fullDataFormatter$.pipe(
506
- takeUntil(destroy$),
507
- map(d => {
508
- let textAnchor: 'start' | 'middle' | 'end' = 'start'
509
- let dominantBaseline: 'auto' | 'middle' | 'hanging' = 'hanging'
510
-
511
- if (d.groupAxis.position === 'bottom') {
512
- dominantBaseline = 'auto'
513
- } else if (d.groupAxis.position === 'top') {
514
- dominantBaseline = 'hanging'
515
- } else if (d.groupAxis.position === 'left') {
516
- textAnchor = 'start'
517
- } else if (d.groupAxis.position === 'right') {
518
- textAnchor = 'end'
519
- }
520
- if (d.valueAxis.position === 'left') {
521
- textAnchor = 'end'
522
- } else if (d.valueAxis.position === 'right') {
523
- textAnchor = 'start'
524
- } else if (d.valueAxis.position === 'bottom') {
525
- dominantBaseline = 'hanging'
526
- } else if (d.valueAxis.position === 'top') {
527
- dominantBaseline = 'auto'
528
- }
529
- return {
530
- textAnchor,
531
- dominantBaseline
532
- }
533
- })
534
- )
535
-
536
-
537
- combineLatest({
538
- axisSelection: axisSelection$,
539
- fullParams: fullParams$,
540
- tickTextAlign: tickTextAlign$,
541
- axisLabelAlign: axisLabelAlign$,
542
- computedData: computedData$,
543
- gridAxesSize: gridAxesSize$,
544
- fullDataFormatter: fullDataFormatter$,
545
- fullChartParams: fullChartParams$,
546
- valueScale: valueScale$,
547
- textReverseTransform: textReverseTransform$,
548
- textReverseTransformWithRotate: textReverseTransformWithRotate$,
549
- filteredMinMaxValue: filteredMinMaxValue$
550
- }).pipe(
551
- takeUntil(destroy$),
552
- switchMap(async (d) => d),
553
- ).subscribe(data => {
554
-
555
- renderAxis({
556
- selection: data.axisSelection,
557
- yAxisClassName,
558
- fullParams: data.fullParams,
559
- tickTextAlign: data.tickTextAlign,
560
- gridAxesSize: data.gridAxesSize,
561
- fullDataFormatter: data.fullDataFormatter,
562
- fullChartParams: data.fullChartParams,
563
- valueScale: data.valueScale,
564
- textReverseTransformWithRotate: data.textReverseTransformWithRotate,
565
- filteredMinMaxValue: data.filteredMinMaxValue
566
- })
567
-
568
- renderAxisLabel({
569
- selection: data.axisSelection,
570
- textClassName,
571
- fullParams: data.fullParams,
572
- axisLabelAlign: data.axisLabelAlign,
573
- gridAxesSize: data.gridAxesSize,
574
- fullDataFormatter: data.fullDataFormatter,
575
- fullChartParams: data.fullChartParams,
576
- textReverseTransform: data.textReverseTransform,
577
- })
578
- })
579
-
580
- return () => {
581
- destroy$.next(undefined)
582
- }
583
- }
1
+ import * as d3 from 'd3'
2
+ import {
3
+ combineLatest,
4
+ switchMap,
5
+ distinctUntilChanged,
6
+ first,
7
+ map,
8
+ takeUntil,
9
+ Observable,
10
+ Subject } from 'rxjs'
11
+ import { createValueToAxisScale } from '../../lib/core'
12
+ import type { BasePluginFn } from './types'
13
+ import type {
14
+ ComputedDataGrid,
15
+ DataFormatterGrid,
16
+ ChartParams,
17
+ ComputedDatumGrid,
18
+ ContainerPositionScaled,
19
+ ContainerSize,
20
+ TransformData,
21
+ EventGrid,
22
+ ColorType
23
+ } from '../../lib/core-types'
24
+ import type { BaseValueAxisParams } from '../../lib/plugins-basic-types'
25
+ import { parseTickFormatValue } from '../utils/d3Utils'
26
+ import { getColor, getMinMaxValue, getClassName, getUniID } from '../utils/orbchartsUtils'
27
+ import { gridContainerSelectionsObservable } from '../grid/gridObservables'
28
+
29
+ // export interface BaseValueAxisParams {
30
+ // labelOffset: [number, number]
31
+ // labelColorType: ColorType
32
+ // axisLineVisible: boolean
33
+ // axisLineColorType: ColorType
34
+ // ticks: number
35
+ // tickFormat: string | ((text: d3.NumberValue) => string)
36
+ // tickLineVisible: boolean
37
+ // tickPadding: number
38
+ // tickFullLine: boolean
39
+ // tickFullLineDasharray: string
40
+ // tickColorType: ColorType
41
+ // tickTextRotate: number
42
+ // tickTextColorType: ColorType
43
+ // }
44
+
45
+ interface BaseValueAxisContext {
46
+ selection: d3.Selection<any, unknown, any, unknown>
47
+ computedData$: Observable<ComputedDataGrid>
48
+ filteredMinMaxValue$: Observable<[number, number]>
49
+ fullParams$: Observable<BaseValueAxisParams>
50
+ fullDataFormatter$: Observable<DataFormatterGrid>
51
+ fullChartParams$: Observable<ChartParams>
52
+ gridAxesTransform$: Observable<TransformData>
53
+ gridAxesReverseTransform$: Observable<TransformData>
54
+ // gridAxesSize$: Observable<{
55
+ // width: number;
56
+ // height: number;
57
+ // }>
58
+ gridContainerPosition$: Observable<ContainerPositionScaled[]>
59
+ gridAxesSize$: Observable<ContainerSize>
60
+ // gridAxesContainerSize$: Observable<ContainerSize>
61
+ isSeriesSeprate$: Observable<boolean>
62
+ }
63
+
64
+ interface TextAlign {
65
+ textAnchor: "start" | "middle" | "end"
66
+ dominantBaseline: "middle" | "auto" | "hanging"
67
+ }
68
+
69
+ // const pluginName = 'ValueAxis'
70
+ // const containerClassName = getClassName(pluginName, 'container')
71
+ // const yAxisGClassName = getClassName(pluginName, 'yAxisG')
72
+ // const yAxisClassName = getClassName(pluginName, 'yAxis')
73
+ // const textClassName = getClassName(pluginName, 'text')
74
+ const defaultTickSize = 6
75
+
76
+ function renderAxisLabel ({ selection, textClassName, fullParams, axisLabelAlign, gridAxesSize, fullDataFormatter, fullChartParams, textReverseTransform }: {
77
+ selection: d3.Selection<SVGGElement, any, any, any>,
78
+ textClassName: string
79
+ fullParams: BaseValueAxisParams
80
+ axisLabelAlign: TextAlign
81
+ gridAxesSize: ContainerSize
82
+ fullDataFormatter: DataFormatterGrid,
83
+ fullChartParams: ChartParams
84
+ textReverseTransform: string,
85
+ }) {
86
+ const offsetX = fullParams.tickPadding - fullParams.labelOffset[0]
87
+ const offsetY = fullParams.tickPadding + fullParams.labelOffset[1]
88
+ let labelX = 0
89
+ let labelY = 0
90
+ if (fullDataFormatter.groupAxis.position === 'bottom') {
91
+ // labelY = - gridAxesSize.height - offsetY
92
+ labelY = - offsetY
93
+ if (fullDataFormatter.valueAxis.position === 'left') {
94
+ labelX = - offsetX
95
+ } else if (fullDataFormatter.valueAxis.position === 'right') {
96
+ labelX = offsetX
97
+ }
98
+ } else if (fullDataFormatter.groupAxis.position === 'top') {
99
+ // labelY = gridAxesSize.height + offsetY
100
+ labelY = offsetY
101
+ if (fullDataFormatter.valueAxis.position === 'left') {
102
+ labelX = - offsetX
103
+ } else if (fullDataFormatter.valueAxis.position === 'right') {
104
+ labelX = offsetX
105
+ }
106
+ } else if (fullDataFormatter.groupAxis.position === 'left') {
107
+ // labelX = gridAxesSize.width + offsetX
108
+ labelX = offsetX
109
+ if (fullDataFormatter.valueAxis.position === 'bottom') {
110
+ labelY = offsetY
111
+ } else if (fullDataFormatter.valueAxis.position === 'top') {
112
+ labelY = - offsetY
113
+ }
114
+ } else if (fullDataFormatter.groupAxis.position === 'right') {
115
+ labelX = - offsetX
116
+ if (fullDataFormatter.valueAxis.position === 'bottom') {
117
+ labelY = offsetY
118
+ } else if (fullDataFormatter.valueAxis.position === 'top') {
119
+ labelY = - offsetY
120
+ }
121
+ }
122
+
123
+ const axisLabelSelection = selection
124
+ .selectAll<SVGGElement, BaseValueAxisParams>(`g.${textClassName}`)
125
+ .data([fullParams])
126
+ .join('g')
127
+ .classed(textClassName, true)
128
+ .each((d, i, g) => {
129
+ const text = d3.select(g[i])
130
+ .selectAll<SVGTextElement, BaseValueAxisParams>(`text`)
131
+ .data([d])
132
+ .join(
133
+ enter => {
134
+ return enter
135
+ .append('text')
136
+ .style('font-weight', 'bold')
137
+ },
138
+ update => update,
139
+ exit => exit.remove()
140
+ )
141
+ .attr('text-anchor', axisLabelAlign.textAnchor)
142
+ .attr('dominant-baseline', axisLabelAlign.dominantBaseline)
143
+ .attr('font-size', fullChartParams.styles.textSize)
144
+ .style('fill', getColor(fullParams.labelColorType, fullChartParams))
145
+ .style('transform', textReverseTransform)
146
+ // 偏移使用 x, y 而非 transform 才不會受到外層 scale 變形影響
147
+ .attr('x', labelX)
148
+ .attr('y', labelY)
149
+ .text(d => fullDataFormatter.valueAxis.label)
150
+ })
151
+ .attr('transform', d => `translate(0, ${gridAxesSize.height})`)
152
+ // .attr('transform', d => `translate(${- fullParams.tickPadding + fullParams.labelOffset[0]}, ${gridAxesSize.height + fullParams.tickPadding + fullParams.labelOffset[1]})`)
153
+
154
+
155
+ }
156
+
157
+ function renderAxis ({ selection, yAxisClassName, fullParams, tickTextAlign, gridAxesSize, fullDataFormatter, fullChartParams, valueScale, textReverseTransformWithRotate, filteredMinMaxValue }: {
158
+ selection: d3.Selection<SVGGElement, any, any, any>,
159
+ yAxisClassName: string
160
+ fullParams: BaseValueAxisParams
161
+ tickTextAlign: TextAlign
162
+ gridAxesSize: ContainerSize
163
+ fullDataFormatter: DataFormatterGrid,
164
+ fullChartParams: ChartParams
165
+ valueScale: d3.ScaleLinear<number, number>
166
+ textReverseTransformWithRotate: string,
167
+ filteredMinMaxValue: [number, number]
168
+ }) {
169
+
170
+ const yAxisSelection = selection
171
+ .selectAll<SVGGElement, BaseValueAxisParams>(`g.${yAxisClassName}`)
172
+ .data([fullParams])
173
+ .join('g')
174
+ .classed(yAxisClassName, true)
175
+
176
+ // const _valueScale = d3.scaleLinear()
177
+ // .domain([0, 150])
178
+ // .range([416.5, 791.349])
179
+
180
+ // 刻度文字偏移
181
+ let tickPadding = 0
182
+ let textY = 0
183
+ if (fullDataFormatter.valueAxis.position === 'left') {
184
+ tickPadding = fullParams.tickPadding
185
+ textY = 0
186
+ } else if (fullDataFormatter.valueAxis.position === 'right') {
187
+ tickPadding = - fullParams.tickPadding
188
+ textY = 0
189
+ } else if (fullDataFormatter.valueAxis.position === 'bottom') {
190
+ tickPadding = 0
191
+ textY = fullParams.tickPadding
192
+ } else if (fullDataFormatter.valueAxis.position === 'top') {
193
+ tickPadding = 0
194
+ textY = - fullParams.tickPadding
195
+ }
196
+
197
+ // 設定Y軸刻度
198
+ const yAxis = d3.axisLeft(valueScale)
199
+ .scale(valueScale)
200
+ .ticks(fullParams.ticks) // 刻度分段數量
201
+ .tickFormat(d => parseTickFormatValue(d, fullParams.tickFormat))
202
+ .tickSize(fullParams.tickFullLine == true
203
+ ? -gridAxesSize.width
204
+ : defaultTickSize)
205
+ .tickPadding(tickPadding)
206
+
207
+ const yAxisEl = yAxisSelection
208
+ .transition()
209
+ .duration(100)
210
+ .ease(d3.easeLinear) // 線性的 - 當托曳或快速變動的時候比較滑順
211
+ .call(yAxis)
212
+
213
+ yAxisEl.selectAll('line')
214
+ .style('fill', 'none')
215
+ .style('stroke', fullParams.tickLineVisible == true ? getColor(fullParams.tickColorType, fullChartParams) : 'none')
216
+ .style('stroke-dasharray', fullParams.tickFullLineDasharray)
217
+ .style('vector-effect', 'non-scaling-stroke') // 避免 scale 導致線條變形
218
+ .attr('pointer-events', 'none')
219
+
220
+ yAxisEl.selectAll('path')
221
+ .style('fill', 'none')
222
+ // .style('stroke', this.fullParams.axisLineColor!)
223
+ .style('stroke', fullParams.axisLineVisible == true ? getColor(fullParams.axisLineColorType, fullChartParams) : 'none')
224
+ .style('shape-rendering', 'crispEdges')
225
+
226
+ // const yText = yAxisEl.selectAll('text')
227
+ const yText = yAxisSelection.selectAll('text')
228
+ // .style('font-family', 'sans-serif')
229
+ .attr('font-size', fullChartParams.styles.textSize)
230
+ .style('color', getColor(fullParams.tickTextColorType, fullChartParams))
231
+ .attr('text-anchor', tickTextAlign.textAnchor)
232
+ .attr('dominant-baseline', tickTextAlign.dominantBaseline)
233
+ // .attr('dy', 0)
234
+ .attr('y', textY)
235
+ .attr('dy', 0)
236
+ yText.style('transform', textReverseTransformWithRotate)
237
+
238
+ // 抵消掉預設的偏移
239
+ if (fullDataFormatter.valueAxis.position === 'bottom' || fullDataFormatter.valueAxis.position === 'top') {
240
+ yText.attr('dy', 0)
241
+ }
242
+
243
+ return yAxisSelection
244
+ }
245
+
246
+
247
+
248
+ export const createBaseValueAxis: BasePluginFn<BaseValueAxisContext> = (pluginName: string, {
249
+ selection,
250
+ computedData$,
251
+ filteredMinMaxValue$,
252
+ fullParams$,
253
+ fullDataFormatter$,
254
+ fullChartParams$,
255
+ gridAxesSize$,
256
+ gridAxesTransform$,
257
+ gridAxesReverseTransform$,
258
+ // gridAxesSize$,
259
+ gridContainerPosition$,
260
+ // gridAxesContainerSize$,
261
+ isSeriesSeprate$,
262
+ }) => {
263
+
264
+ const destroy$ = new Subject()
265
+
266
+ const containerClassName = getClassName(pluginName, 'container')
267
+ const yAxisGClassName = getClassName(pluginName, 'yAxisG')
268
+ const yAxisClassName = getClassName(pluginName, 'yAxis')
269
+ const textClassName = getClassName(pluginName, 'text')
270
+
271
+ const containerSelection$ = gridContainerSelectionsObservable({
272
+ selection,
273
+ pluginName,
274
+ computedData$,
275
+ gridContainerPosition$,
276
+ isSeriesSeprate$
277
+ })
278
+
279
+ // const containerSelection$ = combineLatest({
280
+ // computedData: computedData$.pipe(
281
+ // distinctUntilChanged((a, b) => {
282
+ // // 只有當series的數量改變時,才重新計算
283
+ // return a.length === b.length
284
+ // }),
285
+ // ),
286
+ // isSeriesSeprate: isSeriesSeprate$
287
+ // }).pipe(
288
+ // takeUntil(destroy$),
289
+ // switchMap(async (d) => d),
290
+ // map(data => {
291
+ // return data.isSeriesSeprate
292
+ // // series分開的時候顯示各別axis
293
+ // ? data.computedData
294
+ // // series合併的時候只顯示第一個axis
295
+ // : [data.computedData[0]]
296
+ // }),
297
+ // map((computedData, i) => {
298
+ // return selection
299
+ // .selectAll<SVGGElement, ComputedDatumGrid[]>(`g.${containerClassName}`)
300
+ // .data(computedData, d => d[0] ? d[0].seriesIndex : i)
301
+ // .join('g')
302
+ // .classed(containerClassName, true)
303
+ // })
304
+ // )
305
+
306
+ const axisSelection$ = containerSelection$.pipe(
307
+ takeUntil(destroy$),
308
+ map((containerSelection, i) => {
309
+ return containerSelection
310
+ .selectAll<SVGGElement, ComputedDatumGrid[]>(`g.${yAxisGClassName}`)
311
+ .data([yAxisGClassName])
312
+ .join('g')
313
+ .classed(yAxisGClassName, true)
314
+ })
315
+ )
316
+
317
+ // combineLatest({
318
+ // containerSelection: containerSelection$,
319
+ // gridContainerPosition: gridContainerPosition$
320
+ // }).pipe(
321
+ // takeUntil(destroy$),
322
+ // switchMap(async d => d)
323
+ // ).subscribe(data => {
324
+ // data.containerSelection
325
+ // .attr('transform', (d, i) => {
326
+ // const gridContainerPosition = data.gridContainerPosition[i] ?? data.gridContainerPosition[0]
327
+ // const translate = gridContainerPosition.translate
328
+ // const scale = gridContainerPosition.scale
329
+ // // return `translate(${translate[0]}, ${translate[1]}) scale(${scale[0]}, ${scale[1]})`
330
+ // return `translate(${translate[0]}, ${translate[1]})`
331
+ // })
332
+ // // .attr('opacity', 0)
333
+ // // .transition()
334
+ // // .attr('opacity', 1)
335
+ // })
336
+
337
+ combineLatest({
338
+ axisSelection: axisSelection$,
339
+ gridAxesTransform: gridAxesTransform$,
340
+ }).pipe(
341
+ takeUntil(destroy$),
342
+ switchMap(async d => d)
343
+ ).subscribe(data => {
344
+ data.axisSelection
345
+ .style('transform', data.gridAxesTransform.value)
346
+ // .attr('opacity', 0)
347
+ // .transition()
348
+ // .attr('opacity', 1)
349
+
350
+ })
351
+
352
+ // const gridAxesSize$ = gridAxisSizeObservable({
353
+ // fullDataFormatter$,
354
+ // layout$
355
+ // })
356
+
357
+ // const textReverseTransform$: Observable<string> = new Observable(subscriber => {
358
+ // combineLatest({
359
+ // fullParams: fullParams$,
360
+ // layout: layout$
361
+ // }).pipe(
362
+ // takeUntil(destroy$),
363
+ // // 轉換後會退訂前一個未完成的訂閱事件,因此可以取到「同時間」最後一次的訂閱事件
364
+ // switchMap(async (d) => d),
365
+ // ).subscribe(data => {
366
+
367
+ // const transformData = Object.assign({}, data.layout.content.axesTransformData)
368
+
369
+ // const value = getAxesTransformValue({
370
+ // translate: [0, 0],
371
+ // scale: [transformData.scale[0] * -1, transformData.scale[1] * -1],
372
+ // rotate: transformData.rotate * -1 + data.fullParams.tickTextRotate,
373
+ // rotateX: transformData.rotateX * -1,
374
+ // rotateY: transformData.rotateY * -1
375
+ // })
376
+
377
+ // subscriber.next(value)
378
+ // })
379
+ // })
380
+ // const reverseTransform$: Observable<TransformData> = gridAxesTransform$.pipe(
381
+ // takeUntil(destroy$),
382
+ // map(d => {
383
+ // const translate: [number, number] = [d.translate[0] * -1, d.translate[1] * -1]
384
+ // const scale: [number, number] = [d.scale[0] * -1, d.scale[1] * -1]
385
+ // const rotate = d.rotate * -1
386
+ // const rotateX = d.rotateX * -1
387
+ // const rotateY = d.rotateY * -1
388
+ // return {
389
+ // translate,
390
+ // scale,
391
+ // rotate,
392
+ // rotateX,
393
+ // rotateY,
394
+ // value: ''
395
+ // }
396
+ // }),
397
+ // )
398
+ const textReverseTransform$ = combineLatest({
399
+ gridAxesReverseTransform: gridAxesReverseTransform$,
400
+ gridContainerPosition: gridContainerPosition$
401
+ }).pipe(
402
+ takeUntil(destroy$),
403
+ switchMap(async (d) => d),
404
+ map(data => {
405
+ // const axisReverseTranslateValue = `translate(${data.gridAxesReverseTransform.translate[0]}px, ${data.gridAxesReverseTransform.translate[1]}px)`
406
+ const axesRotateXYReverseValue = `rotateX(${data.gridAxesReverseTransform.rotateX}deg) rotateY(${data.gridAxesReverseTransform.rotateY}deg)`
407
+ const axesRotateReverseValue = `rotate(${data.gridAxesReverseTransform.rotate}deg)`
408
+ const containerScaleReverseValue = `scale(${1 / data.gridContainerPosition[0].scale[0]}, ${1 / data.gridContainerPosition[0].scale[1]})`
409
+ // 必須按照順序(先抵消外層rotate,再抵消最外層scale)
410
+ return `${axesRotateXYReverseValue} ${axesRotateReverseValue} ${containerScaleReverseValue}`
411
+ }),
412
+ distinctUntilChanged()
413
+ )
414
+
415
+ const textReverseTransformWithRotate$ = combineLatest({
416
+ textReverseTransform: textReverseTransform$,
417
+ fullParams: fullParams$,
418
+ }).pipe(
419
+ takeUntil(destroy$),
420
+ switchMap(async (d) => d),
421
+ map(data => {
422
+ // 必須按照順序(先抵消外層rotate,再抵消最外層scale,最後再做本身的rotate)
423
+ return `${data.textReverseTransform} rotate(${data.fullParams.tickTextRotate}deg)`
424
+ })
425
+ )
426
+
427
+ // const minMax$: Observable<[number, number]> = new Observable(subscriber => {
428
+ // combineLatest({
429
+ // fullDataFormatter: fullDataFormatter$,
430
+ // computedData: computedData$
431
+ // }).pipe(
432
+ // takeUntil(destroy$),
433
+ // switchMap(async (d) => d),
434
+ // ).subscribe(data => {
435
+ // const groupMin = 0
436
+ // const groupMax = data.computedData[0] ? data.computedData[0].length - 1 : 0
437
+ // // const groupScaleDomainMin = data.fullDataFormatter.groupAxis.scaleDomain[0] === 'auto'
438
+ // // ? groupMin - data.fullDataFormatter.groupAxis.scalePadding
439
+ // // : data.fullDataFormatter.groupAxis.scaleDomain[0] as number - data.fullDataFormatter.groupAxis.scalePadding
440
+ // const groupScaleDomainMin = data.fullDataFormatter.groupAxis.scaleDomain[0] - data.fullDataFormatter.groupAxis.scalePadding
441
+ // const groupScaleDomainMax = data.fullDataFormatter.groupAxis.scaleDomain[1] === 'max'
442
+ // ? groupMax + data.fullDataFormatter.groupAxis.scalePadding
443
+ // : data.fullDataFormatter.groupAxis.scaleDomain[1] as number + data.fullDataFormatter.groupAxis.scalePadding
444
+
445
+ // const filteredData = data.computedData.map((d, i) => {
446
+ // return d.filter((_d, _i) => {
447
+ // return _i >= groupScaleDomainMin && _i <= groupScaleDomainMax
448
+ // })
449
+ // })
450
+
451
+ // const filteredMinMax = getMinMaxValue(filteredData.flat())
452
+ // if (filteredMinMax[0] === filteredMinMax[1]) {
453
+ // filteredMinMax[0] = filteredMinMax[1] - 1 // 避免最大及最小值相同造成無法計算scale
454
+ // }
455
+ // subscriber.next(filteredMinMax)
456
+ // })
457
+ // })
458
+
459
+ const valueScale$: Observable<d3.ScaleLinear<number, number>> = new Observable(subscriber => {
460
+ combineLatest({
461
+ fullDataFormatter: fullDataFormatter$,
462
+ gridAxesSize: gridAxesSize$,
463
+ // minMax: minMax$
464
+ filteredMinMaxValue: filteredMinMaxValue$
465
+ }).pipe(
466
+ takeUntil(destroy$),
467
+ switchMap(async (d) => d),
468
+ ).subscribe(data => {
469
+ let maxValue = data.filteredMinMaxValue[1]
470
+ let minValue = data.filteredMinMaxValue[0]
471
+ if (maxValue === minValue && maxValue === 0) {
472
+ // 避免最大及最小值同等於 0 造成無法計算scale
473
+ maxValue = 1
474
+ }
475
+
476
+ const valueScale: d3.ScaleLinear<number, number> = createValueToAxisScale({
477
+ maxValue,
478
+ minValue,
479
+ axisWidth: data.gridAxesSize.height,
480
+ scaleDomain: data.fullDataFormatter.valueAxis.scaleDomain,
481
+ scaleRange: data.fullDataFormatter.valueAxis.scaleRange
482
+ })
483
+
484
+ subscriber.next(valueScale)
485
+ })
486
+ })
487
+
488
+ const tickTextAlign$: Observable<TextAlign> = combineLatest({
489
+ fullDataFormatter: fullDataFormatter$,
490
+ fullParams: fullParams$
491
+ }).pipe(
492
+ takeUntil(destroy$),
493
+ switchMap(async (d) => d),
494
+ map(data => {
495
+ let textAnchor: 'start' | 'middle' | 'end' = 'start'
496
+ let dominantBaseline: 'auto' | 'middle' | 'hanging' = 'hanging'
497
+
498
+ if (data.fullDataFormatter.valueAxis.position === 'left') {
499
+ textAnchor = 'end'
500
+ dominantBaseline = 'middle'
501
+ } else if (data.fullDataFormatter.valueAxis.position === 'right') {
502
+ textAnchor = 'start'
503
+ dominantBaseline = 'middle'
504
+ } else if (data.fullDataFormatter.valueAxis.position === 'bottom') {
505
+ textAnchor = data.fullParams.tickTextRotate
506
+ ? 'end'
507
+ : 'middle'
508
+ dominantBaseline = 'hanging'
509
+ } else if (data.fullDataFormatter.valueAxis.position === 'top') {
510
+ textAnchor = data.fullParams.tickTextRotate
511
+ ? 'start'
512
+ : 'middle'
513
+ dominantBaseline = 'auto'
514
+ }
515
+ return {
516
+ textAnchor,
517
+ dominantBaseline
518
+ }
519
+ })
520
+ )
521
+
522
+ const axisLabelAlign$: Observable<TextAlign> = fullDataFormatter$.pipe(
523
+ takeUntil(destroy$),
524
+ map(d => {
525
+ let textAnchor: 'start' | 'middle' | 'end' = 'start'
526
+ let dominantBaseline: 'auto' | 'middle' | 'hanging' = 'hanging'
527
+
528
+ if (d.groupAxis.position === 'bottom') {
529
+ dominantBaseline = 'auto'
530
+ } else if (d.groupAxis.position === 'top') {
531
+ dominantBaseline = 'hanging'
532
+ } else if (d.groupAxis.position === 'left') {
533
+ textAnchor = 'start'
534
+ } else if (d.groupAxis.position === 'right') {
535
+ textAnchor = 'end'
536
+ }
537
+ if (d.valueAxis.position === 'left') {
538
+ textAnchor = 'end'
539
+ } else if (d.valueAxis.position === 'right') {
540
+ textAnchor = 'start'
541
+ } else if (d.valueAxis.position === 'bottom') {
542
+ dominantBaseline = 'hanging'
543
+ } else if (d.valueAxis.position === 'top') {
544
+ dominantBaseline = 'auto'
545
+ }
546
+ return {
547
+ textAnchor,
548
+ dominantBaseline
549
+ }
550
+ })
551
+ )
552
+
553
+
554
+ combineLatest({
555
+ axisSelection: axisSelection$,
556
+ fullParams: fullParams$,
557
+ tickTextAlign: tickTextAlign$,
558
+ axisLabelAlign: axisLabelAlign$,
559
+ computedData: computedData$,
560
+ gridAxesSize: gridAxesSize$,
561
+ fullDataFormatter: fullDataFormatter$,
562
+ fullChartParams: fullChartParams$,
563
+ valueScale: valueScale$,
564
+ textReverseTransform: textReverseTransform$,
565
+ textReverseTransformWithRotate: textReverseTransformWithRotate$,
566
+ filteredMinMaxValue: filteredMinMaxValue$
567
+ }).pipe(
568
+ takeUntil(destroy$),
569
+ switchMap(async (d) => d),
570
+ ).subscribe(data => {
571
+
572
+ renderAxis({
573
+ selection: data.axisSelection,
574
+ yAxisClassName,
575
+ fullParams: data.fullParams,
576
+ tickTextAlign: data.tickTextAlign,
577
+ gridAxesSize: data.gridAxesSize,
578
+ fullDataFormatter: data.fullDataFormatter,
579
+ fullChartParams: data.fullChartParams,
580
+ valueScale: data.valueScale,
581
+ textReverseTransformWithRotate: data.textReverseTransformWithRotate,
582
+ filteredMinMaxValue: data.filteredMinMaxValue
583
+ })
584
+
585
+ renderAxisLabel({
586
+ selection: data.axisSelection,
587
+ textClassName,
588
+ fullParams: data.fullParams,
589
+ axisLabelAlign: data.axisLabelAlign,
590
+ gridAxesSize: data.gridAxesSize,
591
+ fullDataFormatter: data.fullDataFormatter,
592
+ fullChartParams: data.fullChartParams,
593
+ textReverseTransform: data.textReverseTransform,
594
+ })
595
+ })
596
+
597
+ return () => {
598
+ destroy$.next(undefined)
599
+ }
600
+ }