quacky-charts 0.0.5 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +3 -8
- data/lib/generators/quacky/install_generator.rb +1 -1
- data/lib/generators/quacky/templates/pie_charts.js.coffee +36 -0
- data/lib/quacky/pie_chart_builder.rb +3 -1
- data/lib/quacky/version.rb +1 -1
- data/lib/quacky-charts.rb +1 -7
- data/quacky-charts.gemspec +3 -0
- data/spec/cases/pie_chart_builder_spec.rb +20 -0
- data/spec/spec_helper.rb +12 -0
- metadata +41 -5
- data/lib/generators/quacky/templates/pie_charts.js +0 -47
data/README.md
CHANGED
@@ -18,16 +18,11 @@ Run this command to install the needed JS files:
|
|
18
18
|
|
19
19
|
## Usage
|
20
20
|
|
21
|
-
Add
|
21
|
+
Add this line to the controller:
|
22
22
|
|
23
|
-
|
24
|
-
//= require pie_charts.js
|
23
|
+
@chart = Quacky::PieChartBuilder.new
|
25
24
|
|
26
|
-
and
|
27
|
-
|
28
|
-
@chart = QuackyC::PieChartBuilder.new
|
29
|
-
|
30
|
-
and finally, in the view:
|
25
|
+
and in the view:
|
31
26
|
|
32
27
|
<%= @chart.draw %>
|
33
28
|
|
@@ -8,7 +8,7 @@ module Quacky
|
|
8
8
|
desc "This gesnerator installs JS files needed for D3 pie charts"
|
9
9
|
|
10
10
|
def write_js_files
|
11
|
-
copy_file "pie_charts.js", "app/assets/javascripts/pie_charts.js"
|
11
|
+
copy_file "pie_charts.js.coffee", "app/assets/javascripts/pie_charts.js.coffee"
|
12
12
|
copy_file "d3.v2.min.js", "app/assets/javascripts/d3.v2.min.js"
|
13
13
|
end
|
14
14
|
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# based on the example at https://github.com/mbostock/d3/blob/master/examples/donut/donut.html
|
2
|
+
$(document).ready( ->
|
3
|
+
builder = new PieChartBuilder
|
4
|
+
builder.drawCharts()
|
5
|
+
)
|
6
|
+
|
7
|
+
class PieChartBuilder
|
8
|
+
|
9
|
+
drawCharts: ->
|
10
|
+
w = 300
|
11
|
+
h = 300
|
12
|
+
r = 100
|
13
|
+
color = d3.scale.category20c()
|
14
|
+
|
15
|
+
data = [{"label":"one", "value":20},
|
16
|
+
{"label":"two", "value":50},
|
17
|
+
{"label":"three", "value":30}]
|
18
|
+
|
19
|
+
vis = d3.select(".pie-chart").append("svg:svg").data([data]).attr("width", w).attr("height", h).append("svg:g").attr("transform", "translate(" + r + "," + r + ")")
|
20
|
+
arc = d3.svg.arc().outerRadius(r)
|
21
|
+
|
22
|
+
pie = d3.layout.pie().value( (d) ->
|
23
|
+
return d.value
|
24
|
+
)
|
25
|
+
arcs = vis.selectAll("g.slice").data(pie).enter().append("svg:g").attr("class", "slice")
|
26
|
+
arcs.append("svg:path").attr("fill", (d, i) ->
|
27
|
+
return color(i)
|
28
|
+
).attr("d", arc)
|
29
|
+
|
30
|
+
arcs.append("svg:text").attr("transform", (d) ->
|
31
|
+
d.innerRadius = 0
|
32
|
+
d.outerRadius = r
|
33
|
+
return "translate(" + arc.centroid(d) + ")"
|
34
|
+
).attr("text-anchor", "middle").text( (d, i) ->
|
35
|
+
return data[i].label
|
36
|
+
)
|
data/lib/quacky/version.rb
CHANGED
data/lib/quacky-charts.rb
CHANGED
@@ -1,13 +1,7 @@
|
|
1
1
|
require "quacky/version"
|
2
2
|
require "quacky/pie_chart_builder"
|
3
3
|
|
4
|
-
include ActionView::Helpers::TagHelper
|
4
|
+
#include ActionView::Helpers::TagHelper
|
5
5
|
|
6
6
|
module Quacky
|
7
|
-
|
8
|
-
# return a content tag that can be selected by the client-side, and drawn on
|
9
|
-
def draw
|
10
|
-
content_tag(:div, nil, :class => 'pie-chart')
|
11
|
-
end
|
12
|
-
|
13
7
|
end
|
data/quacky-charts.gemspec
CHANGED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Quacky::PieChartBuilder" do
|
4
|
+
|
5
|
+
it "can be initialized" do
|
6
|
+
chart = Quacky::PieChartBuilder.new
|
7
|
+
chart.should be_true
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should be the correct type" do
|
11
|
+
chart = Quacky::PieChartBuilder.new
|
12
|
+
chart.class.should eq(Quacky::PieChartBuilder)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should be able to draw and raise error" do
|
16
|
+
chart = Quacky::PieChartBuilder.new
|
17
|
+
lambda {chart.draw}.should raise_error
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
data/spec/spec_helper.rb
ADDED
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.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,8 +9,40 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-10-
|
13
|
-
dependencies:
|
12
|
+
date: 2012-10-24 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: coffee-rails
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 3.2.1
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 3.2.1
|
14
46
|
description: A Rails Charting Gem
|
15
47
|
email:
|
16
48
|
- travissheppard.1988@gmail.com
|
@@ -25,11 +57,13 @@ files:
|
|
25
57
|
- Rakefile
|
26
58
|
- lib/generators/quacky/install_generator.rb
|
27
59
|
- lib/generators/quacky/templates/d3.v2.min.js
|
28
|
-
- lib/generators/quacky/templates/pie_charts.js
|
60
|
+
- lib/generators/quacky/templates/pie_charts.js.coffee
|
29
61
|
- lib/quacky-charts.rb
|
30
62
|
- lib/quacky/pie_chart_builder.rb
|
31
63
|
- lib/quacky/version.rb
|
32
64
|
- quacky-charts.gemspec
|
65
|
+
- spec/cases/pie_chart_builder_spec.rb
|
66
|
+
- spec/spec_helper.rb
|
33
67
|
homepage: ''
|
34
68
|
licenses: []
|
35
69
|
post_install_message:
|
@@ -54,4 +88,6 @@ rubygems_version: 1.8.23
|
|
54
88
|
signing_key:
|
55
89
|
specification_version: 3
|
56
90
|
summary: Configure Charts in Ruby; QuackyCharts builds them with JS tools.
|
57
|
-
test_files:
|
91
|
+
test_files:
|
92
|
+
- spec/cases/pie_chart_builder_spec.rb
|
93
|
+
- spec/spec_helper.rb
|
@@ -1,47 +0,0 @@
|
|
1
|
-
// based on the example at https://github.com/mbostock/d3/blob/master/examples/donut/donut.html
|
2
|
-
$(document).ready(function() {
|
3
|
-
// the number of slices
|
4
|
-
var slices = 5;
|
5
|
-
|
6
|
-
var width = 400,
|
7
|
-
height = 400,
|
8
|
-
outerRadius = Math.min(width, height) / 2,
|
9
|
-
innerRadius = 0,
|
10
|
-
n = slices,
|
11
|
-
q = 0,
|
12
|
-
data0 = d3.range(n).map(Math.random),
|
13
|
-
data1 = d3.range(n).map(Math.random),
|
14
|
-
data,
|
15
|
-
color = d3.scale.category20(),
|
16
|
-
arc = d3.svg.arc(),
|
17
|
-
donut = d3.layout.pie().sort(null);
|
18
|
-
|
19
|
-
var vis = d3.select(".pie-chart")
|
20
|
-
.append("svg")
|
21
|
-
.attr("width", width)
|
22
|
-
.attr("height", height);
|
23
|
-
|
24
|
-
vis.selectAll("g.arc")
|
25
|
-
.data(arcs(data0, data1))
|
26
|
-
.enter().append("g")
|
27
|
-
.attr("class", "arc")
|
28
|
-
.attr("transform", "translate(" + outerRadius + "," + outerRadius + ")")
|
29
|
-
.append("path")
|
30
|
-
.attr("fill", function(d, i) { return color(i); })
|
31
|
-
.attr("d", arc);
|
32
|
-
|
33
|
-
|
34
|
-
function arcs(data0, data1) {
|
35
|
-
var arcs0 = donut(data0),
|
36
|
-
arcs1 = donut(data1),
|
37
|
-
i = -1,
|
38
|
-
arc;
|
39
|
-
while (++i < n) {
|
40
|
-
arc = arcs0[i];
|
41
|
-
arc.innerRadius = innerRadius;
|
42
|
-
arc.outerRadius = outerRadius;
|
43
|
-
arc.next = arcs1[i];
|
44
|
-
}
|
45
|
-
return arcs0;
|
46
|
-
}
|
47
|
-
});
|