From c56dc8eace6a71b45240d1bb6768d75661052a2e Mon Sep 17 00:00:00 2001 From: Kamil Gabryjelski Date: Mon, 28 Feb 2022 14:07:55 +0100 Subject: [PATCH] feat(legacy-preset-chart-deckgl): Add ,.1f and ,.2f value formats to deckgl charts (#18945) * Add ,.1f and ,.2f value formats to deckgl charts * Remove duplicated code --- .../src/utils/D3Formatting.ts | 2 ++ .../src/utilities/Shared_DeckGL.jsx | 7 ++++--- .../src/utilities/controls.jsx | 17 ----------------- 3 files changed, 6 insertions(+), 20 deletions(-) diff --git a/superset-frontend/packages/superset-ui-chart-controls/src/utils/D3Formatting.ts b/superset-frontend/packages/superset-ui-chart-controls/src/utils/D3Formatting.ts index 2afac915269b..02585cc58db9 100644 --- a/superset-frontend/packages/superset-ui-chart-controls/src/utils/D3Formatting.ts +++ b/superset-frontend/packages/superset-ui-chart-controls/src/utils/D3Formatting.ts @@ -34,6 +34,8 @@ export const D3_FORMAT_OPTIONS: [string, string][] = [ ['.2%', '.2% (12345.432 => 1234543.20%)'], ['.3%', '.3% (12345.432 => 1234543.200%)'], ['.4r', '.4r (12345.432 => 12350)'], + [',.1f', ',.1f (12345.432 => 12,345.4)'], + [',.2f', ',.2f (12345.432 => 12,345.43)'], [',.3f', ',.3f (12345.432 => 12,345.432)'], ['+,', '+, (12345.432 => +12,345.432)'], ['$,.2f', '$,.2f (12345.432 => $12,345.43)'], diff --git a/superset-frontend/plugins/legacy-preset-chart-deckgl/src/utilities/Shared_DeckGL.jsx b/superset-frontend/plugins/legacy-preset-chart-deckgl/src/utilities/Shared_DeckGL.jsx index d3e3751479a3..b801338f0c28 100644 --- a/superset-frontend/plugins/legacy-preset-chart-deckgl/src/utilities/Shared_DeckGL.jsx +++ b/superset-frontend/plugins/legacy-preset-chart-deckgl/src/utilities/Shared_DeckGL.jsx @@ -21,8 +21,8 @@ import React from 'react'; import { t, validateNonEmpty } from '@superset-ui/core'; -import { sharedControls } from '@superset-ui/chart-controls'; -import { D3_FORMAT_OPTIONS, columnChoices, PRIMARY_COLOR } from './controls'; +import { D3_FORMAT_OPTIONS, sharedControls } from '@superset-ui/chart-controls'; +import { columnChoices, PRIMARY_COLOR } from './controls'; const DEFAULT_VIEWPORT = { longitude: 6.85236157047845, @@ -161,9 +161,10 @@ export const legendFormat = { description: t('Choose the format for legend values'), type: 'SelectControl', clearable: false, - default: D3_FORMAT_OPTIONS[0], + default: D3_FORMAT_OPTIONS[0][0], choices: D3_FORMAT_OPTIONS, renderTrigger: true, + freeForm: true, }, }; diff --git a/superset-frontend/plugins/legacy-preset-chart-deckgl/src/utilities/controls.jsx b/superset-frontend/plugins/legacy-preset-chart-deckgl/src/utilities/controls.jsx index 5281fa772fea..03092e7316af 100644 --- a/superset-frontend/plugins/legacy-preset-chart-deckgl/src/utilities/controls.jsx +++ b/superset-frontend/plugins/legacy-preset-chart-deckgl/src/utilities/controls.jsx @@ -27,23 +27,6 @@ export function columnChoices(datasource) { return []; } -// input choices & options -export const D3_FORMAT_OPTIONS = [ - ['SMART_NUMBER', 'Adaptative formating'], - ['~g', 'Original value'], - [',d', ',d (12345.432 => 12,345)'], - ['.1s', '.1s (12345.432 => 10k)'], - ['.3s', '.3s (12345.432 => 12.3k)'], - [',.1%', ',.1% (12345.432 => 1,234,543.2%)'], - ['.3%', '.3% (12345.432 => 1234543.200%)'], - ['.4r', '.4r (12345.432 => 12350)'], - [',.3f', ',.3f (12345.432 => 12,345.432)'], - ['+,', '+, (12345.432 => +12,345.432)'], - ['$,.2f', '$,.2f (12345.432 => $12,345.43)'], - ['DURATION', 'Duration in ms (66000 => 1m 6s)'], - ['DURATION_SUB', 'Duration in ms (100.40008 => 100ms 400µs 80ns)'], -]; - export const PRIMARY_COLOR = { r: 0, g: 122, b: 135, a: 1 }; export default {