@orbcharts/plugins-basic 3.0.0-alpha.50 → 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 +4893 -4913
- package/dist/orbcharts-plugins-basic.umd.js +7 -7
- 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/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 -123
- package/src/grid/gridObservables.ts +248 -248
- package/src/grid/index.ts +15 -15
- package/src/grid/plugins/BarStack.ts +43 -43
- package/src/grid/plugins/Bars.ts +44 -44
- package/src/grid/plugins/{BarsDiverging.ts → BarsPN.ts} +41 -41
- package/src/grid/plugins/BarsTriangle.ts +42 -42
- 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 -35
- 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 -36
- package/src/grid/plugins/ValueStackAxis.ts +38 -38
- package/src/grid/types.ts +122 -120
- package/src/index.ts +9 -9
- package/src/multiGrid/defaults.ts +152 -152
- package/src/multiGrid/index.ts +13 -13
- package/src/multiGrid/multiGridObservables.ts +44 -44
- 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 -69
- package/src/multiGrid/plugins/OverlappingValueAxes.ts +166 -166
- package/src/multiGrid/plugins/OverlappingValueStackAxes.ts +167 -167
- package/src/multiGrid/types.ts +71 -71
- 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,248 +1,248 @@
|
|
1
|
-
import * as d3 from 'd3'
|
2
|
-
import {
|
3
|
-
Observable,
|
4
|
-
Subject,
|
5
|
-
of,
|
6
|
-
takeUntil,
|
7
|
-
filter,
|
8
|
-
map,
|
9
|
-
switchMap,
|
10
|
-
combineLatest,
|
11
|
-
merge,
|
12
|
-
shareReplay,
|
13
|
-
distinctUntilChanged
|
14
|
-
} from 'rxjs'
|
15
|
-
import type {
|
16
|
-
ChartParams,
|
17
|
-
HighlightTarget,
|
18
|
-
DataFormatterGrid,
|
19
|
-
ComputedDataGrid,
|
20
|
-
ComputedDatumGrid,
|
21
|
-
TransformData,
|
22
|
-
GridContainerPosition,
|
23
|
-
Layout } from '@orbcharts/core'
|
24
|
-
import { createAxisQuantizeScale } from '@orbcharts/core'
|
25
|
-
import { getClassName, getUniID } from '../utils/orbchartsUtils'
|
26
|
-
|
27
|
-
// grid選取器
|
28
|
-
export const gridSelectionsObservable = ({ selection, pluginName, clipPathID, seriesLabels$, gridContainerPosition$, gridAxesTransform$, gridGraphicTransform$ }: {
|
29
|
-
selection: d3.Selection<any, unknown, any, unknown>
|
30
|
-
pluginName: string
|
31
|
-
clipPathID: string
|
32
|
-
// computedData$: Observable<ComputedDataGrid>
|
33
|
-
seriesLabels$: Observable<string[]>
|
34
|
-
gridContainerPosition$: Observable<GridContainerPosition[]>
|
35
|
-
gridAxesTransform$: Observable<TransformData>
|
36
|
-
gridGraphicTransform$: Observable<TransformData>
|
37
|
-
}) => {
|
38
|
-
const seriesClassName = getClassName(pluginName, 'series')
|
39
|
-
const axesClassName = getClassName(pluginName, 'axes')
|
40
|
-
const graphicClassName = getClassName(pluginName, 'graphic')
|
41
|
-
|
42
|
-
const seriesSelection$ = seriesLabels$.pipe(
|
43
|
-
map((existSeriesLabels, i) => {
|
44
|
-
return selection
|
45
|
-
.selectAll<SVGGElement, string>(`g.${seriesClassName}`)
|
46
|
-
.data(existSeriesLabels, d => d)
|
47
|
-
.join(
|
48
|
-
enter => {
|
49
|
-
return enter
|
50
|
-
.append('g')
|
51
|
-
.classed(seriesClassName, true)
|
52
|
-
.each((d, i, g) => {
|
53
|
-
const axesSelection = d3.select(g[i])
|
54
|
-
.selectAll<SVGGElement, ComputedDatumGrid[]>(`g.${axesClassName}`)
|
55
|
-
.data([i])
|
56
|
-
.join(
|
57
|
-
enter => {
|
58
|
-
return enter
|
59
|
-
.append('g')
|
60
|
-
.classed(axesClassName, true)
|
61
|
-
.attr('clip-path', `url(#${clipPathID})`)
|
62
|
-
.each((d, i, g) => {
|
63
|
-
const defsSelection = d3.select(g[i])
|
64
|
-
.selectAll<SVGDefsElement, any>('defs')
|
65
|
-
.data([i])
|
66
|
-
.join('defs')
|
67
|
-
|
68
|
-
const graphicGSelection = d3.select(g[i])
|
69
|
-
.selectAll<SVGGElement, any>('g')
|
70
|
-
.data([i])
|
71
|
-
.join('g')
|
72
|
-
.classed(graphicClassName, true)
|
73
|
-
})
|
74
|
-
},
|
75
|
-
update => update,
|
76
|
-
exit => exit.remove()
|
77
|
-
)
|
78
|
-
})
|
79
|
-
},
|
80
|
-
update => update,
|
81
|
-
exit => exit.remove()
|
82
|
-
)
|
83
|
-
}),
|
84
|
-
shareReplay(1)
|
85
|
-
)
|
86
|
-
|
87
|
-
combineLatest({
|
88
|
-
seriesSelection: seriesSelection$,
|
89
|
-
gridContainerPosition: gridContainerPosition$
|
90
|
-
}).pipe(
|
91
|
-
switchMap(async d => d)
|
92
|
-
).subscribe(data => {
|
93
|
-
data.seriesSelection
|
94
|
-
.transition()
|
95
|
-
.attr('transform', (d, i) => {
|
96
|
-
const gridContainerPosition = data.gridContainerPosition[i] ?? data.gridContainerPosition[0]
|
97
|
-
const translate = gridContainerPosition.translate
|
98
|
-
const scale = gridContainerPosition.scale
|
99
|
-
return `translate(${translate[0]}, ${translate[1]}) scale(${scale[0]}, ${scale[1]})`
|
100
|
-
})
|
101
|
-
})
|
102
|
-
|
103
|
-
const axesSelection$ = combineLatest({
|
104
|
-
seriesSelection: seriesSelection$,
|
105
|
-
gridAxesTransform: gridAxesTransform$
|
106
|
-
}).pipe(
|
107
|
-
switchMap(async d => d),
|
108
|
-
map(data => {
|
109
|
-
return data.seriesSelection
|
110
|
-
.select<SVGGElement>(`g.${axesClassName}`)
|
111
|
-
.style('transform', data.gridAxesTransform.value)
|
112
|
-
}),
|
113
|
-
shareReplay(1)
|
114
|
-
)
|
115
|
-
const defsSelection$ = axesSelection$.pipe(
|
116
|
-
map(axesSelection => {
|
117
|
-
return axesSelection.select<SVGDefsElement>('defs')
|
118
|
-
}),
|
119
|
-
shareReplay(1)
|
120
|
-
)
|
121
|
-
const graphicGSelection$ = combineLatest({
|
122
|
-
axesSelection: axesSelection$,
|
123
|
-
gridGraphicTransform: gridGraphicTransform$
|
124
|
-
}).pipe(
|
125
|
-
switchMap(async d => d),
|
126
|
-
map(data => {
|
127
|
-
const graphicGSelection = data.axesSelection
|
128
|
-
.select<SVGGElement>(`g.${graphicClassName}`)
|
129
|
-
graphicGSelection
|
130
|
-
.transition()
|
131
|
-
.duration(50)
|
132
|
-
.style('transform', data.gridGraphicTransform.value)
|
133
|
-
return graphicGSelection
|
134
|
-
}),
|
135
|
-
shareReplay(1)
|
136
|
-
)
|
137
|
-
|
138
|
-
return {
|
139
|
-
seriesSelection$,
|
140
|
-
axesSelection$,
|
141
|
-
defsSelection$,
|
142
|
-
graphicGSelection$
|
143
|
-
}
|
144
|
-
}
|
145
|
-
|
146
|
-
// 由事件取得group data的function
|
147
|
-
export const gridGroupPositionFnObservable = ({ fullDataFormatter$, gridAxesSize$, computedData$, fullChartParams$ }: {
|
148
|
-
fullDataFormatter$: Observable<DataFormatterGrid>
|
149
|
-
gridAxesSize$: Observable<{
|
150
|
-
width: number;
|
151
|
-
height: number;
|
152
|
-
}>
|
153
|
-
computedData$: Observable<ComputedDataGrid>
|
154
|
-
// GroupDataMap$: Observable<Map<string, ComputedDatumGrid[]>>
|
155
|
-
fullChartParams$: Observable<ChartParams>
|
156
|
-
}): Observable<(event: any) => { groupIndex: number; groupLabel: string }> => {
|
157
|
-
const destroy$ = new Subject()
|
158
|
-
|
159
|
-
// 顯示範圍內的group labels
|
160
|
-
const scaleRangeGroupLabels$: Observable<string[]> = new Observable(subscriber => {
|
161
|
-
combineLatest({
|
162
|
-
dataFormatter: fullDataFormatter$,
|
163
|
-
computedData: computedData$
|
164
|
-
}).pipe(
|
165
|
-
takeUntil(destroy$),
|
166
|
-
switchMap(async (d) => d),
|
167
|
-
).subscribe(data => {
|
168
|
-
const groupMin = 0
|
169
|
-
const groupMax = data.computedData[0] ? data.computedData[0].length - 1 : 0
|
170
|
-
const groupScaleDomainMin = data.dataFormatter.grid.groupAxis.scaleDomain[0] === 'auto'
|
171
|
-
? groupMin - data.dataFormatter.grid.groupAxis.scalePadding
|
172
|
-
: data.dataFormatter.grid.groupAxis.scaleDomain[0] as number - data.dataFormatter.grid.groupAxis.scalePadding
|
173
|
-
const groupScaleDomainMax = data.dataFormatter.grid.groupAxis.scaleDomain[1] === 'auto'
|
174
|
-
? groupMax + data.dataFormatter.grid.groupAxis.scalePadding
|
175
|
-
: data.dataFormatter.grid.groupAxis.scaleDomain[1] as number + data.dataFormatter.grid.groupAxis.scalePadding
|
176
|
-
|
177
|
-
// const groupingAmount = data.computedData[0]
|
178
|
-
// ? data.computedData[0].length
|
179
|
-
// : 0
|
180
|
-
|
181
|
-
let _labels = data.dataFormatter.grid.seriesDirection === 'row'
|
182
|
-
? (data.computedData[0] ?? []).map(d => d.groupLabel)
|
183
|
-
: data.computedData.map(d => d[0].groupLabel)
|
184
|
-
|
185
|
-
const _axisLabels =
|
186
|
-
// new Array(groupingAmount).fill(0)
|
187
|
-
// .map((d, i) => {
|
188
|
-
// return _labels[i] != null
|
189
|
-
// ? _labels[i]
|
190
|
-
// : String(i) // 沒有label則用序列號填充
|
191
|
-
// })
|
192
|
-
_labels
|
193
|
-
.filter((d, i) => {
|
194
|
-
return i >= groupScaleDomainMin && i <= groupScaleDomainMax
|
195
|
-
})
|
196
|
-
subscriber.next(_axisLabels)
|
197
|
-
})
|
198
|
-
})
|
199
|
-
|
200
|
-
return new Observable<(event: any) => { groupIndex: number; groupLabel: string }>(subscriber => {
|
201
|
-
combineLatest({
|
202
|
-
dataFormatter: fullDataFormatter$,
|
203
|
-
axisSize: gridAxesSize$,
|
204
|
-
fullChartParams: fullChartParams$,
|
205
|
-
scaleRangeGroupLabels: scaleRangeGroupLabels$
|
206
|
-
}).pipe(
|
207
|
-
takeUntil(destroy$),
|
208
|
-
switchMap(async (d) => d),
|
209
|
-
).subscribe(data => {
|
210
|
-
|
211
|
-
const reverse = data.dataFormatter.grid.valueAxis.position === 'right'
|
212
|
-
|| data.dataFormatter.grid.valueAxis.position === 'bottom'
|
213
|
-
? true : false
|
214
|
-
|
215
|
-
// 比例尺座標對應非連續資料索引
|
216
|
-
const groupIndexScale = createAxisQuantizeScale({
|
217
|
-
axisLabels: data.scaleRangeGroupLabels,
|
218
|
-
axisWidth: data.axisSize.width,
|
219
|
-
reverse
|
220
|
-
})
|
221
|
-
|
222
|
-
// 依比例尺位置計算座標
|
223
|
-
const axisValuePredicate = (event: any) => {
|
224
|
-
return data.dataFormatter.grid.groupAxis.position === 'bottom'
|
225
|
-
|| data.dataFormatter.grid.groupAxis.position === 'top'
|
226
|
-
? event.offsetX - data.fullChartParams.padding.left
|
227
|
-
: event.offsetY - data.fullChartParams.padding.top
|
228
|
-
}
|
229
|
-
|
230
|
-
// 比例尺座標取得groupData的function
|
231
|
-
const createEventGroupData: (event: any) => { groupIndex: number; groupLabel: string } = (event: any) => {
|
232
|
-
const axisValue = axisValuePredicate(event)
|
233
|
-
const groupIndex = groupIndexScale(axisValue)
|
234
|
-
return {
|
235
|
-
groupIndex,
|
236
|
-
groupLabel: data.scaleRangeGroupLabels[groupIndex] ?? ''
|
237
|
-
}
|
238
|
-
}
|
239
|
-
|
240
|
-
subscriber.next(createEventGroupData)
|
241
|
-
|
242
|
-
return function unsubscribe () {
|
243
|
-
destroy$.next(undefined)
|
244
|
-
}
|
245
|
-
})
|
246
|
-
})
|
247
|
-
}
|
248
|
-
|
1
|
+
import * as d3 from 'd3'
|
2
|
+
import {
|
3
|
+
Observable,
|
4
|
+
Subject,
|
5
|
+
of,
|
6
|
+
takeUntil,
|
7
|
+
filter,
|
8
|
+
map,
|
9
|
+
switchMap,
|
10
|
+
combineLatest,
|
11
|
+
merge,
|
12
|
+
shareReplay,
|
13
|
+
distinctUntilChanged
|
14
|
+
} from 'rxjs'
|
15
|
+
import type {
|
16
|
+
ChartParams,
|
17
|
+
HighlightTarget,
|
18
|
+
DataFormatterGrid,
|
19
|
+
ComputedDataGrid,
|
20
|
+
ComputedDatumGrid,
|
21
|
+
TransformData,
|
22
|
+
GridContainerPosition,
|
23
|
+
Layout } from '@orbcharts/core'
|
24
|
+
import { createAxisQuantizeScale } from '@orbcharts/core'
|
25
|
+
import { getClassName, getUniID } from '../utils/orbchartsUtils'
|
26
|
+
|
27
|
+
// grid選取器
|
28
|
+
export const gridSelectionsObservable = ({ selection, pluginName, clipPathID, seriesLabels$, gridContainerPosition$, gridAxesTransform$, gridGraphicTransform$ }: {
|
29
|
+
selection: d3.Selection<any, unknown, any, unknown>
|
30
|
+
pluginName: string
|
31
|
+
clipPathID: string
|
32
|
+
// computedData$: Observable<ComputedDataGrid>
|
33
|
+
seriesLabels$: Observable<string[]>
|
34
|
+
gridContainerPosition$: Observable<GridContainerPosition[]>
|
35
|
+
gridAxesTransform$: Observable<TransformData>
|
36
|
+
gridGraphicTransform$: Observable<TransformData>
|
37
|
+
}) => {
|
38
|
+
const seriesClassName = getClassName(pluginName, 'series')
|
39
|
+
const axesClassName = getClassName(pluginName, 'axes')
|
40
|
+
const graphicClassName = getClassName(pluginName, 'graphic')
|
41
|
+
|
42
|
+
const seriesSelection$ = seriesLabels$.pipe(
|
43
|
+
map((existSeriesLabels, i) => {
|
44
|
+
return selection
|
45
|
+
.selectAll<SVGGElement, string>(`g.${seriesClassName}`)
|
46
|
+
.data(existSeriesLabels, d => d)
|
47
|
+
.join(
|
48
|
+
enter => {
|
49
|
+
return enter
|
50
|
+
.append('g')
|
51
|
+
.classed(seriesClassName, true)
|
52
|
+
.each((d, i, g) => {
|
53
|
+
const axesSelection = d3.select(g[i])
|
54
|
+
.selectAll<SVGGElement, ComputedDatumGrid[]>(`g.${axesClassName}`)
|
55
|
+
.data([i])
|
56
|
+
.join(
|
57
|
+
enter => {
|
58
|
+
return enter
|
59
|
+
.append('g')
|
60
|
+
.classed(axesClassName, true)
|
61
|
+
.attr('clip-path', `url(#${clipPathID})`)
|
62
|
+
.each((d, i, g) => {
|
63
|
+
const defsSelection = d3.select(g[i])
|
64
|
+
.selectAll<SVGDefsElement, any>('defs')
|
65
|
+
.data([i])
|
66
|
+
.join('defs')
|
67
|
+
|
68
|
+
const graphicGSelection = d3.select(g[i])
|
69
|
+
.selectAll<SVGGElement, any>('g')
|
70
|
+
.data([i])
|
71
|
+
.join('g')
|
72
|
+
.classed(graphicClassName, true)
|
73
|
+
})
|
74
|
+
},
|
75
|
+
update => update,
|
76
|
+
exit => exit.remove()
|
77
|
+
)
|
78
|
+
})
|
79
|
+
},
|
80
|
+
update => update,
|
81
|
+
exit => exit.remove()
|
82
|
+
)
|
83
|
+
}),
|
84
|
+
shareReplay(1)
|
85
|
+
)
|
86
|
+
|
87
|
+
combineLatest({
|
88
|
+
seriesSelection: seriesSelection$,
|
89
|
+
gridContainerPosition: gridContainerPosition$
|
90
|
+
}).pipe(
|
91
|
+
switchMap(async d => d)
|
92
|
+
).subscribe(data => {
|
93
|
+
data.seriesSelection
|
94
|
+
.transition()
|
95
|
+
.attr('transform', (d, i) => {
|
96
|
+
const gridContainerPosition = data.gridContainerPosition[i] ?? data.gridContainerPosition[0]
|
97
|
+
const translate = gridContainerPosition.translate
|
98
|
+
const scale = gridContainerPosition.scale
|
99
|
+
return `translate(${translate[0]}, ${translate[1]}) scale(${scale[0]}, ${scale[1]})`
|
100
|
+
})
|
101
|
+
})
|
102
|
+
|
103
|
+
const axesSelection$ = combineLatest({
|
104
|
+
seriesSelection: seriesSelection$,
|
105
|
+
gridAxesTransform: gridAxesTransform$
|
106
|
+
}).pipe(
|
107
|
+
switchMap(async d => d),
|
108
|
+
map(data => {
|
109
|
+
return data.seriesSelection
|
110
|
+
.select<SVGGElement>(`g.${axesClassName}`)
|
111
|
+
.style('transform', data.gridAxesTransform.value)
|
112
|
+
}),
|
113
|
+
shareReplay(1)
|
114
|
+
)
|
115
|
+
const defsSelection$ = axesSelection$.pipe(
|
116
|
+
map(axesSelection => {
|
117
|
+
return axesSelection.select<SVGDefsElement>('defs')
|
118
|
+
}),
|
119
|
+
shareReplay(1)
|
120
|
+
)
|
121
|
+
const graphicGSelection$ = combineLatest({
|
122
|
+
axesSelection: axesSelection$,
|
123
|
+
gridGraphicTransform: gridGraphicTransform$
|
124
|
+
}).pipe(
|
125
|
+
switchMap(async d => d),
|
126
|
+
map(data => {
|
127
|
+
const graphicGSelection = data.axesSelection
|
128
|
+
.select<SVGGElement>(`g.${graphicClassName}`)
|
129
|
+
graphicGSelection
|
130
|
+
.transition()
|
131
|
+
.duration(50)
|
132
|
+
.style('transform', data.gridGraphicTransform.value)
|
133
|
+
return graphicGSelection
|
134
|
+
}),
|
135
|
+
shareReplay(1)
|
136
|
+
)
|
137
|
+
|
138
|
+
return {
|
139
|
+
seriesSelection$,
|
140
|
+
axesSelection$,
|
141
|
+
defsSelection$,
|
142
|
+
graphicGSelection$
|
143
|
+
}
|
144
|
+
}
|
145
|
+
|
146
|
+
// 由事件取得group data的function
|
147
|
+
export const gridGroupPositionFnObservable = ({ fullDataFormatter$, gridAxesSize$, computedData$, fullChartParams$ }: {
|
148
|
+
fullDataFormatter$: Observable<DataFormatterGrid>
|
149
|
+
gridAxesSize$: Observable<{
|
150
|
+
width: number;
|
151
|
+
height: number;
|
152
|
+
}>
|
153
|
+
computedData$: Observable<ComputedDataGrid>
|
154
|
+
// GroupDataMap$: Observable<Map<string, ComputedDatumGrid[]>>
|
155
|
+
fullChartParams$: Observable<ChartParams>
|
156
|
+
}): Observable<(event: any) => { groupIndex: number; groupLabel: string }> => {
|
157
|
+
const destroy$ = new Subject()
|
158
|
+
|
159
|
+
// 顯示範圍內的group labels
|
160
|
+
const scaleRangeGroupLabels$: Observable<string[]> = new Observable(subscriber => {
|
161
|
+
combineLatest({
|
162
|
+
dataFormatter: fullDataFormatter$,
|
163
|
+
computedData: computedData$
|
164
|
+
}).pipe(
|
165
|
+
takeUntil(destroy$),
|
166
|
+
switchMap(async (d) => d),
|
167
|
+
).subscribe(data => {
|
168
|
+
const groupMin = 0
|
169
|
+
const groupMax = data.computedData[0] ? data.computedData[0].length - 1 : 0
|
170
|
+
const groupScaleDomainMin = data.dataFormatter.grid.groupAxis.scaleDomain[0] === 'auto'
|
171
|
+
? groupMin - data.dataFormatter.grid.groupAxis.scalePadding
|
172
|
+
: data.dataFormatter.grid.groupAxis.scaleDomain[0] as number - data.dataFormatter.grid.groupAxis.scalePadding
|
173
|
+
const groupScaleDomainMax = data.dataFormatter.grid.groupAxis.scaleDomain[1] === 'auto'
|
174
|
+
? groupMax + data.dataFormatter.grid.groupAxis.scalePadding
|
175
|
+
: data.dataFormatter.grid.groupAxis.scaleDomain[1] as number + data.dataFormatter.grid.groupAxis.scalePadding
|
176
|
+
|
177
|
+
// const groupingAmount = data.computedData[0]
|
178
|
+
// ? data.computedData[0].length
|
179
|
+
// : 0
|
180
|
+
|
181
|
+
let _labels = data.dataFormatter.grid.seriesDirection === 'row'
|
182
|
+
? (data.computedData[0] ?? []).map(d => d.groupLabel)
|
183
|
+
: data.computedData.map(d => d[0].groupLabel)
|
184
|
+
|
185
|
+
const _axisLabels =
|
186
|
+
// new Array(groupingAmount).fill(0)
|
187
|
+
// .map((d, i) => {
|
188
|
+
// return _labels[i] != null
|
189
|
+
// ? _labels[i]
|
190
|
+
// : String(i) // 沒有label則用序列號填充
|
191
|
+
// })
|
192
|
+
_labels
|
193
|
+
.filter((d, i) => {
|
194
|
+
return i >= groupScaleDomainMin && i <= groupScaleDomainMax
|
195
|
+
})
|
196
|
+
subscriber.next(_axisLabels)
|
197
|
+
})
|
198
|
+
})
|
199
|
+
|
200
|
+
return new Observable<(event: any) => { groupIndex: number; groupLabel: string }>(subscriber => {
|
201
|
+
combineLatest({
|
202
|
+
dataFormatter: fullDataFormatter$,
|
203
|
+
axisSize: gridAxesSize$,
|
204
|
+
fullChartParams: fullChartParams$,
|
205
|
+
scaleRangeGroupLabels: scaleRangeGroupLabels$
|
206
|
+
}).pipe(
|
207
|
+
takeUntil(destroy$),
|
208
|
+
switchMap(async (d) => d),
|
209
|
+
).subscribe(data => {
|
210
|
+
|
211
|
+
const reverse = data.dataFormatter.grid.valueAxis.position === 'right'
|
212
|
+
|| data.dataFormatter.grid.valueAxis.position === 'bottom'
|
213
|
+
? true : false
|
214
|
+
|
215
|
+
// 比例尺座標對應非連續資料索引
|
216
|
+
const groupIndexScale = createAxisQuantizeScale({
|
217
|
+
axisLabels: data.scaleRangeGroupLabels,
|
218
|
+
axisWidth: data.axisSize.width,
|
219
|
+
reverse
|
220
|
+
})
|
221
|
+
|
222
|
+
// 依比例尺位置計算座標
|
223
|
+
const axisValuePredicate = (event: any) => {
|
224
|
+
return data.dataFormatter.grid.groupAxis.position === 'bottom'
|
225
|
+
|| data.dataFormatter.grid.groupAxis.position === 'top'
|
226
|
+
? event.offsetX - data.fullChartParams.padding.left
|
227
|
+
: event.offsetY - data.fullChartParams.padding.top
|
228
|
+
}
|
229
|
+
|
230
|
+
// 比例尺座標取得groupData的function
|
231
|
+
const createEventGroupData: (event: any) => { groupIndex: number; groupLabel: string } = (event: any) => {
|
232
|
+
const axisValue = axisValuePredicate(event)
|
233
|
+
const groupIndex = groupIndexScale(axisValue)
|
234
|
+
return {
|
235
|
+
groupIndex,
|
236
|
+
groupLabel: data.scaleRangeGroupLabels[groupIndex] ?? ''
|
237
|
+
}
|
238
|
+
}
|
239
|
+
|
240
|
+
subscriber.next(createEventGroupData)
|
241
|
+
|
242
|
+
return function unsubscribe () {
|
243
|
+
destroy$.next(undefined)
|
244
|
+
}
|
245
|
+
})
|
246
|
+
})
|
247
|
+
}
|
248
|
+
|
package/src/grid/index.ts
CHANGED
@@ -1,15 +1,15 @@
|
|
1
|
-
export * from './defaults'
|
2
|
-
export * from './types'
|
3
|
-
export { Lines } from './plugins/Lines'
|
4
|
-
export { LineAreas } from './plugins/LineAreas'
|
5
|
-
export { Bars } from './plugins/Bars'
|
6
|
-
export {
|
7
|
-
export { BarStack } from './plugins/BarStack'
|
8
|
-
export { BarsTriangle } from './plugins/BarsTriangle'
|
9
|
-
export { Dots } from './plugins/Dots'
|
10
|
-
export { GridLegend } from './plugins/GridLegend'
|
11
|
-
export { GroupAxis } from './plugins/GroupAxis'
|
12
|
-
export { ValueAxis } from './plugins/ValueAxis'
|
13
|
-
export { ValueStackAxis } from './plugins/ValueStackAxis'
|
14
|
-
export { ScalingArea } from './plugins/ScalingArea'
|
15
|
-
export { GroupAux } from './plugins/GroupAux'
|
1
|
+
export * from './defaults'
|
2
|
+
export * from './types'
|
3
|
+
export { Lines } from './plugins/Lines'
|
4
|
+
export { LineAreas } from './plugins/LineAreas'
|
5
|
+
export { Bars } from './plugins/Bars'
|
6
|
+
export { BarsPN } from './plugins/BarsPN'
|
7
|
+
export { BarStack } from './plugins/BarStack'
|
8
|
+
export { BarsTriangle } from './plugins/BarsTriangle'
|
9
|
+
export { Dots } from './plugins/Dots'
|
10
|
+
export { GridLegend } from './plugins/GridLegend'
|
11
|
+
export { GroupAxis } from './plugins/GroupAxis'
|
12
|
+
export { ValueAxis } from './plugins/ValueAxis'
|
13
|
+
export { ValueStackAxis } from './plugins/ValueStackAxis'
|
14
|
+
export { ScalingArea } from './plugins/ScalingArea'
|
15
|
+
export { GroupAux } from './plugins/GroupAux'
|
@@ -1,44 +1,44 @@
|
|
1
|
-
import {
|
2
|
-
map,
|
3
|
-
distinctUntilChanged,
|
4
|
-
shareReplay,
|
5
|
-
takeUntil,
|
6
|
-
Subject,
|
7
|
-
Observable } from 'rxjs'
|
8
|
-
import { defineGridPlugin } from '@orbcharts/core'
|
9
|
-
import { DEFAULT_BAR_STACK_PARAMS } from '../defaults'
|
10
|
-
import { createBaseBarStack } from '../../base/BaseBarStack'
|
11
|
-
|
12
|
-
const pluginName = 'BarStack'
|
13
|
-
|
14
|
-
|
15
|
-
export const BarStack = defineGridPlugin(pluginName, DEFAULT_BAR_STACK_PARAMS)(({ selection, name, subject, observer }) => {
|
16
|
-
const destroy$ = new Subject()
|
17
|
-
|
18
|
-
const unsubscribeBaseBars = createBaseBarStack(pluginName, {
|
19
|
-
selection,
|
20
|
-
computedData$: observer.computedData$,
|
21
|
-
computedLayoutData$: observer.computedLayoutData$,
|
22
|
-
visibleComputedData$: observer.visibleComputedData$,
|
23
|
-
visibleComputedLayoutData$: observer.visibleComputedLayoutData$,
|
24
|
-
seriesLabels$: observer.seriesLabels$,
|
25
|
-
SeriesDataMap$: observer.SeriesDataMap$,
|
26
|
-
GroupDataMap$: observer.GroupDataMap$,
|
27
|
-
fullParams$: observer.fullParams$,
|
28
|
-
fullDataFormatter$: observer.fullDataFormatter$,
|
29
|
-
fullChartParams$: observer.fullChartParams$,
|
30
|
-
gridAxesTransform$: observer.gridAxesTransform$,
|
31
|
-
gridGraphicTransform$: observer.gridGraphicTransform$,
|
32
|
-
gridGraphicReverseScale$: observer.gridGraphicReverseScale$,
|
33
|
-
gridAxesSize$: observer.gridAxesSize$,
|
34
|
-
gridHighlight$: observer.gridHighlight$,
|
35
|
-
gridContainerPosition$: observer.gridContainerPosition$,
|
36
|
-
isSeriesSeprate$: observer.isSeriesSeprate$,
|
37
|
-
event$: subject.event$,
|
38
|
-
})
|
39
|
-
|
40
|
-
return () => {
|
41
|
-
destroy$.next(undefined)
|
42
|
-
unsubscribeBaseBars()
|
43
|
-
}
|
1
|
+
import {
|
2
|
+
map,
|
3
|
+
distinctUntilChanged,
|
4
|
+
shareReplay,
|
5
|
+
takeUntil,
|
6
|
+
Subject,
|
7
|
+
Observable } from 'rxjs'
|
8
|
+
import { defineGridPlugin } from '@orbcharts/core'
|
9
|
+
import { DEFAULT_BAR_STACK_PARAMS } from '../defaults'
|
10
|
+
import { createBaseBarStack } from '../../base/BaseBarStack'
|
11
|
+
|
12
|
+
const pluginName = 'BarStack'
|
13
|
+
|
14
|
+
|
15
|
+
export const BarStack = defineGridPlugin(pluginName, DEFAULT_BAR_STACK_PARAMS)(({ selection, name, subject, observer }) => {
|
16
|
+
const destroy$ = new Subject()
|
17
|
+
|
18
|
+
const unsubscribeBaseBars = createBaseBarStack(pluginName, {
|
19
|
+
selection,
|
20
|
+
computedData$: observer.computedData$,
|
21
|
+
computedLayoutData$: observer.computedLayoutData$,
|
22
|
+
visibleComputedData$: observer.visibleComputedData$,
|
23
|
+
visibleComputedLayoutData$: observer.visibleComputedLayoutData$,
|
24
|
+
seriesLabels$: observer.seriesLabels$,
|
25
|
+
SeriesDataMap$: observer.SeriesDataMap$,
|
26
|
+
GroupDataMap$: observer.GroupDataMap$,
|
27
|
+
fullParams$: observer.fullParams$,
|
28
|
+
fullDataFormatter$: observer.fullDataFormatter$,
|
29
|
+
fullChartParams$: observer.fullChartParams$,
|
30
|
+
gridAxesTransform$: observer.gridAxesTransform$,
|
31
|
+
gridGraphicTransform$: observer.gridGraphicTransform$,
|
32
|
+
gridGraphicReverseScale$: observer.gridGraphicReverseScale$,
|
33
|
+
gridAxesSize$: observer.gridAxesSize$,
|
34
|
+
gridHighlight$: observer.gridHighlight$,
|
35
|
+
gridContainerPosition$: observer.gridContainerPosition$,
|
36
|
+
isSeriesSeprate$: observer.isSeriesSeprate$,
|
37
|
+
event$: subject.event$,
|
38
|
+
})
|
39
|
+
|
40
|
+
return () => {
|
41
|
+
destroy$.next(undefined)
|
42
|
+
unsubscribeBaseBars()
|
43
|
+
}
|
44
44
|
})
|