Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(plugin-chart-echarts): make to allow the custome of x & y axis title margin i… #18947

Merged
merged 8 commits into from
Mar 10, 2022
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -240,8 +241,8 @@ export default function transformProps(
null,
addXAxisTitleOffset,
yAxisTitlePosition,
yAxisTitleMargin,
xAxisTitleMargin,
convertInteger(yAxisTitleMargin),
convertInteger(xAxisTitleMargin),
);
const echartOptions: EChartsCoreOption = {
grid: {
Expand All @@ -253,15 +254,15 @@ export default function transformProps(
data: transformedData.map(row => row.name),
axisLabel,
name: xAxisTitle,
nameGap: xAxisTitleMargin,
nameGap: convertInteger(xAxisTitleMargin),
nameLocation: 'middle',
},
yAxis: {
...defaultYAxis,
type: 'value',
axisLabel: { formatter: numberFormatter },
name: yAxisTitle,
nameGap: yAxisTitleMargin,
nameGap: convertInteger(yAxisTitleMargin),
nameLocation: yAxisTitlePosition === 'Left' ? 'middle' : 'end',
},
tooltip: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import {
formatForecastTooltipSeries,
rebaseForecastDatum,
} from '../utils/forecast';
import { convertInteger } from '../utils/convertInteger';
import { defaultGrid, defaultTooltip, defaultYAxis } from '../defaults';
import {
getPadding,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -282,7 +283,7 @@ export default function transformProps(
xAxis: {
type: 'time',
name: xAxisTitle,
nameGap: xAxisTitleMargin,
nameGap: convertInteger(xAxisTitleMargin),
nameLocation: 'middle',
axisLabel: {
formatter: xAxisFormatter,
Expand All @@ -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,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import {
formatForecastTooltipSeries,
rebaseForecastDatum,
} from '../utils/forecast';
import { convertInteger } from '../utils/convertInteger';
import { defaultGrid, defaultTooltip, defaultYAxis } from '../defaults';
import {
getPadding,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -282,8 +284,8 @@ export default function transformProps(
legendMargin,
addXAxisLabelOffset,
yAxisTitlePosition,
yAxisTitleMargin,
xAxisTitleMargin,
convertInteger(yAxisTitleMargin),
convertInteger(xAxisTitleMargin),
);

const legendData = rawSeries
Expand All @@ -304,7 +306,7 @@ export default function transformProps(
xAxis: {
type: xAxisType,
name: xAxisTitle,
nameGap: xAxisTitleMargin,
nameGap: convertInteger(xAxisTitleMargin),
nameLocation: 'middle',
axisLabel: {
hideOverlap: true,
Expand All @@ -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: {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
};