You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@superset.apache.org by GitBox <gi...@apache.org> on 2018/04/09 21:02:45 UTC

[GitHub] mistercrunch closed pull request #4774: [explore] forcing .1% number format when using 'Period Ratio'

mistercrunch closed pull request #4774: [explore] forcing .1% number format when using 'Period Ratio'
URL: https://github.com/apache/incubator-superset/pull/4774
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/superset/assets/javascripts/explore/components/ControlHeader.jsx b/superset/assets/javascripts/explore/components/ControlHeader.jsx
index ce00a9d769..3dd884ce21 100644
--- a/superset/assets/javascripts/explore/components/ControlHeader.jsx
+++ b/superset/assets/javascripts/explore/components/ControlHeader.jsx
@@ -15,6 +15,7 @@ const propTypes = {
   hovered: PropTypes.bool,
   tooltipOnClick: PropTypes.func,
   warning: PropTypes.string,
+  danger: PropTypes.string,
 };
 
 const defaultProps = {
@@ -83,6 +84,19 @@ export default class ControlHeader extends React.Component {
                   overlay={
                     <Tooltip id={'error-tooltip'}>{this.props.warning}</Tooltip>
                   }
+                >
+                  <i className="fa fa-exclamation-circle text-warning" />
+                </OverlayTrigger>
+                {' '}
+              </span>
+            }
+            {(this.props.danger) &&
+              <span>
+                <OverlayTrigger
+                  placement="top"
+                  overlay={
+                    <Tooltip id={'error-tooltip'}>{this.props.danger}</Tooltip>
+                  }
                 >
                   <i className="fa fa-exclamation-circle text-danger" />
                 </OverlayTrigger>
diff --git a/superset/assets/javascripts/explore/components/controls/SelectControl.jsx b/superset/assets/javascripts/explore/components/controls/SelectControl.jsx
index 8b78fc027b..16cb95e094 100644
--- a/superset/assets/javascripts/explore/components/controls/SelectControl.jsx
+++ b/superset/assets/javascripts/explore/components/controls/SelectControl.jsx
@@ -11,6 +11,7 @@ const propTypes = {
   choices: PropTypes.array,
   clearable: PropTypes.bool,
   description: PropTypes.string,
+  disabled: PropTypes.bool,
   freeForm: PropTypes.bool,
   isLoading: PropTypes.bool,
   label: PropTypes.string,
@@ -31,6 +32,7 @@ const defaultProps = {
   choices: [],
   clearable: true,
   description: null,
+  disabled: false,
   freeForm: false,
   isLoading: false,
   label: null,
@@ -123,6 +125,7 @@ export default class SelectControl extends React.PureComponent {
       optionRenderer: VirtualizedRendererWrap(this.props.optionRenderer),
       valueRenderer: this.props.valueRenderer,
       selectComponent: this.props.freeForm ? Creatable : Select,
+      disabled: this.props.disabled,
     };
     return (
       <div>
diff --git a/superset/assets/javascripts/explore/stores/controls.jsx b/superset/assets/javascripts/explore/stores/controls.jsx
index 72baf1ff35..e0f58208a4 100644
--- a/superset/assets/javascripts/explore/stores/controls.jsx
+++ b/superset/assets/javascripts/explore/stores/controls.jsx
@@ -1157,6 +1157,11 @@ export const controls = {
     default: '.3s',
     choices: D3_FORMAT_OPTIONS,
     description: D3_FORMAT_DOCS,
+    mapStateToProps: state => ({
+      warning: state.controls && state.controls.num_period_compare.value !== '' ?
+        t('When `Period Ratio` is set, the Y Axis Format is forced to `.1%`') : null,
+      disabled: state.controls && state.controls.num_period_compare.value !== '',
+    }),
   },
 
   y_axis_2_format: {
diff --git a/superset/assets/visualizations/nvd3_vis.js b/superset/assets/visualizations/nvd3_vis.js
index 9ce02bd031..7af0220711 100644
--- a/superset/assets/visualizations/nvd3_vis.js
+++ b/superset/assets/visualizations/nvd3_vis.js
@@ -378,7 +378,12 @@ function nvd3Vis(slice, payload) {
 
     const yAxisFormatter = d3FormatPreset(fd.y_axis_format);
     if (chart.yAxis && chart.yAxis.tickFormat) {
-      chart.yAxis.tickFormat(yAxisFormatter);
+      if (fd.num_period_compare) {
+        // When computing a "Period Ratio", we force a percentage format
+        chart.yAxis.tickFormat(d3.format('.1%'));
+      } else {
+        chart.yAxis.tickFormat(yAxisFormatter);
+      }
     }
     if (chart.y2Axis && chart.y2Axis.tickFormat) {
       chart.y2Axis.tickFormat(yAxisFormatter);


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services