@orbcharts/plugins-basic 3.0.0-alpha.30 → 3.0.0-alpha.32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. package/dist/orbcharts-plugins-basic.es.js +15995 -15706
  2. package/dist/orbcharts-plugins-basic.umd.js +8 -8
  3. package/dist/src/base/BaseBarStack.d.ts +29 -0
  4. package/dist/src/base/BaseBars.d.ts +29 -0
  5. package/dist/src/base/BaseBarsTriangle.d.ts +28 -0
  6. package/dist/src/base/BaseLegend.d.ts +17 -6
  7. package/dist/src/base/BaseLines.d.ts +27 -0
  8. package/dist/src/base/types.d.ts +2 -2
  9. package/dist/src/grid/defaults.d.ts +10 -10
  10. package/dist/src/grid/plugins/BarStack.d.ts +1 -3
  11. package/dist/src/grid/plugins/Bars.d.ts +1 -3
  12. package/dist/src/grid/plugins/BarsTriangle.d.ts +1 -3
  13. package/dist/src/grid/plugins/Lines.d.ts +1 -3
  14. package/dist/src/grid/types.d.ts +10 -2
  15. package/dist/src/index.d.ts +1 -0
  16. package/dist/src/multiGrid/defaults.d.ts +4 -0
  17. package/dist/src/multiGrid/index.d.ts +4 -0
  18. package/dist/src/multiGrid/plugins/BarsAndLines.d.ts +1 -0
  19. package/dist/src/multiGrid/plugins/MultiGridLegend.d.ts +1 -0
  20. package/dist/src/multiGrid/types.d.ts +24 -0
  21. package/dist/src/series/defaults.d.ts +2 -2
  22. package/dist/src/series/types.d.ts +10 -2
  23. package/package.json +2 -2
  24. package/src/base/BaseBarStack.ts +699 -0
  25. package/src/base/BaseBars.ts +639 -0
  26. package/src/base/BaseBarsTriangle.ts +626 -0
  27. package/src/base/BaseLegend.ts +50 -20
  28. package/src/base/BaseLines.ts +566 -0
  29. package/src/base/types.ts +2 -2
  30. package/src/grid/defaults.ts +10 -10
  31. package/src/grid/plugins/BarStack.ts +18 -645
  32. package/src/grid/plugins/Bars.ts +17 -588
  33. package/src/grid/plugins/BarsTriangle.ts +16 -579
  34. package/src/grid/plugins/Dots.ts +2 -2
  35. package/src/grid/plugins/GridLegend.ts +19 -1
  36. package/src/grid/plugins/GroupArea.ts +2 -2
  37. package/src/grid/plugins/GroupAxis.ts +2 -2
  38. package/src/grid/plugins/Lines.ts +15 -509
  39. package/src/grid/plugins/ScalingArea.ts +2 -2
  40. package/src/grid/plugins/ValueAxis.ts +2 -2
  41. package/src/grid/plugins/ValueStackAxis.ts +2 -2
  42. package/src/grid/types.ts +12 -2
  43. package/src/index.ts +1 -0
  44. package/src/multiGrid/defaults.ts +33 -0
  45. package/src/multiGrid/index.ts +4 -0
  46. package/src/multiGrid/plugins/BarsAndLines.ts +110 -0
  47. package/src/multiGrid/plugins/BarsTriangleAndLines.ts +0 -0
  48. package/src/multiGrid/plugins/DivergingValueAxes.ts +0 -0
  49. package/src/multiGrid/plugins/FirstGroupScaleAxis.ts +0 -0
  50. package/src/multiGrid/plugins/MultiGridLegend.ts +89 -0
  51. package/src/multiGrid/plugins/TwoValueScaleAxes.ts +0 -0
  52. package/src/multiGrid/types.ts +27 -0
  53. package/src/series/defaults.ts +2 -2
  54. package/src/series/plugins/Bubbles.ts +2 -2
  55. package/src/series/plugins/Pie.ts +2 -2
  56. package/src/series/plugins/SeriesLegend.ts +19 -1
  57. package/src/series/types.ts +12 -2
  58. /package/dist/src/multiGrid/plugins/{DivergingAxes.d.ts → BarStackAndLines.d.ts} +0 -0
  59. /package/dist/src/multiGrid/plugins/{TwoScaleAxes.d.ts → BarsTriangleAndLines.d.ts} +0 -0
  60. /package/dist/src/multiGrid/plugins/{TwoScales.d.ts → DivergingValueAxes.d.ts} +0 -0
  61. /package/{src/multiGrid/plugins/DivergingAxes.ts → dist/src/multiGrid/plugins/FirstGroupScaleAxis.d.ts} +0 -0
  62. /package/{src/multiGrid/plugins/TwoScaleAxes.ts → dist/src/multiGrid/plugins/TwoValueScaleAxes.d.ts} +0 -0
  63. /package/src/multiGrid/plugins/{TwoScales.ts → BarStackAndLines.ts} +0 -0
