@orbcharts/core 3.0.0-alpha.43 → 3.0.0-alpha.45
Sign up to get free protection for your applications and to get access to all the features.
- package/LICENSE +200 -200
- package/dist/orbcharts-core.es.js +97 -97
- package/dist/orbcharts-core.umd.js +2 -2
- package/dist/src/series/seriesObservables.d.ts +3 -3
- package/dist/src/types/ContextObserverSeries.d.ts +1 -1
- package/dist/src/types/DataFormatterSeries.d.ts +3 -3
- package/package.json +41 -41
- package/src/AbstractChart.ts +48 -48
- package/src/GridChart.ts +20 -20
- package/src/MultiGridChart.ts +20 -20
- package/src/MultiValueChart.ts +20 -20
- package/src/RelationshipChart.ts +20 -20
- package/src/SeriesChart.ts +20 -20
- package/src/TreeChart.ts +20 -20
- package/src/base/createBaseChart.ts +368 -367
- package/src/base/createBasePlugin.ts +89 -89
- package/src/defaults.ts +220 -220
- package/src/defineGridPlugin.ts +3 -3
- package/src/defineMultiGridPlugin.ts +3 -3
- package/src/defineMultiValuePlugin.ts +3 -3
- package/src/defineNoneDataPlugin.ts +4 -4
- package/src/defineRelationshipPlugin.ts +3 -3
- package/src/defineSeriesPlugin.ts +3 -3
- package/src/defineTreePlugin.ts +3 -3
- package/src/grid/computeGridData.ts +134 -134
- package/src/grid/createGridContextObserver.ts +147 -147
- package/src/grid/gridObservables.ts +573 -573
- package/src/index.ts +21 -21
- package/src/multiGrid/computeMultiGridData.ts +130 -130
- package/src/multiGrid/createMultiGridContextObserver.ts +40 -40
- package/src/multiGrid/multiGridObservables.ts +350 -350
- package/src/multiValue/computeMultiValueData.ts +143 -143
- package/src/multiValue/createMultiValueContextObserver.ts +12 -12
- package/src/relationship/computeRelationshipData.ts +118 -118
- package/src/relationship/createRelationshipContextObserver.ts +12 -12
- package/src/series/computeSeriesData.ts +90 -90
- package/src/series/createSeriesContextObserver.ts +93 -93
- package/src/series/seriesObservables.ts +175 -175
- package/src/tree/computeTreeData.ts +131 -131
- package/src/tree/createTreeContextObserver.ts +61 -61
- package/src/tree/treeObservables.ts +94 -94
- package/src/types/Chart.ts +48 -48
- package/src/types/ChartParams.ts +51 -51
- package/src/types/ComputedData.ts +83 -83
- package/src/types/ComputedDataGrid.ts +13 -13
- package/src/types/ComputedDataMultiGrid.ts +2 -2
- package/src/types/ComputedDataMultiValue.ts +9 -9
- package/src/types/ComputedDataRelationship.ts +19 -19
- package/src/types/ComputedDataSeries.ts +7 -7
- package/src/types/ComputedDataTree.ts +19 -19
- package/src/types/ContextObserver.ts +38 -38
- package/src/types/ContextObserverGrid.ts +41 -41
- package/src/types/ContextObserverMultiGrid.ts +15 -15
- package/src/types/ContextObserverMultiValue.ts +4 -4
- package/src/types/ContextObserverRelationship.ts +4 -4
- package/src/types/ContextObserverSeries.ts +29 -29
- package/src/types/ContextObserverTree.ts +11 -11
- package/src/types/ContextSubject.ts +18 -18
- package/src/types/Data.ts +45 -45
- package/src/types/DataFormatter.ts +74 -74
- package/src/types/DataFormatterGrid.ts +67 -67
- package/src/types/DataFormatterMultiGrid.ts +44 -44
- package/src/types/DataFormatterMultiValue.ts +23 -23
- package/src/types/DataFormatterRelationship.ts +25 -25
- package/src/types/DataFormatterSeries.ts +20 -20
- package/src/types/DataFormatterTree.ts +12 -12
- package/src/types/DataGrid.ts +11 -11
- package/src/types/DataMultiGrid.ts +6 -6
- package/src/types/DataMultiValue.ts +12 -12
- package/src/types/DataRelationship.ts +27 -27
- package/src/types/DataSeries.ts +11 -11
- package/src/types/DataTree.ts +20 -20
- package/src/types/Event.ts +153 -153
- package/src/types/Layout.ts +11 -11
- package/src/types/Padding.ts +5 -5
- package/src/types/Plugin.ts +60 -60
- package/src/types/TransformData.ts +7 -7
- package/src/types/index.ts +37 -37
- package/src/utils/commonUtils.ts +50 -50
- package/src/utils/d3Utils.ts +89 -89
- package/src/utils/index.ts +4 -4
- package/src/utils/observables.ts +201 -201
- package/src/utils/orbchartsUtils.ts +349 -349
- package/tsconfig.json +13 -13
- package/vite.config.js +44 -44
@@ -1,143 +1,143 @@
|
|
1
|
-
import type { DataMultiValue, DataMultiValueDatum } from '../types/DataMultiValue'
|
2
|
-
import type { DataFormatterContext } from '../types/DataFormatter'
|
3
|
-
import type { ComputedDataFn } from '../types/ComputedData'
|
4
|
-
import type { ComputedDataMultiValue, ComputedDatumMultiValue } from '../types/ComputedDataMultiValue'
|
5
|
-
import { formatValueToLabel, createDefaultDatumId } from '../utils/orbchartsUtils'
|
6
|
-
import { createAxisLinearScale, createAxisPointScale } from '../utils/d3Utils'
|
7
|
-
import { getMinAndMaxValue } from '../utils/orbchartsUtils'
|
8
|
-
|
9
|
-
export const computeMultiValueData: ComputedDataFn<'multiValue'> = (context) => {
|
10
|
-
const { data, dataFormatter, chartParams } = context
|
11
|
-
if (!data.length) {
|
12
|
-
return []
|
13
|
-
}
|
14
|
-
|
15
|
-
// @Q@ 假資料待改寫
|
16
|
-
const layout = {
|
17
|
-
width: 1000,
|
18
|
-
height: 1000
|
19
|
-
}
|
20
|
-
|
21
|
-
let computedDataMultiValue: ComputedDatumMultiValue[][] = []
|
22
|
-
|
23
|
-
try {
|
24
|
-
const dataMultiValue: DataMultiValueDatum[][] = data.map((d, i) => {
|
25
|
-
return d.map((_d, _i) => {
|
26
|
-
const datum: DataMultiValueDatum = typeof _d === 'number'
|
27
|
-
? {
|
28
|
-
id: '',
|
29
|
-
label: '',
|
30
|
-
description: '',
|
31
|
-
// tooltipContent: '',
|
32
|
-
data: {},
|
33
|
-
categoryLabel: '',
|
34
|
-
value: _d
|
35
|
-
}
|
36
|
-
: {
|
37
|
-
id: _d.id ?? '',
|
38
|
-
label: _d.label ?? '',
|
39
|
-
description: _d.description ?? '',
|
40
|
-
// tooltipContent: _d.tooltipContent ?? '',
|
41
|
-
data: _d.data ?? {},
|
42
|
-
categoryLabel: _d.categoryLabel ??'',
|
43
|
-
value: _d.value
|
44
|
-
}
|
45
|
-
|
46
|
-
return datum
|
47
|
-
})
|
48
|
-
})
|
49
|
-
|
50
|
-
// x軸資料最小及最大值(第二維陣列中的第1筆為x軸資料)
|
51
|
-
const [xMinValue, xMaxValue] = getMinAndMaxValue(dataMultiValue.map(d => d[0]))
|
52
|
-
// y軸資料最小及最大值(第二維陣列中的第2筆為y軸資料)
|
53
|
-
const [yMinValue, yMaxValue] = getMinAndMaxValue(dataMultiValue.map(d => d[1]))
|
54
|
-
|
55
|
-
// const axisWidth = layout.width - dataFormatter.padding.left - dataFormatter.padding.right
|
56
|
-
// const axisHeight = layout.height - dataFormatter.padding.top - dataFormatter.padding.bottom
|
57
|
-
// const axisWidth = layout.width
|
58
|
-
// const axisHeight = layout.height
|
59
|
-
const xAxisWidth = (dataFormatter.xAxis.position === 'top' || dataFormatter.xAxis.position === 'bottom')
|
60
|
-
? layout.width
|
61
|
-
: layout.height
|
62
|
-
const yAxisWidth = (dataFormatter.yAxis.position === 'left' || dataFormatter.yAxis.position === 'right')
|
63
|
-
? layout.height
|
64
|
-
: layout.width
|
65
|
-
|
66
|
-
const xScale: d3.ScaleLinear<number, number> = createAxisLinearScale({
|
67
|
-
maxValue: xMaxValue,
|
68
|
-
minValue: xMinValue,
|
69
|
-
axisWidth: xAxisWidth,
|
70
|
-
// scaleDomain: dataFormatter.xAxis.scaleDomain,
|
71
|
-
// scaleRange: dataFormatter.xAxis.scaleRange
|
72
|
-
scaleDomain: [xMinValue, xMaxValue],
|
73
|
-
scaleRange: [0, 1]
|
74
|
-
})
|
75
|
-
const yScale: d3.ScaleLinear<number, number> = createAxisLinearScale({
|
76
|
-
maxValue: yMaxValue,
|
77
|
-
minValue: yMinValue,
|
78
|
-
axisWidth: yAxisWidth,
|
79
|
-
// scaleDomain: dataFormatter.yAxis.scaleDomain,
|
80
|
-
// scaleRange: dataFormatter.yAxis.scaleRange
|
81
|
-
scaleDomain: [yMinValue, yMaxValue],
|
82
|
-
scaleRange: [0, 1]
|
83
|
-
})
|
84
|
-
|
85
|
-
const _xScaleDoamin: [number, number] = [
|
86
|
-
dataFormatter.xAxis.scaleDomain[0] === 'auto' ? xMinValue : dataFormatter.xAxis.scaleDomain[0],
|
87
|
-
dataFormatter.xAxis.scaleDomain[1] === 'auto' ? xMaxValue : dataFormatter.xAxis.scaleDomain[1]
|
88
|
-
]
|
89
|
-
const _yScaleDoamin: [number, number] = [
|
90
|
-
dataFormatter.yAxis.scaleDomain[0] === 'auto' ? yMinValue : dataFormatter.yAxis.scaleDomain[0],
|
91
|
-
dataFormatter.yAxis.scaleDomain[1] === 'auto' ? yMaxValue : dataFormatter.yAxis.scaleDomain[1]
|
92
|
-
]
|
93
|
-
|
94
|
-
// // 篩選顯示狀態
|
95
|
-
// const visibleFilter = (datum: DataMultiValueDatum, rowIndex: number, columnIndex: number, context: DataFormatterContext<"multiValue">) => {
|
96
|
-
// // 如果不在scale的範圍內則為false,不再做visibleFilter的判斷
|
97
|
-
// if (columnIndex === 0 && datum.value != null && ((datum.value as number) < _xScaleDoamin[0] || datum.value > _xScaleDoamin[1])) {
|
98
|
-
// return false
|
99
|
-
// }
|
100
|
-
// if (columnIndex === 1 && datum.value != null && (datum.value < _yScaleDoamin[0] || datum.value > _yScaleDoamin[1])) {
|
101
|
-
// return false
|
102
|
-
// }
|
103
|
-
|
104
|
-
// return dataFormatter.visibleFilter(datum, rowIndex, columnIndex, context)
|
105
|
-
// }
|
106
|
-
|
107
|
-
let index = 0
|
108
|
-
|
109
|
-
computedDataMultiValue = dataMultiValue.map((d, i) => {
|
110
|
-
return d.map((_d, _i) => {
|
111
|
-
const currentIndex = index
|
112
|
-
index++
|
113
|
-
|
114
|
-
const defaultId = createDefaultDatumId(dataFormatter.type, i, _i)
|
115
|
-
|
116
|
-
const computedDatum: ComputedDatumMultiValue = {
|
117
|
-
id: _d.id ? _d.id : defaultId,
|
118
|
-
index: currentIndex,
|
119
|
-
label: _d.label ? _d.label : defaultId,
|
120
|
-
description: _d.description ?? '',
|
121
|
-
// tooltipContent: _d.tooltipContent ? _d.tooltipContent : dataFormatter.tooltipContentFormat(_d, i, _i, context),
|
122
|
-
data: _d.data,
|
123
|
-
value: _d.value,
|
124
|
-
categoryIndex: 0, // @Q@ 未完成
|
125
|
-
categoryLabel: '', // @Q@ 未完成
|
126
|
-
// valueLabel: formatValueToLabel(_d.value, dataFormatter.multiValue[_i].valueFormat),
|
127
|
-
axis: _i == 0 ? xScale(_d.value) : yScale(_d.value),
|
128
|
-
visible: true, // 先給預設值
|
129
|
-
color: '' // @Q@ 未完成
|
130
|
-
}
|
131
|
-
|
132
|
-
computedDatum.visible = dataFormatter.visibleFilter(computedDatum, context)
|
133
|
-
|
134
|
-
return computedDatum
|
135
|
-
})
|
136
|
-
})
|
137
|
-
} catch (e) {
|
138
|
-
// console.error(e)
|
139
|
-
throw Error(e)
|
140
|
-
}
|
141
|
-
|
142
|
-
return computedDataMultiValue
|
143
|
-
}
|
1
|
+
import type { DataMultiValue, DataMultiValueDatum } from '../types/DataMultiValue'
|
2
|
+
import type { DataFormatterContext } from '../types/DataFormatter'
|
3
|
+
import type { ComputedDataFn } from '../types/ComputedData'
|
4
|
+
import type { ComputedDataMultiValue, ComputedDatumMultiValue } from '../types/ComputedDataMultiValue'
|
5
|
+
import { formatValueToLabel, createDefaultDatumId } from '../utils/orbchartsUtils'
|
6
|
+
import { createAxisLinearScale, createAxisPointScale } from '../utils/d3Utils'
|
7
|
+
import { getMinAndMaxValue } from '../utils/orbchartsUtils'
|
8
|
+
|
9
|
+
export const computeMultiValueData: ComputedDataFn<'multiValue'> = (context) => {
|
10
|
+
const { data, dataFormatter, chartParams } = context
|
11
|
+
if (!data.length) {
|
12
|
+
return []
|
13
|
+
}
|
14
|
+
|
15
|
+
// @Q@ 假資料待改寫
|
16
|
+
const layout = {
|
17
|
+
width: 1000,
|
18
|
+
height: 1000
|
19
|
+
}
|
20
|
+
|
21
|
+
let computedDataMultiValue: ComputedDatumMultiValue[][] = []
|
22
|
+
|
23
|
+
try {
|
24
|
+
const dataMultiValue: DataMultiValueDatum[][] = data.map((d, i) => {
|
25
|
+
return d.map((_d, _i) => {
|
26
|
+
const datum: DataMultiValueDatum = typeof _d === 'number'
|
27
|
+
? {
|
28
|
+
id: '',
|
29
|
+
label: '',
|
30
|
+
description: '',
|
31
|
+
// tooltipContent: '',
|
32
|
+
data: {},
|
33
|
+
categoryLabel: '',
|
34
|
+
value: _d
|
35
|
+
}
|
36
|
+
: {
|
37
|
+
id: _d.id ?? '',
|
38
|
+
label: _d.label ?? '',
|
39
|
+
description: _d.description ?? '',
|
40
|
+
// tooltipContent: _d.tooltipContent ?? '',
|
41
|
+
data: _d.data ?? {},
|
42
|
+
categoryLabel: _d.categoryLabel ??'',
|
43
|
+
value: _d.value
|
44
|
+
}
|
45
|
+
|
46
|
+
return datum
|
47
|
+
})
|
48
|
+
})
|
49
|
+
|
50
|
+
// x軸資料最小及最大值(第二維陣列中的第1筆為x軸資料)
|
51
|
+
const [xMinValue, xMaxValue] = getMinAndMaxValue(dataMultiValue.map(d => d[0]))
|
52
|
+
// y軸資料最小及最大值(第二維陣列中的第2筆為y軸資料)
|
53
|
+
const [yMinValue, yMaxValue] = getMinAndMaxValue(dataMultiValue.map(d => d[1]))
|
54
|
+
|
55
|
+
// const axisWidth = layout.width - dataFormatter.padding.left - dataFormatter.padding.right
|
56
|
+
// const axisHeight = layout.height - dataFormatter.padding.top - dataFormatter.padding.bottom
|
57
|
+
// const axisWidth = layout.width
|
58
|
+
// const axisHeight = layout.height
|
59
|
+
const xAxisWidth = (dataFormatter.xAxis.position === 'top' || dataFormatter.xAxis.position === 'bottom')
|
60
|
+
? layout.width
|
61
|
+
: layout.height
|
62
|
+
const yAxisWidth = (dataFormatter.yAxis.position === 'left' || dataFormatter.yAxis.position === 'right')
|
63
|
+
? layout.height
|
64
|
+
: layout.width
|
65
|
+
|
66
|
+
const xScale: d3.ScaleLinear<number, number> = createAxisLinearScale({
|
67
|
+
maxValue: xMaxValue,
|
68
|
+
minValue: xMinValue,
|
69
|
+
axisWidth: xAxisWidth,
|
70
|
+
// scaleDomain: dataFormatter.xAxis.scaleDomain,
|
71
|
+
// scaleRange: dataFormatter.xAxis.scaleRange
|
72
|
+
scaleDomain: [xMinValue, xMaxValue],
|
73
|
+
scaleRange: [0, 1]
|
74
|
+
})
|
75
|
+
const yScale: d3.ScaleLinear<number, number> = createAxisLinearScale({
|
76
|
+
maxValue: yMaxValue,
|
77
|
+
minValue: yMinValue,
|
78
|
+
axisWidth: yAxisWidth,
|
79
|
+
// scaleDomain: dataFormatter.yAxis.scaleDomain,
|
80
|
+
// scaleRange: dataFormatter.yAxis.scaleRange
|
81
|
+
scaleDomain: [yMinValue, yMaxValue],
|
82
|
+
scaleRange: [0, 1]
|
83
|
+
})
|
84
|
+
|
85
|
+
const _xScaleDoamin: [number, number] = [
|
86
|
+
dataFormatter.xAxis.scaleDomain[0] === 'auto' ? xMinValue : dataFormatter.xAxis.scaleDomain[0],
|
87
|
+
dataFormatter.xAxis.scaleDomain[1] === 'auto' ? xMaxValue : dataFormatter.xAxis.scaleDomain[1]
|
88
|
+
]
|
89
|
+
const _yScaleDoamin: [number, number] = [
|
90
|
+
dataFormatter.yAxis.scaleDomain[0] === 'auto' ? yMinValue : dataFormatter.yAxis.scaleDomain[0],
|
91
|
+
dataFormatter.yAxis.scaleDomain[1] === 'auto' ? yMaxValue : dataFormatter.yAxis.scaleDomain[1]
|
92
|
+
]
|
93
|
+
|
94
|
+
// // 篩選顯示狀態
|
95
|
+
// const visibleFilter = (datum: DataMultiValueDatum, rowIndex: number, columnIndex: number, context: DataFormatterContext<"multiValue">) => {
|
96
|
+
// // 如果不在scale的範圍內則為false,不再做visibleFilter的判斷
|
97
|
+
// if (columnIndex === 0 && datum.value != null && ((datum.value as number) < _xScaleDoamin[0] || datum.value > _xScaleDoamin[1])) {
|
98
|
+
// return false
|
99
|
+
// }
|
100
|
+
// if (columnIndex === 1 && datum.value != null && (datum.value < _yScaleDoamin[0] || datum.value > _yScaleDoamin[1])) {
|
101
|
+
// return false
|
102
|
+
// }
|
103
|
+
|
104
|
+
// return dataFormatter.visibleFilter(datum, rowIndex, columnIndex, context)
|
105
|
+
// }
|
106
|
+
|
107
|
+
let index = 0
|
108
|
+
|
109
|
+
computedDataMultiValue = dataMultiValue.map((d, i) => {
|
110
|
+
return d.map((_d, _i) => {
|
111
|
+
const currentIndex = index
|
112
|
+
index++
|
113
|
+
|
114
|
+
const defaultId = createDefaultDatumId(dataFormatter.type, i, _i)
|
115
|
+
|
116
|
+
const computedDatum: ComputedDatumMultiValue = {
|
117
|
+
id: _d.id ? _d.id : defaultId,
|
118
|
+
index: currentIndex,
|
119
|
+
label: _d.label ? _d.label : defaultId,
|
120
|
+
description: _d.description ?? '',
|
121
|
+
// tooltipContent: _d.tooltipContent ? _d.tooltipContent : dataFormatter.tooltipContentFormat(_d, i, _i, context),
|
122
|
+
data: _d.data,
|
123
|
+
value: _d.value,
|
124
|
+
categoryIndex: 0, // @Q@ 未完成
|
125
|
+
categoryLabel: '', // @Q@ 未完成
|
126
|
+
// valueLabel: formatValueToLabel(_d.value, dataFormatter.multiValue[_i].valueFormat),
|
127
|
+
axis: _i == 0 ? xScale(_d.value) : yScale(_d.value),
|
128
|
+
visible: true, // 先給預設值
|
129
|
+
color: '' // @Q@ 未完成
|
130
|
+
}
|
131
|
+
|
132
|
+
computedDatum.visible = dataFormatter.visibleFilter(computedDatum, context)
|
133
|
+
|
134
|
+
return computedDatum
|
135
|
+
})
|
136
|
+
})
|
137
|
+
} catch (e) {
|
138
|
+
// console.error(e)
|
139
|
+
throw Error(e)
|
140
|
+
}
|
141
|
+
|
142
|
+
return computedDataMultiValue
|
143
|
+
}
|
@@ -1,12 +1,12 @@
|
|
1
|
-
import type { ContextObserverFn } from '../types'
|
2
|
-
|
3
|
-
export const createMultiValueContextObserver: ContextObserverFn<'multiValue'> = ({ 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 { ContextObserverFn } from '../types'
|
2
|
+
|
3
|
+
export const createMultiValueContextObserver: ContextObserverFn<'multiValue'> = ({ 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,118 +1,118 @@
|
|
1
|
-
import type { DataRelationship, DataRelationshipObj, DataRelationshipList, Node, Edge } from '../types/DataRelationship'
|
2
|
-
import type { ComputedDataFn } from '../types/ComputedData'
|
3
|
-
import type { ComputedDataRelationship, ComputedNode, ComputedEdge } from '../types/ComputedDataRelationship'
|
4
|
-
|
5
|
-
export const computeRelationshipData: ComputedDataFn<'relationship'> = (context) => {
|
6
|
-
const { data, dataFormatter, chartParams } = context
|
7
|
-
|
8
|
-
let computedNodes: ComputedNode[] = []
|
9
|
-
let computedEdges: ComputedEdge[] = []
|
10
|
-
|
11
|
-
try {
|
12
|
-
// -- 取得nodes和edges資料 --
|
13
|
-
let nodes: Node[] = []
|
14
|
-
let edges: Edge[] = []
|
15
|
-
if ((data as DataRelationshipObj).nodes) {
|
16
|
-
nodes = (data as DataRelationshipObj).nodes
|
17
|
-
edges = (data as DataRelationshipObj).edges
|
18
|
-
} else if ((data as DataRelationshipList)[0]) {
|
19
|
-
nodes = (data as DataRelationshipList)[0]
|
20
|
-
edges = (data as DataRelationshipList)[1]
|
21
|
-
} else {
|
22
|
-
// 無值直接回傳
|
23
|
-
return {
|
24
|
-
nodes: [],
|
25
|
-
edges: []
|
26
|
-
} as ComputedDataRelationship
|
27
|
-
}
|
28
|
-
|
29
|
-
// -- nodes --
|
30
|
-
computedNodes = nodes.map((node, i) => {
|
31
|
-
const computedNode: ComputedNode = {
|
32
|
-
id: node.id,
|
33
|
-
index: i,
|
34
|
-
label: node.label ?? '',
|
35
|
-
description: node.description ?? '',
|
36
|
-
// tooltipContent: node.tooltipContent ? node.tooltipContent : dataFormatter.tooltipContentFormat(node, 0, i, context), // 0代表node
|
37
|
-
data: node.data ?? {},
|
38
|
-
value: node.value ?? 0,
|
39
|
-
categoryIndex: 0, // @Q@ 未完成
|
40
|
-
categoryLabel: '', // @Q@ 未完成
|
41
|
-
color: '', // @Q@ 未完成
|
42
|
-
startNodes: [], // 後面再取得資料
|
43
|
-
startNodeIds: [], // 後面再取得資料
|
44
|
-
endNodes: [], // 後面再取得資料
|
45
|
-
endNodeIds: [], // 後面再取得資料
|
46
|
-
visible: true // 後面再取得資料
|
47
|
-
}
|
48
|
-
return computedNode
|
49
|
-
})
|
50
|
-
|
51
|
-
const NodesMap: Map<string, ComputedNode> = new Map(computedNodes.map(d => [d.id, d]))
|
52
|
-
|
53
|
-
// -- edges --
|
54
|
-
computedEdges = edges.map((edge, i) => {
|
55
|
-
const computedEdge: ComputedEdge = {
|
56
|
-
id: edge.id,
|
57
|
-
index: i,
|
58
|
-
label: edge.label ?? '',
|
59
|
-
description: edge.description ?? '',
|
60
|
-
// tooltipContent: edge.tooltipContent ? edge.tooltipContent : dataFormatter.tooltipContentFormat(edge, 1, i, context), // 1代表edge
|
61
|
-
data: edge.data ?? {},
|
62
|
-
value: edge.value ?? 0,
|
63
|
-
startNode: NodesMap.get(edge.start),
|
64
|
-
startNodeId: edge.start,
|
65
|
-
endNode: NodesMap.get(edge.end),
|
66
|
-
endNodeId: edge.end,
|
67
|
-
visible: true // 先給預設值
|
68
|
-
}
|
69
|
-
|
70
|
-
return computedEdge
|
71
|
-
})
|
72
|
-
|
73
|
-
const StartNodesMap: Map<string, ComputedNode[]> = (function () {
|
74
|
-
const _StartNodesMap = new Map()
|
75
|
-
computedEdges.forEach(edge => {
|
76
|
-
const startNodes: ComputedNode[] = _StartNodesMap.get(edge.endNodeId) ?? []
|
77
|
-
startNodes.push(edge.startNode)
|
78
|
-
_StartNodesMap.set(edge.endNodeId, startNodes)
|
79
|
-
})
|
80
|
-
return _StartNodesMap
|
81
|
-
})()
|
82
|
-
|
83
|
-
const EndNodesMap: Map<string, ComputedNode[]> = (function () {
|
84
|
-
const _EndNodesMap = new Map()
|
85
|
-
computedEdges.forEach(edge => {
|
86
|
-
const endNodes: ComputedNode[] = _EndNodesMap.get(edge.startNodeId) ?? []
|
87
|
-
endNodes.push(edge.endNode)
|
88
|
-
_EndNodesMap.set(edge.startNodeId, endNodes)
|
89
|
-
})
|
90
|
-
return _EndNodesMap
|
91
|
-
})()
|
92
|
-
|
93
|
-
// -- 補齊nodes資料 --
|
94
|
-
Array.from(NodesMap).forEach(([nodeId, node]) => {
|
95
|
-
node.startNodes = StartNodesMap.get(nodeId)
|
96
|
-
node.startNodeIds = node.startNodes.map(d => d.id)
|
97
|
-
node.endNodes = EndNodesMap.get(nodeId)
|
98
|
-
node.endNodeIds = node.endNodes.map(d => d.id)
|
99
|
-
node.visible = dataFormatter.visibleFilter(node, context)
|
100
|
-
})
|
101
|
-
|
102
|
-
// -- 補齊edges資料 --
|
103
|
-
computedEdges = computedEdges.map(edge => {
|
104
|
-
edge.visible = edge.startNode.visible && edge.endNode.visible
|
105
|
-
? true
|
106
|
-
: false
|
107
|
-
return edge
|
108
|
-
})
|
109
|
-
} catch (e) {
|
110
|
-
// console.error(e)
|
111
|
-
throw Error(e)
|
112
|
-
}
|
113
|
-
|
114
|
-
return {
|
115
|
-
nodes: computedNodes,
|
116
|
-
edges: computedEdges
|
117
|
-
}
|
118
|
-
}
|
1
|
+
import type { DataRelationship, DataRelationshipObj, DataRelationshipList, Node, Edge } from '../types/DataRelationship'
|
2
|
+
import type { ComputedDataFn } from '../types/ComputedData'
|
3
|
+
import type { ComputedDataRelationship, ComputedNode, ComputedEdge } from '../types/ComputedDataRelationship'
|
4
|
+
|
5
|
+
export const computeRelationshipData: ComputedDataFn<'relationship'> = (context) => {
|
6
|
+
const { data, dataFormatter, chartParams } = context
|
7
|
+
|
8
|
+
let computedNodes: ComputedNode[] = []
|
9
|
+
let computedEdges: ComputedEdge[] = []
|
10
|
+
|
11
|
+
try {
|
12
|
+
// -- 取得nodes和edges資料 --
|
13
|
+
let nodes: Node[] = []
|
14
|
+
let edges: Edge[] = []
|
15
|
+
if ((data as DataRelationshipObj).nodes) {
|
16
|
+
nodes = (data as DataRelationshipObj).nodes
|
17
|
+
edges = (data as DataRelationshipObj).edges
|
18
|
+
} else if ((data as DataRelationshipList)[0]) {
|
19
|
+
nodes = (data as DataRelationshipList)[0]
|
20
|
+
edges = (data as DataRelationshipList)[1]
|
21
|
+
} else {
|
22
|
+
// 無值直接回傳
|
23
|
+
return {
|
24
|
+
nodes: [],
|
25
|
+
edges: []
|
26
|
+
} as ComputedDataRelationship
|
27
|
+
}
|
28
|
+
|
29
|
+
// -- nodes --
|
30
|
+
computedNodes = nodes.map((node, i) => {
|
31
|
+
const computedNode: ComputedNode = {
|
32
|
+
id: node.id,
|
33
|
+
index: i,
|
34
|
+
label: node.label ?? '',
|
35
|
+
description: node.description ?? '',
|
36
|
+
// tooltipContent: node.tooltipContent ? node.tooltipContent : dataFormatter.tooltipContentFormat(node, 0, i, context), // 0代表node
|
37
|
+
data: node.data ?? {},
|
38
|
+
value: node.value ?? 0,
|
39
|
+
categoryIndex: 0, // @Q@ 未完成
|
40
|
+
categoryLabel: '', // @Q@ 未完成
|
41
|
+
color: '', // @Q@ 未完成
|
42
|
+
startNodes: [], // 後面再取得資料
|
43
|
+
startNodeIds: [], // 後面再取得資料
|
44
|
+
endNodes: [], // 後面再取得資料
|
45
|
+
endNodeIds: [], // 後面再取得資料
|
46
|
+
visible: true // 後面再取得資料
|
47
|
+
}
|
48
|
+
return computedNode
|
49
|
+
})
|
50
|
+
|
51
|
+
const NodesMap: Map<string, ComputedNode> = new Map(computedNodes.map(d => [d.id, d]))
|
52
|
+
|
53
|
+
// -- edges --
|
54
|
+
computedEdges = edges.map((edge, i) => {
|
55
|
+
const computedEdge: ComputedEdge = {
|
56
|
+
id: edge.id,
|
57
|
+
index: i,
|
58
|
+
label: edge.label ?? '',
|
59
|
+
description: edge.description ?? '',
|
60
|
+
// tooltipContent: edge.tooltipContent ? edge.tooltipContent : dataFormatter.tooltipContentFormat(edge, 1, i, context), // 1代表edge
|
61
|
+
data: edge.data ?? {},
|
62
|
+
value: edge.value ?? 0,
|
63
|
+
startNode: NodesMap.get(edge.start),
|
64
|
+
startNodeId: edge.start,
|
65
|
+
endNode: NodesMap.get(edge.end),
|
66
|
+
endNodeId: edge.end,
|
67
|
+
visible: true // 先給預設值
|
68
|
+
}
|
69
|
+
|
70
|
+
return computedEdge
|
71
|
+
})
|
72
|
+
|
73
|
+
const StartNodesMap: Map<string, ComputedNode[]> = (function () {
|
74
|
+
const _StartNodesMap = new Map()
|
75
|
+
computedEdges.forEach(edge => {
|
76
|
+
const startNodes: ComputedNode[] = _StartNodesMap.get(edge.endNodeId) ?? []
|
77
|
+
startNodes.push(edge.startNode)
|
78
|
+
_StartNodesMap.set(edge.endNodeId, startNodes)
|
79
|
+
})
|
80
|
+
return _StartNodesMap
|
81
|
+
})()
|
82
|
+
|
83
|
+
const EndNodesMap: Map<string, ComputedNode[]> = (function () {
|
84
|
+
const _EndNodesMap = new Map()
|
85
|
+
computedEdges.forEach(edge => {
|
86
|
+
const endNodes: ComputedNode[] = _EndNodesMap.get(edge.startNodeId) ?? []
|
87
|
+
endNodes.push(edge.endNode)
|
88
|
+
_EndNodesMap.set(edge.startNodeId, endNodes)
|
89
|
+
})
|
90
|
+
return _EndNodesMap
|
91
|
+
})()
|
92
|
+
|
93
|
+
// -- 補齊nodes資料 --
|
94
|
+
Array.from(NodesMap).forEach(([nodeId, node]) => {
|
95
|
+
node.startNodes = StartNodesMap.get(nodeId)
|
96
|
+
node.startNodeIds = node.startNodes.map(d => d.id)
|
97
|
+
node.endNodes = EndNodesMap.get(nodeId)
|
98
|
+
node.endNodeIds = node.endNodes.map(d => d.id)
|
99
|
+
node.visible = dataFormatter.visibleFilter(node, context)
|
100
|
+
})
|
101
|
+
|
102
|
+
// -- 補齊edges資料 --
|
103
|
+
computedEdges = computedEdges.map(edge => {
|
104
|
+
edge.visible = edge.startNode.visible && edge.endNode.visible
|
105
|
+
? true
|
106
|
+
: false
|
107
|
+
return edge
|
108
|
+
})
|
109
|
+
} catch (e) {
|
110
|
+
// console.error(e)
|
111
|
+
throw Error(e)
|
112
|
+
}
|
113
|
+
|
114
|
+
return {
|
115
|
+
nodes: computedNodes,
|
116
|
+
edges: computedEdges
|
117
|
+
}
|
118
|
+
}
|
@@ -1,12 +1,12 @@
|
|
1
|
-
import type { ContextObserverFn } from '../types'
|
2
|
-
|
3
|
-
export const createRelationshipContextObserver: ContextObserverFn<'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 { ContextObserverFn } from '../types'
|
2
|
+
|
3
|
+
export const createRelationshipContextObserver: ContextObserverFn<'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
|
+
}
|