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

Introducing form overrides for label and tooltips #76

Merged
merged 1 commit into from
Dec 9, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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