@orbcharts/plugins-basic 3.0.0-alpha.49 → 3.0.0-alpha.50
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/orbcharts-plugins-basic.es.js +6001 -5928
- package/dist/orbcharts-plugins-basic.umd.js +8 -8
- package/dist/src/multiGrid/defaults.d.ts +2 -1
- package/dist/src/multiGrid/index.d.ts +2 -0
- package/dist/src/multiGrid/multiGridObservables.d.ts +1 -1
- package/dist/src/multiGrid/plugins/MultiValueStackAxis.d.ts +1 -0
- package/dist/src/multiGrid/plugins/OverlappingValueStackAxes.d.ts +1 -0
- package/dist/src/multiGrid/types.d.ts +3 -0
- package/package.json +2 -2
- package/src/grid/defaults.ts +3 -1
- package/src/grid/gridObservables.ts +1 -0
- package/src/grid/plugins/BarStack.ts +1 -8
- package/src/grid/plugins/Bars.ts +1 -8
- package/src/grid/plugins/BarsTriangle.ts +1 -9
- package/src/grid/plugins/GroupAxis.ts +1 -8
- package/src/grid/plugins/ValueAxis.ts +1 -8
- package/src/grid/plugins/ValueStackAxis.ts +4 -45
- package/src/multiGrid/defaults.ts +5 -0
- package/src/multiGrid/index.ts +3 -1
- package/src/multiGrid/multiGridObservables.ts +3 -2
- package/src/multiGrid/plugins/MultiBarStack.ts +3 -3
- package/src/multiGrid/plugins/MultiBars.ts +3 -3
- package/src/multiGrid/plugins/MultiBarsTriangle.ts +3 -3
- package/src/multiGrid/plugins/MultiDots.ts +3 -3
- package/src/multiGrid/plugins/MultiGroupAxis.ts +3 -3
- package/src/multiGrid/plugins/MultiLineAreas.ts +3 -3
- package/src/multiGrid/plugins/MultiLines.ts +3 -3
- package/src/multiGrid/plugins/MultiValueAxis.ts +3 -3
- package/src/multiGrid/plugins/MultiValueStackAxis.ts +69 -0
- package/src/multiGrid/plugins/OverlappingValueAxes.ts +5 -12
- package/src/multiGrid/plugins/OverlappingValueStackAxes.ts +167 -0
- package/src/multiGrid/types.ts +4 -0
@@ -0,0 +1,167 @@
|
|
1
|
+
import * as d3 from 'd3'
|
2
|
+
import {
|
3
|
+
of,
|
4
|
+
map,
|
5
|
+
switchMap,
|
6
|
+
combineLatest,
|
7
|
+
takeUntil,
|
8
|
+
distinctUntilChanged,
|
9
|
+
shareReplay,
|
10
|
+
iif,
|
11
|
+
Observable,
|
12
|
+
Subject } from 'rxjs'
|
13
|
+
import type { ContextObserverMultiGrid, DataFormatterGrid, DataFormatterTypeMap, Layout } from '@orbcharts/core'
|
14
|
+
import {
|
15
|
+
defineMultiGridPlugin } from '@orbcharts/core'
|
16
|
+
import { DEFAULT_OVERLAPPING_VALUE_AXES_PARAMS } from '../defaults'
|
17
|
+
import { createBaseValueAxis } from '../../base/BaseValueAxis'
|
18
|
+
import { multiGridPluginDetailObservables } from '../multiGridObservables'
|
19
|
+
import { getClassName, getUniID } from '../../utils/orbchartsUtils'
|
20
|
+
import { gridAxesTransformObservable, gridAxesReverseTransformObservable, gridContainerPositionObservable } from '@orbcharts/core/src/grid/gridObservables'
|
21
|
+
|
22
|
+
const pluginName = 'OverlappingValueStackAxes'
|
23
|
+
|
24
|
+
const gridClassName = getClassName(pluginName, 'grid')
|
25
|
+
|
26
|
+
// 第一個圖軸使用堆疊的資料,第二個圖軸使用原始資料
|
27
|
+
export const OverlappingValueStackAxes = defineMultiGridPlugin(pluginName, DEFAULT_OVERLAPPING_VALUE_AXES_PARAMS)(({ selection, name, subject, observer }) => {
|
28
|
+
const destroy$ = new Subject()
|
29
|
+
|
30
|
+
const unsubscribeFnArr: (() => void)[] = []
|
31
|
+
|
32
|
+
const firstGridIndex$ = observer.fullParams$.pipe(
|
33
|
+
takeUntil(destroy$),
|
34
|
+
map(fullParams => fullParams.gridIndexes[0])
|
35
|
+
)
|
36
|
+
|
37
|
+
const secondGridIndex$ = observer.fullParams$.pipe(
|
38
|
+
takeUntil(destroy$),
|
39
|
+
map(fullParams => fullParams.gridIndexes[1])
|
40
|
+
)
|
41
|
+
|
42
|
+
// 為了要反轉第二個valueAxis的位置所以要重新計算
|
43
|
+
const secondGridDataFormatter$: Observable<DataFormatterGrid> = combineLatest({
|
44
|
+
firstGridIndex: firstGridIndex$,
|
45
|
+
secondGridIndex: secondGridIndex$,
|
46
|
+
fullDataFormatter: observer.fullDataFormatter$,
|
47
|
+
}).pipe(
|
48
|
+
takeUntil(destroy$),
|
49
|
+
switchMap(async (d) => d),
|
50
|
+
map(data => {
|
51
|
+
if (!data.fullDataFormatter.gridList[data.secondGridIndex]) {
|
52
|
+
data.fullDataFormatter.gridList[data.secondGridIndex] = Object.assign({}, data.fullDataFormatter.gridList[data.firstGridIndex])
|
53
|
+
}
|
54
|
+
// 反轉第二個valueAxis的位置
|
55
|
+
let reversePosition = ''
|
56
|
+
if (data.fullDataFormatter.gridList[data.firstGridIndex].valueAxis.position === 'left') {
|
57
|
+
reversePosition = 'right'
|
58
|
+
} else if (data.fullDataFormatter.gridList[data.firstGridIndex].valueAxis.position === 'bottom') {
|
59
|
+
reversePosition = 'top'
|
60
|
+
} else if (data.fullDataFormatter.gridList[data.firstGridIndex].valueAxis.position === 'top') {
|
61
|
+
reversePosition = 'bottom'
|
62
|
+
} else if (data.fullDataFormatter.gridList[data.firstGridIndex].valueAxis.position === 'right') {
|
63
|
+
reversePosition = 'left'
|
64
|
+
}
|
65
|
+
return <DataFormatterGrid>{
|
66
|
+
type: 'grid',
|
67
|
+
visibleFilter: data.fullDataFormatter.visibleFilter as any,
|
68
|
+
grid: {
|
69
|
+
...data.fullDataFormatter.gridList[data.secondGridIndex],
|
70
|
+
valueAxis: {
|
71
|
+
...data.fullDataFormatter.gridList[data.secondGridIndex].valueAxis,
|
72
|
+
position: reversePosition
|
73
|
+
}
|
74
|
+
},
|
75
|
+
container: {
|
76
|
+
...data.fullDataFormatter.container
|
77
|
+
}
|
78
|
+
}
|
79
|
+
})
|
80
|
+
)
|
81
|
+
|
82
|
+
const multiGridPluginDetail$ = of(observer).pipe(
|
83
|
+
takeUntil(destroy$),
|
84
|
+
map(observer => {
|
85
|
+
// 將observer的gridIndexes限制在2個
|
86
|
+
return {
|
87
|
+
...observer,
|
88
|
+
fullParams$: observer.fullParams$.pipe(
|
89
|
+
map(fullParams => {
|
90
|
+
if (fullParams.gridIndexes.length > 2) {
|
91
|
+
fullParams.gridIndexes.length = 2
|
92
|
+
}
|
93
|
+
return fullParams
|
94
|
+
})
|
95
|
+
)
|
96
|
+
}
|
97
|
+
}),
|
98
|
+
switchMap(observer => multiGridPluginDetailObservables(observer)),
|
99
|
+
map(data => {
|
100
|
+
return data.map((observables, index) => {
|
101
|
+
if (index === 0) {
|
102
|
+
return observables
|
103
|
+
}
|
104
|
+
// index === 1,將跟第二個valueAxis有關的observables全部重新計算
|
105
|
+
const gridAxesTransform$ = gridAxesTransformObservable({
|
106
|
+
fullDataFormatter$: secondGridDataFormatter$,
|
107
|
+
layout$: observer.layout$
|
108
|
+
})
|
109
|
+
const gridAxesReverseTransform$ = gridAxesReverseTransformObservable({
|
110
|
+
gridAxesTransform$
|
111
|
+
})
|
112
|
+
const gridContainerPosition$ = gridContainerPositionObservable({
|
113
|
+
computedData$: observables.computedData$,
|
114
|
+
fullDataFormatter$: secondGridDataFormatter$,
|
115
|
+
layout$: observer.layout$
|
116
|
+
})
|
117
|
+
return {
|
118
|
+
...observables,
|
119
|
+
gridAxesTransform$,
|
120
|
+
gridAxesReverseTransform$,
|
121
|
+
gridContainerPosition$,
|
122
|
+
}
|
123
|
+
})
|
124
|
+
})
|
125
|
+
)
|
126
|
+
|
127
|
+
multiGridPluginDetail$
|
128
|
+
.pipe(
|
129
|
+
takeUntil(destroy$)
|
130
|
+
)
|
131
|
+
.subscribe(data => {
|
132
|
+
// 每次重新計算時,清除之前的訂閱
|
133
|
+
unsubscribeFnArr.forEach(fn => fn())
|
134
|
+
|
135
|
+
selection.selectAll(`g.${gridClassName}`)
|
136
|
+
.data(data)
|
137
|
+
.join('g')
|
138
|
+
.attr('class', gridClassName)
|
139
|
+
.each((d, i, g) => {
|
140
|
+
if (i > 1) {
|
141
|
+
return
|
142
|
+
}
|
143
|
+
|
144
|
+
const gridSelection = d3.select(g[i])
|
145
|
+
|
146
|
+
unsubscribeFnArr[i] = createBaseValueAxis(pluginName, {
|
147
|
+
selection: gridSelection,
|
148
|
+
computedData$: i === 0 ? d.computedStackedData$ : d.computedData$, // 第一個圖軸計算疊加value的資料
|
149
|
+
fullParams$: observer.fullParams$.pipe(
|
150
|
+
map(fullParams => i === 0 ? fullParams.firstAxis : fullParams.secondAxis)
|
151
|
+
),
|
152
|
+
fullDataFormatter$: d.dataFormatter$,
|
153
|
+
fullChartParams$: observer.fullChartParams$,
|
154
|
+
gridAxesTransform$: d.gridAxesTransform$,
|
155
|
+
gridAxesReverseTransform$: d.gridAxesReverseTransform$,
|
156
|
+
gridAxesSize$: d.gridAxesSize$,
|
157
|
+
gridContainerPosition$: d.gridContainerPosition$,
|
158
|
+
isSeriesSeprate$: d.isSeriesSeprate$,
|
159
|
+
})
|
160
|
+
})
|
161
|
+
})
|
162
|
+
|
163
|
+
return () => {
|
164
|
+
destroy$.next(undefined)
|
165
|
+
unsubscribeFnArr.forEach(fn => fn())
|
166
|
+
}
|
167
|
+
})
|
package/src/multiGrid/types.ts
CHANGED
@@ -36,6 +36,10 @@ export interface MultiValueAxisParams extends BaseValueAxisParams {
|
|
36
36
|
gridIndexes: number[]
|
37
37
|
}
|
38
38
|
|
39
|
+
export interface MultiValueStackAxisParams extends BaseValueAxisParams {
|
40
|
+
gridIndexes: number[]
|
41
|
+
}
|
42
|
+
|
39
43
|
export interface MultiBarsParams extends BaseBarsParams {
|
40
44
|
gridIndexes: number[]
|
41
45
|
}
|