diff --git a/examples/discreteBarChart.py b/examples/discreteBarChart.py
index 0fb6375f..e8ffa29b 100644
--- a/examples/discreteBarChart.py
+++ b/examples/discreteBarChart.py
@@ -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
" + type + "
\n\n")
xdata = ["A", "B", "C", "D", "E", "F", "G"]
ydata = [3, 12, -10, 5, 25, -7, 2]
diff --git a/examples/pieChart.py b/examples/pieChart.py
index 618c885d..3e208a6b 100644
--- a/examples/pieChart.py
+++ b/examples/pieChart.py
@@ -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" + type + "
\n\n")
chart.callback = '''
function(){
diff --git a/nvd3/templates/bulletchart.html b/nvd3/templates/bulletchart.html
index 081dba96..985f4239 100644
--- a/nvd3/templates/bulletchart.html
+++ b/nvd3/templates/bulletchart.html
@@ -25,6 +25,10 @@
return chart;
});
+
+ {% block extras %}
+ {{ super () }}
+ {% endblock extras %}
{% endblock body %}
diff --git a/nvd3/templates/content.html b/nvd3/templates/content.html
index f4d2125a..a3831940 100644
--- a/nvd3/templates/content.html
+++ b/nvd3/templates/content.html
@@ -39,6 +39,7 @@
{% if chart.show_values %}
chart.showValues(true);
{% endif %}
+
{% endblock rendering_opts %}
{% block focus %}
@@ -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 %}
diff --git a/nvd3/templates/discretebarchart.html b/nvd3/templates/discretebarchart.html
index 221b280d..adcc38d4 100644
--- a/nvd3/templates/discretebarchart.html
+++ b/nvd3/templates/discretebarchart.html
@@ -32,6 +32,10 @@
{{ super() }}
{% endblock inject %}
+ {% block extras %}
+ {{ super () }}
+ {% endblock extras %}
+
{% block close %}
{{ super() }}
{% endblock close %}
diff --git a/nvd3/templates/linebarwfocuschart.html b/nvd3/templates/linebarwfocuschart.html
index d12c796f..7e4b9211 100644
--- a/nvd3/templates/linebarwfocuschart.html
+++ b/nvd3/templates/linebarwfocuschart.html
@@ -52,9 +52,9 @@
{{super()}}
{% endblock inject %}
- {% if chart.extras %}
- {{ chart.extras }}
- {% endif %}
+ {% block extras %}
+ {{ super () }}
+ {% endblock extras %}
{% block close %}
});
diff --git a/nvd3/templates/linechart.html b/nvd3/templates/linechart.html
index a1b19adf..d22aaa44 100644
--- a/nvd3/templates/linechart.html
+++ b/nvd3/templates/linechart.html
@@ -47,6 +47,10 @@
{{ super() }}
{% endblock inject %}
+ {% block extras %}
+ {{ super () }}
+ {% endblock extras %}
+
{% block close %}
{{ super() }}
{% endblock close %}
diff --git a/nvd3/templates/lineplusbarchart.html b/nvd3/templates/lineplusbarchart.html
index bfcb9069..009a7050 100644
--- a/nvd3/templates/lineplusbarchart.html
+++ b/nvd3/templates/lineplusbarchart.html
@@ -40,6 +40,10 @@
{{ super() }}
{% endblock inject %}
+ {% block extras %}
+ {{ super () }}
+ {% endblock extras %}
+
{% block close %}
{{ super() }}
{% endblock close %}
diff --git a/nvd3/templates/multichart.html b/nvd3/templates/multichart.html
index db1100ff..8264b00e 100644
--- a/nvd3/templates/multichart.html
+++ b/nvd3/templates/multichart.html
@@ -43,6 +43,10 @@
{{ super() }}
{% endblock inject %}
+ {% block extras %}
+ {{ super () }}
+ {% endblock extras %}
+
{% block close %}
{{ super() }}
{% endblock close %}
diff --git a/nvd3/templates/piechart.html b/nvd3/templates/piechart.html
index e818509e..1cc45ea7 100644
--- a/nvd3/templates/piechart.html
+++ b/nvd3/templates/piechart.html
@@ -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 %}
diff --git a/nvd3/templates/scatterchart.html b/nvd3/templates/scatterchart.html
index 35bbebd5..0a88a06c 100644
--- a/nvd3/templates/scatterchart.html
+++ b/nvd3/templates/scatterchart.html
@@ -49,6 +49,10 @@
{{ super() }}
{% endblock inject %}
+ {% block extras %}
+ {{ super () }}
+ {% endblock extras %}
+
{% block close %}
{{ super() }}
{% endblock close %}
diff --git a/tests.py b/tests.py
index 4de8b360..c1c291a5 100644
--- a/tests.py
+++ b/tests.py
@@ -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):