peity_vanilla_rails 0.2.0 → 0.2.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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: de5631424fd3980ed3c9c8a7e02a4c7e10cc77650ebdea1f8d17cb99d526ca96
|
4
|
+
data.tar.gz: 85a1ae8f2d6e05fad50d5362c0ce3c55d8e0b8d04354d028cf247562a76194a6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a90b637c07453922d6ad43cff0def5c8daa35fcdd4c0e094acd053f6e85226fab91a5f606efc434fe9144ed676993a2ebe95582ad8420aca182cf6e987674054
|
7
|
+
data.tar.gz: 0b2a6938fd2ab60492f943965a8a45e128f31098d262ec5315a9e3252daa257b40be98728dee23402192ac5bd485069d839cfa080102126af39d711aa870c4ec
|
data/README.md
CHANGED
@@ -141,3 +141,7 @@ You are welcome to contribute.
|
|
141
141
|
## License
|
142
142
|
|
143
143
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
144
|
+
|
145
|
+
|
146
|
+
[<img src="https://github.com/igorkasyanchuk/rails_time_travel/blob/main/docs/more_gems.png?raw=true"
|
147
|
+
/>](https://www.railsjazz.com/?utm_source=github&utm_medium=bottom&utm_campaign=peity_vanilla_rails)
|
@@ -1,5 +1,5 @@
|
|
1
1
|
/*!
|
2
|
-
Peity Vanila Rails 0.2.
|
2
|
+
Peity Vanila Rails 0.2.1
|
3
3
|
Copyright © 2022 RailsJazz
|
4
4
|
https://railsjazz.com
|
5
5
|
*/
|
@@ -424,7 +424,17 @@ const peity = function (element, type, options) {
|
|
424
424
|
peity.defaults = Peity.defaults;
|
425
425
|
peity.graphers = Peity.graphers;
|
426
426
|
|
427
|
-
|
427
|
+
function domReady() {
|
428
|
+
return new Promise((resolve) => {
|
429
|
+
if (document.readyState == "loading") {
|
430
|
+
document.addEventListener("DOMContentLoaded", resolve);
|
431
|
+
} else {
|
432
|
+
resolve();
|
433
|
+
}
|
434
|
+
});
|
435
|
+
}
|
436
|
+
|
437
|
+
const getPeityType = (node) => node.getAttribute("peity");
|
428
438
|
|
429
439
|
const elementFromNode = (node) => {
|
430
440
|
if (node.nodeType == Node.ELEMENT_NODE) {
|
@@ -456,7 +466,7 @@ const processAttributeChanged = (mutation) => {
|
|
456
466
|
}
|
457
467
|
break;
|
458
468
|
case "data-peity":
|
459
|
-
if(node._peity) {
|
469
|
+
if (node._peity) {
|
460
470
|
peity(node, node._peity.type);
|
461
471
|
}
|
462
472
|
break;
|
@@ -493,11 +503,17 @@ const observerOptions = {
|
|
493
503
|
subtree: true,
|
494
504
|
};
|
495
505
|
|
496
|
-
const
|
497
|
-
|
506
|
+
const start = async () => {
|
507
|
+
await domReady();
|
498
508
|
|
499
|
-
|
500
|
-
|
501
|
-
|
509
|
+
const observer = new MutationObserver(callback);
|
510
|
+
observer.observe(document.documentElement, observerOptions);
|
511
|
+
|
512
|
+
for (const node of Array.from(document.documentElement.querySelectorAll("[peity]"))) {
|
513
|
+
processNodeAdded(node);
|
514
|
+
}
|
515
|
+
};
|
516
|
+
|
517
|
+
start();
|
502
518
|
|
503
519
|
export { peity as default };
|
@@ -1,5 +1,5 @@
|
|
1
1
|
/*!
|
2
|
-
Peity Vanila Rails 0.2.
|
2
|
+
Peity Vanila Rails 0.2.1
|
3
3
|
Copyright © 2022 RailsJazz
|
4
4
|
https://railsjazz.com
|
5
5
|
*/
|
@@ -8,4 +8,4 @@ var peity=function(){"use strict";
|
|
8
8
|
Peity Vanila JS 0.0.8
|
9
9
|
Copyright © 2022 RailsJazz
|
10
10
|
https://railsjazz.com
|
11
|
-
*/const t=t=>null!==t&&"function"==typeof t&&!!t.apply,e=(t,e)=>{const i=document.createElementNS("http://www.w3.org/2000/svg",t);for(var n in e)i.setAttribute(n,e[n]);return i},i="createElementNS"in document&&e("svg",{}).createSVGRect();class n{static defaults={};static graphers={};constructor(t,e,i={}){this.element=t,this.type=e,this.options=Object.assign({},n.defaults[this.type],JSON.parse(t.dataset.peity||"{}"),i),this.element._peity&&this.element._peity.destroy(),this.element._peity=this}draw(){const e=this.options;n.graphers[this.type](this),t(e.after)&&e.after.call(this,e)}fill(){var e=this.options.fill;return t(e)?e:function(t,i){return e[i%e.length]}}prepare(t,i){return this.svg||(this.element.style.display="none",this.element.after(this.svg=e("svg",{class:"peity"}))),this.svg.innerHTML="",this.svg.setAttribute("width",t),this.svg.setAttribute("height",i),this.svg}get values(){return this.element.innerText.split(this.options.delimiter).map((t=>parseFloat(t)))}mount(){i&&(this.element.addEventListener("DOMSubtreeModified",this.draw.bind(this)),this.draw(),this.mounted=!0)}unmount(){this.element.removeEventListener("DOMSubtreeModified",this.draw),this.svg.remove(),this.mounted=!1}destroy(){this.unmount(),delete this.element._peity}static register(t,e,i){n.defaults[t]=e,n.graphers[t]=i}}const s=t=>{if(!t.options.delimiter){const e=t.element.innerText.match(/[^0-9\.]/);t.options.delimiter=e?e[0]:","}let i=t.values.map((t=>t>0?t:0));if("/"==t.options.delimiter){let t=i[0],e=i[1];i=[t,Math.max(0,e-t)]}let n=0,s=i.length,o=0;for(;n<s;n++)o+=i[n];o||(s=2,o=1,i=[0,1]);let
|
11
|
+
*/const t=t=>null!==t&&"function"==typeof t&&!!t.apply,e=(t,e)=>{const i=document.createElementNS("http://www.w3.org/2000/svg",t);for(var n in e)i.setAttribute(n,e[n]);return i},i="createElementNS"in document&&e("svg",{}).createSVGRect();class n{static defaults={};static graphers={};constructor(t,e,i={}){this.element=t,this.type=e,this.options=Object.assign({},n.defaults[this.type],JSON.parse(t.dataset.peity||"{}"),i),this.element._peity&&this.element._peity.destroy(),this.element._peity=this}draw(){const e=this.options;n.graphers[this.type](this),t(e.after)&&e.after.call(this,e)}fill(){var e=this.options.fill;return t(e)?e:function(t,i){return e[i%e.length]}}prepare(t,i){return this.svg||(this.element.style.display="none",this.element.after(this.svg=e("svg",{class:"peity"}))),this.svg.innerHTML="",this.svg.setAttribute("width",t),this.svg.setAttribute("height",i),this.svg}get values(){return this.element.innerText.split(this.options.delimiter).map((t=>parseFloat(t)))}mount(){i&&(this.element.addEventListener("DOMSubtreeModified",this.draw.bind(this)),this.draw(),this.mounted=!0)}unmount(){this.element.removeEventListener("DOMSubtreeModified",this.draw),this.svg.remove(),this.mounted=!1}destroy(){this.unmount(),delete this.element._peity}static register(t,e,i){n.defaults[t]=e,n.graphers[t]=i}}const s=t=>{if(!t.options.delimiter){const e=t.element.innerText.match(/[^0-9\.]/);t.options.delimiter=e?e[0]:","}let i=t.values.map((t=>t>0?t:0));if("/"==t.options.delimiter){let t=i[0],e=i[1];i=[t,Math.max(0,e-t)]}let n=0,s=i.length,o=0;for(;n<s;n++)o+=i[n];o||(s=2,o=1,i=[0,1]);let a=2*t.options.radius;const r=t.prepare(t.options.width||a,t.options.height||a),l=r.clientWidth,h=r.clientHeight,p=l/2,c=h/2,d=Math.min(p,c);let u=t.options.innerRadius;"donut"!=t.type||u||(u=.5*d);const m=t.fill(),f=(t,e)=>{const i=t/o*Math.PI*2-Math.PI/2;return[e*Math.cos(i)+p,e*Math.sin(i)+c]};let g=0;for(n=0;n<s;n++){const s=i[n],a=s/o;let l;if(0!=a){if(1==a)if(u){const t=p-.01,i=c-d,n=c-u;l=e("path",{d:["M",p,i,"A",d,d,0,1,1,t,i,"L",t,n,"A",u,u,0,1,0,p,n].join(" "),"data-value":s})}else l=e("circle",{cx:p,cy:c,"data-value":s,r:d});else{const t=g+s;let i=["M"].concat(f(g,d),"A",d,d,0,a>.5?1:0,1,f(t,d),"L");u?i=i.concat(f(t,u),"A",u,u,0,a>.5?1:0,0,f(g,u)):i.push(p,c),g+=s,l=e("path",{d:i.join(" "),"data-value":s})}l.setAttribute("fill",m.call(t,s,n,i)),r.append(l)}}},o={fill:["#ff9900","#fff4dd","#ffc66e"],radius:8};n.register("pie",o,s),n.register("donut",o,s),n.register("bar",{delimiter:",",fill:["#4D89F9"],height:16,min:0,padding:.1,width:32},(t=>{const i=t.values,n=Math.max.apply(Math,null==t.options.max?i:i.concat(t.options.max)),s=Math.min.apply(Math,null==t.options.min?i:i.concat(t.options.min)),o=t.prepare(t.options.width,t.options.height),a=o.clientWidth,r=o.clientHeight,l=n-s,h=t.options.padding,p=t.fill(),c=t=>t*a/i.length,d=t=>r-(l?(t-s)/l*r:1);for(var u=0;u<i.length;u++){let a,r=c(u+h),m=c(u+1-h)-r,f=i[u],g=d(f),y=g,v=g;l?f<0?y=d(Math.min(n,0)):v=d(Math.max(s,0)):a=1,a=v-y,0==a&&(a=1,n>0&&l&&y--),o.append(e("rect",{"data-value":f,fill:p.call(t,f,u,i),x:r,y:y,width:m,height:a}))}})),n.register("line",{delimiter:",",fill:"#c6d9fd",height:16,min:0,stroke:"#4d89f9",strokeWidth:1,width:32},(t=>{const i=t.values;1==i.length&&i.push(i[0]);const n=Math.max.apply(Math,null==t.options.max?i:i.concat(t.options.max)),s=Math.min.apply(Math,null==t.options.min?i:i.concat(t.options.min)),o=t.prepare(t.options.width,t.options.height),a=t.options.strokeWidth,r=o.clientWidth,l=o.clientHeight-a,h=n-s,p=t=>{let e=l;return h&&(e-=(t-s)/h*l),e+a/2};let c=p(Math.max(s,0)),d=[0,c];for(var u=0;u<i.length;u++)d.push(u*(r/(i.length-1)),p(i[u]));d.push(r,c),t.options.fill&&o.append(e("polygon",{fill:t.options.fill,points:d.join(" ")})),a&&o.append(e("polyline",{fill:"none",points:d.slice(2,d.length-2).join(" "),stroke:t.options.stroke,"stroke-width":a,"stroke-linecap":"square"}))}));const a=function(t,e,i){const s=new n(t,e,i);return s.mount(),s};a.defaults=n.defaults,a.graphers=n.graphers;const r=t=>t.getAttribute("peity"),l=t=>{if(t.nodeType==Node.ELEMENT_NODE)return t},h=t=>{t.matches("[peity]")&&a(t,r(t))},p=t=>{t._peity&&t._peity.destroy()},c=(t,e)=>{t.forEach((function(t){switch(t.type){case"childList":for(const e of Array.from(t.addedNodes)){const t=l(e);t&&h(t)}for(const e of Array.from(t.removedNodes)){const t=l(e);t&&p(t)}break;case"attributes":(t=>{const e=t.target;switch(t.attributeName){case"peity":const t=r(e);t?a(e,t):e._peity.unmount();break;case"data-peity":e._peity&&a(e,e._peity.type)}})(t)}}))},d={childList:!0,attributes:!0,subtree:!0};return(async()=>{await new Promise((t=>{"loading"==document.readyState?document.addEventListener("DOMContentLoaded",t):t()}));new MutationObserver(c).observe(document.documentElement,d);for(const t of Array.from(document.documentElement.querySelectorAll("[peity]")))h(t)})(),a}();
|
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.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Igor Kasyanchuk
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2022-05-
|
12
|
+
date: 2022-05-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -94,6 +94,7 @@ licenses:
|
|
94
94
|
metadata:
|
95
95
|
homepage_uri: https://github.com/railsjazz/peity_vanilla_rails
|
96
96
|
source_code_uri: https://github.com/railsjazz/peity_vanilla_rails
|
97
|
+
changelog_uri: https://github.com/railsjazz/peity_vanilla_rails/releases
|
97
98
|
post_install_message:
|
98
99
|
rdoc_options: []
|
99
100
|
require_paths:
|