rubyvis_charts 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 8ab10c1ecb4e36e42957a92277495cf52c4d34cec83bfcaeb7f41f8d1a0b3cf8
4
+ data.tar.gz: c7a2e9ad58d70b470aeb8226602986db39d38298cfe1ce5aa762dd518f63c893
5
+ SHA512:
6
+ metadata.gz: f23866ff285257a60dae96cd59c9ebe7458cc1add747e657446d53a4fadd9ef56d550aead92c22be218d2c0d2e45acb5e0ee1bc6a624b8f000baadcc093283f2
7
+ data.tar.gz: d0b3fa6838b46e20bfff83bd7a6f3c8a84a9de77feb4db4f5fedda1e582c81ec52c1a5501d72eece5cca6d761485ea67d91e5ac2c4390cc35bd4913d17c5d303
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.2.4
7
+ before_install: gem install bundler -v 1.16.3
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at asolonyn@cisco.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in rubyvis_charts.gemspec
6
+ gemspec
@@ -0,0 +1,56 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ rubyvis_charts (0.1.3)
5
+ activesupport
6
+ rubyvis (~> 0.6.1)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ activesupport (5.2.2)
12
+ concurrent-ruby (~> 1.0, >= 1.0.2)
13
+ i18n (>= 0.7, < 2)
14
+ minitest (~> 5.1)
15
+ tzinfo (~> 1.1)
16
+ byebug (10.0.2)
17
+ concurrent-ruby (1.1.4)
18
+ diff-lcs (1.3)
19
+ i18n (1.2.0)
20
+ concurrent-ruby (~> 1.0)
21
+ mini_portile2 (2.3.0)
22
+ minitest (5.11.3)
23
+ nokogiri (1.8.4)
24
+ mini_portile2 (~> 2.3.0)
25
+ rake (10.5.0)
26
+ rspec (3.7.0)
27
+ rspec-core (~> 3.7.0)
28
+ rspec-expectations (~> 3.7.0)
29
+ rspec-mocks (~> 3.7.0)
30
+ rspec-core (3.7.1)
31
+ rspec-support (~> 3.7.0)
32
+ rspec-expectations (3.7.0)
33
+ diff-lcs (>= 1.2.0, < 2.0)
34
+ rspec-support (~> 3.7.0)
35
+ rspec-mocks (3.7.0)
36
+ diff-lcs (>= 1.2.0, < 2.0)
37
+ rspec-support (~> 3.7.0)
38
+ rspec-support (3.7.1)
39
+ rubyvis (0.6.1)
40
+ thread_safe (0.3.6)
41
+ tzinfo (1.2.5)
42
+ thread_safe (~> 0.1)
43
+
44
+ PLATFORMS
45
+ ruby
46
+
47
+ DEPENDENCIES
48
+ bundler (~> 1.16)
49
+ byebug (~> 10.0)
50
+ nokogiri (~> 1.8)
51
+ rake (~> 10.0)
52
+ rspec (~> 3.0)
53
+ rubyvis_charts!
54
+
55
+ BUNDLED WITH
56
+ 1.16.5
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Andriy Solonyna
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.
@@ -0,0 +1,176 @@
1
+ # RubyvisCharts
2
+
3
+ RubyvisCharts gem is a wrapper around rubyvis gem which allows you to create charts
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'rubyvis_charts'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install rubyvis_charts
20
+
21
+ ## Usage
22
+
23
+ ### BarTimelineChart
24
+ ```
25
+ data = {
26
+ :legend_titles => ["Value1", "Value2"],
27
+ :values => [81000, 67000, 287000, 174000, 217000, 185000, 280000, 230000, 219000, 138000, 93000, 74000, 89000, 67000],
28
+ :bars_padding => RubyvisCharts::Padding.new(right: 3, left: 3),
29
+ :bars_colors => ["#83c9e9", "#5096b6"],
30
+ :weekend_bar_color => "#ffffff",
31
+ :dates_height_ratio => 0.1,
32
+ :legend_colors => ["#83c9e9", "#5096b6"],
33
+ :dates => [1541980800, 1542067200, 1542153600, 1542240000, 1542326400, 1542412800, 1542499200],
34
+ :y_scale_max => 287000,
35
+ :width => 355,
36
+ :height => 160,
37
+ :padding => RubyvisCharts::Padding.new(top: 6, bottom: 6)
38
+ }
39
+
40
+ RubyvisCharts::BarTimelineChart.new(data).render
41
+ ```
42
+
43
+ <p align="center">
44
+ <img src ="/images/BarTimelineChart.png" width="300"/>
45
+ </p>
46
+
47
+
48
+ ### GroupedBarTimelineChart
49
+ ```
50
+ data = {
51
+ :legend_titles => ["Value1", "Value2"],
52
+ :values => [81000, 67000, 287000, 174000, 217000, 185000, 280000, 230000, 219000, 138000, 93000, 74000, 89000, 67000],
53
+ :bars_padding => RubyvisCharts::Padding.new(right: 6, left: 6),
54
+ :bars_colors => ["#83c9e9", "#5096b6"],
55
+ :weekend_bar_color => "#ffffff",
56
+ :dates_height_ratio => 0.1,
57
+ :legend_colors => ["#83c9e9", "#5096b6"],
58
+ :dates => [1541980800, 1542067200, 1542153600, 1542240000, 1542326400, 1542412800, 1542499200],
59
+ :y_scale_max => 287000,
60
+ :width => 355,
61
+ :height => 160,
62
+ :padding => RubyvisCharts::Padding.new(top: 6, bottom: 6)
63
+ }
64
+
65
+ RubyvisCharts::GroupedBarTimelineChart.new(data).render
66
+ ```
67
+ <p align="center">
68
+ <img src ="/images/GroupedBarTimelineChart.png" width="300"/>
69
+ </p>
70
+
71
+ ### StackedBarTimelineChart
72
+ ```
73
+ data = {
74
+ :legend_titles=>["Value1", "Value2"],
75
+ :values=>[[5310, 2000, 9760, 2100, 7700, 6140, 9070], [106, 700, 41, 249, 800, 700, 44]],
76
+ :bars_padding=>RubyvisCharts::Padding.new(right: 6, left: 6),
77
+ :bars_colors=>["#14a792", "#8CB2D4"],
78
+ :weekend_bar_color=>"#ffffff",
79
+ :dates_height_ratio=>0.1,
80
+ :legend_colors=>["#14a792", "#8CB2D4"],
81
+ :dates=>[1541980800, 1542067200, 1542153600, 1542240000, 1542326400, 1542412800, 1542499200],
82
+ :y_scale_max=>9801,
83
+ :width=>355,
84
+ :height=>160,
85
+ :padding=>RubyvisCharts::Padding.new(top: 6, bottom: 6)
86
+ }
87
+
88
+ RubyvisCharts::StackedBarTimelineChart.new(data).render
89
+ ```
90
+ <p align="center">
91
+ <img src ="/images/StackedBarTimelineChart.png" width="300"/>
92
+ </p>
93
+
94
+ ### LineTimelineChart
95
+ ```
96
+ data = {
97
+ :legend_titles=>["Value"],
98
+ :legend_colors=>["#83c9e9"],
99
+ :lines_colors=>["#83c9e9"],
100
+ :values=>[[67058, 60843, 48407, 71359, 34323, 57690, 81868, 40042, 65890, 33722, 44754, 73729, 77828, 79634, 43539, 130, 23139, 12948, 21869, 46683, 21286, 50869, 53065, 34532, 29532, 1610, 32371, 5087, 75394, 9621, 7263]],
101
+ :dates=>[1514764800, 1514851200, 1514937600, 1515024000, 1515110400, 1515196800, 1515283200, 1515369600, 1515456000, 1515542400, 1515628800, 1515715200, 1515801600, 1515888000, 1515974400, 1516060800, 1516147200, 1516233600, 1516320000, 1516406400, 1516492800, 1516579200, 1516665600, 1516752000, 1516838400, 1516924800, 1517011200, 1517097600, 1517184000, 1517270400, 1517356800],
102
+ :y_scale_max=>81868,
103
+ :width=>550,
104
+ :height=>160,
105
+ :padding=>RubyvisCharts::Padding.new(top: 6, bottom: 20)
106
+ }
107
+
108
+ RubyvisCharts::LineTimelineChart.new(data).render
109
+ ```
110
+ <p align="center">
111
+ <img src ="/images/LineTimelineChart.png" width="300"/>
112
+ </p>
113
+
114
+ ### AreaTimelineChart
115
+ ```
116
+ data = {
117
+ :areas_colors=>["#8CB2D4", "#14a792"],
118
+ :dates_height_ratio=>0.1,
119
+ :legend_titles=>["Value1", "Value2"],
120
+ :legend_colors=>["#8CB2D4", "#14a792"],
121
+ :values=>[[1353, 1353, 1326, 1401, 1324, 1327, 1660, 1508, 1519, 1504, 1503, 1513, 1518, 1518, 1580, 1600, 1507, 1500, 1519, 1500, 1640, 1656, 1642, 1632, 1634, 1680, 1694, 1685, 1707, 1697, 1288], [1300, 1300, 1300, 1300, 1300, 1300, 1500, 1500, 1500, 1500, 1500, 1500, 1500, 1500, 1500, 1500, 1500, 1500, 1500, 1500, 1630, 1630, 1630, 1630, 1630, 1680, 1680, 1680, 1680, 1680, 1253]],
122
+ :dates=>[1514764800, 1514851200, 1514937600, 1515024000, 1515110400, 1515196800, 1515283200, 1515369600, 1515456000, 1515542400, 1515628800, 1515715200, 1515801600, 1515888000, 1515974400, 1516060800, 1516147200, 1516233600, 1516320000, 1516406400, 1516492800, 1516579200, 1516665600, 1516752000, 1516838400, 1516924800, 1517011200, 1517097600, 1517184000, 1517270400, 1517356800],
123
+ :y_scale_max=>1707,
124
+ :width=>550, :height=>160,
125
+ :padding=>RubyvisCharts::Padding.new(top: 6, bottom: 6)
126
+ }
127
+
128
+ RubyvisCharts::AreaTimelineChart.new(data).render
129
+ ```
130
+ <p align="center">
131
+ <img src ="/images/AreaTimelineChart.png" width="300"/>
132
+ </p>
133
+
134
+ You can use keys dates, marks, y_scale_max, numbers_formatter, numbers_color, numbers_font, title_text, title_color, title_font, dates_formatter, dates_color, dates_font, marks_color, rules_color, rules_count, weekend_bar_color, timeline_width_ratio, dates_height_ratio, marks_height_ratio, legend_titles, legend_colors, legend_text_color, legend_font, legend_shape, legend_chars, custom_legend_offset, threshold_number, threshold_color, threshold_width, threshold_caption
135
+ for all timeline charts
136
+
137
+ ### DonutChart
138
+ ```
139
+ data = {
140
+ :values=>[{percentage: 0.18906606},
141
+ {percentage: 0.05694761},
142
+ {percentage: 0.0501139},
143
+ {percentage: 0.04783599},
144
+ {percentage: 0.04555809},
145
+ {percentage: 0.61047836}],
146
+ :width=>240,
147
+ :height=>240,
148
+ :cones_colors=>["#cf2030", "#F73000", "#ffcc00", "#64bbe3", "#6cc04a", "#f2f2f2"],
149
+ :outer_radius=>120,
150
+ :inner_radius=>75
151
+ }
152
+
153
+ RubyvisCharts::DonutChart.new(data).render
154
+ ```
155
+ <p align="center">
156
+ <img src ="/images/DonutChart.png" width="150"/>
157
+ </p>
158
+
159
+
160
+ ## Development
161
+
162
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
163
+
164
+ 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`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
165
+
166
+ ## Contributing
167
+
168
+ Bug reports and pull requests are welcome on GitHub at https://github.com/Cisco-AMP/rubyvis_charts. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
169
+
170
+ ## License
171
+
172
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
173
+
174
+ ## Code of Conduct
175
+
176
+ Everyone interacting in the RubyvisCharts project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/Cisco-AMP/rubyvis_charts/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "rubyvis_charts"
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(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
Binary file
@@ -0,0 +1,12 @@
1
+ require 'active_support/time'
2
+ require 'rubyvis'
3
+ require 'nokogiri'
4
+ require "rubyvis_charts/version"
5
+ require "rubyvis_charts/abstract_chart"
6
+ require "rubyvis_charts/abstract_timeline_chart"
7
+ require "rubyvis_charts/area_timeline_chart"
8
+ require "rubyvis_charts/bar_timeline_chart"
9
+ require "rubyvis_charts/donut_chart"
10
+ require "rubyvis_charts/grouped_bar_timeline_chart"
11
+ require "rubyvis_charts/line_timeline_chart"
12
+ require "rubyvis_charts/stacked_bar_timeline_chart"
@@ -0,0 +1,49 @@
1
+ require_relative 'padding'
2
+
3
+ module RubyvisCharts
4
+ class AbstractChart
5
+ module DefaultArguments
6
+ WIDTH = 400
7
+ HEIGHT = 225
8
+ PADDING = Padding.new
9
+ end
10
+
11
+ attr_reader :values, :width, :height, :padding,
12
+ :inner_box_width, :inner_box_height,
13
+ :parent_layer
14
+
15
+ def initialize(
16
+ values:,
17
+ width: DefaultArguments::WIDTH,
18
+ height: DefaultArguments::HEIGHT,
19
+ padding: DefaultArguments::PADDING
20
+ )
21
+ @values = values
22
+ @width = width
23
+ @height = height
24
+ @padding = padding
25
+
26
+ @inner_box_width = width - padding.left - padding.right
27
+ @inner_box_height = height - padding.top - padding.bottom
28
+
29
+ initialize_parent_layer!
30
+ end
31
+
32
+ def render
33
+ @parent_layer.render
34
+ @parent_layer.to_svg
35
+ end
36
+
37
+ private
38
+
39
+ def initialize_parent_layer!
40
+ @parent_layer = Rubyvis::Panel.new
41
+ .width(inner_box_width)
42
+ .height(inner_box_height)
43
+ .top(padding.top)
44
+ .right(padding.right)
45
+ .left(padding.left)
46
+ .bottom(padding.bottom)
47
+ end
48
+ end
49
+ end