You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by GitBox <gi...@apache.org> on 2019/07/15 11:09:24 UTC
[GitHub] [incubator-superset] gbrian commented on issue #6883: superset
0.28.1 integrated echarts method
gbrian commented on issue #6883: superset 0.28.1 integrated echarts method
URL: https://github.com/apache/incubator-superset/issues/6883#issuecomment-511360296
Hi,
Have an intermediate step while developing the final Chart plugin. Is about using a modified version of the `Markup` visualization. It requieres just few changes on Superset (no need to deal with plugins repo currently).
_Not a final solution but helps in the meantime 😄_

Changes are:
* Add Jinja2 templates
* Add Query and data functionalities
CODE:
```
class MarkupViz(BaseViz):
"""Use html or markdown to create a free form widget"""
viz_type = "markup"
verbose_name = _("Markup")
is_timeseries = False
def should_be_timeseries(self):
fd = self.form_data
# TODO handle datasource-type-specific code in datasource
conditions_met = (fd.get("granularity") and fd.get("granularity") != "all") or (
fd.get("granularity_sqla") and fd.get("time_grain_sqla")
)
if fd.get("include_time") and not conditions_met:
raise Exception(
_("Pick a granularity in the Time section or " "uncheck 'Include Time'")
)
return fd.get("include_time")
def query_obj(self):
d = super().query_obj()
fd = self.form_data
if fd.get("all_columns") and (fd.get("groupby") or fd.get("metrics")):
raise Exception(
_(
"Choose either fields to [Group By] and [Metrics] or "
"[Columns], not both"
)
)
sort_by = fd.get("timeseries_limit_metric")
if fd.get("all_columns"):
d["columns"] = fd.get("all_columns")
d["groupby"] = []
order_by_cols = fd.get("order_by_cols") or []
d["orderby"] = [json.loads(t) for t in order_by_cols]
elif sort_by:
sort_by_label = utils.get_metric_name(sort_by)
if sort_by_label not in utils.get_metric_names(d["metrics"]):
d["metrics"] += [sort_by]
d["orderby"] = [(sort_by, not fd.get("order_desc", True))]
# Add all percent metrics that are not already in the list
if "percent_metrics" in fd:
d["metrics"] = d["metrics"] + list(
filter(lambda m: m not in d["metrics"], fd["percent_metrics"] or [])
)
d["is_timeseries"] = self.should_be_timeseries()
return d
def get_code(self, df):
code = self.form_data.get("code", "")
processor = get_template_processor(self.datasource.database)
return processor.process_template(code, data=df.to_dict('r'))
def get_data(self, df):
print("markup df:%s" % df)
markup_type = self.form_data.get("markup_type")
code = self.get_code(df)
if markup_type == "markdown":
code = markdown(code, extensions=['tables'])
return dict(html=code, theme_css=get_css_manifest_files("theme"))
```
**markup.js**
```
import { t } from '@superset-ui/translation';
export default {
controlPanelSections: [
{
label: t('GROUP BY'),
description: t('Use this section if you want a query that aggregates'),
expanded: true,
controlSetRows: [
['groupby'],
['metrics'],
['percent_metrics'],
['timeseries_limit_metric', 'row_limit'],
['include_time', 'order_desc'],
],
},
{
label: t('NOT GROUPED BY'),
description: t('Use this section if you want to query atomic rows'),
expanded: true,
controlSetRows: [
['all_columns'],
['order_by_cols'],
['row_limit', null],
],
},
{
label: t('Query'),
expanded: true,
controlSetRows: [
['adhoc_filters'],
],
},
{
label: t('Options'),
expanded: true,
controlSetRows: [
['table_timestamp_format'],
['page_length', null],
['include_search', 'table_filter'],
['align_pn', 'color_pn'],
],
},
{
label: t('Code'),
expanded: true,
controlSetRows: [
['markup_type'],
['code'],
],
},
],
controlOverrides: {
metrics: {
validators: [],
},
},
};
```
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org