From d600ad2da17bc1160e08b457fecd1757b5dca1be Mon Sep 17 00:00:00 2001 From: Cyd La Luz Date: Wed, 14 Mar 2018 15:55:02 -0700 Subject: [PATCH 1/5] Move call to render chart.extras to inheritable template block #135 --- nvd3/templates/content.html | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/nvd3/templates/content.html b/nvd3/templates/content.html index f4d2125a..8690a230 100644 --- a/nvd3/templates/content.html +++ b/nvd3/templates/content.html @@ -39,6 +39,11 @@ {% if chart.show_values %} chart.showValues(true); {% endif %} + + {# extra chart attributes #} + {% if chart.extras %} + {{ chart.extras }} + {% endif %} {% endblock rendering_opts %} {% block focus %} @@ -130,11 +135,6 @@ .call(chart); {% endblock inject %} - {# extra chart attributes #} - {% if chart.extras %} - {{ chart.extras }} - {% endif %} - {# callback for clicking on charts #} {% if chart.callback %} },{{ chart.callback }}); From 7ef403569155d2632c92467b81fad8af61dd27b6 Mon Sep 17 00:00:00 2001 From: Cyd La Luz Date: Wed, 14 Mar 2018 15:58:29 -0700 Subject: [PATCH 2/5] Remove now redundant template rendering for chart.extras now that it is inherited from content.html --- nvd3/templates/linebarwfocuschart.html | 4 ---- 1 file changed, 4 deletions(-) diff --git a/nvd3/templates/linebarwfocuschart.html b/nvd3/templates/linebarwfocuschart.html index d12c796f..b65ae034 100644 --- a/nvd3/templates/linebarwfocuschart.html +++ b/nvd3/templates/linebarwfocuschart.html @@ -52,10 +52,6 @@ {{super()}} {% endblock inject %} - {% if chart.extras %} - {{ chart.extras }} - {% endif %} - {% block close %} }); {% endblock close %} From 77ec6fe9f666ac172ba506bfe79e938e9db76036 Mon Sep 17 00:00:00 2001 From: Cyd La Luz Date: Wed, 14 Mar 2018 16:07:51 -0700 Subject: [PATCH 3/5] Add extras rendering block to piechart as well. --- nvd3/templates/piechart.html | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/nvd3/templates/piechart.html b/nvd3/templates/piechart.html index e818509e..f5eb0623 100644 --- a/nvd3/templates/piechart.html +++ b/nvd3/templates/piechart.html @@ -76,6 +76,10 @@ {% if chart.show_controls == False %} chart.showControls(false); {% endif %} + {# extra chart attributes #} + {% if chart.extras %} + {{ chart.extras }} + {% endif %} {% endblock rendering_opts %} {% block inject %} From 82e90fee1085c821dda8e8005425c56ecbcc7e37 Mon Sep 17 00:00:00 2001 From: Cyd La Luz Date: Wed, 14 Mar 2018 16:27:37 -0700 Subject: [PATCH 4/5] render extras after inject to better honor original implementation / documented example --- nvd3/templates/content.html | 11 +++++++---- nvd3/templates/discretebarchart.html | 4 ++++ nvd3/templates/linebarwfocuschart.html | 4 ++++ nvd3/templates/linechart.html | 4 ++++ nvd3/templates/multichart.html | 4 ++++ nvd3/templates/piechart.html | 11 +++++++---- nvd3/templates/scatterchart.html | 4 ++++ 7 files changed, 34 insertions(+), 8 deletions(-) diff --git a/nvd3/templates/content.html b/nvd3/templates/content.html index 8690a230..a3831940 100644 --- a/nvd3/templates/content.html +++ b/nvd3/templates/content.html @@ -40,10 +40,6 @@ chart.showValues(true); {% endif %} - {# extra chart attributes #} - {% if chart.extras %} - {{ chart.extras }} - {% endif %} {% endblock rendering_opts %} {% block focus %} @@ -135,6 +131,13 @@ .call(chart); {% endblock inject %} + {% block extras %} + {# extra chart attributes #} + {% if chart.extras %} + {{ chart.extras }} + {% endif %} + {% endblock extras %} + {# callback for clicking on charts #} {% if chart.callback %} },{{ 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 b65ae034..7e4b9211 100644 --- a/nvd3/templates/linebarwfocuschart.html +++ b/nvd3/templates/linebarwfocuschart.html @@ -52,6 +52,10 @@ {{super()}} {% endblock inject %} + {% block extras %} + {{ super () }} + {% endblock extras %} + {% block close %} }); {% endblock 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/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 f5eb0623..1cc45ea7 100644 --- a/nvd3/templates/piechart.html +++ b/nvd3/templates/piechart.html @@ -76,16 +76,19 @@ {% if chart.show_controls == False %} chart.showControls(false); {% endif %} - {# extra chart attributes #} - {% if chart.extras %} - {{ chart.extras }} - {% endif %} {% endblock rendering_opts %} {% block inject %} {{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 %} From 5bfa46e8916d393dbb3edab2520f725ffb2722f9 Mon Sep 17 00:00:00 2001 From: Cyd La Luz Date: Wed, 14 Mar 2018 16:41:14 -0700 Subject: [PATCH 5/5] Add specs and extras to two examples file; add feature for bullet chart and lineplusbarchart --- examples/discreteBarChart.py | 2 +- examples/pieChart.py | 2 +- nvd3/templates/bulletchart.html | 4 ++++ nvd3/templates/lineplusbarchart.html | 4 ++++ tests.py | 18 ++++++++++++++++++ 5 files changed, 28 insertions(+), 2 deletions(-) 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/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/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):