mirror of
https://github.com/apache/superset.git
synced 2024-09-06 13:57:40 -04:00
fix: custom SQL in the XAxis (#21847)
This commit is contained in:
parent
b77335494a
commit
0a4ecca9f2
@ -21,7 +21,7 @@ import {
|
|||||||
getColumnLabel,
|
getColumnLabel,
|
||||||
getMetricLabel,
|
getMetricLabel,
|
||||||
PostProcessingPivot,
|
PostProcessingPivot,
|
||||||
getXAxis,
|
getXAxisLabel,
|
||||||
} from '@superset-ui/core';
|
} from '@superset-ui/core';
|
||||||
import { PostProcessingFactory } from './types';
|
import { PostProcessingFactory } from './types';
|
||||||
|
|
||||||
@ -30,7 +30,7 @@ export const pivotOperator: PostProcessingFactory<PostProcessingPivot> = (
|
|||||||
queryObject,
|
queryObject,
|
||||||
) => {
|
) => {
|
||||||
const metricLabels = ensureIsArray(queryObject.metrics).map(getMetricLabel);
|
const metricLabels = ensureIsArray(queryObject.metrics).map(getMetricLabel);
|
||||||
const xAxis = getXAxis(formData);
|
const xAxis = getXAxisLabel(formData);
|
||||||
|
|
||||||
if (xAxis && metricLabels.length) {
|
if (xAxis && metricLabels.length) {
|
||||||
return {
|
return {
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
* specific language governing permissions and limitationsxw
|
* specific language governing permissions and limitationsxw
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
import { PostProcessingProphet, getXAxis } from '@superset-ui/core';
|
import { PostProcessingProphet, getXAxisLabel } from '@superset-ui/core';
|
||||||
import { PostProcessingFactory } from './types';
|
import { PostProcessingFactory } from './types';
|
||||||
|
|
||||||
/* eslint-disable @typescript-eslint/no-unused-vars */
|
/* eslint-disable @typescript-eslint/no-unused-vars */
|
||||||
@ -24,7 +24,7 @@ export const prophetOperator: PostProcessingFactory<PostProcessingProphet> = (
|
|||||||
formData,
|
formData,
|
||||||
queryObject,
|
queryObject,
|
||||||
) => {
|
) => {
|
||||||
const xAxis = getXAxis(formData);
|
const xAxis = getXAxisLabel(formData);
|
||||||
if (formData.forecastEnabled && xAxis) {
|
if (formData.forecastEnabled && xAxis) {
|
||||||
return {
|
return {
|
||||||
operation: 'prophet',
|
operation: 'prophet',
|
||||||
|
@ -22,7 +22,7 @@ import {
|
|||||||
ensureIsArray,
|
ensureIsArray,
|
||||||
getMetricLabel,
|
getMetricLabel,
|
||||||
ComparisionType,
|
ComparisionType,
|
||||||
getXAxis,
|
getXAxisLabel,
|
||||||
} from '@superset-ui/core';
|
} from '@superset-ui/core';
|
||||||
import { PostProcessingFactory } from './types';
|
import { PostProcessingFactory } from './types';
|
||||||
import { getMetricOffsetsMap, isTimeComparison } from './utils';
|
import { getMetricOffsetsMap, isTimeComparison } from './utils';
|
||||||
@ -34,7 +34,7 @@ export const renameOperator: PostProcessingFactory<PostProcessingRename> = (
|
|||||||
const metrics = ensureIsArray(queryObject.metrics);
|
const metrics = ensureIsArray(queryObject.metrics);
|
||||||
const columns = ensureIsArray(queryObject.columns);
|
const columns = ensureIsArray(queryObject.columns);
|
||||||
const { truncate_metric } = formData;
|
const { truncate_metric } = formData;
|
||||||
const xAxis = getXAxis(formData);
|
const xAxis = getXAxisLabel(formData);
|
||||||
// remove or rename top level of column name(metric name) in the MultiIndex when
|
// remove or rename top level of column name(metric name) in the MultiIndex when
|
||||||
// 1) only 1 metric
|
// 1) only 1 metric
|
||||||
// 2) exist dimentsion
|
// 2) exist dimentsion
|
||||||
|
@ -22,7 +22,7 @@ import {
|
|||||||
getColumnLabel,
|
getColumnLabel,
|
||||||
NumpyFunction,
|
NumpyFunction,
|
||||||
PostProcessingPivot,
|
PostProcessingPivot,
|
||||||
getXAxis,
|
getXAxisLabel,
|
||||||
} from '@superset-ui/core';
|
} from '@superset-ui/core';
|
||||||
import { getMetricOffsetsMap, isTimeComparison } from './utils';
|
import { getMetricOffsetsMap, isTimeComparison } from './utils';
|
||||||
import { PostProcessingFactory } from './types';
|
import { PostProcessingFactory } from './types';
|
||||||
@ -30,7 +30,7 @@ import { PostProcessingFactory } from './types';
|
|||||||
export const timeComparePivotOperator: PostProcessingFactory<PostProcessingPivot> =
|
export const timeComparePivotOperator: PostProcessingFactory<PostProcessingPivot> =
|
||||||
(formData, queryObject) => {
|
(formData, queryObject) => {
|
||||||
const metricOffsetMap = getMetricOffsetsMap(formData, queryObject);
|
const metricOffsetMap = getMetricOffsetsMap(formData, queryObject);
|
||||||
const xAxis = getXAxis(formData);
|
const xAxis = getXAxisLabel(formData);
|
||||||
|
|
||||||
if (isTimeComparison(formData, queryObject) && xAxis) {
|
if (isTimeComparison(formData, queryObject) && xAxis) {
|
||||||
const aggregates = Object.fromEntries(
|
const aggregates = Object.fromEntries(
|
||||||
|
@ -23,6 +23,8 @@ import {
|
|||||||
getColumnLabel,
|
getColumnLabel,
|
||||||
isQueryFormColumn,
|
isQueryFormColumn,
|
||||||
QueryFormData,
|
QueryFormData,
|
||||||
|
QueryFormColumn,
|
||||||
|
Optional,
|
||||||
} from '@superset-ui/core';
|
} from '@superset-ui/core';
|
||||||
|
|
||||||
export const isXAxisSet = (formData: QueryFormData) =>
|
export const isXAxisSet = (formData: QueryFormData) =>
|
||||||
@ -32,14 +34,24 @@ export const hasGenericChartAxes = isFeatureEnabled(
|
|||||||
FeatureFlag.GENERIC_CHART_AXES,
|
FeatureFlag.GENERIC_CHART_AXES,
|
||||||
);
|
);
|
||||||
|
|
||||||
export const getXAxis = (formData: QueryFormData): string | undefined => {
|
export const getXAxisColumn = (
|
||||||
|
formData: QueryFormData,
|
||||||
|
): Optional<QueryFormColumn> => {
|
||||||
// The formData should be "raw form_data" -- the snake_case version of formData rather than camelCase.
|
// The formData should be "raw form_data" -- the snake_case version of formData rather than camelCase.
|
||||||
if (!(formData.granularity_sqla || formData.x_axis)) {
|
if (!(formData.granularity_sqla || formData.x_axis)) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isXAxisSet(formData)) {
|
if (isXAxisSet(formData)) {
|
||||||
return getColumnLabel(formData.x_axis);
|
return formData.x_axis;
|
||||||
}
|
}
|
||||||
return DTTM_ALIAS;
|
return DTTM_ALIAS;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const getXAxisLabel = (formData: QueryFormData): Optional<string> => {
|
||||||
|
const col = getXAxisColumn(formData);
|
||||||
|
if (col) {
|
||||||
|
return getColumnLabel(col);
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
};
|
||||||
|
@ -29,7 +29,12 @@ export { default as getMetricLabel } from './getMetricLabel';
|
|||||||
export { default as DatasourceKey } from './DatasourceKey';
|
export { default as DatasourceKey } from './DatasourceKey';
|
||||||
export { default as normalizeOrderBy } from './normalizeOrderBy';
|
export { default as normalizeOrderBy } from './normalizeOrderBy';
|
||||||
export { normalizeTimeColumn } from './normalizeTimeColumn';
|
export { normalizeTimeColumn } from './normalizeTimeColumn';
|
||||||
export { getXAxis, isXAxisSet, hasGenericChartAxes } from './getXAxis';
|
export {
|
||||||
|
getXAxisLabel,
|
||||||
|
getXAxisColumn,
|
||||||
|
isXAxisSet,
|
||||||
|
hasGenericChartAxes,
|
||||||
|
} from './getXAxis';
|
||||||
|
|
||||||
export * from './types/AnnotationLayer';
|
export * from './types/AnnotationLayer';
|
||||||
export * from './types/QueryFormData';
|
export * from './types/QueryFormData';
|
||||||
|
@ -20,4 +20,6 @@ export * from '../query/types';
|
|||||||
|
|
||||||
export type Maybe<T> = T | null;
|
export type Maybe<T> = T | null;
|
||||||
|
|
||||||
|
export type Optional<T> = T | undefined;
|
||||||
|
|
||||||
export type ValueOf<T> = T[keyof T];
|
export type ValueOf<T> = T[keyof T];
|
||||||
|
@ -19,7 +19,7 @@
|
|||||||
import {
|
import {
|
||||||
buildQueryContext,
|
buildQueryContext,
|
||||||
ensureIsArray,
|
ensureIsArray,
|
||||||
getXAxis,
|
getXAxisColumn,
|
||||||
isXAxisSet,
|
isXAxisSet,
|
||||||
QueryFormData,
|
QueryFormData,
|
||||||
} from '@superset-ui/core';
|
} from '@superset-ui/core';
|
||||||
@ -35,7 +35,9 @@ export default function buildQuery(formData: QueryFormData) {
|
|||||||
{
|
{
|
||||||
...baseQueryObject,
|
...baseQueryObject,
|
||||||
columns: [
|
columns: [
|
||||||
...(isXAxisSet(formData) ? ensureIsArray(getXAxis(formData)) : []),
|
...(isXAxisSet(formData)
|
||||||
|
? ensureIsArray(getXAxisColumn(formData))
|
||||||
|
: []),
|
||||||
],
|
],
|
||||||
...(isXAxisSet(formData) ? {} : { is_timeseries: true }),
|
...(isXAxisSet(formData) ? {} : { is_timeseries: true }),
|
||||||
post_processing: [
|
post_processing: [
|
||||||
|
@ -26,7 +26,7 @@ import {
|
|||||||
smartDateVerboseFormatter,
|
smartDateVerboseFormatter,
|
||||||
NumberFormatter,
|
NumberFormatter,
|
||||||
TimeFormatter,
|
TimeFormatter,
|
||||||
getXAxis,
|
getXAxisLabel,
|
||||||
} from '@superset-ui/core';
|
} from '@superset-ui/core';
|
||||||
import { EChartsCoreOption, graphic } from 'echarts';
|
import { EChartsCoreOption, graphic } from 'echarts';
|
||||||
import {
|
import {
|
||||||
@ -102,7 +102,7 @@ export default function transformProps(
|
|||||||
const { r, g, b } = colorPicker;
|
const { r, g, b } = colorPicker;
|
||||||
const mainColor = `rgb(${r}, ${g}, ${b})`;
|
const mainColor = `rgb(${r}, ${g}, ${b})`;
|
||||||
|
|
||||||
const timeColumn = getXAxis(rawFormData) as string;
|
const timeColumn = getXAxisLabel(rawFormData) as string;
|
||||||
let trendLineData;
|
let trendLineData;
|
||||||
let percentChange = 0;
|
let percentChange = 0;
|
||||||
let bigNumber = data.length === 0 ? null : data[0][metricName];
|
let bigNumber = data.length === 0 ? null : data[0][metricName];
|
||||||
|
@ -23,8 +23,8 @@ import {
|
|||||||
PostProcessingPivot,
|
PostProcessingPivot,
|
||||||
QueryFormData,
|
QueryFormData,
|
||||||
QueryObject,
|
QueryObject,
|
||||||
getXAxis,
|
|
||||||
isXAxisSet,
|
isXAxisSet,
|
||||||
|
getXAxisColumn,
|
||||||
} from '@superset-ui/core';
|
} from '@superset-ui/core';
|
||||||
import {
|
import {
|
||||||
pivotOperator,
|
pivotOperator,
|
||||||
@ -54,7 +54,9 @@ export default function buildQuery(formData: QueryFormData) {
|
|||||||
const queryObject = {
|
const queryObject = {
|
||||||
...baseQueryObject,
|
...baseQueryObject,
|
||||||
columns: [
|
columns: [
|
||||||
...(isXAxisSet(formData) ? ensureIsArray(getXAxis(formData)) : []),
|
...(isXAxisSet(formData)
|
||||||
|
? ensureIsArray(getXAxisColumn(formData))
|
||||||
|
: []),
|
||||||
...ensureIsArray(fd.groupby),
|
...ensureIsArray(fd.groupby),
|
||||||
],
|
],
|
||||||
series_columns: fd.groupby,
|
series_columns: fd.groupby,
|
||||||
|
@ -29,7 +29,7 @@ import {
|
|||||||
QueryFormData,
|
QueryFormData,
|
||||||
TimeseriesChartDataResponseResult,
|
TimeseriesChartDataResponseResult,
|
||||||
TimeseriesDataRecord,
|
TimeseriesDataRecord,
|
||||||
getXAxis,
|
getXAxisLabel,
|
||||||
} from '@superset-ui/core';
|
} from '@superset-ui/core';
|
||||||
import { EChartsCoreOption, SeriesOption } from 'echarts';
|
import { EChartsCoreOption, SeriesOption } from 'echarts';
|
||||||
import {
|
import {
|
||||||
@ -152,7 +152,9 @@ export default function transformProps(
|
|||||||
|
|
||||||
const colorScale = CategoricalColorNamespace.getScale(colorScheme as string);
|
const colorScale = CategoricalColorNamespace.getScale(colorScheme as string);
|
||||||
|
|
||||||
const xAxisCol = getXAxis(chartProps.rawFormData as QueryFormData) as string;
|
const xAxisCol = getXAxisLabel(
|
||||||
|
chartProps.rawFormData as QueryFormData,
|
||||||
|
) as string;
|
||||||
|
|
||||||
const rebasedDataA = rebaseForecastDatum(data1, verboseMap);
|
const rebasedDataA = rebaseForecastDatum(data1, verboseMap);
|
||||||
const rawSeriesA = extractSeries(rebasedDataA, {
|
const rawSeriesA = extractSeries(rebasedDataA, {
|
||||||
|
@ -22,7 +22,7 @@ import {
|
|||||||
normalizeOrderBy,
|
normalizeOrderBy,
|
||||||
PostProcessingPivot,
|
PostProcessingPivot,
|
||||||
QueryFormData,
|
QueryFormData,
|
||||||
getXAxis,
|
getXAxisColumn,
|
||||||
isXAxisSet,
|
isXAxisSet,
|
||||||
} from '@superset-ui/core';
|
} from '@superset-ui/core';
|
||||||
import {
|
import {
|
||||||
@ -72,7 +72,9 @@ export default function buildQuery(formData: QueryFormData) {
|
|||||||
{
|
{
|
||||||
...baseQueryObject,
|
...baseQueryObject,
|
||||||
columns: [
|
columns: [
|
||||||
...(isXAxisSet(formData) ? ensureIsArray(getXAxis(formData)) : []),
|
...(isXAxisSet(formData)
|
||||||
|
? ensureIsArray(getXAxisColumn(formData))
|
||||||
|
: []),
|
||||||
...ensureIsArray(groupby),
|
...ensureIsArray(groupby),
|
||||||
],
|
],
|
||||||
series_columns: groupby,
|
series_columns: groupby,
|
||||||
|
@ -28,8 +28,8 @@ import {
|
|||||||
isTimeseriesAnnotationLayer,
|
isTimeseriesAnnotationLayer,
|
||||||
TimeseriesChartDataResponseResult,
|
TimeseriesChartDataResponseResult,
|
||||||
t,
|
t,
|
||||||
getXAxis,
|
|
||||||
AxisType,
|
AxisType,
|
||||||
|
getXAxisLabel,
|
||||||
} from '@superset-ui/core';
|
} from '@superset-ui/core';
|
||||||
import { isDerivedSeries } from '@superset-ui/chart-controls';
|
import { isDerivedSeries } from '@superset-ui/chart-controls';
|
||||||
import { EChartsCoreOption, SeriesOption } from 'echarts';
|
import { EChartsCoreOption, SeriesOption } from 'echarts';
|
||||||
@ -148,7 +148,7 @@ export default function transformProps(
|
|||||||
|
|
||||||
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 = getXAxis(chartProps.rawFormData) as string;
|
const xAxisCol = getXAxisLabel(chartProps.rawFormData) as string;
|
||||||
const isHorizontal = orientation === OrientationType.horizontal;
|
const isHorizontal = orientation === OrientationType.horizontal;
|
||||||
const { totalStackedValues, thresholdValues } = extractDataTotalValues(
|
const { totalStackedValues, thresholdValues } = extractDataTotalValues(
|
||||||
rebasedData,
|
rebasedData,
|
||||||
|
Loading…
Reference in New Issue
Block a user