@orbcharts/plugins-basic 3.0.0-alpha.49 → 3.0.0-alpha.51
Sign up to get free protection for your applications and to get access to all the features.
- package/LICENSE +200 -200
- package/dist/orbcharts-plugins-basic.es.js +6325 -6272
- package/dist/orbcharts-plugins-basic.umd.js +8 -8
- package/dist/src/base/BaseGroupAxis.d.ts +1 -0
- package/dist/src/grid/index.d.ts +1 -1
- package/dist/src/grid/plugins/BarsPN.d.ts +1 -0
- package/dist/src/grid/types.d.ts +3 -2
- 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/dist/src/series/types.d.ts +2 -3
- package/package.json +42 -42
- package/src/base/BaseBarStack.ts +778 -778
- package/src/base/BaseBars.ts +764 -764
- package/src/base/BaseBarsTriangle.ts +672 -672
- package/src/base/BaseDots.ts +513 -502
- package/src/base/BaseGroupAxis.ts +562 -496
- package/src/base/BaseLegend.ts +641 -641
- package/src/base/BaseLineAreas.ts +625 -625
- package/src/base/BaseLines.ts +699 -699
- package/src/base/BaseValueAxis.ts +478 -478
- package/src/base/types.ts +2 -2
- package/src/grid/defaults.ts +125 -121
- package/src/grid/gridObservables.ts +248 -247
- package/src/grid/index.ts +15 -15
- package/src/grid/plugins/BarStack.ts +43 -50
- package/src/grid/plugins/Bars.ts +44 -51
- package/src/grid/plugins/{BarsDiverging.ts → BarsPN.ts} +41 -41
- package/src/grid/plugins/BarsTriangle.ts +42 -50
- package/src/grid/plugins/Dots.ts +37 -37
- package/src/grid/plugins/GridLegend.ts +59 -59
- package/src/grid/plugins/GroupAux.ts +645 -645
- package/src/grid/plugins/GroupAxis.ts +35 -42
- package/src/grid/plugins/LineAreas.ts +39 -39
- package/src/grid/plugins/Lines.ts +38 -38
- package/src/grid/plugins/ScalingArea.ts +173 -173
- package/src/grid/plugins/ValueAxis.ts +36 -43
- package/src/grid/plugins/ValueStackAxis.ts +38 -79
- package/src/grid/types.ts +122 -120
- package/src/index.ts +9 -9
- package/src/multiGrid/defaults.ts +152 -147
- package/src/multiGrid/index.ts +14 -12
- package/src/multiGrid/multiGridObservables.ts +44 -43
- package/src/multiGrid/plugins/MultiBarStack.ts +78 -78
- package/src/multiGrid/plugins/MultiBars.ts +77 -77
- package/src/multiGrid/plugins/MultiBarsTriangle.ts +77 -77
- package/src/multiGrid/plugins/MultiDots.ts +65 -65
- package/src/multiGrid/plugins/MultiGridLegend.ts +89 -89
- package/src/multiGrid/plugins/MultiGroupAxis.ts +69 -69
- package/src/multiGrid/plugins/MultiLineAreas.ts +67 -67
- package/src/multiGrid/plugins/MultiLines.ts +66 -66
- package/src/multiGrid/plugins/MultiValueAxis.ts +69 -69
- package/src/multiGrid/plugins/MultiValueStackAxis.ts +69 -0
- package/src/multiGrid/plugins/OverlappingValueAxes.ts +166 -173
- package/src/multiGrid/plugins/OverlappingValueStackAxes.ts +167 -0
- package/src/multiGrid/types.ts +71 -67
- package/src/noneData/defaults.ts +64 -64
- package/src/noneData/index.ts +3 -3
- package/src/noneData/plugins/Container.ts +10 -10
- package/src/noneData/plugins/Tooltip.ts +310 -310
- package/src/noneData/types.ts +26 -26
- package/src/series/defaults.ts +126 -126
- package/src/series/index.ts +9 -9
- package/src/series/plugins/Bubbles.ts +545 -602
- package/src/series/plugins/Pie.ts +576 -576
- package/src/series/plugins/PieEventTexts.ts +262 -262
- package/src/series/plugins/PieLabels.ts +304 -304
- package/src/series/plugins/Rose.ts +472 -472
- package/src/series/plugins/RoseLabels.ts +362 -362
- package/src/series/plugins/SeriesLegend.ts +59 -59
- package/src/series/seriesObservables.ts +145 -145
- package/src/series/seriesUtils.ts +51 -51
- package/src/series/types.ts +83 -83
- package/src/tree/defaults.ts +22 -22
- package/src/tree/index.ts +3 -3
- package/src/tree/plugins/TreeLegend.ts +59 -59
- package/src/tree/plugins/TreeMap.ts +305 -305
- package/src/tree/types.ts +23 -23
- package/src/utils/commonUtils.ts +21 -21
- package/src/utils/d3Graphics.ts +124 -124
- package/src/utils/d3Utils.ts +73 -73
- package/src/utils/observables.ts +14 -14
- package/src/utils/orbchartsUtils.ts +100 -100
- package/tsconfig.dev.json +16 -16
- package/tsconfig.json +13 -13
- package/tsconfig.prod.json +13 -13
- package/vite.config.js +49 -49
- package/dist/src/grid/plugins/BarsDiverging.d.ts +0 -1
@@ -1,173 +1,166 @@
|
|
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 {
|
19
|
-
import { getClassName, getUniID } from '../../utils/orbchartsUtils'
|
20
|
-
import { gridAxesTransformObservable, gridAxesReverseTransformObservable, gridContainerPositionObservable } from '@orbcharts/core/src/grid/gridObservables'
|
21
|
-
|
22
|
-
const pluginName = 'OverlappingValueAxes'
|
23
|
-
|
24
|
-
const gridClassName = getClassName(pluginName, 'grid')
|
25
|
-
|
26
|
-
export const OverlappingValueAxes = defineMultiGridPlugin(pluginName, DEFAULT_OVERLAPPING_VALUE_AXES_PARAMS)(({ selection, name, subject, observer }) => {
|
27
|
-
const destroy$ = new Subject()
|
28
|
-
|
29
|
-
const unsubscribeFnArr: (() => void)[] = []
|
30
|
-
|
31
|
-
const firstGridIndex$ = observer.fullParams$.pipe(
|
32
|
-
takeUntil(destroy$),
|
33
|
-
map(fullParams => fullParams.gridIndexes[0])
|
34
|
-
)
|
35
|
-
|
36
|
-
const secondGridIndex$ = observer.fullParams$.pipe(
|
37
|
-
takeUntil(destroy$),
|
38
|
-
map(fullParams => fullParams.gridIndexes[1])
|
39
|
-
)
|
40
|
-
|
41
|
-
// 為了要反轉第二個valueAxis的位置所以要重新計算
|
42
|
-
const secondGridDataFormatter$: Observable<DataFormatterGrid> = combineLatest({
|
43
|
-
firstGridIndex: firstGridIndex$,
|
44
|
-
secondGridIndex: secondGridIndex$,
|
45
|
-
fullDataFormatter: observer.fullDataFormatter$,
|
46
|
-
}).pipe(
|
47
|
-
takeUntil(destroy$),
|
48
|
-
switchMap(async (d) => d),
|
49
|
-
map(data => {
|
50
|
-
if (!data.fullDataFormatter.gridList[data.secondGridIndex]) {
|
51
|
-
data.fullDataFormatter.gridList[data.secondGridIndex] = Object.assign({}, data.fullDataFormatter.gridList[data.firstGridIndex])
|
52
|
-
}
|
53
|
-
// 反轉第二個valueAxis的位置
|
54
|
-
let reversePosition = ''
|
55
|
-
if (data.fullDataFormatter.gridList[data.firstGridIndex].valueAxis.position === 'left') {
|
56
|
-
reversePosition = 'right'
|
57
|
-
} else if (data.fullDataFormatter.gridList[data.firstGridIndex].valueAxis.position === 'bottom') {
|
58
|
-
reversePosition = 'top'
|
59
|
-
} else if (data.fullDataFormatter.gridList[data.firstGridIndex].valueAxis.position === 'top') {
|
60
|
-
reversePosition = 'bottom'
|
61
|
-
} else if (data.fullDataFormatter.gridList[data.firstGridIndex].valueAxis.position === 'right') {
|
62
|
-
reversePosition = 'left'
|
63
|
-
}
|
64
|
-
return <DataFormatterGrid>{
|
65
|
-
type: 'grid',
|
66
|
-
visibleFilter: data.fullDataFormatter.visibleFilter as any,
|
67
|
-
grid: {
|
68
|
-
...data.fullDataFormatter.gridList[data.secondGridIndex],
|
69
|
-
valueAxis: {
|
70
|
-
...data.fullDataFormatter.gridList[data.secondGridIndex].valueAxis,
|
71
|
-
position: reversePosition
|
72
|
-
}
|
73
|
-
},
|
74
|
-
container: {
|
75
|
-
...data.fullDataFormatter.container
|
76
|
-
}
|
77
|
-
}
|
78
|
-
})
|
79
|
-
)
|
80
|
-
|
81
|
-
const
|
82
|
-
takeUntil(destroy$),
|
83
|
-
map(observer => {
|
84
|
-
// 將observer的gridIndexes限制在2個
|
85
|
-
return {
|
86
|
-
...observer,
|
87
|
-
fullParams$: observer.fullParams$.pipe(
|
88
|
-
map(fullParams => {
|
89
|
-
if (fullParams.gridIndexes.length > 2) {
|
90
|
-
fullParams.gridIndexes.length = 2
|
91
|
-
}
|
92
|
-
return fullParams
|
93
|
-
})
|
94
|
-
)
|
95
|
-
}
|
96
|
-
}),
|
97
|
-
switchMap(observer =>
|
98
|
-
map(data => {
|
99
|
-
return data.map((observables, index) => {
|
100
|
-
if (index === 0) {
|
101
|
-
return observables
|
102
|
-
}
|
103
|
-
// index === 1,將跟第二個valueAxis有關的observables全部重新計算
|
104
|
-
const gridAxesTransform$ = gridAxesTransformObservable({
|
105
|
-
fullDataFormatter$: secondGridDataFormatter$,
|
106
|
-
layout$: observer.layout$
|
107
|
-
})
|
108
|
-
const gridAxesReverseTransform$ = gridAxesReverseTransformObservable({
|
109
|
-
gridAxesTransform$
|
110
|
-
})
|
111
|
-
const gridContainerPosition$ = gridContainerPositionObservable({
|
112
|
-
computedData$: observables.computedData$,
|
113
|
-
fullDataFormatter$: secondGridDataFormatter$,
|
114
|
-
layout$: observer.layout$
|
115
|
-
})
|
116
|
-
return {
|
117
|
-
...observables,
|
118
|
-
gridAxesTransform$,
|
119
|
-
gridAxesReverseTransform$,
|
120
|
-
gridContainerPosition$,
|
121
|
-
}
|
122
|
-
})
|
123
|
-
})
|
124
|
-
)
|
125
|
-
|
126
|
-
|
127
|
-
.pipe(
|
128
|
-
takeUntil(destroy$)
|
129
|
-
)
|
130
|
-
.subscribe(data => {
|
131
|
-
// 每次重新計算時,清除之前的訂閱
|
132
|
-
unsubscribeFnArr.forEach(fn => fn())
|
133
|
-
|
134
|
-
selection.selectAll(`g.${gridClassName}`)
|
135
|
-
.data(data)
|
136
|
-
.join('g')
|
137
|
-
.attr('class', gridClassName)
|
138
|
-
.each((d, i, g) => {
|
139
|
-
if (i > 1) {
|
140
|
-
return
|
141
|
-
}
|
142
|
-
|
143
|
-
const gridSelection = d3.select(g[i])
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
})
|
168
|
-
|
169
|
-
return () => {
|
170
|
-
destroy$.next(undefined)
|
171
|
-
unsubscribeFnArr.forEach(fn => fn())
|
172
|
-
}
|
173
|
-
})
|
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 = 'OverlappingValueAxes'
|
23
|
+
|
24
|
+
const gridClassName = getClassName(pluginName, 'grid')
|
25
|
+
|
26
|
+
export const OverlappingValueAxes = defineMultiGridPlugin(pluginName, DEFAULT_OVERLAPPING_VALUE_AXES_PARAMS)(({ selection, name, subject, observer }) => {
|
27
|
+
const destroy$ = new Subject()
|
28
|
+
|
29
|
+
const unsubscribeFnArr: (() => void)[] = []
|
30
|
+
|
31
|
+
const firstGridIndex$ = observer.fullParams$.pipe(
|
32
|
+
takeUntil(destroy$),
|
33
|
+
map(fullParams => fullParams.gridIndexes[0])
|
34
|
+
)
|
35
|
+
|
36
|
+
const secondGridIndex$ = observer.fullParams$.pipe(
|
37
|
+
takeUntil(destroy$),
|
38
|
+
map(fullParams => fullParams.gridIndexes[1])
|
39
|
+
)
|
40
|
+
|
41
|
+
// 為了要反轉第二個valueAxis的位置所以要重新計算
|
42
|
+
const secondGridDataFormatter$: Observable<DataFormatterGrid> = combineLatest({
|
43
|
+
firstGridIndex: firstGridIndex$,
|
44
|
+
secondGridIndex: secondGridIndex$,
|
45
|
+
fullDataFormatter: observer.fullDataFormatter$,
|
46
|
+
}).pipe(
|
47
|
+
takeUntil(destroy$),
|
48
|
+
switchMap(async (d) => d),
|
49
|
+
map(data => {
|
50
|
+
if (!data.fullDataFormatter.gridList[data.secondGridIndex]) {
|
51
|
+
data.fullDataFormatter.gridList[data.secondGridIndex] = Object.assign({}, data.fullDataFormatter.gridList[data.firstGridIndex])
|
52
|
+
}
|
53
|
+
// 反轉第二個valueAxis的位置
|
54
|
+
let reversePosition = ''
|
55
|
+
if (data.fullDataFormatter.gridList[data.firstGridIndex].valueAxis.position === 'left') {
|
56
|
+
reversePosition = 'right'
|
57
|
+
} else if (data.fullDataFormatter.gridList[data.firstGridIndex].valueAxis.position === 'bottom') {
|
58
|
+
reversePosition = 'top'
|
59
|
+
} else if (data.fullDataFormatter.gridList[data.firstGridIndex].valueAxis.position === 'top') {
|
60
|
+
reversePosition = 'bottom'
|
61
|
+
} else if (data.fullDataFormatter.gridList[data.firstGridIndex].valueAxis.position === 'right') {
|
62
|
+
reversePosition = 'left'
|
63
|
+
}
|
64
|
+
return <DataFormatterGrid>{
|
65
|
+
type: 'grid',
|
66
|
+
visibleFilter: data.fullDataFormatter.visibleFilter as any,
|
67
|
+
grid: {
|
68
|
+
...data.fullDataFormatter.gridList[data.secondGridIndex],
|
69
|
+
valueAxis: {
|
70
|
+
...data.fullDataFormatter.gridList[data.secondGridIndex].valueAxis,
|
71
|
+
position: reversePosition
|
72
|
+
}
|
73
|
+
},
|
74
|
+
container: {
|
75
|
+
...data.fullDataFormatter.container
|
76
|
+
}
|
77
|
+
}
|
78
|
+
})
|
79
|
+
)
|
80
|
+
|
81
|
+
const multiGridPluginDetail$ = of(observer).pipe(
|
82
|
+
takeUntil(destroy$),
|
83
|
+
map(observer => {
|
84
|
+
// 將observer的gridIndexes限制在2個
|
85
|
+
return {
|
86
|
+
...observer,
|
87
|
+
fullParams$: observer.fullParams$.pipe(
|
88
|
+
map(fullParams => {
|
89
|
+
if (fullParams.gridIndexes.length > 2) {
|
90
|
+
fullParams.gridIndexes.length = 2
|
91
|
+
}
|
92
|
+
return fullParams
|
93
|
+
})
|
94
|
+
)
|
95
|
+
}
|
96
|
+
}),
|
97
|
+
switchMap(observer => multiGridPluginDetailObservables(observer)),
|
98
|
+
map(data => {
|
99
|
+
return data.map((observables, index) => {
|
100
|
+
if (index === 0) {
|
101
|
+
return observables
|
102
|
+
}
|
103
|
+
// index === 1,將跟第二個valueAxis有關的observables全部重新計算
|
104
|
+
const gridAxesTransform$ = gridAxesTransformObservable({
|
105
|
+
fullDataFormatter$: secondGridDataFormatter$,
|
106
|
+
layout$: observer.layout$
|
107
|
+
})
|
108
|
+
const gridAxesReverseTransform$ = gridAxesReverseTransformObservable({
|
109
|
+
gridAxesTransform$
|
110
|
+
})
|
111
|
+
const gridContainerPosition$ = gridContainerPositionObservable({
|
112
|
+
computedData$: observables.computedData$,
|
113
|
+
fullDataFormatter$: secondGridDataFormatter$,
|
114
|
+
layout$: observer.layout$
|
115
|
+
})
|
116
|
+
return {
|
117
|
+
...observables,
|
118
|
+
gridAxesTransform$,
|
119
|
+
gridAxesReverseTransform$,
|
120
|
+
gridContainerPosition$,
|
121
|
+
}
|
122
|
+
})
|
123
|
+
})
|
124
|
+
)
|
125
|
+
|
126
|
+
multiGridPluginDetail$
|
127
|
+
.pipe(
|
128
|
+
takeUntil(destroy$)
|
129
|
+
)
|
130
|
+
.subscribe(data => {
|
131
|
+
// 每次重新計算時,清除之前的訂閱
|
132
|
+
unsubscribeFnArr.forEach(fn => fn())
|
133
|
+
|
134
|
+
selection.selectAll(`g.${gridClassName}`)
|
135
|
+
.data(data)
|
136
|
+
.join('g')
|
137
|
+
.attr('class', gridClassName)
|
138
|
+
.each((d, i, g) => {
|
139
|
+
if (i > 1) {
|
140
|
+
return
|
141
|
+
}
|
142
|
+
|
143
|
+
const gridSelection = d3.select(g[i])
|
144
|
+
|
145
|
+
unsubscribeFnArr[i] = createBaseValueAxis(pluginName, {
|
146
|
+
selection: gridSelection,
|
147
|
+
computedData$: d.computedData$,
|
148
|
+
fullParams$: observer.fullParams$.pipe(
|
149
|
+
map(fullParams => i === 0 ? fullParams.firstAxis : fullParams.secondAxis)
|
150
|
+
),
|
151
|
+
fullDataFormatter$: d.dataFormatter$,
|
152
|
+
fullChartParams$: observer.fullChartParams$,
|
153
|
+
gridAxesTransform$: d.gridAxesTransform$,
|
154
|
+
gridAxesReverseTransform$: d.gridAxesReverseTransform$,
|
155
|
+
gridAxesSize$: d.gridAxesSize$,
|
156
|
+
gridContainerPosition$: d.gridContainerPosition$,
|
157
|
+
isSeriesSeprate$: d.isSeriesSeprate$,
|
158
|
+
})
|
159
|
+
})
|
160
|
+
})
|
161
|
+
|
162
|
+
return () => {
|
163
|
+
destroy$.next(undefined)
|
164
|
+
unsubscribeFnArr.forEach(fn => fn())
|
165
|
+
}
|
166
|
+
})
|
@@ -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
@@ -1,67 +1,71 @@
|
|
1
|
-
import type { BaseBarsParams } from '../base/BaseBars'
|
2
|
-
import type { BaseBarStackParams } from '../base/BaseBarStack'
|
3
|
-
import type { BaseBarsTriangleParams } from '../base/BaseBarsTriangle'
|
4
|
-
import type { BaseLinesParams } from '../base/BaseLines'
|
5
|
-
import type { BaseLineAreasParams } from '../base/BaseLineAreas'
|
6
|
-
import type { BaseDotsParams } from '../base/BaseDots'
|
7
|
-
import type { BaseGroupAxisParams } from '../base/BaseGroupAxis'
|
8
|
-
import type { BaseValueAxisParams } from '../base/BaseValueAxis'
|
9
|
-
import type {
|
10
|
-
ChartParams, Layout, ColorType } from '@orbcharts/core'
|
11
|
-
|
12
|
-
export interface MultiGridLegendParams {
|
13
|
-
position: 'top' | 'bottom' | 'left' | 'right'
|
14
|
-
justify: 'start' | 'center' | 'end'
|
15
|
-
padding: number
|
16
|
-
backgroundFill: ColorType
|
17
|
-
backgroundStroke: ColorType
|
18
|
-
gap: number
|
19
|
-
listRectWidth: number
|
20
|
-
listRectHeight: number
|
21
|
-
listRectRadius: number
|
22
|
-
// 可針對各grid設定,覆蓋全域設定
|
23
|
-
gridList: Array<{
|
24
|
-
listRectWidth: number
|
25
|
-
listRectHeight: number
|
26
|
-
listRectRadius: number
|
27
|
-
}>
|
28
|
-
textColorType: ColorType
|
29
|
-
}
|
30
|
-
|
31
|
-
export interface MultiGroupAxisParams extends BaseGroupAxisParams {
|
32
|
-
gridIndexes: number[]
|
33
|
-
}
|
34
|
-
|
35
|
-
export interface MultiValueAxisParams extends BaseValueAxisParams {
|
36
|
-
gridIndexes: number[]
|
37
|
-
}
|
38
|
-
|
39
|
-
export interface
|
40
|
-
gridIndexes: number[]
|
41
|
-
}
|
42
|
-
|
43
|
-
export interface
|
44
|
-
gridIndexes: number[]
|
45
|
-
}
|
46
|
-
|
47
|
-
export interface
|
48
|
-
gridIndexes: number[]
|
49
|
-
}
|
50
|
-
|
51
|
-
export interface
|
52
|
-
gridIndexes: number[]
|
53
|
-
}
|
54
|
-
|
55
|
-
export interface
|
56
|
-
gridIndexes: number[]
|
57
|
-
}
|
58
|
-
|
59
|
-
export interface
|
60
|
-
gridIndexes: number[]
|
61
|
-
}
|
62
|
-
|
63
|
-
export interface
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
1
|
+
import type { BaseBarsParams } from '../base/BaseBars'
|
2
|
+
import type { BaseBarStackParams } from '../base/BaseBarStack'
|
3
|
+
import type { BaseBarsTriangleParams } from '../base/BaseBarsTriangle'
|
4
|
+
import type { BaseLinesParams } from '../base/BaseLines'
|
5
|
+
import type { BaseLineAreasParams } from '../base/BaseLineAreas'
|
6
|
+
import type { BaseDotsParams } from '../base/BaseDots'
|
7
|
+
import type { BaseGroupAxisParams } from '../base/BaseGroupAxis'
|
8
|
+
import type { BaseValueAxisParams } from '../base/BaseValueAxis'
|
9
|
+
import type {
|
10
|
+
ChartParams, Layout, ColorType } from '@orbcharts/core'
|
11
|
+
|
12
|
+
export interface MultiGridLegendParams {
|
13
|
+
position: 'top' | 'bottom' | 'left' | 'right'
|
14
|
+
justify: 'start' | 'center' | 'end'
|
15
|
+
padding: number
|
16
|
+
backgroundFill: ColorType
|
17
|
+
backgroundStroke: ColorType
|
18
|
+
gap: number
|
19
|
+
listRectWidth: number
|
20
|
+
listRectHeight: number
|
21
|
+
listRectRadius: number
|
22
|
+
// 可針對各grid設定,覆蓋全域設定
|
23
|
+
gridList: Array<{
|
24
|
+
listRectWidth: number
|
25
|
+
listRectHeight: number
|
26
|
+
listRectRadius: number
|
27
|
+
}>
|
28
|
+
textColorType: ColorType
|
29
|
+
}
|
30
|
+
|
31
|
+
export interface MultiGroupAxisParams extends BaseGroupAxisParams {
|
32
|
+
gridIndexes: number[]
|
33
|
+
}
|
34
|
+
|
35
|
+
export interface MultiValueAxisParams extends BaseValueAxisParams {
|
36
|
+
gridIndexes: number[]
|
37
|
+
}
|
38
|
+
|
39
|
+
export interface MultiValueStackAxisParams extends BaseValueAxisParams {
|
40
|
+
gridIndexes: number[]
|
41
|
+
}
|
42
|
+
|
43
|
+
export interface MultiBarsParams extends BaseBarsParams {
|
44
|
+
gridIndexes: number[]
|
45
|
+
}
|
46
|
+
|
47
|
+
export interface MultiBarStackParams extends BaseBarStackParams {
|
48
|
+
gridIndexes: number[]
|
49
|
+
}
|
50
|
+
|
51
|
+
export interface MultiBarsTriangleParams extends BaseBarsTriangleParams {
|
52
|
+
gridIndexes: number[]
|
53
|
+
}
|
54
|
+
|
55
|
+
export interface MultiLinesParams extends BaseLinesParams {
|
56
|
+
gridIndexes: number[]
|
57
|
+
}
|
58
|
+
|
59
|
+
export interface MultiLineAreasParams extends BaseLineAreasParams {
|
60
|
+
gridIndexes: number[]
|
61
|
+
}
|
62
|
+
|
63
|
+
export interface MultiDotsParams extends BaseDotsParams {
|
64
|
+
gridIndexes: number[]
|
65
|
+
}
|
66
|
+
|
67
|
+
export interface OverlappingValueAxesParams {
|
68
|
+
firstAxis: BaseValueAxisParams
|
69
|
+
secondAxis: BaseValueAxisParams
|
70
|
+
gridIndexes: [number, number]
|
71
|
+
}
|