@orbcharts/plugin-basic 4.0.0-pre-alpha.0
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/LICENSE +201 -0
- package/dist/orbcharts-plugin-basic.es.js +25335 -0
- package/dist/orbcharts-plugin-basic.umd.js +341 -0
- package/dist/plugin-basic/src/baseLayers/BaseBars.d.ts +38 -0
- package/dist/plugin-basic/src/baseLayers/BaseBarsTriangle.d.ts +37 -0
- package/dist/plugin-basic/src/baseLayers/BaseCategoryAxis.d.ts +42 -0
- package/dist/plugin-basic/src/baseLayers/BaseDots.d.ts +38 -0
- package/dist/plugin-basic/src/baseLayers/BaseLegend.d.ts +31 -0
- package/dist/plugin-basic/src/baseLayers/BaseLineAreas.d.ts +36 -0
- package/dist/plugin-basic/src/baseLayers/BaseLines.d.ts +36 -0
- package/dist/plugin-basic/src/baseLayers/BaseStackedBars.d.ts +41 -0
- package/dist/plugin-basic/src/baseLayers/BaseTooltip.d.ts +47 -0
- package/dist/plugin-basic/src/baseLayers/BaseValueAxis.d.ts +38 -0
- package/dist/plugin-basic/src/baseLayers/BaseXAxis.d.ts +25 -0
- package/dist/plugin-basic/src/baseLayers/BaseXZoom.d.ts +22 -0
- package/dist/plugin-basic/src/baseLayers/BaseYAxis.d.ts +23 -0
- package/dist/plugin-basic/src/baseLayers/types.d.ts +171 -0
- package/dist/plugin-basic/src/const/layerIndex.d.ts +10 -0
- package/dist/plugin-basic/src/const/sharedPluginParams.d.ts +6 -0
- package/dist/plugin-basic/src/index.d.ts +2 -0
- package/dist/plugin-basic/src/plugins/CompositionPlot/CompositionPlot.d.ts +22 -0
- package/dist/plugin-basic/src/plugins/CompositionPlot/contextObservables.d.ts +40 -0
- package/dist/plugin-basic/src/plugins/CompositionPlot/defaults.d.ts +10 -0
- package/dist/plugin-basic/src/plugins/CompositionPlot/index.d.ts +3 -0
- package/dist/plugin-basic/src/plugins/CompositionPlot/layers/Bubbles.d.ts +16 -0
- package/dist/plugin-basic/src/plugins/CompositionPlot/layers/Indicator.d.ts +0 -0
- package/dist/plugin-basic/src/plugins/CompositionPlot/layers/Pie.d.ts +16 -0
- package/dist/plugin-basic/src/plugins/CompositionPlot/layers/PieEventTexts.d.ts +16 -0
- package/dist/plugin-basic/src/plugins/CompositionPlot/layers/PieLabels.d.ts +16 -0
- package/dist/plugin-basic/src/plugins/CompositionPlot/layers/Rose.d.ts +16 -0
- package/dist/plugin-basic/src/plugins/CompositionPlot/layers/RoseLabels.d.ts +16 -0
- package/dist/plugin-basic/src/plugins/CompositionPlot/layers/Waffle.d.ts +0 -0
- package/dist/plugin-basic/src/plugins/CompositionPlot/types.d.ts +110 -0
- package/dist/plugin-basic/src/plugins/CompositionPlot/utils.d.ts +19 -0
- package/dist/plugin-basic/src/plugins/HierarchyPlot/HierarchyPlot.d.ts +22 -0
- package/dist/plugin-basic/src/plugins/HierarchyPlot/contextObservables.d.ts +16 -0
- package/dist/plugin-basic/src/plugins/HierarchyPlot/defaults.d.ts +4 -0
- package/dist/plugin-basic/src/plugins/HierarchyPlot/index.d.ts +3 -0
- package/dist/plugin-basic/src/plugins/HierarchyPlot/layers/TreeMap.d.ts +16 -0
- package/dist/plugin-basic/src/plugins/HierarchyPlot/types.d.ts +29 -0
- package/dist/plugin-basic/src/plugins/Legend/Legend.d.ts +22 -0
- package/dist/plugin-basic/src/plugins/Legend/contextObservables.d.ts +9 -0
- package/dist/plugin-basic/src/plugins/Legend/defaults.d.ts +4 -0
- package/dist/plugin-basic/src/plugins/Legend/index.d.ts +3 -0
- package/dist/plugin-basic/src/plugins/Legend/layers/Legend.d.ts +16 -0
- package/dist/plugin-basic/src/plugins/Legend/types.d.ts +31 -0
- package/dist/plugin-basic/src/plugins/Legend/utils.d.ts +19 -0
- package/dist/plugin-basic/src/plugins/NetworkPlot/NetworkPlot.d.ts +22 -0
- package/dist/plugin-basic/src/plugins/NetworkPlot/contextObservables.d.ts +19 -0
- package/dist/plugin-basic/src/plugins/NetworkPlot/defaults.d.ts +5 -0
- package/dist/plugin-basic/src/plugins/NetworkPlot/index.d.ts +3 -0
- package/dist/plugin-basic/src/plugins/NetworkPlot/layers/ForceDirected.d.ts +16 -0
- package/dist/plugin-basic/src/plugins/NetworkPlot/layers/ForceDirectedBubbles.d.ts +16 -0
- package/dist/plugin-basic/src/plugins/NetworkPlot/types.d.ts +117 -0
- package/dist/plugin-basic/src/plugins/ScatterPlot/ScatterPlot.d.ts +22 -0
- package/dist/plugin-basic/src/plugins/ScatterPlot/contextObservables.d.ts +140 -0
- package/dist/plugin-basic/src/plugins/ScatterPlot/defaults.d.ts +8 -0
- package/dist/plugin-basic/src/plugins/ScatterPlot/index.d.ts +3 -0
- package/dist/plugin-basic/src/plugins/ScatterPlot/layers/Scatter.d.ts +16 -0
- package/dist/plugin-basic/src/plugins/ScatterPlot/layers/ScatterBubbles.d.ts +16 -0
- package/dist/plugin-basic/src/plugins/ScatterPlot/layers/XYAux.d.ts +16 -0
- package/dist/plugin-basic/src/plugins/ScatterPlot/layers/XYAxes.d.ts +16 -0
- package/dist/plugin-basic/src/plugins/ScatterPlot/layers/XZoom.d.ts +16 -0
- package/dist/plugin-basic/src/plugins/ScatterPlot/types.d.ts +146 -0
- package/dist/plugin-basic/src/plugins/SeriesPlot/SeriesPlot.d.ts +22 -0
- package/dist/plugin-basic/src/plugins/SeriesPlot/contextObservables.d.ts +77 -0
- package/dist/plugin-basic/src/plugins/SeriesPlot/defaults.d.ts +15 -0
- package/dist/plugin-basic/src/plugins/SeriesPlot/index.d.ts +3 -0
- package/dist/plugin-basic/src/plugins/SeriesPlot/layers/Bars.d.ts +16 -0
- package/dist/plugin-basic/src/plugins/SeriesPlot/layers/BarsPN.d.ts +16 -0
- package/dist/plugin-basic/src/plugins/SeriesPlot/layers/BarsTriangle.d.ts +16 -0
- package/dist/plugin-basic/src/plugins/SeriesPlot/layers/CategoryAux.d.ts +16 -0
- package/dist/plugin-basic/src/plugins/SeriesPlot/layers/CategoryAxis.d.ts +16 -0
- package/dist/plugin-basic/src/plugins/SeriesPlot/layers/CategoryZoom.d.ts +16 -0
- package/dist/plugin-basic/src/plugins/SeriesPlot/layers/Dots.d.ts +16 -0
- package/dist/plugin-basic/src/plugins/SeriesPlot/layers/LineAreas.d.ts +16 -0
- package/dist/plugin-basic/src/plugins/SeriesPlot/layers/Lines.d.ts +16 -0
- package/dist/plugin-basic/src/plugins/SeriesPlot/layers/StackedBars.d.ts +16 -0
- package/dist/plugin-basic/src/plugins/SeriesPlot/layers/StackedValueAxis.d.ts +16 -0
- package/dist/plugin-basic/src/plugins/SeriesPlot/layers/ValueAxis.d.ts +16 -0
- package/dist/plugin-basic/src/plugins/SeriesPlot/types.d.ts +140 -0
- package/dist/plugin-basic/src/plugins/Tooltip/Tooltip.d.ts +22 -0
- package/dist/plugin-basic/src/plugins/Tooltip/contextObservables.d.ts +9 -0
- package/dist/plugin-basic/src/plugins/Tooltip/defaults.d.ts +4 -0
- package/dist/plugin-basic/src/plugins/Tooltip/index.d.ts +3 -0
- package/dist/plugin-basic/src/plugins/Tooltip/layers/Tooltip.d.ts +16 -0
- package/dist/plugin-basic/src/plugins/Tooltip/types.d.ts +35 -0
- package/dist/plugin-basic/src/plugins/Tooltip/utils.d.ts +19 -0
- package/dist/plugin-basic/src/plugins/index.d.ts +7 -0
- package/dist/plugin-basic/src/types/BaseLayer.d.ts +3 -0
- package/dist/plugin-basic/src/types/Common.d.ts +14 -0
- package/dist/plugin-basic/src/types/ComputedData.d.ts +27 -0
- package/dist/plugin-basic/src/types/PluginParams.d.ts +66 -0
- package/dist/plugin-basic/src/types/index.d.ts +3 -0
- package/dist/plugin-basic/src/utils/commonUtils.d.ts +3 -0
- package/dist/plugin-basic/src/utils/d3Graphics.d.ts +24 -0
- package/dist/plugin-basic/src/utils/d3Scale.d.ts +28 -0
- package/dist/plugin-basic/src/utils/d3Utils.d.ts +14 -0
- package/dist/plugin-basic/src/utils/graphObservables.d.ts +0 -0
- package/dist/plugin-basic/src/utils/gridObservables.d.ts +51 -0
- package/dist/plugin-basic/src/utils/multivariateObservables.d.ts +74 -0
- package/dist/plugin-basic/src/utils/observables.d.ts +34 -0
- package/dist/plugin-basic/src/utils/orbchartsUtils.d.ts +26 -0
- package/dist/plugin-basic/src/utils/seriesObservables.d.ts +22 -0
- package/dist/plugin-basic/vite.config.d.ts +2 -0
- package/dist/src/index.d.ts +1 -0
- package/package.json +62 -0
- package/src/baseLayers/BaseBars.ts +783 -0
- package/src/baseLayers/BaseBarsTriangle.ts +692 -0
- package/src/baseLayers/BaseCategoryAxis.ts +708 -0
- package/src/baseLayers/BaseDots.ts +495 -0
- package/src/baseLayers/BaseLegend.ts +684 -0
- package/src/baseLayers/BaseLineAreas.ts +644 -0
- package/src/baseLayers/BaseLines.ts +721 -0
- package/src/baseLayers/BaseStackedBars.ts +818 -0
- package/src/baseLayers/BaseTooltip.ts +435 -0
- package/src/baseLayers/BaseValueAxis.ts +612 -0
- package/src/baseLayers/BaseXAxis.ts +412 -0
- package/src/baseLayers/BaseXZoom.ts +250 -0
- package/src/baseLayers/BaseYAxis.ts +371 -0
- package/src/baseLayers/types.ts +174 -0
- package/src/const/layerIndex.ts +36 -0
- package/src/const/sharedPluginParams.ts +29 -0
- package/src/index.ts +3 -0
- package/src/plugins/CompositionPlot/CompositionPlot.ts +308 -0
- package/src/plugins/CompositionPlot/contextObservables.ts +251 -0
- package/src/plugins/CompositionPlot/defaults.ts +162 -0
- package/src/plugins/CompositionPlot/index.ts +3 -0
- package/src/plugins/CompositionPlot/layers/Bubbles.ts +808 -0
- package/src/plugins/CompositionPlot/layers/Indicator.ts +0 -0
- package/src/plugins/CompositionPlot/layers/Pie.ts +776 -0
- package/src/plugins/CompositionPlot/layers/PieEventTexts.ts +326 -0
- package/src/plugins/CompositionPlot/layers/PieLabels.ts +651 -0
- package/src/plugins/CompositionPlot/layers/Rose.ts +546 -0
- package/src/plugins/CompositionPlot/layers/RoseLabels.ts +616 -0
- package/src/plugins/CompositionPlot/layers/Waffle.ts +0 -0
- package/src/plugins/CompositionPlot/types.ts +129 -0
- package/src/plugins/CompositionPlot/utils.ts +53 -0
- package/src/plugins/HierarchyPlot/HierarchyPlot.ts +190 -0
- package/src/plugins/HierarchyPlot/contextObservables.ts +136 -0
- package/src/plugins/HierarchyPlot/defaults.ts +31 -0
- package/src/plugins/HierarchyPlot/index.ts +3 -0
- package/src/plugins/HierarchyPlot/layers/TreeMap.ts +371 -0
- package/src/plugins/HierarchyPlot/types.ts +36 -0
- package/src/plugins/Legend/Legend.ts +151 -0
- package/src/plugins/Legend/contextObservables.ts +55 -0
- package/src/plugins/Legend/defaults.ts +37 -0
- package/src/plugins/Legend/index.ts +3 -0
- package/src/plugins/Legend/layers/Legend.ts +114 -0
- package/src/plugins/Legend/types.ts +45 -0
- package/src/plugins/Legend/utils.ts +53 -0
- package/src/plugins/NetworkPlot/NetworkPlot.ts +228 -0
- package/src/plugins/NetworkPlot/contextObservables.ts +123 -0
- package/src/plugins/NetworkPlot/defaults.ts +147 -0
- package/src/plugins/NetworkPlot/index.ts +3 -0
- package/src/plugins/NetworkPlot/layers/ForceDirected.ts +1048 -0
- package/src/plugins/NetworkPlot/layers/ForceDirectedBubbles.ts +1318 -0
- package/src/plugins/NetworkPlot/types.ts +146 -0
- package/src/plugins/ScatterPlot/ScatterPlot.ts +569 -0
- package/src/plugins/ScatterPlot/contextObservables.ts +901 -0
- package/src/plugins/ScatterPlot/defaults.ts +212 -0
- package/src/plugins/ScatterPlot/index.ts +3 -0
- package/src/plugins/ScatterPlot/layers/Scatter.ts +518 -0
- package/src/plugins/ScatterPlot/layers/ScatterBubbles.ts +670 -0
- package/src/plugins/ScatterPlot/layers/XYAux.ts +686 -0
- package/src/plugins/ScatterPlot/layers/XYAxes.ts +205 -0
- package/src/plugins/ScatterPlot/layers/XZoom.ts +48 -0
- package/src/plugins/ScatterPlot/types.ts +179 -0
- package/src/plugins/SeriesPlot/SeriesPlot.ts +494 -0
- package/src/plugins/SeriesPlot/contextObservables.ts +726 -0
- package/src/plugins/SeriesPlot/defaults.ts +142 -0
- package/src/plugins/SeriesPlot/index.ts +3 -0
- package/src/plugins/SeriesPlot/layers/Bars.ts +84 -0
- package/src/plugins/SeriesPlot/layers/BarsPN.ts +85 -0
- package/src/plugins/SeriesPlot/layers/BarsTriangle.ts +89 -0
- package/src/plugins/SeriesPlot/layers/CategoryAux.ts +1131 -0
- package/src/plugins/SeriesPlot/layers/CategoryAxis.ts +92 -0
- package/src/plugins/SeriesPlot/layers/CategoryZoom.ts +233 -0
- package/src/plugins/SeriesPlot/layers/Dots.ts +91 -0
- package/src/plugins/SeriesPlot/layers/LineAreas.ts +82 -0
- package/src/plugins/SeriesPlot/layers/Lines.ts +75 -0
- package/src/plugins/SeriesPlot/layers/StackedBars.ts +85 -0
- package/src/plugins/SeriesPlot/layers/StackedValueAxis.ts +111 -0
- package/src/plugins/SeriesPlot/layers/ValueAxis.ts +111 -0
- package/src/plugins/SeriesPlot/types.ts +201 -0
- package/src/plugins/Tooltip/Tooltip.ts +159 -0
- package/src/plugins/Tooltip/contextObservables.ts +55 -0
- package/src/plugins/Tooltip/defaults.ts +458 -0
- package/src/plugins/Tooltip/index.ts +3 -0
- package/src/plugins/Tooltip/layers/Tooltip.ts +90 -0
- package/src/plugins/Tooltip/types.ts +55 -0
- package/src/plugins/Tooltip/utils.ts +53 -0
- package/src/plugins/index.ts +8 -0
- package/src/types/BaseLayer.ts +3 -0
- package/src/types/Common.ts +20 -0
- package/src/types/ComputedData.ts +55 -0
- package/src/types/PluginParams.ts +81 -0
- package/src/types/index.ts +3 -0
- package/src/utils/commonUtils.ts +31 -0
- package/src/utils/d3Graphics.ts +177 -0
- package/src/utils/d3Scale.ts +198 -0
- package/src/utils/d3Utils.ts +92 -0
- package/src/utils/graphObservables.ts +0 -0
- package/src/utils/gridObservables.ts +637 -0
- package/src/utils/multivariateObservables.ts +790 -0
- package/src/utils/observables.ts +357 -0
- package/src/utils/orbchartsUtils.ts +335 -0
- package/src/utils/seriesObservables.ts +172 -0
|
@@ -0,0 +1,708 @@
|
|
|
1
|
+
import * as d3 from 'd3'
|
|
2
|
+
import {
|
|
3
|
+
combineLatest,
|
|
4
|
+
debounceTime,
|
|
5
|
+
switchMap,
|
|
6
|
+
distinctUntilChanged,
|
|
7
|
+
of,
|
|
8
|
+
first,
|
|
9
|
+
map,
|
|
10
|
+
takeUntil,
|
|
11
|
+
shareReplay,
|
|
12
|
+
Observable,
|
|
13
|
+
Subject } from 'rxjs'
|
|
14
|
+
import type { ColorType, Theme } from '@orbcharts/core'
|
|
15
|
+
import type {
|
|
16
|
+
ComputedData,
|
|
17
|
+
ContainerPositionScaled,
|
|
18
|
+
ComputedDatumGrid,
|
|
19
|
+
TransformData,
|
|
20
|
+
ValueAxis,
|
|
21
|
+
CategoryAxis,
|
|
22
|
+
GraphicStyles,
|
|
23
|
+
} from '../types'
|
|
24
|
+
import type { BaseLayerFn } from '../types/BaseLayer'
|
|
25
|
+
import { parseTickFormatValue } from '../utils/d3Utils'
|
|
26
|
+
import { getColor, createClassName } from '../utils/orbchartsUtils'
|
|
27
|
+
import { renderTspansOnAxis } from '../utils/d3Graphics'
|
|
28
|
+
|
|
29
|
+
export interface BaseCategoryAxisParams {
|
|
30
|
+
labelOffset: [number, number];
|
|
31
|
+
labelColorType: ColorType;
|
|
32
|
+
axisLineVisible: boolean;
|
|
33
|
+
axisLineColorType: ColorType;
|
|
34
|
+
ticks: number | null | 'all';
|
|
35
|
+
tickFormat: string | ((text: any) => string | d3.NumberValue);
|
|
36
|
+
tickLineVisible: boolean;
|
|
37
|
+
tickPadding: number;
|
|
38
|
+
tickFullLine: boolean;
|
|
39
|
+
tickFullLineDasharray: string;
|
|
40
|
+
tickColorType: ColorType;
|
|
41
|
+
tickTextRotate: number;
|
|
42
|
+
tickTextColorType: ColorType;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
interface BaseGroupAxisContext {
|
|
46
|
+
selection: d3.Selection<any, unknown, any, unknown>
|
|
47
|
+
pluginName: string
|
|
48
|
+
layerName: string
|
|
49
|
+
computedData$: Observable<ComputedData<'grid'>>
|
|
50
|
+
baseCategoryAxisParams$: Observable<BaseCategoryAxisParams>
|
|
51
|
+
categoryAxis$: Observable<CategoryAxis>
|
|
52
|
+
valueAxis$: Observable<ValueAxis>
|
|
53
|
+
theme$: Observable<Theme>
|
|
54
|
+
styles$: Observable<GraphicStyles>
|
|
55
|
+
gridAxesTransform$: Observable<TransformData>
|
|
56
|
+
gridAxesReverseTransform$: Observable<TransformData>
|
|
57
|
+
gridAxesSize$: Observable<{
|
|
58
|
+
width: number;
|
|
59
|
+
height: number;
|
|
60
|
+
}>
|
|
61
|
+
gridContainerPosition$: Observable<ContainerPositionScaled[]>
|
|
62
|
+
isSeriesSeprate$: Observable<boolean>
|
|
63
|
+
fontSizePx$: Observable<number>
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
interface TextAlign {
|
|
67
|
+
textAnchor: "start" | "middle" | "end"
|
|
68
|
+
dominantBaseline: "middle" | "auto" | "hanging"
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
interface GroupLabelData {
|
|
72
|
+
text: string
|
|
73
|
+
textArr: string[]
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// const pluginName = 'GroupAxis'
|
|
77
|
+
// const containerClassName = createClassName(pluginName, 'container')
|
|
78
|
+
// const xAxisGClassName = createClassName(pluginName, 'xAxisG')
|
|
79
|
+
// const xAxisClassName = createClassName(pluginName, 'xAxis')
|
|
80
|
+
// const categoryLabelClassName = createClassName(pluginName, 'categoryLabel')
|
|
81
|
+
const defaultTickSize = 6
|
|
82
|
+
|
|
83
|
+
function createGroupLabelData (categoryLabels: string[], tickFormat: string | ((text: any) => string | d3.NumberValue)): GroupLabelData[] {
|
|
84
|
+
return categoryLabels.map((_text, i) => {
|
|
85
|
+
const text = parseTickFormatValue(_text, tickFormat)
|
|
86
|
+
const textArr = typeof text === 'string' ? text.split('\n') : [text]
|
|
87
|
+
|
|
88
|
+
return {
|
|
89
|
+
text,
|
|
90
|
+
textArr
|
|
91
|
+
}
|
|
92
|
+
})
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function renderAxisLabel ({ selection, categoryLabelClassName, baseCategoryAxisParams, axisLabelAlign, gridAxesSize, categoryAxis, valueAxis, styles, theme, textReverseTransform }: {
|
|
96
|
+
selection: d3.Selection<SVGGElement, any, any, any>,
|
|
97
|
+
categoryLabelClassName: string
|
|
98
|
+
baseCategoryAxisParams: BaseCategoryAxisParams
|
|
99
|
+
axisLabelAlign: TextAlign
|
|
100
|
+
gridAxesSize: { width: number, height: number }
|
|
101
|
+
categoryAxis: CategoryAxis
|
|
102
|
+
valueAxis: ValueAxis
|
|
103
|
+
styles: GraphicStyles
|
|
104
|
+
theme: Theme
|
|
105
|
+
textReverseTransform: string
|
|
106
|
+
}) {
|
|
107
|
+
|
|
108
|
+
const offsetX = baseCategoryAxisParams.tickPadding + baseCategoryAxisParams.labelOffset[0]
|
|
109
|
+
const offsetY = baseCategoryAxisParams.tickPadding + baseCategoryAxisParams.labelOffset[1]
|
|
110
|
+
let labelX = 0
|
|
111
|
+
let labelY = 0
|
|
112
|
+
if (categoryAxis.position === 'bottom') {
|
|
113
|
+
labelY = offsetY
|
|
114
|
+
if (valueAxis.position === 'left') {
|
|
115
|
+
labelX = offsetX
|
|
116
|
+
} else if (valueAxis.position === 'right') {
|
|
117
|
+
labelX = - offsetX
|
|
118
|
+
}
|
|
119
|
+
} else if (categoryAxis.position === 'top') {
|
|
120
|
+
labelY = - offsetY
|
|
121
|
+
if (valueAxis.position === 'left') {
|
|
122
|
+
labelX = offsetX
|
|
123
|
+
} else if (valueAxis.position === 'right') {
|
|
124
|
+
labelX = - offsetX
|
|
125
|
+
}
|
|
126
|
+
} else if (categoryAxis.position === 'left') {
|
|
127
|
+
labelX = - offsetX
|
|
128
|
+
if (valueAxis.position === 'bottom') {
|
|
129
|
+
labelY = - offsetY
|
|
130
|
+
} else if (valueAxis.position === 'top') {
|
|
131
|
+
labelY = offsetY
|
|
132
|
+
}
|
|
133
|
+
} else if (categoryAxis.position === 'right') {
|
|
134
|
+
labelX = offsetX
|
|
135
|
+
if (valueAxis.position === 'bottom') {
|
|
136
|
+
labelY = - offsetY
|
|
137
|
+
} else if (valueAxis.position === 'top') {
|
|
138
|
+
labelY = offsetY
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const axisLabelSelection = selection
|
|
143
|
+
.selectAll<SVGGElement, BaseCategoryAxisParams>(`g.${categoryLabelClassName}`)
|
|
144
|
+
.data([baseCategoryAxisParams])
|
|
145
|
+
.join('g')
|
|
146
|
+
.classed(categoryLabelClassName, true)
|
|
147
|
+
.each((d, i, g) => {
|
|
148
|
+
const text = d3.select(g[i])
|
|
149
|
+
.selectAll<SVGTextElement, BaseCategoryAxisParams>('text')
|
|
150
|
+
.data([d])
|
|
151
|
+
.join(
|
|
152
|
+
enter => {
|
|
153
|
+
return enter
|
|
154
|
+
.append('text')
|
|
155
|
+
.style('font-weight', 'bold')
|
|
156
|
+
},
|
|
157
|
+
update => update,
|
|
158
|
+
exit => exit.remove()
|
|
159
|
+
)
|
|
160
|
+
.attr('text-anchor', axisLabelAlign.textAnchor)
|
|
161
|
+
.attr('dominant-baseline', axisLabelAlign.dominantBaseline)
|
|
162
|
+
.attr('font-size', theme.fontSize)
|
|
163
|
+
.style('fill', getColor(baseCategoryAxisParams.labelColorType, theme))
|
|
164
|
+
.style('transform', textReverseTransform)
|
|
165
|
+
// 偏移使用 x, y 而非 transform 才不會受到外層 scale 變形影響
|
|
166
|
+
.attr('x', labelX)
|
|
167
|
+
.attr('y', labelY)
|
|
168
|
+
.text(d => categoryAxis.label)
|
|
169
|
+
})
|
|
170
|
+
.attr('transform', d => `translate(${gridAxesSize.width}, 0)`)
|
|
171
|
+
// .attr('transform', d => `translate(${gridAxesSize.width + d.tickPadding + baseCategoryAxisParams.labelOffset[0]}, ${- d.tickPadding - baseCategoryAxisParams.labelOffset[1]})`)
|
|
172
|
+
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
function renderAxis ({ selection, xAxisClassName, baseCategoryAxisParams, tickTextAlign, gridAxesSize, categoryAxis, categoryScale, categoryScaleDomain, categoryLabelData, textReverseTransformWithRotate, theme, fontSizePx }: {
|
|
176
|
+
selection: d3.Selection<SVGGElement, any, any, any>,
|
|
177
|
+
xAxisClassName: string
|
|
178
|
+
baseCategoryAxisParams: BaseCategoryAxisParams
|
|
179
|
+
tickTextAlign: TextAlign
|
|
180
|
+
gridAxesSize: { width: number, height: number }
|
|
181
|
+
categoryAxis: CategoryAxis
|
|
182
|
+
categoryScale: d3.ScaleLinear<number, number>
|
|
183
|
+
categoryScaleDomain: number[]
|
|
184
|
+
// categoryLabels: string[]
|
|
185
|
+
categoryLabelData: GroupLabelData[]
|
|
186
|
+
textReverseTransformWithRotate: string
|
|
187
|
+
theme: Theme
|
|
188
|
+
fontSizePx: number
|
|
189
|
+
}) {
|
|
190
|
+
|
|
191
|
+
const xAxisSelection = selection
|
|
192
|
+
.selectAll<SVGGElement, BaseCategoryAxisParams>(`g.${xAxisClassName}`)
|
|
193
|
+
.data([baseCategoryAxisParams])
|
|
194
|
+
.join('g')
|
|
195
|
+
.classed(xAxisClassName, true)
|
|
196
|
+
|
|
197
|
+
// 計算所有範圍內categoryLabels數量(顯示所有刻度)
|
|
198
|
+
const allTicksAmount = Math.floor(categoryScaleDomain[1]) - Math.ceil(categoryScaleDomain[0]) + 1
|
|
199
|
+
|
|
200
|
+
// 刻度文字偏移
|
|
201
|
+
let tickPadding = 0
|
|
202
|
+
let textX = 0
|
|
203
|
+
if (categoryAxis.position === 'left') {
|
|
204
|
+
tickPadding = 0
|
|
205
|
+
textX = - baseCategoryAxisParams.tickPadding
|
|
206
|
+
} else if (categoryAxis.position === 'right') {
|
|
207
|
+
tickPadding = 0
|
|
208
|
+
textX = baseCategoryAxisParams.tickPadding
|
|
209
|
+
} else if (categoryAxis.position === 'bottom') {
|
|
210
|
+
if (baseCategoryAxisParams.tickFullLine == true) {
|
|
211
|
+
tickPadding = - baseCategoryAxisParams.tickPadding
|
|
212
|
+
} else {
|
|
213
|
+
tickPadding = - baseCategoryAxisParams.tickPadding - defaultTickSize
|
|
214
|
+
}
|
|
215
|
+
textX = 0
|
|
216
|
+
} else if (categoryAxis.position === 'top') {
|
|
217
|
+
if (baseCategoryAxisParams.tickFullLine == true) {
|
|
218
|
+
tickPadding = baseCategoryAxisParams.tickPadding
|
|
219
|
+
} else {
|
|
220
|
+
tickPadding = baseCategoryAxisParams.tickPadding - defaultTickSize
|
|
221
|
+
}
|
|
222
|
+
textX = - 0
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
// 設定X軸刻度
|
|
226
|
+
const xAxis = d3.axisTop(categoryScale)
|
|
227
|
+
.scale(categoryScale)
|
|
228
|
+
.ticks(baseCategoryAxisParams.ticks === 'all'
|
|
229
|
+
? allTicksAmount
|
|
230
|
+
: baseCategoryAxisParams.ticks > allTicksAmount
|
|
231
|
+
? allTicksAmount // 不顯示超過categoryLabels數量的刻度
|
|
232
|
+
: baseCategoryAxisParams.ticks)
|
|
233
|
+
.tickSize(baseCategoryAxisParams.tickFullLine == true
|
|
234
|
+
? - gridAxesSize.height
|
|
235
|
+
: defaultTickSize)
|
|
236
|
+
.tickSizeOuter(0)
|
|
237
|
+
.tickFormat((categoryIndex: number) => {
|
|
238
|
+
// 用index對應到categoryLabel
|
|
239
|
+
// const categoryLabel = categoryLabels[categoryIndex] ?? '' // 非整數index不顯示
|
|
240
|
+
// return parseTickFormatValue(categoryLabel, baseCategoryAxisParams.tickFormat)
|
|
241
|
+
return categoryLabelData[categoryIndex]?.text ?? ''
|
|
242
|
+
})
|
|
243
|
+
.tickPadding(tickPadding)
|
|
244
|
+
|
|
245
|
+
const xAxisEl = xAxisSelection
|
|
246
|
+
.transition()
|
|
247
|
+
.duration(100)
|
|
248
|
+
.ease(d3.easeLinear) // 線性的 - 當托曳或快速變動的時候比較滑順
|
|
249
|
+
.call(xAxis)
|
|
250
|
+
|
|
251
|
+
.on('end', (self, t) => {
|
|
252
|
+
// 先等transition結束再處理文字,否則會被原本的文字覆蓋
|
|
253
|
+
xAxisSelection
|
|
254
|
+
.selectAll('.tick text')
|
|
255
|
+
.each((categoryIndex: number, i, n) => {
|
|
256
|
+
// const categoryLabel = categoryLabels[categoryIndex] ?? '' // 非整數index不顯示
|
|
257
|
+
// const categoryLabelText = parseTickFormatValue(categoryLabel, baseCategoryAxisParams.tickFormat)
|
|
258
|
+
const textArr = categoryLabelData[categoryIndex]?.textArr ?? []
|
|
259
|
+
|
|
260
|
+
// 將原本單行文字改為多行文字
|
|
261
|
+
renderTspansOnAxis(d3.select(n[i]), {
|
|
262
|
+
textArr,
|
|
263
|
+
textSizePx: fontSizePx,
|
|
264
|
+
categoryAxisPosition: categoryAxis.position,
|
|
265
|
+
isContainerRotated: true
|
|
266
|
+
})
|
|
267
|
+
})
|
|
268
|
+
})
|
|
269
|
+
|
|
270
|
+
xAxisEl.selectAll('line')
|
|
271
|
+
.style('fill', 'none')
|
|
272
|
+
.style('stroke', baseCategoryAxisParams.tickLineVisible == true ? getColor(baseCategoryAxisParams.tickColorType, theme) : 'none')
|
|
273
|
+
.style('stroke-dasharray', baseCategoryAxisParams.tickFullLineDasharray)
|
|
274
|
+
.style('vector-effect', 'non-scaling-stroke') // 避免 scale 導致線條變形
|
|
275
|
+
.attr('pointer-events', 'none')
|
|
276
|
+
|
|
277
|
+
xAxisEl.selectAll('path')
|
|
278
|
+
.style('fill', 'none')
|
|
279
|
+
.style('stroke', baseCategoryAxisParams.axisLineVisible == true ? getColor(baseCategoryAxisParams.axisLineColorType, theme) : 'none')
|
|
280
|
+
.style('shape-rendering', 'crispEdges')
|
|
281
|
+
|
|
282
|
+
const xText = xAxisSelection.selectAll<SVGTextElement, BaseCategoryAxisParams>('text')
|
|
283
|
+
// .style('font-family', 'sans-serif')
|
|
284
|
+
.attr('font-size', theme.fontSize)
|
|
285
|
+
// .style('font-weight', 'bold')
|
|
286
|
+
.attr('fill', getColor(baseCategoryAxisParams.tickTextColorType, theme))
|
|
287
|
+
.attr('text-anchor', tickTextAlign.textAnchor)
|
|
288
|
+
.attr('dominant-baseline', tickTextAlign.dominantBaseline)
|
|
289
|
+
.attr('x', textX)
|
|
290
|
+
.style('transform', textReverseTransformWithRotate)
|
|
291
|
+
|
|
292
|
+
// 抵消掉預設的偏移
|
|
293
|
+
// if (fullDataFormatter.categoryAxis.position === 'left' || fullDataFormatter.categoryAxis.position === 'right') {
|
|
294
|
+
xText.attr('dy', 0)
|
|
295
|
+
// }
|
|
296
|
+
|
|
297
|
+
return xAxisSelection
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
|
|
301
|
+
export const createBaseCategoryAxis: BaseLayerFn<BaseGroupAxisContext> = (({
|
|
302
|
+
selection,
|
|
303
|
+
pluginName,
|
|
304
|
+
layerName,
|
|
305
|
+
computedData$,
|
|
306
|
+
baseCategoryAxisParams$,
|
|
307
|
+
categoryAxis$,
|
|
308
|
+
valueAxis$,
|
|
309
|
+
theme$,
|
|
310
|
+
styles$,
|
|
311
|
+
gridAxesTransform$,
|
|
312
|
+
gridAxesReverseTransform$,
|
|
313
|
+
gridAxesSize$,
|
|
314
|
+
gridContainerPosition$,
|
|
315
|
+
isSeriesSeprate$,
|
|
316
|
+
fontSizePx$,
|
|
317
|
+
}) => {
|
|
318
|
+
|
|
319
|
+
const destroy$ = new Subject()
|
|
320
|
+
|
|
321
|
+
const containerClassName = createClassName(pluginName, layerName, 'container')
|
|
322
|
+
const xAxisGClassName = createClassName(pluginName, layerName, 'xAxisG')
|
|
323
|
+
const xAxisClassName = createClassName(pluginName, layerName, 'xAxis')
|
|
324
|
+
const categoryLabelClassName = createClassName(pluginName, layerName, 'categoryLabel')
|
|
325
|
+
|
|
326
|
+
const containerSelection$ = combineLatest({
|
|
327
|
+
computedData: computedData$.pipe(
|
|
328
|
+
distinctUntilChanged((a, b) => {
|
|
329
|
+
// 只有當series的數量改變時,才重新計算
|
|
330
|
+
return a.length === b.length
|
|
331
|
+
}),
|
|
332
|
+
),
|
|
333
|
+
isSeriesSeprate: isSeriesSeprate$
|
|
334
|
+
}).pipe(
|
|
335
|
+
takeUntil(destroy$),
|
|
336
|
+
switchMap(async (d) => d),
|
|
337
|
+
map(data => {
|
|
338
|
+
return data.isSeriesSeprate
|
|
339
|
+
// series分開的時候顯示各別axis
|
|
340
|
+
? data.computedData
|
|
341
|
+
// series合併的時候只顯示第一個axis
|
|
342
|
+
: [data.computedData[0]]
|
|
343
|
+
}),
|
|
344
|
+
map((computedData, i) => {
|
|
345
|
+
return selection
|
|
346
|
+
.selectAll<SVGGElement, ComputedDatumGrid[]>(`g.${containerClassName}`)
|
|
347
|
+
.data(computedData, d => (d && d[0]) ? d[0].seriesIndex : i)
|
|
348
|
+
.join('g')
|
|
349
|
+
.classed(containerClassName, true)
|
|
350
|
+
})
|
|
351
|
+
)
|
|
352
|
+
|
|
353
|
+
const axisSelection$ = containerSelection$.pipe(
|
|
354
|
+
takeUntil(destroy$),
|
|
355
|
+
map((containerSelection, i) => {
|
|
356
|
+
return containerSelection
|
|
357
|
+
.selectAll<SVGGElement, ComputedDatumGrid[]>(`g.${xAxisGClassName}`)
|
|
358
|
+
.data([xAxisGClassName])
|
|
359
|
+
.join('g')
|
|
360
|
+
.classed(xAxisGClassName, true)
|
|
361
|
+
})
|
|
362
|
+
)
|
|
363
|
+
|
|
364
|
+
combineLatest({
|
|
365
|
+
containerSelection: containerSelection$,
|
|
366
|
+
gridContainerPosition: gridContainerPosition$
|
|
367
|
+
}).pipe(
|
|
368
|
+
takeUntil(destroy$),
|
|
369
|
+
debounceTime(0)
|
|
370
|
+
).subscribe(data => {
|
|
371
|
+
data.containerSelection
|
|
372
|
+
.attr('transform', (d, i) => {
|
|
373
|
+
const gridContainerPosition = data.gridContainerPosition[i] ?? data.gridContainerPosition[0]
|
|
374
|
+
const translate = gridContainerPosition.translate
|
|
375
|
+
const scale = gridContainerPosition.scale
|
|
376
|
+
return `translate(${translate[0]}, ${translate[1]}) scale(${scale[0]}, ${scale[1]})`
|
|
377
|
+
})
|
|
378
|
+
// .attr('opacity', 0)
|
|
379
|
+
// .transition()
|
|
380
|
+
// .attr('opacity', 1)
|
|
381
|
+
})
|
|
382
|
+
|
|
383
|
+
combineLatest({
|
|
384
|
+
axisSelection: axisSelection$,
|
|
385
|
+
gridAxesTransform: gridAxesTransform$,
|
|
386
|
+
}).pipe(
|
|
387
|
+
takeUntil(destroy$),
|
|
388
|
+
debounceTime(0)
|
|
389
|
+
).subscribe(data => {
|
|
390
|
+
data.axisSelection
|
|
391
|
+
.style('transform', data.gridAxesTransform.value)
|
|
392
|
+
// .attr('opacity', 0)
|
|
393
|
+
// .transition()
|
|
394
|
+
// .attr('opacity', 1)
|
|
395
|
+
|
|
396
|
+
})
|
|
397
|
+
|
|
398
|
+
|
|
399
|
+
// const gridAxesSize$ = gridAxisSizeObservable({
|
|
400
|
+
// fullDataFormatter$,
|
|
401
|
+
// layout$
|
|
402
|
+
// })
|
|
403
|
+
|
|
404
|
+
|
|
405
|
+
// const tickTextFormatter$ = fullDataFormatter$
|
|
406
|
+
// .pipe(
|
|
407
|
+
// map(d => {
|
|
408
|
+
// return d.seriesDirection === 'row' ? d.columnLabelFormat : d.rowLabelFormat
|
|
409
|
+
// })
|
|
410
|
+
// )
|
|
411
|
+
|
|
412
|
+
// const textReverseTransform$: Observable<string> = new Observable(subscriber => {
|
|
413
|
+
// combineLatest({
|
|
414
|
+
// params: baseCategoryAxisParams$,
|
|
415
|
+
// gridAxesTransform: gridAxesTransform$
|
|
416
|
+
// }).pipe(
|
|
417
|
+
// takeUntil(destroy$),
|
|
418
|
+
// // 轉換後會退訂前一個未完成的訂閱事件,因此可以取到「同時間」最後一次的訂閱事件
|
|
419
|
+
// switchMap(async (d) => d),
|
|
420
|
+
// ).subscribe(data => {
|
|
421
|
+
|
|
422
|
+
// const transformData = Object.assign({}, data.gridAxesTransform)
|
|
423
|
+
|
|
424
|
+
// const value = getAxesTransformValue({
|
|
425
|
+
// translate: [0, 0],
|
|
426
|
+
// scale: [transformData.scale[0] * -1, transformData.scale[1] * -1],
|
|
427
|
+
// rotate: transformData.rotate * -1 + data.params.tickTextRotate,
|
|
428
|
+
// rotateX: transformData.rotateX * -1,
|
|
429
|
+
// rotateY: transformData.rotateY * -1
|
|
430
|
+
// })
|
|
431
|
+
|
|
432
|
+
// subscriber.next(value)
|
|
433
|
+
// })
|
|
434
|
+
// })
|
|
435
|
+
// const reverseTransform$: Observable<TransformData> = gridAxesTransform$.pipe(
|
|
436
|
+
// takeUntil(destroy$),
|
|
437
|
+
// map(d => {
|
|
438
|
+
// const translate: [number, number] = [d.translate[0] * -1, d.translate[1] * -1]
|
|
439
|
+
// const scale: [number, number] = [d.scale[0] * -1, d.scale[1] * -1]
|
|
440
|
+
// const rotate = d.rotate * -1
|
|
441
|
+
// const rotateX = d.rotateX * -1
|
|
442
|
+
// const rotateY = d.rotateY * -1
|
|
443
|
+
// return {
|
|
444
|
+
// translate,
|
|
445
|
+
// scale,
|
|
446
|
+
// rotate,
|
|
447
|
+
// rotateX,
|
|
448
|
+
// rotateY,
|
|
449
|
+
// value: ''
|
|
450
|
+
// }
|
|
451
|
+
// }),
|
|
452
|
+
// )
|
|
453
|
+
const textReverseTransform$ = combineLatest({
|
|
454
|
+
gridAxesReverseTransform: gridAxesReverseTransform$,
|
|
455
|
+
gridContainerPosition: gridContainerPosition$
|
|
456
|
+
}).pipe(
|
|
457
|
+
takeUntil(destroy$),
|
|
458
|
+
switchMap(async (d) => d),
|
|
459
|
+
map(data => {
|
|
460
|
+
// const axisReverseTranslateValue = `translate(${data.gridAxesReverseTransform.translate[0]}px, ${data.gridAxesReverseTransform.translate[1]}px)`
|
|
461
|
+
const axesRotateXYReverseValue = `rotateX(${data.gridAxesReverseTransform.rotateX}deg) rotateY(${data.gridAxesReverseTransform.rotateY}deg)`
|
|
462
|
+
const axesRotateReverseValue = `rotate(${data.gridAxesReverseTransform.rotate}deg)`
|
|
463
|
+
const containerScaleReverseValue = `scale(${1 / data.gridContainerPosition[0].scale[0]}, ${1 / data.gridContainerPosition[0].scale[1]})`
|
|
464
|
+
// 必須按照順序(先抵消外層rotate,再抵消最外層scale)
|
|
465
|
+
return `${axesRotateXYReverseValue} ${axesRotateReverseValue} ${containerScaleReverseValue}`
|
|
466
|
+
}),
|
|
467
|
+
distinctUntilChanged()
|
|
468
|
+
)
|
|
469
|
+
|
|
470
|
+
const textReverseTransformWithRotate$ = combineLatest({
|
|
471
|
+
textReverseTransform: textReverseTransform$,
|
|
472
|
+
baseCategoryAxisParams: baseCategoryAxisParams$,
|
|
473
|
+
}).pipe(
|
|
474
|
+
takeUntil(destroy$),
|
|
475
|
+
switchMap(async (d) => d),
|
|
476
|
+
map(data => {
|
|
477
|
+
// 必須按照順序(先抵消外層rotate,再抵消最外層scale,最後再做本身的rotate)
|
|
478
|
+
return `${data.textReverseTransform} rotate(${data.baseCategoryAxisParams.tickTextRotate}deg)`
|
|
479
|
+
})
|
|
480
|
+
)
|
|
481
|
+
|
|
482
|
+
// 使用pointScale計算非連續性比例尺
|
|
483
|
+
// const categoryScale$: Observable<d3.ScalePoint<string>> = new Observable(subscriber => {
|
|
484
|
+
// combineLatest({
|
|
485
|
+
// fullDataFormatter: fullDataFormatter$,
|
|
486
|
+
// gridAxesSize: gridAxesSize$,
|
|
487
|
+
// computedData: computedData$
|
|
488
|
+
// }).pipe(
|
|
489
|
+
// takeUntil(destroy$),
|
|
490
|
+
// switchMap(async (d) => d),
|
|
491
|
+
// ).subscribe(data => {
|
|
492
|
+
// const categoryMin = 0
|
|
493
|
+
// const categoryMax = data.computedData[0] ? data.computedData[0].length - 1 : 0
|
|
494
|
+
// const categoryScaleDomainMin = data.fullDataFormatter.categoryAxis.scaleDomain[0] === 'auto'
|
|
495
|
+
// ? categoryMin - data.fullDataFormatter.categoryAxis.scalePadding
|
|
496
|
+
// : data.fullDataFormatter.categoryAxis.scaleDomain[0] as number - data.fullDataFormatter.categoryAxis.scalePadding
|
|
497
|
+
// const categoryScaleDomainMax = data.fullDataFormatter.categoryAxis.scaleDomain[1] === 'auto'
|
|
498
|
+
// ? categoryMax + data.fullDataFormatter.categoryAxis.scalePadding
|
|
499
|
+
// : data.fullDataFormatter.categoryAxis.scaleDomain[1] as number + data.fullDataFormatter.categoryAxis.scalePadding
|
|
500
|
+
|
|
501
|
+
// const categoryLength = data.computedData[0]
|
|
502
|
+
// ? data.computedData[0].length
|
|
503
|
+
// : 0
|
|
504
|
+
|
|
505
|
+
// let _labels = (data.computedData[0] ?? []).map(d => d.categoryLabel)
|
|
506
|
+
|
|
507
|
+
// const axisLabels = new Array(categoryLength).fill(0)
|
|
508
|
+
// .map((d, i) => {
|
|
509
|
+
// return _labels[i] != null
|
|
510
|
+
// ? _labels[i]
|
|
511
|
+
// : String(i) // 沒有label則用序列號填充
|
|
512
|
+
// })
|
|
513
|
+
// .filter((d, i) => {
|
|
514
|
+
// return i >= categoryScaleDomainMin && i <= categoryScaleDomainMax
|
|
515
|
+
// })
|
|
516
|
+
|
|
517
|
+
|
|
518
|
+
// const padding = data.fullDataFormatter.categoryAxis.scalePadding
|
|
519
|
+
|
|
520
|
+
// const categoryScale = createLabelToAxisScale({
|
|
521
|
+
// axisLabels,
|
|
522
|
+
// axisWidth: data.gridAxesSize.width,
|
|
523
|
+
// padding
|
|
524
|
+
// })
|
|
525
|
+
|
|
526
|
+
// subscriber.next(categoryScale)
|
|
527
|
+
// })
|
|
528
|
+
// })
|
|
529
|
+
|
|
530
|
+
const categoryScaleDomain$ = combineLatest({
|
|
531
|
+
categoryAxis: categoryAxis$,
|
|
532
|
+
valueAxis: valueAxis$,
|
|
533
|
+
gridAxesSize: gridAxesSize$,
|
|
534
|
+
computedData: computedData$
|
|
535
|
+
}).pipe(
|
|
536
|
+
takeUntil(destroy$),
|
|
537
|
+
switchMap(async (d) => d),
|
|
538
|
+
map(data => {
|
|
539
|
+
const categoryMin = 0
|
|
540
|
+
const categoryMax = data.computedData[0] ? data.computedData[0].length - 1 : 0
|
|
541
|
+
// const categoryScaleDomainMin = data.fullDataFormatter.categoryAxis.scaleDomain[0] === 'auto'
|
|
542
|
+
// ? categoryMin - data.fullDataFormatter.categoryAxis.scalePadding
|
|
543
|
+
// : data.fullDataFormatter.categoryAxis.scaleDomain[0] as number - data.fullDataFormatter.categoryAxis.scalePadding
|
|
544
|
+
const categoryScaleDomainMin = data.categoryAxis.scaleDomain[0] - data.categoryAxis.scalePadding
|
|
545
|
+
const categoryScaleDomainMax = data.categoryAxis.scaleDomain[1] === 'max'
|
|
546
|
+
? categoryMax + data.categoryAxis.scalePadding
|
|
547
|
+
: data.categoryAxis.scaleDomain[1] as number + data.categoryAxis.scalePadding
|
|
548
|
+
|
|
549
|
+
return [categoryScaleDomainMin, categoryScaleDomainMax]
|
|
550
|
+
}),
|
|
551
|
+
shareReplay(1)
|
|
552
|
+
)
|
|
553
|
+
|
|
554
|
+
const categoryScale$ = combineLatest({
|
|
555
|
+
categoryScaleDomain: categoryScaleDomain$,
|
|
556
|
+
gridAxesSize: gridAxesSize$
|
|
557
|
+
}).pipe(
|
|
558
|
+
takeUntil(destroy$),
|
|
559
|
+
switchMap(async (d) => d),
|
|
560
|
+
map(data => {
|
|
561
|
+
const categoryScale: d3.ScaleLinear<number, number> = d3.scaleLinear()
|
|
562
|
+
.domain(data.categoryScaleDomain)
|
|
563
|
+
.range([0, data.gridAxesSize.width])
|
|
564
|
+
return categoryScale
|
|
565
|
+
})
|
|
566
|
+
)
|
|
567
|
+
|
|
568
|
+
const categoryLabels$ = computedData$.pipe(
|
|
569
|
+
map(computedData => (computedData[0] ?? []).map(d => d.category))
|
|
570
|
+
)
|
|
571
|
+
|
|
572
|
+
const tickTextAlign$: Observable<TextAlign> = combineLatest({
|
|
573
|
+
categoryAxis: categoryAxis$,
|
|
574
|
+
baseCategoryAxisParams: baseCategoryAxisParams$
|
|
575
|
+
}).pipe(
|
|
576
|
+
takeUntil(destroy$),
|
|
577
|
+
switchMap(async (d) => d),
|
|
578
|
+
map(data => {
|
|
579
|
+
let textAnchor: 'start' | 'middle' | 'end' = 'middle'
|
|
580
|
+
let dominantBaseline: 'auto' | 'middle' | 'hanging' = 'hanging'
|
|
581
|
+
|
|
582
|
+
if (data.categoryAxis.position === 'bottom') {
|
|
583
|
+
textAnchor = data.baseCategoryAxisParams.tickTextRotate
|
|
584
|
+
? 'end'
|
|
585
|
+
: 'middle'
|
|
586
|
+
dominantBaseline = 'hanging'
|
|
587
|
+
} else if (data.categoryAxis.position === 'top') {
|
|
588
|
+
textAnchor = data.baseCategoryAxisParams.tickTextRotate
|
|
589
|
+
? 'start'
|
|
590
|
+
: 'middle'
|
|
591
|
+
dominantBaseline = 'auto'
|
|
592
|
+
} else if (data.categoryAxis.position === 'left') {
|
|
593
|
+
textAnchor = 'end'
|
|
594
|
+
dominantBaseline = 'middle'
|
|
595
|
+
} else if (data.categoryAxis.position === 'right') {
|
|
596
|
+
textAnchor = 'start'
|
|
597
|
+
dominantBaseline = 'middle'
|
|
598
|
+
}
|
|
599
|
+
return {
|
|
600
|
+
textAnchor,
|
|
601
|
+
dominantBaseline
|
|
602
|
+
}
|
|
603
|
+
})
|
|
604
|
+
)
|
|
605
|
+
|
|
606
|
+
const axisLabelAlign$: Observable<TextAlign> = combineLatest({
|
|
607
|
+
categoryAxis: categoryAxis$,
|
|
608
|
+
valueAxis: valueAxis$
|
|
609
|
+
}).pipe(
|
|
610
|
+
takeUntil(destroy$),
|
|
611
|
+
debounceTime(0),
|
|
612
|
+
map(data => {
|
|
613
|
+
let textAnchor: 'start' | 'middle' | 'end' = 'start'
|
|
614
|
+
let dominantBaseline: 'auto' | 'middle' | 'hanging' = 'hanging'
|
|
615
|
+
|
|
616
|
+
if (data.categoryAxis.position === 'bottom') {
|
|
617
|
+
dominantBaseline = 'hanging'
|
|
618
|
+
} else if (data.categoryAxis.position === 'top') {
|
|
619
|
+
dominantBaseline = 'auto'
|
|
620
|
+
} else if (data.categoryAxis.position === 'left') {
|
|
621
|
+
textAnchor = 'end'
|
|
622
|
+
} else if (data.categoryAxis.position === 'right') {
|
|
623
|
+
textAnchor = 'start'
|
|
624
|
+
}
|
|
625
|
+
if (data.valueAxis.position === 'left') {
|
|
626
|
+
textAnchor = 'start'
|
|
627
|
+
} else if (data.valueAxis.position === 'right') {
|
|
628
|
+
textAnchor = 'end'
|
|
629
|
+
} else if (data.valueAxis.position === 'bottom') {
|
|
630
|
+
dominantBaseline = 'auto'
|
|
631
|
+
} else if (data.valueAxis.position === 'top') {
|
|
632
|
+
dominantBaseline = 'hanging'
|
|
633
|
+
}
|
|
634
|
+
return {
|
|
635
|
+
textAnchor,
|
|
636
|
+
dominantBaseline
|
|
637
|
+
}
|
|
638
|
+
})
|
|
639
|
+
)
|
|
640
|
+
|
|
641
|
+
const categoryLabelData$ = combineLatest({
|
|
642
|
+
categoryLabels: categoryLabels$,
|
|
643
|
+
baseCategoryAxisParams: baseCategoryAxisParams$
|
|
644
|
+
}).pipe(
|
|
645
|
+
takeUntil(destroy$),
|
|
646
|
+
switchMap(async (d) => d),
|
|
647
|
+
map(data => {
|
|
648
|
+
return createGroupLabelData(data.categoryLabels, data.baseCategoryAxisParams.tickFormat)
|
|
649
|
+
})
|
|
650
|
+
)
|
|
651
|
+
|
|
652
|
+
combineLatest({
|
|
653
|
+
axisSelection: axisSelection$,
|
|
654
|
+
baseCategoryAxisParams: baseCategoryAxisParams$,
|
|
655
|
+
tickTextAlign: tickTextAlign$,
|
|
656
|
+
axisLabelAlign: axisLabelAlign$,
|
|
657
|
+
gridAxesSize: gridAxesSize$,
|
|
658
|
+
categoryAxis: categoryAxis$,
|
|
659
|
+
valueAxis: valueAxis$,
|
|
660
|
+
theme: theme$,
|
|
661
|
+
styles: styles$,
|
|
662
|
+
categoryScale: categoryScale$,
|
|
663
|
+
categoryScaleDomain: categoryScaleDomain$,
|
|
664
|
+
// categoryLabels: categoryLabels$,
|
|
665
|
+
categoryLabelData: categoryLabelData$,
|
|
666
|
+
textReverseTransform: textReverseTransform$,
|
|
667
|
+
textReverseTransformWithRotate: textReverseTransformWithRotate$,
|
|
668
|
+
fontSizePx: fontSizePx$
|
|
669
|
+
// tickTextFormatter: tickTextFormatter$
|
|
670
|
+
}).pipe(
|
|
671
|
+
takeUntil(destroy$),
|
|
672
|
+
switchMap(async (d) => d),
|
|
673
|
+
).subscribe(data => {
|
|
674
|
+
|
|
675
|
+
renderAxis({
|
|
676
|
+
selection: data.axisSelection,
|
|
677
|
+
xAxisClassName,
|
|
678
|
+
baseCategoryAxisParams: data.baseCategoryAxisParams,
|
|
679
|
+
tickTextAlign: data.tickTextAlign,
|
|
680
|
+
gridAxesSize: data.gridAxesSize,
|
|
681
|
+
categoryAxis: data.categoryAxis,
|
|
682
|
+
theme: data.theme,
|
|
683
|
+
categoryScale: data.categoryScale,
|
|
684
|
+
categoryScaleDomain: data.categoryScaleDomain,
|
|
685
|
+
// categoryLabels: data.categoryLabels,
|
|
686
|
+
categoryLabelData: data.categoryLabelData,
|
|
687
|
+
textReverseTransformWithRotate: data.textReverseTransformWithRotate,
|
|
688
|
+
fontSizePx: data.fontSizePx
|
|
689
|
+
})
|
|
690
|
+
|
|
691
|
+
renderAxisLabel({
|
|
692
|
+
selection: data.axisSelection,
|
|
693
|
+
categoryLabelClassName,
|
|
694
|
+
baseCategoryAxisParams: data.baseCategoryAxisParams,
|
|
695
|
+
axisLabelAlign: data.axisLabelAlign,
|
|
696
|
+
gridAxesSize: data.gridAxesSize,
|
|
697
|
+
categoryAxis: data.categoryAxis,
|
|
698
|
+
valueAxis: data.valueAxis,
|
|
699
|
+
theme: data.theme,
|
|
700
|
+
styles: data.styles,
|
|
701
|
+
textReverseTransform: data.textReverseTransform,
|
|
702
|
+
})
|
|
703
|
+
})
|
|
704
|
+
|
|
705
|
+
return () => {
|
|
706
|
+
destroy$.next(undefined)
|
|
707
|
+
}
|
|
708
|
+
})
|