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

feat: format timestamps in drill by breadcrumbs #23698

Merged
merged 10 commits into from
Apr 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -297,5 +297,6 @@ export default function transformProps(
selectedValues,
onContextMenu,
refs,
coltypeMapping,
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import {
import {
extractGroupbyLabel,
getChartPadding,
getColtypesMapping,
getLegendProps,
sanitizeHtml,
} from '../utils/series';
Expand Down Expand Up @@ -95,7 +96,7 @@ export default function transformProps(
emitCrossFilters,
} = chartProps;
const data: DataRecord[] = queriesData[0].data || [];

const coltypeMapping = getColtypesMapping(queriesData[0]);
const {
colorScheme,
groupby,
Expand Down Expand Up @@ -244,5 +245,6 @@ export default function transformProps(
selectedValues,
onContextMenu,
refs,
coltypeMapping,
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import {
import { OpacityEnum } from '../constants';
import { getDefaultTooltip } from '../utils/tooltip';
import { Refs } from '../types';
import { getColtypesMapping } from '../utils/series';

const setIntervalBoundsAndColors = (
intervals: string,
Expand Down Expand Up @@ -130,6 +131,7 @@ export default function transformProps(
}: EchartsGaugeFormData = { ...DEFAULT_GAUGE_FORM_DATA, ...formData };
const refs: Refs = {};
const data = (queriesData[0]?.data || []) as DataRecord[];
const coltypeMapping = getColtypesMapping(queriesData[0]);
const numberFormatter = getNumberFormatter(numberFormat);
const colorFn = CategoricalColorNamespace.getScale(colorScheme as string);
const axisLineWidth = calculateAxisLineWidth(data, fontSize, overlap);
Expand Down Expand Up @@ -341,5 +343,6 @@ export default function transformProps(
selectedValues: filterState.selectedValues || [],
onContextMenu,
refs,
coltypeMapping,
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,15 @@
* under the License.
*/
import React from 'react';
import {
getColumnLabel,
getNumberFormatter,
getTimeFormatter,
} from '@superset-ui/core';
import { EventHandlers } from '../types';
import Echart from '../components/Echart';
import { GraphChartTransformedProps } from './types';
import { formatSeriesName } from '../utils/series';

type DataRow = {
source?: string;
Expand All @@ -46,6 +52,7 @@ export default function EchartsGraph({
filterState,
emitCrossFilters,
refs,
coltypeMapping,
}: GraphChartTransformedProps) {
const getCrossFilterDataMask = (node: DataRow | undefined) => {
if (!node?.name || !node?.col) {
Expand Down Expand Up @@ -143,7 +150,18 @@ export default function EchartsGraph({
drillToDetail: drillToDetailFilters,
crossFilter: getCrossFilterDataMask(node),
drillBy: node && {
filters: [{ col: node.col, op: '==', val: node.name }],
filters: [
{
col: node.col,
op: '==',
val: node.name,
formattedVal: formatSeriesName(node.name, {
timeFormatter: getTimeFormatter(formData.dateFormat),
numberFormatter: getNumberFormatter(formData.numberFormat),
coltype: coltypeMapping?.[getColumnLabel(node.col)],
}),
},
],
groupbyFieldName:
node.col === formData.source ? 'source' : 'target',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,12 @@ import {
EchartsGraphChartProps,
} from './types';
import { DEFAULT_GRAPH_SERIES_OPTION } from './constants';
import { getChartPadding, getLegendProps, sanitizeHtml } from '../utils/series';
import {
getChartPadding,
getColtypesMapping,
getLegendProps,
sanitizeHtml,
} from '../utils/series';
import { getDefaultTooltip } from '../utils/tooltip';
import { Refs } from '../types';

Expand Down Expand Up @@ -174,7 +179,7 @@ export default function transformProps(
theme,
} = chartProps;
const data: DataRecord[] = queriesData[0].data || [];

const coltypeMapping = getColtypesMapping(queriesData[0]);
const {
source,
target,
Expand Down Expand Up @@ -343,5 +348,6 @@ export default function transformProps(
filterState,
refs,
emitCrossFilters,
coltypeMapping,
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,17 @@
import React, { useCallback } from 'react';
import {
AxisType,
DataRecordValue,
DTTM_ALIAS,
BinaryQueryObjectFilterClause,
DTTM_ALIAS,
DataRecordValue,
getColumnLabel,
getNumberFormatter,
getTimeFormatter,
} from '@superset-ui/core';
import { EchartsMixedTimeseriesChartTransformedProps } from './types';
import Echart from '../components/Echart';
import { EventHandlers } from '../types';
import { currentSeries } from '../utils/series';
import { currentSeries, formatSeriesName } from '../utils/series';

export default function EchartsMixedTimeseries({
height,
Expand All @@ -45,6 +48,7 @@ export default function EchartsMixedTimeseries({
xValueFormatter,
xAxis,
refs,
coltypeMapping,
}: EchartsMixedTimeseriesChartTransformedProps) {
const isFirstQuery = useCallback(
(seriesIndex: number) => seriesIndex < seriesBreakdown,
Expand Down Expand Up @@ -125,7 +129,7 @@ export default function EchartsMixedTimeseries({
mouseover: params => {
currentSeries.name = params.seriesName;
},
contextmenu: eventParams => {
contextmenu: async eventParams => {
if (onContextMenu) {
eventParams.event.stop();
const { data, seriesName, seriesIndex } = eventParams;
Expand Down Expand Up @@ -167,6 +171,11 @@ export default function EchartsMixedTimeseries({
col: dimension,
op: '==',
val: values[i],
formattedVal: formatSeriesName(values[i], {
timeFormatter: getTimeFormatter(formData.dateFormat),
numberFormatter: getNumberFormatter(formData.numberFormat),
coltype: coltypeMapping?.[getColumnLabel(dimension)],
}),
}),
);
onContextMenu(pointerEvent.clientX, pointerEvent.clientY, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,10 @@ export default function transformProps(
const data1 = (queriesData[0].data || []) as TimeseriesDataRecord[];
const data2 = (queriesData[1].data || []) as TimeseriesDataRecord[];
const annotationData = getAnnotationData(chartProps);

const coltypeMapping = {
...getColtypesMapping(queriesData[0]),
...getColtypesMapping(queriesData[1]),
};
const {
area,
areaB,
Expand Down Expand Up @@ -523,5 +526,6 @@ export default function transformProps(
type: xAxisType,
},
refs,
coltypeMapping,
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -345,5 +345,6 @@ export default function transformProps(
onContextMenu,
refs,
emitCrossFilters,
coltypeMapping,
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -259,5 +259,6 @@ export default function transformProps(
selectedValues,
onContextMenu,
refs,
coltypeMapping,
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,16 @@
* under the License.
*/
import React, { useCallback } from 'react';
import { BinaryQueryObjectFilterClause } from '@superset-ui/core';
import {
BinaryQueryObjectFilterClause,
getColumnLabel,
getNumberFormatter,
getTimeFormatter,
} from '@superset-ui/core';
import { SunburstTransformedProps } from './types';
import Echart from '../components/Echart';
import { EventHandlers, TreePathInfo } from '../types';
import { formatSeriesName } from '../utils/series';

export const extractTreePathInfo = (treePathInfo: TreePathInfo[] | undefined) =>
(treePathInfo ?? [])
Expand All @@ -39,6 +45,7 @@ export default function EchartsSunburst(props: SunburstTransformedProps) {
onContextMenu,
refs,
emitCrossFilters,
coltypeMapping,
} = props;
const { columns } = formData;

Expand Down Expand Up @@ -102,7 +109,7 @@ export default function EchartsSunburst(props: SunburstTransformedProps) {
const { treePathInfo } = props;
handleChange(treePathInfo);
},
contextmenu: eventParams => {
contextmenu: async eventParams => {
if (onContextMenu) {
eventParams.event.stop();
const { data, treePathInfo } = eventParams;
Expand All @@ -120,10 +127,17 @@ export default function EchartsSunburst(props: SunburstTransformedProps) {
formattedVal: path,
}),
);
const val = treePath[treePath.length - 1];
drillByFilters.push({
col: columns[treePath.length - 1],
op: '==',
val: treePath[treePath.length - 1],
val,
formattedVal: formatSeriesName(val, {
timeFormatter: getTimeFormatter(formData.dateFormat),
numberFormatter: getNumberFormatter(formData.numberFormat),
coltype:
coltypeMapping?.[getColumnLabel(columns[treePath.length - 1])],
}),
});
}
onContextMenu(pointerEvent.clientX, pointerEvent.clientY, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -377,5 +377,6 @@ export default function transformProps(
selectedValues: filterState.selectedValues || [],
onContextMenu,
refs,
coltypeMapping,
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,17 @@ import {
DTTM_ALIAS,
BinaryQueryObjectFilterClause,
AxisType,
getTimeFormatter,
getColumnLabel,
getNumberFormatter,
} from '@superset-ui/core';
import { ViewRootGroup } from 'echarts/types/src/util/types';
import GlobalModel from 'echarts/types/src/model/Global';
import ComponentModel from 'echarts/types/src/model/Component';
import { EchartsHandler, EventHandlers } from '../types';
import Echart from '../components/Echart';
import { TimeseriesChartTransformedProps } from './types';
import { currentSeries } from '../utils/series';
import { currentSeries, formatSeriesName } from '../utils/series';
import { ExtraControls } from '../components/ExtraControls';

const TIMER_DURATION = 300;
Expand All @@ -50,6 +53,7 @@ export default function EchartsTimeseries({
xAxis,
refs,
emitCrossFilters,
coltypeMapping,
}: TimeseriesChartTransformedProps) {
const { stack } = formData;
const echartRef = useRef<EchartsHandler | null>(null);
Expand Down Expand Up @@ -196,7 +200,7 @@ export default function EchartsTimeseries({
handleDoubleClickChange();
}
},
contextmenu: eventParams => {
contextmenu: async eventParams => {
if (onContextMenu) {
eventParams.event.stop();
const { data, seriesName } = eventParams;
Expand Down Expand Up @@ -232,10 +236,16 @@ export default function EchartsTimeseries({
}),
);
formData.groupby.forEach((dimension, i) => {
const val = labelMap[seriesName][i];
drillByFilters.push({
col: dimension,
op: '==',
val: labelMap[seriesName][i],
val,
formattedVal: formatSeriesName(values[i], {
timeFormatter: getTimeFormatter(formData.dateFormat),
numberFormatter: getNumberFormatter(formData.numberFormat),
coltype: coltypeMapping?.[getColumnLabel(dimension)],
}),
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -533,5 +533,6 @@ export default function transformProps(
type: xAxisType,
},
refs,
coltypeMapping: dataTypes,
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,17 @@
import {
DataRecordValue,
BinaryQueryObjectFilterClause,
getTimeFormatter,
getColumnLabel,
getNumberFormatter,
} from '@superset-ui/core';
import React, { useCallback } from 'react';
import Echart from '../components/Echart';
import { NULL_STRING } from '../constants';
import { EventHandlers } from '../types';
import { extractTreePathInfo } from './constants';
import { TreemapTransformedProps } from './types';
import { formatSeriesName } from '../utils/series';

export default function EchartsTreemap({
echartOptions,
Expand All @@ -38,6 +42,8 @@ export default function EchartsTreemap({
setDataMask,
selectedValues,
width,
formData,
coltypeMapping,
}: TreemapTransformedProps) {
const getCrossFilterDataMask = useCallback(
(data, treePathInfo) => {
Expand Down Expand Up @@ -108,7 +114,7 @@ export default function EchartsTreemap({
const { data, treePathInfo } = props;
handleChange(data, treePathInfo);
},
contextmenu: eventParams => {
contextmenu: async eventParams => {
if (onContextMenu) {
eventParams.event.stop();
const { data, treePathInfo } = eventParams;
Expand All @@ -129,6 +135,11 @@ export default function EchartsTreemap({
col: groupby[i],
op: '==',
val,
formattedVal: formatSeriesName(val, {
timeFormatter: getTimeFormatter(formData.dateFormat),
numberFormatter: getNumberFormatter(formData.numberFormat),
coltype: coltypeMapping?.[getColumnLabel(groupby[i])],
}),
});
});
onContextMenu(pointerEvent.clientX, pointerEvent.clientY, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,5 +294,6 @@ export default function transformProps(
selectedValues: filterState.selectedValues || [],
onContextMenu,
refs,
coltypeMapping,
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ export interface BaseTransformedProps<F> {
refs: Refs;
width: number;
emitCrossFilters?: boolean;
coltypeMapping?: Record<string, number>;
}

export type CrossFilterTransformedProps = {
Expand Down
Loading