Skip to content

Commit

Permalink
feat(deck.gl): add color range for deck.gl 3D (apache#19520)
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenLYZ authored and akshatsri committed Jul 19, 2022
1 parent f591f01 commit 2b03020
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@
*/
import { GridLayer } from 'deck.gl';
import React from 'react';
import { t } from '@superset-ui/core';
import { t, CategoricalColorNamespace } from '@superset-ui/core';

import { commonLayerProps, getAggFunc } from '../common';
import sandboxedEval from '../../utils/sandbox';
import { hexToRGB } from '../../utils/colors';
import { createDeckGLComponent } from '../../factory';
import TooltipRow from '../../TooltipRow';

Expand All @@ -42,11 +43,9 @@ function setTooltipContent(o) {

export function getLayer(formData, payload, onAddFilter, setTooltip) {
const fd = formData;
const c = fd.color_picker;
let data = payload.data.features.map(d => ({
...d,
color: [c.r, c.g, c.b, 255 * c.a],
}));
const colorScale = CategoricalColorNamespace.getScale(fd.color_scheme);
const colorRange = colorScale.range().map(color => hexToRGB(color));
let data = payload.data.features;

if (fd.js_data_mutator) {
// Applying user defined data mutator if defined
Expand All @@ -61,9 +60,8 @@ export function getLayer(formData, payload, onAddFilter, setTooltip) {
data,
pickable: true,
cellSize: fd.grid_size,
minColor: [0, 0, 0, 0],
extruded: fd.extruded,
maxColor: [c.r, c.g, c.b, 255 * c.a],
colorRange,
outline: false,
getElevationValue: aggFunc,
getColorValue: aggFunc,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,10 @@ const config: ControlPanelConfig = {
label: t('Map'),
controlSetRows: [
[mapboxStyle, viewport],
['color_picker', autozoom],
[gridSize, extruded],
['color_scheme'],
[autozoom],
[gridSize],
[extruded],
],
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@
*/
import { HexagonLayer } from 'deck.gl';
import React from 'react';
import { t } from '@superset-ui/core';
import { t, CategoricalColorNamespace } from '@superset-ui/core';

import { commonLayerProps, getAggFunc } from '../common';
import sandboxedEval from '../../utils/sandbox';
import { hexToRGB } from '../../utils/colors';
import { createDeckGLComponent } from '../../factory';
import TooltipRow from '../../TooltipRow';

Expand All @@ -42,11 +43,9 @@ function setTooltipContent(o) {

export function getLayer(formData, payload, onAddFilter, setTooltip) {
const fd = formData;
const c = fd.color_picker;
let data = payload.data.features.map(d => ({
...d,
color: [c.r, c.g, c.b, 255 * c.a],
}));
const colorScale = CategoricalColorNamespace.getScale(fd.color_scheme);
const colorRange = colorScale.range().map(color => hexToRGB(color));
let data = payload.data.features;

if (fd.js_data_mutator) {
// Applying user defined data mutator if defined
Expand All @@ -60,9 +59,8 @@ export function getLayer(formData, payload, onAddFilter, setTooltip) {
data,
pickable: true,
radius: fd.grid_size,
minColor: [0, 0, 0, 0],
extruded: fd.extruded,
maxColor: [c.r, c.g, c.b, 255 * c.a],
colorRange,
outline: false,
getElevationValue: aggFunc,
getColorValue: aggFunc,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ const config: ControlPanelConfig = {
label: t('Map'),
controlSetRows: [
[mapboxStyle, viewport],
['color_picker'],
['color_scheme'],
[autozoom],
[gridSize],
[extruded],
Expand Down

0 comments on commit 2b03020

Please sign in to comment.