Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding a new viz line-bar chart #5144

Closed
wants to merge 8 commits into from
Closed

Conversation

VinodLouis
Copy link

This pull request is a very simple and straightforward implementation of a line-bar chart. I recently added this in my project and thought it would be an good addition. Nothing fancy but leveraging the nvd3 charting functionality to accomplish it.

line_bar

@codecov-io
Copy link

codecov-io commented Jun 6, 2018

Codecov Report

Merging #5144 into master will increase coverage by 13.67%.
The diff coverage is 17.02%.

Impacted file tree graph

@@             Coverage Diff             @@
##           master    #5144       +/-   ##
===========================================
+ Coverage   63.48%   77.16%   +13.67%     
===========================================
  Files         360       44      -316     
  Lines       22886     8784    -14102     
  Branches     2547        0     -2547     
===========================================
- Hits        14529     6778     -7751     
+ Misses       8342     2006     -6336     
+ Partials       15        0       -15
Impacted Files Coverage Δ
superset/viz.py 79.43% <17.02%> (-1.74%) ⬇️
superset/views/annotations.py 67.64% <0%> (-7.91%) ⬇️
superset/legacy.py 14.7% <0%> (-3.61%) ⬇️
superset/views/base.py 67.12% <0%> (-2.94%) ⬇️
superset/connectors/druid/models.py 80.53% <0%> (-2.01%) ⬇️
superset/cli.py 44.69% <0%> (-1.91%) ⬇️
superset/__init__.py 72.32% <0%> (-0.79%) ⬇️
superset/connectors/base/models.py 90.74% <0%> (-0.76%) ⬇️
superset/connectors/sqla/models.py 78.22% <0%> (-0.75%) ⬇️
superset/utils.py 88.52% <0%> (-0.61%) ⬇️
... and 332 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5c1d906...28fbd69. Read the comment docs.

@SpyderRivera
Copy link
Contributor

@VinodLouis can you fix the conflicts? We would really like to use your visualization!

@VinodLouis
Copy link
Author

@SpyderRivera Thanks for your response I have resolved the conflicts and pushed the changes.

@jeremyhiggs
Copy link

Would be great to see this integrated!

@SpyderRivera
Copy link
Contributor

I'll ping the dev list about this.

@conglei
Copy link
Contributor

conglei commented Dec 6, 2018

@VinodLouis Thanks for adding this new visualization type to superset!

As the community of superset is getting larger, we are aware of the increasing number of new visualization types added to Superset. It is great, however, it makes the visualization code hard to maintain and make the js bundle size larger. Due to this reason, the Superset community has proposed #5692, a js plugin system, to separate the visualization code from the superset core infra. You can also check one example we are working on apache-superset/superset-ui#50. It will be great if you can follow the same structure and help us to embrace the visualization plug-in system and any suggestion are welcome!

cc @SpyderRivera

@kristw kristw added the .vis label Jan 8, 2019
@kristw kristw added the enhancement:request Enhancement request submitted by anyone from the community label Jan 22, 2019
@Rijicp Rijicp mentioned this pull request Feb 6, 2019
@stale
Copy link

stale bot commented Apr 10, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the inactive Inactive for >= 30 days label Apr 10, 2019
@stale stale bot closed this Apr 17, 2019
self.form_data.get('metric_2'),
]
for i, m in enumerate(metrics):
ys = series[m]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this line execution returns a error: can not hash a dict

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

class LineBarViz(DistributionPieViz):
    """A rich line chart with dual axis"""
    viz_type = 'line_bar'
    verbose_name = _('Time Series - Line Bar Chart')
    sort_series = False
    is_timeseries = True
    def query_obj(self):
        d = super(LineBarViz, self).query_obj()
        m1 = self.form_data.get('metric')
        m2 = self.form_data.get('metric_2i')
        d['metrics'] = [m1, m2]
        if not m1:
            raise Exception(_('Pick a metric for left(bar) axis!'))
        if not m2:
            raise Exception(_('Pick a metric for right(line) axis!'))
        if m1['label'] == m2['label']:
            raise Exception(_('Please choose different metrics'
                            ' on left and right axis'))
        return d
    def to_series(self, df, classed=''):
        cols = []
        for col in df.columns:
            if col == '':
                cols.append('N/A')
            elif col is None:
                cols.append('NULL')
            else:
                cols.append(col)
        df.columns = cols
        series = df.to_dict('series')
        chart_data = []
        metrics = [
            self.form_data.get('metric')['label'],
            self.form_data.get('metric_2i')['label'],
        ]
        for i, m in enumerate(metrics):
            ys = series[m]
            if df[m].dtype.kind not in 'biufc':
                continue
            series_title = m
            d = {
                'key': series_title,
                'classed': classed,
                'values': [
                    {'x': ds, 'y': ys[ds] if ds in ys else None}
                    for ds in df.index
                ],
                'yAxis': i + 1,
                'type': 'bar' if i==0 else 'line',
            }
            chart_data.append(d)
        return chart_data
    def get_data(self, df):
        fd = self.form_data
        df = df.fillna(0)
        if self.form_data.get('granularity') == 'all':
            raise Exception(_('Pick a time granularity for your time series'))
        metric = fd.get('metric')
        metric_2i = fd.get('metric_2i')
        print(metric)
        df = df.pivot_table(
            index=DTTM_ALIAS,
            values=[metric['label'], metric_2i['label']])
        chart_data = self.to_series(df)
        return chart_data

This May help you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement:request Enhancement request submitted by anyone from the community inactive Inactive for >= 30 days
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants