Skip to content
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
4 changes: 4 additions & 0 deletions nvd3/NVD3Chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 - ``''``
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions nvd3/templates/content.html
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@

{% endblock custoattr %}

{% block y_axis_scale %}
{% if chart.y_axis_scale_min or chart.y_axis_scale_max %}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why or if we use both parameters? maybe and will be more appropriate?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It adds the possibility to set either min or max. So you can set y_axis_scale_min =-1 but leave it 'open' towards the maximum by just not specifying it.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so if y_axis_scale_min is -1 and chart.y_axis_scale_max is empty, the next line will produce:

chart.forceY([-1,]);

Are you sure forceY method will be happy with [-1,] (that's the same in JS as [-1]) ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@areski I did not find any documentation on the forcceY method and experimented a bit with it and worked for me all the time. Also [,1] works flawless in case only the max value is defined.
I could add an if statement in the case that only min is defined, but for the max case the first parameter needs to stay undefined anyway.
It seems more consistent to me to leave it undefined in both cases.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That seems good enough, thanks for testing!

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')
Expand Down