diff --git a/superset-frontend/plugins/plugin-chart-echarts/src/BoxPlot/transformProps.ts b/superset-frontend/plugins/plugin-chart-echarts/src/BoxPlot/transformProps.ts index 929d63b98711..8e89914b4d8a 100644 --- a/superset-frontend/plugins/plugin-chart-echarts/src/BoxPlot/transformProps.ts +++ b/superset-frontend/plugins/plugin-chart-echarts/src/BoxPlot/transformProps.ts @@ -36,6 +36,7 @@ import { getColtypesMapping, sanitizeHtml, } from '../utils/series'; +import { convertInteger } from '../utils/convertInteger'; import { defaultGrid, defaultTooltip, defaultYAxis } from '../defaults'; import { getPadding } from '../Timeseries/transformers'; import { OpacityEnum } from '../constants'; @@ -240,8 +241,8 @@ export default function transformProps( null, addXAxisTitleOffset, yAxisTitlePosition, - yAxisTitleMargin, - xAxisTitleMargin, + convertInteger(yAxisTitleMargin), + convertInteger(xAxisTitleMargin), ); const echartOptions: EChartsCoreOption = { grid: { @@ -253,7 +254,7 @@ export default function transformProps( data: transformedData.map(row => row.name), axisLabel, name: xAxisTitle, - nameGap: xAxisTitleMargin, + nameGap: convertInteger(xAxisTitleMargin), nameLocation: 'middle', }, yAxis: { @@ -261,7 +262,7 @@ export default function transformProps( type: 'value', axisLabel: { formatter: numberFormatter }, name: yAxisTitle, - nameGap: yAxisTitleMargin, + nameGap: convertInteger(yAxisTitleMargin), nameLocation: yAxisTitlePosition === 'Left' ? 'middle' : 'end', }, tooltip: { diff --git a/superset-frontend/plugins/plugin-chart-echarts/src/MixedTimeseries/transformProps.ts b/superset-frontend/plugins/plugin-chart-echarts/src/MixedTimeseries/transformProps.ts index 9ac3ff28c2df..c3d6e979a96a 100644 --- a/superset-frontend/plugins/plugin-chart-echarts/src/MixedTimeseries/transformProps.ts +++ b/superset-frontend/plugins/plugin-chart-echarts/src/MixedTimeseries/transformProps.ts @@ -50,6 +50,7 @@ import { formatForecastTooltipSeries, rebaseForecastDatum, } from '../utils/forecast'; +import { convertInteger } from '../utils/convertInteger'; import { defaultGrid, defaultTooltip, defaultYAxis } from '../defaults'; import { getPadding, @@ -251,8 +252,8 @@ export default function transformProps( null, addXAxisTitleOffset, yAxisTitlePosition, - yAxisTitleMargin, - xAxisTitleMargin, + convertInteger(yAxisTitleMargin), + convertInteger(xAxisTitleMargin), ); const labelMap = rawSeriesA.reduce((acc, datum) => { const label = datum.name as string; @@ -282,7 +283,7 @@ export default function transformProps( xAxis: { type: 'time', name: xAxisTitle, - nameGap: xAxisTitleMargin, + nameGap: convertInteger(xAxisTitleMargin), nameLocation: 'middle', axisLabel: { formatter: xAxisFormatter, @@ -300,7 +301,7 @@ export default function transformProps( axisLabel: { formatter }, scale: truncateYAxis, name: yAxisTitle, - nameGap: yAxisTitleMargin, + nameGap: convertInteger(yAxisTitleMargin), nameLocation: yAxisTitlePosition === 'Left' ? 'middle' : 'end', alignTicks, }, diff --git a/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/transformProps.ts b/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/transformProps.ts index e7848c4e4f60..b3a3d58c3995 100644 --- a/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/transformProps.ts +++ b/superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/transformProps.ts @@ -55,6 +55,7 @@ import { formatForecastTooltipSeries, rebaseForecastDatum, } from '../utils/forecast'; +import { convertInteger } from '../utils/convertInteger'; import { defaultGrid, defaultTooltip, defaultYAxis } from '../defaults'; import { getPadding, @@ -125,6 +126,7 @@ export default function transformProps( yAxisTitleMargin, yAxisTitlePosition, }: EchartsTimeseriesFormData = { ...DEFAULT_FORM_DATA, ...formData }; + const colorScale = CategoricalColorNamespace.getScale(colorScheme as string); const rebasedData = rebaseForecastDatum(data, verboseMap); const xAxisCol = verboseMap[xAxisOrig] || xAxisOrig || DTTM_ALIAS; @@ -282,8 +284,8 @@ export default function transformProps( legendMargin, addXAxisLabelOffset, yAxisTitlePosition, - yAxisTitleMargin, - xAxisTitleMargin, + convertInteger(yAxisTitleMargin), + convertInteger(xAxisTitleMargin), ); const legendData = rawSeries @@ -304,7 +306,7 @@ export default function transformProps( xAxis: { type: xAxisType, name: xAxisTitle, - nameGap: xAxisTitleMargin, + nameGap: convertInteger(xAxisTitleMargin), nameLocation: 'middle', axisLabel: { hideOverlap: true, @@ -322,7 +324,7 @@ export default function transformProps( axisLabel: { formatter }, scale: truncateYAxis, name: yAxisTitle, - nameGap: yAxisTitleMargin, + nameGap: convertInteger(yAxisTitleMargin), nameLocation: yAxisTitlePosition === 'Left' ? 'middle' : 'end', }, tooltip: { diff --git a/superset-frontend/plugins/plugin-chart-echarts/src/utils/convertInteger.ts b/superset-frontend/plugins/plugin-chart-echarts/src/utils/convertInteger.ts new file mode 100644 index 000000000000..16aa607ac594 --- /dev/null +++ b/superset-frontend/plugins/plugin-chart-echarts/src/utils/convertInteger.ts @@ -0,0 +1,22 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +export const convertInteger = (value: string | number) => { + if (typeof value !== 'number') return parseInt(value, 10) || 0; + return value; +};