@orbcharts/core 3.0.0-beta.5 → 3.0.0-beta.7

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 (71) hide show
  1. package/LICENSE +200 -200
  2. package/dist/orbcharts-core.es.js +1481 -1412
  3. package/dist/orbcharts-core.umd.js +4 -4
  4. package/dist/src/defaults.d.ts +22 -22
  5. package/dist/src/utils/orbchartsUtils.d.ts +7 -7
  6. package/dist/src/utils/relationshipObservables.d.ts +13 -0
  7. package/lib/core-types.ts +7 -7
  8. package/package.json +42 -42
  9. package/src/AbstractChart.ts +57 -57
  10. package/src/GridChart.ts +24 -24
  11. package/src/MultiGridChart.ts +24 -24
  12. package/src/MultiValueChart.ts +24 -24
  13. package/src/RelationshipChart.ts +24 -24
  14. package/src/SeriesChart.ts +24 -24
  15. package/src/TreeChart.ts +24 -24
  16. package/src/base/createBaseChart.ts +505 -505
  17. package/src/base/createBasePlugin.ts +153 -153
  18. package/src/base/validators/chartOptionsValidator.ts +23 -23
  19. package/src/base/validators/chartParamsValidator.ts +133 -133
  20. package/src/base/validators/elementValidator.ts +13 -13
  21. package/src/base/validators/pluginsValidator.ts +14 -14
  22. package/src/defaults.ts +235 -235
  23. package/src/defineGridPlugin.ts +3 -3
  24. package/src/defineMultiGridPlugin.ts +3 -3
  25. package/src/defineMultiValuePlugin.ts +3 -3
  26. package/src/defineNoneDataPlugin.ts +4 -4
  27. package/src/defineRelationshipPlugin.ts +3 -3
  28. package/src/defineSeriesPlugin.ts +3 -3
  29. package/src/defineTreePlugin.ts +3 -3
  30. package/src/grid/computedDataFn.ts +129 -129
  31. package/src/grid/contextObserverCallback.ts +176 -176
  32. package/src/grid/dataFormatterValidator.ts +101 -101
  33. package/src/grid/dataValidator.ts +12 -12
  34. package/src/index.ts +20 -20
  35. package/src/multiGrid/computedDataFn.ts +123 -123
  36. package/src/multiGrid/contextObserverCallback.ts +41 -41
  37. package/src/multiGrid/dataFormatterValidator.ts +115 -115
  38. package/src/multiGrid/dataValidator.ts +12 -12
  39. package/src/multiValue/computedDataFn.ts +110 -110
  40. package/src/multiValue/contextObserverCallback.ts +160 -160
  41. package/src/multiValue/dataFormatterValidator.ts +9 -9
  42. package/src/multiValue/dataValidator.ts +9 -9
  43. package/src/relationship/computedDataFn.ts +144 -125
  44. package/src/relationship/contextObserverCallback.ts +80 -12
  45. package/src/relationship/dataFormatterValidator.ts +9 -9
  46. package/src/relationship/dataValidator.ts +9 -9
  47. package/src/series/computedDataFn.ts +88 -88
  48. package/src/series/contextObserverCallback.ts +100 -100
  49. package/src/series/dataFormatterValidator.ts +41 -41
  50. package/src/series/dataValidator.ts +12 -12
  51. package/src/tree/computedDataFn.ts +129 -129
  52. package/src/tree/contextObserverCallback.ts +58 -58
  53. package/src/tree/dataFormatterValidator.ts +13 -13
  54. package/src/tree/dataValidator.ts +13 -13
  55. package/src/utils/commonUtils.ts +55 -55
  56. package/src/utils/d3Scale.ts +198 -198
  57. package/src/utils/errorMessage.ts +42 -42
  58. package/src/utils/gridObservables.ts +683 -683
  59. package/src/utils/index.ts +9 -9
  60. package/src/utils/multiGridObservables.ts +392 -392
  61. package/src/utils/multiValueObservables.ts +661 -661
  62. package/src/utils/observables.ts +219 -219
  63. package/src/utils/orbchartsUtils.ts +377 -377
  64. package/src/utils/relationshipObservables.ts +85 -0
  65. package/src/utils/seriesObservables.ts +175 -175
  66. package/src/utils/treeObservables.ts +105 -105
  67. package/src/utils/validator.ts +126 -126
  68. package/tsconfig.base.json +13 -13
  69. package/tsconfig.json +2 -2
  70. package/vite-env.d.ts +6 -6
  71. package/vite.config.js +22 -22
