Skip to content

Commit f0f4f7e

Browse files
authored
feat(visualization): add timeRangeFixed to Big Number w/ Trendlines (#9341)
* feat: add timeRangeFixed and increase font size for Big Number chart * Update package-lock.json
1 parent 893c955 commit f0f4f7e

File tree

7 files changed

+215
-186
lines changed

7 files changed

+215
-186
lines changed

superset-frontend/package-lock.json

Lines changed: 145 additions & 134 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

superset-frontend/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181
"@superset-ui/legacy-plugin-chart-treemap": "^0.11.15",
8282
"@superset-ui/legacy-plugin-chart-word-cloud": "^0.11.15",
8383
"@superset-ui/legacy-plugin-chart-world-map": "^0.11.15",
84-
"@superset-ui/legacy-preset-chart-big-number": "^0.11.15",
84+
"@superset-ui/legacy-preset-chart-big-number": "^0.11.21",
8585
"@superset-ui/legacy-preset-chart-deckgl": "^0.2.3",
8686
"@superset-ui/legacy-preset-chart-nvd3": "^0.11.15",
8787
"@superset-ui/number-format": "^0.12.10",

superset-frontend/src/explore/components/ControlPanelsContainer.jsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,12 @@ class ControlPanelsContainer extends React.Component {
9797

9898
renderControl(name, config, lookupControlData) {
9999
const { actions, controls, exploreState, form_data: formData } = this.props;
100+
const { visibility } = config;
101+
102+
// if visibility check says the config is not visible, don't render it
103+
if (visibility && !visibility.call(config, this.props)) {
104+
return null;
105+
}
100106

101107
// Looking to find mapStateToProps override for this viz type
102108
const controlPanelConfig =
@@ -179,7 +185,6 @@ class ControlPanelsContainer extends React.Component {
179185
// is not specified directly. Have to look up the config from
180186
// centralized configs.
181187
const name = controlItem;
182-
183188
return this.renderControl(name, controlConfigs[name], true);
184189
}
185190
return null;

superset-frontend/src/explore/controlPanels/BigNumber.js renamed to superset-frontend/src/explore/controlPanels/BigNumber.jsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@ export default {
3131
expanded: true,
3232
controlSetRows: [
3333
['compare_lag', 'compare_suffix'],
34-
['y_axis_format', null],
34+
['y_axis_format'],
3535
['show_trend_line', 'start_y_axis_at_zero'],
36+
['time_range_fixed'],
3637
],
3738
},
3839
{

superset-frontend/src/explore/controlUtils.js

Lines changed: 29 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
* under the License.
1818
*/
1919
import { getChartControlPanelRegistry } from '@superset-ui/chart';
20-
import controls from './controls';
21-
import * as sections from './controlPanels/sections';
20+
import { controls as SHARED_CONTROLS } from './controls';
21+
import * as SECTIONS from './controlPanels/sections';
2222

2323
export function getFormDataFromControls(controlsState) {
2424
const formData = {};
@@ -45,38 +45,36 @@ export function validateControl(control) {
4545
return control;
4646
}
4747

48-
function isGlobalControl(controlKey) {
49-
return controlKey in controls;
48+
function findCustomControl(controlPanelSections, controlKey) {
49+
// find custom control in `controlPanelSections` and apply `controlOverrides` if needed.
50+
for (const section of controlPanelSections) {
51+
for (const controlArr of section.controlSetRows) {
52+
for (const control of controlArr) {
53+
if (control != null && typeof control === 'object') {
54+
if (control.config && control.name === controlKey) {
55+
return control.config;
56+
}
57+
}
58+
}
59+
}
60+
}
61+
return null;
5062
}
5163

5264
export function getControlConfig(controlKey, vizType) {
53-
// Gets the control definition, applies overrides, and executes
54-
// the mapStatetoProps
5565
const controlPanelConfig = getChartControlPanelRegistry().get(vizType) || {};
5666
const {
5767
controlOverrides = {},
5868
controlPanelSections = [],
5969
} = controlPanelConfig;
6070

61-
if (!isGlobalControl(controlKey)) {
62-
for (const section of controlPanelSections) {
63-
for (const controlArr of section.controlSetRows) {
64-
for (const control of controlArr) {
65-
if (control != null && typeof control === 'object') {
66-
if (control.config && control.name === controlKey) {
67-
return {
68-
...control.config,
69-
...controlOverrides[controlKey],
70-
};
71-
}
72-
}
73-
}
74-
}
75-
}
76-
}
71+
const config =
72+
controlKey in SHARED_CONTROLS
73+
? SHARED_CONTROLS[controlKey]
74+
: findCustomControl(controlPanelSections, controlKey);
7775

7876
return {
79-
...controls[controlKey],
77+
...config,
8078
...controlOverrides[controlKey],
8179
};
8280
}
@@ -150,31 +148,25 @@ export function sectionsToRender(vizType, datasourceType) {
150148
controlPanelSections = [],
151149
} = controlPanelConfig;
152150

153-
const sectionsCopy = { ...sections };
151+
const sections = { ...SECTIONS };
154152

155153
Object.entries(sectionOverrides).forEach(([section, overrides]) => {
156154
if (typeof overrides === 'object' && overrides.constructor === Object) {
157-
sectionsCopy[section] = {
158-
...sectionsCopy[section],
155+
sections[section] = {
156+
...sections[section],
159157
...overrides,
160158
};
161159
} else {
162-
sectionsCopy[section] = overrides;
160+
sections[section] = overrides;
163161
}
164162
});
165163

166-
const {
167-
datasourceAndVizType,
168-
sqlaTimeSeries,
169-
druidTimeSeries,
170-
} = sectionsCopy;
164+
const { datasourceAndVizType, sqlaTimeSeries, druidTimeSeries } = sections;
165+
const timeSection =
166+
datasourceType === 'table' ? sqlaTimeSeries : druidTimeSeries;
171167

172168
return []
173-
.concat(
174-
datasourceAndVizType,
175-
datasourceType === 'table' ? sqlaTimeSeries : druidTimeSeries,
176-
controlPanelSections,
177-
)
169+
.concat(datasourceAndVizType, timeSection, controlPanelSections)
178170
.filter(section => section);
179171
}
180172

superset-frontend/src/explore/controls.jsx

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -843,7 +843,7 @@ export const controls = {
843843
type: 'DateFilterControl',
844844
freeForm: true,
845845
label: TIME_FILTER_LABELS.time_range,
846-
default: t('Last week'),
846+
default: t('Last week'), // this value is translated, but the backend wouldn't understand a translated value?
847847
description: t(
848848
'The time range for the visualization. All relative times, e.g. "Last month", ' +
849849
'"Last 7 days", "now", etc. are evaluated on the server using the server\'s ' +
@@ -857,6 +857,24 @@ export const controls = {
857857
}),
858858
},
859859

860+
time_range_fixed: {
861+
type: 'CheckboxControl',
862+
label: t('Fix to selected Time Range'),
863+
description: t(
864+
'Fix the trend line to the full time range specified in case filtered results do not include the start or end dates',
865+
),
866+
renderTrigger: true,
867+
visibility(props) {
868+
const {
869+
time_range: timeRange,
870+
viz_type: vizType,
871+
show_trend_line: showTrendLine,
872+
} = props.form_data;
873+
// only display this option when a time range is selected
874+
return timeRange && timeRange !== 'No filter';
875+
},
876+
},
877+
860878
max_bubble_size: {
861879
type: 'SelectControl',
862880
freeForm: true,
@@ -1197,28 +1215,28 @@ export const controls = {
11971215
label: t('Header Font Size'),
11981216
renderTrigger: true,
11991217
clearable: false,
1200-
default: 0.3,
1218+
default: 0.4,
12011219
// Values represent the percentage of space a header should take
12021220
options: [
12031221
{
12041222
label: t('Tiny'),
1205-
value: 0.125,
1223+
value: 0.2,
12061224
},
12071225
{
12081226
label: t('Small'),
1209-
value: 0.2,
1227+
value: 0.3,
12101228
},
12111229
{
12121230
label: t('Normal'),
1213-
value: 0.3,
1231+
value: 0.4,
12141232
},
12151233
{
12161234
label: t('Large'),
1217-
value: 0.4,
1235+
value: 0.5,
12181236
},
12191237
{
12201238
label: t('Huge'),
1221-
value: 0.5,
1239+
value: 0.6,
12221240
},
12231241
],
12241242
},
@@ -1228,7 +1246,7 @@ export const controls = {
12281246
label: t('Subheader Font Size'),
12291247
renderTrigger: true,
12301248
clearable: false,
1231-
default: 0.125,
1249+
default: 0.15,
12321250
// Values represent the percentage of space a subheader should take
12331251
options: [
12341252
{
@@ -1237,19 +1255,19 @@ export const controls = {
12371255
},
12381256
{
12391257
label: t('Small'),
1240-
value: 0.2,
1258+
value: 0.15,
12411259
},
12421260
{
12431261
label: t('Normal'),
1244-
value: 0.3,
1262+
value: 0.2,
12451263
},
12461264
{
12471265
label: t('Large'),
1248-
value: 0.4,
1266+
value: 0.3,
12491267
},
12501268
{
12511269
label: t('Huge'),
1252-
value: 0.5,
1270+
value: 0.4,
12531271
},
12541272
],
12551273
},

superset/viz.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,8 @@ def get_df_payload(self, query_obj=None, **kwargs):
484484
"form_data": self.form_data,
485485
"is_cached": self._any_cache_key is not None,
486486
"query": self.query,
487+
"from_dttm": self.from_dttm,
488+
"to_dttm": self.to_dttm,
487489
"status": self.status,
488490
"stacktrace": stacktrace,
489491
"rowcount": len(df.index) if df is not None else 0,

0 commit comments

Comments
 (0)