peity_vanilla_rails 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3c48643fc2950ad8495f99384593c7fd1ee26732b64c9df86b62781b738a25ce
4
- data.tar.gz: c6ef11ccda4de91fd692c17902255a719b64cfb8038dbd0aefa02ffb13b107ab
3
+ metadata.gz: 32f04e35a10743476825e404056471ab5ec13c54372653d516a43c684e632b82
4
+ data.tar.gz: ae91de3bee20977261f2ac80a70fcac274aa27e109035f5fdfe825f9f5481a92
5
5
  SHA512:
6
- metadata.gz: 77de0c81a7259fb311f37804511e85654e1bd91eca5dc3a487d2b49a8a5b433a2100eaa6af5ff5c012070188316e60f3af5e9079f8902377e901efd38777b7dd
7
- data.tar.gz: eab3b26b503ebf900d799a8cbdca94aee4acc85bc57fbba4144a9be393d03c889c0802d47931e9decfc44025d11161a3e5faab25db16c2a75933fef19276a6d6
6
+ metadata.gz: 5a5903519f2834b17ab6a9e1421636855cba3602206e50d2224b4e072b38d218145e5ea6d0fef7ffbd35552494b51f57517ec25f6e8701048cf35a226dc1f213
7
+ data.tar.gz: 3a3cf7fc61864c1b88d3459568997b56de62732eaf476b13bea94741942b25e59abfe43b88818fa6261f84043b8b54d17f190308aef3b538fb2f91e317342eef
data/README.md CHANGED
@@ -2,19 +2,25 @@
2
2
 
