-
Notifications
You must be signed in to change notification settings - Fork 14.6k
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
Conversation
Codecov Report
@@ 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
Continue to review full report at Codecov.
|
@VinodLouis can you fix the conflicts? We would really like to use your visualization! |
@SpyderRivera Thanks for your response I have resolved the conflicts and pushed the changes. |
Would be great to see this integrated! |
I'll ping the dev list about this. |
@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! |
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. |
self.form_data.get('metric_2'), | ||
] | ||
for i, m in enumerate(metrics): | ||
ys = series[m] |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
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.