From commits-return-1861-archive-asf-public=cust-asf.ponee.io@superset.incubator.apache.org Mon Nov 19 23:01:33 2018 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx-eu-01.ponee.io (Postfix) with SMTP id 7EB38180671 for ; Mon, 19 Nov 2018 23:01:32 +0100 (CET) Received: (qmail 51959 invoked by uid 500); 19 Nov 2018 22:01:31 -0000 Mailing-List: contact commits-help@superset.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@superset.incubator.apache.org Delivered-To: mailing list commits@superset.incubator.apache.org Received: (qmail 51950 invoked by uid 99); 19 Nov 2018 22:01:31 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 19 Nov 2018 22:01:31 +0000 Received: by gitbox.apache.org (ASF Mail Server at gitbox.apache.org, from userid 33) id E018B850D1; Mon, 19 Nov 2018 22:01:30 +0000 (UTC) Date: Mon, 19 Nov 2018 22:01:30 +0000 To: "commits@superset.apache.org" Subject: [incubator-superset] branch master updated: Minor improvements to Histogram viz (#6391) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Message-ID: <154266489060.2270.16737556552666468030@gitbox.apache.org> From: maximebeauchemin@apache.org X-Git-Host: gitbox.apache.org X-Git-Repo: incubator-superset X-Git-Refname: refs/heads/master X-Git-Reftype: branch X-Git-Oldrev: d1a3ba85dd9e75ecbdc52a7c92ed27efda709f48 X-Git-Newrev: 4c4b6c41a1ee0c2f4172208389b616d666b0ea1d X-Git-Rev: 4c4b6c41a1ee0c2f4172208389b616d666b0ea1d X-Git-NotificationType: ref_changed_plus_diff X-Git-Multimail-Version: 1.5.dev Auto-Submitted: auto-generated This is an automated email from the ASF dual-hosted git repository. maximebeauchemin pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-superset.git The following commit(s) were added to refs/heads/master by this push: new 4c4b6c4 Minor improvements to Histogram viz (#6391) 4c4b6c4 is described below commit 4c4b6c41a1ee0c2f4172208389b616d666b0ea1d Author: Maxime Beauchemin AuthorDate: Mon Nov 19 14:01:20 2018 -0800 Minor improvements to Histogram viz (#6391) * Minor improvements to Histogram viz * prevent legend overflow (spill) by simply hiding it * legend title only includes metric name when necessary * control validator asking forcing at least one numeric column to be selected * Removing print() --- .../assets/src/explore/controlPanels/Histogram.js | 2 ++ .../src/visualizations/Histogram/Histogram.css | 3 +++ .../src/visualizations/Histogram/Histogram.jsx | 1 + superset/viz.py | 20 +++++++++++++------- 4 files changed, 19 insertions(+), 7 deletions(-) diff --git a/superset/assets/src/explore/controlPanels/Histogram.js b/superset/assets/src/explore/controlPanels/Histogram.js index 5289614..186dda2 100644 --- a/superset/assets/src/explore/controlPanels/Histogram.js +++ b/superset/assets/src/explore/controlPanels/Histogram.js @@ -1,4 +1,5 @@ import { t } from '@superset-ui/translation'; +import { nonEmpty } from '../validators'; export default { controlPanelSections: [ @@ -29,6 +30,7 @@ export default { label: t('Numeric Columns'), description: t('Select the numeric columns to draw the histogram'), multi: true, + validators: [nonEmpty], }, link_length: { label: t('No of Bins'), diff --git a/superset/assets/src/visualizations/Histogram/Histogram.css b/superset/assets/src/visualizations/Histogram/Histogram.css new file mode 100644 index 0000000..28b7d70 --- /dev/null +++ b/superset/assets/src/visualizations/Histogram/Histogram.css @@ -0,0 +1,3 @@ +.histogram { + overflow: hidden; +} diff --git a/superset/assets/src/visualizations/Histogram/Histogram.jsx b/superset/assets/src/visualizations/Histogram/Histogram.jsx index 8414830..2b54519 100644 --- a/superset/assets/src/visualizations/Histogram/Histogram.jsx +++ b/superset/assets/src/visualizations/Histogram/Histogram.jsx @@ -6,6 +6,7 @@ import { LegendOrdinal } from '@vx/legend'; import { scaleOrdinal } from '@vx/scale'; import { CategoricalColorNamespace } from '@superset-ui/color'; import WithLegend from '../WithLegend'; +import './Histogram.css'; const propTypes = { className: PropTypes.string, diff --git a/superset/viz.py b/superset/viz.py index 068a70d..e3e891a 100644 --- a/superset/viz.py +++ b/superset/viz.py @@ -1467,6 +1467,16 @@ class HistogramViz(BaseViz): d['groupby'] = [] return d + def labelify(self, keys, column): + if isinstance(keys, str): + keys = (keys,) + # removing undesirable characters + labels = [re.sub(r'\W+', r'_', k) for k in keys] + if len(self.columns) > 1 or not self.groupby: + # Only show numeric column in label if there are many + labels = [column] + labels + return '__'.join(labels) + def get_data(self, df): """Returns the chart data""" chart_data = [] @@ -1475,14 +1485,10 @@ class HistogramViz(BaseViz): else: groups = [((), df)] for keys, data in groups: - if isinstance(keys, str): - keys = (keys,) - # removing undesirable characters - keys = [re.sub(r'\W+', r'_', k) for k in keys] chart_data.extend([{ - 'key': '__'.join([c] + keys), - 'values': data[c].tolist()} - for c in self.columns]) + 'key': self.labelify(keys, column), + 'values': data[column].tolist()} + for column in self.columns]) return chart_data