3
3
  Sparklines are small but intense charts. This gem is a wrapper around [peity_vanilla](https://github.com/railsjazz/peity_vanilla) library. You can generate simple but informative charts with vanilla JS.
4
4
 
5
- ![Sparklines Rails](docs/sparklines.png)
5
+ <img src="./docs/sparklines.png" height="400px"/>
6
6
 
7
7
  ## Usage
8
8
 
9
- 1. Add to `application.js`
9
+ 1. add gem to the `Gemfile`
10
+
11
+ ```ruby
12
+ gem "peity_vanilla_rails"
13
+ ```
14
+
15
+ 2. Add to `application.js`
10
16
 
11
17
  ```javascript
12
18
  //= require peity_vanilla.js
13
19
  ```
14
20
 
15
- 2. Add charts in your code:
21
+ 3. Add charts in your code:
16
22
 
17
- ```ruby
23
+ ```erb
18
24
  <h3>Line</h3>
19
25
  <%= peity_line_chart([115,123,234,-113,-43,-223,127,332,152,233]) %>
20
26
  <%= peity_line_chart(100.times.map{rand(100) * [1,-1].sample}, options: { width: 240, fill: 'lightgreen', stroke: 'blue' }) %>
@@ -36,16 +42,31 @@ Sparklines are small but intense charts. This gem is a wrapper around [peity_van
36
42
  <%= peity_donut_chart [236,300] %>
37
43
  ```
38
44
 
39
- ## Installation
40
- Add this line to your application's Gemfile:
45
+ ## More Examples
41
46
 
42
- ```ruby
43
- gem "peity_vanilla_rails"
44
- ```
47
+ Check the [original](https://github.com/railsjazz/peity_vanilla) page.
45
48
 
46
- And then execute:
47
- ```bash
48
- $ bundle
49
+ <img src="https://github.com/railsjazz/peity_vanilla/raw/main/docs/color.png"/>
50
+ <img src="https://github.com/railsjazz/peity_vanilla/raw/main/docs/custom.png"/>
51
+ <img src="https://github.com/railsjazz/peity_vanilla/raw/main/docs/animation.gif"/>
52
+
53
+ ```html
54
+ <span class="updating-chart">5,3,9,6,5,9,7,3,5,2,5,3,9,6,5,9,7,3,5,2</span>
55
+
56
+ <script>
57
+ var updatingChart = peity(document.getElementById("updating-chart"), "line", { width: 64 });
58
+
59
+ setInterval(function() {
60
+ var random = Math.round(Math.random() * 10)
61
+ // debugger
62
+ var values = updatingChart.innerText.split(",")
63
+ values.shift()
64
+ values.push(random)
65
+
66
+ updatingChart.innerText = values.join(",")
67
+ updatingChart.dispatchEvent(new Event('change'))
68
+ }, 1000);
69
+ </script>
49
70
  ```
50
71
 
51
72
  ## Default Options
@@ -96,8 +117,15 @@ You can pass in `options` any of the attributes.
96
117
  </script>
97
118
  ```
98
119
 
120
+ ## TODO
121
+
122
+ - stimulus, turbo, etc.
123
+ - remote datasource and autoupdate
124
+
99
125
  ## Contributing
100
- Contribution directions go here.
126
+
127
+ You are welcome to contribute.
101
128
 
102
129
  ## License
130
+
103
131
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -1,2 +1,317 @@
1
- !function(t,e){if("object"==typeof exports&&"object"==typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var i,n=e();for(i in n)("object"==typeof exports?exports:t)[i]=n[i]}}(self,()=>(()=>{"use strict";function a(t,e,i){var n;if(s)return n=(t=t).dataset._peity,n=new r(t,e,Object.assign({},a.defaults[e],JSON.parse(t.dataset.peity||"{}"),i)),t.addEventListener("change",function(){n.draw()}),(t.dataset._peity=n).draw(),t}function r(t,e,i){this.$el=t,this.type=e,this.opts=i}var t=r.prototype,M=t.svgElement=function(t,e){var i,n=document.createElementNS("http://www.w3.org/2000/svg",t);for(i in e)n.setAttribute(i,e[i]);return n},s="createElementNS"in document&&M("svg",{}).createSVGRect();return t.draw=function(){var t=this.opts;a.graphers[this.type].call(this,t),t.after&&t.after.call(this,t)},t.isFunction=function(t){return null!==t&&"function"==typeof t&&!!t.apply},t.fill=function(){var i=this.opts.fill;return t.isFunction(i)?i:function(t,e){return i[e%i.length]}},t.prepare=function(t,e){return this.$svg||(this.$el.style.display="none",this.$el.after(this.$svg=M("svg",{class:"peity"}))),this.$svg.innerHTML="",this.$svg.setAttribute("width",t),this.$svg.setAttribute("height",e),this.$svg},t.values=function(){return this.$el.innerText.split(this.opts.delimiter).map(function(t){return parseFloat(t)})},a.defaults={},a.graphers={},a.register=function(t,e,i){this.defaults[t]=e,this.graphers[t]=i},a.register("pie",{fill:["#ff9900","#fff4dd","#ffc66e"],radius:8},function(t){t.delimiter||(l=this.$el.innerText.match(/[^0-9\.]/),t.delimiter=l?l[0]:",");for(var e=this.values().map(function(t){return 0<t?t:0}),i=("/"==t.delimiter&&(l=e[0],r=e[1],e=[l,Math.max(0,r-l)]),0),n=e.length,a=0;i<n;i++)a+=e[i];a||(n=2,e=[0,a=1]);for(var r=2*t.radius,s=this.prepare(t.width||r,t.height||r),l=s.clientWidth,r=s.clientHeight,h=l/2,o=r/2,u=Math.min(h,o),c=t.innerRadius,p=("donut"!=this.type||c||(c=.5*u),Math.PI),f=this.fill(),d=this.scale=function(t,e){t=t/a*p*2-p/2;return[e*Math.cos(t)+h,e*Math.sin(t)+o]},g=0,i=0;i<n;i++){var m,v,y=e[i],x=y/a;0!=x&&((x=1==x?c?M("path",{d:["M",h,v=o-u,"A",u,u,0,1,1,m=h-.01,v,"L",m,v=o-c,"A",c,c,0,1,0,h,v].join(" "),"data-value":y}):M("circle",{cx:h,cy:o,"data-value":y,r:u}):(m=g+y,v=["M"].concat(d(g,u),"A",u,u,0,.5<x?1:0,1,d(m,u),"L"),c?v=v.concat(d(m,c),"A",c,c,0,.5<x?1:0,0,d(g,c)):v.push(h,o),g+=y,M("path",{d:v.join(" "),"data-value":y}))).setAttribute("fill",f.call(this,y,i,e)),s.append(x))}}),a.register("donut",Object.assign(!0,{},a.defaults.pie),function(t){a.graphers.pie.call(this,t)}),a.register("bar",{delimiter:",",fill:["#4D89F9"],height:16,min:0,padding:.1,width:32},function(t){for(var e=this.values(),i=Math.max.apply(Math,null==t.max?e:e.concat(t.max)),n=Math.min.apply(Math,null==t.min?e:e.concat(t.min)),a=this.prepare(t.width,t.height),r=a.clientWidth,s=a.clientHeight,l=i-n,h=t.padding,o=this.fill(),u=this.x=function(t){return t*r/e.length},c=this.y=function(t){return s-(l?(t-n)/l*s:1)},p=0;p<e.length;p++){var f,d=u(p+h),g=u(p+1-h)-d,m=e[p],v=c(m),y=v;l?m<0?y=c(Math.min(i,0)):v=c(Math.max(n,0)):f=1,0==(f=v-y)&&(f=1,0<i&&l&&y--),a.append(M("rect",{"data-value":m,fill:o.call(this,m,p,e),x:d,y:y,width:g,height:f}))}}),a.register("line",{delimiter:",",fill:"#c6d9fd",height:16,min:0,stroke:"#4d89f9",strokeWidth:1,width:32},function(t){for(var e=this.values(),i=(1==e.length&&e.push(e[0]),Math.max.apply(Math,null==t.max?e:e.concat(t.max))),n=Math.min.apply(Math,null==t.min?e:e.concat(t.min)),a=this.prepare(t.width,t.height),r=t.strokeWidth,s=a.clientWidth,l=a.clientHeight-r,h=i-n,o=this.x=function(t){return t*(s/(e.length-1))},u=this.y=function(t){var e=l;return h&&(e-=(t-n)/h*l),e+r/2},i=u(Math.max(n,0)),c=[0,i],p=0;p<e.length;p++)c.push(o(p),u(e[p]));c.push(s,i),t.fill&&a.append(M("polygon",{fill:t.fill,points:c.join(" ")})),r&&a.append(M("polyline",{fill:"none",points:c.slice(2,c.length-2).join(" "),stroke:t.stroke,"stroke-width":r,"stroke-linecap":"square"}))}),window.peity=a,{}})());
2
- //# sourceMappingURL=peity_vanilla.js.map
1
+ /*!
2
+ Peity Vanila JS
3
+ */
4
+
5
+ (function (global, factory) {
6
+ typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
7
+ typeof define === 'function' && define.amd ? define(factory) :
8
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.peity_vanilla = factory());
9
+ })(this, (function () { 'use strict';
10
+
11
+ var peity = function peity(element, type, options) {
12
+ if (svgSupported) {
13
+ var $this = element;
14
+ var chart = new Peity($this, type, Object.assign({}, peity.defaults[type], JSON.parse($this.dataset['peity'] || '{}'), options));
15
+ $this.addEventListener("change", function () {
16
+ chart.draw();
17
+ });
18
+ $this.dataset['_peity'] = "1";
19
+ chart.draw();
20
+ return $this;
21
+ }
22
+ };
23
+
24
+ var Peity = function Peity($el, type, opts) {
25
+ this.$el = $el;
26
+ this.type = type;
27
+ this.opts = opts;
28
+ };
29
+
30
+ var PeityPrototype = Peity.prototype;
31
+
32
+ var svgElement = PeityPrototype.svgElement = function (tag, attrs) {
33
+ var element = document.createElementNS('http://www.w3.org/2000/svg', tag);
34
+
35
+ for (var attr in attrs) {
36
+ element.setAttribute(attr, attrs[attr]);
37
+ }
38
+
39
+ return element;
40
+ }; // https://gist.github.com/madrobby/3201472
41
+
42
+
43
+ var svgSupported = 'createElementNS' in document && svgElement('svg', {}).createSVGRect();
44
+
45
+ PeityPrototype.draw = function () {
46
+ var opts = this.opts;
47
+ peity.graphers[this.type].call(this, opts);
48
+ if (opts.after) opts.after.call(this, opts);
49
+ };
50
+
51
+ PeityPrototype.isFunction = function (o) {
52
+ return null !== o && "function" === typeof o && !!o.apply;
53
+ };
54
+
55
+ PeityPrototype.fill = function () {
56
+ var fill = this.opts.fill;
57
+ return PeityPrototype.isFunction(fill) ? fill : function (_, i) {
58
+ return fill[i % fill.length];
59
+ };
60
+ };
61
+
62
+ PeityPrototype.prepare = function (width, height) {
63
+ if (!this.$svg) {
64
+ this.$el.style.display = 'none';
65
+ this.$el.after(this.$svg = svgElement('svg', {
66
+ "class": "peity"
67
+ }));
68
+ }
69
+
70
+ this.$svg.innerHTML = "";
71
+ this.$svg.setAttribute("width", width);
72
+ this.$svg.setAttribute("height", height);
73
+ return this.$svg;
74
+ };
75
+
76
+ PeityPrototype.values = function () {
77
+ return this.$el.innerText.split(this.opts.delimiter).map(function (value) {
78
+ return parseFloat(value);
79
+ });
80
+ };
81
+
82
+ peity.defaults = {};
83
+ peity.graphers = {};
84
+
85
+ peity.register = function (type, defaults, grapher) {
86
+ this.defaults[type] = defaults;
87
+ this.graphers[type] = grapher;
88
+ };
89
+
90
+ peity.register('pie', {
91
+ fill: ['#ff9900', '#fff4dd', '#ffc66e'],
92
+ radius: 8
93
+ }, function (opts) {
94
+ if (!opts.delimiter) {
95
+ var delimiter = this.$el.innerText.match(/[^0-9\.]/);
96
+ opts.delimiter = delimiter ? delimiter[0] : ",";
97
+ }
98
+
99
+ var values = this.values().map(function (n) {
100
+ return n > 0 ? n : 0;
101
+ });
102
+
103
+ if (opts.delimiter == "/") {
104
+ var v1 = values[0];
105
+ var v2 = values[1];
106
+ values = [v1, Math.max(0, v2 - v1)];
107
+ }
108
+
109
+ var i = 0;
110
+ var length = values.length;
111
+ var sum = 0;
112
+
113
+ for (; i < length; i++) {
114
+ sum += values[i];
115
+ }
116
+
117
+ if (!sum) {
118
+ length = 2;
119
+ sum = 1;
120
+ values = [0, 1];
121
+ }
122
+
123
+ var diameter = opts.radius * 2;
124
+ var $svg = this.prepare(opts.width || diameter, opts.height || diameter);
125
+ var width = $svg.clientWidth,
126
+ height = $svg.clientHeight,
127
+ cx = width / 2,
128
+ cy = height / 2;
129
+ var radius = Math.min(cx, cy),
130
+ innerRadius = opts.innerRadius;
131
+
132
+ if (this.type == 'donut' && !innerRadius) {
133
+ innerRadius = radius * 0.5;
134
+ }
135
+
136
+ var pi = Math.PI;
137
+ var fill = this.fill();
138
+
139
+ var scale = this.scale = function (value, radius) {
140
+ var radians = value / sum * pi * 2 - pi / 2;
141
+ return [radius * Math.cos(radians) + cx, radius * Math.sin(radians) + cy];
142
+ };
143
+
144
+ var cumulative = 0;
145
+
146
+ for (i = 0; i < length; i++) {
147
+ var value = values[i],
148
+ portion = value / sum,
149
+ $node;
150
+ if (portion == 0) continue;
151
+
152
+ if (portion == 1) {
153
+ if (innerRadius) {
154
+ var x2 = cx - 0.01,
155
+ y1 = cy - radius,
156
+ y2 = cy - innerRadius;
157
+ $node = svgElement('path', {
158
+ d: ['M', cx, y1, 'A', radius, radius, 0, 1, 1, x2, y1, 'L', x2, y2, 'A', innerRadius, innerRadius, 0, 1, 0, cx, y2].join(' '),
159
+ 'data-value': value
160
+ });
161
+ } else {
162
+ $node = svgElement('circle', {
163
+ cx: cx,
164
+ cy: cy,
165
+ 'data-value': value,
166
+ r: radius
167
+ });
168
+ }
169
+ } else {
170
+ var cumulativePlusValue = cumulative + value;
171
+ var d = ['M'].concat(scale(cumulative, radius), 'A', radius, radius, 0, portion > 0.5 ? 1 : 0, 1, scale(cumulativePlusValue, radius), 'L');
172
+
173
+ if (innerRadius) {
174
+ d = d.concat(scale(cumulativePlusValue, innerRadius), 'A', innerRadius, innerRadius, 0, portion > 0.5 ? 1 : 0, 0, scale(cumulative, innerRadius));
175
+ } else {
176
+ d.push(cx, cy);
177
+ }
178
+
179
+ cumulative += value;
180
+ $node = svgElement('path', {
181
+ d: d.join(" "),
182
+ 'data-value': value
183
+ });
184
+ }
185
+
186
+ $node.setAttribute('fill', fill.call(this, value, i, values));
187
+ $svg.append($node);
188
+ }
189
+ });
190
+ peity.register('donut', Object.assign(true, {}, peity.defaults.pie), function (opts) {
191
+ peity.graphers.pie.call(this, opts);
192
+ });
193
+ peity.register('bar', {
194
+ delimiter: ",",
195
+ fill: ["#4D89F9"],
196
+ height: 16,
197
+ min: 0,
198
+ padding: 0.1,
199
+ width: 32
200
+ }, function (opts) {
201
+ var values = this.values(),
202
+ max = Math.max.apply(Math, opts.max == undefined ? values : values.concat(opts.max)),
203
+ min = Math.min.apply(Math, opts.min == undefined ? values : values.concat(opts.min));
204
+ var $svg = this.prepare(opts.width, opts.height),
205
+ width = $svg.clientWidth,
206
+ height = $svg.clientHeight,
207
+ diff = max - min,
208
+ padding = opts.padding,
209
+ fill = this.fill();
210
+
211
+ var xScale = this.x = function (input) {
212
+ return input * width / values.length;
213
+ };
214
+
215
+ var yScale = this.y = function (input) {
216
+ return height - (diff ? (input - min) / diff * height : 1);
217
+ };
218
+
219
+ for (var i = 0; i < values.length; i++) {
220
+ var x = xScale(i + padding),
221
+ w = xScale(i + 1 - padding) - x,
222
+ value = values[i],
223
+ valueY = yScale(value),
224
+ y1 = valueY,
225
+ y2 = valueY,
226
+ h;
227
+
228
+ if (!diff) {
229
+ h = 1;
230
+ } else if (value < 0) {
231
+ y1 = yScale(Math.min(max, 0));
232
+ } else {
233
+ y2 = yScale(Math.max(min, 0));
234
+ }
235
+
236
+ h = y2 - y1;
237
+
238
+ if (h == 0) {
239
+ h = 1;
240
+ if (max > 0 && diff) y1--;
241
+ }
242
+
243
+ $svg.append(svgElement('rect', {
244
+ 'data-value': value,
245
+ fill: fill.call(this, value, i, values),
246
+ x: x,
247
+ y: y1,
248
+ width: w,
249
+ height: h
250
+ }));
251
+ }
252
+ });
253
+ peity.register("line", {
254
+ delimiter: ",",
255
+ fill: "#c6d9fd",
256
+ height: 16,
257
+ min: 0,
258
+ stroke: "#4d89f9",
259
+ strokeWidth: 1,
260
+ width: 32
261
+ }, function (opts) {
262
+ var values = this.values();
263
+ if (values.length == 1) values.push(values[0]);
264
+ var max = Math.max.apply(Math, opts.max == undefined ? values : values.concat(opts.max)),
265
+ min = Math.min.apply(Math, opts.min == undefined ? values : values.concat(opts.min));
266
+ var $svg = this.prepare(opts.width, opts.height),
267
+ strokeWidth = opts.strokeWidth,
268
+ width = $svg.clientWidth,
269
+ height = $svg.clientHeight - strokeWidth,
270
+ diff = max - min;
271
+
272
+ var xScale = this.x = function (input) {
273
+ return input * (width / (values.length - 1));
274
+ };
275
+
276
+ var yScale = this.y = function (input) {
277
+ var y = height;
278
+
279
+ if (diff) {
280
+ y -= (input - min) / diff * height;
281
+ }
282
+
283
+ return y + strokeWidth / 2;
284
+ };
285
+
286
+ var zero = yScale(Math.max(min, 0)),
287
+ coords = [0, zero];
288
+
289
+ for (var i = 0; i < values.length; i++) {
290
+ coords.push(xScale(i), yScale(values[i]));
291
+ }
292
+
293
+ coords.push(width, zero);
294
+
295
+ if (opts.fill) {
296
+ $svg.append(svgElement('polygon', {
297
+ fill: opts.fill,
298
+ points: coords.join(' ')
299
+ }));
300
+ }
301
+
302
+ if (strokeWidth) {
303
+ $svg.append(svgElement('polyline', {
304
+ fill: 'none',
305
+ points: coords.slice(2, coords.length - 2).join(' '),
306
+ stroke: opts.stroke,
307
+ 'stroke-width': strokeWidth,
308
+ 'stroke-linecap': 'square'
309
+ }));
310
+ }
311
+ });
312
+ var index = window.peity = peity;
313
+
314
+ return index;
315
+
316
+ }));
317
+ //# sourceMappingURL=peity_vanilla.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["webpack://piety_vanilla/webpack/universalModuleDefinition","webpack://piety_vanilla/./src/index.js"],"names":["root","factory","exports","module","define","amd","i","a","self","peity","element","type","options","chart","svgSupported","$this","dataset","Peity","Object","assign","defaults","JSON","parse","addEventListener","draw","$el","opts","this","PeityPrototype","prototype","svgElement","tag","attrs","attr","document","createElementNS","setAttribute","createSVGRect","graphers","call","after","isFunction","o","apply","fill","_","length","prepare","width","height","$svg","style","display","innerHTML","values","innerText","split","delimiter","map","value","parseFloat","register","grapher","radius","match","n","v1","v2","Math","max","sum","diameter","clientWidth","clientHeight","cx","cy","min","innerRadius","pi","PI","scale","radians","cos","sin","cumulative","cumulativePlusValue","d","portion","$node","y1","x2","y2","join","r","concat","push","append","pie","padding","undefined","diff","xScale","x","input","yScale","y","h","w","valueY","stroke","strokeWidth","zero","coords","points","slice","window"],"mappings":"CAAA,SAA2CA,EAAMC,GAChD,GAAsB,iBAAZC,SAA0C,iBAAXC,OACxCA,OAAOD,QAAUD,SACb,GAAqB,mBAAXG,QAAyBA,OAAOC,IAC9CD,OAAO,GAAIH,OACP,CACJ,IACQK,EADJC,EAAIN,IACR,IAAQK,KAAKC,GAAuB,iBAAZL,QAAuBA,QAAUF,GAAMM,GAAKC,EAAED,IAPxE,CASGE,KAAM,K,kBCPG,SAARC,EAAiBC,EAASC,EAAMC,GAClC,IAIEC,EAJF,GAAIC,EAiBF,OAfID,GADAE,EAAQL,GACMM,QAAgB,OAElCH,EAAQ,IAAII,EACVF,EACAJ,EACAO,OAAOC,OAAO,GACZV,EAAMW,SAAST,GACfU,KAAKC,MAAMP,EAAMC,QAAe,OAAK,MACrCJ,IAGJG,EAAMQ,iBAAiB,SAAU,WAAaV,EAAMW,UACpDT,EAAMC,QAAgB,OAAIH,GAEpBW,OACCT,EAIC,SAARE,EAAiBQ,EAAKd,EAAMe,GAC9BC,KAAKF,IAAMA,EACXE,KAAKhB,KAAOA,EACZgB,KAAKD,KAAOA,E,IAGVE,EAAiBX,EAAMY,UAEvBC,EAAaF,EAAeE,WAAa,SAASC,EAAKC,GACzD,IACQC,EADJvB,EAAUwB,SAASC,gBAAgB,6BAA8BJ,GACrE,IAAQE,KAAQD,EACdtB,EAAQ0B,aAAaH,EAAMD,EAAMC,IAEnC,OAAOvB,GAILI,EAAe,oBAAqBoB,UAAYJ,EAAW,MAAO,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OpE,EAAKkD,MAE/E1B,EAAOvB,KAAKoB,QAAQrB,EAAKsB,MAAOtB,EAAKuB,QACrC6D,EAAcpF,EAAKoF,YACnB9D,EAAQE,EAAKsB,YACbvB,EAASC,EAAKuB,aAAeqC,EAC7BV,EAAO/B,EAAMO,EAEbyB,EAAS1E,KAAK2E,EAAI,SAASC,GAC7B,OAAOA,GAASvD,GAASM,EAAOR,OAAS,KAGvC0D,EAAS7E,KAAK8E,EAAI,SAASF,GAC7B,IAAIE,EAAIxD,EAMR,OAJImD,IACFK,IAAOF,EAAQ3B,GAAOwB,EAAQnD,GAGzBwD,EAAIK,EAAc,GAGvBC,EAAOP,EAAOpC,KAAKC,IAAIO,EAAK,IAC5BoC,EAAS,CAAC,EAAGD,GAERzG,EAAI,EAAGA,EAAIgD,EAAOR,OAAQxC,IACjC0G,EAAOjB,KACLM,EAAO/F,GACPkG,EAAOlD,EAAOhD,KAIlB0G,EAAOjB,KAAK/C,EAAO+D,GAEfrF,EAAKkB,MACPM,EAAK8C,OACHlE,EAAW,UAAW,CACpBc,KAAMlB,EAAKkB,KACXqE,OAAQD,EAAOpB,KAAK,QAKtBkB,GACF5D,EAAK8C,OACHlE,EAAW,WAAY,CACrBc,KAAM,OACNqE,OAAQD,EAAOE,MAAM,EAAGF,EAAOlE,OAAS,GAAG8C,KAAK,KAChDiB,OAAQnF,EAAKmF,OACb,eAAgBC,EAChB,iBAAkB,cAQ5BK,OAAO1G,MAAQA,E","file":"peity_vanilla.js","sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([], factory);\n\telse {\n\t\tvar a = factory();\n\t\tfor(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i];\n\t}\n})(self, () => {\nreturn ","\"use strict\";\r\n\r\nvar peity = function(element, type, options) {\r\n if (svgSupported) {\r\n var $this = element\r\n var chart = $this.dataset['_peity']\r\n\r\n chart = new Peity(\r\n $this,\r\n type,\r\n Object.assign({},\r\n peity.defaults[type],\r\n JSON.parse($this.dataset['peity'] || '{}'),\r\n options)\r\n )\r\n\r\n $this.addEventListener(\"change\", function() { chart.draw() })\r\n $this.dataset['_peity'] = chart\r\n\r\n chart.draw()\r\n return $this;\r\n }\r\n};\r\n\r\nvar Peity = function($el, type, opts) {\r\n this.$el = $el\r\n this.type = type\r\n this.opts = opts\r\n}\r\n\r\nvar PeityPrototype = Peity.prototype\r\n\r\nvar svgElement = PeityPrototype.svgElement = function(tag, attrs) {\r\n var element = document.createElementNS('http://www.w3.org/2000/svg', tag)\r\n for(var attr in attrs) {\r\n element.setAttribute(attr, attrs[attr])\r\n }\r\n return element;\r\n}\r\n\r\n// https://gist.github.com/madrobby/3201472\r\nvar svgSupported = 'createElementNS' in document && svgElement('svg', {}).createSVGRect()\r\n\r\nPeityPrototype.draw = function() {\r\n var opts = this.opts\r\n peity.graphers[this.type].call(this, opts)\r\n if (opts.after) opts.after.call(this, opts)\r\n}\r\n\r\nPeityPrototype.isFunction = function(o) { return null !== o && \"function\" === typeof o && !!o.apply; }\r\n\r\nPeityPrototype.fill = function() {\r\n var fill = this.opts.fill\r\n\r\n return PeityPrototype.isFunction(fill)\r\n ? fill\r\n : function(_, i) { return fill[i % fill.length] }\r\n}\r\n\r\nPeityPrototype.prepare = function(width, height) {\r\n if (!this.$svg) {\r\n this.$el.style.display = 'none'\r\n this.$el.after(\r\n this.$svg = svgElement('svg', {\r\n \"class\": \"peity\"\r\n })\r\n )\r\n }\r\n\r\n this.$svg.innerHTML = \"\";\r\n this.$svg.setAttribute(\"width\", width)\r\n this.$svg.setAttribute(\"height\", height)\r\n\r\n return this.$svg;\r\n}\r\n\r\nPeityPrototype.values = function() {\r\n return this.$el.innerText.split(this.opts.delimiter).map(function(value) {\r\n return parseFloat(value)\r\n })\r\n}\r\n\r\npeity.defaults = {}\r\npeity.graphers = {}\r\n\r\npeity.register = function(type, defaults, grapher) {\r\n this.defaults[type] = defaults\r\n this.graphers[type] = grapher\r\n}\r\n\r\npeity.register(\r\n 'pie',\r\n {\r\n fill: ['#ff9900', '#fff4dd', '#ffc66e'],\r\n radius: 8\r\n },\r\n function(opts) {\r\n if (!opts.delimiter) {\r\n var delimiter = this.$el.innerText.match(/[^0-9\\.]/)\r\n opts.delimiter = delimiter ? delimiter[0] : \",\"\r\n }\r\n\r\n var values = this.values().map(function(n) {\r\n return n > 0 ? n : 0\r\n });\r\n\r\n if (opts.delimiter == \"/\") {\r\n var v1 = values[0]\r\n var v2 = values[1]\r\n values = [v1, Math.max(0, v2 - v1)]\r\n }\r\n\r\n var i = 0\r\n var length = values.length\r\n var sum = 0\r\n\r\n for (; i < length; i++) {\r\n sum += values[i]\r\n }\r\n\r\n if (!sum) {\r\n length = 2\r\n sum = 1\r\n values = [0, 1]\r\n }\r\n\r\n var diameter = opts.radius * 2\r\n\r\n var $svg = this.prepare(\r\n opts.width || diameter,\r\n opts.height || diameter\r\n )\r\n\r\n var width = $svg.clientWidth\r\n , height = $svg.clientHeight\r\n , cx = width / 2\r\n , cy = height / 2\r\n\r\n var radius = Math.min(cx, cy)\r\n , innerRadius = opts.innerRadius\r\n\r\n if (this.type == 'donut' && !innerRadius) {\r\n innerRadius = radius * 0.5\r\n }\r\n\r\n var pi = Math.PI\r\n var fill = this.fill()\r\n\r\n var scale = this.scale = function(value, radius) {\r\n var radians = value / sum * pi * 2 - pi / 2\r\n\r\n return [\r\n radius * Math.cos(radians) + cx,\r\n radius * Math.sin(radians) + cy\r\n ]\r\n }\r\n\r\n var cumulative = 0\r\n\r\n for (i = 0; i < length; i++) {\r\n var value = values[i]\r\n , portion = value / sum\r\n , $node\r\n\r\n if (portion == 0) continue\r\n\r\n if (portion == 1) {\r\n if (innerRadius) {\r\n var x2 = cx - 0.01\r\n , y1 = cy - radius\r\n , y2 = cy - innerRadius\r\n\r\n $node = svgElement('path', {\r\n d: [\r\n 'M', cx, y1,\r\n 'A', radius, radius, 0, 1, 1, x2, y1,\r\n 'L', x2, y2,\r\n 'A', innerRadius, innerRadius, 0, 1, 0, cx, y2\r\n ].join(' '),\r\n 'data-value': value,\r\n })\r\n } else {\r\n $node = svgElement('circle', {\r\n cx: cx,\r\n cy: cy,\r\n 'data-value': value,\r\n r: radius\r\n })\r\n }\r\n } else {\r\n var cumulativePlusValue = cumulative + value\r\n\r\n var d = ['M'].concat(\r\n scale(cumulative, radius),\r\n 'A', radius, radius, 0, portion > 0.5 ? 1 : 0, 1,\r\n scale(cumulativePlusValue, radius),\r\n 'L'\r\n )\r\n\r\n if (innerRadius) {\r\n d = d.concat(\r\n scale(cumulativePlusValue, innerRadius),\r\n 'A', innerRadius, innerRadius, 0, portion > 0.5 ? 1 : 0, 0,\r\n scale(cumulative, innerRadius)\r\n )\r\n } else {\r\n d.push(cx, cy)\r\n }\r\n\r\n cumulative += value\r\n\r\n $node = svgElement('path', {\r\n d: d.join(\" \"),\r\n 'data-value': value,\r\n })\r\n }\r\n\r\n $node.setAttribute('fill', fill.call(this, value, i, values))\r\n\r\n $svg.append($node)\r\n }\r\n }\r\n)\r\n\r\npeity.register(\r\n 'donut',\r\n Object.assign(true, {}, peity.defaults.pie),\r\n function(opts) {\r\n peity.graphers.pie.call(this, opts)\r\n }\r\n)\r\n\r\npeity.register(\r\n 'bar',\r\n {\r\n delimiter: \",\",\r\n fill: [\"#4D89F9\"],\r\n height: 16,\r\n min: 0,\r\n padding: 0.1,\r\n width: 32\r\n },\r\n function(opts) {\r\n var values = this.values()\r\n , max = Math.max.apply(Math, opts.max == undefined ? values : values.concat(opts.max))\r\n , min = Math.min.apply(Math, opts.min == undefined ? values : values.concat(opts.min))\r\n\r\n var $svg = this.prepare(opts.width, opts.height)\r\n , width = $svg.clientWidth\r\n , height = $svg.clientHeight\r\n , diff = max - min\r\n , padding = opts.padding\r\n , fill = this.fill()\r\n\r\n var xScale = this.x = function(input) {\r\n return input * width / values.length\r\n }\r\n\r\n var yScale = this.y = function(input) {\r\n return height - (\r\n diff\r\n ? ((input - min) / diff) * height\r\n : 1\r\n )\r\n }\r\n\r\n for (var i = 0; i < values.length; i++) {\r\n var x = xScale(i + padding)\r\n , w = xScale(i + 1 - padding) - x\r\n , value = values[i]\r\n , valueY = yScale(value)\r\n , y1 = valueY\r\n , y2 = valueY\r\n , h\r\n\r\n if (!diff) {\r\n h = 1\r\n } else if (value < 0) {\r\n y1 = yScale(Math.min(max, 0))\r\n } else {\r\n y2 = yScale(Math.max(min, 0))\r\n }\r\n\r\n h = y2 - y1\r\n\r\n if (h == 0) {\r\n h = 1\r\n if (max > 0 && diff) y1--\r\n }\r\n\r\n $svg.append(\r\n svgElement('rect', {\r\n 'data-value': value,\r\n fill: fill.call(this, value, i, values),\r\n x: x,\r\n y: y1,\r\n width: w,\r\n height: h\r\n })\r\n )\r\n }\r\n }\r\n);\r\n\r\npeity.register(\r\n \"line\",\r\n {\r\n delimiter: \",\",\r\n fill: \"#c6d9fd\",\r\n height: 16,\r\n min: 0,\r\n stroke: \"#4d89f9\",\r\n strokeWidth: 1,\r\n width: 32\r\n },\r\n function(opts) {\r\n var values = this.values()\r\n if (values.length == 1) values.push(values[0])\r\n var max = Math.max.apply(Math, opts.max == undefined ? values : values.concat(opts.max))\r\n , min = Math.min.apply(Math, opts.min == undefined ? values : values.concat(opts.min))\r\n\r\n var $svg = this.prepare(opts.width, opts.height)\r\n , strokeWidth = opts.strokeWidth\r\n , width = $svg.clientWidth\r\n , height = $svg.clientHeight - strokeWidth\r\n , diff = max - min\r\n\r\n var xScale = this.x = function(input) {\r\n return input * (width / (values.length - 1))\r\n }\r\n\r\n var yScale = this.y = function(input) {\r\n var y = height\r\n\r\n if (diff) {\r\n y -= ((input - min) / diff) * height\r\n }\r\n\r\n return y + strokeWidth / 2\r\n }\r\n\r\n var zero = yScale(Math.max(min, 0))\r\n , coords = [0, zero]\r\n\r\n for (var i = 0; i < values.length; i++) {\r\n coords.push(\r\n xScale(i),\r\n yScale(values[i])\r\n )\r\n }\r\n\r\n coords.push(width, zero)\r\n\r\n if (opts.fill) {\r\n $svg.append(\r\n svgElement('polygon', {\r\n fill: opts.fill,\r\n points: coords.join(' ')\r\n })\r\n )\r\n }\r\n\r\n if (strokeWidth) {\r\n $svg.append(\r\n svgElement('polyline', {\r\n fill: 'none',\r\n points: coords.slice(2, coords.length - 2).join(' '),\r\n stroke: opts.stroke,\r\n 'stroke-width': strokeWidth,\r\n 'stroke-linecap': 'square'\r\n })\r\n )\r\n }\r\n }\r\n);\r\n\r\n// rework?\r\nwindow.peity = peity;"],"sourceRoot":""}
1
+ {"version":3,"file":"peity_vanilla.js","sources":["../src/index.js"],"sourcesContent":["\"use strict\";\r\n\r\nvar peity = function(element, type, options) {\r\n if (svgSupported) {\r\n var $this = element\r\n\r\n var chart = new Peity(\r\n $this,\r\n type,\r\n Object.assign({},\r\n peity.defaults[type],\r\n JSON.parse($this.dataset['peity'] || '{}'),\r\n options)\r\n )\r\n\r\n $this.addEventListener(\"change\", function() { chart.draw() })\r\n $this.dataset['_peity'] = \"1\"\r\n\r\n chart.draw()\r\n return $this;\r\n }\r\n};\r\n\r\nvar Peity = function($el, type, opts) {\r\n this.$el = $el\r\n this.type = type\r\n this.opts = opts\r\n}\r\n\r\nvar PeityPrototype = Peity.prototype\r\n\r\nvar svgElement = PeityPrototype.svgElement = function(tag, attrs) {\r\n var element = document.createElementNS('http://www.w3.org/2000/svg', tag)\r\n for(var attr in attrs) {\r\n element.setAttribute(attr, attrs[attr])\r\n }\r\n return element;\r\n}\r\n\r\n// https://gist.github.com/madrobby/3201472\r\nvar svgSupported = 'createElementNS' in document && svgElement('svg', {}).createSVGRect()\r\n\r\nPeityPrototype.draw = function() {\r\n var opts = this.opts\r\n peity.graphers[this.type].call(this, opts)\r\n if (opts.after) opts.after.call(this, opts)\r\n}\r\n\r\nPeityPrototype.isFunction = function(o) { return null !== o && \"function\" === typeof o && !!o.apply; }\r\n\r\nPeityPrototype.fill = function() {\r\n var fill = this.opts.fill\r\n\r\n return PeityPrototype.isFunction(fill)\r\n ? fill\r\n : function(_, i) { return fill[i % fill.length] }\r\n}\r\n\r\nPeityPrototype.prepare = function(width, height) {\r\n if (!this.$svg) {\r\n this.$el.style.display = 'none'\r\n this.$el.after(\r\n this.$svg = svgElement('svg', {\r\n \"class\": \"peity\"\r\n })\r\n )\r\n }\r\n\r\n this.$svg.innerHTML = \"\";\r\n this.$svg.setAttribute(\"width\", width)\r\n this.$svg.setAttribute(\"height\", height)\r\n\r\n return this.$svg;\r\n}\r\n\r\nPeityPrototype.values = function() {\r\n return this.$el.innerText.split(this.opts.delimiter).map(function(value) {\r\n return parseFloat(value)\r\n })\r\n}\r\n\r\npeity.defaults = {}\r\npeity.graphers = {}\r\n\r\npeity.register = function(type, defaults, grapher) {\r\n this.defaults[type] = defaults\r\n this.graphers[type] = grapher\r\n}\r\n\r\npeity.register(\r\n 'pie',\r\n {\r\n fill: ['#ff9900', '#fff4dd', '#ffc66e'],\r\n radius: 8\r\n },\r\n function(opts) {\r\n if (!opts.delimiter) {\r\n var delimiter = this.$el.innerText.match(/[^0-9\\.]/)\r\n opts.delimiter = delimiter ? delimiter[0] : \",\"\r\n }\r\n\r\n var values = this.values().map(function(n) {\r\n return n > 0 ? n : 0\r\n });\r\n\r\n if (opts.delimiter == \"/\") {\r\n var v1 = values[0]\r\n var v2 = values[1]\r\n values = [v1, Math.max(0, v2 - v1)]\r\n }\r\n\r\n var i = 0\r\n var length = values.length\r\n var sum = 0\r\n\r\n for (; i < length; i++) {\r\n sum += values[i]\r\n }\r\n\r\n if (!sum) {\r\n length = 2\r\n sum = 1\r\n values = [0, 1]\r\n }\r\n\r\n var diameter = opts.radius * 2\r\n\r\n var $svg = this.prepare(\r\n opts.width || diameter,\r\n opts.height || diameter\r\n )\r\n\r\n var width = $svg.clientWidth\r\n , height = $svg.clientHeight\r\n , cx = width / 2\r\n , cy = height / 2\r\n\r\n var radius = Math.min(cx, cy)\r\n , innerRadius = opts.innerRadius\r\n\r\n if (this.type == 'donut' && !innerRadius) {\r\n innerRadius = radius * 0.5\r\n }\r\n\r\n var pi = Math.PI\r\n var fill = this.fill()\r\n\r\n var scale = this.scale = function(value, radius) {\r\n var radians = value / sum * pi * 2 - pi / 2\r\n\r\n return [\r\n radius * Math.cos(radians) + cx,\r\n radius * Math.sin(radians) + cy\r\n ]\r\n }\r\n\r\n var cumulative = 0\r\n\r\n for (i = 0; i < length; i++) {\r\n var value = values[i]\r\n , portion = value / sum\r\n , $node\r\n\r\n if (portion == 0) continue\r\n\r\n if (portion == 1) {\r\n if (innerRadius) {\r\n var x2 = cx - 0.01\r\n , y1 = cy - radius\r\n , y2 = cy - innerRadius\r\n\r\n $node = svgElement('path', {\r\n d: [\r\n 'M', cx, y1,\r\n 'A', radius, radius, 0, 1, 1, x2, y1,\r\n 'L', x2, y2,\r\n 'A', innerRadius, innerRadius, 0, 1, 0, cx, y2\r\n ].join(' '),\r\n 'data-value': value,\r\n })\r\n } else {\r\n $node = svgElement('circle', {\r\n cx: cx,\r\n cy: cy,\r\n 'data-value': value,\r\n r: radius\r\n })\r\n }\r\n } else {\r\n var cumulativePlusValue = cumulative + value\r\n\r\n var d = ['M'].concat(\r\n scale(cumulative, radius),\r\n 'A', radius, radius, 0, portion > 0.5 ? 1 : 0, 1,\r\n scale(cumulativePlusValue, radius),\r\n 'L'\r\n )\r\n\r\n if (innerRadius) {\r\n d = d.concat(\r\n scale(cumulativePlusValue, innerRadius),\r\n 'A', innerRadius, innerRadius, 0, portion > 0.5 ? 1 : 0, 0,\r\n scale(cumulative, innerRadius)\r\n )\r\n } else {\r\n d.push(cx, cy)\r\n }\r\n\r\n cumulative += value\r\n\r\n $node = svgElement('path', {\r\n d: d.join(\" \"),\r\n 'data-value': value,\r\n })\r\n }\r\n\r\n $node.setAttribute('fill', fill.call(this, value, i, values))\r\n\r\n $svg.append($node)\r\n }\r\n }\r\n)\r\n\r\npeity.register(\r\n 'donut',\r\n Object.assign(true, {}, peity.defaults.pie),\r\n function(opts) {\r\n peity.graphers.pie.call(this, opts)\r\n }\r\n)\r\n\r\npeity.register(\r\n 'bar',\r\n {\r\n delimiter: \",\",\r\n fill: [\"#4D89F9\"],\r\n height: 16,\r\n min: 0,\r\n padding: 0.1,\r\n width: 32\r\n },\r\n function(opts) {\r\n var values = this.values()\r\n , max = Math.max.apply(Math, opts.max == undefined ? values : values.concat(opts.max))\r\n , min = Math.min.apply(Math, opts.min == undefined ? values : values.concat(opts.min))\r\n\r\n var $svg = this.prepare(opts.width, opts.height)\r\n , width = $svg.clientWidth\r\n , height = $svg.clientHeight\r\n , diff = max - min\r\n , padding = opts.padding\r\n , fill = this.fill()\r\n\r\n var xScale = this.x = function(input) {\r\n return input * width / values.length\r\n }\r\n\r\n var yScale = this.y = function(input) {\r\n return height - (\r\n diff\r\n ? ((input - min) / diff) * height\r\n : 1\r\n )\r\n }\r\n\r\n for (var i = 0; i < values.length; i++) {\r\n var x = xScale(i + padding)\r\n , w = xScale(i + 1 - padding) - x\r\n , value = values[i]\r\n , valueY = yScale(value)\r\n , y1 = valueY\r\n , y2 = valueY\r\n , h\r\n\r\n if (!diff) {\r\n h = 1\r\n } else if (value < 0) {\r\n y1 = yScale(Math.min(max, 0))\r\n } else {\r\n y2 = yScale(Math.max(min, 0))\r\n }\r\n\r\n h = y2 - y1\r\n\r\n if (h == 0) {\r\n h = 1\r\n if (max > 0 && diff) y1--\r\n }\r\n\r\n $svg.append(\r\n svgElement('rect', {\r\n 'data-value': value,\r\n fill: fill.call(this, value, i, values),\r\n x: x,\r\n y: y1,\r\n width: w,\r\n height: h\r\n })\r\n )\r\n }\r\n }\r\n);\r\n\r\npeity.register(\r\n \"line\",\r\n {\r\n delimiter: \",\",\r\n fill: \"#c6d9fd\",\r\n height: 16,\r\n min: 0,\r\n stroke: \"#4d89f9\",\r\n strokeWidth: 1,\r\n width: 32\r\n },\r\n function(opts) {\r\n var values = this.values()\r\n if (values.length == 1) values.push(values[0])\r\n var max = Math.max.apply(Math, opts.max == undefined ? values : values.concat(opts.max))\r\n , min = Math.min.apply(Math, opts.min == undefined ? values : values.concat(opts.min))\r\n\r\n var $svg = this.prepare(opts.width, opts.height)\r\n , strokeWidth = opts.strokeWidth\r\n , width = $svg.clientWidth\r\n , height = $svg.clientHeight - strokeWidth\r\n , diff = max - min\r\n\r\n var xScale = this.x = function(input) {\r\n return input * (width / (values.length - 1))\r\n }\r\n\r\n var yScale = this.y = function(input) {\r\n var y = height\r\n\r\n if (diff) {\r\n y -= ((input - min) / diff) * height\r\n }\r\n\r\n return y + strokeWidth / 2\r\n }\r\n\r\n var zero = yScale(Math.max(min, 0))\r\n , coords = [0, zero]\r\n\r\n for (var i = 0; i < values.length; i++) {\r\n coords.push(\r\n xScale(i),\r\n yScale(values[i])\r\n )\r\n }\r\n\r\n coords.push(width, zero)\r\n\r\n if (opts.fill) {\r\n $svg.append(\r\n svgElement('polygon', {\r\n fill: opts.fill,\r\n points: coords.join(' ')\r\n })\r\n )\r\n }\r\n\r\n if (strokeWidth) {\r\n $svg.append(\r\n svgElement('polyline', {\r\n fill: 'none',\r\n points: coords.slice(2, coords.length - 2).join(' '),\r\n stroke: opts.stroke,\r\n 'stroke-width': strokeWidth,\r\n 'stroke-linecap': 'square'\r\n })\r\n )\r\n }\r\n }\r\n);\r\n\r\nexport default window.peity = peity;"],"names":["peity","element","type","options","svgSupported","$this","chart","Peity","Object","assign","defaults","JSON","parse","dataset","addEventListener","draw","$el","opts","PeityPrototype","prototype","svgElement","tag","attrs","document","createElementNS","attr","setAttribute","createSVGRect","graphers","call","after","isFunction","o","apply","fill","_","i","length","prepare","width","height","$svg","style","display","innerHTML","values","innerText","split","delimiter","map","value","parseFloat","register","grapher","radius","match","n","v1","v2","Math","max","sum","diameter","clientWidth","clientHeight","cx","cy","min","innerRadius","pi","PI","scale","radians","cos","sin","cumulative","portion","$node","x2","y1","y2","d","join","r","cumulativePlusValue","concat","push","append","pie","padding","undefined","diff","xScale","x","input","yScale","y","w","valueY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BkB,MAAM,EAAEnF,IAAI,CAACmF,MAHQ;EAIrB,MAAA,cAAA,EAAgBC,WAJK;QAKrB,gBAAkB,EAAA,QAAA;EALG,KAAb,CADZ,CAAA,CAAA;EASD,GAAA;EACF,CArEH,CAAA,CAAA;AAwEA,cAAeK,MAAM,CAAC1G,KAAP,GAAeA,KAA9B;;;;;;;;"}
@@ -26,7 +26,23 @@ module PeityVanillaRails
26
26
  end,
27
27
  tag.script do
28
28
  %Q{
29
- peity(document.getElementById("#{id}"), "#{type}");
29
+ function init_peity_charts_#{id}() {
30
+ var element = document.getElementById("#{id}");
31
+
32
+ if (!element) {
33
+ return;
34
+ }
35
+
36
+ if(element.getAttribute("data-_peity")) {
37
+ return;
38
+ }
39
+
40
+ window.peity(element, "#{type}");
41
+ }
42
+
43
+ window.addEventListener('load', init_peity_charts_#{id});
44
+ window.addEventListener('turbo:load', init_peity_charts_#{id});
45
+ window.addEventListener('turbolinks:load', init_peity_charts_#{id});
30
46
  }.html_safe
31
47
  end
32
48
  ].join.html_safe
@@ -1,3 +1,3 @@
1
1
  module PeityVanillaRails
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: peity_vanilla_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Igor Kasyanchuk