Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring deckgl #4293

Merged
merged 6 commits into from Jan 31, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 0 additions & 2 deletions superset/assets/visualizations/deckgl/layers/index.js
Expand Up @@ -3,7 +3,6 @@ import deck_grid from './grid';
import deck_screengrid from './screengrid';
import deck_path from './path';
import deck_hex from './hex';
import deck_scatter from './scatter';
import deck_geojson from './geojson';
import deck_arc from './arc';
import deck_polygon from './polygon';
Expand All @@ -13,7 +12,6 @@ const layerGenerators = {
deck_screengrid,
deck_path,
deck_hex,
deck_scatter,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removing this here may break the deck_multi charts that combine deck_scatter

deck_geojson,
deck_arc,
deck_polygon,
Expand Down
44 changes: 0 additions & 44 deletions superset/assets/visualizations/deckgl/layers/scatter.jsx

This file was deleted.

70 changes: 70 additions & 0 deletions superset/assets/visualizations/deckgl/scatter.jsx
@@ -0,0 +1,70 @@
import React from 'react';
import ReactDOM from 'react-dom';

import DeckGLContainer from './DeckGLContainer';

import { ScatterplotLayer } from 'deck.gl';

import * as common from './layers/common';
import { getColorFromScheme, hexToRGB } from '../../javascripts/modules/colors';
import { unitToRadius } from '../../javascripts/modules/geo';
import sandboxedEval from '../../javascripts/modules/sandbox';

function deckScatter(slice, payload, setControlValue) {
const layer = getLayer(slice.formData, payload, slice);
const viewport = {
...slice.formData.viewport,
width: slice.width(),
height: slice.height(),
};
ReactDOM.render(
<DeckGLContainer
mapboxApiAccessToken={payload.data.mapboxApiKey}
viewport={viewport}
layers={[layer]}
mapStyle={slice.formData.mapbox_style}
setControlValue={setControlValue}
/>,
document.getElementById(slice.containerId),
);
}

function getLayer(formData, payload, slice) {
const fd = formData;
const c = fd.color_picker || { r: 0, g: 0, b: 0, a: 1 };
const fixedColor = [c.r, c.g, c.b, 255 * c.a];

let data = payload.data.features.map((d) => {
let radius = unitToRadius(fd.point_unit, d.radius) || 10;
if (fd.multiplier) {
radius *= fd.multiplier;
}
let color;
if (fd.dimension) {
color = hexToRGB(getColorFromScheme(d.cat_color, fd.color_scheme), c.a * 255);
} else {
color = fixedColor;
}
return {
...d,
radius,
color,
};
});

if (fd.js_data_mutator) {
// Applying user defined data mutator if defined
const jsFnMutator = sandboxedEval(fd.js_data_mutator);
data = jsFnMutator(data);
}

return new ScatterplotLayer({
id: `scatter-layer-${fd.slice_id}`,
data,
fp64: true,
outline: false,
...common.commonLayerProps(fd, slice),
});
}

module.exports = deckScatter;
2 changes: 1 addition & 1 deletion superset/assets/visualizations/main.js
Expand Up @@ -89,7 +89,7 @@ const vizMap = {
[VIZ_TYPES.event_flow]: require('./EventFlow.jsx'),
[VIZ_TYPES.paired_ttest]: require('./paired_ttest.jsx'),
[VIZ_TYPES.partition]: require('./partition.js'),
[VIZ_TYPES.deck_scatter]: deckglFactory,
[VIZ_TYPES.deck_scatter]: require('./deckgl/scatter.jsx'),
[VIZ_TYPES.deck_screengrid]: deckglFactory,
[VIZ_TYPES.deck_grid]: deckglFactory,
[VIZ_TYPES.deck_hex]: deckglFactory,
Expand Down