@@ -0,0 +1,110 @@
1
+ import {
2
+ combineLatest,
3
+ map,
4
+ switchMap,
5
+ takeUntil,
6
+ Subject,
7
+ Observable } from 'rxjs'
8
+ import {
9
+ defineMultiGridPlugin } from '@orbcharts/core'
10
+ // import { defineMultiGridPlugin } from '../../../../orbcharts-core/src'
11
+ import { getClassName, getUniID } from '../../utils/orbchartsUtils'
12
+ import { DEFAULT_BARS_AND_LINES_PARAMS } from '../defaults'
13
+ import { createBaseBars } from '../../base/BaseBars'
14
+ import { createBaseLines } from '../../base/BaseLines'
15
+
16
+ const pluginName = 'BarsAndLines'
17
+ const barsClassName = getClassName(pluginName, 'bars')
18
+ const linesClassName = getClassName(pluginName, 'lines')
19
+
20
+ export const BarsAndLines = defineMultiGridPlugin(pluginName, DEFAULT_BARS_AND_LINES_PARAMS)(({ selection, name, subject, observer }) => {
21
+ const destroy$ = new Subject()
22
+
23
+ const barsSelection = selection.append('g').attr('class', barsClassName)
24
+ const linesSelection = selection.append('g').attr('class', linesClassName)
25
+
26
+ let unsubscribeBaseBars = () => {}
27
+ let unsubscribeBaseLines = () => {}
28
+
29
+ // combineLatest({
30
+ // fullParams: observer.fullParams$,
31
+ // fullChartParams: observer.fullChartParams$,
32
+ // computedData: observer.computedData$,
33
+ // event: subject.event$,
34
+ // multiGrid: observer.multiGrid$,
35
+ // }).pipe(
36
+ // takeUntil(destroy$),
37
+ // switchMap(async d => d)
38
+ // ).subscribe(data => {
39
+
40
+ // })
41
+
42
+ const barsComputedData$ = observer.computedData$.pipe(
43
+ map((computedData) => computedData[0] || [])
44
+ )
45
+
46
+ const linesComputedData$ = observer.computedData$.pipe(
47
+ map((computedData) => computedData[1] || [])
48
+ )
49
+
50
+ const barsFullParams$ = observer.fullParams$.pipe(
51
+ map((fullParams) => fullParams.bars)
52
+ )
53
+
54
+ const linesFullParams$ = observer.fullParams$.pipe(
55
+ map((fullParams) => fullParams.lines)
56
+ )
57
+
58
+ const linesFullDataFormatter$ = observer.fullDataFormatter$.pipe(
59
+ map((fullDataFormatter) => fullDataFormatter.multiGrid[1])
60
+ )
61
+
62
+ observer.multiGrid$.subscribe((multiGrid) => {
63
+ // bars
64
+ if (multiGrid[0]) {
65
+ unsubscribeBaseBars = createBaseBars(pluginName, {
66
+ selection: barsSelection,
67
+ computedData$: barsComputedData$,
68
+ visibleComputedData$: multiGrid[0].visibleComputedData$,
69
+ SeriesDataMap$: multiGrid[0].SeriesDataMap$,
70
+ GroupDataMap$: multiGrid[0].GroupDataMap$,
71
+ fullParams$: barsFullParams$,
72
+ fullChartParams$: observer.fullChartParams$,
73
+ gridAxesTransform$: multiGrid[0].gridAxesTransform$,
74
+ gridGraphicTransform$: multiGrid[0].gridGraphicTransform$,
75
+ gridAxesSize$: multiGrid[0].gridAxesSize$,
76
+ gridHighlight$: multiGrid[0].gridHighlight$,
77
+ event$: subject.event$ as Subject<any>,
78
+ })
79
+ } else {
80
+ unsubscribeBaseBars()
81
+ }
82
+ // lines
83
+ if (multiGrid[1]) {
84
+ unsubscribeBaseLines = createBaseLines(pluginName, {
85
+ selection: linesSelection,
86
+ computedData$: linesComputedData$,
87
+ SeriesDataMap$: multiGrid[1].SeriesDataMap$,
88
+ GroupDataMap$: multiGrid[1].GroupDataMap$,
89
+ fullParams$: linesFullParams$,
90
+ fullDataFormatter$: linesFullDataFormatter$,
91
+ fullChartParams$: observer.fullChartParams$,
92
+ gridAxesTransform$: multiGrid[1].gridAxesTransform$,
93
+ gridGraphicTransform$: multiGrid[1].gridGraphicTransform$,
94
+ gridAxesSize$: multiGrid[1].gridAxesSize$,
95
+ gridHighlight$: multiGrid[1].gridHighlight$,
96
+ event$: subject.event$ as Subject<any>,
97
+ })
98
+ } else {
99
+ unsubscribeBaseLines()
100
+ }
101
+ })
102
+
103
+
104
+
105
+ return () => {
106
+ destroy$.next(undefined)
107
+ unsubscribeBaseBars()
108
+ unsubscribeBaseLines()
109
+ }
110
+ })
File without changes
File without changes
File without changes
@@ -0,0 +1,89 @@
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
+ defineMultiGridPlugin } from '@orbcharts/core'
11
+ import { DEFAULT_MULTI_GRID_LEGEND_PARAMS } from '../defaults'
12
+ import { createBaseLegend } from '../../base/BaseLegend'
13
+ import type { BaseLegendParams } from '../../base/BaseLegend'
14
+
15
+ const pluginName = 'MultiGridLegend'
16
+
17
+ export const MultiGridLegend = defineMultiGridPlugin(pluginName, DEFAULT_MULTI_GRID_LEGEND_PARAMS)(({ selection, rootSelection, observer, subject }) => {
18
+
19
+ const destroy$ = new Subject()
20
+
21
+ const seriesLabels$ = observer.multiGrid$.pipe(
22
+ takeUntil(destroy$),
23
+ map(multiGrid => {
24
+ const seriesLabelsObservableArr = multiGrid.map((grid, gridIndex) => {
25
+ return grid.SeriesDataMap$.pipe(
26
+ // grid內的seriesLabels
27
+ map(seriesDataMap => Array.from(seriesDataMap.keys()))
28
+ )
29
+ })
30
+ return seriesLabelsObservableArr
31
+ }),
32
+ switchMap(seriesLabelsObservableArr => combineLatest(seriesLabelsObservableArr)),
33
+ map(data => data.flat())
34
+ )
35
+
36
+ const seriesList$ = combineLatest({
37
+ fullParams: observer.fullParams$,
38
+ multiGrid: observer.multiGrid$,
39
+ computedData: observer.computedData$,
40
+ }).pipe(
41
+ takeUntil(destroy$),
42
+ switchMap(async d => d),
43
+ map(data => {
44
+ // grid
45
+ return data.computedData
46
+ .map((gridData, gridIndex) => {
47
+ // 這個grid全部series要套用的圖例列點樣式
48
+ const gridListStyle = data.fullParams.gridList[gridIndex]
49
+ ? data.fullParams.gridList[gridIndex]
50
+ : {
51
+ listRectWidth: data.fullParams.listRectWidth,
52
+ listRectHeight: data.fullParams.listRectHeight,
53
+ listRectRadius: data.fullParams.listRectRadius,
54
+ }
55
+ // series
56
+ return gridData.map(d => gridListStyle)
57
+ })
58
+ .flat()
59
+
60
+ })
61
+ )
62
+
63
+ const fullParams$: Observable<BaseLegendParams> = combineLatest({
64
+ fullParams: observer.fullParams$,
65
+ seriesList: seriesList$
66
+ }).pipe(
67
+ takeUntil(destroy$),
68
+ map(d => {
69
+ return {
70
+ ...d.fullParams,
71
+ seriesList: d.seriesList
72
+ }
73
+ })
74
+ )
75
+
76
+ const unsubscribeBaseLegend = createBaseLegend(pluginName, {
77
+ rootSelection,
78
+ seriesLabels$,
79
+ fullParams$,
80
+ layout$: observer.layout$,
81
+ fullChartParams$: observer.fullChartParams$
82
+ })
83
+
84
+ return () => {
85
+ destroy$.next(undefined)
86
+ unsubscribeBaseLegend()
87
+ }
88
+ })
89
+
File without changes
@@ -0,0 +1,27 @@
1
+ import type { BaseBarsParams } from '../base/BaseBars'
2
+ import type { BaseLinesParams } from '../base/BaseLines'
3
+ import type {
4
+ ChartParams, Layout, ColorType } from '@orbcharts/core'
5
+
6
+ export interface BarsAndLinesParams {
7
+ bars: BaseBarsParams
8
+ lines: BaseLinesParams
9
+ }
10
+
11
+ export interface MultiGridLegendParams {
12
+ position: 'top' | 'bottom' | 'left' | 'right'
13
+ justify: 'start' | 'center' | 'end'
14
+ padding: number
15
+ backgroundFill: ColorType
16
+ backgroundStroke: ColorType
17
+ gap: number
18
+ listRectWidth: number
19
+ listRectHeight: number
20
+ listRectRadius: number
21
+ // 可針對各grid設定,覆蓋全域設定
22
+ gridList: Array<{
23
+ listRectWidth: number
24
+ listRectHeight: number
25
+ listRectRadius: number
26
+ }>
27
+ }
@@ -7,7 +7,7 @@ import type {
7
7
  SeriesLegendParams } from './types'
8
8
 
9
9
 
10
- export const DEFAULT_BUBBLES_PLUGIN_PARAMS: BubblesParams = {
10
+ export const DEFAULT_BUBBLES_PARAMS: BubblesParams = {
11
11
  force: {
12
12
  strength: 0.03, // 泡泡引力
13
13
  velocityDecay: 0.2, // 衰減數
@@ -22,7 +22,7 @@ export const DEFAULT_BUBBLES_PLUGIN_PARAMS: BubblesParams = {
22
22
  bubbleScaleType: 'area'
23
23
  }
24
24
 
25
- export const DEFAULT_PIE_PLUGIN_PARAMS: PieParams = {
25
+ export const DEFAULT_PIE_PARAMS: PieParams = {
26
26
  // padding: {
27
27
  // top: 50,
28
28
  // right: 70,
@@ -18,7 +18,7 @@ import type {
18
18
  import {
19
19
  defineSeriesPlugin } from '@orbcharts/core'
20
20
  import type { BubblesParams, BubbleScaleType } from '../types'
21
- import { DEFAULT_BUBBLES_PLUGIN_PARAMS } from '../defaults'
21
+ import { DEFAULT_BUBBLES_PARAMS } from '../defaults'
22
22
  import { renderCircleText } from '../../utils/d3Graphics'
23
23
 
24
24
  interface BubblesDatum extends ComputedDatumSeries {
@@ -298,7 +298,7 @@ function highlight ({ bubblesSelection, highlightIds, fullChartParams }: {
298
298
  })
299
299
  }
300
300
 
301
- export const Bubbles = defineSeriesPlugin('Bubbles', DEFAULT_BUBBLES_PLUGIN_PARAMS)(({ selection, name, observer, subject }) => {
301
+ export const Bubbles = defineSeriesPlugin('Bubbles', DEFAULT_BUBBLES_PARAMS)(({ selection, name, observer, subject }) => {
302
302
 
303
303
  const destroy$ = new Subject()
304
304
 
@@ -19,7 +19,7 @@ import type {
19
19
  ChartParams } from '@orbcharts/core'
20
20
  import type { PieParams } from '../types'
21
21
  import type { PieDatum } from '../seriesUtils'
22
- import { DEFAULT_PIE_PLUGIN_PARAMS } from '../defaults'
22
+ import { DEFAULT_PIE_PARAMS } from '../defaults'
23
23
  import { makePieData } from '../seriesUtils'
24
24
  import { getD3TransitionEase, makeD3Arc } from '../../utils/d3Utils'
25
25
  import { getClassName } from '../../utils/orbchartsUtils'
@@ -163,7 +163,7 @@ function highlight ({ pathSelection, ids, fullChartParams, arc, arcMouseover }:
163
163
  }
164
164
 
165
165
 
166
- export const Pie = defineSeriesPlugin(pluginName, DEFAULT_PIE_PLUGIN_PARAMS)(({ selection, name, observer, subject }) => {
166
+ export const Pie = defineSeriesPlugin(pluginName, DEFAULT_PIE_PARAMS)(({ selection, name, observer, subject }) => {
167
167
 
168
168
  const destroy$ = new Subject()
169
169
 
@@ -24,10 +24,28 @@ export const SeriesLegend = defineSeriesPlugin(pluginName, DEFAULT_SERIES_LEGEND
24
24
  })
25
25
  )
26
26
 
27
+ // 全部列點矩型使用相同樣式參數
28
+ const fullParams$ = observer.fullParams$.pipe(
29
+ takeUntil(destroy$),
30
+ map(d => {
31
+ const seriesList = [
32
+ {
33
+ listRectWidth: d.listRectWidth,
34
+ listRectHeight: d.listRectHeight,
35
+ listRectRadius: d.listRectRadius,
36
+ }
37
+ ]
38
+ return {
39
+ ...d,
40
+ seriesList
41
+ }
42
+ })
43
+ )
44
+
27
45
  const unsubscribeBaseLegend = createBaseLegend(pluginName, {
28
46
  rootSelection,
29
47
  seriesLabels$,
30
- fullParams$: observer.fullParams$,
48
+ fullParams$,
31
49
  layout$: observer.layout$,
32
50
  fullChartParams$: observer.fullChartParams$
33
51
  })
@@ -1,5 +1,5 @@
1
1
  import type { ComputedDatumSeries, EventSeries, EventName, ColorType } from '@orbcharts/core'
2
- import type { BaseLegendParams } from '../base/BaseLegend'
2
+ // import type { BaseLegendParams } from '../base/BaseLegend'
3
3
 
4
4
  export type BubbleScaleType = 'area' | 'radius'
5
5
 
@@ -53,4 +53,14 @@ export interface PieLabelsParams {
53
53
  labelColorType: ColorType
54
54
  }
55
55
 
56
- export interface SeriesLegendParams extends BaseLegendParams {}
56
+ export interface SeriesLegendParams {
57
+ position: 'top' | 'bottom' | 'left' | 'right'
58
+ justify: 'start' | 'center' | 'end'
59
+ padding: number
60
+ backgroundFill: ColorType
61
+ backgroundStroke: ColorType
62
+ gap: number
63
+ listRectWidth: number
64
+ listRectHeight: number
65
+ listRectRadius: number
66
+ }