@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,458 @@
|
|
|
1
|
+
import type { TooltipParams, TooltipPluginParams } from './types'
|
|
2
|
+
import type { EventData, ModelDatumMultivariate, ModelDatumSeries } from '@orbcharts/core'
|
|
3
|
+
|
|
4
|
+
export const DEFAULT_SERIES_TOOLTIP_PLUGIN_PARAMS: TooltipPluginParams = {
|
|
5
|
+
styles: {
|
|
6
|
+
padding: {
|
|
7
|
+
top: 60,
|
|
8
|
+
right: 60,
|
|
9
|
+
bottom: 60,
|
|
10
|
+
left: 60
|
|
11
|
+
},
|
|
12
|
+
highlightTarget: 'datum',
|
|
13
|
+
highlightDefault: null,
|
|
14
|
+
unhighlightedOpacity: 0.3,
|
|
15
|
+
transitionDuration: 800,
|
|
16
|
+
transitionEase: 'easeCubic'
|
|
17
|
+
},
|
|
18
|
+
visibleFilter: (datum: ModelDatumSeries) => true,
|
|
19
|
+
sort: null,
|
|
20
|
+
datasetIndex: 0
|
|
21
|
+
}
|
|
22
|
+
DEFAULT_SERIES_TOOLTIP_PLUGIN_PARAMS.visibleFilter.toString = () => '(datum) => true'
|
|
23
|
+
|
|
24
|
+
export const DEFAULT_SERIES_TOOLTIP_PARAMS: TooltipParams = {
|
|
25
|
+
backgroundColorType: 'background',
|
|
26
|
+
strokeColorType: 'primary',
|
|
27
|
+
backgroundOpacity: 0.8,
|
|
28
|
+
textColorType: 'primary',
|
|
29
|
+
offset: [20, 5],
|
|
30
|
+
padding: 10,
|
|
31
|
+
// renderFn: (eventData, { styles, utils }) => {
|
|
32
|
+
// const hasSeriesLabel = eventData.target.series.slice(0, 7) === 'series_' ? false : true
|
|
33
|
+
// const hasDatumLabel = eventData.target.name.slice(0, 7) === 'series_' ? false : true
|
|
34
|
+
// const valueText = utils.toCurrency(eventData.target.value)
|
|
35
|
+
// const bulletWidth = styles.textSizePx * 0.7
|
|
36
|
+
// const offset = (styles.textSizePx / 2) - (bulletWidth / 2)
|
|
37
|
+
// const seriesSvg = hasSeriesLabel
|
|
38
|
+
// ? `<rect width="${bulletWidth}" height="${bulletWidth}" x="${offset}" y="${offset - 1}" rx="${bulletWidth / 2}" fill="${eventData.target.color}"></rect>
|
|
39
|
+
// <text x="${styles.textSizePx * 1.5}" font-size="${styles.textSizePx}" dominant-baseline="hanging" fill="${styles.textColor}">
|
|
40
|
+
// <tspan>${eventData.target.name}</tspan>
|
|
41
|
+
// </text>`
|
|
42
|
+
// : ''
|
|
43
|
+
// const datumLabelSvg = hasDatumLabel
|
|
44
|
+
// ? `<tspan>${eventData.target.name}</tspan> `
|
|
45
|
+
// : ''
|
|
46
|
+
// const seriesLabelTextWidth = hasSeriesLabel
|
|
47
|
+
// ? utils.measureTextWidth(`${eventData.target.series}${valueText}`, styles.textSizePx) + styles.textSizePx * 1.5
|
|
48
|
+
// : 0
|
|
49
|
+
// const datumLabelTextWidth = hasDatumLabel
|
|
50
|
+
// ? utils.measureTextWidth(`${eventData.target.name}${valueText}`, styles.textSizePx)
|
|
51
|
+
// : 0
|
|
52
|
+
// const maxTextWidth = Math.max(seriesLabelTextWidth, datumLabelTextWidth)
|
|
53
|
+
// const lineEndX = hasDatumLabel
|
|
54
|
+
// ? maxTextWidth + styles.textSizePx * 1.5
|
|
55
|
+
// : 0
|
|
56
|
+
// const valueTextAnchor = hasDatumLabel ? 'end' : 'start'
|
|
57
|
+
// const datumSvg = `<text font-size="${styles.textSizePx}" dominant-baseline="hanging" fill="${styles.textColor}">
|
|
58
|
+
// ${datumLabelSvg}<tspan font-weight="bold" text-anchor="${valueTextAnchor}" x="${lineEndX}">${valueText}</tspan>
|
|
59
|
+
// </text>`
|
|
60
|
+
|
|
61
|
+
// return `${seriesSvg}
|
|
62
|
+
// <g ${hasSeriesLabel ? `transform="translate(0, ${styles.textSizePx * 2})"` : ''}>
|
|
63
|
+
// ${datumSvg}
|
|
64
|
+
// </g>`
|
|
65
|
+
// },
|
|
66
|
+
renderFn: (eventData, { styles, utils, categoryData }) => {
|
|
67
|
+
function renderSeriesData () {
|
|
68
|
+
const hasSeriesLabel = eventData.target.series.slice(0, 7) === 'series_' ? false : true
|
|
69
|
+
const hasDatumLabel = eventData.target.name.slice(0, 7) === 'series_' ? false : true
|
|
70
|
+
const valueText = utils.toCurrency(eventData.target.value)
|
|
71
|
+
const bulletWidth = styles.textSizePx * 0.7
|
|
72
|
+
const offset = (styles.textSizePx / 2) - (bulletWidth / 2)
|
|
73
|
+
const seriesSvg = hasSeriesLabel
|
|
74
|
+
? `<rect width="${bulletWidth}" height="${bulletWidth}" x="${offset}" y="${offset - 1}" rx="${bulletWidth / 2}" fill="${eventData.target.color}"></rect>
|
|
75
|
+
<text x="${styles.textSizePx * 1.5}" font-size="${styles.textSizePx}" dominant-baseline="hanging" fill="${styles.textColor}">
|
|
76
|
+
<tspan>${eventData.target.name}</tspan>
|
|
77
|
+
</text>`
|
|
78
|
+
: ''
|
|
79
|
+
const datumLabelSvg = hasDatumLabel
|
|
80
|
+
? `<tspan>${eventData.target.name}</tspan> `
|
|
81
|
+
: ''
|
|
82
|
+
const seriesLabelTextWidth = hasSeriesLabel
|
|
83
|
+
? utils.measureTextWidth(`${eventData.target.series}${valueText}`, styles.textSizePx) + styles.textSizePx * 1.5
|
|
84
|
+
: 0
|
|
85
|
+
const datumLabelTextWidth = hasDatumLabel
|
|
86
|
+
? utils.measureTextWidth(`${eventData.target.name}${valueText}`, styles.textSizePx)
|
|
87
|
+
: 0
|
|
88
|
+
const maxTextWidth = Math.max(seriesLabelTextWidth, datumLabelTextWidth)
|
|
89
|
+
const lineEndX = hasDatumLabel
|
|
90
|
+
? maxTextWidth + styles.textSizePx * 1.5
|
|
91
|
+
: 0
|
|
92
|
+
const valueTextAnchor = hasDatumLabel ? 'end' : 'start'
|
|
93
|
+
const datumSvg = `<text font-size="${styles.textSizePx}" dominant-baseline="hanging" fill="${styles.textColor}">
|
|
94
|
+
${datumLabelSvg}<tspan font-weight="bold" text-anchor="${valueTextAnchor}" x="${lineEndX}">${valueText}</tspan>
|
|
95
|
+
</text>`
|
|
96
|
+
|
|
97
|
+
return `${seriesSvg}
|
|
98
|
+
<g ${hasSeriesLabel ? `transform="translate(0, ${styles.textSizePx * 2})"` : ''}>
|
|
99
|
+
${datumSvg}
|
|
100
|
+
</g>`
|
|
101
|
+
}
|
|
102
|
+
function renderGridData () {
|
|
103
|
+
const bulletWidth = styles.textSizePx * 0.7
|
|
104
|
+
const offset = (styles.textSizePx / 2) - (bulletWidth / 2)
|
|
105
|
+
|
|
106
|
+
const titleSvg = `<g><text dominant-baseline="hanging" font-size="${styles.textSizePx}" fill="${styles.textColor}">${eventData.target.category}</text></g>`
|
|
107
|
+
const categoryLabelTextWidth = utils.measureTextWidth(eventData.target.category, styles.textSizePx)
|
|
108
|
+
const listTextWidth = categoryData.reduce((acc, category) => {
|
|
109
|
+
const text = `${category.series}${utils.toCurrency(category.value)}`
|
|
110
|
+
const _maxTextWidth = utils.measureTextWidth(text, styles.textSizePx)
|
|
111
|
+
return _maxTextWidth > acc ? _maxTextWidth : acc
|
|
112
|
+
}, 0)
|
|
113
|
+
const maxTextWidth = Math.max(categoryLabelTextWidth, listTextWidth)
|
|
114
|
+
const lineEndX = maxTextWidth + styles.textSizePx * 3
|
|
115
|
+
const contentSvg = categoryData
|
|
116
|
+
.map((category, i) => {
|
|
117
|
+
const y = i * styles.textSizePx * 1.5
|
|
118
|
+
const isHighlight = category.id === (eventData.target && eventData.target.id)
|
|
119
|
+
return `<g transform="translate(0, ${styles.textSizePx * 2})">
|
|
120
|
+
<rect width="${bulletWidth}" height="${bulletWidth}" x="${offset}" y="${y + offset}" rx="${bulletWidth / 2}" fill="${category.color}"></rect>
|
|
121
|
+
<text x="${styles.textSizePx * 1.5}" y="${y}" font-size="${styles.textSizePx}" dominant-baseline="hanging" fill="${styles.textColor}">
|
|
122
|
+
<tspan font-weight="${isHighlight ? 'bold' : ''}">${category.series}</tspan>
|
|
123
|
+
<tspan font-weight="bold" text-anchor="end" x="${lineEndX}">${utils.toCurrency(category.value)}</tspan>
|
|
124
|
+
</text>
|
|
125
|
+
</g>`
|
|
126
|
+
})
|
|
127
|
+
.join('')
|
|
128
|
+
return `${titleSvg}
|
|
129
|
+
${contentSvg}`
|
|
130
|
+
}
|
|
131
|
+
function renderMultivariateData () {
|
|
132
|
+
const hasCategoryLabel = eventData.target.category === '' ? false : true
|
|
133
|
+
const hasDatumLabel = eventData == null || eventData.target.name.slice(0, 11) === 'multiValue_' ? false : true
|
|
134
|
+
const bulletWidth = styles.textSizePx * 0.7
|
|
135
|
+
const offset = (styles.textSizePx / 2) - (bulletWidth / 2)
|
|
136
|
+
const categorySvg = hasCategoryLabel
|
|
137
|
+
? `<rect width="${bulletWidth}" height="${bulletWidth}" x="${offset}" y="${offset - 1}" rx="${bulletWidth / 2}" fill="${eventData.target.color}"></rect>
|
|
138
|
+
<text x="${styles.textSizePx * 1.5}" font-size="${styles.textSizePx}" dominant-baseline="hanging" fill="${styles.textColor}">
|
|
139
|
+
<tspan>${eventData.target.category}</tspan>
|
|
140
|
+
</text>`
|
|
141
|
+
: ''
|
|
142
|
+
|
|
143
|
+
const datumLabelSvg = hasDatumLabel
|
|
144
|
+
? `<text font-size="${styles.textSizePx}" dominant-baseline="hanging" fill="${styles.textColor}">
|
|
145
|
+
<tspan>${eventData.target.name}</tspan>
|
|
146
|
+
</text>`
|
|
147
|
+
: ''
|
|
148
|
+
|
|
149
|
+
const maxTextWidth = (() => {
|
|
150
|
+
const categoryLabelTextWidth = utils.measureTextWidth(eventData.target.category, styles.textSizePx)
|
|
151
|
+
const datumLabelTextWidth = hasDatumLabel ? utils.measureTextWidth(eventData.target.name, styles.textSizePx) : 0
|
|
152
|
+
const valueDetailTextWidth = (eventData.target as ModelDatumMultivariate).multivariate.reduce((acc, detail) => {
|
|
153
|
+
const text = `${detail.name}${utils.toCurrency(detail.value)}`
|
|
154
|
+
const _maxTextWidth = utils.measureTextWidth(text, styles.textSizePx)
|
|
155
|
+
return _maxTextWidth > acc ? _maxTextWidth : acc
|
|
156
|
+
}, 0)
|
|
157
|
+
return Math.max(categoryLabelTextWidth, datumLabelTextWidth, valueDetailTextWidth)
|
|
158
|
+
})()
|
|
159
|
+
|
|
160
|
+
const valueDetailSvg = (eventData.target as ModelDatumMultivariate).multivariate.map((detail, i) => {
|
|
161
|
+
const y = (i * styles.textSizePx * 1.5) + (datumLabelSvg ? styles.textSizePx * 2 : 0)
|
|
162
|
+
const lineEndX = maxTextWidth + styles.textSizePx * 3
|
|
163
|
+
return `<text x="0" y="${y}" font-weight="bold" font-size="${styles.textSizePx}" dominant-baseline="hanging" fill="${styles.textColor}">
|
|
164
|
+
<tspan>${detail.name}</tspan>
|
|
165
|
+
<tspan text-anchor="end" x="${lineEndX}">${utils.toCurrency(detail.value)}</tspan>
|
|
166
|
+
</text>`
|
|
167
|
+
}).join('')
|
|
168
|
+
|
|
169
|
+
const datumDetailSvg = datumLabelSvg || valueDetailSvg
|
|
170
|
+
? `<g ${hasCategoryLabel ? `transform="translate(0, ${styles.textSizePx * 2})"` : ''}>
|
|
171
|
+
${datumLabelSvg}
|
|
172
|
+
${valueDetailSvg}
|
|
173
|
+
</g>`
|
|
174
|
+
: ''
|
|
175
|
+
|
|
176
|
+
return `${categorySvg}
|
|
177
|
+
${datumDetailSvg}`
|
|
178
|
+
}
|
|
179
|
+
function renderGraphData () {
|
|
180
|
+
const hasCategoryLabel = eventData.target.category ? true : false
|
|
181
|
+
const hasDatumLabel = eventData.target.name ? true : false
|
|
182
|
+
const valueText = utils.toCurrency(eventData.target.value)
|
|
183
|
+
const bulletWidth = styles.textSizePx * 0.7
|
|
184
|
+
const offset = (styles.textSizePx / 2) - (bulletWidth / 2)
|
|
185
|
+
const categorySvg = hasCategoryLabel
|
|
186
|
+
? `<rect width="${bulletWidth}" height="${bulletWidth}" x="${offset}" y="${offset - 1}" rx="${bulletWidth / 2}" fill="${eventData.target.color}"></rect>
|
|
187
|
+
<text x="${styles.textSizePx * 1.5}" font-size="${styles.textSizePx}" dominant-baseline="hanging" fill="${styles.textColor}">
|
|
188
|
+
<tspan>${eventData.target.category}</tspan>
|
|
189
|
+
</text>`
|
|
190
|
+
: ''
|
|
191
|
+
const datumLabelSvg = hasDatumLabel
|
|
192
|
+
? `<tspan>${eventData.target.name}</tspan> `
|
|
193
|
+
: ''
|
|
194
|
+
const categoryLabelTextWidth = hasCategoryLabel
|
|
195
|
+
? utils.measureTextWidth(`${eventData.target.category}${valueText}`, styles.textSizePx) + styles.textSizePx * 1.5
|
|
196
|
+
: 0
|
|
197
|
+
const datumLabelTextWidth = hasDatumLabel
|
|
198
|
+
? utils.measureTextWidth(`${eventData.target.name}${valueText}`, styles.textSizePx)
|
|
199
|
+
: 0
|
|
200
|
+
const maxTextWidth = Math.max(categoryLabelTextWidth, datumLabelTextWidth)
|
|
201
|
+
const lineEndX = hasDatumLabel
|
|
202
|
+
? maxTextWidth + styles.textSizePx * 0.5
|
|
203
|
+
: 0
|
|
204
|
+
const valueTextAnchor = hasDatumLabel ? 'end' : 'start'
|
|
205
|
+
const datumSvg = `<text font-size="${styles.textSizePx}" dominant-baseline="hanging" fill="${styles.textColor}">
|
|
206
|
+
${datumLabelSvg}<tspan font-weight="bold" text-anchor="${valueTextAnchor}" x="${lineEndX}">${valueText}</tspan>
|
|
207
|
+
</text>`
|
|
208
|
+
|
|
209
|
+
return `${categorySvg}
|
|
210
|
+
<g ${hasCategoryLabel ? `transform="translate(0, ${styles.textSizePx * 2})"` : ''}>
|
|
211
|
+
${datumSvg}
|
|
212
|
+
</g>`
|
|
213
|
+
}
|
|
214
|
+
function renderTreeData () {
|
|
215
|
+
const hasCategoryLabel = eventData.target.category ? true : false
|
|
216
|
+
const hasDatumLabel = eventData.target.name ? true : false
|
|
217
|
+
const valueText = utils.toCurrency(eventData.target.value)
|
|
218
|
+
const bulletWidth = styles.textSizePx * 0.7
|
|
219
|
+
const offset = (styles.textSizePx / 2) - (bulletWidth / 2)
|
|
220
|
+
const categorySvg = hasCategoryLabel
|
|
221
|
+
? `<rect width="${bulletWidth}" height="${bulletWidth}" x="${offset}" y="${offset - 1}" rx="${bulletWidth / 2}" fill="${eventData.target.color}"></rect>
|
|
222
|
+
<text x="${styles.textSizePx * 1.5}" font-size="${styles.textSizePx}" dominant-baseline="hanging" fill="${styles.textColor}">
|
|
223
|
+
<tspan>${eventData.target.category}</tspan>
|
|
224
|
+
</text>`
|
|
225
|
+
: ''
|
|
226
|
+
const datumLabelSvg = hasDatumLabel
|
|
227
|
+
? `<tspan>${eventData.target.name}</tspan> `
|
|
228
|
+
: ''
|
|
229
|
+
const categoryLabelTextWidth = hasCategoryLabel
|
|
230
|
+
? utils.measureTextWidth(`${eventData.target.category}${valueText}`, styles.textSizePx) + styles.textSizePx * 1.5
|
|
231
|
+
: 0
|
|
232
|
+
const datumLabelTextWidth = hasDatumLabel
|
|
233
|
+
? utils.measureTextWidth(`${eventData.target.name}${valueText}`, styles.textSizePx)
|
|
234
|
+
: 0
|
|
235
|
+
const maxTextWidth = Math.max(categoryLabelTextWidth, datumLabelTextWidth)
|
|
236
|
+
const lineEndX = hasDatumLabel
|
|
237
|
+
? maxTextWidth + styles.textSizePx * 0.5
|
|
238
|
+
: 0
|
|
239
|
+
const valueTextAnchor = hasDatumLabel ? 'end' : 'start'
|
|
240
|
+
const datumSvg = `<text font-size="${styles.textSizePx}" dominant-baseline="hanging" fill="${styles.textColor}">
|
|
241
|
+
${datumLabelSvg}<tspan font-weight="bold" text-anchor="${valueTextAnchor}" x="${lineEndX}">${valueText}</tspan>
|
|
242
|
+
</text>`
|
|
243
|
+
|
|
244
|
+
return `${categorySvg}
|
|
245
|
+
<g ${hasCategoryLabel ? `transform="translate(0, ${styles.textSizePx * 2})"` : ''}>
|
|
246
|
+
${datumSvg}
|
|
247
|
+
</g>`
|
|
248
|
+
}
|
|
249
|
+
if (eventData.target.modelType === 'series') {
|
|
250
|
+
return renderSeriesData()
|
|
251
|
+
} else if (eventData.target.modelType === 'grid') {
|
|
252
|
+
return renderGridData()
|
|
253
|
+
} else if (eventData.target.modelType === 'multivariate') {
|
|
254
|
+
return renderMultivariateData()
|
|
255
|
+
} else if (eventData.target.modelType === 'graph') {
|
|
256
|
+
return renderGraphData()
|
|
257
|
+
} else if (eventData.target.modelType === 'tree') {
|
|
258
|
+
return renderTreeData()
|
|
259
|
+
}
|
|
260
|
+
return ''
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
DEFAULT_SERIES_TOOLTIP_PARAMS.renderFn.toString = () => `(eventData, { styles, utils }) => {
|
|
264
|
+
function renderSeriesData () {
|
|
265
|
+
const hasSeriesLabel = eventData.target.series.slice(0, 7) === 'series_' ? false : true
|
|
266
|
+
const hasDatumLabel = eventData.target.name.slice(0, 7) === 'series_' ? false : true
|
|
267
|
+
const valueText = utils.toCurrency(eventData.target.value)
|
|
268
|
+
const bulletWidth = styles.textSizePx * 0.7
|
|
269
|
+
const offset = (styles.textSizePx / 2) - (bulletWidth / 2)
|
|
270
|
+
const seriesSvg = hasSeriesLabel
|
|
271
|
+
? \`<rect width="$\{bulletWidth}" height="$\{bulletWidth}" x="$\{offset}" y="$\{offset - 1}" rx="$\{bulletWidth / 2}" fill="$\{eventData.target.color}"></rect>
|
|
272
|
+
<text x="$\{styles.textSizePx * 1.5}" font-size="$\{styles.textSizePx}" dominant-baseline="hanging" fill="$\{styles.textColor}">
|
|
273
|
+
<tspan>$\{eventData.target.name}</tspan>
|
|
274
|
+
</text>\`
|
|
275
|
+
: ''
|
|
276
|
+
const datumLabelSvg = hasDatumLabel
|
|
277
|
+
? \`<tspan>$\{eventData.target.name}</tspan> \`
|
|
278
|
+
: ''
|
|
279
|
+
const seriesLabelTextWidth = hasSeriesLabel
|
|
280
|
+
? utils.measureTextWidth(\`$\{eventData.target.series}$\{valueText}\`, styles.textSizePx) + styles.textSizePx * 1.5
|
|
281
|
+
: 0
|
|
282
|
+
const datumLabelTextWidth = hasDatumLabel
|
|
283
|
+
? utils.measureTextWidth(\`$\{eventData.target.name}$\{valueText}\`, styles.textSizePx)
|
|
284
|
+
: 0
|
|
285
|
+
const maxTextWidth = Math.max(seriesLabelTextWidth, datumLabelTextWidth)
|
|
286
|
+
const lineEndX = hasDatumLabel
|
|
287
|
+
? maxTextWidth + styles.textSizePx * 1.5
|
|
288
|
+
: 0
|
|
289
|
+
const valueTextAnchor = hasDatumLabel ? 'end' : 'start'
|
|
290
|
+
const datumSvg = \`<text font-size="$\{styles.textSizePx}" dominant-baseline="hanging" fill="$\{styles.textColor}">
|
|
291
|
+
$\{datumLabelSvg}<tspan font-weight="bold" text-anchor="$\{valueTextAnchor}" x="$\{lineEndX}">$\{valueText}</tspan>
|
|
292
|
+
</text>\`
|
|
293
|
+
|
|
294
|
+
return \`$\{seriesSvg}
|
|
295
|
+
<g $\{hasSeriesLabel ? \`transform="translate(0, $\{styles.textSizePx * 2})"\` : ''}>
|
|
296
|
+
$\{datumSvg}
|
|
297
|
+
</g>\`
|
|
298
|
+
}
|
|
299
|
+
function renderGridData () \{
|
|
300
|
+
const bulletWidth = styles.textSizePx * 0.7
|
|
301
|
+
const offset = (styles.textSizePx / 2) - (bulletWidth / 2)
|
|
302
|
+
|
|
303
|
+
const titleSvg = \`<g><text dominant-baseline="hanging" font-size="$\{styles.textSizePx}" fill="$\{styles.textColor}">$\{eventData.target.category}</text></g>\`
|
|
304
|
+
const categoryLabelTextWidth = utils.measureTextWidth(eventData.target.category, styles.textSizePx)
|
|
305
|
+
const listTextWidth = categoryData.reduce((acc, category) => \{
|
|
306
|
+
const text = \`$\{category.series}$\{utils.toCurrency(category.value)}\`
|
|
307
|
+
const _maxTextWidth = utils.measureTextWidth(text, styles.textSizePx)
|
|
308
|
+
return _maxTextWidth > acc ? _maxTextWidth : acc
|
|
309
|
+
}, 0)
|
|
310
|
+
const maxTextWidth = Math.max(categoryLabelTextWidth, listTextWidth)
|
|
311
|
+
const lineEndX = maxTextWidth + styles.textSizePx * 3
|
|
312
|
+
const contentSvg = categoryData
|
|
313
|
+
.map((category, i) => \{
|
|
314
|
+
const y = i * styles.textSizePx * 1.5
|
|
315
|
+
const isHighlight = category.id === (eventData.target && eventData.target.id)
|
|
316
|
+
return \`<g transform="translate(0, $\{styles.textSizePx * 2})">
|
|
317
|
+
<rect width="$\{bulletWidth}" height="$\{bulletWidth}" x="$\{offset}" y="$\{y + offset}" rx="$\{bulletWidth / 2}" fill="$\{category.color}"></rect>
|
|
318
|
+
<text x="$\{styles.textSizePx * 1.5}" y="$\{y}" font-size="$\{styles.textSizePx}" dominant-baseline="hanging" fill="$\{styles.textColor}">
|
|
319
|
+
<tspan font-weight="$\{isHighlight ? 'bold' : ''}">$\{category.series}</tspan>
|
|
320
|
+
<tspan font-weight="bold" text-anchor="end" x="$\{lineEndX}">$\{utils.toCurrency(category.value)}</tspan>
|
|
321
|
+
</text>
|
|
322
|
+
</g>\`
|
|
323
|
+
})
|
|
324
|
+
.join('')
|
|
325
|
+
return \`$\{titleSvg}
|
|
326
|
+
$\{contentSvg}\`
|
|
327
|
+
}
|
|
328
|
+
function renderMultivariateData () \{
|
|
329
|
+
const hasCategoryLabel = eventData.target.category === '' ? false : true
|
|
330
|
+
const hasDatumLabel = eventData == null || eventData.target.name.slice(0, 11) === 'multiValue_' ? false : true
|
|
331
|
+
const bulletWidth = styles.textSizePx * 0.7
|
|
332
|
+
const offset = (styles.textSizePx / 2) - (bulletWidth / 2)
|
|
333
|
+
const categorySvg = hasCategoryLabel
|
|
334
|
+
? \`<rect width="$\{bulletWidth}" height="$\{bulletWidth}" x="$\{offset}" y="$\{offset - 1}" rx="$\{bulletWidth / 2}" fill="$\{eventData.target.color}"></rect>
|
|
335
|
+
<text x="$\{styles.textSizePx * 1.5}" font-size="$\{styles.textSizePx}" dominant-baseline="hanging" fill="$\{styles.textColor}">
|
|
336
|
+
<tspan>$\{eventData.target.category}</tspan>
|
|
337
|
+
</text>\`
|
|
338
|
+
: ''
|
|
339
|
+
|
|
340
|
+
const datumLabelSvg = hasDatumLabel
|
|
341
|
+
? \`<text font-size="$\{styles.textSizePx}" dominant-baseline="hanging" fill="$\{styles.textColor}">
|
|
342
|
+
<tspan>$\{eventData.target.name}</tspan>
|
|
343
|
+
</text>\`
|
|
344
|
+
: ''
|
|
345
|
+
|
|
346
|
+
const maxTextWidth = (() => \{
|
|
347
|
+
const categoryLabelTextWidth = utils.measureTextWidth(eventData.target.category, styles.textSizePx)
|
|
348
|
+
const datumLabelTextWidth = hasDatumLabel ? utils.measureTextWidth(eventData.target.name, styles.textSizePx) : 0
|
|
349
|
+
const valueDetailTextWidth = (eventData.target as ModelDatumMultivariate).multivariate.reduce((acc, detail) => \{
|
|
350
|
+
const text = \`$\{detail.name}$\{utils.toCurrency(detail.value)}\`
|
|
351
|
+
const _maxTextWidth = utils.measureTextWidth(text, styles.textSizePx)
|
|
352
|
+
return _maxTextWidth > acc ? _maxTextWidth : acc
|
|
353
|
+
}, 0)
|
|
354
|
+
return Math.max(categoryLabelTextWidth, datumLabelTextWidth, valueDetailTextWidth)
|
|
355
|
+
})()
|
|
356
|
+
|
|
357
|
+
const valueDetailSvg = (eventData.target as ModelDatumMultivariate).multivariate.map((detail, i) => \{
|
|
358
|
+
const y = (i * styles.textSizePx * 1.5) + (datumLabelSvg ? styles.textSizePx * 2 : 0)
|
|
359
|
+
const lineEndX = maxTextWidth + styles.textSizePx * 3
|
|
360
|
+
return \`<text x="0" y="$\{y}" font-weight="bold" font-size="$\{styles.textSizePx}" dominant-baseline="hanging" fill="$\{styles.textColor}">
|
|
361
|
+
<tspan>$\{detail.name}</tspan>
|
|
362
|
+
<tspan text-anchor="end" x="$\{lineEndX}">$\{utils.toCurrency(detail.value)}</tspan>
|
|
363
|
+
</text>\`
|
|
364
|
+
}).join('')
|
|
365
|
+
|
|
366
|
+
const datumDetailSvg = datumLabelSvg || valueDetailSvg
|
|
367
|
+
? \`<g $\{hasCategoryLabel ? \`transform="translate(0, $\{styles.textSizePx * 2})"\` : ''}>
|
|
368
|
+
$\{datumLabelSvg}
|
|
369
|
+
$\{valueDetailSvg}
|
|
370
|
+
</g>\`
|
|
371
|
+
: ''
|
|
372
|
+
|
|
373
|
+
return \`$\{categorySvg}
|
|
374
|
+
$\{datumDetailSvg}\`
|
|
375
|
+
}
|
|
376
|
+
function renderGraphData () \{
|
|
377
|
+
const hasCategoryLabel = eventData.target.category ? true : false
|
|
378
|
+
const hasDatumLabel = eventData.target.name ? true : false
|
|
379
|
+
const valueText = utils.toCurrency(eventData.target.value)
|
|
380
|
+
const bulletWidth = styles.textSizePx * 0.7
|
|
381
|
+
const offset = (styles.textSizePx / 2) - (bulletWidth / 2)
|
|
382
|
+
const categorySvg = hasCategoryLabel
|
|
383
|
+
? \`<rect width="$\{bulletWidth}" height="$\{bulletWidth}" x="$\{offset}" y="$\{offset - 1}" rx="$\{bulletWidth / 2}" fill="$\{eventData.target.color}"></rect>
|
|
384
|
+
<text x="$\{styles.textSizePx * 1.5}" font-size="$\{styles.textSizePx}" dominant-baseline="hanging" fill="$\{styles.textColor}">
|
|
385
|
+
<tspan>$\{eventData.target.category}</tspan>
|
|
386
|
+
</text>\`
|
|
387
|
+
: ''
|
|
388
|
+
const datumLabelSvg = hasDatumLabel
|
|
389
|
+
? \`<tspan>$\{eventData.target.name}</tspan> \`
|
|
390
|
+
: ''
|
|
391
|
+
const categoryLabelTextWidth = hasCategoryLabel
|
|
392
|
+
? utils.measureTextWidth(\`$\{eventData.target.category}$\{valueText}\`, styles.textSizePx) + styles.textSizePx * 1.5
|
|
393
|
+
: 0
|
|
394
|
+
const datumLabelTextWidth = hasDatumLabel
|
|
395
|
+
? utils.measureTextWidth(\`$\{eventData.target.name}$\{valueText}\`, styles.textSizePx)
|
|
396
|
+
: 0
|
|
397
|
+
const maxTextWidth = Math.max(categoryLabelTextWidth, datumLabelTextWidth)
|
|
398
|
+
const lineEndX = hasDatumLabel
|
|
399
|
+
? maxTextWidth + styles.textSizePx * 0.5
|
|
400
|
+
: 0
|
|
401
|
+
const valueTextAnchor = hasDatumLabel ? 'end' : 'start'
|
|
402
|
+
const datumSvg = \`<text font-size="$\{styles.textSizePx}" dominant-baseline="hanging" fill="$\{styles.textColor}">
|
|
403
|
+
$\{datumLabelSvg}<tspan font-weight="bold" text-anchor="$\{valueTextAnchor}" x="$\{lineEndX}">$\{valueText}</tspan>
|
|
404
|
+
</text>\`
|
|
405
|
+
|
|
406
|
+
return \`$\{categorySvg}
|
|
407
|
+
<g $\{hasCategoryLabel ? \`transform="translate(0, $\{styles.textSizePx * 2})"\` : ''}>
|
|
408
|
+
$\{datumSvg}
|
|
409
|
+
</g>\`
|
|
410
|
+
}
|
|
411
|
+
function renderTreeData () \{
|
|
412
|
+
const hasCategoryLabel = eventData.target.category ? true : false
|
|
413
|
+
const hasDatumLabel = eventData.target.name ? true : false
|
|
414
|
+
const valueText = utils.toCurrency(eventData.target.value)
|
|
415
|
+
const bulletWidth = styles.textSizePx * 0.7
|
|
416
|
+
const offset = (styles.textSizePx / 2) - (bulletWidth / 2)
|
|
417
|
+
const categorySvg = hasCategoryLabel
|
|
418
|
+
? \`<rect width="$\{bulletWidth}" height="$\{bulletWidth}" x="$\{offset}" y="$\{offset - 1}" rx="$\{bulletWidth / 2}" fill="$\{eventData.target.color}"></rect>
|
|
419
|
+
<text x="$\{styles.textSizePx * 1.5}" font-size="$\{styles.textSizePx}" dominant-baseline="hanging" fill="$\{styles.textColor}">
|
|
420
|
+
<tspan>$\{eventData.target.category}</tspan>
|
|
421
|
+
</text>\`
|
|
422
|
+
: ''
|
|
423
|
+
const datumLabelSvg = hasDatumLabel
|
|
424
|
+
? \`<tspan>$\{eventData.target.name}</tspan> \`
|
|
425
|
+
: ''
|
|
426
|
+
const categoryLabelTextWidth = hasCategoryLabel
|
|
427
|
+
? utils.measureTextWidth(\`$\{eventData.target.category}$\{valueText}\`, styles.textSizePx) + styles.textSizePx * 1.5
|
|
428
|
+
: 0
|
|
429
|
+
const datumLabelTextWidth = hasDatumLabel
|
|
430
|
+
? utils.measureTextWidth(\`$\{eventData.target.name}$\{valueText}\`, styles.textSizePx)
|
|
431
|
+
: 0
|
|
432
|
+
const maxTextWidth = Math.max(categoryLabelTextWidth, datumLabelTextWidth)
|
|
433
|
+
const lineEndX = hasDatumLabel
|
|
434
|
+
? maxTextWidth + styles.textSizePx * 0.5
|
|
435
|
+
: 0
|
|
436
|
+
const valueTextAnchor = hasDatumLabel ? 'end' : 'start'
|
|
437
|
+
const datumSvg = \`<text font-size="$\{styles.textSizePx}" dominant-baseline="hanging" fill="$\{styles.textColor}">
|
|
438
|
+
$\{datumLabelSvg}<tspan font-weight="bold" text-anchor="$\{valueTextAnchor}" x="$\{lineEndX}">$\{valueText}</tspan>
|
|
439
|
+
</text>\`
|
|
440
|
+
|
|
441
|
+
return \`$\{categorySvg}
|
|
442
|
+
<g $\{hasCategoryLabel ? \`transform="translate(0, $\{styles.textSizePx * 2})"\` : ''}>
|
|
443
|
+
$\{datumSvg}
|
|
444
|
+
</g>\`
|
|
445
|
+
}
|
|
446
|
+
if (eventData.target.modelType === 'series') \{
|
|
447
|
+
return renderSeriesData()
|
|
448
|
+
} else if (eventData.target.modelType === 'grid') \{
|
|
449
|
+
return renderGridData()
|
|
450
|
+
} else if (eventData.target.modelType === 'multivariate') \{
|
|
451
|
+
return renderMultivariateData()
|
|
452
|
+
} else if (eventData.target.modelType === 'graph') \{
|
|
453
|
+
return renderGraphData()
|
|
454
|
+
} else if (eventData.target.modelType === 'tree') \{
|
|
455
|
+
return renderTreeData()
|
|
456
|
+
}
|
|
457
|
+
return ''
|
|
458
|
+
}`
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import * as d3 from 'd3'
|
|
2
|
+
import {
|
|
3
|
+
Subject,
|
|
4
|
+
Observable,
|
|
5
|
+
BehaviorSubject} from 'rxjs'
|
|
6
|
+
import type { TooltipExtendContext, TooltipPluginParams, TooltipParams } from "../types"
|
|
7
|
+
import type { ColorType } from '@orbcharts/core'
|
|
8
|
+
import { defineSVGLayer } from '@orbcharts/core'
|
|
9
|
+
import { validateObject } from '@orbcharts/core'
|
|
10
|
+
import { DEFAULT_SERIES_TOOLTIP_PARAMS } from "../defaults"
|
|
11
|
+
import { LAYER_INDEX_OF_TOOLTIP } from '../../../const/layerIndex'
|
|
12
|
+
import { createBaseTooltip } from '../../../baseLayers/BaseTooltip'
|
|
13
|
+
|
|
14
|
+
const pluginName = 'Tooltip'
|
|
15
|
+
const layerName = 'Tooltip'
|
|
16
|
+
|
|
17
|
+
export const Tooltip = defineSVGLayer<TooltipExtendContext, TooltipPluginParams, TooltipParams>({
|
|
18
|
+
name: layerName,
|
|
19
|
+
defaultParams: DEFAULT_SERIES_TOOLTIP_PARAMS,
|
|
20
|
+
layerIndex: LAYER_INDEX_OF_TOOLTIP,
|
|
21
|
+
initShow: true,
|
|
22
|
+
validator: (params) => {
|
|
23
|
+
const result = validateObject(params, {
|
|
24
|
+
backgroundColorType: {
|
|
25
|
+
toBe: 'ColorType',
|
|
26
|
+
test: (value: any) => {
|
|
27
|
+
const colorTypes: ColorType[] = ['data', 'primary', 'secondary', 'dataContrast', 'background', 'none']
|
|
28
|
+
return typeof value === 'string'
|
|
29
|
+
&& colorTypes.includes(value as ColorType)
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
backgroundOpacity: {
|
|
33
|
+
toBeTypes: ['number']
|
|
34
|
+
},
|
|
35
|
+
strokeColorType: {
|
|
36
|
+
toBe: 'ColorType',
|
|
37
|
+
test: (value: any) => {
|
|
38
|
+
const colorTypes: ColorType[] = ['data', 'primary', 'secondary', 'dataContrast', 'background', 'none']
|
|
39
|
+
return typeof value === 'string'
|
|
40
|
+
&& colorTypes.includes(value as ColorType)
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
offset: {
|
|
44
|
+
toBe: '[number, number]',
|
|
45
|
+
test: (value: any) => {
|
|
46
|
+
return Array.isArray(value)
|
|
47
|
+
&& value.length === 2
|
|
48
|
+
&& typeof value[0] === 'number'
|
|
49
|
+
&& typeof value[1] === 'number'
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
padding: {
|
|
53
|
+
toBeTypes: ['number']
|
|
54
|
+
},
|
|
55
|
+
textColorType: {
|
|
56
|
+
toBe: 'ColorType',
|
|
57
|
+
test: (value: any) => {
|
|
58
|
+
const colorTypes: ColorType[] = ['data', 'primary', 'secondary', 'dataContrast', 'background', 'none']
|
|
59
|
+
return typeof value === 'string'
|
|
60
|
+
&& colorTypes.includes(value as ColorType)
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
renderFn: {
|
|
64
|
+
toBeTypes: ['Function']
|
|
65
|
+
},
|
|
66
|
+
})
|
|
67
|
+
return result
|
|
68
|
+
},
|
|
69
|
+
setup: ({ svgG, pluginParams$, layerParams$, context }) => {
|
|
70
|
+
|
|
71
|
+
const destroy$ = new Subject()
|
|
72
|
+
|
|
73
|
+
const unsubscribeTooltip = createBaseTooltip({
|
|
74
|
+
rootSelection: d3.select(svgG),
|
|
75
|
+
pluginName,
|
|
76
|
+
layerName,
|
|
77
|
+
baseTooltipParams$: layerParams$,
|
|
78
|
+
theme$: context.theme$,
|
|
79
|
+
layout$: context.layout$,
|
|
80
|
+
event$: context.event$,
|
|
81
|
+
SeriesDataMap$: context.SeriesDataMap$,
|
|
82
|
+
CategoryDataMap$: context.CategoryDataMap$
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
return () => {
|
|
86
|
+
destroy$.next(undefined)
|
|
87
|
+
unsubscribeTooltip()
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
})
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
|
|
2
|
+
import { Observable } from 'rxjs'
|
|
3
|
+
import type { ColorType, ModelDatumSeries, EventData } from '@orbcharts/core'
|
|
4
|
+
import type { GraphicStyles, Layout, VisibleFilter } from '../../types/PluginParams'
|
|
5
|
+
import { ComputedDatum, ComputedDatumSeries } from '../../types/ComputedData'
|
|
6
|
+
import { BaseTooltipStyle, BaseTooltipUtils } from '../../baseLayers/types'
|
|
7
|
+
|
|
8
|
+
// context
|
|
9
|
+
export interface TooltipExtendContext {
|
|
10
|
+
layout$: Observable<Layout>
|
|
11
|
+
fontSizePx$: Observable<number>
|
|
12
|
+
SeriesDataMap$: Observable<Map<string, ComputedDatumSeries[]>>
|
|
13
|
+
CategoryDataMap$: Observable<Map<string, ComputedDatumSeries[]>>
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// plugin params
|
|
17
|
+
export interface TooltipPluginParams {
|
|
18
|
+
styles: GraphicStyles
|
|
19
|
+
visibleFilter: VisibleFilter<'series'>
|
|
20
|
+
sort: ((a: ModelDatumSeries, b: ModelDatumSeries) => number) | null
|
|
21
|
+
// container: Container
|
|
22
|
+
// separateSeries: boolean
|
|
23
|
+
// separateName: boolean
|
|
24
|
+
datasetIndex: number
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// all layer params
|
|
28
|
+
export interface TooltipAllLayerParams {
|
|
29
|
+
Tooltip: TooltipParams
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// -- layer params --
|
|
33
|
+
|
|
34
|
+
export interface TooltipParams {
|
|
35
|
+
backgroundColorType: ColorType
|
|
36
|
+
backgroundOpacity: number
|
|
37
|
+
strokeColorType: ColorType
|
|
38
|
+
textColorType: ColorType
|
|
39
|
+
offset: [number, number]
|
|
40
|
+
padding: number
|
|
41
|
+
// textRenderFn: (<T extends ChartType>(eventData: EventTypeMap<T>) => string[] | string) | null
|
|
42
|
+
// svgRenderFn: (<T extends ChartType>(eventData: EventTypeMap<T>) => string) | null
|
|
43
|
+
renderFn: (
|
|
44
|
+
(
|
|
45
|
+
eventData: EventData,
|
|
46
|
+
context: {
|
|
47
|
+
styles: BaseTooltipStyle
|
|
48
|
+
utils: BaseTooltipUtils
|
|
49
|
+
seriesData: ComputedDatum<'series'>[]
|
|
50
|
+
categoryData: ComputedDatum<'series'>[]
|
|
51
|
+
}
|
|
52
|
+
) => string[] | string
|
|
53
|
+
)
|
|
54
|
+
}
|
|
55
|
+
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import * as d3 from 'd3'
|
|
2
|
+
// import type { ModelDatumSeries } from '@orbcharts/core'
|
|
3
|
+
import type { ComputedDatumSeries } from '../../types/ComputedData'
|
|
4
|
+
// import type { D3PieDatum, PieDatum } from '../types'
|
|
5
|
+
|
|
6
|
+
// 由d3.pie()建出來的資料格式
|
|
7
|
+
export interface D3PieDatum {
|
|
8
|
+
data: any
|
|
9
|
+
index: number,
|
|
10
|
+
value: number,
|
|
11
|
+
startAngle: number,
|
|
12
|
+
endAngle: number,
|
|
13
|
+
padAngle: number,
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface PieDatum extends D3PieDatum {
|
|
17
|
+
data: ComputedDatumSeries
|
|
18
|
+
id: string
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function makePieData ({ data, startAngle, endAngle }: {
|
|
22
|
+
data: ComputedDatumSeries[]
|
|
23
|
+
startAngle: number
|
|
24
|
+
endAngle: number
|
|
25
|
+
// itemLabels: string[]
|
|
26
|
+
// arcLabels: string[]
|
|
27
|
+
}): PieDatum[] {
|
|
28
|
+
let pie = d3.pie<any, any>()
|
|
29
|
+
.startAngle(startAngle)
|
|
30
|
+
// .endAngle(startAngle + (endAngle - startAngle) * t)
|
|
31
|
+
.endAngle(endAngle)
|
|
32
|
+
.value(d => d.value)
|
|
33
|
+
// .value((d) => d.visible == false ? 0 : d.value)
|
|
34
|
+
// .sort(null) // 不要排序
|
|
35
|
+
.sort((a, b) => a.seq - b.seq)
|
|
36
|
+
// .sort((a: any, b: any) => {
|
|
37
|
+
// return b.value - a.value
|
|
38
|
+
// })
|
|
39
|
+
// .sort(d3.ascending)
|
|
40
|
+
const pieData = pie(data)
|
|
41
|
+
return pieData.map((d: D3PieDatum, i: number) => {
|
|
42
|
+
// const itemLabel = d.data.itemLabel
|
|
43
|
+
let _d: any = d
|
|
44
|
+
_d.id = d.data.id
|
|
45
|
+
return _d
|
|
46
|
+
// return {
|
|
47
|
+
// ...d,
|
|
48
|
+
// itemIndex: itemLabels.indexOf(itemLabel),
|
|
49
|
+
// itemLabel,
|
|
50
|
+
// id: d.data.id,
|
|
51
|
+
// }
|
|
52
|
+
})
|
|
53
|
+
}
|