@orbcharts/core 3.0.0-alpha.61 → 3.0.0-alpha.63

Sign up to get free protection for your applications and to get access to all the features.
Files changed (215) hide show
  1. package/LICENSE +200 -200
  2. package/dist/lib/core-types.d.ts +1 -0
  3. package/dist/orbcharts-core.es.js +3418 -2726
  4. package/dist/orbcharts-core.umd.js +6 -2
  5. package/dist/src/AbstractChart.d.ts +5 -3
  6. package/dist/src/GridChart.d.ts +1 -1
  7. package/dist/src/MultiGridChart.d.ts +1 -1
  8. package/dist/src/MultiValueChart.d.ts +1 -1
  9. package/dist/src/RelationshipChart.d.ts +1 -1
  10. package/dist/src/SeriesChart.d.ts +1 -1
  11. package/dist/src/TreeChart.d.ts +1 -1
  12. package/dist/src/base/createBaseChart.d.ts +1 -1
  13. package/dist/src/base/createBasePlugin.d.ts +1 -1
  14. package/dist/src/base/validators/chartOptionsValidator.d.ts +3 -0
  15. package/dist/src/base/validators/chartParamsValidator.d.ts +3 -0
  16. package/dist/src/base/validators/elementValidator.d.ts +3 -0
  17. package/dist/src/base/validators/pluginsValidator.d.ts +3 -0
  18. package/dist/src/defaults.d.ts +1 -16
  19. package/dist/src/defineGridPlugin.d.ts +1 -1
  20. package/dist/src/defineMultiGridPlugin.d.ts +1 -1
  21. package/dist/src/defineMultiValuePlugin.d.ts +1 -1
  22. package/dist/src/defineNoneDataPlugin.d.ts +1 -1
  23. package/dist/src/defineRelationshipPlugin.d.ts +1 -1
  24. package/dist/src/defineSeriesPlugin.d.ts +1 -1
  25. package/dist/src/defineTreePlugin.d.ts +1 -1
  26. package/dist/src/grid/computedDataFn.d.ts +4 -0
  27. package/dist/src/grid/contextObserverCallback.d.ts +3 -0
  28. package/dist/src/grid/dataFormatterValidator.d.ts +3 -0
  29. package/dist/src/grid/dataValidator.d.ts +3 -0
  30. package/dist/src/index.d.ts +1 -1
  31. package/dist/src/multiGrid/computedDataFn.d.ts +3 -0
  32. package/dist/src/multiGrid/contextObserverCallback.d.ts +3 -0
  33. package/dist/src/multiGrid/dataFormatterValidator.d.ts +3 -0
  34. package/dist/src/multiGrid/dataValidator.d.ts +3 -0
  35. package/dist/src/multiValue/computedDataFn.d.ts +3 -0
  36. package/dist/src/multiValue/contextObserverCallback.d.ts +3 -0
  37. package/dist/src/multiValue/dataFormatterValidator.d.ts +3 -0
  38. package/dist/src/multiValue/dataValidator.d.ts +3 -0
  39. package/dist/src/relationship/computedDataFn.d.ts +3 -0
  40. package/dist/src/relationship/contextObserverCallback.d.ts +3 -0
  41. package/dist/src/relationship/dataFormatterValidator.d.ts +3 -0
  42. package/dist/src/relationship/dataValidator.d.ts +3 -0
  43. package/dist/src/series/computedDataFn.d.ts +3 -0
  44. package/dist/src/series/contextObserverCallback.d.ts +3 -0
  45. package/dist/src/series/dataFormatterValidator.d.ts +3 -0
  46. package/dist/src/series/dataValidator.d.ts +3 -0
  47. package/dist/src/tree/computedDataFn.d.ts +3 -0
  48. package/dist/src/tree/contextObserverCallback.d.ts +3 -0
  49. package/dist/src/tree/dataFormatterValidator.d.ts +3 -0
  50. package/dist/src/tree/dataValidator.d.ts +3 -0
  51. package/dist/src/utils/commonUtils.d.ts +1 -0
  52. package/dist/src/utils/errorMessage.d.ts +14 -0
  53. package/dist/src/{grid → utils}/gridObservables.d.ts +2 -2
  54. package/dist/src/utils/index.d.ts +7 -3
  55. package/dist/src/{multiGrid → utils}/multiGridObservables.d.ts +1 -1
  56. package/dist/src/utils/observables.d.ts +2 -1
  57. package/dist/src/utils/orbchartsUtils.d.ts +1 -12
  58. package/dist/src/{series → utils}/seriesObservables.d.ts +3 -3
  59. package/dist/src/{tree → utils}/treeObservables.d.ts +1 -1
  60. package/dist/src/utils/validator.d.ts +3 -0
  61. package/lib/core-types.ts +7 -0
  62. package/package.json +42 -41
  63. package/src/AbstractChart.ts +57 -48
  64. package/src/GridChart.ts +24 -20
  65. package/src/MultiGridChart.ts +24 -20
  66. package/src/MultiValueChart.ts +24 -20
  67. package/src/RelationshipChart.ts +24 -20
  68. package/src/SeriesChart.ts +24 -20
  69. package/src/TreeChart.ts +24 -20
  70. package/src/base/createBaseChart.ts +500 -388
  71. package/src/base/createBasePlugin.ts +152 -95
  72. package/src/base/validators/chartOptionsValidator.ts +24 -0
  73. package/src/base/validators/chartParamsValidator.ts +134 -0
  74. package/src/base/validators/elementValidator.ts +14 -0
  75. package/src/base/validators/pluginsValidator.ts +15 -0
  76. package/src/defaults.ts +232 -228
  77. package/src/defineGridPlugin.ts +3 -3
  78. package/src/defineMultiGridPlugin.ts +3 -3
  79. package/src/defineMultiValuePlugin.ts +3 -3
  80. package/src/defineNoneDataPlugin.ts +4 -4
  81. package/src/defineRelationshipPlugin.ts +3 -3
  82. package/src/defineSeriesPlugin.ts +3 -3
  83. package/src/defineTreePlugin.ts +3 -3
  84. package/src/grid/{computeGridData.ts → computedDataFn.ts} +129 -134
  85. package/src/grid/{createGridContextObserver.ts → contextObserverCallback.ts} +155 -155
  86. package/src/grid/dataFormatterValidator.ts +102 -0
  87. package/src/grid/dataValidator.ts +13 -0
  88. package/src/index.ts +20 -21
  89. package/src/multiGrid/{computeMultiGridData.ts → computedDataFn.ts} +123 -130
  90. package/src/multiGrid/{createMultiGridContextObserver.ts → contextObserverCallback.ts} +41 -41
  91. package/src/multiGrid/dataFormatterValidator.ts +116 -0
  92. package/src/multiGrid/dataValidator.ts +13 -0
  93. package/src/multiValue/{computeMultiValueData.ts → computedDataFn.ts} +176 -179
  94. package/src/multiValue/{createMultiValueContextObserver.ts → contextObserverCallback.ts} +12 -12
  95. package/src/multiValue/dataFormatterValidator.ts +10 -0
  96. package/src/multiValue/dataValidator.ts +10 -0
  97. package/src/relationship/{computeRelationshipData.ts → computedDataFn.ts} +125 -118
  98. package/src/relationship/{createRelationshipContextObserver.ts → contextObserverCallback.ts} +12 -12
  99. package/src/relationship/dataFormatterValidator.ts +10 -0
  100. package/src/relationship/dataValidator.ts +10 -0
  101. package/src/series/{computeSeriesData.ts → computedDataFn.ts} +88 -90
  102. package/src/series/{createSeriesContextObserver.ts → contextObserverCallback.ts} +100 -93
  103. package/src/series/dataFormatterValidator.ts +42 -0
  104. package/src/series/dataValidator.ts +13 -0
  105. package/src/tree/{computeTreeData.ts → computedDataFn.ts} +130 -132
  106. package/src/tree/{createTreeContextObserver.ts → contextObserverCallback.ts} +61 -61
  107. package/src/tree/dataFormatterValidator.ts +14 -0
  108. package/src/tree/dataValidator.ts +14 -0
  109. package/src/utils/commonUtils.ts +54 -50
  110. package/src/utils/d3Utils.ts +108 -108
  111. package/src/utils/errorMessage.ts +43 -0
  112. package/src/{grid → utils}/gridObservables.ts +611 -614
  113. package/src/utils/index.ts +10 -4
  114. package/src/{multiGrid → utils}/multiGridObservables.ts +366 -365
  115. package/src/utils/observables.ts +219 -202
  116. package/src/utils/orbchartsUtils.ts +352 -349
  117. package/src/{series → utils}/seriesObservables.ts +175 -175
  118. package/src/{tree → utils}/treeObservables.ts +94 -94
  119. package/src/utils/validator.ts +126 -0
  120. package/tsconfig.base.json +13 -13
  121. package/tsconfig.json +2 -2
  122. package/vite-env.d.ts +7 -0
  123. package/vite.config.js +22 -22
  124. package/dist/src/grid/computeGridData.d.ts +0 -6
  125. package/dist/src/grid/createGridContextObserver.d.ts +0 -3
  126. package/dist/src/multiGrid/computeMultiGridData.d.ts +0 -3
  127. package/dist/src/multiGrid/createMultiGridContextObserver.d.ts +0 -3
  128. package/dist/src/multiValue/computeMultiValueData.d.ts +0 -3
  129. package/dist/src/multiValue/createMultiValueContextObserver.d.ts +0 -3
  130. package/dist/src/relationship/computeRelationshipData.d.ts +0 -3
  131. package/dist/src/relationship/createRelationshipContextObserver.d.ts +0 -3
  132. package/dist/src/series/computeSeriesData.d.ts +0 -3
  133. package/dist/src/series/createSeriesContextObserver.d.ts +0 -3
  134. package/dist/src/tree/computeTreeData.d.ts +0 -3
  135. package/dist/src/tree/createTreeContextObserver.d.ts +0 -3
  136. package/dist/src/types/Axis.d.ts +0 -1
  137. package/dist/src/types/Chart.d.ts +0 -45
  138. package/dist/src/types/ChartParams.d.ts +0 -36
  139. package/dist/src/types/ComputedData.d.ts +0 -42
  140. package/dist/src/types/ComputedDataGrid.d.ts +0 -5
  141. package/dist/src/types/ComputedDataMultiGrid.d.ts +0 -3
  142. package/dist/src/types/ComputedDataMultiValue.d.ts +0 -6
  143. package/dist/src/types/ComputedDataRelationship.d.ts +0 -18
  144. package/dist/src/types/ComputedDataSeries.d.ts +0 -5
  145. package/dist/src/types/ComputedDataTree.d.ts +0 -7
  146. package/dist/src/types/ContextObserver.d.ts +0 -28
  147. package/dist/src/types/ContextObserverGrid.d.ts +0 -41
  148. package/dist/src/types/ContextObserverMultiGrid.d.ts +0 -15
  149. package/dist/src/types/ContextObserverMultiValue.d.ts +0 -4
  150. package/dist/src/types/ContextObserverRelationship.d.ts +0 -4
  151. package/dist/src/types/ContextObserverSeries.d.ts +0 -27
  152. package/dist/src/types/ContextObserverTree.d.ts +0 -11
  153. package/dist/src/types/ContextSubject.d.ts +0 -15
  154. package/dist/src/types/Data.d.ts +0 -19
  155. package/dist/src/types/DataFormatter.d.ts +0 -41
  156. package/dist/src/types/DataFormatterGrid.d.ts +0 -34
  157. package/dist/src/types/DataFormatterMultiGrid.d.ts +0 -20
  158. package/dist/src/types/DataFormatterMultiValue.d.ts +0 -18
  159. package/dist/src/types/DataFormatterRelationship.d.ts +0 -10
  160. package/dist/src/types/DataFormatterSeries.d.ts +0 -19
  161. package/dist/src/types/DataFormatterTree.d.ts +0 -7
  162. package/dist/src/types/DataGrid.d.ts +0 -6
  163. package/dist/src/types/DataMultiGrid.d.ts +0 -6
  164. package/dist/src/types/DataMultiValue.d.ts +0 -7
  165. package/dist/src/types/DataRelationship.d.ts +0 -21
  166. package/dist/src/types/DataSeries.d.ts +0 -6
  167. package/dist/src/types/DataTree.d.ts +0 -15
  168. package/dist/src/types/Event.d.ts +0 -56
  169. package/dist/src/types/Layout.d.ts +0 -8
  170. package/dist/src/types/Padding.d.ts +0 -6
  171. package/dist/src/types/Plugin.d.ts +0 -37
  172. package/dist/src/types/TransformData.d.ts +0 -8
  173. package/dist/src/types/index.d.ts +0 -37
  174. package/src/types/Axis.ts +0 -1
  175. package/src/types/Chart.ts +0 -54
  176. package/src/types/ChartParams.ts +0 -51
  177. package/src/types/ComputedData.ts +0 -84
  178. package/src/types/ComputedDataGrid.ts +0 -14
  179. package/src/types/ComputedDataMultiGrid.ts +0 -3
  180. package/src/types/ComputedDataMultiValue.ts +0 -9
  181. package/src/types/ComputedDataRelationship.ts +0 -20
  182. package/src/types/ComputedDataSeries.ts +0 -8
  183. package/src/types/ComputedDataTree.ts +0 -20
  184. package/src/types/ContextObserver.ts +0 -38
  185. package/src/types/ContextObserverGrid.ts +0 -43
  186. package/src/types/ContextObserverMultiGrid.ts +0 -17
  187. package/src/types/ContextObserverMultiValue.ts +0 -5
  188. package/src/types/ContextObserverRelationship.ts +0 -5
  189. package/src/types/ContextObserverSeries.ts +0 -29
  190. package/src/types/ContextObserverTree.ts +0 -11
  191. package/src/types/ContextSubject.ts +0 -18
  192. package/src/types/Data.ts +0 -45
  193. package/src/types/DataFormatter.ts +0 -74
  194. package/src/types/DataFormatterGrid.ts +0 -68
  195. package/src/types/DataFormatterMultiGrid.ts +0 -45
  196. package/src/types/DataFormatterMultiValue.ts +0 -24
  197. package/src/types/DataFormatterRelationship.ts +0 -26
  198. package/src/types/DataFormatterSeries.ts +0 -20
  199. package/src/types/DataFormatterTree.ts +0 -12
  200. package/src/types/DataGrid.ts +0 -11
  201. package/src/types/DataMultiGrid.ts +0 -7
  202. package/src/types/DataMultiValue.ts +0 -12
  203. package/src/types/DataRelationship.ts +0 -28
  204. package/src/types/DataSeries.ts +0 -11
  205. package/src/types/DataTree.ts +0 -20
  206. package/src/types/Event.ts +0 -153
  207. package/src/types/Layout.ts +0 -12
  208. package/src/types/Padding.ts +0 -6
  209. package/src/types/Plugin.ts +0 -60
  210. package/src/types/TransformData.ts +0 -8
  211. package/src/types/index.ts +0 -37
  212. /package/dist/src/{multiValue → utils}/multiValueObservables.d.ts +0 -0
  213. /package/dist/src/{relationship → utils}/relationshipObservables.d.ts +0 -0
  214. /package/src/{multiValue → utils}/multiValueObservables.ts +0 -0
  215. /package/src/{relationship → utils}/relationshipObservables.ts +0 -0
