quacky-charts 0.0.8 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +9 -0
- data/lib/generators/quacky/install_generator.rb +1 -0
- data/lib/generators/quacky/templates/line_graph_builder.js.coffee +17 -15
- data/lib/generators/quacky/templates/line_graphs.css +14 -0
- data/lib/generators/quacky/templates/pie_chart_builder.js.coffee +3 -3
- data/lib/quacky/line_graph_builder.rb +2 -2
- data/lib/quacky/version.rb +1 -1
- metadata +3 -2
data/README.md
CHANGED
@@ -31,6 +31,15 @@ and in the view:
|
|
31
31
|
|
32
32
|
<%= @chart.draw %>
|
33
33
|
|
34
|
+
To draw a line graph:
|
35
|
+
|
36
|
+
example_data = [{ time: Time.now, data: 50 },{ time: Time.now + 1.hour, data: 75 },{ time: Time.now + 2.hours, data: 25 }]
|
37
|
+
@line_graph = Quacky::LineGraphBuilder.new(example_data)
|
38
|
+
|
39
|
+
and in the view:
|
40
|
+
|
41
|
+
<%= @line_graph.draw %>
|
42
|
+
|
34
43
|
## Contributing
|
35
44
|
|
36
45
|
1. Fork it
|
@@ -16,6 +16,7 @@ module Quacky
|
|
16
16
|
copy_file 'd3.v2.min.js', 'app/assets/javascripts/d3.v2.min.js'
|
17
17
|
copy_file 'rickshaw.min.js', 'app/assets/javascripts/rickshaw.min.js'
|
18
18
|
copy_file 'rickshaw.min.css', 'app/assets/stylesheets/rickshaw.min.css'
|
19
|
+
copy_file 'line_graphs.css', 'app/assets/stylesheets/line_graphs.css'
|
19
20
|
end
|
20
21
|
|
21
22
|
end
|
@@ -12,18 +12,20 @@ class LineGraphBuilder
|
|
12
12
|
@appendGraph graph for graph in allGraphs
|
13
13
|
|
14
14
|
appendGraph: (container) ->
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
15
|
+
data = $(container).data()['chart']
|
16
|
+
graph = new Rickshaw.Graph(
|
17
|
+
element: $(container)[0]
|
18
|
+
renderer: 'line'
|
19
|
+
series: [{ color: 'steelblue', data: data }]
|
20
|
+
)
|
21
|
+
|
22
|
+
x_axis = new Rickshaw.Graph.Axis.Time( { graph: graph } )
|
23
|
+
|
24
|
+
y_axis = new Rickshaw.Graph.Axis.Y(
|
25
|
+
graph: graph
|
26
|
+
orientation: 'left'
|
27
|
+
tickFormat: Rickshaw.Fixtures.Number.formatKMBT
|
28
|
+
element: $('.y-axis')[0]
|
29
|
+
)
|
30
|
+
|
31
|
+
graph.render()
|
@@ -15,9 +15,9 @@ class PieChartBuilder
|
|
15
15
|
# If no init data, draws from dummy data.
|
16
16
|
appendChart: (container) ->
|
17
17
|
|
18
|
-
w =
|
19
|
-
h =
|
20
|
-
r =
|
18
|
+
w = $(container).width()
|
19
|
+
h = w
|
20
|
+
r = w / 2
|
21
21
|
color = d3.scale.category20c()
|
22
22
|
|
23
23
|
# If there is data in the container's data attribute, set it.
|
@@ -10,7 +10,7 @@ module Quacky
|
|
10
10
|
# Return a content tag that can be selected by the client-side, and drawn on.
|
11
11
|
# The data attribute of the HTML tag is @data.
|
12
12
|
def draw
|
13
|
-
"<div class='line-graph' data-chart='#{self.get_data}'></div>".html_safe
|
13
|
+
"<div class='line-graph-container'><div class='y-axis'></div><div class='line-graph' data-chart='#{self.get_data}'></div></div>".html_safe
|
14
14
|
end
|
15
15
|
|
16
16
|
def get_data
|
@@ -18,7 +18,7 @@ module Quacky
|
|
18
18
|
|
19
19
|
@data.each do |event|
|
20
20
|
output << {
|
21
|
-
x: event[:time].to_i
|
21
|
+
x: event[:time].to_i,
|
22
22
|
y: event[:data]
|
23
23
|
}
|
24
24
|
end
|
data/lib/quacky/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: quacky-charts
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-01-
|
12
|
+
date: 2013-01-31 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
@@ -90,6 +90,7 @@ files:
|
|
90
90
|
- lib/generators/quacky/install_generator.rb
|
91
91
|
- lib/generators/quacky/templates/d3.v2.min.js
|
92
92
|
- lib/generators/quacky/templates/line_graph_builder.js.coffee
|
93
|
+
- lib/generators/quacky/templates/line_graphs.css
|
93
94
|
- lib/generators/quacky/templates/pie_chart_builder.js.coffee
|
94
95
|
- lib/generators/quacky/templates/rickshaw.min.css
|
95
96
|
- lib/generators/quacky/templates/rickshaw.min.js
|