@orbcharts/core 3.0.0-alpha.26 → 3.0.0-alpha.27
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/orbcharts-core.es.js +1522 -1426
- package/dist/orbcharts-core.umd.js +2 -2
- package/dist/src/multiGrid/multiGridObservables.d.ts +22 -0
- package/dist/src/types/ContextObserverMultiGrid.d.ts +17 -0
- package/dist/src/types/DataFormatterMultiGrid.d.ts +4 -11
- package/package.json +1 -1
- package/src/defaults.ts +20 -3
- package/src/grid/gridObservables.ts +4 -3
- package/src/multiGrid/createMultiGridContextObserver.ts +14 -0
- package/src/multiGrid/multiGridObservables.ts +152 -0
- package/src/types/ContextObserverMultiGrid.ts +14 -0
- package/src/types/DataFormatterMultiGrid.ts +11 -11
package/package.json
CHANGED
package/src/defaults.ts
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
// import { ChartRenderOptions } from './types/Chart'
|
3
3
|
import type { ChartType, ChartOptionsPartial } from './types/Chart'
|
4
4
|
import type { DataSeries } from './types/DataSeries'
|
5
|
-
import type { DataGrid } from './types/DataGrid'
|
5
|
+
import type { DataGrid, DataGridDatum } from './types/DataGrid'
|
6
6
|
import type { DataMultiGrid } from './types/DataMultiGrid'
|
7
7
|
import type { DataMultiValue } from './types/DataMultiValue'
|
8
8
|
import type { DataTree } from './types/DataTree'
|
@@ -197,7 +197,24 @@ export const DATA_FORMATTER_GRID_DEFAULT: DataFormatterGrid = {
|
|
197
197
|
export const DATA_FORMATTER_MULTI_GRID_DEFAULT: DataFormatterMultiGrid = {
|
198
198
|
...DATA_FORMATTER,
|
199
199
|
type: 'multiGrid',
|
200
|
-
multiGrid: [
|
200
|
+
multiGrid: [
|
201
|
+
{
|
202
|
+
...DATA_FORMATTER_GRID_DEFAULT
|
203
|
+
},
|
204
|
+
{
|
205
|
+
...DATA_FORMATTER_GRID_DEFAULT,
|
206
|
+
valueAxis: {
|
207
|
+
...DATA_FORMATTER_VALUE_AXIS,
|
208
|
+
position: 'right'
|
209
|
+
},
|
210
|
+
colorsPredicate: (datum, rowIndex, columnIndex, { chartParams, dataFormatter }) => {
|
211
|
+
const seriesIndex = dataFormatter.grid.seriesType === 'row' ? rowIndex : columnIndex
|
212
|
+
// @Q@ 暫時性的邏輯,之後改寫成接續前一個grid的series index
|
213
|
+
const reverseIndex = chartParams.colors[chartParams.colorScheme].series.length - 1 - seriesIndex
|
214
|
+
return chartParams.colors[chartParams.colorScheme].series[reverseIndex]
|
215
|
+
},
|
216
|
+
}
|
217
|
+
],
|
201
218
|
// visibleGroupRange: null,
|
202
219
|
}
|
203
220
|
|
@@ -205,7 +222,7 @@ export const DATA_FORMATTER_MULTI_VALUE_DEFAULT: DataFormatterMultiValue = {
|
|
205
222
|
...DATA_FORMATTER,
|
206
223
|
type: 'multiValue',
|
207
224
|
// labelFormat: (datum: any) => (datum && datum.label) ?? '',
|
208
|
-
multiValue: [],
|
225
|
+
multiValue: [],
|
209
226
|
xAxis: { ...DATA_FORMATTER_VALUE_AXIS },
|
210
227
|
yAxis: { ...DATA_FORMATTER_VALUE_AXIS },
|
211
228
|
}
|
@@ -127,7 +127,8 @@ export const gridAxesTransformObservable = ({ fullDataFormatter$, layout$ }: {
|
|
127
127
|
fullDataFormatter: fullDataFormatter$,
|
128
128
|
layout: layout$
|
129
129
|
}).pipe(
|
130
|
-
takeUntil(destroy$)
|
130
|
+
takeUntil(destroy$),
|
131
|
+
switchMap(async (d) => d),
|
131
132
|
).subscribe(data => {
|
132
133
|
const axesTransformData = calcAxesTransform({
|
133
134
|
xAxis: data.fullDataFormatter.groupAxis,
|
@@ -238,7 +239,8 @@ export const gridGraphicTransformObservable = ({ computedData$, fullDataFormatte
|
|
238
239
|
fullDataFormatter: fullDataFormatter$,
|
239
240
|
layout: layout$
|
240
241
|
}).pipe(
|
241
|
-
takeUntil(destroy$)
|
242
|
+
takeUntil(destroy$),
|
243
|
+
switchMap(async (d) => d),
|
242
244
|
).subscribe(data => {
|
243
245
|
const dataAreaTransformData = calcGridDataAreaTransform ({
|
244
246
|
data: data.computedData,
|
@@ -311,7 +313,6 @@ export const gridAxesSizeObservable = ({ fullDataFormatter$, layout$ }: {
|
|
311
313
|
layout: layout$
|
312
314
|
}).pipe(
|
313
315
|
takeUntil(destroy$),
|
314
|
-
// 轉換後會退訂前一個未完成的訂閱事件,因此可以取到「同時間」最後一次的訂閱事件
|
315
316
|
switchMap(async (d) => d),
|
316
317
|
).subscribe(data => {
|
317
318
|
|
@@ -1,12 +1,26 @@
|
|
1
|
+
import {
|
2
|
+
shareReplay } from 'rxjs'
|
1
3
|
import type { ContextObserverFn } from '../types'
|
4
|
+
import { multiGridObservable } from './multiGridObservables'
|
2
5
|
|
3
6
|
export const createMultiGridContextObserver: ContextObserverFn<'multiGrid'> = ({ subject, observer }) => {
|
4
7
|
|
8
|
+
const multiGrid$ = multiGridObservable({
|
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
|
+
|
5
18
|
return {
|
6
19
|
fullParams$: observer.fullParams$,
|
7
20
|
fullChartParams$: observer.fullChartParams$,
|
8
21
|
fullDataFormatter$: observer.fullDataFormatter$,
|
9
22
|
computedData$: observer.computedData$,
|
10
23
|
layout$: observer.layout$,
|
24
|
+
multiGrid$
|
11
25
|
}
|
12
26
|
}
|
@@ -0,0 +1,152 @@
|
|
1
|
+
import {
|
2
|
+
combineLatest,
|
3
|
+
distinctUntilChanged,
|
4
|
+
filter,
|
5
|
+
of,
|
6
|
+
map,
|
7
|
+
merge,
|
8
|
+
takeUntil,
|
9
|
+
shareReplay,
|
10
|
+
switchMap,
|
11
|
+
Subject,
|
12
|
+
Observable,
|
13
|
+
combineLatestAll} from 'rxjs'
|
14
|
+
import type {
|
15
|
+
AxisPosition,
|
16
|
+
ChartType,
|
17
|
+
ChartParams,
|
18
|
+
ComputedDataTypeMap,
|
19
|
+
ComputedDatumTypeMap,
|
20
|
+
ContextObserverFn,
|
21
|
+
DataTypeMap,
|
22
|
+
DataFormatterTypeMap,
|
23
|
+
DataFormatterGrid,
|
24
|
+
DataFormatterContext,
|
25
|
+
DataFormatterValueAxis,
|
26
|
+
DataFormatterGroupAxis,
|
27
|
+
EventMultiGrid,
|
28
|
+
HighlightTarget,
|
29
|
+
Layout,
|
30
|
+
TransformData } from '../types'
|
31
|
+
import { getMinAndMaxGrid, transposeData } from '../utils/orbchartsUtils'
|
32
|
+
import { createAxisLinearScale, createAxisPointScale, createAxisQuantizeScale } from '../utils/d3Utils'
|
33
|
+
import {
|
34
|
+
highlightObservable,
|
35
|
+
seriesDataMapObservable,
|
36
|
+
groupDataMapObservable } from '../utils/observables'
|
37
|
+
import {
|
38
|
+
gridAxesTransformObservable,
|
39
|
+
gridGraphicTransformObservable,
|
40
|
+
gridAxesOppositeTransformObservable,
|
41
|
+
gridAxesSizeObservable,
|
42
|
+
gridVisibleComputedDataObservable } from '../grid/gridObservables'
|
43
|
+
|
44
|
+
export const multiGridObservable = ({ fullDataFormatter$, computedData$, layout$, fullChartParams$, event$ }: {
|
45
|
+
fullDataFormatter$: Observable<DataFormatterTypeMap<'multiGrid'>>
|
46
|
+
computedData$: Observable<ComputedDataTypeMap<'multiGrid'>>
|
47
|
+
layout$: Observable<Layout>
|
48
|
+
fullChartParams$: Observable<ChartParams>
|
49
|
+
event$: Subject<EventMultiGrid>
|
50
|
+
}) => {
|
51
|
+
const destroy$ = new Subject()
|
52
|
+
|
53
|
+
return combineLatest({
|
54
|
+
fullDataFormatter: fullDataFormatter$,
|
55
|
+
computedData: computedData$,
|
56
|
+
}).pipe(
|
57
|
+
switchMap(async (d) => d),
|
58
|
+
distinctUntilChanged((a, b) => {
|
59
|
+
return a.fullDataFormatter.multiGrid.length === b.fullDataFormatter.multiGrid.length
|
60
|
+
&& a.computedData.length === b.computedData.length
|
61
|
+
}),
|
62
|
+
map(data => {
|
63
|
+
// 每次重新計算時,清除之前的訂閱
|
64
|
+
destroy$.next(undefined)
|
65
|
+
|
66
|
+
return data.fullDataFormatter.multiGrid.map((gridDataFormatter, gridIndex) => {
|
67
|
+
|
68
|
+
// -- 取得該grid的data和dataFormatter
|
69
|
+
const gridDataFormatter$ = of(gridDataFormatter).pipe(
|
70
|
+
takeUntil(destroy$),
|
71
|
+
shareReplay(1)
|
72
|
+
)
|
73
|
+
const gridComputedData$ = of(data.computedData[gridIndex] || []).pipe(
|
74
|
+
takeUntil(destroy$),
|
75
|
+
shareReplay(1)
|
76
|
+
)
|
77
|
+
|
78
|
+
// -- 建立Observables --
|
79
|
+
const gridAxesTransform$ = gridAxesTransformObservable({
|
80
|
+
fullDataFormatter$: gridDataFormatter$,
|
81
|
+
layout$: layout$
|
82
|
+
}).pipe(
|
83
|
+
shareReplay(1)
|
84
|
+
)
|
85
|
+
|
86
|
+
const gridGraphicTransform$ = gridGraphicTransformObservable({
|
87
|
+
computedData$: gridComputedData$,
|
88
|
+
fullDataFormatter$: gridDataFormatter$,
|
89
|
+
layout$: layout$
|
90
|
+
}).pipe(
|
91
|
+
shareReplay(1)
|
92
|
+
)
|
93
|
+
|
94
|
+
const gridAxesOppositeTransform$ = gridAxesOppositeTransformObservable({
|
95
|
+
gridAxesTransform$
|
96
|
+
}).pipe(
|
97
|
+
shareReplay(1)
|
98
|
+
)
|
99
|
+
|
100
|
+
const gridAxesSize$ = gridAxesSizeObservable({
|
101
|
+
fullDataFormatter$: gridDataFormatter$,
|
102
|
+
layout$: layout$
|
103
|
+
}).pipe(
|
104
|
+
shareReplay(1)
|
105
|
+
)
|
106
|
+
|
107
|
+
const datumList$ = gridComputedData$.pipe(
|
108
|
+
map(d => d.flat())
|
109
|
+
).pipe(
|
110
|
+
shareReplay(1)
|
111
|
+
)
|
112
|
+
|
113
|
+
const gridHighlight$ = highlightObservable({
|
114
|
+
datumList$,
|
115
|
+
fullChartParams$: fullChartParams$,
|
116
|
+
event$: event$
|
117
|
+
}).pipe(
|
118
|
+
shareReplay(1)
|
119
|
+
)
|
120
|
+
|
121
|
+
const SeriesDataMap$ = seriesDataMapObservable({
|
122
|
+
datumList$: datumList$
|
123
|
+
}).pipe(
|
124
|
+
shareReplay(1)
|
125
|
+
)
|
126
|
+
|
127
|
+
const GroupDataMap$ = groupDataMapObservable({
|
128
|
+
datumList$: datumList$
|
129
|
+
}).pipe(
|
130
|
+
shareReplay(1)
|
131
|
+
)
|
132
|
+
|
133
|
+
const visibleComputedData$ = gridVisibleComputedDataObservable({
|
134
|
+
computedData$: gridComputedData$,
|
135
|
+
}).pipe(
|
136
|
+
shareReplay(1)
|
137
|
+
)
|
138
|
+
|
139
|
+
return {
|
140
|
+
gridAxesTransform$,
|
141
|
+
gridGraphicTransform$,
|
142
|
+
gridAxesOppositeTransform$,
|
143
|
+
gridAxesSize$,
|
144
|
+
gridHighlight$,
|
145
|
+
SeriesDataMap$,
|
146
|
+
GroupDataMap$,
|
147
|
+
visibleComputedData$
|
148
|
+
}
|
149
|
+
})
|
150
|
+
})
|
151
|
+
)
|
152
|
+
}
|
@@ -1,5 +1,19 @@
|
|
1
|
+
import { Observable } from 'rxjs'
|
1
2
|
import type { ContextObserverBase } from './ContextObserver'
|
3
|
+
import type { ComputedDataGrid, ComputedDatumGrid } from './ComputedDataGrid'
|
4
|
+
import type { TransformData } from './TransformData'
|
2
5
|
|
3
6
|
export interface ContextObserverMultiGrid<PluginParams> extends ContextObserverBase<'multiGrid', PluginParams> {
|
7
|
+
multiGrid$: Observable<MultiGridObservableAll[]>
|
8
|
+
}
|
4
9
|
|
10
|
+
export interface MultiGridObservableAll {
|
11
|
+
gridAxesTransform$: Observable<TransformData>
|
12
|
+
gridGraphicTransform$: Observable<TransformData>
|
13
|
+
gridAxesOppositeTransform$: Observable<TransformData>
|
14
|
+
gridAxesSize$: Observable<{ width: number; height: number; }>
|
15
|
+
gridHighlight$: Observable<string[]>
|
16
|
+
SeriesDataMap$: Observable<Map<string, ComputedDatumGrid[]>>
|
17
|
+
GroupDataMap$: Observable<Map<string, ComputedDatumGrid[]>>
|
18
|
+
visibleComputedData$: Observable<ComputedDataGrid>
|
5
19
|
}
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { DataGridDatum, DataGridValue } from './DataGrid'
|
2
|
-
import { DataFormatterGridGrid } from './DataFormatterGrid'
|
2
|
+
import { DataFormatterGrid, DataFormatterGridGrid } from './DataFormatterGrid'
|
3
3
|
import {
|
4
4
|
DataFormatterBase,
|
5
5
|
DataFormatterBasePartial,
|
@@ -9,19 +9,19 @@ import {
|
|
9
9
|
import { AxisPosition } from './Axis'
|
10
10
|
|
11
11
|
export interface DataFormatterMultiGrid extends DataFormatterBase<'multiGrid'> {
|
12
|
-
multiGrid: Array<
|
12
|
+
multiGrid: Array<DataFormatterGrid>
|
13
13
|
// visibleGroupRange: [number, number] | null
|
14
14
|
}
|
15
15
|
|
16
16
|
export interface DataFormatterMultiGridPartial extends DataFormatterBasePartial<'multiGrid'> {
|
17
|
-
multiGrid?: Array<Partial<
|
17
|
+
multiGrid?: Array<Partial<DataFormatterGrid>>
|
18
18
|
}
|
19
19
|
|
20
|
-
// multiGrid欄位
|
21
|
-
export interface DataFormatterMultiGridMultiGrid {
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
}
|
20
|
+
// // multiGrid欄位
|
21
|
+
// export interface DataFormatterMultiGridMultiGrid {
|
22
|
+
// grid: DataFormatterGridGrid
|
23
|
+
// valueAxis: DataFormatterValueAxis // default: 'left'
|
24
|
+
// groupAxis: DataFormatterGroupAxis // default: 'bottom'
|
25
|
+
// colorsPredicate: (datum: DataGridDatum | DataGridValue, rowIndex: number, columnIndex: number, context: DataFormatterContext<'grid'>) => string
|
26
|
+
// // colors: Colors
|
27
|
+
// }
|