Skip to content

Commit

Permalink
update pie chart + nvd3 file include
Browse files Browse the repository at this point in the history
  • Loading branch information
shrenik committed Oct 1, 2013
1 parent 286b4ed commit 7af62e3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
18 changes: 11 additions & 7 deletions nvd3/NVD3Chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,10 @@ def __init__(self, name=None, color_category=None, jquery_on_ready=False,
self.header_js = [
'<script src="%s" type="text/javascript"></script>\n' % h for h in
(
'./bower_components/d3/d3.min.js',
'./bower_components/nvd3/nv.d3.min.js'
#'./bower_components/d3/d3.min.js',
'./bower_components/nvd3/lib/d3.v2.js',
#'./bower_components/nvd3/nv.d3.min.js'
'http://nvd3.org/nv.d3.js'
)
]

Expand Down Expand Up @@ -178,7 +180,10 @@ def add_serie(self, y, x, name=None, extra={}, **kwargs):
"size": csize[i] if isinstance(csize, list) else csize
} for i, y in enumerate(y)]
else:
serie = [{"x": x[i], "y": y} for i, y in enumerate(y)]
if self.model == 'pieChart':
serie = [{"label": x[i], "value": y} for i, y in enumerate(y)]
else:
serie = [{"x": x[i], "y": y} for i, y in enumerate(y)]

data_keyvalue = {"values": serie, "key": name}

Expand All @@ -196,7 +201,8 @@ def add_serie(self, y, x, name=None, extra={}, **kwargs):
if 'yaxis' in kwargs and kwargs["yaxis"]:
data_keyvalue["yAxis"] = kwargs["yaxis"]
else:
data_keyvalue["yAxis"] = "1"
if self.model != 'pieChart':
data_keyvalue["yAxis"] = "1"

if 'bar' in kwargs and kwargs["bar"]:
data_keyvalue["bar"] = 'true'
Expand Down Expand Up @@ -238,7 +244,7 @@ def add_serie(self, y, x, name=None, extra={}, **kwargs):
_start = ("'" + str(_start) + "' + ") if _start else ''
_end = (" + '" + str(_end) + "'") if _end else ''
self.tooltip_condition_string += \
"var y = " + _start + " String(e.point.y) " + _end + ";\n"
"var y = " + _start + " String(y) " + _end + ";\n"

self.series.append(data_keyvalue)

Expand Down Expand Up @@ -385,8 +391,6 @@ def buildjschart(self):
self.d3_select_extra += ".attr('height', %s)\n" % self.height

datum = "data_%s" % self.name
if self.model == 'pieChart':
datum = "[data_%s[0].values]" % self.name

# add custom tooltip string in jschart
# default condition (if build_custom_tooltip is not called explicitly with date_flag=True)
Expand Down
7 changes: 3 additions & 4 deletions nvd3/pieChart.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class pieChart(NVD3Chart):
chart.tooltipContent(function(key, y, e, graph) {
var x = String(key);
var y = String(e.point.y) + ' cal';
var y = String(y) + ' cal';
tooltip_str = '<center><b>'+x+'</b></center>' + y;
return tooltip_str;
});
Expand Down Expand Up @@ -104,9 +104,8 @@ def buildjschart(self):
if start_js > 0:
self.jschart = self.jschart[:replace_index] + color_js + self.jschart[replace_index:]

pie_jschart = '\n' + stab(2) + 'chart.x(function(d) { return d.x })\n' + \
stab(3) + '.y(function(d) { return d.y })\n' + \
stab(3) + '.values(function(d) { return d });\n'
pie_jschart = '\n' + stab(2) + 'chart.x(function(d) { return d.label })\n' + \
stab(3) + '.y(function(d) { return d.value });\n'
if self.width:
pie_jschart += stab(2) + 'chart.width(%s);\n' % self.width
if self.height:
Expand Down

0 comments on commit 7af62e3

Please sign in to comment.