chartism 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +3 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +51 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/chartism.gemspec +25 -0
- data/lib/chartism/engine.rb +11 -0
- data/lib/chartism/helper.rb +25 -0
- data/lib/chartism/line/options.rb +32 -0
- data/lib/chartism/line.rb +68 -0
- data/lib/chartism/version.rb +3 -0
- data/lib/chartism.rb +6 -0
- data/vendor/assets/javascripts/chartist.js +3418 -0
- data/vendor/assets/stylesheets/chartist.min.css +1 -0
- metadata +104 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 536c7f984b360c963808c663c10ea669984bed85
|
4
|
+
data.tar.gz: cd3c6c3d271c11f66404bbb073b5673f70d314b3
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: afe5a49db3b51643a4e2b4329dc843f1218792c5c08e81d24a0400f958f3bae40801d5e21368fc178103ff653f29a703696f30fccb6c4fc0fa3bfab2a1d32b62
|
7
|
+
data.tar.gz: 3ef2573abacd27712b0fd1e3479784963f1369e57f6a4d8c808b4828af9d25f93960c66e5281a933f9a55efdec3e0afe55e11a62d669d5e0eee7002735af53be
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Tim Peters
|
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
|
13
|
+
all 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
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
# Chartism
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/chartism`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'chartism'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install chartism
|
22
|
+
|
23
|
+
Add to your `application.js`
|
24
|
+
|
25
|
+
```
|
26
|
+
//= require chartist
|
27
|
+
```
|
28
|
+
|
29
|
+
And add to your `application.css`
|
30
|
+
|
31
|
+
```
|
32
|
+
*= require chartist.min
|
33
|
+
```
|
34
|
+
|
35
|
+
## Usage
|
36
|
+
|
37
|
+
TODO: Write usage instructions here
|
38
|
+
|
39
|
+
## Development
|
40
|
+
|
41
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
|
42
|
+
|
43
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
44
|
+
|
45
|
+
## Contributing
|
46
|
+
|
47
|
+
1. Fork it ( https://github.com/[my-github-username]/chartism/fork )
|
48
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
49
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
50
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
51
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "chartism"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/chartism.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'chartism/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "chartism"
|
8
|
+
spec.version = Chartism::VERSION
|
9
|
+
spec.authors = ["Tim Peters"]
|
10
|
+
spec.email = ["mail@darksecond.nl"]
|
11
|
+
|
12
|
+
spec.summary = %q{A ruby chart library based on chartist.js}
|
13
|
+
spec.description = %q{A library to create beautiful charts using a clean DSL and chartist.js}
|
14
|
+
spec.homepage = "http://github.com/darksecond/chartism"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "docile", "~> 1.1"
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.8"
|
24
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'securerandom'
|
2
|
+
|
3
|
+
module Chartism
|
4
|
+
module Helper
|
5
|
+
# Options include:
|
6
|
+
# - class
|
7
|
+
def chart chartism, options={}
|
8
|
+
data_json = chartism.data.to_json
|
9
|
+
options_json = chartism.options.to_json
|
10
|
+
id = "chartism-line-#{SecureRandom.hex(6)}"
|
11
|
+
classes = ( ['ct-chart'] + Array(options[:class]) ).join(' ')
|
12
|
+
|
13
|
+
%Q[
|
14
|
+
<div class="#{classes}" id="#{id}"></div>
|
15
|
+
<script>
|
16
|
+
(function() {
|
17
|
+
var data = #{data_json};
|
18
|
+
var options = #{options_json};
|
19
|
+
new Chartist.Line("##{id}", data, options);
|
20
|
+
})();
|
21
|
+
</script>
|
22
|
+
].html_safe
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Chartism
|
2
|
+
module Line
|
3
|
+
class Options
|
4
|
+
def initialize
|
5
|
+
@options = {
|
6
|
+
showPoint: true,
|
7
|
+
lineSmooth: true,
|
8
|
+
showArea: false
|
9
|
+
}
|
10
|
+
end
|
11
|
+
|
12
|
+
def points value=nil, &block
|
13
|
+
@options[:showPoint] = value
|
14
|
+
@options[:showPoint] = instance_eval(&block) if block_given?
|
15
|
+
end
|
16
|
+
|
17
|
+
def smooth value=nil, &block
|
18
|
+
@options[:lineSmooth] = value unless value.nil?
|
19
|
+
@options[:lineSmooth] = instance_eval(&block) if block_given?
|
20
|
+
end
|
21
|
+
|
22
|
+
def area value=nil, &block
|
23
|
+
@options[:showArea] = value unless value.nil?
|
24
|
+
@options[:showArea] = instance_eval(&block) if block_given?
|
25
|
+
end
|
26
|
+
|
27
|
+
def options
|
28
|
+
@options
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'docile'
|
2
|
+
require 'chartism/line/options'
|
3
|
+
|
4
|
+
module Chartism
|
5
|
+
module Line
|
6
|
+
def self.included(base)
|
7
|
+
base.extend(ClassMethods)
|
8
|
+
end
|
9
|
+
|
10
|
+
module ClassMethods
|
11
|
+
def labels value=nil, &block
|
12
|
+
if block_given?
|
13
|
+
@labels = block
|
14
|
+
elsif value
|
15
|
+
@labels = value
|
16
|
+
end
|
17
|
+
|
18
|
+
@labels
|
19
|
+
end
|
20
|
+
|
21
|
+
def series value=nil, &block
|
22
|
+
@series ||= []
|
23
|
+
|
24
|
+
if block_given?
|
25
|
+
@series << block
|
26
|
+
elsif value
|
27
|
+
@series << value
|
28
|
+
end
|
29
|
+
|
30
|
+
@series
|
31
|
+
end
|
32
|
+
|
33
|
+
def options &block
|
34
|
+
@options = block if block_given?
|
35
|
+
@options
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def labels
|
40
|
+
if self.class.labels.is_a?(Proc)
|
41
|
+
instance_eval(&self.class.labels)
|
42
|
+
else
|
43
|
+
self.class.labels
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def series
|
48
|
+
Array(self.class.series).map do |serie|
|
49
|
+
if serie.is_a?(Proc)
|
50
|
+
instance_eval(&serie)
|
51
|
+
else
|
52
|
+
serie
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def data
|
58
|
+
{
|
59
|
+
labels: labels,
|
60
|
+
series: series
|
61
|
+
}
|
62
|
+
end
|
63
|
+
|
64
|
+
def options
|
65
|
+
Docile.dsl_eval(Options.new, &(self.class.options || ->{}) ).options
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|