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 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
- data = $(container).data()['chart']
16
- graph = new Rickshaw.Graph(
17
- element: $(container)[0]
18
- width: 580
19
- height: 250
20
- renderer: 'line'
21
- series: [{ color: 'steelblue', data: data }]
22
- )
23
- y_axis = new Rickshaw.Graph.Axis.Y(
24
- graph: graph
25
- orientation: 'left'
26
- tickFormat: Rickshaw.Fixtures.Number.formatKMBT
27
- element: document.getElementById('y-axis')
28
- )
29
- graph.render()
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()
@@ -0,0 +1,14 @@
1
+ .line-graph-container {
2
+ position: relative;
3
+ font-family: Arial, Helvetica, sans-serif;
4
+ }
5
+ .line-graph {
6
+ position: relative;
7
+ margin-left: 40px;
8
+ }
9
+ .y-axis {
10
+ position: absolute;
11
+ top: 0;
12
+ bottom: 0;
13
+ width: 40px;
14
+ }
@@ -15,9 +15,9 @@ class PieChartBuilder
15
15
  # If no init data, draws from dummy data.
16
16
  appendChart: (container) ->
17
17
 
18
- w = 300
19
- h = 300
20
- r = 150
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 * 1000,
21
+ x: event[:time].to_i,
22
22
  y: event[:data]
23
23
  }
24
24
  end
@@ -1,3 +1,3 @@
1
1
  module QuackyCharts
2
- VERSION = "0.0.8"
2
+ VERSION = "0.0.9"
3
3
  end
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.8
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-28 00:00:00.000000000 Z
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