@orbcharts/plugins-basic 3.0.0-alpha.30 → 3.0.0-alpha.32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/orbcharts-plugins-basic.es.js +15995 -15706
- package/dist/orbcharts-plugins-basic.umd.js +8 -8
- package/dist/src/base/BaseBarStack.d.ts +29 -0
- package/dist/src/base/BaseBars.d.ts +29 -0
- package/dist/src/base/BaseBarsTriangle.d.ts +28 -0
- package/dist/src/base/BaseLegend.d.ts +17 -6
- package/dist/src/base/BaseLines.d.ts +27 -0
- package/dist/src/base/types.d.ts +2 -2
- package/dist/src/grid/defaults.d.ts +10 -10
- package/dist/src/grid/plugins/BarStack.d.ts +1 -3
- package/dist/src/grid/plugins/Bars.d.ts +1 -3
- package/dist/src/grid/plugins/BarsTriangle.d.ts +1 -3
- package/dist/src/grid/plugins/Lines.d.ts +1 -3
- package/dist/src/grid/types.d.ts +10 -2
- package/dist/src/index.d.ts +1 -0
- package/dist/src/multiGrid/defaults.d.ts +4 -0
- package/dist/src/multiGrid/index.d.ts +4 -0
- package/dist/src/multiGrid/plugins/BarsAndLines.d.ts +1 -0
- package/dist/src/multiGrid/plugins/MultiGridLegend.d.ts +1 -0
- package/dist/src/multiGrid/types.d.ts +24 -0
- package/dist/src/series/defaults.d.ts +2 -2
- package/dist/src/series/types.d.ts +10 -2
- package/package.json +2 -2
- package/src/base/BaseBarStack.ts +699 -0
- package/src/base/BaseBars.ts +639 -0
- package/src/base/BaseBarsTriangle.ts +626 -0
- package/src/base/BaseLegend.ts +50 -20
- package/src/base/BaseLines.ts +566 -0
- package/src/base/types.ts +2 -2
- package/src/grid/defaults.ts +10 -10
- package/src/grid/plugins/BarStack.ts +18 -645
- package/src/grid/plugins/Bars.ts +17 -588
- package/src/grid/plugins/BarsTriangle.ts +16 -579
- package/src/grid/plugins/Dots.ts +2 -2
- package/src/grid/plugins/GridLegend.ts +19 -1
- package/src/grid/plugins/GroupArea.ts +2 -2
- package/src/grid/plugins/GroupAxis.ts +2 -2
- package/src/grid/plugins/Lines.ts +15 -509
- package/src/grid/plugins/ScalingArea.ts +2 -2
- package/src/grid/plugins/ValueAxis.ts +2 -2
- package/src/grid/plugins/ValueStackAxis.ts +2 -2
- package/src/grid/types.ts +12 -2
- package/src/index.ts +1 -0
- package/src/multiGrid/defaults.ts +33 -0
- package/src/multiGrid/index.ts +4 -0
- package/src/multiGrid/plugins/BarsAndLines.ts +110 -0
- package/src/multiGrid/plugins/BarsTriangleAndLines.ts +0 -0
- package/src/multiGrid/plugins/DivergingValueAxes.ts +0 -0
- package/src/multiGrid/plugins/FirstGroupScaleAxis.ts +0 -0
- package/src/multiGrid/plugins/MultiGridLegend.ts +89 -0
- package/src/multiGrid/plugins/TwoValueScaleAxes.ts +0 -0
- package/src/multiGrid/types.ts +27 -0
- package/src/series/defaults.ts +2 -2
- package/src/series/plugins/Bubbles.ts +2 -2
- package/src/series/plugins/Pie.ts +2 -2
- package/src/series/plugins/SeriesLegend.ts +19 -1
- package/src/series/types.ts +12 -2
- /package/dist/src/multiGrid/plugins/{DivergingAxes.d.ts → BarStackAndLines.d.ts} +0 -0
- /package/dist/src/multiGrid/plugins/{TwoScaleAxes.d.ts → BarsTriangleAndLines.d.ts} +0 -0
- /package/dist/src/multiGrid/plugins/{TwoScales.d.ts → DivergingValueAxes.d.ts} +0 -0
- /package/{src/multiGrid/plugins/DivergingAxes.ts → dist/src/multiGrid/plugins/FirstGroupScaleAxis.d.ts} +0 -0
- /package/{src/multiGrid/plugins/TwoScaleAxes.ts → dist/src/multiGrid/plugins/TwoValueScaleAxes.d.ts} +0 -0
- /package/src/multiGrid/plugins/{TwoScales.ts → BarStackAndLines.ts} +0 -0
@@ -1,528 +1,34 @@
|
|
1
|
-
import * as d3 from 'd3'
|
2
1
|
import {
|
3
|
-
Observable,
|
4
|
-
combineLatest,
|
5
|
-
switchMap,
|
6
|
-
distinctUntilChanged,
|
7
|
-
filter,
|
8
|
-
first,
|
9
|
-
share,
|
10
|
-
shareReplay,
|
11
|
-
map,
|
12
|
-
takeUntil,
|
13
2
|
Subject } from 'rxjs'
|
14
3
|
import {
|
15
4
|
defineGridPlugin } from '@orbcharts/core'
|
16
|
-
import
|
17
|
-
|
18
|
-
ChartParams,
|
19
|
-
Layout } from '@orbcharts/core'
|
20
|
-
import type { LinesParams } from '../types'
|
21
|
-
import { DEFAULT_LINES_PLUGIN_PARAMS } from '../defaults'
|
22
|
-
import { getD3TransitionEase } from '../../utils/d3Utils'
|
23
|
-
import { getClassName, getUniID } from '../../utils/orbchartsUtils'
|
24
|
-
import { gridGroupPositionFnObservable } from '../gridObservables'
|
25
|
-
|
26
|
-
type ClipPathDatum = {
|
27
|
-
id: string;
|
28
|
-
// x: number;
|
29
|
-
// y: number;
|
30
|
-
width: number;
|
31
|
-
height: number;
|
32
|
-
}
|
5
|
+
import { DEFAULT_LINES_PARAMS } from '../defaults'
|
6
|
+
import { createBaseLines } from '../../base/BaseLines'
|
33
7
|
|
34
8
|
const pluginName = 'Lines'
|
35
|
-
const gClassName = getClassName(pluginName, 'g')
|
36
|
-
const pathClassName = getClassName(pluginName, 'path')
|
37
|
-
|
38
|
-
function createLinePath (lineCurve: string = 'curveLinear'): d3.Line<ComputedDatumGrid> {
|
39
|
-
return d3.line<ComputedDatumGrid>()
|
40
|
-
.x((d) => d.axisX)
|
41
|
-
.y((d) => d.axisY)
|
42
|
-
.curve((d3 as any)[lineCurve])
|
43
|
-
}
|
44
|
-
|
45
|
-
// function renderGraphicG ({ selection }) {
|
46
|
-
|
47
|
-
// }
|
48
|
-
|
49
|
-
// 依無值的資料分段
|
50
|
-
function makeSegmentData (data: ComputedDatumGrid[]): ComputedDatumGrid[][] {
|
51
|
-
let segmentData: ComputedDatumGrid[][] = [[]]
|
52
|
-
|
53
|
-
let currentIndex = 0
|
54
|
-
for (let i in data) {
|
55
|
-
if (data[i].visible == false || data[i].value === undefined || data[i].value === null) {
|
56
|
-
// 換下一段的 index
|
57
|
-
if (segmentData[currentIndex].length) {
|
58
|
-
currentIndex ++
|
59
|
-
segmentData[currentIndex] = []
|
60
|
-
}
|
61
|
-
continue
|
62
|
-
}
|
63
|
-
segmentData[currentIndex].push(data[i])
|
64
|
-
}
|
65
|
-
|
66
|
-
return segmentData
|
67
|
-
}
|
68
|
-
|
69
|
-
|
70
|
-
function renderLine ({ selection, segmentData, linePath, params }: {
|
71
|
-
selection: d3.Selection<SVGGElement, unknown, any, unknown>
|
72
|
-
segmentData: ComputedDatumGrid[][]
|
73
|
-
linePath: d3.Line<ComputedDatumGrid>
|
74
|
-
params: LinesParams
|
75
|
-
}): d3.Selection<SVGPathElement, ComputedDatumGrid[], any, any> {
|
76
|
-
// if (!data[0]) {
|
77
|
-
// return undefined
|
78
|
-
// }
|
79
|
-
|
80
|
-
const lines = selection
|
81
|
-
.selectAll<SVGPathElement, ComputedDatumGrid[]>('path')
|
82
|
-
.data(segmentData, (d, i) => d.length ? `${d[0].id}_${d[d.length - 1].id}` : i) // 以線段起迄id結合為線段id
|
83
|
-
.join(
|
84
|
-
enter => {
|
85
|
-
return enter
|
86
|
-
.append<SVGPathElement>('path')
|
87
|
-
.classed(pathClassName, true)
|
88
|
-
.attr("fill","none")
|
89
|
-
.attr('pointer-events', 'visibleStroke') // 只對線條產生事件
|
90
|
-
.style('vector-effect', 'non-scaling-stroke')
|
91
|
-
.style('cursor', 'pointer')
|
92
|
-
},
|
93
|
-
update => update,
|
94
|
-
exit => exit.remove()
|
95
|
-
)
|
96
|
-
.attr("stroke-width", params.lineWidth)
|
97
|
-
.attr("stroke", (d, i) => d[0] && d[0].color)
|
98
|
-
.attr("d", (d) => {
|
99
|
-
return linePath(d)
|
100
|
-
})
|
101
|
-
|
102
|
-
return lines
|
103
|
-
}
|
104
|
-
|
105
|
-
function highlightLine ({ selection, seriesLabel, fullChartParams }: {
|
106
|
-
selection: d3.Selection<any, string, any, any>
|
107
|
-
seriesLabel: string | null
|
108
|
-
fullChartParams: ChartParams
|
109
|
-
}) {
|
110
|
-
selection.interrupt('highlight')
|
111
|
-
if (!seriesLabel) {
|
112
|
-
// remove highlight
|
113
|
-
selection
|
114
|
-
.transition('highlight')
|
115
|
-
.duration(200)
|
116
|
-
.style('opacity', 1)
|
117
|
-
return
|
118
|
-
}
|
119
|
-
|
120
|
-
selection
|
121
|
-
.each((d, i, n) => {
|
122
|
-
if (d === seriesLabel) {
|
123
|
-
d3.select(n[i])
|
124
|
-
.style('opacity', 1)
|
125
|
-
} else {
|
126
|
-
d3.select(n[i])
|
127
|
-
.style('opacity', fullChartParams.styles.unhighlightedOpacity)
|
128
|
-
}
|
129
|
-
})
|
130
|
-
}
|
131
|
-
|
132
|
-
function renderClipPath ({ defsSelection, clipPathData, transitionDuration, transitionEase }: {
|
133
|
-
defsSelection: d3.Selection<SVGDefsElement, any, any, any>
|
134
|
-
clipPathData: ClipPathDatum[]
|
135
|
-
transitionDuration: number
|
136
|
-
transitionEase: string
|
137
|
-
}) {
|
138
|
-
const clipPath = defsSelection
|
139
|
-
.selectAll<SVGClipPathElement, Layout>('clipPath')
|
140
|
-
.data(clipPathData)
|
141
|
-
.join(
|
142
|
-
enter => {
|
143
|
-
return enter
|
144
|
-
.append('clipPath')
|
145
|
-
},
|
146
|
-
update => update,
|
147
|
-
exit => exit.remove()
|
148
|
-
)
|
149
|
-
.attr('id', d => d.id)
|
150
|
-
.each((d, i, g) => {
|
151
|
-
const rect = d3.select(g[i])
|
152
|
-
.selectAll<SVGRectElement, typeof d>('rect')
|
153
|
-
.data([d])
|
154
|
-
.join(
|
155
|
-
enter => {
|
156
|
-
const enterSelection = enter
|
157
|
-
.append('rect')
|
158
|
-
enterSelection
|
159
|
-
.transition()
|
160
|
-
.duration(transitionDuration)
|
161
|
-
.ease(getD3TransitionEase(transitionEase))
|
162
|
-
// .delay(100) // @Q@ 不知為何如果沒加 delay位置會有點跑掉
|
163
|
-
.tween('tween', (_d, _i, _g) => {
|
164
|
-
return (t) => {
|
165
|
-
const transitionWidth = _d.width * t
|
166
|
-
|
167
|
-
enterSelection
|
168
|
-
.attr('x', 0)
|
169
|
-
.attr('y', 0)
|
170
|
-
.attr('width', _d => transitionWidth)
|
171
|
-
.attr('height', _d => _d.height)
|
172
|
-
}
|
173
|
-
})
|
174
|
-
return enterSelection
|
175
|
-
},
|
176
|
-
update => {
|
177
|
-
return update
|
178
|
-
.attr('x', 0)
|
179
|
-
.attr('y', 0)
|
180
|
-
.attr('width', _d => _d.width)
|
181
|
-
.attr('height', _d => _d.height)
|
182
|
-
},
|
183
|
-
exit => exit.remove()
|
184
|
-
)
|
185
|
-
})
|
186
|
-
|
187
|
-
}
|
188
9
|
|
10
|
+
export const Lines = defineGridPlugin(pluginName, DEFAULT_LINES_PARAMS)(({ selection, name, observer, subject }) => {
|
189
11
|
|
190
|
-
export const Lines = defineGridPlugin(pluginName, DEFAULT_LINES_PLUGIN_PARAMS)(({ selection, name, observer, subject }) => {
|
191
|
-
// const axisGUpdate = selection
|
192
|
-
// .selectAll('g')
|
193
|
-
// .data()
|
194
12
|
const destroy$ = new Subject()
|
195
13
|
|
196
|
-
const
|
197
|
-
|
198
|
-
|
199
|
-
.
|
200
|
-
.
|
201
|
-
|
202
|
-
const graphicGSelection: d3.Selection<SVGGElement, any, any, any> = axisSelection.append('g')
|
203
|
-
const graphicSelection$: Subject<d3.Selection<SVGGElement, string, any, any>> = new Subject()
|
204
|
-
// let pathSelection: d3.Selection<SVGPathElement, ComputedDatumGrid[], any, any> | undefined
|
205
|
-
// .style('transform', 'translate(0px, 0px) scale(1)')
|
206
|
-
|
207
|
-
observer.gridAxesTransform$
|
208
|
-
.pipe(
|
209
|
-
takeUntil(destroy$),
|
210
|
-
map(d => d.value),
|
211
|
-
distinctUntilChanged()
|
212
|
-
).subscribe(d => {
|
213
|
-
axisSelection
|
214
|
-
.style('transform', d)
|
215
|
-
})
|
216
|
-
|
217
|
-
observer.gridGraphicTransform$
|
218
|
-
.pipe(
|
219
|
-
takeUntil(destroy$),
|
220
|
-
map(d => d.value),
|
221
|
-
distinctUntilChanged()
|
222
|
-
).subscribe(d => {
|
223
|
-
graphicGSelection
|
224
|
-
.transition()
|
225
|
-
.duration(50)
|
226
|
-
.style('transform', d)
|
227
|
-
})
|
228
|
-
|
229
|
-
const linePath$: Observable<d3.Line<ComputedDatumGrid>> = new Observable(subscriber => {
|
230
|
-
const paramsSubscription = observer.fullParams$
|
231
|
-
.pipe(
|
232
|
-
takeUntil(destroy$)
|
233
|
-
)
|
234
|
-
.subscribe(d => {
|
235
|
-
if (!d) return
|
236
|
-
const linePath = createLinePath(d.lineCurve)
|
237
|
-
subscriber.next(linePath)
|
238
|
-
})
|
239
|
-
return () => {
|
240
|
-
paramsSubscription.unsubscribe()
|
241
|
-
}
|
242
|
-
})
|
243
|
-
|
244
|
-
// 顯示範圍內的series labels
|
245
|
-
const seriesLabels$: Observable<string[]> = new Observable(subscriber => {
|
246
|
-
observer.computedData$.pipe(
|
247
|
-
takeUntil(destroy$),
|
248
|
-
// 轉換後會退訂前一個未完成的訂閱事件,因此可以取到「同時間」最後一次的訂閱事件
|
249
|
-
switchMap(async (d) => d),
|
250
|
-
).subscribe(data => {
|
251
|
-
const labels = data[0] && data[0][0]
|
252
|
-
? data.map(d => d[0].seriesLabel)
|
253
|
-
: []
|
254
|
-
subscriber.next(labels)
|
255
|
-
})
|
256
|
-
})
|
257
|
-
|
258
|
-
// const axisSize$ = gridAxisSizeObservable({
|
259
|
-
// fullDataFormatter$,
|
260
|
-
// computedLayout$
|
261
|
-
// })
|
262
|
-
|
263
|
-
const transitionDuration$ = observer.fullChartParams$
|
264
|
-
.pipe(
|
265
|
-
map(d => d.transitionDuration),
|
266
|
-
distinctUntilChanged()
|
267
|
-
)
|
268
|
-
|
269
|
-
const transitionEase$ = observer.fullChartParams$
|
270
|
-
.pipe(
|
271
|
-
map(d => d.transitionEase),
|
272
|
-
distinctUntilChanged()
|
273
|
-
)
|
274
|
-
|
275
|
-
const clipPathSubscription = combineLatest({
|
276
|
-
seriesLabels: seriesLabels$,
|
277
|
-
axisSize: observer.gridAxesSize$,
|
278
|
-
transitionDuration: transitionDuration$,
|
279
|
-
transitionEase: transitionEase$
|
280
|
-
}).pipe(
|
281
|
-
takeUntil(destroy$),
|
282
|
-
// 轉換後會退訂前一個未完成的訂閱事件,因此可以取到「同時間」最後一次的訂閱事件
|
283
|
-
switchMap(async (d) => d),
|
284
|
-
).subscribe(data => {
|
285
|
-
// 外層的遮罩
|
286
|
-
const clipPathBox = [{
|
287
|
-
id: clipPathID,
|
288
|
-
width: data.axisSize.width,
|
289
|
-
height: data.axisSize.height
|
290
|
-
}]
|
291
|
-
// 各別線條的遮罩(各別動畫)
|
292
|
-
const clipPathData = clipPathBox.concat(
|
293
|
-
data.seriesLabels.map(d => {
|
294
|
-
return {
|
295
|
-
id: `orbcharts__clipPath_${d}`,
|
296
|
-
width: data.axisSize.width,
|
297
|
-
height: data.axisSize.height
|
298
|
-
}
|
299
|
-
})
|
300
|
-
)
|
301
|
-
renderClipPath({
|
302
|
-
defsSelection,
|
303
|
-
clipPathData,
|
304
|
-
transitionDuration: data.transitionDuration,
|
305
|
-
transitionEase: data.transitionEase
|
306
|
-
})
|
307
|
-
})
|
308
|
-
|
309
|
-
// const SeriesDataMap$ = observer.computedData$.pipe(
|
310
|
-
// map(d => makeGridSeriesDataMap(d))
|
311
|
-
// )
|
312
|
-
|
313
|
-
// const GroupDataMap$ = observer.computedData$.pipe(
|
314
|
-
// map(d => makeGridGroupDataMap(d))
|
315
|
-
// )
|
316
|
-
|
317
|
-
const DataMap$ = observer.computedData$.pipe(
|
318
|
-
map(d => {
|
319
|
-
const DataMap: Map<string, ComputedDatumGrid> = new Map()
|
320
|
-
d.flat().forEach(_d => DataMap.set(_d.id, _d))
|
321
|
-
return DataMap
|
322
|
-
})
|
323
|
-
)
|
324
|
-
|
325
|
-
// 取得事件座標的group資料
|
326
|
-
const gridGroupPositionFn$ = gridGroupPositionFnObservable({
|
14
|
+
const unsubscribeBaseBars = createBaseLines(pluginName, {
|
15
|
+
selection,
|
16
|
+
computedData$: observer.computedData$,
|
17
|
+
SeriesDataMap$: observer.SeriesDataMap$,
|
18
|
+
GroupDataMap$: observer.GroupDataMap$,
|
19
|
+
fullParams$: observer.fullParams$,
|
327
20
|
fullDataFormatter$: observer.fullDataFormatter$,
|
21
|
+
fullChartParams$: observer.fullChartParams$,
|
22
|
+
gridAxesTransform$: observer.gridAxesTransform$,
|
23
|
+
gridGraphicTransform$: observer.gridGraphicTransform$,
|
328
24
|
gridAxesSize$: observer.gridAxesSize$,
|
329
|
-
|
330
|
-
|
331
|
-
})
|
332
|
-
|
333
|
-
const highlightTarget$ = observer.fullChartParams$.pipe(
|
334
|
-
takeUntil(destroy$),
|
335
|
-
map(d => d.highlightTarget),
|
336
|
-
distinctUntilChanged()
|
337
|
-
)
|
338
|
-
|
339
|
-
const graphSubscription = combineLatest({
|
340
|
-
seriesLabels: seriesLabels$,
|
341
|
-
computedData: observer.computedData$,
|
342
|
-
SeriesDataMap: observer.SeriesDataMap$,
|
343
|
-
GroupDataMap: observer.GroupDataMap$,
|
344
|
-
linePath: linePath$,
|
345
|
-
params: observer.fullParams$,
|
346
|
-
highlightTarget: highlightTarget$,
|
347
|
-
gridGroupPositionFn: gridGroupPositionFn$,
|
348
|
-
}).pipe(
|
349
|
-
takeUntil(destroy$),
|
350
|
-
// 轉換後會退訂前一個未完成的訂閱事件,因此可以取到「同時間」最後一次的訂閱事件
|
351
|
-
switchMap(async (d) => d),
|
352
|
-
).subscribe(data => {
|
353
|
-
|
354
|
-
const updateGraphic = graphicGSelection
|
355
|
-
.selectAll<SVGGElement, number>('g')
|
356
|
-
.data(data.seriesLabels, (d, i) => d)
|
357
|
-
const enterGraphic = updateGraphic.enter()
|
358
|
-
.append('g')
|
359
|
-
.classed(gClassName, true)
|
360
|
-
updateGraphic.exit().remove()
|
361
|
-
const graphicSelection = updateGraphic.merge(enterGraphic)
|
362
|
-
.attr('clip-path', (d, i) => `url(#orbcharts__clipPath_${d})`)
|
363
|
-
|
364
|
-
// 繪圖
|
365
|
-
graphicSelection.each((d, i, all) => {
|
366
|
-
// 將資料分段
|
367
|
-
const segmentData = makeSegmentData(data.computedData[i] ?? [])
|
368
|
-
|
369
|
-
const pathSelection = renderLine({
|
370
|
-
selection: d3.select(all[i]),
|
371
|
-
linePath: data.linePath,
|
372
|
-
segmentData: segmentData,
|
373
|
-
params: data.params
|
374
|
-
})
|
375
|
-
|
376
|
-
pathSelection
|
377
|
-
.on('mouseover', (event, datum) => {
|
378
|
-
event.stopPropagation()
|
379
|
-
|
380
|
-
const seriesLabel = datum[0] ? datum[0].seriesLabel : ''
|
381
|
-
const { groupIndex, groupLabel } = data.gridGroupPositionFn(event)
|
382
|
-
const groupData = data.GroupDataMap.get(groupLabel)!
|
383
|
-
const targetDatum = groupData.find(d => d.seriesLabel === seriesLabel)
|
384
|
-
const _datum = targetDatum ?? datum[0]
|
385
|
-
|
386
|
-
subject.event$.next({
|
387
|
-
type: 'grid',
|
388
|
-
eventName: 'mouseover',
|
389
|
-
pluginName: name,
|
390
|
-
highlightTarget: data.highlightTarget,
|
391
|
-
datum: _datum,
|
392
|
-
series: data.SeriesDataMap.get(_datum.seriesLabel)!,
|
393
|
-
seriesIndex: _datum.seriesIndex,
|
394
|
-
seriesLabel: _datum.seriesLabel,
|
395
|
-
groups: data.GroupDataMap.get(_datum.groupLabel)!,
|
396
|
-
groupIndex: _datum.groupIndex,
|
397
|
-
groupLabel: _datum.groupLabel,
|
398
|
-
event,
|
399
|
-
data: data.computedData
|
400
|
-
})
|
401
|
-
})
|
402
|
-
.on('mousemove', (event, datum) => {
|
403
|
-
event.stopPropagation()
|
404
|
-
|
405
|
-
const seriesLabel = datum[0] ? datum[0].seriesLabel : ''
|
406
|
-
const { groupIndex, groupLabel } = data.gridGroupPositionFn(event)
|
407
|
-
const groupData = data.GroupDataMap.get(groupLabel)!
|
408
|
-
const targetDatum = groupData.find(d => d.seriesLabel === seriesLabel)
|
409
|
-
const _datum = targetDatum ?? datum[0]
|
410
|
-
|
411
|
-
subject.event$.next({
|
412
|
-
type: 'grid',
|
413
|
-
eventName: 'mousemove',
|
414
|
-
pluginName: name,
|
415
|
-
highlightTarget: data.highlightTarget,
|
416
|
-
datum: _datum,
|
417
|
-
series: data.SeriesDataMap.get(_datum.seriesLabel)!,
|
418
|
-
seriesIndex: _datum.seriesIndex,
|
419
|
-
seriesLabel: _datum.seriesLabel,
|
420
|
-
groups: data.GroupDataMap.get(_datum.groupLabel)!,
|
421
|
-
groupIndex: _datum.groupIndex,
|
422
|
-
groupLabel: _datum.groupLabel,
|
423
|
-
event,
|
424
|
-
data: data.computedData
|
425
|
-
})
|
426
|
-
})
|
427
|
-
.on('mouseout', (event, datum) => {
|
428
|
-
event.stopPropagation()
|
429
|
-
|
430
|
-
const seriesLabel = datum[0] ? datum[0].seriesLabel : ''
|
431
|
-
const { groupIndex, groupLabel } = data.gridGroupPositionFn(event)
|
432
|
-
const groupData = data.GroupDataMap.get(groupLabel)!
|
433
|
-
const targetDatum = groupData.find(d => d.seriesLabel === seriesLabel)
|
434
|
-
const _datum = targetDatum ?? datum[0]
|
435
|
-
|
436
|
-
subject.event$.next({
|
437
|
-
type: 'grid',
|
438
|
-
eventName: 'mouseout',
|
439
|
-
pluginName: name,
|
440
|
-
highlightTarget: data.highlightTarget,
|
441
|
-
datum: _datum,
|
442
|
-
series: data.SeriesDataMap.get(_datum.seriesLabel)!,
|
443
|
-
seriesIndex: _datum.seriesIndex,
|
444
|
-
seriesLabel: _datum.seriesLabel,
|
445
|
-
groups: data.GroupDataMap.get(_datum.groupLabel)!,
|
446
|
-
groupIndex: _datum.groupIndex,
|
447
|
-
groupLabel: _datum.groupLabel,
|
448
|
-
event,
|
449
|
-
data: data.computedData
|
450
|
-
})
|
451
|
-
})
|
452
|
-
.on('click', (event, datum) => {
|
453
|
-
event.stopPropagation()
|
454
|
-
|
455
|
-
const seriesLabel = datum[0] ? datum[0].seriesLabel : ''
|
456
|
-
const { groupIndex, groupLabel } = data.gridGroupPositionFn(event)
|
457
|
-
const groupData = data.GroupDataMap.get(groupLabel)!
|
458
|
-
const targetDatum = groupData.find(d => d.seriesLabel === seriesLabel)
|
459
|
-
const _datum = targetDatum ?? datum[0]
|
460
|
-
|
461
|
-
subject.event$.next({
|
462
|
-
type: 'grid',
|
463
|
-
eventName: 'click',
|
464
|
-
pluginName: name,
|
465
|
-
highlightTarget: data.highlightTarget,
|
466
|
-
datum: _datum,
|
467
|
-
series: data.SeriesDataMap.get(_datum.seriesLabel)!,
|
468
|
-
seriesIndex: _datum.seriesIndex,
|
469
|
-
seriesLabel: _datum.seriesLabel,
|
470
|
-
groups: data.GroupDataMap.get(_datum.groupLabel)!,
|
471
|
-
groupIndex: _datum.groupIndex,
|
472
|
-
groupLabel: _datum.groupLabel,
|
473
|
-
event,
|
474
|
-
data: data.computedData
|
475
|
-
})
|
476
|
-
})
|
477
|
-
|
478
|
-
})
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
graphicSelection$.next(graphicSelection)
|
483
|
-
|
484
|
-
|
485
|
-
// pathSelection = renderLine({
|
486
|
-
// selection: graphicSelection,
|
487
|
-
// linePath: d.linePath,
|
488
|
-
// data: d.computedData
|
489
|
-
// })
|
490
|
-
})
|
491
|
-
|
492
|
-
// const datumList$ = observer.computedData$.pipe(
|
493
|
-
// takeUntil(destroy$),
|
494
|
-
// map(d => d.flat())
|
495
|
-
// )
|
496
|
-
// const highlight$ = highlightObservable({ datumList$, fullChartParams$, event$: store.event$ })
|
497
|
-
const highlightSubscription = observer.gridHighlight$.subscribe()
|
498
|
-
|
499
|
-
observer.fullChartParams$.pipe(
|
500
|
-
takeUntil(destroy$),
|
501
|
-
filter(d => d.highlightTarget === 'series'),
|
502
|
-
switchMap(d => combineLatest({
|
503
|
-
graphicSelection: graphicSelection$,
|
504
|
-
highlight: observer.gridHighlight$,
|
505
|
-
DataMap: DataMap$,
|
506
|
-
fullChartParams: observer.fullChartParams$
|
507
|
-
}).pipe(
|
508
|
-
takeUntil(destroy$),
|
509
|
-
switchMap(async d => d)
|
510
|
-
))
|
511
|
-
).subscribe(data => {
|
512
|
-
const datum = data.DataMap.get(data.highlight[0])
|
513
|
-
// if (!datum) {
|
514
|
-
// return
|
515
|
-
// }
|
516
|
-
highlightLine({
|
517
|
-
selection: data.graphicSelection,
|
518
|
-
seriesLabel: (datum && datum.seriesLabel) ? datum.seriesLabel : null,
|
519
|
-
fullChartParams: data.fullChartParams
|
520
|
-
})
|
25
|
+
gridHighlight$: observer.gridHighlight$,
|
26
|
+
event$: subject.event$,
|
521
27
|
})
|
522
28
|
|
523
29
|
|
524
30
|
return () => {
|
525
|
-
highlightSubscription.unsubscribe()
|
526
31
|
destroy$.next(undefined)
|
32
|
+
unsubscribeBaseBars()
|
527
33
|
}
|
528
34
|
})
|
@@ -11,14 +11,14 @@ import {
|
|
11
11
|
Subject } from 'rxjs'
|
12
12
|
import {
|
13
13
|
defineGridPlugin } from '@orbcharts/core'
|
14
|
-
import {
|
14
|
+
import { DEFAULT_SCALING_AREA_PARAMS } from '../defaults'
|
15
15
|
import { getClassName, getUniID } from '../../utils/orbchartsUtils'
|
16
16
|
import { createAxisPointScale, createAxisLinearScale } from '@orbcharts/core'
|
17
17
|
|
18
18
|
const pluginName = 'ScalingArea'
|
19
19
|
const rectClassName = getClassName(pluginName, 'rect')
|
20
20
|
|
21
|
-
export const ScalingArea = defineGridPlugin(pluginName,
|
21
|
+
export const ScalingArea = defineGridPlugin(pluginName, DEFAULT_SCALING_AREA_PARAMS)(({ selection, rootSelection, name, observer, subject }) => {
|
22
22
|
|
23
23
|
const destroy$ = new Subject()
|
24
24
|
|
@@ -16,7 +16,7 @@ import type {
|
|
16
16
|
ChartParams,
|
17
17
|
TransformData } from '@orbcharts/core'
|
18
18
|
import type { ValueAxisParams } from '../types'
|
19
|
-
import {
|
19
|
+
import { DEFAULT_VALUE_AXIS_PARAMS } from '../defaults'
|
20
20
|
import { parseTickFormatValue } from '../../utils/d3Utils'
|
21
21
|
import { getColor, getMinAndMaxValue, getClassName, getUniID } from '../../utils/orbchartsUtils'
|
22
22
|
|
@@ -123,7 +123,7 @@ function renderLinearAxis ({ selection, fullParams, tickTextAlign, axisLabelAlig
|
|
123
123
|
}
|
124
124
|
|
125
125
|
|
126
|
-
export const ValueAxis = defineGridPlugin(pluginName,
|
126
|
+
export const ValueAxis = defineGridPlugin(pluginName, DEFAULT_VALUE_AXIS_PARAMS)(({ selection, name, observer, subject }) => {
|
127
127
|
|
128
128
|
const destroy$ = new Subject()
|
129
129
|
|
@@ -16,7 +16,7 @@ import type {
|
|
16
16
|
ChartParams,
|
17
17
|
TransformData } from '@orbcharts/core'
|
18
18
|
import type { ValueStackAxisParams } from '../types'
|
19
|
-
import {
|
19
|
+
import { DEFAULT_VALUE_STACK_AXIS_PARAMS } from '../defaults'
|
20
20
|
import { getMinAndMax } from '../../utils/commonUtils'
|
21
21
|
import { parseTickFormatValue } from '../../utils/d3Utils'
|
22
22
|
import { getColor, getClassName } from '../../utils/orbchartsUtils'
|
@@ -125,7 +125,7 @@ function renderLinearAxis ({ selection, fullParams, tickTextAlign, axisLabelAlig
|
|
125
125
|
}
|
126
126
|
|
127
127
|
|
128
|
-
export const ValueStackAxis = defineGridPlugin(pluginName,
|
128
|
+
export const ValueStackAxis = defineGridPlugin(pluginName, DEFAULT_VALUE_STACK_AXIS_PARAMS)(({ selection, name, observer, subject }) => {
|
129
129
|
|
130
130
|
const destroy$ = new Subject()
|
131
131
|
|
package/src/grid/types.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import type { ColorType } from '@orbcharts/core'
|
2
|
-
import type { BaseLegendParams } from '../base/BaseLegend'
|
2
|
+
// import type { BaseLegendParams } from '../base/BaseLegend'
|
3
3
|
|
4
4
|
// export type LineType = 'line' | 'area' | 'gradientArea'
|
5
5
|
// export type BarType = 'rect' | 'triangle'
|
@@ -101,4 +101,14 @@ export interface ScalingAreaParams {
|
|
101
101
|
|
102
102
|
}
|
103
103
|
|
104
|
-
export interface GridLegendParams
|
104
|
+
export interface GridLegendParams {
|
105
|
+
position: 'top' | 'bottom' | 'left' | 'right'
|
106
|
+
justify: 'start' | 'center' | 'end'
|
107
|
+
padding: number
|
108
|
+
backgroundFill: ColorType
|
109
|
+
backgroundStroke: ColorType
|
110
|
+
gap: number
|
111
|
+
listRectWidth: number
|
112
|
+
listRectHeight: number
|
113
|
+
listRectRadius: number
|
114
|
+
}
|
package/src/index.ts
CHANGED
@@ -0,0 +1,33 @@
|
|
1
|
+
import type { BarsAndLinesParams, MultiGridLegendParams } from './types'
|
2
|
+
|
3
|
+
export const DEFAULT_BARS_AND_LINES_PARAMS: BarsAndLinesParams = {
|
4
|
+
bars: {
|
5
|
+
barWidth: 0,
|
6
|
+
barPadding: 1,
|
7
|
+
barGroupPadding: 40,
|
8
|
+
barRadius: false,
|
9
|
+
},
|
10
|
+
lines: {
|
11
|
+
lineCurve: 'curveLinear',
|
12
|
+
lineWidth: 2
|
13
|
+
}
|
14
|
+
}
|
15
|
+
|
16
|
+
export const DEFAULT_MULTI_GRID_LEGEND_PARAMS: MultiGridLegendParams = {
|
17
|
+
position: 'right',
|
18
|
+
justify: 'end',
|
19
|
+
padding: 28,
|
20
|
+
backgroundFill: 'none',
|
21
|
+
backgroundStroke: 'none',
|
22
|
+
gap: 10,
|
23
|
+
listRectWidth: 14,
|
24
|
+
listRectHeight: 14,
|
25
|
+
listRectRadius: 0,
|
26
|
+
gridList: [
|
27
|
+
{
|
28
|
+
listRectWidth: 14,
|
29
|
+
listRectHeight: 14,
|
30
|
+
listRectRadius: 0,
|
31
|
+
}
|
32
|
+
]
|
33
|
+
}
|
package/src/multiGrid/index.ts
CHANGED