@orbcharts/plugins-basic 3.0.0-alpha.45 → 3.0.0-alpha.46
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 +182 -159
- package/dist/orbcharts-plugins-basic.umd.js +7 -7
- package/dist/src/index.d.ts +5 -1
- package/dist/{orbcharts-plugins-basic/src → src}/series/seriesObservables.d.ts +4 -4
- 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 +502 -502
- package/src/base/BaseGroupAxis.ts +496 -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 +121 -121
- package/src/grid/gridObservables.ts +247 -247
- package/src/grid/index.ts +15 -15
- package/src/grid/plugins/BarStack.ts +50 -50
- package/src/grid/plugins/Bars.ts +51 -51
- package/src/grid/plugins/BarsDiverging.ts +41 -41
- package/src/grid/plugins/BarsTriangle.ts +50 -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 +42 -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 +43 -43
- package/src/grid/plugins/ValueStackAxis.ts +79 -79
- package/src/grid/types.ts +120 -120
- package/src/index.ts +9 -9
- package/src/multiGrid/defaults.ts +147 -147
- package/src/multiGrid/index.ts +11 -11
- package/src/multiGrid/multiGridObservables.ts +42 -42
- package/src/multiGrid/plugins/MultiBarStack.ts +74 -74
- package/src/multiGrid/plugins/MultiBars.ts +73 -73
- package/src/multiGrid/plugins/MultiBarsTriangle.ts +73 -73
- package/src/multiGrid/plugins/MultiDots.ts +60 -60
- package/src/multiGrid/plugins/MultiGridLegend.ts +89 -89
- package/src/multiGrid/plugins/MultiGroupAxis.ts +65 -65
- package/src/multiGrid/plugins/MultiLineAreas.ts +62 -62
- package/src/multiGrid/plugins/MultiLines.ts +61 -61
- package/src/multiGrid/plugins/MultiValueAxis.ts +65 -65
- package/src/multiGrid/plugins/OverlappingValueAxes.ts +169 -169
- package/src/multiGrid/types.ts +67 -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 +109 -109
- package/src/series/index.ts +6 -6
- package/src/series/plugins/Bubbles.ts +602 -571
- package/src/series/plugins/Pie.ts +555 -548
- package/src/series/plugins/PieEventTexts.ts +258 -258
- package/src/series/plugins/PieLabels.ts +335 -335
- package/src/series/plugins/SeriesLegend.ts +59 -59
- package/src/series/seriesObservables.ts +145 -145
- package/src/series/seriesUtils.ts +50 -50
- package/src/series/types.ts +67 -67
- 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 -16
- package/tsconfig.prod.json +13 -13
- package/vite.config.js +49 -49
- package/dist/orbcharts-plugins-basic/src/index.d.ts +0 -5
- /package/dist/{orbcharts-plugins-basic/src → src}/base/BaseBarStack.d.ts +0 -0
- /package/dist/{orbcharts-plugins-basic/src → src}/base/BaseBars.d.ts +0 -0
- /package/dist/{orbcharts-plugins-basic/src → src}/base/BaseBarsTriangle.d.ts +0 -0
- /package/dist/{orbcharts-plugins-basic/src → src}/base/BaseDots.d.ts +0 -0
- /package/dist/{orbcharts-plugins-basic/src → src}/base/BaseGroupArea.d.ts +0 -0
- /package/dist/{orbcharts-plugins-basic/src → src}/base/BaseGroupAxis.d.ts +0 -0
- /package/dist/{orbcharts-plugins-basic/src → src}/base/BaseLegend.d.ts +0 -0
- /package/dist/{orbcharts-plugins-basic/src → src}/base/BaseLineAreas.d.ts +0 -0
- /package/dist/{orbcharts-plugins-basic/src → src}/base/BaseLines.d.ts +0 -0
- /package/dist/{orbcharts-plugins-basic/src → src}/base/BaseValueAxis.d.ts +0 -0
- /package/dist/{orbcharts-plugins-basic/src → src}/base/types.d.ts +0 -0
- /package/dist/{orbcharts-plugins-basic/src → src}/grid/defaults.d.ts +0 -0
- /package/dist/{orbcharts-plugins-basic/src → src}/grid/gridObservables.d.ts +0 -0
- /package/dist/{orbcharts-plugins-basic/src → src}/grid/index.d.ts +0 -0
- /package/dist/{orbcharts-plugins-basic/src → src}/grid/plugins/BarStack.d.ts +0 -0
- /package/dist/{orbcharts-plugins-basic/src → src}/grid/plugins/Bars.d.ts +0 -0
- /package/dist/{orbcharts-plugins-basic/src → src}/grid/plugins/BarsDiverging.d.ts +0 -0
- /package/dist/{orbcharts-plugins-basic/src → src}/grid/plugins/BarsTriangle.d.ts +0 -0
- /package/dist/{orbcharts-plugins-basic/src → src}/grid/plugins/Dots.d.ts +0 -0
- /package/dist/{orbcharts-plugins-basic/src → src}/grid/plugins/GridLegend.d.ts +0 -0
- /package/dist/{orbcharts-plugins-basic/src → src}/grid/plugins/GroupAux.d.ts +0 -0
- /package/dist/{orbcharts-plugins-basic/src → src}/grid/plugins/GroupAxis.d.ts +0 -0
- /package/dist/{orbcharts-plugins-basic/src → src}/grid/plugins/LineAreas.d.ts +0 -0
- /package/dist/{orbcharts-plugins-basic/src → src}/grid/plugins/Lines.d.ts +0 -0
- /package/dist/{orbcharts-plugins-basic/src → src}/grid/plugins/Ranking.d.ts +0 -0
- /package/dist/{orbcharts-plugins-basic/src → src}/grid/plugins/RankingAxis.d.ts +0 -0
- /package/dist/{orbcharts-plugins-basic/src → src}/grid/plugins/ScalingArea.d.ts +0 -0
- /package/dist/{orbcharts-plugins-basic/src → src}/grid/plugins/ValueAxis.d.ts +0 -0
- /package/dist/{orbcharts-plugins-basic/src → src}/grid/plugins/ValueStackAxis.d.ts +0 -0
- /package/dist/{orbcharts-plugins-basic/src → src}/grid/types.d.ts +0 -0
- /package/dist/{orbcharts-plugins-basic/src → src}/multiGrid/defaults.d.ts +0 -0
- /package/dist/{orbcharts-plugins-basic/src → src}/multiGrid/index.d.ts +0 -0
- /package/dist/{orbcharts-plugins-basic/src → src}/multiGrid/multiGridObservables.d.ts +0 -0
- /package/dist/{orbcharts-plugins-basic/src → src}/multiGrid/plugins/MultiBarStack.d.ts +0 -0
- /package/dist/{orbcharts-plugins-basic/src → src}/multiGrid/plugins/MultiBars.d.ts +0 -0
- /package/dist/{orbcharts-plugins-basic/src → src}/multiGrid/plugins/MultiBarsTriangle.d.ts +0 -0
- /package/dist/{orbcharts-plugins-basic/src → src}/multiGrid/plugins/MultiDots.d.ts +0 -0
- /package/dist/{orbcharts-plugins-basic/src → src}/multiGrid/plugins/MultiGridLegend.d.ts +0 -0
- /package/dist/{orbcharts-plugins-basic/src → src}/multiGrid/plugins/MultiGroupAxis.d.ts +0 -0
- /package/dist/{orbcharts-plugins-basic/src → src}/multiGrid/plugins/MultiLineAreas.d.ts +0 -0
- /package/dist/{orbcharts-plugins-basic/src → src}/multiGrid/plugins/MultiLines.d.ts +0 -0
- /package/dist/{orbcharts-plugins-basic/src → src}/multiGrid/plugins/MultiValueAxis.d.ts +0 -0
- /package/dist/{orbcharts-plugins-basic/src → src}/multiGrid/plugins/OverlappingValueAxes.d.ts +0 -0
- /package/dist/{orbcharts-plugins-basic/src → src}/multiGrid/types.d.ts +0 -0
- /package/dist/{orbcharts-plugins-basic/src → src}/multiValue/index.d.ts +0 -0
- /package/dist/{orbcharts-plugins-basic/src → src}/multiValue/plugins/Scatter.d.ts +0 -0
- /package/dist/{orbcharts-plugins-basic/src → src}/multiValue/plugins/ScatterAxes.d.ts +0 -0
- /package/dist/{orbcharts-plugins-basic/src → src}/noneData/defaults.d.ts +0 -0
- /package/dist/{orbcharts-plugins-basic/src → src}/noneData/index.d.ts +0 -0
- /package/dist/{orbcharts-plugins-basic/src → src}/noneData/plugins/Container.d.ts +0 -0
- /package/dist/{orbcharts-plugins-basic/src → src}/noneData/plugins/Tooltip.d.ts +0 -0
- /package/dist/{orbcharts-plugins-basic/src → src}/noneData/types.d.ts +0 -0
- /package/dist/{orbcharts-plugins-basic/src → src}/relationship/index.d.ts +0 -0
- /package/dist/{orbcharts-plugins-basic/src → src}/relationship/plugins/Relationship.d.ts +0 -0
- /package/dist/{orbcharts-plugins-basic/src → src}/series/defaults.d.ts +0 -0
- /package/dist/{orbcharts-plugins-basic/src → src}/series/index.d.ts +0 -0
- /package/dist/{orbcharts-plugins-basic/src → src}/series/plugins/Bubbles.d.ts +0 -0
- /package/dist/{orbcharts-plugins-basic/src → src}/series/plugins/Pie.d.ts +0 -0
- /package/dist/{orbcharts-plugins-basic/src → src}/series/plugins/PieEventTexts.d.ts +0 -0
- /package/dist/{orbcharts-plugins-basic/src → src}/series/plugins/PieLabels.d.ts +0 -0
- /package/dist/{orbcharts-plugins-basic/src → src}/series/plugins/SeriesLegend.d.ts +0 -0
- /package/dist/{orbcharts-plugins-basic/src → src}/series/plugins/Waffle.d.ts +0 -0
- /package/dist/{orbcharts-plugins-basic/src → src}/series/seriesUtils.d.ts +0 -0
- /package/dist/{orbcharts-plugins-basic/src → src}/series/types.d.ts +0 -0
- /package/dist/{orbcharts-plugins-basic/src → src}/tree/defaults.d.ts +0 -0
- /package/dist/{orbcharts-plugins-basic/src → src}/tree/index.d.ts +0 -0
- /package/dist/{orbcharts-plugins-basic/src → src}/tree/plugins/TreeLegend.d.ts +0 -0
- /package/dist/{orbcharts-plugins-basic/src → src}/tree/plugins/TreeMap.d.ts +0 -0
- /package/dist/{orbcharts-plugins-basic/src → src}/tree/types.d.ts +0 -0
- /package/dist/{orbcharts-plugins-basic/src → src}/utils/commonUtils.d.ts +0 -0
- /package/dist/{orbcharts-plugins-basic/src → src}/utils/d3Graphics.d.ts +0 -0
- /package/dist/{orbcharts-plugins-basic/src → src}/utils/d3Utils.d.ts +0 -0
- /package/dist/{orbcharts-plugins-basic/src → src}/utils/observables.d.ts +0 -0
- /package/dist/{orbcharts-plugins-basic/src → src}/utils/orbchartsUtils.d.ts +0 -0
- /package/dist/{orbcharts-plugins-basic/vite.config.d.ts → vite.config.d.ts} +0 -0
@@ -1,247 +1,247 @@
|
|
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
|
-
}
|
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
|
+
}
|
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 { BarsDiverging } from './plugins/BarsDiverging'
|
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 { BarsDiverging } from './plugins/BarsDiverging'
|
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,51 +1,51 @@
|
|
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 isSeriesSeprate$ = observer.fullDataFormatter$.pipe(
|
19
|
-
takeUntil(destroy$),
|
20
|
-
map(d => d.grid.separateSeries),
|
21
|
-
distinctUntilChanged(),
|
22
|
-
shareReplay(1)
|
23
|
-
)
|
24
|
-
|
25
|
-
const unsubscribeBaseBars = createBaseBarStack(pluginName, {
|
26
|
-
selection,
|
27
|
-
computedData$: observer.computedData$,
|
28
|
-
computedLayoutData$: observer.computedLayoutData$,
|
29
|
-
visibleComputedData$: observer.visibleComputedData$,
|
30
|
-
visibleComputedLayoutData$: observer.visibleComputedLayoutData$,
|
31
|
-
seriesLabels$: observer.seriesLabels$,
|
32
|
-
SeriesDataMap$: observer.SeriesDataMap$,
|
33
|
-
GroupDataMap$: observer.GroupDataMap$,
|
34
|
-
fullParams$: observer.fullParams$,
|
35
|
-
fullDataFormatter$: observer.fullDataFormatter$,
|
36
|
-
fullChartParams$: observer.fullChartParams$,
|
37
|
-
gridAxesTransform$: observer.gridAxesTransform$,
|
38
|
-
gridGraphicTransform$: observer.gridGraphicTransform$,
|
39
|
-
gridGraphicReverseScale$: observer.gridGraphicReverseScale$,
|
40
|
-
gridAxesSize$: observer.gridAxesSize$,
|
41
|
-
gridHighlight$: observer.gridHighlight$,
|
42
|
-
gridContainerPosition$: observer.gridContainerPosition$,
|
43
|
-
isSeriesSeprate$,
|
44
|
-
event$: subject.event$,
|
45
|
-
})
|
46
|
-
|
47
|
-
return () => {
|
48
|
-
destroy$.next(undefined)
|
49
|
-
unsubscribeBaseBars()
|
50
|
-
}
|
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 isSeriesSeprate$ = observer.fullDataFormatter$.pipe(
|
19
|
+
takeUntil(destroy$),
|
20
|
+
map(d => d.grid.separateSeries),
|
21
|
+
distinctUntilChanged(),
|
22
|
+
shareReplay(1)
|
23
|
+
)
|
24
|
+
|
25
|
+
const unsubscribeBaseBars = createBaseBarStack(pluginName, {
|
26
|
+
selection,
|
27
|
+
computedData$: observer.computedData$,
|
28
|
+
computedLayoutData$: observer.computedLayoutData$,
|
29
|
+
visibleComputedData$: observer.visibleComputedData$,
|
30
|
+
visibleComputedLayoutData$: observer.visibleComputedLayoutData$,
|
31
|
+
seriesLabels$: observer.seriesLabels$,
|
32
|
+
SeriesDataMap$: observer.SeriesDataMap$,
|
33
|
+
GroupDataMap$: observer.GroupDataMap$,
|
34
|
+
fullParams$: observer.fullParams$,
|
35
|
+
fullDataFormatter$: observer.fullDataFormatter$,
|
36
|
+
fullChartParams$: observer.fullChartParams$,
|
37
|
+
gridAxesTransform$: observer.gridAxesTransform$,
|
38
|
+
gridGraphicTransform$: observer.gridGraphicTransform$,
|
39
|
+
gridGraphicReverseScale$: observer.gridGraphicReverseScale$,
|
40
|
+
gridAxesSize$: observer.gridAxesSize$,
|
41
|
+
gridHighlight$: observer.gridHighlight$,
|
42
|
+
gridContainerPosition$: observer.gridContainerPosition$,
|
43
|
+
isSeriesSeprate$,
|
44
|
+
event$: subject.event$,
|
45
|
+
})
|
46
|
+
|
47
|
+
return () => {
|
48
|
+
destroy$.next(undefined)
|
49
|
+
unsubscribeBaseBars()
|
50
|
+
}
|
51
51
|
})
|