mirror of
https://github.com/apache/superset.git
synced 2026-04-18 07:35:09 +00:00
fix(chart): implement geohash decoding (#37027)
This commit is contained in:
@@ -69,6 +69,37 @@ describe('Polygon transformProps', () => {
|
||||
emitCrossFilters: false,
|
||||
};
|
||||
|
||||
const mockedChartPropsWithGeoHash: Partial<ChartProps> = {
|
||||
...mockChartProps,
|
||||
rawFormData: {
|
||||
line_column: 'geohash',
|
||||
line_type: 'geohash',
|
||||
viewport: {},
|
||||
},
|
||||
queriesData: [
|
||||
{
|
||||
data: [
|
||||
{
|
||||
geohash: '9q8yt',
|
||||
'sum(population)': 9800,
|
||||
},
|
||||
{
|
||||
geohash: '9q8yk',
|
||||
'sum(population)': 13100,
|
||||
},
|
||||
{
|
||||
geohash: '9q8yv',
|
||||
'sum(population)': 15600,
|
||||
},
|
||||
{
|
||||
geohash: '9q8yq',
|
||||
'sum(population)': 7500,
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
test('should use constant elevation value when point_radius_fixed type is "fix"', () => {
|
||||
const fixProps = {
|
||||
...mockChartProps,
|
||||
@@ -257,4 +288,23 @@ describe('Polygon transformProps', () => {
|
||||
expect(features).toHaveLength(1);
|
||||
expect(features[0]?.elevation).toBeUndefined();
|
||||
});
|
||||
|
||||
test('should handle geohash decoding successfully', () => {
|
||||
const props = {
|
||||
...mockedChartPropsWithGeoHash,
|
||||
rawFormData: {
|
||||
...mockedChartPropsWithGeoHash.rawFormData,
|
||||
point_radius_fixed: {
|
||||
type: 'fix',
|
||||
value: '1000',
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
const result = transformProps(props as ChartProps);
|
||||
|
||||
const features = result.payload.data.features as PolygonFeature[];
|
||||
expect(features.flatMap(p => p?.polygon || [])).toHaveLength(20); // 4 geohashes x 5 corners each
|
||||
expect(features[0]?.elevation).toBe(1000);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -26,6 +26,7 @@ import {
|
||||
addPropertiesToFeature,
|
||||
} from '../transformUtils';
|
||||
import { DeckPolygonFormData } from './buildQuery';
|
||||
import { decode_bbox } from 'ngeohash';
|
||||
|
||||
function parseElevationValue(value: string): number | undefined {
|
||||
const parsed = parseFloat(value);
|
||||
@@ -122,6 +123,16 @@ function processPolygonData(
|
||||
break;
|
||||
}
|
||||
case 'geohash':
|
||||
polygonCoords = [];
|
||||
const decoded = decode_bbox(String(rawPolygonData));
|
||||
if (decoded) {
|
||||
polygonCoords.push([decoded[1], decoded[0]]); // SW (minLon, minLat)
|
||||
polygonCoords.push([decoded[1], decoded[2]]); // NW (minLon, maxLat)
|
||||
polygonCoords.push([decoded[3], decoded[2]]); // NE (maxLon, maxLat)
|
||||
polygonCoords.push([decoded[3], decoded[0]]); // SE (maxLon, minLat)
|
||||
polygonCoords.push([decoded[1], decoded[0]]); // SW (close polygon)
|
||||
}
|
||||
break;
|
||||
case 'zipcode':
|
||||
default: {
|
||||
polygonCoords = Array.isArray(rawPolygonData) ? rawPolygonData : [];
|
||||
|
||||
Reference in New Issue
Block a user