Skip to content

Commit

Permalink
fix(plugin-chart-echarts): make to allow the custome of x & y axis ti…
Browse files Browse the repository at this point in the history
…tle 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
  • Loading branch information
prosdev0107 committed Mar 10, 2022
1 parent 999c2c6 commit c79ee56
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 12 deletions.
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;
};

0 comments on commit c79ee56

Please sign in to comment.