From 1c71935ad06c70463bcea0172fa217a7a9de81c3 Mon Sep 17 00:00:00 2001 From: Wolfram Kerl Date: Mon, 28 Dec 2015 19:17:57 +0100 Subject: [PATCH] possibility to adjust the y-axis range --- nvd3/NVD3Chart.py | 4 ++++ nvd3/templates/content.html | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/nvd3/NVD3Chart.py b/nvd3/NVD3Chart.py index 0a296c23..7ffe21b8 100644 --- a/nvd3/NVD3Chart.py +++ b/nvd3/NVD3Chart.py @@ -87,6 +87,8 @@ def __init__(self, **kwargs): Signal that x axis is a date axis :keyword: **date_format** - default - ``%x`` see https://github.com/mbostock/d3/wiki/Time-Formatting + :keyword: **y_axis_scale_min** - default - ``''``. + :keyword: **y_axis_scale_max** - default - ``''``. :keyword: **x_axis_format** - default - ``''``. :keyword: **y_axis_format** - default - ``''``. :keyword: **style** - default - ``''`` @@ -131,6 +133,8 @@ def __init__(self, **kwargs): self.style = kwargs.get('style', '') self.date_format = kwargs.get('date_format', '%x') self.x_axis_date = kwargs.get('x_axis_date', False) + self.y_axis_scale_min = kwargs.get('y_axis_scale_min', '') + self.y_axis_scale_max = kwargs.get('y_axis_scale_max', '') #: x-axis contain date format or not # possible duplicate of x_axis_date self.date_flag = kwargs.get('date_flag', False) diff --git a/nvd3/templates/content.html b/nvd3/templates/content.html index 787f39b5..ff278cc2 100644 --- a/nvd3/templates/content.html +++ b/nvd3/templates/content.html @@ -96,6 +96,12 @@ {% endblock custoattr %} + {% block y_axis_scale %} + {% if chart.y_axis_scale_min or chart.y_axis_scale_max %} + chart.forceY([{{ chart.y_axis_scale_min }},{{ chart.y_axis_scale_max }}]); + {% endif %} + {% endblock y_axis_scale %} + {% block inject %} {# Inject data to D3 #} d3.select('#{{ chart.name }} svg')