Skip to content

Commit 30d4352

Browse files
authored
Merge pull request #60 from agiliq/add_more_yui_charts
Add more yui charts
2 parents 7080185 + 087571a commit 30d4352

File tree

10 files changed

+112
-35
lines changed

10 files changed

+112
-35
lines changed

demo_project/demo/templates/demo/yui.html

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,55 @@ <h2>Line Chart</h2>
2929

3030
{{ line_chart.as_html }}
3131
<pre class="code">
32+
queryset = Account.objects.all()
3233
data_source = ModelDataSource(queryset, fields=['year', 'sales',],)
33-
gchart.LineChart(data_source, options={'title': "Sales Growth"})
34+
chart = yui.LineChart(data_source, options={'title': "Sales Growth"})
35+
</pre>
36+
</div>
37+
<br />
38+
39+
<h2>Spline Chart</h2>
40+
<div id="spline_chart" class="well">
41+
42+
{{ spline_chart.as_html }}
43+
<pre class="code">
44+
data = [
45+
['Year', 'Sales', 'Expenses', 'Items Sold', 'Net Profit'],
46+
['2004', 1000, 400, 100, 600],
47+
['2005', 1170, 460, 120, 310],
48+
['2006', 660, 1120, 50, -460],
49+
['2007', 1030, 540, 100, 200],
50+
]
51+
data_source = SimpleDataSource(data)
52+
chart = yui.SplineChart(data_source, options={'title': "Sales/ Expense"})
3453
</pre>
3554
</div>
3655
<br />
3756

3857
<h2>Column Chart</h2>
3958
<div id="column_chart" class="well">
4059
{{ column_chart.as_html }}
60+
<pre class="code">
61+
data = [
62+
['Year', 'Sales', 'Expenses', 'Items Sold', 'Net Profit'],
63+
['2004', 1000, 400, 100, 600],
64+
['2005', 1170, 460, 120, 310],
65+
['2006', 660, 1120, 50, -460],
66+
['2007', 1030, 540, 100, 200],
67+
]
68+
data_source = SimpleDataSource(data)
69+
chart = yui.ColumnChart(data_source, options={'title': "Sales/ Expense"})
4170
</div>
4271

4372
<br />
4473

4574
<h2>Bar Chart</h2>
4675
<div id="bar_chart" class="well">
4776
{{ bar_chart.as_html }}
77+
<pre class="code">
78+
data_source = ModelDataSource(queryset, fields=['year', 'sales'])
79+
chart = yui.BarChart(data_source, options={'title': "Expense Growth"})
80+
</pre>
4881
</div>
4982
<br />
5083

@@ -56,6 +89,28 @@ <h2>Candlestick Chart</h2>
5689
<h2>Pie Chart</h2>
5790
<div id="pie_chart" class="well">
5891
{{ pie_chart.as_html }}
92+
<pre class="code">
93+
data_source = ModelDataSource(queryset, fields=['year', 'sales'])
94+
chart = yui.PieChart(data_source)
95+
</pre>
96+
</div>
97+
98+
<h2>Area Chart</h2>
99+
<div id="area_chart" class="well">
100+
{{ area_chart.as_html }}
101+
<pre class="code">
102+
data_source = ModelDataSource(queryset, fields=['year', 'sales'])
103+
chart = yui.AreaChart(data_source)
104+
</pre>
105+
</div>
106+
107+
<h2>Areaspline Chart</h2>
108+
<div id="area_spline_chart" class="well">
109+
{{ area_spline_chart.as_html }}
110+
<pre class="code">
111+
data_source = ModelDataSource(queryset, fields=['year', 'sales'])
112+
chart = yui.AreaSplineChart(data_source)
113+
</pre>
59114
</div>
60115

61116
{% endblock %}

demo_project/demo/views.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,19 @@ def get_context_data(self, **kwargs):
211211
class YUIDemo(Demo):
212212
template_name = 'demo/yui.html'
213213

