Skip to content

Commit

Permalink
Merge pull request #159 from quetzaluz/feature/inheritable-extras
Browse files Browse the repository at this point in the history
 Move call to render chart.extras to inheritable template block (issue #135)
  • Loading branch information
areski authored Mar 15, 2018
2 parents 8588e6c + 5bfa46e commit 8e6fd92
Show file tree
Hide file tree
Showing 12 changed files with 61 additions and 9 deletions.
2 changes: 1 addition & 1 deletion examples/discreteBarChart.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
output_file = open('test_discreteBarChart.html', 'w')

type = "discreteBarChart"
chart = discreteBarChart(name='mygraphname', height=400, width=600)
chart = discreteBarChart(name='mygraphname', height=400, width=600, show_values=True, extras="d3.selectAll('#mygraphname text').style('fill', 'red')")
chart.set_containerheader("\n\n<h2>" + type + "</h2>\n\n")
xdata = ["A", "B", "C", "D", "E", "F", "G"]
ydata = [3, 12, -10, 5, 25, -7, 2]
Expand Down
2 changes: 1 addition & 1 deletion examples/pieChart.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
output_file = open('test_pieChart.html', 'w')

type = "pieChart"
chart = pieChart(name=type, color_category='category20c', height=400, width=400)
chart = pieChart(name=type, color_category='category20c', height=400, width=400, extras="d3.selectAll('#piechart .nv-slice').style('opacity', 0.5);")
chart.set_containerheader("\n\n<h2>" + type + "</h2>\n\n")
chart.callback = '''
function(){
Expand Down
4 changes: 4 additions & 0 deletions nvd3/templates/bulletchart.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@

return chart;
});

{% block extras %}
{{ super () }}
{% endblock extras %}
{% endblock body %}


11 changes: 7 additions & 4 deletions nvd3/templates/content.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
{% if chart.show_values %}
chart.showValues(true);
{% endif %}

{% endblock rendering_opts %}

{% block focus %}
Expand Down Expand Up @@ -130,10 +131,12 @@
.call(chart);
{% endblock inject %}

{# extra chart attributes #}
{% if chart.extras %}
{{ chart.extras }}
{% endif %}
{% block extras %}
{# extra chart attributes #}
{% if chart.extras %}
{{ chart.extras }}
{% endif %}
{% endblock extras %}

{# callback for clicking on charts #}
{% if chart.callback %}
Expand Down
4 changes: 4 additions & 0 deletions nvd3/templates/discretebarchart.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
{{ super() }}
{% endblock inject %}

{% block extras %}
{{ super () }}
{% endblock extras %}

{% block close %}
{{ super() }}
{% endblock close %}
Expand Down
6 changes: 3 additions & 3 deletions nvd3/templates/linebarwfocuschart.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@
{{super()}}
{% endblock inject %}

{% if chart.extras %}
{{ chart.extras }}
{% endif %}
{% block extras %}
{{ super () }}
{% endblock extras %}

{% block close %}
});
Expand Down
4 changes: 4 additions & 0 deletions nvd3/templates/linechart.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@
{{ super() }}
{% endblock inject %}

{% block extras %}
{{ super () }}
{% endblock extras %}

{% block close %}
{{ super() }}
{% endblock close %}
Expand Down
4 changes: 4 additions & 0 deletions nvd3/templates/lineplusbarchart.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@
{{ super() }}
{% endblock inject %}

{% block extras %}
{{ super () }}
{% endblock extras %}

{% block close %}
{{ super() }}
{% endblock close %}
Expand Down
4 changes: 4 additions & 0 deletions nvd3/templates/multichart.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@
{{ super() }}
{% endblock inject %}

{% block extras %}
{{ super () }}
{% endblock extras %}

{% block close %}
{{ super() }}
{% endblock close %}
Expand Down
7 changes: 7 additions & 0 deletions nvd3/templates/piechart.html
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,13 @@
{{super()}}
{% endblock inject %}

{% block extras %}
{# extra chart attributes #}
{% if chart.extras %}
{{ chart.extras }}
{% endif %}
{% endblock extras %}

{% if chart.callback %}
},{{ chart.callback }});
{% endif %}
Expand Down
4 changes: 4 additions & 0 deletions nvd3/templates/scatterchart.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@
{{ super() }}
{% endblock inject %}

{% block extras %}
{{ super () }}
{% endblock extras %}

{% block close %}
{{ super() }}
{% endblock close %}
Expand Down
18 changes: 18 additions & 0 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,24 @@ def test_bulletChart_marker_optional(self):
assert 'marker' not in chart.htmlcontent


def test_charts_with_extras(self):
# extras="d3.selectAll('#mygraphname text').style('opacity', 0.5)"
type_bullet = 'bulletChart'
bullet_chart = bulletChart(name=type_bullet, height=100, width=500, extras="d3.selectAll('#mygraphname text').style('opacity', 0.5)")
bullet_chart.buildhtml()
assert 'data_bulletchart' in bullet_chart.htmlcontent
assert "d3.selectAll('#mygraphname text').style('opacity', 0.5)" in bullet_chart.htmlcontent

type_pie = "pieChart"
pie_chart = pieChart(name=type_pie, height=400, width=400, donut=True, donutRatio=0.2, extras="alert('Example of extra not even related to d3!')")
pie_chart.buildhtml()
assert "alert('Example of extra not even related to d3!')" in pie_chart.htmlcontent

type_line_plus_bar = "linePlusBarChart"
line_plus_bar_chart = linePlusBarChart(name=type_line_plus_bar, date=True, height=350, extras="d3.selectAll('#mygraphname text').style('fill', 'red')")
line_plus_bar_chart.buildhtml()
assert "d3.selectAll('#mygraphname text').style('fill', 'red')" in line_plus_bar_chart.htmlcontent

class FuncTest(unittest.TestCase):

def test_stab(self):
Expand Down

0 comments on commit 8e6fd92

Please sign in to comment.