(cherry picked from commit b491d6b4dc)
Co-authored-by: Leon Sorokin <leeoniya@gmail.com>
This commit is contained in:
co-authored by
Leon Sorokin
parent
03e8428caa
commit
433ff19f77
@@ -15,7 +15,15 @@ import {
|
|||||||
getFieldSeriesColor,
|
getFieldSeriesColor,
|
||||||
GrafanaTheme2,
|
GrafanaTheme2,
|
||||||
} from '@grafana/data';
|
} from '@grafana/data';
|
||||||
import { Themeable2, UPlotConfigBuilder, UPlotChart, VizLayout, PlotLegend } from '@grafana/ui';
|
import {
|
||||||
|
Themeable2,
|
||||||
|
UPlotConfigBuilder,
|
||||||
|
UPlotChart,
|
||||||
|
VizLayout,
|
||||||
|
PlotLegend,
|
||||||
|
measureText,
|
||||||
|
UPLOT_AXIS_FONT_SIZE,
|
||||||
|
} from '@grafana/ui';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
histogramBucketSizes,
|
histogramBucketSizes,
|
||||||
@@ -119,7 +127,20 @@ const prepConfig = (frame: DataFrame, theme: GrafanaTheme2) => {
|
|||||||
placement: AxisPlacement.Bottom,
|
placement: AxisPlacement.Bottom,
|
||||||
incrs: histogramBucketSizes,
|
incrs: histogramBucketSizes,
|
||||||
splits: xSplits,
|
splits: xSplits,
|
||||||
values: (u: uPlot, vals: any[]) => vals.map(xAxisFormatter),
|
values: (u: uPlot, splits: any[]) => {
|
||||||
|
const tickLabels = splits.map(xAxisFormatter);
|
||||||
|
|
||||||
|
const maxWidth = tickLabels.reduce(
|
||||||
|
(curMax, label) => Math.max(measureText(label, UPLOT_AXIS_FONT_SIZE).width, curMax),
|
||||||
|
0
|
||||||
|
);
|
||||||
|
|
||||||
|
const labelSpacing = 10;
|
||||||
|
const maxCount = u.bbox.width / ((maxWidth + labelSpacing) * devicePixelRatio);
|
||||||
|
const keepMod = Math.ceil(tickLabels.length / maxCount);
|
||||||
|
|
||||||
|
return tickLabels.map((label, i) => (i % keepMod === 0 ? label : null));
|
||||||
|
},
|
||||||
//incrs: () => [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10].map((mult) => mult * bucketSize),
|
//incrs: () => [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10].map((mult) => mult * bucketSize),
|
||||||
//splits: config.xSplits,
|
//splits: config.xSplits,
|
||||||
//values: config.xValues,
|
//values: config.xValues,
|
||||||
|
|||||||
Reference in New Issue
Block a user