@orbcharts/core 3.0.0-alpha.39 → 3.0.0-alpha.40
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.
- package/LICENSE +200 -200
- package/dist/orbcharts-core.es.js +6 -6
- package/dist/orbcharts-core.umd.js +1 -1
- package/dist/src/types/ContextObserverGrid.d.ts +1 -1
- package/dist/src/types/ContextObserverSeries.d.ts +1 -1
- package/dist/src/types/ContextObserverTree.d.ts +1 -1
- package/dist/src/utils/observables.d.ts +5 -5
- 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 +367 -367
- package/src/base/createBasePlugin.ts +89 -89
- package/src/defaults.ts +247 -247
- 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 +205 -205
- package/src/grid/createGridContextObserver.ts +124 -124
- package/src/grid/gridObservables.ts +486 -486
- package/src/index.ts +21 -21
- package/src/multiGrid/computeMultiGridData.ts +173 -173
- package/src/multiGrid/createMultiGridContextObserver.ts +34 -34
- package/src/multiGrid/multiGridObservables.ts +285 -285
- package/src/multiValue/computeMultiValueData.ts +136 -136
- package/src/multiValue/createMultiValueContextObserver.ts +12 -12
- package/src/relationship/computeRelationshipData.ts +106 -106
- package/src/relationship/createRelationshipContextObserver.ts +12 -12
- package/src/series/computeSeriesData.ts +153 -153
- package/src/series/createSeriesContextObserver.ts +33 -33
- package/src/series/seriesObservables.ts +23 -23
- package/src/tree/computeTreeData.ts +128 -128
- package/src/tree/createTreeContextObserver.ts +56 -56
- 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 +82 -82
- 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 +33 -33
- package/src/types/ContextObserverMultiGrid.ts +27 -27
- package/src/types/ContextObserverMultiValue.ts +4 -4
- package/src/types/ContextObserverRelationship.ts +4 -4
- package/src/types/ContextObserverSeries.ts +7 -7
- package/src/types/ContextObserverTree.ts +10 -10
- package/src/types/ContextSubject.ts +18 -18
- package/src/types/Data.ts +45 -45
- package/src/types/DataFormatter.ts +95 -95
- package/src/types/DataFormatterGrid.ts +55 -55
- package/src/types/DataFormatterMultiGrid.ts +42 -42
- package/src/types/DataFormatterMultiValue.ts +20 -20
- package/src/types/DataFormatterRelationship.ts +22 -22
- package/src/types/DataFormatterSeries.ts +29 -29
- 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 +181 -183
- package/src/utils/orbchartsUtils.ts +253 -253
- package/tsconfig.json +13 -13
- package/vite.config.js +44 -44
package/src/index.ts
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
export { SeriesChart } from './SeriesChart'
|
|
3
|
-
export { GridChart } from './GridChart'
|
|
4
|
-
export { MultiGridChart } from './MultiGridChart'
|
|
5
|
-
export { MultiValueChart } from './MultiValueChart'
|
|
6
|
-
export { RelationshipChart } from './RelationshipChart'
|
|
7
|
-
export { TreeChart } from './TreeChart'
|
|
8
|
-
|
|
9
|
-
export { defineSeriesPlugin } from './defineSeriesPlugin'
|
|
10
|
-
export { defineGridPlugin } from './defineGridPlugin'
|
|
11
|
-
export { defineMultiGridPlugin } from './defineMultiGridPlugin'
|
|
12
|
-
export { defineMultiValuePlugin } from './defineMultiValuePlugin'
|
|
13
|
-
export { defineNoneDataPlugin } from './defineNoneDataPlugin'
|
|
14
|
-
export { defineRelationshipPlugin } from './defineRelationshipPlugin'
|
|
15
|
-
export { defineTreePlugin } from './defineTreePlugin'
|
|
16
|
-
|
|
17
|
-
export * from './types'
|
|
18
|
-
export * from './utils'
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
1
|
+
|
|
2
|
+
export { SeriesChart } from './SeriesChart'
|
|
3
|
+
export { GridChart } from './GridChart'
|
|
4
|
+
export { MultiGridChart } from './MultiGridChart'
|
|
5
|
+
export { MultiValueChart } from './MultiValueChart'
|
|
6
|
+
export { RelationshipChart } from './RelationshipChart'
|
|
7
|
+
export { TreeChart } from './TreeChart'
|
|
8
|
+
|
|
9
|
+
export { defineSeriesPlugin } from './defineSeriesPlugin'
|
|
10
|
+
export { defineGridPlugin } from './defineGridPlugin'
|
|
11
|
+
export { defineMultiGridPlugin } from './defineMultiGridPlugin'
|
|
12
|
+
export { defineMultiValuePlugin } from './defineMultiValuePlugin'
|
|
13
|
+
export { defineNoneDataPlugin } from './defineNoneDataPlugin'
|
|
14
|
+
export { defineRelationshipPlugin } from './defineRelationshipPlugin'
|
|
15
|
+
export { defineTreePlugin } from './defineTreePlugin'
|
|
16
|
+
|
|
17
|
+
export * from './types'
|
|
18
|
+
export * from './utils'
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
@@ -1,173 +1,173 @@
|
|
|
1
|
-
import type { DataGrid } from '../types/DataGrid'
|
|
2
|
-
import type { ComputedDataFn } from '../types/ComputedData'
|
|
3
|
-
import type { ComputedDatumGrid } from '../types/ComputedDataGrid'
|
|
4
|
-
import type { DataFormatterContext } from '../types/DataFormatter'
|
|
5
|
-
import type { DataFormatterGrid } from '../types/DataFormatterGrid'
|
|
6
|
-
import type { ComputedDataMultiGrid } from '../types/ComputedDataMultiGrid'
|
|
7
|
-
// import { computeBaseGridData } from '../grid/computeGridData'
|
|
8
|
-
import { DATA_FORMATTER_MULTI_GRID_GRID_DEFAULT } from '../defaults'
|
|
9
|
-
import {
|
|
10
|
-
createDefaultDatumId,
|
|
11
|
-
seriesColorPredicate,
|
|
12
|
-
createGridSeriesLabels,
|
|
13
|
-
createMultiGridSeriesLabels,
|
|
14
|
-
createMultiGridGroupLabels
|
|
15
|
-
} from '../utils/orbchartsUtils'
|
|
16
|
-
import type { DataGridDatumTemp } from '../grid/computeGridData'
|
|
17
|
-
import { createTransposedDataGrid, createGroupScale, createSeriesValueScaleArr } from '../grid/computeGridData'
|
|
18
|
-
|
|
19
|
-
function createGridData ({ context, gridIndex, transposedDataGrid, gridSeriesLabels, SeriesLabelColorMap }: {
|
|
20
|
-
context: DataFormatterContext<'grid'>
|
|
21
|
-
gridIndex: number
|
|
22
|
-
transposedDataGrid: DataGridDatumTemp[][]
|
|
23
|
-
gridSeriesLabels: string[]
|
|
24
|
-
SeriesLabelColorMap: Map<string, string>
|
|
25
|
-
}) {
|
|
26
|
-
const { data = [], dataFormatter, chartParams, layout } = context
|
|
27
|
-
if (!data.length) {
|
|
28
|
-
return []
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
const groupScale = createGroupScale(transposedDataGrid, dataFormatter, layout)
|
|
32
|
-
|
|
33
|
-
// const seriesLabels = createGridSeriesLabels({ transposedDataGrid, dataFormatter, chartType: 'multiGrid', gridIndex })
|
|
34
|
-
|
|
35
|
-
const groupLabels = createMultiGridGroupLabels({ transposedDataGrid, dataFormatter, chartType: 'multiGrid', gridIndex })
|
|
36
|
-
|
|
37
|
-
// 每一個series的valueScale
|
|
38
|
-
const seriesValueScaleArr = createSeriesValueScaleArr(transposedDataGrid, dataFormatter, layout)
|
|
39
|
-
|
|
40
|
-
const zeroYArr = transposedDataGrid.map((series, seriesIndex) => {
|
|
41
|
-
return seriesValueScaleArr[seriesIndex]!(0)
|
|
42
|
-
})
|
|
43
|
-
|
|
44
|
-
let _index = 0
|
|
45
|
-
let computedDataGrid: ComputedDatumGrid[][] = transposedDataGrid.map((seriesData, seriesIndex) => {
|
|
46
|
-
return seriesData.map((groupDatum, groupIndex) => {
|
|
47
|
-
|
|
48
|
-
const defaultId = createDefaultDatumId('multiGrid', gridIndex, seriesIndex, groupIndex)
|
|
49
|
-
const groupLabel = groupLabels[groupIndex]
|
|
50
|
-
const seriesLabel = gridSeriesLabels[seriesIndex]
|
|
51
|
-
const valueScale = seriesValueScaleArr[seriesIndex]
|
|
52
|
-
const axisY = valueScale(groupDatum.value ?? 0)
|
|
53
|
-
const zeroY = zeroYArr[seriesIndex]
|
|
54
|
-
|
|
55
|
-
const computedDatum: ComputedDatumGrid = {
|
|
56
|
-
id: groupDatum.id ? groupDatum.id : defaultId,
|
|
57
|
-
index: _index,
|
|
58
|
-
label: groupDatum.label ? groupDatum.label : defaultId,
|
|
59
|
-
description: groupDatum.description ?? '',
|
|
60
|
-
data: groupDatum.data,
|
|
61
|
-
value: groupDatum.value,
|
|
62
|
-
gridIndex,
|
|
63
|
-
// accSeriesIndex: seriesIndex, // 預設為seriesIndex
|
|
64
|
-
seriesIndex,
|
|
65
|
-
seriesLabel,
|
|
66
|
-
groupIndex,
|
|
67
|
-
groupLabel,
|
|
68
|
-
// color: seriesColorPredicate(seriesIndex, chartParams),
|
|
69
|
-
color: SeriesLabelColorMap.get(seriesLabel),
|
|
70
|
-
axisX: groupScale(groupIndex),
|
|
71
|
-
axisY,
|
|
72
|
-
axisYFromZero: axisY - zeroY,
|
|
73
|
-
visible: groupDatum._visible
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
_index ++
|
|
77
|
-
|
|
78
|
-
return computedDatum
|
|
79
|
-
})
|
|
80
|
-
})
|
|
81
|
-
|
|
82
|
-
return computedDataGrid
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
export const computeMultiGridData: ComputedDataFn<'multiGrid'> = ({ data = [], dataFormatter, chartParams, layout }) => {
|
|
86
|
-
if (!data.length) {
|
|
87
|
-
return []
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
let multiGridData: ComputedDataMultiGrid = []
|
|
91
|
-
|
|
92
|
-
try {
|
|
93
|
-
const defaultGrid = dataFormatter.gridList[0] || DATA_FORMATTER_MULTI_GRID_GRID_DEFAULT
|
|
94
|
-
|
|
95
|
-
// 計算每個grid的dataFormatter
|
|
96
|
-
const gridDataFormatterList: DataFormatterGrid[] = data.map((gridData, gridIndex) => {
|
|
97
|
-
const currentDataFormatterGrid = dataFormatter.gridList[gridIndex] || defaultGrid
|
|
98
|
-
|
|
99
|
-
return {
|
|
100
|
-
type: 'grid',
|
|
101
|
-
grid: {
|
|
102
|
-
...currentDataFormatterGrid
|
|
103
|
-
},
|
|
104
|
-
container: {
|
|
105
|
-
...dataFormatter.container
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
})
|
|
109
|
-
|
|
110
|
-
const gridContextList = data.map((gridData, gridIndex) => {
|
|
111
|
-
// grid context
|
|
112
|
-
return {
|
|
113
|
-
data: gridData,
|
|
114
|
-
dataFormatter: gridDataFormatterList[gridIndex],
|
|
115
|
-
chartParams,
|
|
116
|
-
layout
|
|
117
|
-
}
|
|
118
|
-
})
|
|
119
|
-
|
|
120
|
-
const transposedDataGridList = data.map((gridData, gridIndex) => {
|
|
121
|
-
// 依seriesDirection轉置資料矩陣
|
|
122
|
-
return createTransposedDataGrid(gridContextList[gridIndex])
|
|
123
|
-
})
|
|
124
|
-
|
|
125
|
-
const createSeriesLabelsFn = (() => {
|
|
126
|
-
const SlotIndexSet = new Set(gridDataFormatterList.map(d => d.grid.slotIndex))
|
|
127
|
-
// 判斷是否有重疊的grid
|
|
128
|
-
const isOverlappingMultiGrid = SlotIndexSet.size !== gridDataFormatterList.length
|
|
129
|
-
return isOverlappingMultiGrid
|
|
130
|
-
? createMultiGridSeriesLabels // 有重疊的grid則使用「不同」的seriesLabels
|
|
131
|
-
: createGridSeriesLabels // 沒有重疊的grid則使用「相同」的seriesLabels
|
|
132
|
-
})()
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
const multiGridSeriesLabels = transposedDataGridList
|
|
136
|
-
.map((gridData, gridIndex) => {
|
|
137
|
-
return createSeriesLabelsFn({
|
|
138
|
-
transposedDataGrid: gridData,
|
|
139
|
-
dataFormatter: gridDataFormatterList[gridIndex],
|
|
140
|
-
chartType: 'multiGrid',
|
|
141
|
-
gridIndex
|
|
142
|
-
} as any)
|
|
143
|
-
})
|
|
144
|
-
|
|
145
|
-
const SeriesLabelColorMap: Map<string, string> = new Map()
|
|
146
|
-
let accIndex = 0
|
|
147
|
-
multiGridSeriesLabels.flat().forEach((label, i) => {
|
|
148
|
-
if (!SeriesLabelColorMap.has(label)) {
|
|
149
|
-
const color = seriesColorPredicate(accIndex, chartParams)
|
|
150
|
-
SeriesLabelColorMap.set(label, color)
|
|
151
|
-
accIndex ++
|
|
152
|
-
}
|
|
153
|
-
})
|
|
154
|
-
|
|
155
|
-
// 計算每個grid的資料
|
|
156
|
-
multiGridData = data.map((gridData, gridIndex) => {
|
|
157
|
-
return createGridData({
|
|
158
|
-
context: gridContextList[gridIndex],
|
|
159
|
-
gridIndex,
|
|
160
|
-
transposedDataGrid: transposedDataGridList[gridIndex],
|
|
161
|
-
gridSeriesLabels: multiGridSeriesLabels[gridIndex],
|
|
162
|
-
SeriesLabelColorMap
|
|
163
|
-
})
|
|
164
|
-
})
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
} catch (e) {
|
|
168
|
-
// console.error(e)
|
|
169
|
-
throw Error(e)
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
return multiGridData
|
|
173
|
-
}
|
|
1
|
+
import type { DataGrid } from '../types/DataGrid'
|
|
2
|
+
import type { ComputedDataFn } from '../types/ComputedData'
|
|
3
|
+
import type { ComputedDatumGrid } from '../types/ComputedDataGrid'
|
|
4
|
+
import type { DataFormatterContext } from '../types/DataFormatter'
|
|
5
|
+
import type { DataFormatterGrid } from '../types/DataFormatterGrid'
|
|
6
|
+
import type { ComputedDataMultiGrid } from '../types/ComputedDataMultiGrid'
|
|
7
|
+
// import { computeBaseGridData } from '../grid/computeGridData'
|
|
8
|
+
import { DATA_FORMATTER_MULTI_GRID_GRID_DEFAULT } from '../defaults'
|
|
9
|
+
import {
|
|
10
|
+
createDefaultDatumId,
|
|
11
|
+
seriesColorPredicate,
|
|
12
|
+
createGridSeriesLabels,
|
|
13
|
+
createMultiGridSeriesLabels,
|
|
14
|
+
createMultiGridGroupLabels
|
|
15
|
+
} from '../utils/orbchartsUtils'
|
|
16
|
+
import type { DataGridDatumTemp } from '../grid/computeGridData'
|
|
17
|
+
import { createTransposedDataGrid, createGroupScale, createSeriesValueScaleArr } from '../grid/computeGridData'
|
|
18
|
+
|
|
19
|
+
function createGridData ({ context, gridIndex, transposedDataGrid, gridSeriesLabels, SeriesLabelColorMap }: {
|
|
20
|
+
context: DataFormatterContext<'grid'>
|
|
21
|
+
gridIndex: number
|
|
22
|
+
transposedDataGrid: DataGridDatumTemp[][]
|
|
23
|
+
gridSeriesLabels: string[]
|
|
24
|
+
SeriesLabelColorMap: Map<string, string>
|
|
25
|
+
}) {
|
|
26
|
+
const { data = [], dataFormatter, chartParams, layout } = context
|
|
27
|
+
if (!data.length) {
|
|
28
|
+
return []
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const groupScale = createGroupScale(transposedDataGrid, dataFormatter, layout)
|
|
32
|
+
|
|
33
|
+
// const seriesLabels = createGridSeriesLabels({ transposedDataGrid, dataFormatter, chartType: 'multiGrid', gridIndex })
|
|
34
|
+
|
|
35
|
+
const groupLabels = createMultiGridGroupLabels({ transposedDataGrid, dataFormatter, chartType: 'multiGrid', gridIndex })
|
|
36
|
+
|
|
37
|
+
// 每一個series的valueScale
|
|
38
|
+
const seriesValueScaleArr = createSeriesValueScaleArr(transposedDataGrid, dataFormatter, layout)
|
|
39
|
+
|
|
40
|
+
const zeroYArr = transposedDataGrid.map((series, seriesIndex) => {
|
|
41
|
+
return seriesValueScaleArr[seriesIndex]!(0)
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
let _index = 0
|
|
45
|
+
let computedDataGrid: ComputedDatumGrid[][] = transposedDataGrid.map((seriesData, seriesIndex) => {
|
|
46
|
+
return seriesData.map((groupDatum, groupIndex) => {
|
|
47
|
+
|
|
48
|
+
const defaultId = createDefaultDatumId('multiGrid', gridIndex, seriesIndex, groupIndex)
|
|
49
|
+
const groupLabel = groupLabels[groupIndex]
|
|
50
|
+
const seriesLabel = gridSeriesLabels[seriesIndex]
|
|
51
|
+
const valueScale = seriesValueScaleArr[seriesIndex]
|
|
52
|
+
const axisY = valueScale(groupDatum.value ?? 0)
|
|
53
|
+
const zeroY = zeroYArr[seriesIndex]
|
|
54
|
+
|
|
55
|
+
const computedDatum: ComputedDatumGrid = {
|
|
56
|
+
id: groupDatum.id ? groupDatum.id : defaultId,
|
|
57
|
+
index: _index,
|
|
58
|
+
label: groupDatum.label ? groupDatum.label : defaultId,
|
|
59
|
+
description: groupDatum.description ?? '',
|
|
60
|
+
data: groupDatum.data,
|
|
61
|
+
value: groupDatum.value,
|
|
62
|
+
gridIndex,
|
|
63
|
+
// accSeriesIndex: seriesIndex, // 預設為seriesIndex
|
|
64
|
+
seriesIndex,
|
|
65
|
+
seriesLabel,
|
|
66
|
+
groupIndex,
|
|
67
|
+
groupLabel,
|
|
68
|
+
// color: seriesColorPredicate(seriesIndex, chartParams),
|
|
69
|
+
color: SeriesLabelColorMap.get(seriesLabel),
|
|
70
|
+
axisX: groupScale(groupIndex),
|
|
71
|
+
axisY,
|
|
72
|
+
axisYFromZero: axisY - zeroY,
|
|
73
|
+
visible: groupDatum._visible
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
_index ++
|
|
77
|
+
|
|
78
|
+
return computedDatum
|
|
79
|
+
})
|
|
80
|
+
})
|
|
81
|
+
|
|
82
|
+
return computedDataGrid
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export const computeMultiGridData: ComputedDataFn<'multiGrid'> = ({ data = [], dataFormatter, chartParams, layout }) => {
|
|
86
|
+
if (!data.length) {
|
|
87
|
+
return []
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
let multiGridData: ComputedDataMultiGrid = []
|
|
91
|
+
|
|
92
|
+
try {
|
|
93
|
+
const defaultGrid = dataFormatter.gridList[0] || DATA_FORMATTER_MULTI_GRID_GRID_DEFAULT
|
|
94
|
+
|
|
95
|
+
// 計算每個grid的dataFormatter
|
|
96
|
+
const gridDataFormatterList: DataFormatterGrid[] = data.map((gridData, gridIndex) => {
|
|
97
|
+
const currentDataFormatterGrid = dataFormatter.gridList[gridIndex] || defaultGrid
|
|
98
|
+
|
|
99
|
+
return {
|
|
100
|
+
type: 'grid',
|
|
101
|
+
grid: {
|
|
102
|
+
...currentDataFormatterGrid
|
|
103
|
+
},
|
|
104
|
+
container: {
|
|
105
|
+
...dataFormatter.container
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
})
|
|
109
|
+
|
|
110
|
+
const gridContextList = data.map((gridData, gridIndex) => {
|
|
111
|
+
// grid context
|
|
112
|
+
return {
|
|
113
|
+
data: gridData,
|
|
114
|
+
dataFormatter: gridDataFormatterList[gridIndex],
|
|
115
|
+
chartParams,
|
|
116
|
+
layout
|
|
117
|
+
}
|
|
118
|
+
})
|
|
119
|
+
|
|
120
|
+
const transposedDataGridList = data.map((gridData, gridIndex) => {
|
|
121
|
+
// 依seriesDirection轉置資料矩陣
|
|
122
|
+
return createTransposedDataGrid(gridContextList[gridIndex])
|
|
123
|
+
})
|
|
124
|
+
|
|
125
|
+
const createSeriesLabelsFn = (() => {
|
|
126
|
+
const SlotIndexSet = new Set(gridDataFormatterList.map(d => d.grid.slotIndex))
|
|
127
|
+
// 判斷是否有重疊的grid
|
|
128
|
+
const isOverlappingMultiGrid = SlotIndexSet.size !== gridDataFormatterList.length
|
|
129
|
+
return isOverlappingMultiGrid
|
|
130
|
+
? createMultiGridSeriesLabels // 有重疊的grid則使用「不同」的seriesLabels
|
|
131
|
+
: createGridSeriesLabels // 沒有重疊的grid則使用「相同」的seriesLabels
|
|
132
|
+
})()
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
const multiGridSeriesLabels = transposedDataGridList
|
|
136
|
+
.map((gridData, gridIndex) => {
|
|
137
|
+
return createSeriesLabelsFn({
|
|
138
|
+
transposedDataGrid: gridData,
|
|
139
|
+
dataFormatter: gridDataFormatterList[gridIndex],
|
|
140
|
+
chartType: 'multiGrid',
|
|
141
|
+
gridIndex
|
|
142
|
+
} as any)
|
|
143
|
+
})
|
|
144
|
+
|
|
145
|
+
const SeriesLabelColorMap: Map<string, string> = new Map()
|
|
146
|
+
let accIndex = 0
|
|
147
|
+
multiGridSeriesLabels.flat().forEach((label, i) => {
|
|
148
|
+
if (!SeriesLabelColorMap.has(label)) {
|
|
149
|
+
const color = seriesColorPredicate(accIndex, chartParams)
|
|
150
|
+
SeriesLabelColorMap.set(label, color)
|
|
151
|
+
accIndex ++
|
|
152
|
+
}
|
|
153
|
+
})
|
|
154
|
+
|
|
155
|
+
// 計算每個grid的資料
|
|
156
|
+
multiGridData = data.map((gridData, gridIndex) => {
|
|
157
|
+
return createGridData({
|
|
158
|
+
context: gridContextList[gridIndex],
|
|
159
|
+
gridIndex,
|
|
160
|
+
transposedDataGrid: transposedDataGridList[gridIndex],
|
|
161
|
+
gridSeriesLabels: multiGridSeriesLabels[gridIndex],
|
|
162
|
+
SeriesLabelColorMap
|
|
163
|
+
})
|
|
164
|
+
})
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
} catch (e) {
|
|
168
|
+
// console.error(e)
|
|
169
|
+
throw Error(e)
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
return multiGridData
|
|
173
|
+
}
|
|
@@ -1,34 +1,34 @@
|
|
|
1
|
-
import {
|
|
2
|
-
shareReplay } from 'rxjs'
|
|
3
|
-
import type { ContextObserverFn } from '../types'
|
|
4
|
-
import { multiGridEachDetailObservable, multiGridContainerObservable } from './multiGridObservables'
|
|
5
|
-
|
|
6
|
-
export const createMultiGridContextObserver: ContextObserverFn<'multiGrid'> = ({ subject, observer }) => {
|
|
7
|
-
|
|
8
|
-
const multiGridEachDetail$ = multiGridEachDetailObservable({
|
|
9
|
-
fullDataFormatter$: observer.fullDataFormatter$,
|
|
10
|
-
computedData$: observer.computedData$,
|
|
11
|
-
layout$: observer.layout$,
|
|
12
|
-
fullChartParams$: observer.fullChartParams$,
|
|
13
|
-
event$: subject.event$
|
|
14
|
-
}).pipe(
|
|
15
|
-
shareReplay(1)
|
|
16
|
-
)
|
|
17
|
-
|
|
18
|
-
const multiGridContainer$ = multiGridContainerObservable({
|
|
19
|
-
computedData$: observer.computedData$,
|
|
20
|
-
fullDataFormatter$: observer.fullDataFormatter$,
|
|
21
|
-
fullChartParams$: observer.fullChartParams$,
|
|
22
|
-
layout$: observer.layout$,
|
|
23
|
-
})
|
|
24
|
-
|
|
25
|
-
return {
|
|
26
|
-
fullParams$: observer.fullParams$,
|
|
27
|
-
fullChartParams$: observer.fullChartParams$,
|
|
28
|
-
fullDataFormatter$: observer.fullDataFormatter$,
|
|
29
|
-
computedData$: observer.computedData$,
|
|
30
|
-
layout$: observer.layout$,
|
|
31
|
-
multiGridEachDetail$,
|
|
32
|
-
multiGridContainer$
|
|
33
|
-
}
|
|
34
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
shareReplay } from 'rxjs'
|
|
3
|
+
import type { ContextObserverFn } from '../types'
|
|
4
|
+
import { multiGridEachDetailObservable, multiGridContainerObservable } from './multiGridObservables'
|
|
5
|
+
|
|
6
|
+
export const createMultiGridContextObserver: ContextObserverFn<'multiGrid'> = ({ subject, observer }) => {
|
|
7
|
+
|
|
8
|
+
const multiGridEachDetail$ = multiGridEachDetailObservable({
|
|
9
|
+
fullDataFormatter$: observer.fullDataFormatter$,
|
|
10
|
+
computedData$: observer.computedData$,
|
|
11
|
+
layout$: observer.layout$,
|
|
12
|
+
fullChartParams$: observer.fullChartParams$,
|
|
13
|
+
event$: subject.event$
|
|
14
|
+
}).pipe(
|
|
15
|
+
shareReplay(1)
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
const multiGridContainer$ = multiGridContainerObservable({
|
|
19
|
+
computedData$: observer.computedData$,
|
|
20
|
+
fullDataFormatter$: observer.fullDataFormatter$,
|
|
21
|
+
fullChartParams$: observer.fullChartParams$,
|
|
22
|
+
layout$: observer.layout$,
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
return {
|
|
26
|
+
fullParams$: observer.fullParams$,
|
|
27
|
+
fullChartParams$: observer.fullChartParams$,
|
|
28
|
+
fullDataFormatter$: observer.fullDataFormatter$,
|
|
29
|
+
computedData$: observer.computedData$,
|
|
30
|
+
layout$: observer.layout$,
|
|
31
|
+
multiGridEachDetail$,
|
|
32
|
+
multiGridContainer$
|
|
33
|
+
}
|
|
34
|
+
}
|