Skip to content
This repository has been archived by the owner on Dec 10, 2021. It is now read-only.

Commit

Permalink
fix cross-filter and CI
Browse files Browse the repository at this point in the history
  • Loading branch information
zhaoyongjie committed Apr 15, 2021
1 parent 3d24cd3 commit 6717fa1
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/
import React, { useMemo, useState } from 'react';
import {ChartDataResponseResult, useTheme, t, GenericDataType} from '@superset-ui/core';
import { ChartDataResponseResult, useTheme, t, GenericDataType } from '@superset-ui/core';
import ControlHeader from '../../../components/ControlHeader';
import { ControlComponentProps } from '../types';

Expand Down Expand Up @@ -63,7 +63,7 @@ export default function ColumnConfigControl<T extends ColumnConfig>({
colnames.push(col);
coltypes.push(_coltypes?.[idx] as GenericDataType);
}
})
});
}
const theme = useTheme();
const columnConfigs = useMemo(() => {
Expand Down
6 changes: 2 additions & 4 deletions plugins/plugin-chart-echarts/src/Radar/EchartsRadar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
* under the License.
*/
import React, { useCallback } from 'react';
import { DataRecordValue } from '@superset-ui/core';
import { RadarChartTransformedProps } from './types';
import Echart from '../components/Echart';
import { EventHandlers } from '../types';
Expand All @@ -38,7 +37,7 @@ export default function EchartsRadar({
return;
}

const groupbyValues = values.map(value => labelMap.get(value));
const groupbyValues = values.map(value => labelMap[value]);

setDataMask({
crossFilters: {
Expand All @@ -48,8 +47,7 @@ export default function EchartsRadar({
values.length === 0
? []
: groupby.map((col, idx) => {
// const val = groupbyValues.map((v: DataRecordValue) => v[idx]);
const val = values[0];
const val = groupbyValues.map(v => v[idx]);
if (val === null || val === undefined)
return {
col,
Expand Down
48 changes: 26 additions & 22 deletions plugins/plugin-chart-echarts/src/Radar/controlPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ import {
isFeatureEnabled,
QueryFormMetric,
t,
validateNonEmpty, validateNumber
validateNonEmpty,
validateNumber,
} from '@superset-ui/core';
import {
ControlPanelConfig,
Expand All @@ -33,26 +34,31 @@ import {
D3_TIME_FORMAT_OPTIONS,
sections,
} from '@superset-ui/chart-controls';
import { ControlFormItemSpec } from '@superset-ui/chart-controls/lib/components/ControlForm';
import { DEFAULT_FORM_DATA } from './types';
import { legendOrientationControl, legendTypeControl, showLegendControl } from '../controls';
import { LABEL_POSITION } from '../constants';
import {ControlFormItemSpec} from "@superset-ui/chart-controls/lib/components/ControlForm";

const { labelType, labelPosition, numberFormat, showLabels, isCircle, emitFilter } = DEFAULT_FORM_DATA;
const {
labelType,
labelPosition,
numberFormat,
showLabels,
isCircle,
emitFilter,
} = DEFAULT_FORM_DATA;

const radarMetricMaxValue: { name: string; config: ControlFormItemSpec } = {
name: 'radarMetricMaxValue',
config: {
controlType: 'InputNumber',
label: t('Max'),
description: t(
'Default column width in pixels, may still be restricted by the shortest/longest word in the column',
),
description: t('The maximum value of metrics. It is an optional configuration'),
width: 120,
placeholder: 'auto',
debounceDelay: 400,
validators: [validateNumber],
}
},
};

const config: ControlPanelConfig = {
Expand All @@ -71,17 +77,17 @@ const config: ControlPanelConfig = {
[<h1 className="section-header">{t('Legend')}</h1>],
isFeatureEnabled(FeatureFlag.DASHBOARD_CROSS_FILTERS)
? [
{
name: 'emit_filter',
config: {
type: 'CheckboxControl',
label: t('Enable emitting filters'),
default: emitFilter,
renderTrigger: true,
description: t('Enable emmiting filters.'),
{
name: 'emit_filter',
config: {
type: 'CheckboxControl',
label: t('Enable emitting filters'),
default: emitFilter,
renderTrigger: true,
description: t('Enable emmiting filters.'),
},
},
},
]
]
: [],
[showLegendControl],
[legendTypeControl],
Expand Down Expand Up @@ -169,14 +175,12 @@ const config: ControlPanelConfig = {
description: t('Further customize how to display each metric'),
renderTrigger: true,
configFormLayout: {
[GenericDataType.NUMERIC]: [
[radarMetricMaxValue]
],
[GenericDataType.NUMERIC]: [[radarMetricMaxValue]],
},
mapStateToProps(explore, control, chart) {
const values = explore?.controls?.metrics?.value as QueryFormMetric[];
const metricColumn = values.map((value) => {
if (typeof value === "string") {
const metricColumn = values.map(value => {
if (typeof value === 'string') {
return value;
}
return value.label;
Expand Down
11 changes: 8 additions & 3 deletions plugins/plugin-chart-echarts/src/Radar/transformProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export default function transformProps(
showLabels,
showLegend,
isCircle,
columnConfig,
}: EchartsRadarFormData = {
...DEFAULT_LEGEND_FORM_DATA,
...DEFAULT_RADAR_FORM_DATA,
Expand Down Expand Up @@ -108,7 +109,10 @@ export default function transformProps(
timeFormatter: getTimeFormatter(dateFormat),
});
// map(joined_name: [columnLabel_1, columnLabel_2, ...])
columnsLabelMap.set(joinedName, groupby);
columnsLabelMap.set(
joinedName,
groupby.map(col => datum[col]),
);

// generate transformedData
transformedData.push({
Expand Down Expand Up @@ -137,7 +141,8 @@ export default function transformProps(
);

const indicator = metricsLabel.map(metricLabel => ({
text: metricLabel,
name: metricLabel,
max: columnConfig?.[metricLabel]?.radarMetricMaxValue,
}));

const series: RadarSeriesOption[] = [
Expand Down Expand Up @@ -180,7 +185,7 @@ export default function transformProps(
height,
echartOptions,
setDataMask,
labelMap: columnsLabelMap,
labelMap: Object.fromEntries(columnsLabelMap),
groupby,
selectedValues,
};
Expand Down
5 changes: 4 additions & 1 deletion plugins/plugin-chart-echarts/src/Radar/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,12 @@ import {
LegendType,
} from '../types';

type RadarColumnConfig = Record<string, { radarMetricMaxValue?: number }>;

export type EchartsRadarFormData = QueryFormData &
EchartsLegendFormData & {
colorScheme?: string;
columnConfig?: RadarColumnConfig;
currentOwnValue?: string[] | null;
currentValue?: string[] | null;
defaultValue?: string[] | null;
Expand Down Expand Up @@ -81,7 +84,7 @@ export interface RadarChartTransformedProps {
width: number;
echartOptions: EChartsOption;
setDataMask: SetDataMaskHook;
labelMap: Map<string, DataRecordValue[]>;
labelMap: Record<string, DataRecordValue[]>;
groupby: string[];
selectedValues: Record<number, string>;
}

0 comments on commit 6717fa1

Please sign in to comment.