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

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 (67) hide show
  1. package/LICENSE +200 -200
  2. package/dist/orbcharts-core.es.js +167 -163
  3. package/dist/orbcharts-core.umd.js +3 -3
  4. package/lib/core-types.ts +7 -7
  5. package/package.json +42 -42
  6. package/src/AbstractChart.ts +57 -57
  7. package/src/GridChart.ts +24 -24
  8. package/src/MultiGridChart.ts +24 -24
  9. package/src/MultiValueChart.ts +24 -24
  10. package/src/RelationshipChart.ts +24 -24
  11. package/src/SeriesChart.ts +24 -24
  12. package/src/TreeChart.ts +24 -24
  13. package/src/base/createBaseChart.ts +505 -505
  14. package/src/base/createBasePlugin.ts +153 -153
  15. package/src/base/validators/chartOptionsValidator.ts +23 -23
  16. package/src/base/validators/chartParamsValidator.ts +133 -133
  17. package/src/base/validators/elementValidator.ts +13 -13
  18. package/src/base/validators/pluginsValidator.ts +14 -14
  19. package/src/defaults.ts +235 -235
  20. package/src/defineGridPlugin.ts +3 -3
  21. package/src/defineMultiGridPlugin.ts +3 -3
  22. package/src/defineMultiValuePlugin.ts +3 -3
  23. package/src/defineNoneDataPlugin.ts +4 -4
  24. package/src/defineRelationshipPlugin.ts +3 -3
  25. package/src/defineSeriesPlugin.ts +3 -3
  26. package/src/defineTreePlugin.ts +3 -3
  27. package/src/grid/computedDataFn.ts +129 -129
  28. package/src/grid/contextObserverCallback.ts +176 -176
  29. package/src/grid/dataFormatterValidator.ts +101 -101
  30. package/src/grid/dataValidator.ts +12 -12
  31. package/src/index.ts +20 -20
  32. package/src/multiGrid/computedDataFn.ts +123 -123
  33. package/src/multiGrid/contextObserverCallback.ts +41 -41
  34. package/src/multiGrid/dataFormatterValidator.ts +115 -115
  35. package/src/multiGrid/dataValidator.ts +12 -12
  36. package/src/multiValue/computedDataFn.ts +110 -110
  37. package/src/multiValue/contextObserverCallback.ts +160 -160
  38. package/src/multiValue/dataFormatterValidator.ts +9 -9
  39. package/src/multiValue/dataValidator.ts +9 -9
  40. package/src/relationship/computedDataFn.ts +125 -125
  41. package/src/relationship/contextObserverCallback.ts +12 -12
  42. package/src/relationship/dataFormatterValidator.ts +9 -9
  43. package/src/relationship/dataValidator.ts +9 -9
  44. package/src/series/computedDataFn.ts +88 -88
  45. package/src/series/contextObserverCallback.ts +100 -100
  46. package/src/series/dataFormatterValidator.ts +41 -41
  47. package/src/series/dataValidator.ts +12 -12
  48. package/src/tree/computedDataFn.ts +129 -129
  49. package/src/tree/contextObserverCallback.ts +58 -58
  50. package/src/tree/dataFormatterValidator.ts +13 -13
  51. package/src/tree/dataValidator.ts +13 -13
  52. package/src/utils/commonUtils.ts +55 -55
  53. package/src/utils/d3Scale.ts +198 -198
  54. package/src/utils/errorMessage.ts +42 -42
  55. package/src/utils/gridObservables.ts +683 -671
  56. package/src/utils/index.ts +9 -9
  57. package/src/utils/multiGridObservables.ts +392 -392
  58. package/src/utils/multiValueObservables.ts +661 -642
  59. package/src/utils/observables.ts +219 -219
  60. package/src/utils/orbchartsUtils.ts +377 -377
  61. package/src/utils/seriesObservables.ts +175 -175
  62. package/src/utils/treeObservables.ts +105 -105
  63. package/src/utils/validator.ts +126 -126
  64. package/tsconfig.base.json +13 -13
  65. package/tsconfig.json +2 -2
  66. package/vite-env.d.ts +6 -6
  67. 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,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
-
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
+
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,12 +1,12 @@
1
- import type { ContextObserverCallback } from '../../lib/core-types'
2
-
3
- export const contextObserverCallback: ContextObserverCallback<'relationship'> = ({ subject, observer }) => {
4
-
5
- return {
6
- fullParams$: observer.fullParams$,
7
- fullChartParams$: observer.fullChartParams$,
8
- fullDataFormatter$: observer.fullDataFormatter$,
9
- computedData$: observer.computedData$,
10
- layout$: observer.layout$,
11
- }
12
- }
1
+ import type { ContextObserverCallback } from '../../lib/core-types'
2
+
3
+ export const contextObserverCallback: ContextObserverCallback<'relationship'> = ({ subject, observer }) => {
4
+
5
+ return {
6
+ fullParams$: observer.fullParams$,
7
+ fullChartParams$: observer.fullChartParams$,
8
+ fullDataFormatter$: observer.fullDataFormatter$,
9
+ computedData$: observer.computedData$,
10
+ layout$: observer.layout$,
11
+ }
12
+ }
@@ -1,10 +1,10 @@
1
- import type { DataFormatterValidator, DataFormatterTypeMap } from '../../lib/core-types'
2
-
3
- export const dataFormatterValidator: DataFormatterValidator<'relationship'> = (dataFormatter: DataFormatterTypeMap<'relationship'>) => {
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<'relationship'> = (dataFormatter: DataFormatterTypeMap<'relationship'>) => {
4
+
5
+ return {
6
+ status: 'success',
7
+ columnName: '',
8
+ expectToBe: ''
9
+ }
10
10
  }