rubyvis_charts 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +7 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +56 -0
- data/LICENSE.txt +21 -0
- data/README.md +176 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/images/AreaTimelineChart.png +0 -0
- data/images/BarTimelineChart.png +0 -0
- data/images/DonutChart.png +0 -0
- data/images/GroupedBarTimelineChart.png +0 -0
- data/images/LineTimelineChart.png +0 -0
- data/images/StackedBarTimelineChart.png +0 -0
- data/lib/rubyvis_charts.rb +12 -0
- data/lib/rubyvis_charts/abstract_chart.rb +49 -0
- data/lib/rubyvis_charts/abstract_timeline_chart.rb +441 -0
- data/lib/rubyvis_charts/area_timeline_chart.rb +41 -0
- data/lib/rubyvis_charts/bar_timeline_chart.rb +44 -0
- data/lib/rubyvis_charts/donut_chart.rb +44 -0
- data/lib/rubyvis_charts/grouped_bar_timeline_chart.rb +51 -0
- data/lib/rubyvis_charts/line_timeline_chart.rb +39 -0
- data/lib/rubyvis_charts/padding.rb +19 -0
- data/lib/rubyvis_charts/stacked_bar_timeline_chart.rb +51 -0
- data/lib/rubyvis_charts/version.rb +3 -0
- data/rubyvis_charts.gemspec +37 -0
- metadata +171 -0
@@ -0,0 +1,44 @@
|
|
1
|
+
module RubyvisCharts
|
2
|
+
class BarTimelineChart < AbstractTimelineChart
|
3
|
+
module DefaultArguments
|
4
|
+
BARS_PADDING = Padding.new(right: 0.5, left: 0.5)
|
5
|
+
BARS_COLORS = ['#4d79da'].freeze
|
6
|
+
end
|
7
|
+
|
8
|
+
attr_reader :bars_padding, :bars_colors
|
9
|
+
|
10
|
+
def initialize(
|
11
|
+
bars_padding: DefaultArguments::BARS_PADDING,
|
12
|
+
bars_colors: DefaultArguments::BARS_COLORS,
|
13
|
+
**other
|
14
|
+
)
|
15
|
+
super(other)
|
16
|
+
|
17
|
+
@bars_padding = bars_padding
|
18
|
+
@bars_colors = bars_colors
|
19
|
+
|
20
|
+
initialize_bars!
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def initialize_bars!
|
26
|
+
chart = self
|
27
|
+
|
28
|
+
bar_left_indent = -> { self.index * chart.send(:bars_widths).range_band + chart.bars_padding.left }
|
29
|
+
fill_style_colors = -> { chart.send(:bars_colors_iterator, self.index, self.height, chart.bars_colors) }
|
30
|
+
|
31
|
+
@layer_timeline.add(Rubyvis::Bar)
|
32
|
+
.data(values)
|
33
|
+
.width(bars_widths.range_band - bars_padding.right - bars_padding.left)
|
34
|
+
.height(bars_heights)
|
35
|
+
.left(bar_left_indent)
|
36
|
+
.bottom(0)
|
37
|
+
.fillStyle(fill_style_colors)
|
38
|
+
end
|
39
|
+
|
40
|
+
def bars_widths
|
41
|
+
@bars_widths ||= Rubyvis::Scale.ordinal(Rubyvis.range(values.length)).split_banded(0, timeline_width)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module RubyvisCharts
|
2
|
+
class DonutChart < AbstractChart
|
3
|
+
module DefaultArguments
|
4
|
+
CONES_COLORS = ["#cf2030", "#F73000", "#ffcc00", "#64bbe3", "#6cc04a", "#f2f2f2"].freeze
|
5
|
+
|
6
|
+
OUTER_RADIUS = 120
|
7
|
+
end
|
8
|
+
|
9
|
+
attr_reader :cones_colors, :outer_radius, :inner_radius, :percentage_key
|
10
|
+
|
11
|
+
def initialize(
|
12
|
+
cones_colors: DefaultArguments::CONES_COLORS,
|
13
|
+
outer_radius: DefaultArguments::OUTER_RADIUS,
|
14
|
+
inner_radius: DefaultArguments::OUTER_RADIUS * 0.7,
|
15
|
+
percentage_key: :percentage,
|
16
|
+
**other
|
17
|
+
)
|
18
|
+
super(other)
|
19
|
+
@outer_radius = outer_radius
|
20
|
+
@inner_radius = inner_radius
|
21
|
+
@cones_colors = cones_colors
|
22
|
+
@percentage_key = percentage_key
|
23
|
+
|
24
|
+
initialize_cones!
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def initialize_cones!
|
30
|
+
chart = self
|
31
|
+
angle = ->(segment_hash) { segment_hash[chart.percentage_key].to_f * 2 * Math::PI }
|
32
|
+
fill_style = -> { chart.cones_colors[self.index] || "##{SecureRandom.hex(3)}"}
|
33
|
+
|
34
|
+
parent_layer.add(Rubyvis::Wedge)
|
35
|
+
.data(values)
|
36
|
+
.left(width / 2)
|
37
|
+
.top(height / 2)
|
38
|
+
.innerRadius(inner_radius)
|
39
|
+
.outerRadius(outer_radius)
|
40
|
+
.angle(angle)
|
41
|
+
.fillStyle(fill_style)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module RubyvisCharts
|
2
|
+
class GroupedBarTimelineChart < AbstractTimelineChart
|
3
|
+
module DefaultArguments
|
4
|
+
BARS_PADDING = Padding.new(right: 0.5, left: 0.5)
|
5
|
+
BARS_COLORS = ['#4d79da'].freeze
|
6
|
+
end
|
7
|
+
|
8
|
+
HALF_VALUE = 2
|
9
|
+
|
10
|
+
attr_reader :bars_padding, :bars_colors
|
11
|
+
|
12
|
+
def initialize(
|
13
|
+
bars_padding: DefaultArguments::BARS_PADDING,
|
14
|
+
bars_colors: DefaultArguments::BARS_COLORS,
|
15
|
+
**other
|
16
|
+
)
|
17
|
+
super(other)
|
18
|
+
|
19
|
+
@bars_padding = bars_padding
|
20
|
+
@bars_colors = bars_colors
|
21
|
+
|
22
|
+
initialize_bars!
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def initialize_bars!
|
28
|
+
chart = self
|
29
|
+
|
30
|
+
bar_left_indent = -> do
|
31
|
+
bar_width = chart.send(:bars_widths).range_band / HALF_VALUE
|
32
|
+
colors = chart.send(:bars_colors)
|
33
|
+
left_padding = chart.bars_padding.left
|
34
|
+
self.index * bar_width - (self.index % colors.length) * (bar_width - left_padding * HALF_VALUE) + left_padding
|
35
|
+
end
|
36
|
+
fill_style_colors = -> { chart.send(:bars_colors_iterator, self.index, self.height, chart.bars_colors) }
|
37
|
+
|
38
|
+
@layer_timeline.add(Rubyvis::Bar)
|
39
|
+
.data(values)
|
40
|
+
.width(bars_widths.range_band - (bars_padding.right + bars_padding.left) * HALF_VALUE)
|
41
|
+
.height(bars_heights)
|
42
|
+
.left(bar_left_indent)
|
43
|
+
.bottom(0)
|
44
|
+
.fillStyle(fill_style_colors)
|
45
|
+
end
|
46
|
+
|
47
|
+
def bars_widths
|
48
|
+
@bars_widths ||= Rubyvis::Scale.ordinal(Rubyvis.range(values.length / HALF_VALUE)).split_banded(0, timeline_width)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module RubyvisCharts
|
2
|
+
class LineTimelineChart < AbstractTimelineChart
|
3
|
+
module DefaultArguments
|
4
|
+
LINES_COLORS = %w[#4d79da #31d49e].freeze
|
5
|
+
end
|
6
|
+
|
7
|
+
LONG_MONTH_PADDING = 20
|
8
|
+
LONG_MONTH_DAYS = 31
|
9
|
+
|
10
|
+
attr_reader :lines_colors
|
11
|
+
|
12
|
+
def initialize(
|
13
|
+
lines_colors: DefaultArguments::LINES_COLORS,
|
14
|
+
**other
|
15
|
+
)
|
16
|
+
super(other)
|
17
|
+
@lines_colors = lines_colors
|
18
|
+
initialize_lines!
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def initialize_lines!
|
24
|
+
chart = self
|
25
|
+
|
26
|
+
area_left_offset = -> { chart.send(:graph_width).scale(self.index) + chart.send(:graph_width).scale(1)/2 }
|
27
|
+
height = ->(d) { chart.send(:bars_heights).scale(d) }
|
28
|
+
|
29
|
+
values.each_with_index do |line_data, index|
|
30
|
+
@layer_timeline.add(Rubyvis::Line)
|
31
|
+
.data(line_data)
|
32
|
+
.left(area_left_offset)
|
33
|
+
.bottom(height)
|
34
|
+
.lineWidth(1)
|
35
|
+
.strokeStyle(lines_colors[index])
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module RubyvisCharts
|
2
|
+
class Padding
|
3
|
+
DEFAULT_PADDING = 0
|
4
|
+
|
5
|
+
attr_reader :top, :right, :bottom, :left
|
6
|
+
|
7
|
+
def initialize(
|
8
|
+
top: DEFAULT_PADDING,
|
9
|
+
right: DEFAULT_PADDING,
|
10
|
+
bottom: DEFAULT_PADDING,
|
11
|
+
left: DEFAULT_PADDING
|
12
|
+
)
|
13
|
+
@top = top
|
14
|
+
@right = right
|
15
|
+
@bottom = bottom
|
16
|
+
@left = left
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module RubyvisCharts
|
2
|
+
class StackedBarTimelineChart < AbstractTimelineChart
|
3
|
+
module DefaultArguments
|
4
|
+
BARS_PADDING = Padding.new(right: 0.5, left: 0.5)
|
5
|
+
BARS_COLORS = %w[#4d79da #31d49e].freeze
|
6
|
+
end
|
7
|
+
|
8
|
+
attr_reader :bars_padding, :bars_colors
|
9
|
+
|
10
|
+
def initialize(
|
11
|
+
bars_padding: DefaultArguments::BARS_PADDING,
|
12
|
+
bars_colors: DefaultArguments::BARS_COLORS,
|
13
|
+
**other
|
14
|
+
)
|
15
|
+
super(other)
|
16
|
+
|
17
|
+
@bars_padding = bars_padding
|
18
|
+
@bars_colors = bars_colors
|
19
|
+
|
20
|
+
initialize_bars!
|
21
|
+
end
|
22
|
+
|
23
|
+
protected
|
24
|
+
|
25
|
+
def values_max
|
26
|
+
@max_value ||= values.transpose.map do |transposed_value|
|
27
|
+
transposed_value.inject(0) {|sum, x| sum + x }
|
28
|
+
end.max
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def initialize_bars!
|
34
|
+
chart = self
|
35
|
+
|
36
|
+
fill_style_colors = -> { chart.send(:bars_colors_iterator, self.parent.index, self.height, chart.bars_colors) }
|
37
|
+
|
38
|
+
@layer_timeline.add(Rubyvis::Layout::Stack)
|
39
|
+
.layers(values)
|
40
|
+
.x(-> { chart.send(:bars_widths)[self.index] + chart.bars_padding.left })
|
41
|
+
.y(->(d) { chart.send(:bars_heights)[d] })
|
42
|
+
.layer.add(Rubyvis::Bar)
|
43
|
+
.width(bars_widths.range_band - bars_padding.left - bars_padding.right)
|
44
|
+
.fillStyle(fill_style_colors)
|
45
|
+
end
|
46
|
+
|
47
|
+
def bars_widths
|
48
|
+
@bars_widths ||= Rubyvis::Scale.ordinal(Rubyvis.range(values_max_count)).split_banded(0, timeline_width)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "rubyvis_charts/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "rubyvis_charts"
|
8
|
+
spec.version = RubyvisCharts::VERSION
|
9
|
+
spec.authors = ["Andriy Solonyna"]
|
10
|
+
spec.email = ["asolonyn@cisco.com"]
|
11
|
+
|
12
|
+
spec.summary = "Rubyvis charts"
|
13
|
+
spec.description = "Rubyvis charts"
|
14
|
+
spec.homepage = "https://github.com/Cisco-AMP/rubyvis_charts"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
|
+
|
20
|
+
# Specify which files should be added to the gem when it is released.
|
21
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
22
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
23
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
24
|
+
end
|
25
|
+
spec.bindir = "exe"
|
26
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
27
|
+
spec.require_paths = ["lib"]
|
28
|
+
|
29
|
+
spec.add_dependency "rubyvis", "~> 0.6.1"
|
30
|
+
spec.add_dependency 'activesupport'
|
31
|
+
|
32
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
33
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
34
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
35
|
+
spec.add_development_dependency "nokogiri", "~> 1.8"
|
36
|
+
spec.add_development_dependency "byebug", "~> 10.0"
|
37
|
+
end
|
metadata
ADDED
@@ -0,0 +1,171 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rubyvis_charts
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Andriy Solonyna
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-01-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rubyvis
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.6.1
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.6.1
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activesupport
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
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.16'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.16'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: nokogiri
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '1.8'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '1.8'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: byebug
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '10.0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '10.0'
|
111
|
+
description: Rubyvis charts
|
112
|
+
email:
|
113
|
+
- asolonyn@cisco.com
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- ".gitignore"
|
119
|
+
- ".rspec"
|
120
|
+
- ".travis.yml"
|
121
|
+
- CODE_OF_CONDUCT.md
|
122
|
+
- Gemfile
|
123
|
+
- Gemfile.lock
|
124
|
+
- LICENSE.txt
|
125
|
+
- README.md
|
126
|
+
- Rakefile
|
127
|
+
- bin/console
|
128
|
+
- bin/setup
|
129
|
+
- images/AreaTimelineChart.png
|
130
|
+
- images/BarTimelineChart.png
|
131
|
+
- images/DonutChart.png
|
132
|
+
- images/GroupedBarTimelineChart.png
|
133
|
+
- images/LineTimelineChart.png
|
134
|
+
- images/StackedBarTimelineChart.png
|
135
|
+
- lib/rubyvis_charts.rb
|
136
|
+
- lib/rubyvis_charts/abstract_chart.rb
|
137
|
+
- lib/rubyvis_charts/abstract_timeline_chart.rb
|
138
|
+
- lib/rubyvis_charts/area_timeline_chart.rb
|
139
|
+
- lib/rubyvis_charts/bar_timeline_chart.rb
|
140
|
+
- lib/rubyvis_charts/donut_chart.rb
|
141
|
+
- lib/rubyvis_charts/grouped_bar_timeline_chart.rb
|
142
|
+
- lib/rubyvis_charts/line_timeline_chart.rb
|
143
|
+
- lib/rubyvis_charts/padding.rb
|
144
|
+
- lib/rubyvis_charts/stacked_bar_timeline_chart.rb
|
145
|
+
- lib/rubyvis_charts/version.rb
|
146
|
+
- rubyvis_charts.gemspec
|
147
|
+
homepage: https://github.com/Cisco-AMP/rubyvis_charts
|
148
|
+
licenses:
|
149
|
+
- MIT
|
150
|
+
metadata: {}
|
151
|
+
post_install_message:
|
152
|
+
rdoc_options: []
|
153
|
+
require_paths:
|
154
|
+
- lib
|
155
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - ">="
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0'
|
160
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
161
|
+
requirements:
|
162
|
+
- - ">="
|
163
|
+
- !ruby/object:Gem::Version
|
164
|
+
version: '0'
|
165
|
+
requirements: []
|
166
|
+
rubyforge_project:
|
167
|
+
rubygems_version: 2.7.7
|
168
|
+
signing_key:
|
169
|
+
specification_version: 4
|
170
|
+
summary: Rubyvis charts
|
171
|
+
test_files: []
|