mirror of https://github.com/apache/superset.git
fix(plugin-chart-echarts): make to allow the custome of x & y axis title margin i… (#18947)
* fix(chartviz): make to allow the custome of x & y axis title margin in chart * fix(chartviz): add eslint radix error in chart.js * fix(chartviz): change the transformProps in chart plugin & creat helper. * fix(chartviz): lint fix & chart.js back * fix(plugin-chart-echarts): make to allow the custom margin of X & y axis in BoxPlot & Mixedtimeseries charts * fix(plugin-chart-echarts): make to change changeNumber to changeInteger * fix(plugin-chart-echarts): make to add license & change file name
This commit is contained in:
parent
999c2c6826
commit
c79ee56884
|
@ -36,6 +36,7 @@ import {
|
||||||
getColtypesMapping,
|
getColtypesMapping,
|
||||||
sanitizeHtml,
|
sanitizeHtml,
|
||||||
} from '../utils/series';
|
} from '../utils/series';
|
||||||
|
import { convertInteger } from '../utils/convertInteger';
|
||||||
import { defaultGrid, defaultTooltip, defaultYAxis } from '../defaults';
|
import { defaultGrid, defaultTooltip, defaultYAxis } from '../defaults';
|
||||||
import { getPadding } from '../Timeseries/transformers';
|
import { getPadding } from '../Timeseries/transformers';
|
||||||
import { OpacityEnum } from '../constants';
|
import { OpacityEnum } from '../constants';
|
||||||
|
@ -240,8 +241,8 @@ export default function transformProps(
|
||||||
null,
|
null,
|
||||||
addXAxisTitleOffset,
|
addXAxisTitleOffset,
|
||||||
yAxisTitlePosition,
|
yAxisTitlePosition,
|
||||||
yAxisTitleMargin,
|
convertInteger(yAxisTitleMargin),
|
||||||
xAxisTitleMargin,
|
convertInteger(xAxisTitleMargin),
|
||||||
);
|
);
|
||||||
const echartOptions: EChartsCoreOption = {
|
const echartOptions: EChartsCoreOption = {
|
||||||
grid: {
|
grid: {
|
||||||
|
@ -253,7 +254,7 @@ export default function transformProps(
|
||||||
data: transformedData.map(row => row.name),
|
data: transformedData.map(row => row.name),
|
||||||
axisLabel,
|
axisLabel,
|
||||||
name: xAxisTitle,
|
name: xAxisTitle,
|
||||||
nameGap: xAxisTitleMargin,
|
nameGap: convertInteger(xAxisTitleMargin),
|
||||||
nameLocation: 'middle',
|
nameLocation: 'middle',
|
||||||
},
|
},
|
||||||
yAxis: {
|
yAxis: {
|
||||||
|
@ -261,7 +262,7 @@ export default function transformProps(
|
||||||
type: 'value',
|
type: 'value',
|
||||||
axisLabel: { formatter: numberFormatter },
|
axisLabel: { formatter: numberFormatter },
|
||||||
name: yAxisTitle,
|
name: yAxisTitle,
|
||||||
nameGap: yAxisTitleMargin,
|
nameGap: convertInteger(yAxisTitleMargin),
|
||||||
nameLocation: yAxisTitlePosition === 'Left' ? 'middle' : 'end',
|
nameLocation: yAxisTitlePosition === 'Left' ? 'middle' : 'end',
|
||||||
},
|
},
|
||||||
tooltip: {
|
tooltip: {
|
||||||
|
|
|
@ -50,6 +50,7 @@ import {
|
||||||
formatForecastTooltipSeries,
|
formatForecastTooltipSeries,
|
||||||
rebaseForecastDatum,
|
rebaseForecastDatum,
|
||||||
} from '../utils/forecast';
|
} from '../utils/forecast';
|
||||||
|
import { convertInteger } from '../utils/convertInteger';
|
||||||
import { defaultGrid, defaultTooltip, defaultYAxis } from '../defaults';
|
import { defaultGrid, defaultTooltip, defaultYAxis } from '../defaults';
|
||||||
import {
|
import {
|
||||||
getPadding,
|
getPadding,
|
||||||
|
@ -251,8 +252,8 @@ export default function transformProps(
|
||||||
null,
|
null,
|
||||||
addXAxisTitleOffset,
|
addXAxisTitleOffset,
|
||||||
yAxisTitlePosition,
|
yAxisTitlePosition,
|
||||||
yAxisTitleMargin,
|
convertInteger(yAxisTitleMargin),
|
||||||
xAxisTitleMargin,
|
convertInteger(xAxisTitleMargin),
|
||||||
);
|
);
|
||||||
const labelMap = rawSeriesA.reduce((acc, datum) => {
|
const labelMap = rawSeriesA.reduce((acc, datum) => {
|
||||||
const label = datum.name as string;
|
const label = datum.name as string;
|
||||||
|
@ -282,7 +283,7 @@ export default function transformProps(
|
||||||
xAxis: {
|
xAxis: {
|
||||||
type: 'time',
|
type: 'time',
|
||||||
name: xAxisTitle,
|
name: xAxisTitle,
|
||||||
nameGap: xAxisTitleMargin,
|
nameGap: convertInteger(xAxisTitleMargin),
|
||||||
nameLocation: 'middle',
|
nameLocation: 'middle',
|
||||||
axisLabel: {
|
axisLabel: {
|
||||||
formatter: xAxisFormatter,
|
formatter: xAxisFormatter,
|
||||||
|
@ -300,7 +301,7 @@ export default function transformProps(
|
||||||
axisLabel: { formatter },
|
axisLabel: { formatter },
|
||||||
scale: truncateYAxis,
|
scale: truncateYAxis,
|
||||||
name: yAxisTitle,
|
name: yAxisTitle,
|
||||||
nameGap: yAxisTitleMargin,
|
nameGap: convertInteger(yAxisTitleMargin),
|
||||||
nameLocation: yAxisTitlePosition === 'Left' ? 'middle' : 'end',
|
nameLocation: yAxisTitlePosition === 'Left' ? 'middle' : 'end',
|
||||||
alignTicks,
|
alignTicks,
|
||||||
},
|
},
|
||||||
|
|
|
@ -55,6 +55,7 @@ import {
|
||||||
formatForecastTooltipSeries,
|
formatForecastTooltipSeries,
|
||||||
rebaseForecastDatum,
|
rebaseForecastDatum,
|
||||||
} from '../utils/forecast';
|
} from '../utils/forecast';
|
||||||
|
import { convertInteger } from '../utils/convertInteger';
|
||||||
import { defaultGrid, defaultTooltip, defaultYAxis } from '../defaults';
|
import { defaultGrid, defaultTooltip, defaultYAxis } from '../defaults';
|
||||||
import {
|
import {
|
||||||
getPadding,
|
getPadding,
|
||||||
|
@ -125,6 +126,7 @@ export default function transformProps(
|
||||||
yAxisTitleMargin,
|
yAxisTitleMargin,
|
||||||
yAxisTitlePosition,
|
yAxisTitlePosition,
|
||||||
}: EchartsTimeseriesFormData = { ...DEFAULT_FORM_DATA, ...formData };
|
}: EchartsTimeseriesFormData = { ...DEFAULT_FORM_DATA, ...formData };
|
||||||
|
|
||||||
const colorScale = CategoricalColorNamespace.getScale(colorScheme as string);
|
const colorScale = CategoricalColorNamespace.getScale(colorScheme as string);
|
||||||
const rebasedData = rebaseForecastDatum(data, verboseMap);
|
const rebasedData = rebaseForecastDatum(data, verboseMap);
|
||||||
const xAxisCol = verboseMap[xAxisOrig] || xAxisOrig || DTTM_ALIAS;
|
const xAxisCol = verboseMap[xAxisOrig] || xAxisOrig || DTTM_ALIAS;
|
||||||
|
@ -282,8 +284,8 @@ export default function transformProps(
|
||||||
legendMargin,
|
legendMargin,
|
||||||
addXAxisLabelOffset,
|
addXAxisLabelOffset,
|
||||||
yAxisTitlePosition,
|
yAxisTitlePosition,
|
||||||
yAxisTitleMargin,
|
convertInteger(yAxisTitleMargin),
|
||||||
xAxisTitleMargin,
|
convertInteger(xAxisTitleMargin),
|
||||||
);
|
);
|
||||||
|
|
||||||
const legendData = rawSeries
|
const legendData = rawSeries
|
||||||
|
@ -304,7 +306,7 @@ export default function transformProps(
|
||||||
xAxis: {
|
xAxis: {
|
||||||
type: xAxisType,
|
type: xAxisType,
|
||||||
name: xAxisTitle,
|
name: xAxisTitle,
|
||||||
nameGap: xAxisTitleMargin,
|
nameGap: convertInteger(xAxisTitleMargin),
|
||||||
nameLocation: 'middle',
|
nameLocation: 'middle',
|
||||||
axisLabel: {
|
axisLabel: {
|
||||||
hideOverlap: true,
|
hideOverlap: true,
|
||||||
|
@ -322,7 +324,7 @@ export default function transformProps(
|
||||||
axisLabel: { formatter },
|
axisLabel: { formatter },
|
||||||
scale: truncateYAxis,
|
scale: truncateYAxis,
|
||||||
name: yAxisTitle,
|
name: yAxisTitle,
|
||||||
nameGap: yAxisTitleMargin,
|
nameGap: convertInteger(yAxisTitleMargin),
|
||||||
nameLocation: yAxisTitlePosition === 'Left' ? 'middle' : 'end',
|
nameLocation: yAxisTitlePosition === 'Left' ? 'middle' : 'end',
|
||||||
},
|
},
|
||||||
tooltip: {
|
tooltip: {
|
||||||
|
|
|
@ -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;
|
||||||
|
};
|
Loading…
Reference in New Issue