@gravity-ui/charts 1.8.0 → 1.10.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/dist/cjs/components/Axis/AxisX.d.ts +2 -1
- package/dist/cjs/components/Axis/AxisX.js +147 -141
- package/dist/cjs/components/Axis/AxisY.d.ts +2 -1
- package/dist/cjs/components/Axis/AxisY.js +118 -116
- package/dist/cjs/components/ChartInner/index.js +36 -9
- package/dist/cjs/components/ChartInner/useChartInnerHandlers.d.ts +1 -1
- package/dist/cjs/components/ChartInner/useChartInnerProps.d.ts +8 -5
- package/dist/cjs/components/ChartInner/useChartInnerProps.js +59 -10
- package/dist/cjs/components/ChartInner/utils.d.ts +3 -0
- package/dist/cjs/components/ChartInner/utils.js +28 -0
- package/dist/cjs/components/Legend/index.js +202 -191
- package/dist/cjs/components/Legend/styles.css +2 -0
- package/dist/cjs/components/Tooltip/ChartTooltipContent.d.ts +1 -1
- package/dist/cjs/components/Tooltip/DefaultContent.d.ts +1 -1
- package/dist/cjs/components/Tooltip/DefaultContent.js +1 -1
- package/dist/cjs/components/Tooltip/index.d.ts +1 -1
- package/dist/cjs/constants/chart-types.d.ts +12 -0
- package/dist/cjs/constants/chart-types.js +12 -0
- package/dist/cjs/constants/defaults/axis.d.ts +3 -1
- package/dist/cjs/constants/defaults/axis.js +10 -0
- package/dist/cjs/constants/index.d.ts +6 -47
- package/dist/cjs/constants/index.js +6 -72
- package/dist/cjs/constants/layout-algorithms.d.ts +7 -0
- package/dist/cjs/constants/layout-algorithms.js +8 -0
- package/dist/cjs/constants/line-styles.d.ts +20 -0
- package/dist/cjs/constants/line-styles.js +20 -0
- package/dist/cjs/constants/palette.d.ts +1 -0
- package/dist/cjs/constants/palette.js +22 -0
- package/dist/cjs/constants/symbol-types.d.ts +7 -0
- package/dist/cjs/constants/symbol-types.js +8 -0
- package/dist/cjs/constants/typography.d.ts +1 -0
- package/dist/cjs/constants/typography.js +1 -0
- package/dist/cjs/hooks/hooks-utils/index.d.ts +1 -0
- package/dist/cjs/hooks/hooks-utils/index.js +1 -0
- package/dist/cjs/hooks/hooks-utils/zoom.d.ts +8 -0
- package/dist/cjs/hooks/hooks-utils/zoom.js +81 -0
- package/dist/cjs/hooks/index.d.ts +1 -0
- package/dist/cjs/hooks/index.js +1 -0
- package/dist/cjs/hooks/useAxisScales/index.d.ts +4 -2
- package/dist/cjs/hooks/useAxisScales/index.js +22 -8
- package/dist/cjs/hooks/useBrush/index.d.ts +3 -0
- package/dist/cjs/hooks/useBrush/index.js +70 -0
- package/dist/cjs/hooks/useBrush/styles.css +10 -0
- package/dist/cjs/hooks/useBrush/types.d.ts +24 -0
- package/dist/cjs/hooks/useBrush/types.js +1 -0
- package/dist/cjs/hooks/useChartDimensions/index.d.ts +3 -3
- package/dist/cjs/hooks/useChartDimensions/index.js +2 -2
- package/dist/cjs/hooks/useChartDimensions/utils.d.ts +2 -2
- package/dist/cjs/hooks/useChartOptions/chart.d.ts +2 -1
- package/dist/cjs/hooks/useChartOptions/chart.js +80 -1
- package/dist/cjs/hooks/useChartOptions/index.js +3 -2
- package/dist/cjs/hooks/useChartOptions/types.d.ts +6 -2
- package/dist/cjs/hooks/useChartOptions/x-axis.d.ts +3 -3
- package/dist/cjs/hooks/useChartOptions/x-axis.js +22 -13
- package/dist/cjs/hooks/useChartOptions/y-axis.d.ts +3 -3
- package/dist/cjs/hooks/useChartOptions/y-axis.js +36 -21
- package/dist/cjs/hooks/useCrosshair/index.d.ts +17 -0
- package/dist/cjs/hooks/useCrosshair/index.js +139 -0
- package/dist/cjs/hooks/useCrosshair/useCrosshairHover.d.ts +11 -0
- package/dist/cjs/hooks/useCrosshair/useCrosshairHover.js +18 -0
- package/dist/cjs/hooks/useSeries/index.d.ts +8 -6
- package/dist/cjs/hooks/useSeries/index.js +41 -22
- package/dist/cjs/hooks/useSeries/prepare-bar-y.d.ts +27 -2
- package/dist/cjs/hooks/useSeries/prepare-bar-y.js +5 -5
- package/dist/cjs/hooks/useSeries/prepare-legend.d.ts +1 -1
- package/dist/cjs/hooks/useSeries/prepare-legend.js +27 -9
- package/dist/cjs/hooks/useSeries/prepare-line.d.ts +1 -2
- package/dist/cjs/hooks/useSeries/prepare-line.js +3 -3
- package/dist/cjs/hooks/useSeries/prepareSeries.d.ts +1 -1
- package/dist/cjs/hooks/useSeries/prepareSeries.js +2 -2
- package/dist/cjs/hooks/useSeries/types.d.ts +2 -1
- package/dist/cjs/hooks/useShapes/area/index.js +1 -1
- package/dist/cjs/hooks/useShapes/area/prepare-data.d.ts +1 -1
- package/dist/cjs/hooks/useShapes/area/prepare-data.js +32 -16
- package/dist/cjs/hooks/useShapes/area/types.d.ts +1 -0
- package/dist/cjs/hooks/useShapes/bar-x/prepare-data.d.ts +1 -1
- package/dist/cjs/hooks/useShapes/bar-x/prepare-data.js +17 -13
- package/dist/cjs/hooks/useShapes/bar-y/prepare-data.d.ts +1 -1
- package/dist/cjs/hooks/useShapes/bar-y/prepare-data.js +6 -6
- package/dist/cjs/hooks/useShapes/index.d.ts +1 -1
- package/dist/cjs/hooks/useShapes/index.js +40 -31
- package/dist/cjs/hooks/useShapes/line/prepare-data.d.ts +1 -1
- package/dist/cjs/hooks/useShapes/line/prepare-data.js +14 -11
- package/dist/cjs/hooks/useShapes/line/types.d.ts +1 -0
- package/dist/cjs/hooks/useShapes/marker.js +2 -2
- package/dist/cjs/hooks/useShapes/pie/index.js +3 -3
- package/dist/cjs/hooks/useShapes/pie/prepare-data.d.ts +1 -1
- package/dist/cjs/hooks/useShapes/pie/prepare-data.js +15 -11
- package/dist/cjs/hooks/useShapes/radar/prepare-data.d.ts +1 -1
- package/dist/cjs/hooks/useShapes/radar/prepare-data.js +6 -7
- package/dist/cjs/hooks/useShapes/radar/types.d.ts +1 -0
- package/dist/cjs/hooks/useShapes/scatter/index.js +0 -1
- package/dist/cjs/hooks/useShapes/scatter/prepare-data.js +2 -0
- package/dist/cjs/hooks/useShapes/scatter/types.d.ts +1 -0
- package/dist/cjs/hooks/useShapes/treemap/prepare-data.d.ts +1 -1
- package/dist/cjs/hooks/useShapes/treemap/prepare-data.js +19 -16
- package/dist/cjs/hooks/useShapes/waterfall/index.js +2 -2
- package/dist/cjs/hooks/useShapes/waterfall/prepare-data.d.ts +1 -1
- package/dist/cjs/hooks/useShapes/waterfall/prepare-data.js +8 -7
- package/dist/cjs/hooks/useZoom/index.d.ts +18 -0
- package/dist/cjs/hooks/useZoom/index.js +54 -0
- package/dist/cjs/hooks/useZoom/types.d.ts +19 -0
- package/dist/cjs/hooks/useZoom/types.js +1 -0
- package/dist/cjs/hooks/useZoom/utils.d.ts +12 -0
- package/dist/cjs/hooks/useZoom/utils.js +128 -0
- package/dist/cjs/types/chart/axis.d.ts +26 -21
- package/dist/cjs/types/chart/chart.d.ts +5 -0
- package/dist/cjs/types/chart/line.d.ts +1 -1
- package/dist/cjs/types/chart/pie.d.ts +1 -1
- package/dist/cjs/types/chart/series.d.ts +1 -1
- package/dist/cjs/types/chart/tooltip.d.ts +1 -1
- package/dist/cjs/types/chart/zoom.d.ts +36 -0
- package/dist/cjs/types/chart/zoom.js +1 -0
- package/dist/cjs/types/index.d.ts +1 -0
- package/dist/cjs/types/index.js +1 -0
- package/dist/cjs/types/misc.d.ts +7 -0
- package/dist/cjs/utils/chart/axis-generators/bottom.d.ts +1 -1
- package/dist/cjs/utils/chart/axis-generators/bottom.js +25 -25
- package/dist/cjs/utils/chart/axis.d.ts +2 -1
- package/dist/cjs/utils/chart/axis.js +10 -2
- package/dist/cjs/utils/chart/get-closest-data.js +1 -1
- package/dist/cjs/utils/chart/text.d.ts +7 -7
- package/dist/cjs/utils/chart/text.js +37 -29
- package/dist/cjs/utils/chart-ui/pie-center-text.d.ts +1 -1
- package/dist/cjs/utils/chart-ui/pie-center-text.js +2 -2
- package/dist/cjs/validation/index.d.ts +1 -1
- package/dist/cjs/validation/index.js +16 -16
- package/dist/esm/components/Axis/AxisX.d.ts +2 -1
- package/dist/esm/components/Axis/AxisX.js +147 -141
- package/dist/esm/components/Axis/AxisY.d.ts +2 -1
- package/dist/esm/components/Axis/AxisY.js +118 -116
- package/dist/esm/components/ChartInner/index.js +36 -9
- package/dist/esm/components/ChartInner/useChartInnerHandlers.d.ts +1 -1
- package/dist/esm/components/ChartInner/useChartInnerProps.d.ts +8 -5
- package/dist/esm/components/ChartInner/useChartInnerProps.js +59 -10
- package/dist/esm/components/ChartInner/utils.d.ts +3 -0
- package/dist/esm/components/ChartInner/utils.js +28 -0
- package/dist/esm/components/Legend/index.js +202 -191
- package/dist/esm/components/Legend/styles.css +2 -0
- package/dist/esm/components/Tooltip/ChartTooltipContent.d.ts +1 -1
- package/dist/esm/components/Tooltip/DefaultContent.d.ts +1 -1
- package/dist/esm/components/Tooltip/DefaultContent.js +1 -1
- package/dist/esm/components/Tooltip/index.d.ts +1 -1
- package/dist/esm/constants/chart-types.d.ts +12 -0
- package/dist/esm/constants/chart-types.js +12 -0
- package/dist/esm/constants/defaults/axis.d.ts +3 -1
- package/dist/esm/constants/defaults/axis.js +10 -0
- package/dist/esm/constants/index.d.ts +6 -47
- package/dist/esm/constants/index.js +6 -72
- package/dist/esm/constants/layout-algorithms.d.ts +7 -0
- package/dist/esm/constants/layout-algorithms.js +8 -0
- package/dist/esm/constants/line-styles.d.ts +20 -0
- package/dist/esm/constants/line-styles.js +20 -0
- package/dist/esm/constants/palette.d.ts +1 -0
- package/dist/esm/constants/palette.js +22 -0
- package/dist/esm/constants/symbol-types.d.ts +7 -0
- package/dist/esm/constants/symbol-types.js +8 -0
- package/dist/esm/constants/typography.d.ts +1 -0
- package/dist/esm/constants/typography.js +1 -0
- package/dist/esm/hooks/hooks-utils/index.d.ts +1 -0
- package/dist/esm/hooks/hooks-utils/index.js +1 -0
- package/dist/esm/hooks/hooks-utils/zoom.d.ts +8 -0
- package/dist/esm/hooks/hooks-utils/zoom.js +81 -0
- package/dist/esm/hooks/index.d.ts +1 -0
- package/dist/esm/hooks/index.js +1 -0
- package/dist/esm/hooks/useAxisScales/index.d.ts +4 -2
- package/dist/esm/hooks/useAxisScales/index.js +22 -8
- package/dist/esm/hooks/useBrush/index.d.ts +3 -0
- package/dist/esm/hooks/useBrush/index.js +70 -0
- package/dist/esm/hooks/useBrush/styles.css +10 -0
- package/dist/esm/hooks/useBrush/types.d.ts +24 -0
- package/dist/esm/hooks/useBrush/types.js +1 -0
- package/dist/esm/hooks/useChartDimensions/index.d.ts +3 -3
- package/dist/esm/hooks/useChartDimensions/index.js +2 -2
- package/dist/esm/hooks/useChartDimensions/utils.d.ts +2 -2
- package/dist/esm/hooks/useChartOptions/chart.d.ts +2 -1
- package/dist/esm/hooks/useChartOptions/chart.js +80 -1
- package/dist/esm/hooks/useChartOptions/index.js +3 -2
- package/dist/esm/hooks/useChartOptions/types.d.ts +6 -2
- package/dist/esm/hooks/useChartOptions/x-axis.d.ts +3 -3
- package/dist/esm/hooks/useChartOptions/x-axis.js +22 -13
- package/dist/esm/hooks/useChartOptions/y-axis.d.ts +3 -3
- package/dist/esm/hooks/useChartOptions/y-axis.js +36 -21
- package/dist/esm/hooks/useCrosshair/index.d.ts +17 -0
- package/dist/esm/hooks/useCrosshair/index.js +139 -0
- package/dist/esm/hooks/useCrosshair/useCrosshairHover.d.ts +11 -0
- package/dist/esm/hooks/useCrosshair/useCrosshairHover.js +18 -0
- package/dist/esm/hooks/useSeries/index.d.ts +8 -6
- package/dist/esm/hooks/useSeries/index.js +41 -22
- package/dist/esm/hooks/useSeries/prepare-bar-y.d.ts +27 -2
- package/dist/esm/hooks/useSeries/prepare-bar-y.js +5 -5
- package/dist/esm/hooks/useSeries/prepare-legend.d.ts +1 -1
- package/dist/esm/hooks/useSeries/prepare-legend.js +27 -9
- package/dist/esm/hooks/useSeries/prepare-line.d.ts +1 -2
- package/dist/esm/hooks/useSeries/prepare-line.js +3 -3
- package/dist/esm/hooks/useSeries/prepareSeries.d.ts +1 -1
- package/dist/esm/hooks/useSeries/prepareSeries.js +2 -2
- package/dist/esm/hooks/useSeries/types.d.ts +2 -1
- package/dist/esm/hooks/useShapes/area/index.js +1 -1
- package/dist/esm/hooks/useShapes/area/prepare-data.d.ts +1 -1
- package/dist/esm/hooks/useShapes/area/prepare-data.js +32 -16
- package/dist/esm/hooks/useShapes/area/types.d.ts +1 -0
- package/dist/esm/hooks/useShapes/bar-x/prepare-data.d.ts +1 -1
- package/dist/esm/hooks/useShapes/bar-x/prepare-data.js +17 -13
- package/dist/esm/hooks/useShapes/bar-y/prepare-data.d.ts +1 -1
- package/dist/esm/hooks/useShapes/bar-y/prepare-data.js +6 -6
- package/dist/esm/hooks/useShapes/index.d.ts +1 -1
- package/dist/esm/hooks/useShapes/index.js +40 -31
- package/dist/esm/hooks/useShapes/line/prepare-data.d.ts +1 -1
- package/dist/esm/hooks/useShapes/line/prepare-data.js +14 -11
- package/dist/esm/hooks/useShapes/line/types.d.ts +1 -0
- package/dist/esm/hooks/useShapes/marker.js +2 -2
- package/dist/esm/hooks/useShapes/pie/index.js +3 -3
- package/dist/esm/hooks/useShapes/pie/prepare-data.d.ts +1 -1
- package/dist/esm/hooks/useShapes/pie/prepare-data.js +15 -11
- package/dist/esm/hooks/useShapes/radar/prepare-data.d.ts +1 -1
- package/dist/esm/hooks/useShapes/radar/prepare-data.js +6 -7
- package/dist/esm/hooks/useShapes/radar/types.d.ts +1 -0
- package/dist/esm/hooks/useShapes/scatter/index.js +0 -1
- package/dist/esm/hooks/useShapes/scatter/prepare-data.js +2 -0
- package/dist/esm/hooks/useShapes/scatter/types.d.ts +1 -0
- package/dist/esm/hooks/useShapes/treemap/prepare-data.d.ts +1 -1
- package/dist/esm/hooks/useShapes/treemap/prepare-data.js +19 -16
- package/dist/esm/hooks/useShapes/waterfall/index.js +2 -2
- package/dist/esm/hooks/useShapes/waterfall/prepare-data.d.ts +1 -1
- package/dist/esm/hooks/useShapes/waterfall/prepare-data.js +8 -7
- package/dist/esm/hooks/useZoom/index.d.ts +18 -0
- package/dist/esm/hooks/useZoom/index.js +54 -0
- package/dist/esm/hooks/useZoom/types.d.ts +19 -0
- package/dist/esm/hooks/useZoom/types.js +1 -0
- package/dist/esm/hooks/useZoom/utils.d.ts +12 -0
- package/dist/esm/hooks/useZoom/utils.js +128 -0
- package/dist/esm/types/chart/axis.d.ts +26 -21
- package/dist/esm/types/chart/chart.d.ts +5 -0
- package/dist/esm/types/chart/line.d.ts +1 -1
- package/dist/esm/types/chart/pie.d.ts +1 -1
- package/dist/esm/types/chart/series.d.ts +1 -1
- package/dist/esm/types/chart/tooltip.d.ts +1 -1
- package/dist/esm/types/chart/zoom.d.ts +36 -0
- package/dist/esm/types/chart/zoom.js +1 -0
- package/dist/esm/types/index.d.ts +1 -0
- package/dist/esm/types/index.js +1 -0
- package/dist/esm/types/misc.d.ts +7 -0
- package/dist/esm/utils/chart/axis-generators/bottom.d.ts +1 -1
- package/dist/esm/utils/chart/axis-generators/bottom.js +25 -25
- package/dist/esm/utils/chart/axis.d.ts +2 -1
- package/dist/esm/utils/chart/axis.js +10 -2
- package/dist/esm/utils/chart/get-closest-data.js +1 -1
- package/dist/esm/utils/chart/text.d.ts +7 -7
- package/dist/esm/utils/chart/text.js +37 -29
- package/dist/esm/utils/chart-ui/pie-center-text.d.ts +1 -1
- package/dist/esm/utils/chart-ui/pie-center-text.js +2 -2
- package/dist/esm/validation/index.d.ts +1 -1
- package/dist/esm/validation/index.js +16 -16
- package/package.json +2 -1
|
@@ -2,7 +2,7 @@ import React from 'react';
|
|
|
2
2
|
import { line as lineGenerator, scaleLinear, select, symbol } from 'd3';
|
|
3
3
|
import { CONTINUOUS_LEGEND_SIZE } from '../../constants';
|
|
4
4
|
import { formatNumber } from '../../libs';
|
|
5
|
-
import { block, createGradientRect, getContinuesColorFn, getLabelsSize, getLineDashArray, getSymbol, } from '../../utils';
|
|
5
|
+
import { block, createGradientRect, getContinuesColorFn, getLabelsSize, getLineDashArray, getSymbol, handleOverflowingText, } from '../../utils';
|
|
6
6
|
import { axisBottom } from '../../utils/chart/axis-generators';
|
|
7
7
|
import './styles.css';
|
|
8
8
|
const b = block('legend');
|
|
@@ -142,212 +142,223 @@ export const Legend = (props) => {
|
|
|
142
142
|
setPageIndex(0);
|
|
143
143
|
}, [boundsWidth]);
|
|
144
144
|
React.useEffect(() => {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
.enter()
|
|
172
|
-
.append('g')
|
|
173
|
-
.attr('class', b('item'))
|
|
174
|
-
.on('click', function (e, d) {
|
|
175
|
-
onItemClick({ name: d.name, metaKey: e.metaKey });
|
|
176
|
-
onUpdate === null || onUpdate === void 0 ? void 0 : onUpdate();
|
|
177
|
-
});
|
|
178
|
-
const getXPosition = (i) => {
|
|
179
|
-
return line.slice(0, i).reduce((acc, legendItem) => {
|
|
180
|
-
return (acc +
|
|
181
|
-
legendItem.symbol.width +
|
|
182
|
-
legendItem.symbol.padding +
|
|
183
|
-
legendItem.textWidth +
|
|
184
|
-
legend.itemDistance);
|
|
185
|
-
}, 0);
|
|
186
|
-
};
|
|
187
|
-
const legendLineHeight = Math.max(...line.map((l) => l.height));
|
|
188
|
-
renderLegendSymbol({ selection: legendItemTemplate, legend, legendLineHeight });
|
|
189
|
-
if (htmlLegendLine) {
|
|
190
|
-
htmlLegendLine
|
|
191
|
-
.selectAll('legend-item')
|
|
145
|
+
async function prepareLegend() {
|
|
146
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
147
|
+
if (!ref.current || !htmlLayout) {
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
const svgElement = select(ref.current);
|
|
151
|
+
svgElement.selectAll('*').remove();
|
|
152
|
+
const htmlElement = select(htmlLayout);
|
|
153
|
+
htmlElement.selectAll('[data-legend]').remove();
|
|
154
|
+
const htmlContainer = legend.html
|
|
155
|
+
? htmlElement.append('div').attr('data-legend', 1).style('position', 'absolute')
|
|
156
|
+
: null;
|
|
157
|
+
let legendWidth = 0;
|
|
158
|
+
if (legend.type === 'discrete') {
|
|
159
|
+
const start = (_b = (_a = config.pagination) === null || _a === void 0 ? void 0 : _a.pages[pageIndex]) === null || _b === void 0 ? void 0 : _b.start;
|
|
160
|
+
const end = (_d = (_c = config.pagination) === null || _c === void 0 ? void 0 : _c.pages[pageIndex]) === null || _d === void 0 ? void 0 : _d.end;
|
|
161
|
+
const pageItems = typeof start === 'number' && typeof end === 'number'
|
|
162
|
+
? items.slice(start, end)
|
|
163
|
+
: items;
|
|
164
|
+
const legendLineHeights = [];
|
|
165
|
+
pageItems.forEach((line) => {
|
|
166
|
+
var _a;
|
|
167
|
+
const legendLine = svgElement.append('g').attr('class', b('line'));
|
|
168
|
+
const htmlLegendLine = htmlContainer === null || htmlContainer === void 0 ? void 0 : htmlContainer.append('div').style('position', 'absolute');
|
|
169
|
+
const legendItemTemplate = legendLine
|
|
170
|
+
.selectAll('legend-history')
|
|
192
171
|
.data(line)
|
|
193
172
|
.enter()
|
|
194
|
-
.append('
|
|
195
|
-
.attr('class',
|
|
196
|
-
const mods = { selected: d.visible, unselected: !d.visible };
|
|
197
|
-
return b('item-text-html', mods);
|
|
198
|
-
})
|
|
199
|
-
.style('font-size', legend.itemStyle.fontSize)
|
|
200
|
-
.style('position', 'absolute')
|
|
201
|
-
.style('left', function (d, i) {
|
|
202
|
-
return `${getXPosition(i) + d.symbol.width + d.symbol.padding}px`;
|
|
203
|
-
})
|
|
204
|
-
.style('top', function (d) {
|
|
205
|
-
if (d.height < legendLineHeight) {
|
|
206
|
-
return `${(legendLineHeight - d.height) / 2}px`;
|
|
207
|
-
}
|
|
208
|
-
return '0px';
|
|
209
|
-
})
|
|
173
|
+
.append('g')
|
|
174
|
+
.attr('class', b('item'))
|
|
210
175
|
.on('click', function (e, d) {
|
|
211
176
|
onItemClick({ name: d.name, metaKey: e.metaKey });
|
|
212
177
|
onUpdate === null || onUpdate === void 0 ? void 0 : onUpdate();
|
|
213
|
-
})
|
|
214
|
-
|
|
178
|
+
});
|
|
179
|
+
const getXPosition = (i) => {
|
|
180
|
+
return line.slice(0, i).reduce((acc, legendItem) => {
|
|
181
|
+
return (acc +
|
|
182
|
+
legendItem.symbol.width +
|
|
183
|
+
legendItem.symbol.padding +
|
|
184
|
+
legendItem.textWidth +
|
|
185
|
+
legend.itemDistance);
|
|
186
|
+
}, 0);
|
|
187
|
+
};
|
|
188
|
+
const legendLineHeight = Math.max(...line.map((l) => l.height));
|
|
189
|
+
renderLegendSymbol({ selection: legendItemTemplate, legend, legendLineHeight });
|
|
190
|
+
if (htmlLegendLine) {
|
|
191
|
+
htmlLegendLine
|
|
192
|
+
.selectAll('legend-item')
|
|
193
|
+
.data(line)
|
|
194
|
+
.enter()
|
|
195
|
+
.append('div')
|
|
196
|
+
.attr('class', function (d) {
|
|
197
|
+
const mods = { selected: d.visible, unselected: !d.visible };
|
|
198
|
+
return b('item-text-html', mods);
|
|
199
|
+
})
|
|
200
|
+
.style('font-size', legend.itemStyle.fontSize)
|
|
201
|
+
.style('position', 'absolute')
|
|
202
|
+
.style('max-width', function (d) {
|
|
203
|
+
return `${d.textWidth}px`;
|
|
204
|
+
})
|
|
205
|
+
.style('left', function (d, i) {
|
|
206
|
+
return `${getXPosition(i) + d.symbol.width + d.symbol.padding}px`;
|
|
207
|
+
})
|
|
208
|
+
.style('top', function (d) {
|
|
209
|
+
if (d.height < legendLineHeight) {
|
|
210
|
+
return `${(legendLineHeight - d.height) / 2}px`;
|
|
211
|
+
}
|
|
212
|
+
return '0px';
|
|
213
|
+
})
|
|
214
|
+
.on('click', function (e, d) {
|
|
215
|
+
onItemClick({ name: d.name, metaKey: e.metaKey });
|
|
216
|
+
onUpdate === null || onUpdate === void 0 ? void 0 : onUpdate();
|
|
217
|
+
})[legend.html ? 'html' : 'text'](function (d) {
|
|
218
|
+
return d.name;
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
else {
|
|
222
|
+
legendItemTemplate
|
|
223
|
+
.append('text')
|
|
224
|
+
.attr('x', function (legendItem, i) {
|
|
225
|
+
return (getXPosition(i) +
|
|
226
|
+
legendItem.symbol.width +
|
|
227
|
+
legendItem.symbol.padding);
|
|
228
|
+
})
|
|
229
|
+
.attr('height', legend.height)
|
|
230
|
+
.attr('class', function (d) {
|
|
231
|
+
const mods = { selected: d.visible, unselected: !d.visible };
|
|
232
|
+
return b('item-text', mods);
|
|
233
|
+
})
|
|
234
|
+
.html(function (d) {
|
|
235
|
+
return ('name' in d && d.name);
|
|
236
|
+
})
|
|
237
|
+
.style('font-size', legend.itemStyle.fontSize)
|
|
238
|
+
.each((d, index, nodes) => {
|
|
239
|
+
if (d.overflowed) {
|
|
240
|
+
handleOverflowingText(nodes[index], d.textWidth);
|
|
241
|
+
}
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
const contentWidth = (legend.html
|
|
245
|
+
? getXPosition(line.length) - legend.itemDistance
|
|
246
|
+
: (_a = legendLine.node()) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect().width) || 0;
|
|
247
|
+
let left = 0;
|
|
248
|
+
switch (legend.justifyContent) {
|
|
249
|
+
case 'center': {
|
|
250
|
+
const legendLinePostion = getLegendPosition({
|
|
251
|
+
align: legend.align,
|
|
252
|
+
width: boundsWidth,
|
|
253
|
+
offsetWidth: 0,
|
|
254
|
+
contentWidth,
|
|
255
|
+
});
|
|
256
|
+
left = legendLinePostion.left;
|
|
257
|
+
legendWidth = boundsWidth;
|
|
258
|
+
break;
|
|
259
|
+
}
|
|
260
|
+
case 'start': {
|
|
261
|
+
legendWidth = Math.max(legendWidth, contentWidth);
|
|
262
|
+
break;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
const top = legendLineHeights.reduce((acc, h) => acc + h, 0);
|
|
266
|
+
legendLineHeights.push(legendLineHeight);
|
|
267
|
+
legendLine.attr('transform', `translate(${[left, top].join(',')})`);
|
|
268
|
+
htmlLegendLine === null || htmlLegendLine === void 0 ? void 0 : htmlLegendLine.style('transform', `translate(${left}px, ${top}px)`);
|
|
269
|
+
});
|
|
270
|
+
if (config.pagination) {
|
|
271
|
+
const transform = `translate(${[0, legend.height - legend.lineHeight / 2].join(',')})`;
|
|
272
|
+
appendPaginator({
|
|
273
|
+
container: svgElement,
|
|
274
|
+
pageIndex: pageIndex,
|
|
275
|
+
legend,
|
|
276
|
+
transform,
|
|
277
|
+
pages: config.pagination.pages,
|
|
278
|
+
onArrowClick: setPageIndex,
|
|
215
279
|
});
|
|
216
280
|
}
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
281
|
+
}
|
|
282
|
+
else {
|
|
283
|
+
// gradient rect
|
|
284
|
+
const domain = (_e = legend.colorScale.domain) !== null && _e !== void 0 ? _e : [];
|
|
285
|
+
const rectHeight = CONTINUOUS_LEGEND_SIZE.height;
|
|
286
|
+
svgElement.call(createGradientRect, {
|
|
287
|
+
y: legend.title.height + legend.title.margin,
|
|
288
|
+
height: rectHeight,
|
|
289
|
+
width: legend.width,
|
|
290
|
+
interpolator: getContinuesColorFn({
|
|
291
|
+
values: [0, 1],
|
|
292
|
+
colors: legend.colorScale.colors,
|
|
293
|
+
stops: legend.colorScale.stops,
|
|
294
|
+
}),
|
|
295
|
+
});
|
|
296
|
+
// ticks
|
|
297
|
+
const scale = scaleLinear(domain, [0, legend.width]);
|
|
298
|
+
const xAxisGenerator = await axisBottom({
|
|
299
|
+
scale,
|
|
300
|
+
ticks: {
|
|
301
|
+
items: [[0, -rectHeight]],
|
|
302
|
+
labelsMargin: legend.ticks.labelsMargin,
|
|
303
|
+
labelsLineHeight: legend.ticks.labelsLineHeight,
|
|
304
|
+
maxTickCount: 4,
|
|
305
|
+
tickColor: '#fff',
|
|
306
|
+
labelFormat: (value) => formatNumber(value, { unit: 'auto' }),
|
|
307
|
+
},
|
|
308
|
+
domain: {
|
|
309
|
+
size: legend.width,
|
|
310
|
+
color: 'transparent',
|
|
311
|
+
},
|
|
312
|
+
});
|
|
313
|
+
const tickTop = legend.title.height + legend.title.margin + rectHeight;
|
|
314
|
+
svgElement
|
|
315
|
+
.append('g')
|
|
316
|
+
.attr('transform', `translate(0, ${tickTop})`)
|
|
317
|
+
.call(xAxisGenerator);
|
|
318
|
+
legendWidth = legend.width;
|
|
319
|
+
}
|
|
320
|
+
if (legend.title.enable) {
|
|
321
|
+
const { maxWidth: titleWidth } = await getLabelsSize({
|
|
322
|
+
labels: [legend.title.text],
|
|
323
|
+
style: legend.title.style,
|
|
324
|
+
});
|
|
325
|
+
let dx = 0;
|
|
326
|
+
switch (legend.title.align) {
|
|
240
327
|
case 'center': {
|
|
241
|
-
|
|
242
|
-
align: legend.align,
|
|
243
|
-
width: boundsWidth,
|
|
244
|
-
offsetWidth: 0,
|
|
245
|
-
contentWidth,
|
|
246
|
-
});
|
|
247
|
-
left = legendLinePostion.left;
|
|
248
|
-
legendWidth = boundsWidth;
|
|
328
|
+
dx = legend.width / 2 - titleWidth / 2;
|
|
249
329
|
break;
|
|
250
330
|
}
|
|
251
|
-
case '
|
|
252
|
-
|
|
331
|
+
case 'right': {
|
|
332
|
+
dx = legend.width - titleWidth;
|
|
333
|
+
break;
|
|
334
|
+
}
|
|
335
|
+
case 'left':
|
|
336
|
+
default: {
|
|
337
|
+
dx = 0;
|
|
253
338
|
break;
|
|
254
339
|
}
|
|
255
340
|
}
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
legend,
|
|
267
|
-
transform,
|
|
268
|
-
pages: config.pagination.pages,
|
|
269
|
-
onArrowClick: setPageIndex,
|
|
270
|
-
});
|
|
341
|
+
svgElement
|
|
342
|
+
.append('g')
|
|
343
|
+
.attr('class', b('title'))
|
|
344
|
+
.append('text')
|
|
345
|
+
.attr('dx', dx)
|
|
346
|
+
.attr('font-weight', (_f = legend.title.style.fontWeight) !== null && _f !== void 0 ? _f : null)
|
|
347
|
+
.attr('font-size', (_g = legend.title.style.fontSize) !== null && _g !== void 0 ? _g : null)
|
|
348
|
+
.attr('fill', (_h = legend.title.style.fontColor) !== null && _h !== void 0 ? _h : null)
|
|
349
|
+
.style('dominant-baseline', 'text-before-edge')
|
|
350
|
+
.html(legend.title.text);
|
|
271
351
|
}
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
svgElement.call(createGradientRect, {
|
|
278
|
-
y: legend.title.height + legend.title.margin,
|
|
279
|
-
height: rectHeight,
|
|
280
|
-
width: legend.width,
|
|
281
|
-
interpolator: getContinuesColorFn({
|
|
282
|
-
values: [0, 1],
|
|
283
|
-
colors: legend.colorScale.colors,
|
|
284
|
-
stops: legend.colorScale.stops,
|
|
285
|
-
}),
|
|
286
|
-
});
|
|
287
|
-
// ticks
|
|
288
|
-
const scale = scaleLinear(domain, [0, legend.width]);
|
|
289
|
-
const xAxisGenerator = axisBottom({
|
|
290
|
-
scale,
|
|
291
|
-
ticks: {
|
|
292
|
-
items: [[0, -rectHeight]],
|
|
293
|
-
labelsMargin: legend.ticks.labelsMargin,
|
|
294
|
-
labelsLineHeight: legend.ticks.labelsLineHeight,
|
|
295
|
-
maxTickCount: 4,
|
|
296
|
-
tickColor: '#fff',
|
|
297
|
-
labelFormat: (value) => formatNumber(value, { unit: 'auto' }),
|
|
298
|
-
},
|
|
299
|
-
domain: {
|
|
300
|
-
size: legend.width,
|
|
301
|
-
color: 'transparent',
|
|
302
|
-
},
|
|
303
|
-
});
|
|
304
|
-
const tickTop = legend.title.height + legend.title.margin + rectHeight;
|
|
305
|
-
svgElement
|
|
306
|
-
.append('g')
|
|
307
|
-
.attr('transform', `translate(0, ${tickTop})`)
|
|
308
|
-
.call(xAxisGenerator);
|
|
309
|
-
legendWidth = legend.width;
|
|
310
|
-
}
|
|
311
|
-
if (legend.title.enable) {
|
|
312
|
-
const { maxWidth: titleWidth } = getLabelsSize({
|
|
313
|
-
labels: [legend.title.text],
|
|
314
|
-
style: legend.title.style,
|
|
352
|
+
const { left } = getLegendPosition({
|
|
353
|
+
align: legend.align,
|
|
354
|
+
width: boundsWidth,
|
|
355
|
+
offsetWidth: config.offset.left,
|
|
356
|
+
contentWidth: legendWidth,
|
|
315
357
|
});
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
case 'center': {
|
|
319
|
-
dx = legend.width / 2 - titleWidth / 2;
|
|
320
|
-
break;
|
|
321
|
-
}
|
|
322
|
-
case 'right': {
|
|
323
|
-
dx = legend.width - titleWidth;
|
|
324
|
-
break;
|
|
325
|
-
}
|
|
326
|
-
case 'left':
|
|
327
|
-
default: {
|
|
328
|
-
dx = 0;
|
|
329
|
-
break;
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
svgElement
|
|
333
|
-
.append('g')
|
|
334
|
-
.attr('class', b('title'))
|
|
335
|
-
.append('text')
|
|
336
|
-
.attr('dx', dx)
|
|
337
|
-
.attr('font-weight', (_f = legend.title.style.fontWeight) !== null && _f !== void 0 ? _f : null)
|
|
338
|
-
.attr('font-size', (_g = legend.title.style.fontSize) !== null && _g !== void 0 ? _g : null)
|
|
339
|
-
.attr('fill', (_h = legend.title.style.fontColor) !== null && _h !== void 0 ? _h : null)
|
|
340
|
-
.style('dominant-baseline', 'text-before-edge')
|
|
341
|
-
.html(legend.title.text);
|
|
358
|
+
svgElement.attr('transform', `translate(${[left, config.offset.top].join(',')})`);
|
|
359
|
+
htmlContainer === null || htmlContainer === void 0 ? void 0 : htmlContainer.style('transform', `translate(${left}px, ${config.offset.top}px)`);
|
|
342
360
|
}
|
|
343
|
-
|
|
344
|
-
align: legend.align,
|
|
345
|
-
width: boundsWidth,
|
|
346
|
-
offsetWidth: config.offset.left,
|
|
347
|
-
contentWidth: legendWidth,
|
|
348
|
-
});
|
|
349
|
-
svgElement.attr('transform', `translate(${[left, config.offset.top].join(',')})`);
|
|
350
|
-
htmlContainer === null || htmlContainer === void 0 ? void 0 : htmlContainer.style('transform', `translate(${left}px, ${config.offset.top}px)`);
|
|
361
|
+
prepareLegend();
|
|
351
362
|
}, [
|
|
352
363
|
boundsWidth,
|
|
353
364
|
chartSeries,
|
|
@@ -28,9 +28,11 @@
|
|
|
28
28
|
fill: var(--g-color-text-complementary);
|
|
29
29
|
}
|
|
30
30
|
.gcharts-legend__item-text-html {
|
|
31
|
+
overflow: hidden;
|
|
31
32
|
cursor: pointer;
|
|
32
33
|
user-select: none;
|
|
33
34
|
white-space: nowrap;
|
|
35
|
+
text-overflow: ellipsis;
|
|
34
36
|
}
|
|
35
37
|
.gcharts-legend__item-text-html_unselected {
|
|
36
38
|
color: var(--g-color-text-hint);
|
|
@@ -2,7 +2,7 @@ import React from 'react';
|
|
|
2
2
|
import type { ChartTooltip, ChartXAxis, ChartYAxis, TooltipDataChunk } from '../../types';
|
|
3
3
|
export interface ChartTooltipContentProps {
|
|
4
4
|
hovered?: TooltipDataChunk[];
|
|
5
|
-
xAxis?: ChartXAxis;
|
|
5
|
+
xAxis?: ChartXAxis | null;
|
|
6
6
|
yAxis?: ChartYAxis;
|
|
7
7
|
renderer?: ChartTooltip['renderer'];
|
|
8
8
|
valueFormat?: ChartTooltip['valueFormat'];
|
|
@@ -2,7 +2,7 @@ import React from 'react';
|
|
|
2
2
|
import type { ChartXAxis, ChartYAxis, TooltipDataChunk, ValueFormat } from '../../types';
|
|
3
3
|
type Props = {
|
|
4
4
|
hovered: TooltipDataChunk[];
|
|
5
|
-
xAxis?: ChartXAxis;
|
|
5
|
+
xAxis?: ChartXAxis | null;
|
|
6
6
|
yAxis?: ChartYAxis;
|
|
7
7
|
valueFormat?: ValueFormat;
|
|
8
8
|
};
|
|
@@ -38,7 +38,7 @@ const getMeasureValue = ({ data, xAxis, yAxis, valueFormat, }) => {
|
|
|
38
38
|
format,
|
|
39
39
|
});
|
|
40
40
|
};
|
|
41
|
-
function getDefaultValueFormat({ axis }) {
|
|
41
|
+
function getDefaultValueFormat({ axis, }) {
|
|
42
42
|
switch (axis === null || axis === void 0 ? void 0 : axis.type) {
|
|
43
43
|
case 'linear':
|
|
44
44
|
case 'logarithmic': {
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare const SeriesType: {
|
|
2
|
+
readonly Area: "area";
|
|
3
|
+
readonly BarX: "bar-x";
|
|
4
|
+
readonly BarY: "bar-y";
|
|
5
|
+
readonly Line: "line";
|
|
6
|
+
readonly Pie: "pie";
|
|
7
|
+
readonly Scatter: "scatter";
|
|
8
|
+
readonly Treemap: "treemap";
|
|
9
|
+
readonly Waterfall: "waterfall";
|
|
10
|
+
readonly Sankey: "sankey";
|
|
11
|
+
readonly Radar: "radar";
|
|
12
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { BaseTextStyle, ChartAxis, ChartAxisType } from '../../types';
|
|
1
|
+
import type { AxisCrosshair, BaseTextStyle, ChartAxis, ChartAxisType } from '../../types';
|
|
2
2
|
export declare const axisLabelsDefaults: {
|
|
3
3
|
margin: number;
|
|
4
4
|
padding: number;
|
|
@@ -8,6 +8,8 @@ export declare const axisLabelsDefaults: {
|
|
|
8
8
|
type AxisTitleDefaults = Required<ChartAxis['title']> & {
|
|
9
9
|
style: BaseTextStyle;
|
|
10
10
|
};
|
|
11
|
+
type AxisCrosshairDefaults = Required<AxisCrosshair>;
|
|
12
|
+
export declare const axisCrosshairDefaults: AxisCrosshairDefaults;
|
|
11
13
|
export declare const xAxisTitleDefaults: AxisTitleDefaults;
|
|
12
14
|
export declare const yAxisTitleDefaults: AxisTitleDefaults;
|
|
13
15
|
export declare const DEFAULT_AXIS_TYPE: ChartAxisType;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { DASH_STYLE } from '../line-styles';
|
|
1
2
|
export const axisLabelsDefaults = {
|
|
2
3
|
margin: 10,
|
|
3
4
|
padding: 10,
|
|
@@ -13,6 +14,15 @@ const axisTitleDefaults = {
|
|
|
13
14
|
align: 'center',
|
|
14
15
|
maxRowCount: 1,
|
|
15
16
|
};
|
|
17
|
+
export const axisCrosshairDefaults = {
|
|
18
|
+
enabled: false,
|
|
19
|
+
color: 'var(--g-color-line-generic)',
|
|
20
|
+
width: 1,
|
|
21
|
+
snap: true,
|
|
22
|
+
dashStyle: DASH_STYLE.Solid,
|
|
23
|
+
opacity: 1,
|
|
24
|
+
layerPlacement: 'after',
|
|
25
|
+
};
|
|
16
26
|
export const xAxisTitleDefaults = Object.assign(Object.assign({}, axisTitleDefaults), { margin: 4 });
|
|
17
27
|
export const yAxisTitleDefaults = Object.assign(Object.assign({}, axisTitleDefaults), { margin: 8 });
|
|
18
28
|
export const DEFAULT_AXIS_TYPE = 'linear';
|
|
@@ -1,49 +1,8 @@
|
|
|
1
1
|
export * from './defaults';
|
|
2
2
|
export * from './misc';
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
readonly Scatter: "scatter";
|
|
10
|
-
readonly Treemap: "treemap";
|
|
11
|
-
readonly Waterfall: "waterfall";
|
|
12
|
-
readonly Sankey: "sankey";
|
|
13
|
-
readonly Radar: "radar";
|
|
14
|
-
};
|
|
15
|
-
export declare enum DashStyle {
|
|
16
|
-
Dash = "Dash",
|
|
17
|
-
DashDot = "DashDot",
|
|
18
|
-
Dot = "Dot",
|
|
19
|
-
LongDash = "LongDash",
|
|
20
|
-
LongDashDot = "LongDashDot",
|
|
21
|
-
LongDashDotDot = "LongDashDotDot",
|
|
22
|
-
ShortDash = "ShortDash",
|
|
23
|
-
ShortDashDot = "ShortDashDot",
|
|
24
|
-
ShortDashDotDot = "ShortDashDotDot",
|
|
25
|
-
ShortDot = "ShortDot",
|
|
26
|
-
Solid = "Solid"
|
|
27
|
-
}
|
|
28
|
-
export declare enum SymbolType {
|
|
29
|
-
Circle = "circle",
|
|
30
|
-
Diamond = "diamond",
|
|
31
|
-
Square = "square",
|
|
32
|
-
Triangle = "triangle",
|
|
33
|
-
TriangleDown = "triangle-down"
|
|
34
|
-
}
|
|
35
|
-
export declare enum LineCap {
|
|
36
|
-
Butt = "butt",
|
|
37
|
-
Round = "round",
|
|
38
|
-
Square = "square",
|
|
39
|
-
None = "none"
|
|
40
|
-
}
|
|
41
|
-
export declare enum LayoutAlgorithm {
|
|
42
|
-
Binary = "binary",
|
|
43
|
-
Dice = "dice",
|
|
44
|
-
Slice = "slice",
|
|
45
|
-
SliceDice = "slice-dice",
|
|
46
|
-
Squarify = "squarify"
|
|
47
|
-
}
|
|
48
|
-
export declare const DEFAULT_PALETTE: string[];
|
|
49
|
-
export declare const DEFAULT_AXIS_LABEL_FONT_SIZE = "11px";
|
|
3
|
+
export * from './chart-types';
|
|
4
|
+
export * from './line-styles';
|
|
5
|
+
export * from './symbol-types';
|
|
6
|
+
export * from './layout-algorithms';
|
|
7
|
+
export * from './palette';
|
|
8
|
+
export * from './typography';
|