Skip to content

Commit

Permalink
feat(plugin-chart-echarts): subject Add time formatter on the tooltip…
Browse files Browse the repository at this point in the history
… title (#912)

* feat(plugin-chart-echarts): subject Add time formatter on tooltip title

* Fix lint

* Fix

* Fix

* Fix
  • Loading branch information
maloun96 authored and zhaoyongjie committed Nov 26, 2021
1 parent 1ca3cab commit 2345e34
Showing 1 changed file with 13 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ import {
isFormulaAnnotationLayer,
isIntervalAnnotationLayer,
isTimeseriesAnnotationLayer,
smartDateVerboseFormatter,
getTimeFormatter,
getTimeFormatterForGranularity,
smartDateFormatter,
TimeseriesChartDataResponseResult,
TimeFormatter,
} from '@superset-ui/core';
import { DEFAULT_FORM_DATA, EchartsTimeseriesFormData } from './types';
import { EchartsProps, ForecastSeriesEnum } from '../types';
Expand Down Expand Up @@ -125,6 +125,16 @@ export default function transformProps(chartProps: ChartProps): EchartsProps {
if (min === undefined) min = 0;
if (max === undefined) max = 1;
}

let xAxisFormatter: TimeFormatter | StringConstructor;
if (xAxisTimeFormat === smartDateFormatter.id) {
xAxisFormatter = getTimeFormatterForGranularity(timeGrainSqla);
} else if (xAxisTimeFormat) {
xAxisFormatter = getTimeFormatter(xAxisTimeFormat);
} else {
xAxisFormatter = String;
}

const echartOptions: echarts.EChartOption = {
useUTC: true,
grid: {
Expand All @@ -141,19 +151,7 @@ export default function transformProps(chartProps: ChartProps): EchartsProps {
axisLabel: {
showMinLabel: xAxisShowMinLabel,
showMaxLabel: xAxisShowMaxLabel,
formatter: (value: any) => {
let dateFormatter;

if (xAxisTimeFormat === smartDateFormatter.id) {
dateFormatter = getTimeFormatterForGranularity(timeGrainSqla);
} else if (xAxisTimeFormat) {
dateFormatter = getTimeFormatter(xAxisTimeFormat);
} else {
dateFormatter = String;
}

return dateFormatter(value);
},
formatter: xAxisFormatter,
},
},
yAxis: {
Expand All @@ -171,7 +169,7 @@ export default function transformProps(chartProps: ChartProps): EchartsProps {
trigger: 'axis',
formatter: params => {
// @ts-ignore
const rows = [`${smartDateVerboseFormatter(params[0].value[0])}`];
const rows = [`${xAxisFormatter(params[0].value[0])}`];
// @ts-ignore
const prophetValues = extractProphetValuesFromTooltipParams(params);
Object.keys(prophetValues).forEach(key => {
Expand Down

0 comments on commit 2345e34

Please sign in to comment.