Skip to content

Commit

Permalink
Merge pull request #76 from mistercrunch/form_overrides
Browse files Browse the repository at this point in the history
Introducing form overrides for label and tooltips
  • Loading branch information
mistercrunch committed Dec 9, 2015
2 parents 9c0dd5b + d476dd2 commit 1685911
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 6 deletions.
2 changes: 1 addition & 1 deletion panoramix/templates/panoramix/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
{% endblock %}

{% block tail_js %}
{{ super() }}
<script src="/static/panoramix.js"></script>
<script src="/static/lib/jquery-ui/jquery-ui.min.js"></script>
<script src="/static/lib/select2.sortable.js"></script>
{{ super() }}
{% endblock %}
8 changes: 4 additions & 4 deletions panoramix/templates/panoramix/explore.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ <h4>
<div>
{% set field = form.get_field(fieldname)%}
<div>
{{ field.label }}
{{ viz.get_form_override(fieldname, 'label') or field.label }}
{% if field.description %}
<i class="fa fa-info-circle" data-toggle="tooltip" data-placement="right"
title="{{ field.description }}"></i>
title="{{ viz.get_form_override(fieldname, 'description') or field.description }}"></i>
{% endif %}
{{ field(class_=form.field_css_classes(field.name)) }}
</div>
Expand All @@ -51,10 +51,10 @@ <h4>
<div class="col-xs-{{ (12 / fieldname|length) | int }}">
{% if name %}
{% set field = form.get_field(name)%}
{{ field.label }}
{{ viz.form_overrides.label or field.label }}
{% if field.description %}
<i class="fa fa-info-circle" data-toggle="tooltip" data-placement="right"
title="{{ field.description }}"></i>
title="{{ viz.get_form_override(fieldname, 'description') or field.description }}"></i>
{% endif %}
{{ field(class_=form.field_css_classes(field.name)) }}
{% endif %}
Expand Down
31 changes: 30 additions & 1 deletion panoramix/viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import json
import uuid

from flask import flash, request
from flask import flash, request, Markup
from markdown import markdown
from pandas.io.json import dumps
from werkzeug.datastructures import ImmutableMultiDict
Expand Down Expand Up @@ -36,6 +36,7 @@ class BaseViz(object):
},)
js_files = []
css_files = []
form_overrides = {}

def __init__(self, datasource, form_data):
self.orig_form_data = form_data
Expand Down Expand Up @@ -74,6 +75,16 @@ def __init__(self, datasource, form_data):
self.groupby = self.form_data.get('groupby') or []
self.reassignments()

def get_form_override(self, fieldname, attr):
if (
fieldname in self.form_overrides and
attr in self.form_overrides[fieldname]):
s = self.form_overrides[fieldname][attr]
if attr == 'label':
s = '<label for="{fieldname}">{s}</label>'.format(**locals())
s = Markup(s)
return s

def fieldsetizer(self):
"""
Makes form_fields support either a list approach or a fieldsets
Expand Down Expand Up @@ -804,6 +815,24 @@ class SunburstViz(BaseViz):
'limit',
)
},)
form_overrides = {
'metric': {
'label': 'Primary Metric',
'description': (
"The primary metric is used to "
"define the arc segment sizes"),
},
'secondary_metric': {
'label': 'Secondary Metric',
'description': (
"This secondary metric is used to "
"define the color as a ratio against the primary metric"),
},
'groupby': {
'label': 'Hierarchy',
'description': "This defines the level of the hierarchy",
},
}

def get_df(self):
df = super(SunburstViz, self).get_df()
Expand Down

0 comments on commit 1685911

Please sign in to comment.