@orbcharts/plugins-basic 3.0.0-alpha.25 → 3.0.0-alpha.27
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/orbcharts-plugins-basic.es.js +9529 -9837
- package/dist/orbcharts-plugins-basic.umd.js +11 -11
- package/dist/src/base/BaseLegend.d.ts +15 -0
- package/dist/src/base/types.d.ts +3 -0
- package/dist/src/grid/defaults.d.ts +2 -1
- package/dist/src/grid/index.d.ts +1 -0
- package/dist/src/grid/plugins/GridLegend.d.ts +1 -0
- package/dist/src/grid/types.d.ts +3 -0
- package/dist/src/series/defaults.d.ts +2 -1
- package/dist/src/series/index.d.ts +1 -0
- package/dist/src/series/plugins/SeriesLegend.d.ts +1 -0
- package/dist/src/series/types.d.ts +3 -0
- package/dist/src/utils/orbchartsUtils.d.ts +1 -0
- package/package.json +3 -2
- package/src/base/BaseLegend.ts +543 -0
- package/src/base/types.ts +3 -0
- package/src/grid/defaults.ts +17 -2
- package/src/grid/index.ts +1 -0
- package/src/grid/plugins/GridLegend.ts +40 -0
- package/src/grid/types.ts +2 -0
- package/src/series/defaults.ts +18 -2
- package/src/series/index.ts +2 -1
- package/src/series/plugins/Bubbles.ts +0 -3
- package/src/series/plugins/Pie.ts +0 -4
- package/src/series/plugins/PieLabels.ts +0 -4
- package/src/series/plugins/SeriesLegend.ts +40 -0
- package/src/series/types.ts +3 -0
- package/src/utils/orbchartsUtils.ts +23 -7
package/src/grid/defaults.ts
CHANGED
@@ -8,7 +8,8 @@ import type {
|
|
8
8
|
GroupingAxisParams,
|
9
9
|
ValueAxisParams,
|
10
10
|
ValueStackAxisParams,
|
11
|
-
ScalingAreaParams
|
11
|
+
ScalingAreaParams,
|
12
|
+
GridLegendParams } from './types'
|
12
13
|
|
13
14
|
export const DEFAULT_LINES_PLUGIN_PARAMS: LinesPluginParams = {
|
14
15
|
lineCurve: 'curveLinear',
|
@@ -92,4 +93,18 @@ export const DEFAULT_VALUE_STACK_AXIS_PLUGIN_PARAMS: ValueStackAxisParams = DEFA
|
|
92
93
|
|
93
94
|
export const DEFAULT_SCALING_AREA_PLUGIN_PARAMS: ScalingAreaParams = {
|
94
95
|
|
95
|
-
}
|
96
|
+
}
|
97
|
+
|
98
|
+
export const DEFAULT_GRID_LEGEND_PARAMS: GridLegendParams = {
|
99
|
+
position: 'right',
|
100
|
+
justify: 'end',
|
101
|
+
padding: 28,
|
102
|
+
// offset: [0, 0],
|
103
|
+
backgroundFill: 'none',
|
104
|
+
backgroundStroke: 'none',
|
105
|
+
gap: 10,
|
106
|
+
listRectWidth: 14,
|
107
|
+
listRectHeight: 14,
|
108
|
+
listRectRadius: 0,
|
109
|
+
// highlightEvent: false
|
110
|
+
}
|
package/src/grid/index.ts
CHANGED
@@ -5,6 +5,7 @@ export { Bars } from './plugins/Bars'
|
|
5
5
|
export { BarStack } from './plugins/BarStack'
|
6
6
|
export { BarsTriangle } from './plugins/BarsTriangle'
|
7
7
|
export { Dots } from './plugins/Dots'
|
8
|
+
export { GridLegend } from './plugins/GridLegend'
|
8
9
|
export { GroupAxis } from './plugins/GroupAxis'
|
9
10
|
export { ValueAxis } from './plugins/ValueAxis'
|
10
11
|
export { ValueStackAxis } from './plugins/ValueStackAxis'
|
@@ -0,0 +1,40 @@
|
|
1
|
+
import * as d3 from 'd3'
|
2
|
+
import {
|
3
|
+
combineLatest,
|
4
|
+
map,
|
5
|
+
switchMap,
|
6
|
+
takeUntil,
|
7
|
+
Observable,
|
8
|
+
Subject } from 'rxjs'
|
9
|
+
import {
|
10
|
+
defineGridPlugin } from '@orbcharts/core'
|
11
|
+
import { DEFAULT_GRID_LEGEND_PARAMS } from '../defaults'
|
12
|
+
import { createBaseLegend } from '../../base/BaseLegend'
|
13
|
+
|
14
|
+
const pluginName = 'GridLegend'
|
15
|
+
|
16
|
+
export const GridLegend = defineGridPlugin(pluginName, DEFAULT_GRID_LEGEND_PARAMS)(({ selection, rootSelection, observer, subject }) => {
|
17
|
+
|
18
|
+
const destroy$ = new Subject()
|
19
|
+
|
20
|
+
const seriesLabels$: Observable<string[]> = observer.SeriesDataMap$.pipe(
|
21
|
+
takeUntil(destroy$),
|
22
|
+
map(data => {
|
23
|
+
return Array.from(data.keys())
|
24
|
+
})
|
25
|
+
)
|
26
|
+
|
27
|
+
const unsubscribeBaseLegend = createBaseLegend(pluginName, {
|
28
|
+
rootSelection,
|
29
|
+
seriesLabels$,
|
30
|
+
fullParams$: observer.fullParams$,
|
31
|
+
layout$: observer.layout$,
|
32
|
+
fullChartParams$: observer.fullChartParams$
|
33
|
+
})
|
34
|
+
|
35
|
+
return () => {
|
36
|
+
destroy$.next(undefined)
|
37
|
+
unsubscribeBaseLegend()
|
38
|
+
}
|
39
|
+
})
|
40
|
+
|
package/src/grid/types.ts
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
import type { ColorType } from '@orbcharts/core'
|
2
|
+
import type { BaseLegendParams } from '../base/BaseLegend'
|
2
3
|
|
3
4
|
// export type LineType = 'line' | 'area' | 'gradientArea'
|
4
5
|
// export type BarType = 'rect' | 'triangle'
|
@@ -100,3 +101,4 @@ export interface ScalingAreaParams {
|
|
100
101
|
|
101
102
|
}
|
102
103
|
|
104
|
+
export interface GridLegendParams extends BaseLegendParams {}
|
package/src/series/defaults.ts
CHANGED
@@ -1,10 +1,12 @@
|
|
1
1
|
import type { ComputedDatumSeries, EventSeries, EventName, ColorType } from '@orbcharts/core'
|
2
|
-
import {
|
2
|
+
import type {
|
3
3
|
BubblesPluginParams,
|
4
4
|
PiePluginParams,
|
5
5
|
PieEventTextsPluginParams,
|
6
|
-
PieLabelsPluginParams
|
6
|
+
PieLabelsPluginParams,
|
7
|
+
SeriesLegendParams } from './types'
|
7
8
|
|
9
|
+
|
8
10
|
export const DEFAULT_BUBBLES_PLUGIN_PARAMS: BubblesPluginParams = {
|
9
11
|
force: {
|
10
12
|
strength: 0.03, // 泡泡引力
|
@@ -80,3 +82,17 @@ export const DEFAULT_PIE_LABELS_PARAMS: PieLabelsPluginParams = {
|
|
80
82
|
labelColorType: 'series',
|
81
83
|
labelFn: d => String(d.value),
|
82
84
|
}
|
85
|
+
|
86
|
+
export const DEFAULT_SERIES_LEGEND_PARAMS: SeriesLegendParams = {
|
87
|
+
position: 'right',
|
88
|
+
justify: 'end',
|
89
|
+
padding: 28,
|
90
|
+
// offset: [0, 0],
|
91
|
+
backgroundFill: 'none',
|
92
|
+
backgroundStroke: 'none',
|
93
|
+
gap: 10,
|
94
|
+
listRectWidth: 14,
|
95
|
+
listRectHeight: 14,
|
96
|
+
listRectRadius: 0,
|
97
|
+
// highlightEvent: false
|
98
|
+
}
|
package/src/series/index.ts
CHANGED
@@ -3,4 +3,5 @@ export * from './types'
|
|
3
3
|
export { Bubbles } from './plugins/Bubbles'
|
4
4
|
export { Pie } from './plugins/Pie'
|
5
5
|
export { PieEventTexts } from './plugins/PieEventTexts'
|
6
|
-
export { PieLabels } from './plugins/PieLabels'
|
6
|
+
export { PieLabels } from './plugins/PieLabels'
|
7
|
+
export { SeriesLegend } from './plugins/SeriesLegend'
|
@@ -506,8 +506,6 @@ export const Bubbles = defineSeriesPlugin('Bubbles', DEFAULT_BUBBLES_PLUGIN_PARA
|
|
506
506
|
bubblesSelection$.next(bubblesSelection)
|
507
507
|
})
|
508
508
|
|
509
|
-
// const highlight$ = highlightObservable({ datumList$: computedData$, fullChartParams$, event$: store.event$ })
|
510
|
-
const highlightSubscription = observer.seriesHighlight$.subscribe()
|
511
509
|
combineLatest({
|
512
510
|
bubblesSelection: bubblesSelection$,
|
513
511
|
bubblesData: bubblesData$,
|
@@ -548,6 +546,5 @@ export const Bubbles = defineSeriesPlugin('Bubbles', DEFAULT_BUBBLES_PLUGIN_PARA
|
|
548
546
|
|
549
547
|
return () => {
|
550
548
|
destroy$.next(undefined)
|
551
|
-
highlightSubscription.unsubscribe()
|
552
549
|
}
|
553
550
|
})
|
@@ -508,9 +508,6 @@ export const Pie = defineSeriesPlugin(pluginName, DEFAULT_PIE_PLUGIN_PARAMS)(({
|
|
508
508
|
// arcMouseover: data.arcMouseover
|
509
509
|
// })
|
510
510
|
// })
|
511
|
-
|
512
|
-
// const highlight$ = highlightObservable({ datumList$: computedData$, fullChartParams$, event$: store.event$ })
|
513
|
-
const highlightSubscription = observer.seriesHighlight$.subscribe()
|
514
511
|
|
515
512
|
combineLatest({
|
516
513
|
pathSelection: pathSelection$,
|
@@ -598,6 +595,5 @@ export const Pie = defineSeriesPlugin(pluginName, DEFAULT_PIE_PLUGIN_PARAMS)(({
|
|
598
595
|
|
599
596
|
return () => {
|
600
597
|
destroy$.next(undefined)
|
601
|
-
highlightSubscription.unsubscribe()
|
602
598
|
}
|
603
599
|
})
|
@@ -263,9 +263,6 @@ export const PieLabels = defineSeriesPlugin(pluginName, DEFAULT_PIE_LABELS_PARAM
|
|
263
263
|
labelSelection$.next(labelSelection)
|
264
264
|
|
265
265
|
})
|
266
|
-
|
267
|
-
// const highlight$ = highlightObservable({ datumList$: computedData$, fullChartParams$, event$: store.event$ })
|
268
|
-
const highlightSubscription = observer.seriesHighlight$.subscribe()
|
269
266
|
|
270
267
|
combineLatest({
|
271
268
|
labelSelection: labelSelection$,
|
@@ -284,6 +281,5 @@ export const PieLabels = defineSeriesPlugin(pluginName, DEFAULT_PIE_LABELS_PARAM
|
|
284
281
|
|
285
282
|
return () => {
|
286
283
|
destroy$.next(undefined)
|
287
|
-
highlightSubscription.unsubscribe()
|
288
284
|
}
|
289
285
|
})
|
@@ -0,0 +1,40 @@
|
|
1
|
+
import * as d3 from 'd3'
|
2
|
+
import {
|
3
|
+
combineLatest,
|
4
|
+
map,
|
5
|
+
switchMap,
|
6
|
+
takeUntil,
|
7
|
+
Observable,
|
8
|
+
Subject } from 'rxjs'
|
9
|
+
import {
|
10
|
+
defineSeriesPlugin } from '@orbcharts/core'
|
11
|
+
import { DEFAULT_SERIES_LEGEND_PARAMS } from '../defaults'
|
12
|
+
import { createBaseLegend } from '../../base/BaseLegend'
|
13
|
+
|
14
|
+
const pluginName = 'SeriesLegend'
|
15
|
+
|
16
|
+
export const SeriesLegend = defineSeriesPlugin(pluginName, DEFAULT_SERIES_LEGEND_PARAMS)(({ selection, rootSelection, observer, subject }) => {
|
17
|
+
|
18
|
+
const destroy$ = new Subject()
|
19
|
+
|
20
|
+
const seriesLabels$: Observable<string[]> = observer.SeriesDataMap$.pipe(
|
21
|
+
takeUntil(destroy$),
|
22
|
+
map(data => {
|
23
|
+
return Array.from(data.keys())
|
24
|
+
})
|
25
|
+
)
|
26
|
+
|
27
|
+
const unsubscribeBaseLegend = createBaseLegend(pluginName, {
|
28
|
+
rootSelection,
|
29
|
+
seriesLabels$,
|
30
|
+
fullParams$: observer.fullParams$,
|
31
|
+
layout$: observer.layout$,
|
32
|
+
fullChartParams$: observer.fullChartParams$
|
33
|
+
})
|
34
|
+
|
35
|
+
return () => {
|
36
|
+
destroy$.next(undefined)
|
37
|
+
unsubscribeBaseLegend()
|
38
|
+
}
|
39
|
+
})
|
40
|
+
|
package/src/series/types.ts
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
import type { ComputedDatumSeries, EventSeries, EventName, ColorType } from '@orbcharts/core'
|
2
|
+
import type { BaseLegendParams } from '../base/BaseLegend'
|
2
3
|
|
3
4
|
export type ScaleType = 'area' | 'radius'
|
4
5
|
|
@@ -51,3 +52,5 @@ export interface PieLabelsPluginParams {
|
|
51
52
|
labelFn: ((d: ComputedDatumSeries) => string)
|
52
53
|
labelColorType: ColorType
|
53
54
|
}
|
55
|
+
|
56
|
+
export interface SeriesLegendParams extends BaseLegendParams {}
|
@@ -9,7 +9,7 @@ export function getMinAndMaxValue (data: ComputedDatumBase[]): [number, number]
|
|
9
9
|
return getMinAndMax(arr)
|
10
10
|
}
|
11
11
|
|
12
|
-
|
12
|
+
// 取得colorType顏色
|
13
13
|
export function getColor (colorType: ColorType, fullChartParams: ChartParams) {
|
14
14
|
const colors = fullChartParams.colors[fullChartParams.colorScheme]
|
15
15
|
// 對應series資料中第1個顏色
|
@@ -17,11 +17,25 @@ export function getColor (colorType: ColorType, fullChartParams: ChartParams) {
|
|
17
17
|
return colors.series[0]
|
18
18
|
}
|
19
19
|
// 對應colorType設定的顏色
|
20
|
-
return colors[colorType] != null
|
21
|
-
|
22
|
-
|
20
|
+
// return colors[colorType] != null
|
21
|
+
// ? colors[colorType]
|
22
|
+
// : colors.primary
|
23
|
+
return colorType == 'none'
|
24
|
+
? 'none'
|
25
|
+
: colors[colorType] != undefined
|
26
|
+
? colors[colorType]
|
27
|
+
: colors.primary // 如果比對不到
|
28
|
+
}
|
29
|
+
|
30
|
+
// 取得Series顏色
|
31
|
+
export function getSeriesColor (seriesIndex: number, fullChartParams: ChartParams) {
|
32
|
+
const colorIndex = seriesIndex < fullChartParams.colors[fullChartParams.colorScheme].series.length
|
33
|
+
? seriesIndex
|
34
|
+
: seriesIndex % fullChartParams.colors[fullChartParams.colorScheme].series.length
|
35
|
+
return fullChartParams.colors[fullChartParams.colorScheme].series[colorIndex]
|
23
36
|
}
|
24
37
|
|
38
|
+
// 取得Datum顏色
|
25
39
|
export function getDatumColor ({ datum, colorType, fullChartParams }: { datum: ComputedDatumBase, colorType: ColorType, fullChartParams: ChartParams }) {
|
26
40
|
// 對應series資料中的顏色
|
27
41
|
if (colorType === 'series') {
|
@@ -33,9 +47,11 @@ export function getDatumColor ({ datum, colorType, fullChartParams }: { datum: C
|
|
33
47
|
}
|
34
48
|
}
|
35
49
|
// 對應colorType設定的顏色
|
36
|
-
return
|
37
|
-
?
|
38
|
-
: fullChartParams.colors[fullChartParams.colorScheme]
|
50
|
+
return colorType == 'none'
|
51
|
+
? 'none'
|
52
|
+
: fullChartParams.colors[fullChartParams.colorScheme][colorType] != undefined
|
53
|
+
? fullChartParams.colors[fullChartParams.colorScheme][colorType]
|
54
|
+
: fullChartParams.colors[fullChartParams.colorScheme].primary
|
39
55
|
}
|
40
56
|
|
41
57
|
export function getClassName (pluginName: string, elementName: string, modifier?: string) {
|