Skip to content

Commit dce7401

Browse files
refactor(deckgl): update deck.gl charts to use new api (#34859)
1 parent 619b341 commit dce7401

41 files changed

Lines changed: 2530 additions & 34 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

superset-frontend/plugins/legacy-preset-chart-deckgl/src/CategoricalDeckGLContainer.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -169,12 +169,12 @@ const CategoricalDeckGLContainer = (props: CategoricalDeckGLContainerProps) => {
169169
}));
170170
}
171171
case COLOR_SCHEME_TYPES.color_breakpoints: {
172-
const defaultBreakpointColor = fd.deafult_breakpoint_color
172+
const defaultBreakpointColor = fd.default_breakpoint_color
173173
? [
174-
fd.deafult_breakpoint_color.r,
175-
fd.deafult_breakpoint_color.g,
176-
fd.deafult_breakpoint_color.b,
177-
fd.deafult_breakpoint_color.a * 255,
174+
fd.default_breakpoint_color.r,
175+
fd.default_breakpoint_color.g,
176+
fd.default_breakpoint_color.b,
177+
fd.default_breakpoint_color.a * 255,
178178
]
179179
: [
180180
DEFAULT_DECKGL_COLOR.r,
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
import {
20+
buildQueryContext,
21+
ensureIsArray,
22+
SqlaFormData,
23+
} from '@superset-ui/core';
24+
import {
25+
getSpatialColumns,
26+
addSpatialNullFilters,
27+
SpatialFormData,
28+
} from '../spatialUtils';
29+
import { addTooltipColumnsToQuery } from '../buildQueryUtils';
30+
31+
export interface DeckArcFormData extends SqlaFormData {
32+
start_spatial: SpatialFormData['spatial'];
33+
end_spatial: SpatialFormData['spatial'];
34+
dimension?: string;
35+
js_columns?: string[];
36+
tooltip_contents?: unknown[];
37+
tooltip_template?: string;
38+
}
39+
40+
export default function buildQuery(formData: DeckArcFormData) {
41+
const {
42+
start_spatial,
43+
end_spatial,
44+
dimension,
45+
js_columns,
46+
tooltip_contents,
47+
} = formData;
48+
49+
if (!start_spatial || !end_spatial) {
50+
throw new Error(
51+
'Start and end spatial configurations are required for Arc charts',
52+
);
53+
}
54+
55+
return buildQueryContext(formData, baseQueryObject => {
56+
const startSpatialColumns = getSpatialColumns(start_spatial);
57+
const endSpatialColumns = getSpatialColumns(end_spatial);
58+
59+
let columns = [
60+
...(baseQueryObject.columns || []),
61+
...startSpatialColumns,
62+
...endSpatialColumns,
63+
];
64+
65+
if (dimension) {
66+
columns = [...columns, dimension];
67+
}
68+
69+
const jsColumns = ensureIsArray(js_columns || []);
70+
jsColumns.forEach(col => {
71+
if (!columns.includes(col)) {
72+
columns.push(col);
73+
}
74+
});
75+
76+
columns = addTooltipColumnsToQuery(columns, tooltip_contents);
77+
78+
let filters = addSpatialNullFilters(
79+
start_spatial,
80+
ensureIsArray(baseQueryObject.filters || []),
81+
);
82+
filters = addSpatialNullFilters(end_spatial, filters);
83+
84+
const isTimeseries = !!formData.time_grain_sqla;
85+
86+
return [
87+
{
88+
...baseQueryObject,
89+
columns,
90+
filters,
91+
is_timeseries: isTimeseries,
92+
row_limit: baseQueryObject.row_limit,
93+
},
94+
];
95+
});
96+
}

superset-frontend/plugins/legacy-preset-chart-deckgl/src/layers/Arc/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ import thumbnail from './images/thumbnail.png';
2121
import thumbnailDark from './images/thumbnail-dark.png';
2222
import example from './images/example.png';
2323
import exampleDark from './images/example-dark.png';
24-
import transformProps from '../../transformProps';
24+
import transformProps from './transformProps';
25+
import buildQuery from './buildQuery';
2526
import controlPanel from './controlPanel';
2627

2728
const metadata = new ChartMetadata({
@@ -39,13 +40,13 @@ const metadata = new ChartMetadata({
3940
thumbnail,
4041
thumbnailDark,
4142
exampleGallery: [{ url: example, urlDark: exampleDark }],
42-
useLegacyApi: true,
4343
tags: [t('deckGL'), t('Geo'), t('3D'), t('Relational'), t('Web')],
4444
});
4545

4646
export default class ArcChartPlugin extends ChartPlugin {
4747
constructor() {
4848
super({
49+
buildQuery,
4950
loadChart: () => import('./Arc'),
5051
controlPanel,
5152
metadata,
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
import { ChartProps } from '@superset-ui/core';
20+
import {
21+
processSpatialData,
22+
addJsColumnsToExtraProps,
23+
DataRecord,
24+
} from '../spatialUtils';
25+
import {
26+
createBaseTransformResult,
27+
getRecordsFromQuery,
28+
addPropertiesToFeature,
29+
} from '../transformUtils';
30+
import { DeckArcFormData } from './buildQuery';
31+
32+
interface ArcPoint {
33+
sourcePosition: [number, number];
34+
targetPosition: [number, number];
35+
cat_color?: string;
36+
__timestamp?: number;
37+
extraProps?: Record<string, unknown>;
38+
[key: string]: unknown;
39+
}
40+
41+
function processArcData(
42+
records: DataRecord[],
43+
startSpatial: DeckArcFormData['start_spatial'],
44+
endSpatial: DeckArcFormData['end_spatial'],
45+
dimension?: string,
46+
jsColumns?: string[],
47+
): ArcPoint[] {
48+
if (!startSpatial || !endSpatial || !records.length) {
49+
return [];
50+
}
51+
52+
const startFeatures = processSpatialData(records, startSpatial);
53+
const endFeatures = processSpatialData(records, endSpatial);
54+
const excludeKeys = new Set(
55+
['__timestamp', dimension, ...(jsColumns || [])].filter(
56+
(key): key is string => key != null,
57+
),
58+
);
59+
60+
return records
61+
.map((record, index) => {
62+
const startFeature = startFeatures[index];
63+
const endFeature = endFeatures[index];
64+
65+
if (!startFeature || !endFeature) {
66+
return null;
67+
}
68+
69+
let arcPoint: ArcPoint = {
70+
sourcePosition: startFeature.position,
71+
targetPosition: endFeature.position,
72+
extraProps: {},
73+
};
74+
75+
arcPoint = addJsColumnsToExtraProps(arcPoint, record, jsColumns);
76+
77+
if (dimension && record[dimension] != null) {
78+
arcPoint.cat_color = String(record[dimension]);
79+
}
80+
81+
// eslint-disable-next-line no-underscore-dangle
82+
if (record.__timestamp != null) {
83+
// eslint-disable-next-line no-underscore-dangle
84+
arcPoint.__timestamp = Number(record.__timestamp);
85+
}
86+
87+
arcPoint = addPropertiesToFeature(arcPoint, record, excludeKeys);
88+
return arcPoint;
89+
})
90+
.filter((point): point is ArcPoint => point !== null);
91+
}
92+
93+
export default function transformProps(chartProps: ChartProps) {
94+
const { rawFormData: formData } = chartProps;
95+
const { start_spatial, end_spatial, dimension, js_columns } =
96+
formData as DeckArcFormData;
97+
98+
const records = getRecordsFromQuery(chartProps.queriesData);
99+
const features = processArcData(
100+
records,
101+
start_spatial,
102+
end_spatial,
103+
dimension,
104+
js_columns,
105+
);
106+
107+
return createBaseTransformResult(chartProps, features);
108+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
import { SpatialFormData, buildSpatialQuery } from '../spatialUtils';
20+
21+
export interface DeckContourFormData extends SpatialFormData {
22+
cellSize?: string;
23+
aggregation?: string;
24+
contours?: Array<{
25+
color: { r: number; g: number; b: number };
26+
lowerThreshold: number;
27+
upperThreshold?: number;
28+
strokeWidth?: number;
29+
}>;
30+
}
31+
32+
export default function buildQuery(formData: DeckContourFormData) {
33+
return buildSpatialQuery(formData);
34+
}

superset-frontend/plugins/legacy-preset-chart-deckgl/src/layers/Contour/index.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,13 @@
1717
* under the License.
1818
*/
1919
import { t, ChartMetadata, ChartPlugin, Behavior } from '@superset-ui/core';
20-
import transformProps from '../../transformProps';
21-
import controlPanel from './controlPanel';
2220
import thumbnail from './images/thumbnail.png';
2321
import thumbnailDark from './images/thumbnail-dark.png';
2422
import example from './images/example.png';
2523
import exampleDark from './images/example-dark.png';
24+
import buildQuery from './buildQuery';
25+
import transformProps from './transformProps';
26+
import controlPanel from './controlPanel';
2627

2728
const metadata = new ChartMetadata({
2829
category: t('Map'),
@@ -34,14 +35,14 @@ const metadata = new ChartMetadata({
3435
name: t('deck.gl Contour'),
3536
thumbnail,
3637
thumbnailDark,
37-
useLegacyApi: true,
3838
tags: [t('deckGL'), t('Spatial'), t('Comparison')],
3939
behaviors: [Behavior.InteractiveChart],
4040
});
4141

4242
export default class ContourChartPlugin extends ChartPlugin {
4343
constructor() {
4444
super({
45+
buildQuery,
4546
loadChart: () => import('./Contour'),
4647
controlPanel,
4748
metadata,
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
import { transformSpatialProps } from '../spatialUtils';
20+
21+
export default transformSpatialProps;

superset-frontend/plugins/legacy-preset-chart-deckgl/src/layers/Grid/Grid.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export const getLayer: GetLayerType<GridLayer> = function ({
7676

7777
const colorSchemeType = fd.color_scheme_type;
7878
const colorRange = getColorRange({
79-
defaultBreakpointsColor: fd.deafult_breakpoint_color,
79+
defaultBreakpointsColor: fd.default_breakpoint_color,
8080
colorSchemeType,
8181
colorScale,
8282
colorBreakpoints,
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
import { SpatialFormData, buildSpatialQuery } from '../spatialUtils';
20+
21+
export interface DeckGridFormData extends SpatialFormData {
22+
extruded?: boolean;
23+
}
24+
25+
export default function buildQuery(formData: DeckGridFormData) {
26+
return buildSpatialQuery(formData);
27+
}

0 commit comments

Comments
 (0)