@@ -1,93 +1,100 @@
1
- import { map, shareReplay } from 'rxjs'
2
- import type { ContextObserverFn } from '../types'
3
- import {
4
- seriesDataMapObservable,
5
- groupDataMapObservable } from '../utils/observables'
6
- import { highlightObservable, textSizePxObservable } from '../utils/observables'
7
-
8
- import { separateSeriesObservable, visibleComputedDataObservable, computedLayoutDataObservable, seriesLabelsObservable, seriesContainerPositionObservable, seriesContainerPositionMapObservable } from './seriesObservables'
9
-
10
- export const createSeriesContextObserver: ContextObserverFn<'series'> = ({ subject, observer }) => {
11
-
12
- const textSizePx$ = textSizePxObservable(observer.fullChartParams$).pipe(
13
- shareReplay(1)
14
- )
15
-
16
- const separateSeries$ = separateSeriesObservable({
17
- fullDataFormatter$: observer.fullDataFormatter$
18
- })
19
-
20
- const visibleComputedData$ = visibleComputedDataObservable({
21
- computedData$: observer.computedData$,
22
- })
23
-
24
- const computedLayoutData$ = computedLayoutDataObservable({
25
- computedData$: observer.computedData$,
26
- fullDataFormatter$: observer.fullDataFormatter$
27
- }).pipe(
28
- shareReplay(1)
29
- )
30
-
31
- const visibleComputedLayoutData$ = visibleComputedDataObservable({
32
- computedData$: computedLayoutData$,
33
- })
34
-
35
- const datumList$ = observer.computedData$.pipe(
36
- map(d => d.flat())
37
- ).pipe(
38
- shareReplay(1)
39
- )
40
-
41
- const seriesHighlight$ = highlightObservable({
42
- datumList$,
43
- fullChartParams$: observer.fullChartParams$,
44
- event$: subject.event$
45
- }).pipe(
46
- shareReplay(1)
47
- )
48
-
49
- const seriesLabels$ = seriesLabelsObservable({
50
- computedData$: observer.computedData$,
51
- })
52
-
53
-
54
- const SeriesDataMap$ = seriesDataMapObservable({
55
- datumList$
56
- }).pipe(
57
- shareReplay(1)
58
- )
59
-
60
- const seriesContainerPosition$ = seriesContainerPositionObservable({
61
- computedData$: observer.computedData$,
62
- fullDataFormatter$: observer.fullDataFormatter$,
63
- layout$: observer.layout$,
64
- }).pipe(
65
- shareReplay(1)
66
- )
67
-
68
- const SeriesContainerPositionMap$ = seriesContainerPositionMapObservable({
69
- seriesContainerPosition$: seriesContainerPosition$,
70
- seriesLabels$: seriesLabels$,
71
- separateSeries$: separateSeries$,
72
- }).pipe(
73
- shareReplay(1)
74
- )
75
-
76
- return {
77
- fullParams$: observer.fullParams$,
78
- fullChartParams$: observer.fullChartParams$,
79
- fullDataFormatter$: observer.fullDataFormatter$,
80
- computedData$: observer.computedData$,
81
- layout$: observer.layout$,
82
- textSizePx$,
83
- visibleComputedData$,
84
- visibleComputedLayoutData$,
85
- separateSeries$,
86
- computedLayoutData$,
87
- seriesHighlight$,
88
- seriesLabels$,
89
- SeriesDataMap$,
90
- seriesContainerPosition$,
91
- SeriesContainerPositionMap$,
92
- }
93
- }
1
+ import { map, shareReplay } from 'rxjs'
2
+ import type { ContextObserverCallback } from '../../lib/core-types'
3
+ import {
4
+ seriesDataMapObservable,
5
+ groupDataMapObservable } from '../utils/observables'
6
+ import { highlightObservable, textSizePxObservable } from '../utils/observables'
7
+
8
+ import {
9
+ separateSeriesObservable,
10
+ seriesVisibleComputedDataObservable,
11
+ seriesComputedLayoutDataObservable,
12
+ seriesLabelsObservable,
13
+ seriesContainerPositionObservable,
14
+ seriesContainerPositionMapObservable
15
+ } from '../utils/seriesObservables'
16
+
17
+ export const contextObserverCallback: ContextObserverCallback<'series'> = ({ subject, observer }) => {
18
+
19
+ const textSizePx$ = textSizePxObservable(observer.fullChartParams$).pipe(
20
+ shareReplay(1)
21
+ )
22
+
23
+ const separateSeries$ = separateSeriesObservable({
24
+ fullDataFormatter$: observer.fullDataFormatter$
25
+ })
26
+
27
+ const visibleComputedData$ = seriesVisibleComputedDataObservable({
28
+ computedData$: observer.computedData$,
29
+ })
30
+
31
+ const computedLayoutData$ = seriesComputedLayoutDataObservable({
32
+ computedData$: observer.computedData$,
33
+ fullDataFormatter$: observer.fullDataFormatter$
34
+ }).pipe(
35
+ shareReplay(1)
36
+ )
37
+
38
+ const visibleComputedLayoutData$ = seriesVisibleComputedDataObservable({
39
+ computedData$: computedLayoutData$,
40
+ })
41
+
42
+ const datumList$ = observer.computedData$.pipe(
43
+ map(d => d.flat())
44
+ ).pipe(
45
+ shareReplay(1)
46
+ )
47
+
48
+ const seriesHighlight$ = highlightObservable({
49
+ datumList$,
50
+ fullChartParams$: observer.fullChartParams$,
51
+ event$: subject.event$
52
+ }).pipe(
53
+ shareReplay(1)
54
+ )
55
+
56
+ const seriesLabels$ = seriesLabelsObservable({
57
+ computedData$: observer.computedData$,
58
+ })
59
+
60
+
61
+ const SeriesDataMap$ = seriesDataMapObservable({
62
+ datumList$
63
+ }).pipe(
64
+ shareReplay(1)
65
+ )
66
+
67
+ const seriesContainerPosition$ = seriesContainerPositionObservable({
68
+ computedData$: observer.computedData$,
69
+ fullDataFormatter$: observer.fullDataFormatter$,
70
+ layout$: observer.layout$,
71
+ }).pipe(
72
+ shareReplay(1)
73
+ )
74
+
75
+ const SeriesContainerPositionMap$ = seriesContainerPositionMapObservable({
76
+ seriesContainerPosition$: seriesContainerPosition$,
77
+ seriesLabels$: seriesLabels$,
78
+ separateSeries$: separateSeries$,
79
+ }).pipe(
80
+ shareReplay(1)
81
+ )
82
+
83
+ return {
84
+ fullParams$: observer.fullParams$,
85
+ fullChartParams$: observer.fullChartParams$,
86
+ fullDataFormatter$: observer.fullDataFormatter$,
87
+ computedData$: observer.computedData$,
88
+ layout$: observer.layout$,
89
+ textSizePx$,
90
+ visibleComputedData$,
91
+ visibleComputedLayoutData$,
92
+ separateSeries$,
93
+ computedLayoutData$,
94
+ seriesHighlight$,
95
+ seriesLabels$,
96
+ SeriesDataMap$,
97
+ seriesContainerPosition$,
98
+ SeriesContainerPositionMap$,
99
+ }
100
+ }
@@ -0,0 +1,42 @@
1
+ import type { DataFormatterValidator, DataFormatterTypeMap } from '../../lib/core-types'
2
+ import { validateColumns } from '../utils/validator'
3
+
4
+ export const dataFormatterValidator: DataFormatterValidator<'series'> = (dataFormatter: DataFormatterTypeMap<'series'>) => {
5
+ const result = validateColumns(dataFormatter, {
6
+ visibleFilter: {
7
+ toBeTypes: ['Function']
8
+ },
9
+ sort: {
10
+ toBeTypes: ['Function', 'null']
11
+ },
12
+ seriesLabels: {
13
+ toBeTypes: ['string[]']
14
+ },
15
+ container: {
16
+ toBeTypes: ['object']
17
+ },
18
+ separateSeries: {
19
+ toBeTypes: ['boolean']
20
+ },
21
+ sumSeries: {
22
+ toBeTypes: ['boolean']
23
+ }
24
+ })
25
+ if (dataFormatter.container) {
26
+ const containerResult = validateColumns(dataFormatter.container, {
27
+ gap: {
28
+ toBeTypes: ['number']
29
+ },
30
+ rowAmount: {
31
+ toBeTypes: ['number']
32
+ },
33
+ columnAmount: {
34
+ toBeTypes: ['number']
35
+ }
36
+ })
37
+ if (containerResult.status === 'error') {
38
+ return containerResult
39
+ }
40
+ }
41
+ return result
42
+ }
@@ -0,0 +1,13 @@
1
+ import type { DataValidator, DataTypeMap } from '../../lib/core-types'
2
+ import { validateColumns } from '../utils/validator'
3
+
4
+ export const dataValidator: DataValidator<'series'> = (data: DataTypeMap<'series'>) => {
5
+ const result = validateColumns({ data }, {
6
+ data: {
7
+ toBe: '(DataSeriesDatum | DataSeriesValue)[][] | (DataSeriesDatum | DataSeriesValue)[]',
8
+ // 畢免資料量過大檢查不完,不深度檢查
9
+ test: (value) => Array.isArray(value)
10
+ }
11
+ })
12
+ return result
13
+ }
@@ -1,132 +1,130 @@
1
- import type { DataTree, DataTreeObj, DataTreeDatum } from '../types/DataTree'
2
- import type { ComputedDataFn } from '../types/ComputedData'
3
- import type { ComputedDataTree } from '../types/ComputedDataTree'
4
- import { isPlainObject } from '../utils/commonUtils'
5
- import { seriesColorPredicate } from '../utils/orbchartsUtils'
6
-
7
- export const computeTreeData: ComputedDataFn<'tree'> = (context) => {
8
- const { data = [], dataFormatter, chartParams } = context
9
-
10
- // <categoryLabel, categoryIndex>
11
- const CategoryIndexMap = new Map<string, number>(
12
- dataFormatter.categoryLabels.map((label, index) => [label, index])
13
- )
14
-
15
- let computedBranchData: ComputedDataTree = {
16
- id: '',
17
- index: 0,
18
- label: '',
19
- description: '',
20
- categoryIndex: 0,
21
- categoryLabel: '',
22
- color: '',
23
- visible: true,
24
- // tooltipContent: '',
25
- data: {},
26
- value: 0,
27
- level: 0,
28
- seq: 0,
29
- children: []
30
- }
31
-
32
- try {
33
- // 建立樹狀結構資料
34
- const dataTreeObj: DataTreeObj = (function () {
35
- if (isPlainObject(data) === true) {
36
- // 原本就是樹狀結構則直接複製
37
- // return structuredClone(data) as DataTreeObj
38
- return JSON.parse(JSON.stringify(data)) as DataTreeObj
39
- } else if (Array.isArray(data) === false) {
40
- return {
41
- id: ''
42
- }
43
- }
44
- // -- 陣列格式轉物件 --
45
- // let rootId = ''
46
- let root: DataTreeDatum | undefined = undefined
47
- // const DataMap: Map<string, DataTreeDatum> = new Map()
48
- const ChildrenMap: Map<string, DataTreeDatum[]> = new Map()
49
- ;(data as DataTreeDatum[]).forEach(d => {
50
- // DataMap.set(d.id, d)
51
-
52
- if (!d.parent) {
53
- // rootId = d.id
54
- root = d
55
- } else {
56
- const children: DataTreeDatum[] = ChildrenMap.get(d.parent) ?? []
57
- children.push(d)
58
- ChildrenMap.set(d.parent!, children)
59
- }
60
- })
61
-
62
- const createBranchData = (root: DataTreeDatum): DataTreeObj => {
63
- return {
64
- id: root.id,
65
- label: root.label,
66
- data: root.data,
67
- // tooltipContent: root.tooltipContent,
68
- value: root.value,
69
- categoryLabel: root.categoryLabel,
70
- children: (ChildrenMap.get(root.id) ?? []).map(d => {
71
- // 遞迴
72
- return createBranchData(d)
73
- })
74
- }
75
- }
76
- if (root) {
77
- return createBranchData(root)
78
- } else {
79
- return {
80
- id: ''
81
- }
82
- }
83
- })()
84
-
85
- let index = 0
86
-
87
- const formatBranchData = (branch: DataTreeObj, level: number, seq: number): ComputedDataTree => {
88
- const childLayer = level + 1
89
- const categoryLabel: string | null = branch.categoryLabel ?? null
90
- let categoryIndex = 0
91
- if (categoryLabel != null) {
92
- if (!CategoryIndexMap.has(categoryLabel)) {
93
- CategoryIndexMap.set(categoryLabel, CategoryIndexMap.size)
94
- }
95
- categoryIndex = CategoryIndexMap.get(categoryLabel) ?? 0
96
- }
97
-
98
- const currentIndex = index
99
- index++
100
- const formattedBranchData: ComputedDataTree = {
101
- id: branch.id,
102
- index: currentIndex,
103
- level,
104
- seq,
105
- label: branch.label ?? '',
106
- description: branch.description ?? '',
107
- categoryIndex,
108
- categoryLabel,
109
- color: seriesColorPredicate(categoryIndex, chartParams),
110
- data: branch.data ?? {},
111
- // tooltipContent: branch.tooltipContent ? branch.tooltipContent : dataFormatter.tooltipContentFormat(branch, level, seq, context),
112
- value: branch.value,
113
- visible: true, // 先給預設值
114
- children: (branch.children ?? []).map((d, i) => {
115
- // 遞迴
116
- return formatBranchData(d, childLayer, i)
117
- })
118
- }
119
-
120
- formattedBranchData.visible = dataFormatter.visibleFilter(formattedBranchData, context)
121
-
122
- return formattedBranchData
123
- }
124
- computedBranchData = formatBranchData(dataTreeObj, 0, 0)
125
- } catch (e) {
126
- // console.error(e)
127
- throw Error(e)
128
- }
129
-
130
- return computedBranchData
131
-
132
- }
1
+ import type { DataTree, DataTreeObj, DataTreeDatum, ComputedDataFn, ComputedDataTree } from '../../lib/core-types'
2
+ import { isPlainObject } from '../utils/commonUtils'
3
+ import { seriesColorPredicate } from '../utils/orbchartsUtils'
4
+
5
+ export const computedDataFn: ComputedDataFn<'tree'> = (context) => {
6
+ const { data = [], dataFormatter, chartParams } = context
7
+
8
+ // <categoryLabel, categoryIndex>
9
+ const CategoryIndexMap = new Map<string, number>(
10
+ dataFormatter.categoryLabels.map((label, index) => [label, index])
11
+ )
12
+
13
+ let computedBranchData: ComputedDataTree = {
14
+ id: '',
15
+ index: 0,
16
+ label: '',
17
+ description: '',
18
+ categoryIndex: 0,
19
+ categoryLabel: '',
20
+ color: '',
21
+ visible: true,
22
+ // tooltipContent: '',
23
+ data: {},
24
+ value: 0,
25
+ level: 0,
26
+ seq: 0,
27
+ children: []
28
+ }
29
+
30
+ try {
31
+ // 建立樹狀結構資料
32
+ const dataTreeObj: DataTreeObj = (function () {
33
+ if (isPlainObject(data) === true) {
34
+ // 原本就是樹狀結構則直接複製
35
+ // return structuredClone(data) as DataTreeObj
36
+ return JSON.parse(JSON.stringify(data)) as DataTreeObj
37
+ } else if (Array.isArray(data) === false) {
38
+ return {
39
+ id: ''
40
+ }
41
+ }
42
+ // -- 陣列格式轉物件 --
43
+ // let rootId = ''
44
+ let root: DataTreeDatum | undefined = undefined
45
+ // const DataMap: Map<string, DataTreeDatum> = new Map()
46
+ const ChildrenMap: Map<string, DataTreeDatum[]> = new Map()
47
+ ;(data as DataTreeDatum[]).forEach(d => {
48
+ // DataMap.set(d.id, d)
49
+
50
+ if (!d.parent) {
51
+ // rootId = d.id
52
+ root = d
53
+ } else {
54
+ const children: DataTreeDatum[] = ChildrenMap.get(d.parent) ?? []
55
+ children.push(d)
56
+ ChildrenMap.set(d.parent!, children)
57
+ }
58
+ })
59
+
60
+ const createBranchData = (root: DataTreeDatum): DataTreeObj => {
61
+ return {
62
+ id: root.id,
63
+ label: root.label,
64
+ data: root.data,
65
+ // tooltipContent: root.tooltipContent,
66
+ value: root.value,
67
+ categoryLabel: root.categoryLabel,
68
+ children: (ChildrenMap.get(root.id) ?? []).map(d => {
69
+ // 遞迴
70
+ return createBranchData(d)
71
+ })
72
+ }
73
+ }
74
+ if (root) {
75
+ return createBranchData(root)
76
+ } else {
77
+ return {
78
+ id: ''
79
+ }
80
+ }
81
+ })()
82
+
83
+ let index = 0
84
+
85
+ const formatBranchData = (branch: DataTreeObj, level: number, seq: number): ComputedDataTree => {
86
+ const childLayer = level + 1
87
+ const categoryLabel: string | null = branch.categoryLabel ?? null
88
+ let categoryIndex = 0
89
+ if (categoryLabel != null) {
90
+ if (!CategoryIndexMap.has(categoryLabel)) {
91
+ CategoryIndexMap.set(categoryLabel, CategoryIndexMap.size)
92
+ }
93
+ categoryIndex = CategoryIndexMap.get(categoryLabel) ?? 0
94
+ }
95
+
96
+ const currentIndex = index
97
+ index++
98
+ const formattedBranchData: ComputedDataTree = {
99
+ id: branch.id,
100
+ index: currentIndex,
101
+ level,
102
+ seq,
103
+ label: branch.label ?? '',
104
+ description: branch.description ?? '',
105
+ categoryIndex,
106
+ categoryLabel,
107
+ color: seriesColorPredicate(categoryIndex, chartParams),
108
+ data: branch.data ?? {},
109
+ // tooltipContent: branch.tooltipContent ? branch.tooltipContent : dataFormatter.tooltipContentFormat(branch, level, seq, context),
110
+ value: branch.value,
111
+ visible: true, // 先給預設值
112
+ children: (branch.children ?? []).map((d, i) => {
113
+ // 遞迴
114
+ return formatBranchData(d, childLayer, i)
115
+ })
116
+ }
117
+
118
+ formattedBranchData.visible = dataFormatter.visibleFilter(formattedBranchData, context)
119
+
120
+ return formattedBranchData
121
+ }
122
+ computedBranchData = formatBranchData(dataTreeObj, 0, 0)
123
+ } catch (e) {
124
+ // console.error(e)
125
+ throw Error(e)
126
+ }
127
+
128
+ return computedBranchData
129
+
130
+ }
@@ -1,61 +1,61 @@
1
- import { map, shareReplay } from 'rxjs'
2
- import type { ContextObserverFn } from '../types'
3
- import { highlightObservable, categoryDataMapObservable, textSizePxObservable } from '../utils/observables'
4
- import {
5
- nodeListObservable,
6
- existCategoryLabelsObservable,
7
- treeVisibleComputedDataObservable
8
- } from './treeObservables'
9
-
10
- export const createTreeContextObserver: ContextObserverFn<'tree'> = ({ subject, observer }) => {
11
-
12
- const textSizePx$ = textSizePxObservable(observer.fullChartParams$).pipe(
13
- shareReplay(1)
14
- )
15
-
16
- const nodeList$ = nodeListObservable({
17
- computedData$: observer.computedData$
18
- }).pipe(
19
- shareReplay(1)
20
- )
21
-
22
- const treeHighlight$ = highlightObservable({
23
- datumList$: nodeList$,
24
- fullChartParams$: observer.fullChartParams$,
25
- event$: subject.event$
26
- }).pipe(
27
- shareReplay(1)
28
- )
29
-
30
- const existCategoryLabels$ = existCategoryLabelsObservable({
31
- nodeList$,
32
- fullDataFormatter$: observer.fullDataFormatter$
33
- }).pipe(
34
- shareReplay(1)
35
- )
36
-
37
- const CategoryDataMap$ = categoryDataMapObservable({
38
- datumList$: nodeList$
39
- }).pipe(
40
- shareReplay(1)
41
- )
42
-
43
- const visibleComputedData$ = treeVisibleComputedDataObservable({
44
- computedData$: observer.computedData$
45
- }).pipe(
46
- shareReplay(1)
47
- )
48
-
49
- return {
50
- fullParams$: observer.fullParams$,
51
- fullChartParams$: observer.fullChartParams$,
52
- fullDataFormatter$: observer.fullDataFormatter$,
53
- computedData$: observer.computedData$,
54
- layout$: observer.layout$,
55
- textSizePx$,
56
- treeHighlight$,
57
- existCategoryLabels$,
58
- CategoryDataMap$,
59
- visibleComputedData$
60
- }
61
- }
1
+ import { map, shareReplay } from 'rxjs'
2
+ import type { ContextObserverCallback } from '../../lib/core-types'
3
+ import { highlightObservable, categoryDataMapObservable, textSizePxObservable } from '../utils/observables'
4
+ import {
5
+ nodeListObservable,
6
+ existCategoryLabelsObservable,
7
+ treeVisibleComputedDataObservable
8
+ } from '../utils/treeObservables'
9
+
10
+ export const contextObserverCallback: ContextObserverCallback<'tree'> = ({ subject, observer }) => {
11
+
12
+ const textSizePx$ = textSizePxObservable(observer.fullChartParams$).pipe(
13
+ shareReplay(1)
14
+ )
15
+
16
+ const nodeList$ = nodeListObservable({
17
+ computedData$: observer.computedData$
18
+ }).pipe(
19
+ shareReplay(1)
20
+ )
21
+
22
+ const treeHighlight$ = highlightObservable({
23
+ datumList$: nodeList$,
24
+ fullChartParams$: observer.fullChartParams$,
25
+ event$: subject.event$
26
+ }).pipe(
27
+ shareReplay(1)
28
+ )
29
+
30
+ const existCategoryLabels$ = existCategoryLabelsObservable({
31
+ nodeList$,
32
+ fullDataFormatter$: observer.fullDataFormatter$
33
+ }).pipe(
34
+ shareReplay(1)
35
+ )
36
+
37
+ const CategoryDataMap$ = categoryDataMapObservable({
38
+ datumList$: nodeList$
39
+ }).pipe(
40
+ shareReplay(1)
41
+ )
42
+
43
+ const visibleComputedData$ = treeVisibleComputedDataObservable({
44
+ computedData$: observer.computedData$
45
+ }).pipe(
46
+ shareReplay(1)
47
+ )
48
+
49
+ return {
50
+ fullParams$: observer.fullParams$,
51
+ fullChartParams$: observer.fullChartParams$,
52
+ fullDataFormatter$: observer.fullDataFormatter$,
53
+ computedData$: observer.computedData$,
54
+ layout$: observer.layout$,
55
+ textSizePx$,
56
+ treeHighlight$,
57
+ existCategoryLabels$,
58
+ CategoryDataMap$,
59
+ visibleComputedData$
60
+ }
61
+ }
@@ -0,0 +1,14 @@
1
+ import type { DataFormatterValidator, DataFormatterTypeMap } from '../../lib/core-types'
2
+ import { validateColumns } from '../utils/validator'
3
+
4
+ export const dataFormatterValidator: DataFormatterValidator<'tree'> = (dataFormatter: DataFormatterTypeMap<'tree'>) => {
5
+ const result = validateColumns(dataFormatter, {
6
+ visibleFilter: {
7
+ toBeTypes: ['Function']
8
+ },
9
+ categoryLabels: {
10
+ toBeTypes: ['string[]']
11
+ }
12
+ })
13
+ return result
14
+ }