@@ -1,160 +1,160 @@
1
- import { map, shareReplay, distinctUntilChanged } from 'rxjs'
2
- import type { ContextObserverCallback, ContextObserverTypeMap } from '../../lib/core-types'
3
- import {
4
- highlightObservable,
5
- categoryDataMapObservable,
6
- textSizePxObservable
7
- } from '../utils/observables'
8
- import {
9
- multiValueComputedLayoutDataObservable,
10
- // multiValueAxesTransformObservable,
11
- // multiValueAxesReverseTransformObservable,
12
- multiValueGraphicTransformObservable,
13
- multiValueGraphicReverseScaleObservable,
14
- multiValueCategoryLabelsObservable,
15
- multiValueVisibleComputedDataObservable,
16
- multiValueVisibleComputedLayoutDataObservable,
17
- multiValueContainerPositionObservable,
18
- minMaxXYObservable,
19
- filteredMinMaxXYDataObservable
20
- } from '../utils/multiValueObservables'
21
-
22
- export const contextObserverCallback: ContextObserverCallback<'multiValue'> = ({ subject, observer }) => {
23
-
24
- const textSizePx$ = textSizePxObservable(observer.fullChartParams$).pipe(
25
- shareReplay(1)
26
- )
27
-
28
- const isCategorySeprate$ = observer.fullDataFormatter$.pipe(
29
- map(d => d.separateCategory),
30
- distinctUntilChanged(),
31
- shareReplay(1)
32
- )
33
-
34
- const multiValueContainerPosition$ = multiValueContainerPositionObservable({
35
- computedData$: observer.computedData$,
36
- fullDataFormatter$: observer.fullDataFormatter$,
37
- layout$: observer.layout$,
38
- })
39
-
40
- // const multiValueAxesSize$ = multiValueAxesSizeObservable({
41
- // fullDataFormatter$: observer.fullDataFormatter$,
42
- // layout$: observer.layout$
43
- // }).pipe(
44
- // shareReplay(1)
45
- // )
46
-
47
- const datumList$ = observer.computedData$.pipe(
48
- map(d => d.flat().flat())
49
- ).pipe(
50
- shareReplay(1)
51
- )
52
-
53
- const multiValueHighlight$ = highlightObservable({
54
- datumList$,
55
- fullChartParams$: observer.fullChartParams$,
56
- event$: subject.event$
57
- }).pipe(
58
- shareReplay(1)
59
- )
60
-
61
- const categoryLabels$ = multiValueCategoryLabelsObservable({
62
- computedData$: observer.computedData$,
63
- fullDataFormatter$: observer.fullDataFormatter$,
64
- })
65
-
66
- const CategoryDataMap$ = categoryDataMapObservable({
67
- datumList$: datumList$
68
- }).pipe(
69
- shareReplay(1)
70
- )
71
-
72
- const minMaxXY$ = minMaxXYObservable({
73
- computedData$: observer.computedData$
74
- }).pipe(
75
- shareReplay(1)
76
- )
77
-
78
-
79
- const computedLayoutData$ = multiValueComputedLayoutDataObservable({
80
- computedData$: observer.computedData$,
81
- minMaxXY$,
82
- fullDataFormatter$: observer.fullDataFormatter$,
83
- layout$: observer.layout$,
84
- }).pipe(
85
- shareReplay(1)
86
- )
87
-
88
- const visibleComputedData$ = multiValueVisibleComputedDataObservable({
89
- computedData$: observer.computedData$,
90
- }).pipe(
91
- shareReplay(1)
92
- )
93
-
94
- const visibleComputedLayoutData$ = multiValueVisibleComputedLayoutDataObservable({
95
- computedLayoutData$: computedLayoutData$,
96
- }).pipe(
97
- shareReplay(1)
98
- )
99
-
100
- const filteredMinMaxXYData$ = filteredMinMaxXYDataObservable({
101
- visibleComputedLayoutData$: visibleComputedLayoutData$,
102
- minMaxXY$,
103
- fullDataFormatter$: observer.fullDataFormatter$,
104
- }).pipe(
105
- shareReplay(1)
106
- )
107
-
108
- // const multiValueAxesTransform$ = multiValueAxesTransformObservable({
109
- // fullDataFormatter$: observer.fullDataFormatter$,
110
- // layout$: observer.layout$
111
- // }).pipe(
112
- // shareReplay(1)
113
- // )
114
-
115
- // const multiValueAxesReverseTransform$ = multiValueAxesReverseTransformObservable({
116
- // multiValueAxesTransform$
117
- // }).pipe(
118
- // shareReplay(1)
119
- // )
120
-
121
- const multiValueGraphicTransform$ = multiValueGraphicTransformObservable({
122
- minMaxXY$,
123
- filteredMinMaxXYData$,
124
- fullDataFormatter$: observer.fullDataFormatter$,
125
- layout$: observer.layout$
126
- }).pipe(
127
- shareReplay(1)
128
- )
129
-
130
- const multiValueGraphicReverseScale$ = multiValueGraphicReverseScaleObservable({
131
- multiValueContainerPosition$: multiValueContainerPosition$,
132
- // multiValueAxesTransform$: multiValueAxesTransform$,
133
- multiValueGraphicTransform$: multiValueGraphicTransform$,
134
- })
135
-
136
-
137
- return <ContextObserverTypeMap<'multiValue', any>>{
138
- fullParams$: observer.fullParams$,
139
- fullChartParams$: observer.fullChartParams$,
140
- fullDataFormatter$: observer.fullDataFormatter$,
141
- computedData$: observer.computedData$,
142
- layout$: observer.layout$,
143
- textSizePx$,
144
- isCategorySeprate$,
145
- multiValueContainerPosition$,
146
- // multiValueAxesSize$,
147
- multiValueHighlight$,
148
- categoryLabels$,
149
- CategoryDataMap$,
150
- minMaxXY$,
151
- computedLayoutData$,
152
- visibleComputedData$,
153
- visibleComputedLayoutData$,
154
- filteredMinMaxXYData$,
155
- // multiValueAxesTransform$,
156
- // multiValueAxesReverseTransform$,
157
- multiValueGraphicTransform$,
158
- multiValueGraphicReverseScale$,
159
- }
160
- }
1
+ import { map, shareReplay, distinctUntilChanged } from 'rxjs'
2
+ import type { ContextObserverCallback, ContextObserverTypeMap } from '../../lib/core-types'
3
+ import {
4
+ highlightObservable,
5
+ categoryDataMapObservable,
6
+ textSizePxObservable
7
+ } from '../utils/observables'
8
+ import {
9
+ multiValueComputedLayoutDataObservable,
10
+ // multiValueAxesTransformObservable,
11
+ // multiValueAxesReverseTransformObservable,
12
+ multiValueGraphicTransformObservable,
13
+ multiValueGraphicReverseScaleObservable,
14
+ multiValueCategoryLabelsObservable,
15
+ multiValueVisibleComputedDataObservable,
16
+ multiValueVisibleComputedLayoutDataObservable,
17
+ multiValueContainerPositionObservable,
18
+ minMaxXYObservable,
19
+ filteredMinMaxXYDataObservable
20
+ } from '../utils/multiValueObservables'
21
+
22
+ export const contextObserverCallback: ContextObserverCallback<'multiValue'> = ({ subject, observer }) => {
23
+
24
+ const textSizePx$ = textSizePxObservable(observer.fullChartParams$).pipe(
25
+ shareReplay(1)
26
+ )
27
+
28
+ const isCategorySeprate$ = observer.fullDataFormatter$.pipe(
29
+ map(d => d.separateCategory),
30
+ distinctUntilChanged(),
31
+ shareReplay(1)
32
+ )
33
+
34
+ const multiValueContainerPosition$ = multiValueContainerPositionObservable({
35
+ computedData$: observer.computedData$,
36
+ fullDataFormatter$: observer.fullDataFormatter$,
37
+ layout$: observer.layout$,
38
+ })
39
+
40
+ // const multiValueAxesSize$ = multiValueAxesSizeObservable({
41
+ // fullDataFormatter$: observer.fullDataFormatter$,
42
+ // layout$: observer.layout$
43
+ // }).pipe(
44
+ // shareReplay(1)
45
+ // )
46
+
47
+ const datumList$ = observer.computedData$.pipe(
48
+ map(d => d.flat().flat())
49
+ ).pipe(
50
+ shareReplay(1)
51
+ )
52
+
53
+ const multiValueHighlight$ = highlightObservable({
54
+ datumList$,
55
+ fullChartParams$: observer.fullChartParams$,
56
+ event$: subject.event$
57
+ }).pipe(
58
+ shareReplay(1)
59
+ )
60
+
61
+ const categoryLabels$ = multiValueCategoryLabelsObservable({
62
+ computedData$: observer.computedData$,
63
+ fullDataFormatter$: observer.fullDataFormatter$,
64
+ })
65
+
66
+ const CategoryDataMap$ = categoryDataMapObservable({
67
+ datumList$: datumList$
68
+ }).pipe(
69
+ shareReplay(1)
70
+ )
71
+
72
+ const minMaxXY$ = minMaxXYObservable({
73
+ computedData$: observer.computedData$
74
+ }).pipe(
75
+ shareReplay(1)
76
+ )
77
+
78
+
79
+ const computedLayoutData$ = multiValueComputedLayoutDataObservable({
80
+ computedData$: observer.computedData$,
81
+ minMaxXY$,
82
+ fullDataFormatter$: observer.fullDataFormatter$,
83
+ layout$: observer.layout$,
84
+ }).pipe(
85
+ shareReplay(1)
86
+ )
87
+
88
+ const visibleComputedData$ = multiValueVisibleComputedDataObservable({
89
+ computedData$: observer.computedData$,
90
+ }).pipe(
91
+ shareReplay(1)
92
+ )
93
+
94
+ const visibleComputedLayoutData$ = multiValueVisibleComputedLayoutDataObservable({
95
+ computedLayoutData$: computedLayoutData$,
96
+ }).pipe(
97
+ shareReplay(1)
98
+ )
99
+
100
+ const filteredMinMaxXYData$ = filteredMinMaxXYDataObservable({
101
+ visibleComputedLayoutData$: visibleComputedLayoutData$,
102
+ minMaxXY$,
103
+ fullDataFormatter$: observer.fullDataFormatter$,
104
+ }).pipe(
105
+ shareReplay(1)
106
+ )
107
+
108
+ // const multiValueAxesTransform$ = multiValueAxesTransformObservable({
109
+ // fullDataFormatter$: observer.fullDataFormatter$,
110
+ // layout$: observer.layout$
111
+ // }).pipe(
112
+ // shareReplay(1)
113
+ // )
114
+
115
+ // const multiValueAxesReverseTransform$ = multiValueAxesReverseTransformObservable({
116
+ // multiValueAxesTransform$
117
+ // }).pipe(
118
+ // shareReplay(1)
119
+ // )
120
+
121
+ const multiValueGraphicTransform$ = multiValueGraphicTransformObservable({
122
+ minMaxXY$,
123
+ filteredMinMaxXYData$,
124
+ fullDataFormatter$: observer.fullDataFormatter$,
125
+ layout$: observer.layout$
126
+ }).pipe(
127
+ shareReplay(1)
128
+ )
129
+
130
+ const multiValueGraphicReverseScale$ = multiValueGraphicReverseScaleObservable({
131
+ multiValueContainerPosition$: multiValueContainerPosition$,
132
+ // multiValueAxesTransform$: multiValueAxesTransform$,
133
+ multiValueGraphicTransform$: multiValueGraphicTransform$,
134
+ })
135
+
136
+
137
+ return <ContextObserverTypeMap<'multiValue', any>>{
138
+ fullParams$: observer.fullParams$,
139
+ fullChartParams$: observer.fullChartParams$,
140
+ fullDataFormatter$: observer.fullDataFormatter$,
141
+ computedData$: observer.computedData$,
142
+ layout$: observer.layout$,
143
+ textSizePx$,
144
+ isCategorySeprate$,
145
+ multiValueContainerPosition$,
146
+ // multiValueAxesSize$,
147
+ multiValueHighlight$,
148
+ categoryLabels$,
149
+ CategoryDataMap$,
150
+ minMaxXY$,
151
+ computedLayoutData$,
152
+ visibleComputedData$,
153
+ visibleComputedLayoutData$,
154
+ filteredMinMaxXYData$,
155
+ // multiValueAxesTransform$,
156
+ // multiValueAxesReverseTransform$,
157
+ multiValueGraphicTransform$,
158
+ multiValueGraphicReverseScale$,
159
+ }
160
+ }
@@ -1,10 +1,10 @@
1
- import type { DataFormatterValidator, DataFormatterTypeMap } from '../../lib/core-types'
2
-
3
- export const dataFormatterValidator: DataFormatterValidator<'multiValue'> = (dataFormatter: DataFormatterTypeMap<'multiValue'>) => {
4
-
5
- return {
6
- status: 'success',
7
- columnName: '',
8
- expectToBe: ''
9
- }
1
+ import type { DataFormatterValidator, DataFormatterTypeMap } from '../../lib/core-types'
2
+
3
+ export const dataFormatterValidator: DataFormatterValidator<'multiValue'> = (dataFormatter: DataFormatterTypeMap<'multiValue'>) => {
4
+
5
+ return {
6
+ status: 'success',
7
+ columnName: '',
8
+ expectToBe: ''
9
+ }
10
10
  }
@@ -1,10 +1,10 @@
1
- import type { DataValidator, DataTypeMap } from '../../lib/core-types'
2
-
3
- export const dataValidator: DataValidator<'multiValue'> = (data: DataTypeMap<'multiValue'>) => {
4
-
5
- return {
6
- status: 'success',
7
- columnName: '',
8
- expectToBe: ''
9
- }
1
+ import type { DataValidator, DataTypeMap } from '../../lib/core-types'
2
+
3
+ export const dataValidator: DataValidator<'multiValue'> = (data: DataTypeMap<'multiValue'>) => {
4
+
5
+ return {
6
+ status: 'success',
7
+ columnName: '',
8
+ expectToBe: ''
9
+ }
10
10
  }
@@ -1,125 +1,144 @@
1
- import type {
2
- DataRelationshipObj,
3
- DataRelationshipList,
4
- Node,
5
- Edge,
6
- ComputedDataFn,
7
- ComputedDataRelationship,
8
- ComputedNode,
9
- ComputedEdge
10
- } from '../../lib/core-types'
11
-
12
- export const computedDataFn: ComputedDataFn<'relationship'> = (context) => {
13
- const { data, dataFormatter, chartParams } = context
14
-
15
- let computedNodes: ComputedNode[] = []
16
- let computedEdges: ComputedEdge[] = []
17
-
18
- try {
19
- // -- 取得nodes和edges資料 --
20
- let nodes: Node[] = []
21
- let edges: Edge[] = []
22
- if ((data as DataRelationshipObj).nodes) {
23
- nodes = (data as DataRelationshipObj).nodes
24
- edges = (data as DataRelationshipObj).edges
25
- } else if ((data as DataRelationshipList)[0]) {
26
- nodes = (data as DataRelationshipList)[0]
27
- edges = (data as DataRelationshipList)[1]
28
- } else {
29
- // 無值直接回傳
30
- return {
31
- nodes: [],
32
- edges: []
33
- } as ComputedDataRelationship
34
- }
35
-
36
- // -- nodes --
37
- computedNodes = nodes.map((node, i) => {
38
- const computedNode: ComputedNode = {
39
- id: node.id,
40
- index: i,
41
- label: node.label ?? '',
42
- description: node.description ?? '',
43
- // tooltipContent: node.tooltipContent ? node.tooltipContent : dataFormatter.tooltipContentFormat(node, 0, i, context), // 0代表node
44
- data: node.data ?? {},
45
- value: node.value ?? 0,
46
- categoryIndex: 0, // @Q@ 未完成
47
- categoryLabel: '', // @Q@ 未完成
48
- color: '', // @Q@ 未完成
49
- startNodes: [], // 後面再取得資料
50
- startNodeIds: [], // 後面再取得資料
51
- endNodes: [], // 後面再取得資料
52
- endNodeIds: [], // 後面再取得資料
53
- visible: true // 後面再取得資料
54
- }
55
- return computedNode
56
- })
57
-
58
- const NodesMap: Map<string, ComputedNode> = new Map(computedNodes.map(d => [d.id, d]))
59
-
60
- // -- edges --
61
- computedEdges = edges.map((edge, i) => {
62
- const computedEdge: ComputedEdge = {
63
- id: edge.id,
64
- index: i,
65
- label: edge.label ?? '',
66
- description: edge.description ?? '',
67
- // tooltipContent: edge.tooltipContent ? edge.tooltipContent : dataFormatter.tooltipContentFormat(edge, 1, i, context), // 1代表edge
68
- data: edge.data ?? {},
69
- // value: edge.value ?? 0,
70
- startNode: NodesMap.get(edge.start),
71
- startNodeId: edge.start,
72
- endNode: NodesMap.get(edge.end),
73
- endNodeId: edge.end,
74
- visible: true // 先給預設值
75
- }
76
-
77
- return computedEdge
78
- })
79
-
80
- const StartNodesMap: Map<string, ComputedNode[]> = (function () {
81
- const _StartNodesMap = new Map()
82
- computedEdges.forEach(edge => {
83
- const startNodes: ComputedNode[] = _StartNodesMap.get(edge.endNodeId) ?? []
84
- startNodes.push(edge.startNode)
85
- _StartNodesMap.set(edge.endNodeId, startNodes)
86
- })
87
- return _StartNodesMap
88
- })()
89
-
90
- const EndNodesMap: Map<string, ComputedNode[]> = (function () {
91
- const _EndNodesMap = new Map()
92
- computedEdges.forEach(edge => {
93
- const endNodes: ComputedNode[] = _EndNodesMap.get(edge.startNodeId) ?? []
94
- endNodes.push(edge.endNode)
95
- _EndNodesMap.set(edge.startNodeId, endNodes)
96
- })
97
- return _EndNodesMap
98
- })()
99
-
100
- // -- 補齊nodes資料 --
101
- Array.from(NodesMap).forEach(([nodeId, node]) => {
102
- node.startNodes = StartNodesMap.get(nodeId)
103
- node.startNodeIds = node.startNodes.map(d => d.id)
104
- node.endNodes = EndNodesMap.get(nodeId)
105
- node.endNodeIds = node.endNodes.map(d => d.id)
106
- node.visible = dataFormatter.visibleFilter(node, context)
107
- })
108
-
109
- // -- 補齊edges資料 --
110
- computedEdges = computedEdges.map(edge => {
111
- edge.visible = edge.startNode.visible && edge.endNode.visible
112
- ? true
113
- : false
114
- return edge
115
- })
116
- } catch (e) {
117
- // console.error(e)
118
- throw Error(e)
119
- }
120
-
121
- return {
122
- nodes: computedNodes,
123
- edges: computedEdges
124
- }
125
- }
1
+ import type {
2
+ DataRelationshipObj,
3
+ DataRelationshipList,
4
+ Node,
5
+ Edge,
6
+ ComputedDataFn,
7
+ ComputedDataRelationship,
8
+ ComputedNode,
9
+ ComputedEdge
10
+ } from '../../lib/core-types'
11
+ import { createDefaultCategoryLabel, seriesColorPredicate } from '../utils/orbchartsUtils'
12
+
13
+ export const computedDataFn: ComputedDataFn<'relationship'> = (context) => {
14
+ const { data, dataFormatter, chartParams } = context
15
+
16
+ const defaultCategoryLabel = createDefaultCategoryLabel()
17
+
18
+ let computedNodes: ComputedNode[] = []
19
+ let computedEdges: ComputedEdge[] = []
20
+
21
+ try {
22
+ // -- 取得nodes和edges資料 --
23
+ let nodes: Node[] = []
24
+ let edges: Edge[] = []
25
+ if ((data as DataRelationshipObj).nodes) {
26
+ nodes = (data as DataRelationshipObj).nodes
27
+ edges = (data as DataRelationshipObj).edges
28
+ } else if ((data as DataRelationshipList)[0]) {
29
+ nodes = (data as DataRelationshipList)[0]
30
+ edges = (data as DataRelationshipList)[1]
31
+ } else {
32
+ // 無值直接回傳
33
+ return {
34
+ nodes: [],
35
+ edges: []
36
+ } as ComputedDataRelationship
37
+ }
38
+
39
+ const categoryLabels = (() => {
40
+ // 先使用 dataFormatter.categoryLabels
41
+ const CategoryLabelsSet = new Set(dataFormatter.categoryLabels)
42
+ // 再加入 datum 中的 categoryLabel
43
+ for (let datum of nodes) {
44
+ const categoryLabel = datum.categoryLabel ?? defaultCategoryLabel
45
+ CategoryLabelsSet.add(categoryLabel) // 不重覆
46
+ }
47
+ for (let datum of edges) {
48
+ const categoryLabel = datum.categoryLabel ?? defaultCategoryLabel
49
+ CategoryLabelsSet.add(categoryLabel) // 不重覆
50
+ }
51
+ return Array.from(CategoryLabelsSet)
52
+ })()
53
+
54
+ // <categoryLabel, categoryIndex>
55
+ const CategoryIndexMap = new Map<string, number>(
56
+ categoryLabels.map((label, index) => [label, index])
57
+ )
58
+
59
+ // -- nodes --
60
+ computedNodes = nodes.map((node, i) => {
61
+ const categoryLabel = node.categoryLabel ?? defaultCategoryLabel
62
+ const categoryIndex = CategoryIndexMap.get(categoryLabel) ?? 0
63
+
64
+ const computedNode: ComputedNode = {
65
+ id: node.id,
66
+ index: i,
67
+ label: node.label ?? '',
68
+ description: node.description ?? '',
69
+ data: node.data ?? {},
70
+ value: node.value ?? 0,
71
+ categoryIndex,
72
+ categoryLabel,
73
+ color: seriesColorPredicate(categoryIndex, chartParams),
74
+ // startNodes: [], // 後面再取得資料
75
+ // startNodeIds: [], // 後面再取得資料
76
+ // endNodes: [], // 後面再取得資料
77
+ // endNodeIds: [], // 後面再取得資料
78
+ visible: true // 先給預設值
79
+ }
80
+
81
+ computedNode.visible = dataFormatter.visibleFilter(computedNode, context)
82
+
83
+ return computedNode
84
+ })
85
+
86
+ const NodesMap: Map<string, ComputedNode> = new Map(computedNodes.map(d => [d.id, d]))
87
+
88
+ // const StartNodesMap: Map<string, ComputedNode[]> = (function () {
89
+ // const _StartNodesMap = new Map()
90
+ // computedEdges.forEach(edge => {
91
+ // const startNodes: ComputedNode[] = _StartNodesMap.get(edge.endNodeId) ?? []
92
+ // startNodes.push(edge.startNode)
93
+ // _StartNodesMap.set(edge.endNodeId, startNodes)
94
+ // })
95
+ // return _StartNodesMap
96
+ // })()
97
+
98
+ // const EndNodesMap: Map<string, ComputedNode[]> = (function () {
99
+ // const _EndNodesMap = new Map()
100
+ // computedEdges.forEach(edge => {
101
+ // const endNodes: ComputedNode[] = _EndNodesMap.get(edge.startNodeId) ?? []
102
+ // endNodes.push(edge.endNode)
103
+ // _EndNodesMap.set(edge.startNodeId, endNodes)
104
+ // })
105
+ // return _EndNodesMap
106
+ // })()
107
+
108
+ // -- edges --
109
+ computedEdges = edges.map((edge, i) => {
110
+ const categoryLabel = edge.categoryLabel ?? defaultCategoryLabel
111
+ const startNode = NodesMap.get(edge.start)
112
+ const endNode = NodesMap.get(edge.end)
113
+
114
+ const computedEdge: ComputedEdge = {
115
+ id: edge.id,
116
+ index: i,
117
+ label: edge.label ?? '',
118
+ description: edge.description ?? '',
119
+ data: edge.data ?? {},
120
+ value: edge.value ?? 0,
121
+ categoryIndex: CategoryIndexMap.get(categoryLabel),
122
+ categoryLabel,
123
+ color: seriesColorPredicate(i, chartParams),
124
+ startNode,
125
+ // startNodeId: edge.start,
126
+ endNode,
127
+ // endNodeId: edge.end,
128
+ visible: startNode.visible && endNode.visible
129
+ }
130
+
131
+ return computedEdge
132
+ })
133
+
134
+
135
+ } catch (e) {
136
+ // console.error(e)
137
+ throw Error(e)
138
+ }
139
+
140
+ return {
141
+ nodes: computedNodes,
142
+ edges: computedEdges
143
+ }
144
+ }