d3_charts 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +22 -0
- data/.travis.yml +12 -0
- data/Gemfile +5 -0
- data/Guardfile +8 -0
- data/LICENSE.txt +21 -0
- data/README.md +73 -0
- data/Rakefile +9 -0
- data/d3_charts.gemspec +29 -0
- data/lib/assets/javascripts/charts/area_chart.js.coffee +103 -0
- data/lib/assets/javascripts/charts/pie_chart.js.coffee +68 -0
- data/lib/assets/javascripts/d3_charts.js +2 -0
- data/lib/assets/stylesheets/d3_charts.css.scss +15 -0
- data/lib/d3_charts.rb +8 -0
- data/lib/d3_charts/chart.rb +30 -0
- data/lib/d3_charts/chart/area.rb +18 -0
- data/lib/d3_charts/chart/pie.rb +11 -0
- data/lib/d3_charts/engine.rb +8 -0
- data/lib/d3_charts/railtie.rb +9 -0
- data/lib/d3_charts/version.rb +5 -0
- data/lib/d3_charts/view_helpers.rb +29 -0
- data/test/d3_charts/view_helpers_test.rb +44 -0
- data/test/test_helper.rb +8 -0
- metadata +166 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 986ef08364eb025e3a50c7b33df2f68c813b6f8f
|
4
|
+
data.tar.gz: c8f4ab0880928e253c2d0ee5595b952c76d3a406
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a21b4a77fed16e6ad4a9aa05c8a8ee24f431d47d8db7045e731b464543c2759b43019c1ef8ae8a4aecfab09e8940030efcbe6d094ccddfd5c59d166637284487
|
7
|
+
data.tar.gz: 990b44cd4b1129764e0b9d6c1bd1bb250b76b683c77d842a608e1947720c0af02399dda410f21bc7d6034873adf9b56797acdae5d5466197f7526741a80b20ba
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Guardfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2014 Tomas Celizna
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
# d3_charts
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/tomasc/d3_charts.svg)](https://travis-ci.org/tomasc/d3_charts) [![Gem Version](https://badge.fury.io/rb/d3_charts.svg)](http://badge.fury.io/rb/d3_charts) [![Coverage Status](https://img.shields.io/coveralls/tomasc/d3_charts.svg)](https://coveralls.io/r/tomasc/d3_charts)
|
4
|
+
|
5
|
+
Rails helpers for building SVG charts using the d3 library.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'd3_charts'
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install d3_charts
|
20
|
+
|
21
|
+
To make it work you need to require the javascripts in `application.js`:
|
22
|
+
|
23
|
+
//= require d3_charts
|
24
|
+
|
25
|
+
To add some basic colouring of pie charts, add the the following in `application.css`:
|
26
|
+
|
27
|
+
*= require 'd3_charts'
|
28
|
+
|
29
|
+
## Usage
|
30
|
+
|
31
|
+
### Pie charts
|
32
|
+
|
33
|
+
= pie_chart(data, options)
|
34
|
+
|
35
|
+
Available `options` are:
|
36
|
+
|
37
|
+
* `width`, defaults to 1000
|
38
|
+
* `height`, defaults to 1000
|
39
|
+
|
40
|
+
Which are passed in like so:
|
41
|
+
|
42
|
+
= pie_chart(data, { width: 123, height: 123 })
|
43
|
+
|
44
|
+
### Area charts
|
45
|
+
|
46
|
+
= area_chart(data, options)
|
47
|
+
|
48
|
+
Available `options` are:
|
49
|
+
|
50
|
+
* `width`, defaults to 1000
|
51
|
+
* `height`, defaults to 1000
|
52
|
+
* `margin`, defaults to 25
|
53
|
+
* `format`, the strftime format of the dates, defaults to `%d/%m/%y`
|
54
|
+
|
55
|
+
Which are passed in like so:
|
56
|
+
|
57
|
+
= area_chart(data, { width: 123, height: 123, margin: 25 })
|
58
|
+
|
59
|
+
## TODO:
|
60
|
+
|
61
|
+
* Add more charts:
|
62
|
+
* Line Chart
|
63
|
+
* Histogram Chart
|
64
|
+
* Vertical Bar Chart
|
65
|
+
* Horizontal Bar Chart
|
66
|
+
|
67
|
+
## Contributing
|
68
|
+
|
69
|
+
1. Fork it ( https://github.com/tomasc/d3_charts/fork )
|
70
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
71
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
72
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
73
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/d3_charts.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'd3_charts/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "d3_charts"
|
8
|
+
spec.version = D3::Charts::VERSION
|
9
|
+
spec.authors = ["Tomas Celizna"]
|
10
|
+
spec.email = ["tomas.celizna@gmail.com"]
|
11
|
+
spec.summary = %q{Rails helpers for building SVG charts using the d3 library.}
|
12
|
+
spec.description = %q{}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "rails", ">= 4.1.0"
|
22
|
+
spec.add_dependency "rails-assets-d3", "~> 3.4.11"
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
25
|
+
spec.add_development_dependency "guard"
|
26
|
+
spec.add_development_dependency "guard-minitest"
|
27
|
+
spec.add_development_dependency "minitest"
|
28
|
+
spec.add_development_dependency "rake"
|
29
|
+
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
# https://github.com/zenorocha/jquery-boilerplate
|
2
|
+
(($, window) ->
|
3
|
+
|
4
|
+
# ---------------------------------------------------------------------
|
5
|
+
|
6
|
+
pluginName = 'chart_area'
|
7
|
+
document = window.document
|
8
|
+
|
9
|
+
defaults =
|
10
|
+
debug: false
|
11
|
+
width: 1000
|
12
|
+
height: 1000
|
13
|
+
margin: 40
|
14
|
+
ticks: 'days'
|
15
|
+
format: "%d/%m/%y"
|
16
|
+
|
17
|
+
# ---------------------------------------------------------------------
|
18
|
+
|
19
|
+
class Plugin
|
20
|
+
|
21
|
+
constructor: (@element, options) ->
|
22
|
+
@options = $.extend {}, defaults, options
|
23
|
+
|
24
|
+
@$element = $(@element)
|
25
|
+
|
26
|
+
@_defaults = defaults
|
27
|
+
@_name = pluginName
|
28
|
+
|
29
|
+
@init()
|
30
|
+
|
31
|
+
init: ->
|
32
|
+
@render()
|
33
|
+
|
34
|
+
# ---------------------------------------------------------------------
|
35
|
+
|
36
|
+
get_data: -> @$element.data 'chart-data'
|
37
|
+
get_width: -> @$element.data('width') || @options.width
|
38
|
+
get_height: -> @$element.data('height') || @options.height
|
39
|
+
get_margin: -> @$element.data('margin') || @options.margin
|
40
|
+
get_format: -> @$element.data('format') || @options.format
|
41
|
+
get_ticks: ->
|
42
|
+
format = @$element.data('format') || @options.format
|
43
|
+
if /%d|%e/.test(format)
|
44
|
+
d3.time.days
|
45
|
+
else if /%m|%B|%b|%h/.test(format)
|
46
|
+
d3.time.months
|
47
|
+
alert format
|
48
|
+
else if /%y|%Y/.test(format)
|
49
|
+
d3.time.years
|
50
|
+
|
51
|
+
# ---------------------------------------------------------------------
|
52
|
+
|
53
|
+
render: ->
|
54
|
+
data = @get_data()
|
55
|
+
|
56
|
+
console.log data
|
57
|
+
|
58
|
+
width = @get_width() - @get_margin()*2
|
59
|
+
height = @get_height() - @get_margin()*2
|
60
|
+
parseDate = d3.time.format(@get_format()).parse
|
61
|
+
|
62
|
+
x = d3.time.scale().range([0, width])
|
63
|
+
y = d3.scale.linear().range([height, 0])
|
64
|
+
|
65
|
+
xAxis = d3.svg.axis().scale(x).orient("bottom").ticks(@get_ticks(), 1).tickSize(0).tickPadding(5).tickFormat(d3.time.format(@get_format()))
|
66
|
+
yAxis = d3.svg.axis().scale(y).orient("left").ticks(2).tickSize(0).tickPadding(5)
|
67
|
+
|
68
|
+
area = d3.svg.area().interpolate("basis").x((d) -> x d.label).y0(height).y1((d) -> y d.value)
|
69
|
+
svg = d3.select(@$element[0]).append("svg").attr("width", @get_width()).attr("height", @get_height()).attr("viewBox", "0 0 #{@get_height()} #{@get_width()}").attr("xmlns", "http://www.w3.org/2000/svg").append("g").attr("transform", "translate(#{@get_margin()},#{@get_margin()})")
|
70
|
+
|
71
|
+
data.forEach (d) ->
|
72
|
+
d.label = parseDate(d.label)
|
73
|
+
d.value = +d.value
|
74
|
+
|
75
|
+
x.domain d3.extent(data, (d) -> d.label)
|
76
|
+
y.domain [0, d3.max(data, (d) -> d.value)]
|
77
|
+
|
78
|
+
svg.append("path").datum(data).attr("class", "area").attr("d", area)
|
79
|
+
|
80
|
+
svg.append("g").attr("class", "x axis").attr("transform", "translate(0,#{height})").call(xAxis)
|
81
|
+
svg.append("g").attr("class", "y axis").call(yAxis)
|
82
|
+
|
83
|
+
# ---------------------------------------------------------------------
|
84
|
+
|
85
|
+
# prevents multiple instantiation on same DOM element
|
86
|
+
$.fn[pluginName] = (options) ->
|
87
|
+
@each ->
|
88
|
+
if !$.data(this, "plugin_#{pluginName}")
|
89
|
+
$.data(@, "plugin_#{pluginName}", new Plugin(@, options))
|
90
|
+
|
91
|
+
# ---------------------------------------------------------------------
|
92
|
+
|
93
|
+
)(jQuery, window)
|
94
|
+
|
95
|
+
# =====================================================================
|
96
|
+
|
97
|
+
$ ->
|
98
|
+
|
99
|
+
$('.chart.container.area').chart_area()
|
100
|
+
|
101
|
+
# make sure the plugin is correctly rebound to new elements
|
102
|
+
$('body').on 'dom_update', (e) ->
|
103
|
+
$('.chart.container.area').chart_area()
|
@@ -0,0 +1,68 @@
|
|
1
|
+
# https://github.com/zenorocha/jquery-boilerplate
|
2
|
+
(($, window) ->
|
3
|
+
|
4
|
+
# ---------------------------------------------------------------------
|
5
|
+
|
6
|
+
pluginName = 'chart_pie'
|
7
|
+
document = window.document
|
8
|
+
|
9
|
+
defaults =
|
10
|
+
debug: false
|
11
|
+
width: 1000
|
12
|
+
height: 1000
|
13
|
+
|
14
|
+
# ---------------------------------------------------------------------
|
15
|
+
|
16
|
+
class Plugin
|
17
|
+
|
18
|
+
constructor: (@element, options) ->
|
19
|
+
@options = $.extend {}, defaults, options
|
20
|
+
|
21
|
+
@$element = $(@element)
|
22
|
+
|
23
|
+
@_defaults = defaults
|
24
|
+
@_name = pluginName
|
25
|
+
|
26
|
+
@init()
|
27
|
+
|
28
|
+
init: -> @render()
|
29
|
+
|
30
|
+
# ---------------------------------------------------------------------
|
31
|
+
|
32
|
+
get_data: -> @$element.data 'chart-data'
|
33
|
+
get_radius: -> Math.min(@get_width(), @get_height()) / 2
|
34
|
+
get_width: -> @$element.data('width') || @options.width
|
35
|
+
get_height: -> @$element.data('height') || @options.height
|
36
|
+
|
37
|
+
# ---------------------------------------------------------------------
|
38
|
+
|
39
|
+
render: ->
|
40
|
+
data = @get_data()
|
41
|
+
arc = d3.svg.arc().outerRadius(@get_radius()).innerRadius(0)
|
42
|
+
pie = d3.layout.pie().sort(null).value (d) -> d.value
|
43
|
+
svg = d3.select(@$element[0]).append("svg").attr("width", @get_width()).attr("height", @get_height()).attr("viewBox", "0 0 #{@get_height()} #{@get_width()}").attr("xmlns", "http://www.w3.org/2000/svg").append("g").attr("transform", "translate(#{@get_width()/2},#{@get_height()/2})")
|
44
|
+
|
45
|
+
g = svg.selectAll(".arc").data(pie(data)).enter().append("g").attr("class", "arc")
|
46
|
+
g.append("path").attr("d", arc).attr("class", (d) => "color_#{@get_data().indexOf(d.data)}").attr("title", (d) -> d.data.label)
|
47
|
+
|
48
|
+
# ---------------------------------------------------------------------
|
49
|
+
|
50
|
+
# prevents multiple instantiation on same DOM element
|
51
|
+
$.fn[pluginName] = (options) ->
|
52
|
+
@each ->
|
53
|
+
if !$.data(this, "plugin_#{pluginName}")
|
54
|
+
$.data(@, "plugin_#{pluginName}", new Plugin(@, options))
|
55
|
+
|
56
|
+
# ---------------------------------------------------------------------
|
57
|
+
|
58
|
+
)(jQuery, window)
|
59
|
+
|
60
|
+
# =====================================================================
|
61
|
+
|
62
|
+
$ ->
|
63
|
+
|
64
|
+
$('.chart.container.pie').chart_pie()
|
65
|
+
|
66
|
+
# make sure the plugin is correctly rebound to new elements
|
67
|
+
$('body').on 'dom_update', (e) ->
|
68
|
+
$('.chart.container.pie').chart_pie()
|
@@ -0,0 +1,15 @@
|
|
1
|
+
$colors: (aliceblue, antiquewhite, aqua, aquamarine, azure, beige, bisque, black, blanchedalmond, blue, blueviolet, brown, burlywood, cadetblue, chartreuse, chocolate, coral, cornflowerblue, cornsilk, crimson, cyan, darkblue, darkcyan, darkgoldenrod, darkgray, darkgreen, darkkhaki, darkmagenta, darkolivegreen, darkorange, darkorchid, darkred, darksalmon, darkseagreen, darkslateblue, darkslategray, darkturquoise, darkviolet, deeppink, deepskyblue, dimgray, dodgerblue, firebrick, floralwhite, forestgreen, fuchsia, gainsboro, ghostwhite, gold, goldenrod, gray, green, greenyellow, honeydew, hotpink, indianred, indigo, ivory, khaki, lavender, lavenderblush, lawngreen, lemonchiffon, lightblue, lightcoral, lightcyan, lightgoldenrodyellow, lightgray, lightgreen, lightpink, lightsalmon, lightseagreen, lightskyblue, lightslategray, lightsteelblue, lightyellow, lime, limegreen, linen, magenta, maroon, mediumaquamarine, mediumblue, mediumorchid, mediumpurple, mediumseagreen, mediumslateblue, mediumspringgreen, mediumturquoise, mediumvioletred, midnightblue, mintcream, mistyrose, moccasin, navajowhite, navy, oldlace, olive, olivedrab, orange, orangered, orchid, palegoldenrod, palegreen, paleturquoise, palevioletred, papayawhip, peachpuff, peru, pink, plum, powderblue, purple, red, rosybrown, royalblue, saddlebrown, salmon, sandybrown, seagreen, seashell, sienna, silver, skyblue, slateblue, slategray, snow, springgreen, steelblue, tan, teal, thistle, tomato, turquoise, violet, wheat, white, whitesmoke, yellow, yellowgreen);
|
2
|
+
|
3
|
+
@for $i from 1 through 140 {
|
4
|
+
.chart .color_#{($i - 1)} {
|
5
|
+
fill: nth($colors, $i);
|
6
|
+
}
|
7
|
+
}
|
8
|
+
|
9
|
+
// --------------------------------------------------------------------
|
10
|
+
|
11
|
+
.chart.container.area {
|
12
|
+
svg {
|
13
|
+
// padding: 25px;
|
14
|
+
}
|
15
|
+
}
|
data/lib/d3_charts.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
module D3Charts
|
2
|
+
class Chart
|
3
|
+
|
4
|
+
include ActionView::Helpers::TagHelper
|
5
|
+
|
6
|
+
# ---------------------------------------------------------------------
|
7
|
+
|
8
|
+
def initialize chart_data, options={}
|
9
|
+
@chart_data = chart_data
|
10
|
+
@options = options
|
11
|
+
end
|
12
|
+
|
13
|
+
def dom_class
|
14
|
+
%w(chart container)
|
15
|
+
end
|
16
|
+
|
17
|
+
def dom_data
|
18
|
+
res = {}
|
19
|
+
res[:chart_data] = @chart_data.to_json
|
20
|
+
res[:width] = @options[:width] if @options[:width]
|
21
|
+
res[:height] = @options[:height] if @options[:height]
|
22
|
+
res
|
23
|
+
end
|
24
|
+
|
25
|
+
def tag
|
26
|
+
content_tag(:div, nil, { class: dom_class, data: dom_data })
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module D3Charts
|
2
|
+
class Chart
|
3
|
+
class Area < Chart
|
4
|
+
|
5
|
+
def dom_class
|
6
|
+
super + %w(area)
|
7
|
+
end
|
8
|
+
|
9
|
+
def dom_data
|
10
|
+
res = {}
|
11
|
+
res[:margin] = @options[:margin] if @options[:margin]
|
12
|
+
res[:format] = @options[:format] if @options[:format]
|
13
|
+
super.merge(res)
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'action_view'
|
2
|
+
|
3
|
+
require_relative 'chart'
|
4
|
+
|
5
|
+
module D3Charts
|
6
|
+
module ViewHelpers
|
7
|
+
|
8
|
+
def self.included klass
|
9
|
+
klass.class_eval do
|
10
|
+
include ActionView::Context
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
# ---------------------------------------------------------------------
|
15
|
+
|
16
|
+
def pie_chart chart_data, options={}
|
17
|
+
Chart::Pie.new(chart_data, options).tag.html_safe
|
18
|
+
end
|
19
|
+
|
20
|
+
# ---------------------------------------------------------------------
|
21
|
+
|
22
|
+
def area_chart chart_data, options={}
|
23
|
+
Chart::Area.new(chart_data, options).tag.html_safe
|
24
|
+
end
|
25
|
+
|
26
|
+
# ---------------------------------------------------------------------
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'd3_charts/view_helpers'
|
2
|
+
require 'test_helper'
|
3
|
+
|
4
|
+
module D3Charts
|
5
|
+
describe ViewHelpers do
|
6
|
+
|
7
|
+
include ViewHelpers
|
8
|
+
include ActionView::Helpers
|
9
|
+
include ActionView::Helpers::TagHelper
|
10
|
+
|
11
|
+
# =====================================================================
|
12
|
+
|
13
|
+
describe '#pie_chart' do
|
14
|
+
let(:data) { [{ value: 125, label: 'foo' }, { value: 325, label: 'bar' }] }
|
15
|
+
|
16
|
+
it 'wraps the chart in a div' do
|
17
|
+
pie_chart(data).must_match Regexp.new("<div.*?></div>")
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'returns the correct data' do
|
21
|
+
skip
|
22
|
+
pie_chart(data).must_include "data-chart-data=\"#{data}\">"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
# ---------------------------------------------------------------------
|
27
|
+
|
28
|
+
describe '#area_chart' do
|
29
|
+
let(:data) { [{ date: '2014-08-02', value: 100 }, { date: '2014-09-02', value: 200 }] }
|
30
|
+
|
31
|
+
it 'wraps the chart in a div' do
|
32
|
+
area_chart(data).must_match Regexp.new("<div.*?></div>")
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'returns the correct data' do
|
36
|
+
skip
|
37
|
+
area_chart(data).must_include "data-chart-data=\"#{data}\">"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
# ---------------------------------------------------------------------
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,166 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: d3_charts
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tomas Celizna
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-09-02 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 4.1.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 4.1.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rails-assets-d3
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 3.4.11
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 3.4.11
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.6'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.6'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: guard
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: guard-minitest
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: minitest
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rake
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
description: ''
|
112
|
+
email:
|
113
|
+
- tomas.celizna@gmail.com
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- ".gitignore"
|
119
|
+
- ".travis.yml"
|
120
|
+
- Gemfile
|
121
|
+
- Guardfile
|
122
|
+
- LICENSE.txt
|
123
|
+
- README.md
|
124
|
+
- Rakefile
|
125
|
+
- d3_charts.gemspec
|
126
|
+
- lib/assets/javascripts/charts/area_chart.js.coffee
|
127
|
+
- lib/assets/javascripts/charts/pie_chart.js.coffee
|
128
|
+
- lib/assets/javascripts/d3_charts.js
|
129
|
+
- lib/assets/stylesheets/d3_charts.css.scss
|
130
|
+
- lib/d3_charts.rb
|
131
|
+
- lib/d3_charts/chart.rb
|
132
|
+
- lib/d3_charts/chart/area.rb
|
133
|
+
- lib/d3_charts/chart/pie.rb
|
134
|
+
- lib/d3_charts/engine.rb
|
135
|
+
- lib/d3_charts/railtie.rb
|
136
|
+
- lib/d3_charts/version.rb
|
137
|
+
- lib/d3_charts/view_helpers.rb
|
138
|
+
- test/d3_charts/view_helpers_test.rb
|
139
|
+
- test/test_helper.rb
|
140
|
+
homepage: ''
|
141
|
+
licenses:
|
142
|
+
- MIT
|
143
|
+
metadata: {}
|
144
|
+
post_install_message:
|
145
|
+
rdoc_options: []
|
146
|
+
require_paths:
|
147
|
+
- lib
|
148
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
154
|
+
requirements:
|
155
|
+
- - ">="
|
156
|
+
- !ruby/object:Gem::Version
|
157
|
+
version: '0'
|
158
|
+
requirements: []
|
159
|
+
rubyforge_project:
|
160
|
+
rubygems_version: 2.2.2
|
161
|
+
signing_key:
|
162
|
+
specification_version: 4
|
163
|
+
summary: Rails helpers for building SVG charts using the d3 library.
|
164
|
+
test_files:
|
165
|
+
- test/d3_charts/view_helpers_test.rb
|
166
|
+
- test/test_helper.rb
|