Skip to content

Commit

Permalink
fix: Convert js to ts
Browse files Browse the repository at this point in the history
  • Loading branch information
Mattc1221 committed May 15, 2023
1 parent 2d580bd commit e77a188
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 36 deletions.
49 changes: 29 additions & 20 deletions superset-frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ type deckGLComponentProps = {
viewport: Viewport;
width: number;
};
interface getLayerType<T> {
export interface getLayerType<T> {
(
formData: QueryFormData,
payload: JsonObject,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,18 @@
* specific language governing permissions and limitations
* under the License.
*/
// TODO: implement typescript fix for legacy versions of deck.gl
// https://github.com/visgl/deck.gl/blob/master/docs/get-started/using-with-typescript.md#alternative-solution-for-legacy-versions
import { HeatmapLayer } from 'deck.gl';
import React from 'react';
import { t, getSequentialSchemeRegistry } from '@superset-ui/core';
import { commonLayerProps } from '../common';
import sandboxedEval from '../../utils/sandbox';
import { hexToRGB } from '../../utils/colors';
import { createDeckGLComponent } from '../../factory';
import { createDeckGLComponent, getLayerType } from '../../factory';
import TooltipRow from '../../TooltipRow';

function setTooltipContent(o) {
function setTooltipContent(o: any) {
return (
<div className="deckgl-tooltip">
<TooltipRow
Expand All @@ -35,8 +37,12 @@ function setTooltipContent(o) {
</div>
);
}

export function getLayer(formData, payload, onAddFilter, setTooltip) {
export const getLayer: getLayerType<unknown> = (
formData,
payload,
onAddFilter,
setTooltip,
) => {
const fd = formData;
const {
intensity = 1,
Expand All @@ -54,28 +60,28 @@ export function getLayer(formData, payload, onAddFilter, setTooltip) {
}

const colorScale = getSequentialSchemeRegistry()
.get(colorScheme)
.createLinearScale([0, 6]);
?.get(colorScheme)
?.createLinearScale([0, 6]);
const colorRange = colorScale
.range()
.map(color => hexToRGB(color))
.reverse();
?.range()
?.map(color => hexToRGB(color))
?.reverse();

return new HeatmapLayer({
id: `heatmp-layer-${fd.slice_id}`,
data,
pickable: false,
intensity,
radiusPixels,
colorRange,
aggregation: aggregation.toUpperCase(),
getPosition: d => d.position,
getWeight: d => (d.weight ? d.weight : 1),
getPosition: (d: { position: number[]; weight: number }) => d.position,
getWeight: (d: { position: number[]; weight: number }) =>
d.weight ? d.weight : 1,
...commonLayerProps(fd, setTooltip, setTooltipContent),
});
}
};

function getPoints(data) {
function getPoints(data: any[]) {
return data.map(d => d.position);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
* under the License.
*/
import { t, ChartMetadata, ChartPlugin } from '@superset-ui/core';
import thumbnail from './images/thumbnail.png';
import transformProps from '../../transformProps';
import controlPanel from './controlPanel';
import thumbnail from './images/thumbnail.png';

const metadata = new ChartMetadata({
category: t('Map'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,28 @@
* under the License.
*/
declare module '@math.gl/web-mercator';

declare module 'deck.gl' {
import { Layer, LayerProps } from '@deck.gl/core';

interface HeatmapLayerProps<T extends object = any> extends LayerProps<T> {
id?: string;
data?: T[];
getPosition?: (d: T) => number[] | null | undefined;
getWeight?: (d: T) => number | null | undefined;
radiusPixels?: number;
colorRange?: number[][];
threshold?: number;
intensity?: number;
aggregation?: string;
}

export class HeatmapLayer<T extends object = any> extends Layer<T, HeatmapLayerProps<T>> {
constructor(props: HeatmapLayerProps<T>);
}
}

declare module '*.png' {
const value: any;
export default value;
}

0 comments on commit e77a188

Please sign in to comment.