purechart 0.0.2 → 0.0.4

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8952de0de182e98f9194659337a337b74d8df380f79305226fd6a66024080894
4
- data.tar.gz: 76fb48340a27b82317a50686d3d22442109930299c0abfb52b5d66c331a949cd
3
+ metadata.gz: 3da83a5728b80f59c13b285e45d578f1cc4d14d4b3583f6f9d06f01a28f07f83
4
+ data.tar.gz: 56b3dc6cba9a146ea9dd0f0c0e28c6dc46569c24fe8a6de2ea63f3d7b76d7ca2
5
5
  SHA512:
6
- metadata.gz: e6594c5ea2bbcd0d90e66add465482b372b8457298f36e7a8628897047824486071c50e3f1eb6b034ee8a2a4d669e46be5947d9d3e62246977a4a3eac22cb861
7
- data.tar.gz: 62e79a370de009c0247be793cc949c118b80aee11a407ca07b3ffc4e473fbda8087252c65fee24acb23f83f56eb23e909bab88120fd60058921ed3ca0a72e171
6
+ metadata.gz: 4398210acb1fb3a7a65a3e219fb9517ff94a9ef143d381d60933e374353f26e58caa800abb3892a69ae34af87741f754d6369b4ae5af441beee0101ba0624e8f
7
+ data.tar.gz: 501efff6e2aefca396f15c1d74878c5404d23b1d977c493b3667040e6e455020bbb0d52e292819293b71a3085f3d1898d8c11c38de49382ce9c47ab9ee935c03
@@ -0,0 +1,52 @@
1
+ <!-- TODO - Use 'style' hash to apply styles -->
2
+ <div class="chart-flex-container">
3
+ <div class="chart" style="border-left: <%= style['axes']['style'] %>; border-bottom: <%= style['axes']['style'] %>">
4
+ <div class="chart-elements">
5
+ <%- data.each do |object| %>
6
+ <div class="bar" style="width: <%= object[:width] %>%; background-color: <%= object[:color] %>;">
7
+ <p class="bar-title" style="font-family: <%= style['labels']['font'] %>; font-weight: <%= style['labels']['weight'] %>; color: <%= style['labels']['color'] %>"><%= object[:name] %></p>
8
+ <div class="lollipop-end" style="background-color: <%= object[:color] %>;">
9
+ <div class="tooltip">
10
+ <p style="color: <%= object[:color] %>;"><%= object[:name] %></p>
11
+ <p>$<%= object[:value] %></p>
12
+ </div>
13
+ </div>
14
+ </div>
15
+ <% end %>
16
+ </div>
17
+ <div class="gridlines">
18
+ <div style="width: 10%; border-right: <%= style['gridlines']['style'] %>">
19
+ </div>
20
+ <div style="width: 10%; border-right: <%= style['gridlines']['style'] %>">
21
+ </div>
22
+ <div style="width: 10%; border-right: <%= style['gridlines']['style'] %>">
23
+ </div>
24
+ <div style="width: 10%; border-right: <%= style['gridlines']['style'] %>">
25
+ </div>
26
+ <div style="width: 10%; border-right: <%= style['gridlines']['style'] %>">
27
+ </div>
28
+ <div style="width: 10%; border-right: <%= style['gridlines']['style'] %>">
29
+ </div>
30
+ <div style="width: 10%; border-right: <%= style['gridlines']['style'] %>">
31
+ </div>
32
+ <div style="width: 10%; border-right: <%= style['gridlines']['style'] %>">
33
+ </div>
34
+ <div style="width: 10%; border-right: <%= style['gridlines']['style'] %>">
35
+ </div>
36
+ <div style="width: 10%; border-right: <%= style['gridlines']['style'] %>">
37
+ </div>
38
+ </div>
39
+ </div>
40
+ <div class="gridlines-ticks">
41
+ <%- (1..10).each do |index| %>
42
+ <div class="tick" style="width: 10%; border-right: <%= style['gridlines']['style'] %>">
43
+ <p style="margin-right: 4px; font-family: <%= style['ticks']['font'] %>; font-weight: <%= style['ticks']['weight'] %>; color: <%= style['ticks']['color'] %>"><%= index * 120 %></p>
44
+ </div>
45
+ <% end %>
46
+ </div>
47
+ <div style="margin-left: 96px">
48
+ <h4 style="text-align: center; font-family: <%= style['labels']['font'] %>; font-weight: <%= style['labels']['weight'] %>; color: <%= style['labels']['color'] %>"><%= axes[:horizontal] %> ($)</h4>
49
+ </div>
50
+ </div>
51
+
52
+ <%= render :partial => '/styles' %>
@@ -0,0 +1,91 @@
1
+ <div class="pieContainer">
2
+ <div class="pieBackground"></div>
3
+ <div id="pie-slice-1" class="hold"><div class="pie"></div></div>
4
+ <div id="pie-slice-2" class="hold"><div class="pie"></div></div>
5
+ <div id="pie-slice-3" class="hold"><div class="pie"></div></div>
6
+ <div id="pie-slice-4" class="hold"><div class="pie"></div></div>
7
+ <div id="pie-slice-5" class="hold"><div class="pie"></div></div>
8
+ <div id="pie-slice-6" class="hold"><div class="pie"></div></div>
9
+ </div>
10
+
11
+ <style>
12
+ .pieContainer {
13
+ height: 250px;
14
+ width: 250px;
15
+ position: relative;
16
+ }
17
+
18
+ .pieBackground {
19
+ position: absolute;
20
+ width: 250px;
21
+ height: 250px;
22
+ border-radius: 100%;
23
+ }
24
+
25
+ .pie {
26
+ transition: all 1s;
27
+ position: absolute;
28
+ width: 250px;
29
+ height: 250px;
30
+ border-radius: 100%;
31
+ clip: rect(0px, 125px, 250px, 0px);
32
+ }
33
+
34
+ .hold {
35
+ position: absolute;
36
+ width: 250px;
37
+ height: 250px;
38
+ border-radius: 100%;
39
+ clip: rect(0px, 250px, 250px, 125px);
40
+ }
41
+
42
+ #pie-slice-1 .pie {
43
+ background-color: #2ed573;
44
+ transform:rotate(30deg);
45
+ }
46
+
47
+ #pie-slice-2 {
48
+ transform: rotate(30deg);
49
+ }
50
+
51
+ #pie-slice-2 .pie {
52
+ background-color: #ffa502;
53
+ transform: rotate(60deg);
54
+ }
55
+
56
+ #pie-slice-3 {
57
+ transform: rotate(90deg);
58
+ }
59
+
60
+ #pie-slice-3 .pie {
61
+ background-color: #5352ed;
62
+ transform: rotate(120deg);
63
+ }
64
+
65
+ #pie-slice-4 {
66
+ transform: rotate(210deg);
67
+ }
68
+
69
+ #pie-slice-4 .pie {
70
+ background-color: #ff4757;
71
+ transform: rotate(10deg);
72
+ }
73
+
74
+ #pie-slice-5 {
75
+ transform: rotate(220deg);
76
+ }
77
+
78
+ #pie-slice-5 .pie {
79
+ background-color: #1e90ff;
80
+ transform: rotate(70deg);
81
+ }
82
+
83
+ #pie-slice-6 {
84
+ transform: rotate(290deg);
85
+ }
86
+
87
+ #pie-slice-6 .pie {
88
+ background-color: #ff7f50;
89
+ transform: rotate(70deg);
90
+ }
91
+ </style>
@@ -0,0 +1,164 @@
1
+ <style>
2
+ /* TODO - Remove all general styles except for the font import */
3
+ @import url('https://fonts.googleapis.com/css2?family=Inter+Tight:wght@400;600&display=swap');
4
+
5
+ body {
6
+ padding: 32px;
7
+ }
8
+
9
+ h2,
10
+ h4 {
11
+ margin: 0;
12
+ font-family: 'Inter Tight', sans-serif;
13
+ }
14
+
15
+ h2 {
16
+ margin-bottom: 16px;
17
+ }
18
+
19
+ h4 {
20
+ margin-top: 16px;
21
+ }
22
+
23
+ .chart {
24
+ width: 500px;
25
+ height: 400px;
26
+
27
+ margin-left: 96px;
28
+ padding-top: 32px;
29
+ padding-bottom: 32px;
30
+
31
+ position: relative;
32
+
33
+ border-left: 2px solid black;
34
+ border-bottom: 2px solid black;
35
+ }
36
+
37
+ .chart-elements {
38
+ width: 100%;
39
+ height: 100%;
40
+
41
+ display: flex;
42
+ flex-direction: column;
43
+ align-items: baseline;
44
+ justify-content: space-around;
45
+ }
46
+
47
+ .bar {
48
+ height: 4px;
49
+ background-color: #476D54;
50
+
51
+ margin-bottom: 32px;
52
+ position: relative;
53
+
54
+ cursor: pointer;
55
+ }
56
+
57
+ .lollipop-end {
58
+ width: 16px;
59
+ height: 16px;
60
+ background-color: #476D54;
61
+ border-radius: 100px;
62
+ position: absolute;
63
+ top: 50%;
64
+ right: -8px;
65
+ transform: translateY(-50%);
66
+ }
67
+
68
+ .bar-title {
69
+ position: absolute;
70
+ top: -12px;
71
+ margin: 0;
72
+ right: 100%;
73
+ height: 24px;
74
+ width: 96px;
75
+ line-height: 24px;
76
+ font-family: 'Inter Tight', sans-serif;
77
+ font-weight: 700;
78
+
79
+ white-space: nowrap;
80
+ text-overflow: ellipsis;
81
+ overflow: hidden;
82
+ padding-right: 8px;
83
+ }
84
+
85
+ .tooltip {
86
+ position: absolute;
87
+ top: 50%;
88
+ left: 50%;
89
+
90
+ padding: 8px;
91
+
92
+ background-color: #fff;
93
+ border-radius: 8px;
94
+ box-shadow: rgba(0, 0, 0, 0.25) 0px 10px 36px 0px, rgba(0, 0, 0, 0.15) 0px 0px 0px 1px;
95
+
96
+ opacity: 0;
97
+ transform: translateX(-50%) translateY(-50%);
98
+
99
+ transition: 0.25s all ease;
100
+ }
101
+
102
+ .tooltip p {
103
+ margin: 0px;
104
+ font-family: 'Inter Tight';
105
+ font-weight: 700;
106
+ }
107
+
108
+ .gridlines {
109
+ position: absolute;
110
+ top: 0;
111
+ right: 0;
112
+ left: 0;
113
+ bottom: 0;
114
+
115
+ z-index: -1;
116
+ display: flex;
117
+ }
118
+
119
+ .gridlines div {
120
+ height: 100%;
121
+ border-right: 2px solid #00000033;
122
+
123
+ display: flex;
124
+ flex-direction: column;
125
+ justify-content: end;
126
+ }
127
+
128
+ .gridlines div p {
129
+ margin: 0;
130
+ font-family: 'Inter Tight';
131
+ }
132
+
133
+ /* TICKS */
134
+ .gridlines-ticks {
135
+ margin-left: 96px;
136
+ width: 500px;
137
+ display: flex;
138
+ border-bottom: 2px solid #00000000;
139
+ padding-left: 2px;
140
+ text-align: right;
141
+ }
142
+
143
+ .gridlines-ticks div {
144
+ border-right: 2px solid #0003;
145
+ display: flex;
146
+ flex-direction: column;
147
+ justify-content: end;
148
+ position: relative;
149
+ }
150
+
151
+ .gridlines-ticks div p {
152
+ margin: 0;
153
+ font-family: 'Inter Tight';
154
+ }
155
+
156
+ .bar:hover .tooltip {
157
+ opacity: 1;
158
+ transform: translateX(-50%) translateY(calc(-50% - 32px));
159
+ }
160
+
161
+ * {
162
+ box-sizing: border-box;
163
+ }
164
+ </style>
@@ -0,0 +1,63 @@
1
+ module PureChart
2
+ module ChartHelpers
3
+ def lollipop_chart(data, axes = { horizontal: "Value" }, path = "")
4
+ # Set default configuration file path
5
+ default_config_path = File.join( File.dirname(__FILE__), 'styles/default.yml' )
6
+
7
+ default_config_hash = YAML.load(File.read(default_config_path))
8
+ user_config_hash = {}
9
+
10
+ if path != ""
11
+ # TODO - Implement better logic
12
+ if File.file?("app/purechart/" + path + ".yml")
13
+ puts "loading..."
14
+ user_config_hash = YAML.load(File.read("app/purechart/" + path + ".yml"))
15
+ puts user_config_hash
16
+ elsif File.file?("app/purechart/" + path + ".yaml")
17
+ user_config_hash = YAML.load(File.read("app/purechart/" + path + ".yaml"))
18
+ elsif File.file?("app/purechart/" + path + ".json")
19
+ user_config_hash = JSON.load(File.read("app/purechart/" + path + ".json"))
20
+ else
21
+ raise "(PureChart) ERROR - Could not locate configuration file '" + path + ".[YML, YAML, JSON]'. Make sure this file exists in your 'app/purechart' directory."
22
+ end
23
+ end
24
+
25
+ # Merge user's configuration with default
26
+ style_config = default_config_hash.merge(user_config_hash)
27
+
28
+ puts "USER CONFIG - "
29
+ puts user_config_hash
30
+
31
+ # Format data for chart generation
32
+ largest_value = (data.map { |object| object[:value] }).max()
33
+
34
+ data.each do |object|
35
+ object[:width] = (Float(object[:value]) / largest_value) * 100
36
+ end
37
+
38
+ gridlines = {
39
+ vertical_lines: 10,
40
+ vertical_increment: (Float(largest_value) / 10).ceil
41
+ }
42
+
43
+ ActionController::Base.render partial: '/lollipop', locals: {
44
+ data: data,
45
+ gridlines: gridlines,
46
+ axes: axes,
47
+ style: style_config
48
+ }
49
+ end
50
+
51
+ def bar_chart
52
+ "<div>Bar chart will be rendered here.</div>".html_safe
53
+ end
54
+
55
+ def column_chart
56
+ "<div>Column chart will be rendered here.</div>".html_safe
57
+ end
58
+
59
+ def pie_chart
60
+ ActionController::Base.render partial: '/pie'
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,18 @@
1
+ ---
2
+ title:
3
+ font: Inter Tight
4
+ weight: 700
5
+ color: "#000000"
6
+ labels:
7
+ font: Inter Tight
8
+ weight: 700
9
+ color: "#000000"
10
+ ticks:
11
+ font: Inter Tight
12
+ weight: 400
13
+ color: "#000000"
14
+ axes:
15
+ style: "2px solid #000000"
16
+ gridlines:
17
+ style: "2px dashed #00000033"
18
+ ...
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: purechart
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - George Berdovskiy
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-02-07 00:00:00.000000000 Z
11
+ date: 2023-02-16 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Pure HTML/CSS charts for Ruby on Rails.
14
14
  email:
@@ -16,7 +16,12 @@ executables: []
16
16
  extensions: []
17
17
  extra_rdoc_files: []
18
18
  files:
19
+ - app/views/_lollipop.html.erb
20
+ - app/views/_pie.html.erb
21
+ - app/views/_styles.html.erb
19
22
  - lib/purechart.rb
23
+ - lib/purechart/chart_helper.rb
24
+ - lib/purechart/styles/default.yml
20
25
  homepage:
21
26
  licenses:
22
27
  - MIT