XYChart: Fix numerous axis options (#75044)

This commit is contained in:
Leon Sorokin 2023-09-19 14:44:50 -05:00 committed by GitHub
parent e83054386b
commit 780b60dc81
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 29 additions and 23 deletions

View File

@ -32,11 +32,6 @@ exports[`GraphNG utils preparePlotConfigBuilder 1`] = `
"values": [Function],
},
{
"border": {
"show": false,
"stroke": "rgb(204, 204, 220)",
"width": 1,
},
"filter": undefined,
"font": "12px "Inter", "Helvetica", "Arial", sans-serif",
"gap": 5,

View File

@ -180,8 +180,12 @@ export class UPlotAxisBuilder extends PlotConfigBuilder<AxisProps, Axis> {
incrs,
};
if (border != null) {
config.border = border;
if (border?.show) {
config.border = {
stroke: color ?? theme.colors.text.primary,
width: 1 / devicePixelRatio,
...border,
};
}
if (label != null && label.length > 0) {

View File

@ -65,6 +65,7 @@ export function addAxisConfig(
{ value: false, label: 'Off' },
],
},
showIf: (c) => c.axisPlacement !== AxisPlacement.Hidden,
})
.addRadio({
path: 'axisColorMode',
@ -77,12 +78,14 @@ export function addAxisConfig(
{ value: AxisColorMode.Series, label: 'Series' },
],
},
showIf: (c) => c.axisPlacement !== AxisPlacement.Hidden,
})
.addBooleanSwitch({
path: 'axisShow',
name: 'Show axis',
path: 'axisShow', // TODO: rename to axisBorderShow
name: 'Show border',
category,
defaultValue: false,
showIf: (c) => c.axisPlacement !== AxisPlacement.Hidden,
});
// options for scale range

View File

@ -622,6 +622,8 @@ const prepConfig = (
scaleKey: 'x',
placement: customConfig?.axisPlacement !== AxisPlacement.Hidden ? AxisPlacement.Bottom : AxisPlacement.Hidden,
show: customConfig?.axisPlacement !== AxisPlacement.Hidden,
grid: { show: customConfig?.axisGridShow },
border: { show: customConfig?.axisShow },
theme,
label:
xAxisLabel == null || xAxisLabel === ''
@ -659,21 +661,23 @@ const prepConfig = (
decimals: config.decimals,
});
if (customConfig?.axisPlacement !== AxisPlacement.Hidden) {
// why does this fall back to '' instead of null or undef?
let yAxisLabel = customConfig?.axisLabel;
// why does this fall back to '' instead of null or undef?
let yAxisLabel = customConfig?.axisLabel;
builder.addAxis({
scaleKey,
theme,
placement: customConfig?.axisPlacement,
label:
yAxisLabel == null || yAxisLabel === ''
? getFieldDisplayName(field, scatterSeries[si].frame(frames), frames)
: yAxisLabel,
formatValue: (v, decimals) => formattedValueToString(field.display!(v, decimals)),
});
}
builder.addAxis({
scaleKey,
theme,
placement: customConfig?.axisPlacement === AxisPlacement.Auto ? AxisPlacement.Left : customConfig?.axisPlacement,
show: customConfig?.axisPlacement !== AxisPlacement.Hidden,
grid: { show: customConfig?.axisGridShow },
border: { show: customConfig?.axisShow },
size: customConfig?.axisWidth,
label:
yAxisLabel == null || yAxisLabel === ''
? getFieldDisplayName(field, scatterSeries[si].frame(frames), frames)
: yAxisLabel,
formatValue: (v, decimals) => formattedValueToString(field.display!(v, decimals)),
});
builder.addSeries({
facets: [