This repository has been archived by the owner on Nov 3, 2023. It is now read-only.
forked from apache/superset
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: make polygon support geojson feature and fix autozoom (#11)
* feat: support standard geojson feature in polygon * fix: viewport autozoom * fix: type * fix: lint * refactor: renames * fix: travis * build: add yarn.lock * fix: travis * fix: error message * fix: storybook * fix: improt * fix: address comments * fix: storybook * fix: remove yarn.lock * refactor: viewport * fix: extension * fix: extension
- Loading branch information
1 parent
1a93f58
commit 940e449
Showing
16 changed files
with
18,353 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
...ckgl/packages/superset-ui-legacy-preset-chart-deckgl/src/utils/computeBoundsFromPoints.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { extent as d3Extent } from 'd3-array'; | ||
import { Point, Range } from './types'; | ||
|
||
const LAT_LIMIT: Range = [-90, 90]; | ||
const LNG_LIMIT: Range = [-180, 180]; | ||
|
||
/** | ||
* Expand a coordinate range by `padding` and within limits, if needed | ||
*/ | ||
function expandIfNeeded([curMin, curMax]: Range, [minBound, maxBound]: Range, padding = 0.25) { | ||
return curMin < curMax | ||
? [curMin, curMax] | ||
: [Math.max(minBound, curMin - padding), Math.min(maxBound, curMax + padding)]; | ||
} | ||
|
||
export default function computeBoundsFromPoints(points: Point[]) { | ||
const latBounds = expandIfNeeded(d3Extent(points, (x: Point) => x[1]) as Range, LAT_LIMIT); | ||
const lngBounds = expandIfNeeded(d3Extent(points, (x: Point) => x[0]) as Range, LNG_LIMIT); | ||
return [ | ||
[lngBounds[0], latBounds[0]], | ||
[lngBounds[1], latBounds[1]], | ||
]; | ||
} |
50 changes: 50 additions & 0 deletions
50
...i-plugins-deckgl/packages/superset-ui-legacy-preset-chart-deckgl/src/utils/fitViewport.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { fitBounds } from '@math.gl/web-mercator'; | ||
import computeBoundsFromPoints from './computeBoundsFromPoints'; | ||
import { Point } from './types'; | ||
|
||
type Viewport = { | ||
longtitude: number; | ||
latitude: number; | ||
zoom: number; | ||
bearing?: number; | ||
pitch?: number; | ||
}; | ||
|
||
type FitViewportOptions = { | ||
points: Point[]; | ||
width: number; | ||
height: number; | ||
minExtent?: number; | ||
maxZoom?: number; | ||
offset?: [number, number]; | ||
padding?: number; | ||
}; | ||
|
||
export default function fitViewport( | ||
originalViewPort: Viewport, | ||
{ points, width, height, minExtent, maxZoom, offset, padding = 20 }: FitViewportOptions, | ||
) { | ||
const { bearing, pitch } = originalViewPort; | ||
const bounds = computeBoundsFromPoints(points); | ||
|
||
try { | ||
return { | ||
...fitBounds({ | ||
bounds, | ||
width, | ||
height, | ||
minExtent, | ||
maxZoom, | ||
offset, | ||
padding, | ||
}), | ||
bearing, | ||
pitch, | ||
}; | ||
} catch (error) { | ||
// eslint-disable-next-line no-console | ||
console.error('Could not fit viewport', error); | ||
} | ||
|
||
return originalViewPort; | ||
} |
26 changes: 26 additions & 0 deletions
26
...-deckgl/packages/superset-ui-legacy-preset-chart-deckgl/src/utils/getPointsFromPolygon.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { Point } from './types'; | ||
|
||
/** Format originally used by the Polygon plugin */ | ||
type CustomPolygonFeature = { | ||
polygon: Point[]; | ||
}; | ||
|
||
/** | ||
* Format that is geojson standard | ||
* https://geojson.org/geojson-spec.html | ||
*/ | ||
type GeojsonPolygonFeature = { | ||
polygon: { | ||
type: 'Feature'; | ||
geometry: { | ||
type: 'Polygon'; | ||
coordinates: Point[][]; | ||
}; | ||
}; | ||
}; | ||
|
||
export default function getPointsFromPolygon( | ||
feature: CustomPolygonFeature | GeojsonPolygonFeature, | ||
) { | ||
return 'geometry' in feature.polygon ? feature.polygon.geometry.coordinates[0] : feature.polygon; | ||
} |
5 changes: 5 additions & 0 deletions
5
...rset-ui-plugins-deckgl/packages/superset-ui-legacy-preset-chart-deckgl/src/utils/types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// range and point actually have different value ranges | ||
// and also are different concept-wise | ||
|
||
export type Range = [number, number]; | ||
export type Point = [number, number]; |
Oops, something went wrong.