214+
def get_context_data(self, **kwargs):
215+
context = super(YUIDemo, self).get_context_data(**kwargs)
216+
queryset = Account.objects.all()
217+
data_source = ModelDataSource(queryset,
218+
fields=['year', 'sales'])
219+
area_chart = self.renderer.AreaChart(data_source)
220+
area_spline_chart = self.renderer.AreaSplineChart(data_source)
221+
spline_chart = self.renderer.SplineChart(SimpleDataSource(data=data))
222+
context.update({'area_chart': area_chart,
223+
'area_spline_chart': area_spline_chart,
224+
'spline_chart': spline_chart})
225+
return context
226+
214227
yui_demo = YUIDemo.as_view(renderer=yui)
215228

216229

graphos/renderers/yui.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,53 @@ class LineChart(BaseYuiChart):
2222
def get_js_template(self):
2323
return "graphos/yui/line_chart.html"
2424

25+
def get_chart_type(self):
26+
return "line"
27+
28+
29+
class SplineChart(BaseYuiChart):
30+
def get_js_template(self):
31+
return "graphos/yui/spline_chart.html"
32+
33+
def get_chart_type(self):
34+
return "spline"
35+
2536

2637
class BarChart(BaseYuiChart):
2738
def get_js_template(self):
2839
return "graphos/yui/bar_chart.html"
2940

41+
def get_chart_type(self):
42+
return "bar"
43+
3044

3145
class ColumnChart(BaseYuiChart):
3246
def get_js_template(self):
3347
return "graphos/yui/column_chart.html"
3448

49+
def get_chart_type(self):
50+
return "column"
51+
3552

3653
class PieChart(BaseYuiChart):
3754
def get_js_template(self):
3855
return "graphos/yui/pie_chart.html"
56+
57+
def get_chart_type(self):
58+
return "pie"
59+
60+
61+
class AreaChart(BaseYuiChart):
62+
def get_js_template(self):
63+
return "graphos/yui/area_chart.html"
64+
65+
def get_chart_type(self):
66+
return "area"
67+
68+
69+
class AreaSplineChart(BaseYuiChart):
70+
def get_js_template(self):
71+
return "graphos/yui/area_spline_chart.html"
72+
73+
def get_chart_type(self):
74+
return "areaspline"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{% extends "graphos/yui/base.html" %}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{% extends "graphos/yui/base.html" %}
Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1 @@
1-
{% extends "graphos/yui/base.html" %}
2-
3-
{% block yui_chart_type %}
4-
// Instantiate and render the chart
5-
var mychart = new Y.Chart({
6-
dataProvider: datasets,
7-
render: "#{{ chart.html_id }}",
8-
type: "bar",
9-
categoryKey:"{{ chart.get_category_key }}"
10-
});
11-
{% endblock %}
1+
{% extends "graphos/yui/base.html" %}

graphos/templates/graphos/yui/base.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
var mychart = new Y.Chart({
99
dataProvider: datasets,
1010
render: "#{{ chart.get_html_id }}",
11-
type: "line",
11+
type: "{{chart.get_chart_type}}",
1212
categoryKey:"{{ chart.get_category_key }}",
1313
styles: {{ chart.get_options_json|safe }}
1414
});
Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1 @@
1-
{% extends "graphos/yui/base.html" %}
2-
3-
{% block yui_chart_type %}
4-
// Instantiate and render the chart
5-
var mychart = new Y.Chart({
6-
dataProvider: datasets,
7-
render: "#{{ chart.html_id }}",
8-
type: "column",
9-
categoryKey:"{{ chart.get_category_key }}"
10-
});
11-
{% endblock %}
1+
{% extends "graphos/yui/base.html" %}
Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1 @@
1-
{% extends "graphos/yui/base.html" %}
2-
3-
{% block yui_chart_type %}
4-
// Instantiate and render the chart
5-
var mychart = new Y.Chart({
6-
dataProvider: datasets,
7-
render: "#{{ chart.html_id }}",
8-
type: "pie",
9-
categoryKey:"{{ chart.get_category_key }}"
10-
});
11-
{% endblock %}
1+
{% extends "graphos/yui/base.html" %}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{% extends "graphos/yui/base.html" %}

0 commit comments

Comments
 (0)