peity_vanilla_rails 0.2.1 → 0.2.2
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6ed4200aaf0c4efeb3e7a866b3664102c18d25e4efaf371b0e209906d8fd1342
|
4
|
+
data.tar.gz: 59081cd66aba5f066daa5dc3dee710ffd1b230484adda56f3f70fbf189652191
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 378508634d48a3f6a0dc1ceadfe33b2357196aa63d538fa7d69ec3696e10abc0296df79534f7b2ecc406c5e2b541daa21db78225fbd416fe6974de5779aa5f5a
|
7
|
+
data.tar.gz: 11f38fa1d733923d800868923c3a569f1a22d5aac34164ea317602931023aa95fd6808c81f8afc9c724a6b2f94c15d92a1b57be66279273148b784e04f1e1a0f
|
@@ -1,5 +1,5 @@
|
|
1
1
|
/*!
|
2
|
-
Peity Vanila Rails 0.2.
|
2
|
+
Peity Vanila Rails 0.2.2
|
3
3
|
Copyright © 2022 RailsJazz
|
4
4
|
https://railsjazz.com
|
5
5
|
*/
|
@@ -434,6 +434,8 @@ function domReady() {
|
|
434
434
|
});
|
435
435
|
}
|
436
436
|
|
437
|
+
const queryPeityElements = (node) => node.matches("[peity]") ? [node] : Array.from(node.querySelectorAll("[peity]"));
|
438
|
+
|
437
439
|
const getPeityType = (node) => node.getAttribute("peity");
|
438
440
|
|
439
441
|
const elementFromNode = (node) => {
|
@@ -442,78 +444,106 @@ const elementFromNode = (node) => {
|
|
442
444
|
}
|
443
445
|
};
|
444
446
|
|
445
|
-
|
446
|
-
|
447
|
-
|
447
|
+
class Watcher {
|
448
|
+
constructor() {
|
449
|
+
this.elements = new Set();
|
448
450
|
}
|
449
|
-
};
|
450
451
|
|
451
|
-
|
452
|
-
|
453
|
-
node._peity.destroy();
|
454
|
-
}
|
455
|
-
};
|
452
|
+
async start() {
|
453
|
+
await domReady();
|
456
454
|
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
455
|
+
this.element = document.documentElement;
|
456
|
+
|
457
|
+
const observer = new MutationObserver(this.callback.bind(this));
|
458
|
+
observer.observe(this.element, {
|
459
|
+
childList: true,
|
460
|
+
attributes: true,
|
461
|
+
subtree: true,
|
462
|
+
});
|
463
|
+
|
464
|
+
this.processNodeAdded(this.element);
|
465
|
+
};
|
466
|
+
|
467
|
+
processNodeAdded(node) {
|
468
|
+
for (const element of queryPeityElements(node)) {
|
469
|
+
if (!this.elements.has(element)) {
|
470
|
+
this.elements.add(element);
|
471
|
+
peity(element, getPeityType(element));
|
466
472
|
}
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
473
|
+
}
|
474
|
+
};
|
475
|
+
|
476
|
+
processNodeRemoved(node) {
|
477
|
+
const matches = new Set(queryPeityElements(node));
|
478
|
+
|
479
|
+
for (const element of this.elements) {
|
480
|
+
if(matches.has(element)) {
|
481
|
+
this.elements.delete(element);
|
482
|
+
if (element._peity) {
|
483
|
+
element._peity.destroy();
|
484
|
+
}
|
471
485
|
}
|
472
|
-
|
473
|
-
}
|
474
|
-
|
486
|
+
}
|
487
|
+
};
|
488
|
+
|
489
|
+
processAttributeChanged(mutation) {
|
490
|
+
const node = mutation.target;
|
491
|
+
if(!this.elementIsActive(node)) return;
|
475
492
|
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
if (element) {
|
483
|
-
processNodeAdded(element);
|
493
|
+
switch (mutation.attributeName) {
|
494
|
+
case "peity":
|
495
|
+
const type = getPeityType(node);
|
496
|
+
if (type) {
|
497
|
+
if (!this.elements.has(node)) {
|
498
|
+
this.elements.add(node);
|
484
499
|
}
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
500
|
+
peity(node, type);
|
501
|
+
} else {
|
502
|
+
if (this.elements.has(node)) {
|
503
|
+
this.elements.delete(node);
|
504
|
+
if (node._peity) {
|
505
|
+
node._peity.destroy();
|
506
|
+
}
|
490
507
|
}
|
491
508
|
}
|
492
509
|
break;
|
493
|
-
case "
|
494
|
-
|
510
|
+
case "data-peity":
|
511
|
+
if (node._peity) {
|
512
|
+
peity(node, node._peity.type);
|
513
|
+
}
|
495
514
|
break;
|
496
515
|
}
|
497
|
-
}
|
498
|
-
};
|
499
|
-
|
500
|
-
const observerOptions = {
|
501
|
-
childList: true,
|
502
|
-
attributes: true,
|
503
|
-
subtree: true,
|
504
|
-
};
|
505
|
-
|
506
|
-
const start = async () => {
|
507
|
-
await domReady();
|
516
|
+
}
|
508
517
|
|
509
|
-
|
510
|
-
|
518
|
+
callback(mutationList, observer) {
|
519
|
+
mutationList.forEach((mutation) => {
|
520
|
+
switch (mutation.type) {
|
521
|
+
case "childList":
|
522
|
+
for (const node of Array.from(mutation.removedNodes)) {
|
523
|
+
const element = elementFromNode(node);
|
524
|
+
if (element) {
|
525
|
+
this.processNodeRemoved(element);
|
526
|
+
}
|
527
|
+
}
|
528
|
+
for (const node of Array.from(mutation.addedNodes)) {
|
529
|
+
const element = elementFromNode(node);
|
530
|
+
if (element && this.elementIsActive(element)) {
|
531
|
+
this.processNodeAdded(element);
|
532
|
+
}
|
533
|
+
}
|
534
|
+
break;
|
535
|
+
case "attributes":
|
536
|
+
this.processAttributeChanged(mutation);
|
537
|
+
break;
|
538
|
+
}
|
539
|
+
});
|
540
|
+
};
|
511
541
|
|
512
|
-
|
513
|
-
|
542
|
+
elementIsActive(element) {
|
543
|
+
return this.element.contains(element);
|
514
544
|
}
|
515
|
-
}
|
545
|
+
}
|
516
546
|
|
517
|
-
start();
|
547
|
+
new Watcher().start();
|
518
548
|
|
519
549
|
export { peity as default };
|
@@ -1,5 +1,5 @@
|
|
1
1
|
/*!
|
2
|
-
Peity Vanila Rails 0.2.
|
2
|
+
Peity Vanila Rails 0.2.2
|
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
|
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 s in e)i.setAttribute(s,e[s]);return i},i="createElementNS"in document&&e("svg",{}).createSVGRect();class s{static defaults={};static graphers={};constructor(t,e,i={}){this.element=t,this.type=e,this.options=Object.assign({},s.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;s.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){s.defaults[t]=e,s.graphers[t]=i}}const n=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 s=0,n=i.length,o=0;for(;s<n;s++)o+=i[s];o||(n=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,d=l/2,p=h/2,c=Math.min(d,p);let m=t.options.innerRadius;"donut"!=t.type||m||(m=.5*c);const u=t.fill(),f=(t,e)=>{const i=t/o*Math.PI*2-Math.PI/2;return[e*Math.cos(i)+d,e*Math.sin(i)+p]};let g=0;for(s=0;s<n;s++){const n=i[s],a=n/o;let l;if(0!=a){if(1==a)if(m){const t=d-.01,i=p-c,s=p-m;l=e("path",{d:["M",d,i,"A",c,c,0,1,1,t,i,"L",t,s,"A",m,m,0,1,0,d,s].join(" "),"data-value":n})}else l=e("circle",{cx:d,cy:p,"data-value":n,r:c});else{const t=g+n;let i=["M"].concat(f(g,c),"A",c,c,0,a>.5?1:0,1,f(t,c),"L");m?i=i.concat(f(t,m),"A",m,m,0,a>.5?1:0,0,f(g,m)):i.push(d,p),g+=n,l=e("path",{d:i.join(" "),"data-value":n})}l.setAttribute("fill",u.call(t,n,s,i)),r.append(l)}}},o={fill:["#ff9900","#fff4dd","#ffc66e"],radius:8};s.register("pie",o,n),s.register("donut",o,n),s.register("bar",{delimiter:",",fill:["#4D89F9"],height:16,min:0,padding:.1,width:32},(t=>{const i=t.values,s=Math.max.apply(Math,null==t.options.max?i:i.concat(t.options.max)),n=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=s-n,h=t.options.padding,d=t.fill(),p=t=>t*a/i.length,c=t=>r-(l?(t-n)/l*r:1);for(var m=0;m<i.length;m++){let a,r=p(m+h),u=p(m+1-h)-r,f=i[m],g=c(f),y=g,v=g;l?f<0?y=c(Math.min(s,0)):v=c(Math.max(n,0)):a=1,a=v-y,0==a&&(a=1,s>0&&l&&y--),o.append(e("rect",{"data-value":f,fill:d.call(t,f,m,i),x:r,y:y,width:u,height:a}))}})),s.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 s=Math.max.apply(Math,null==t.options.max?i:i.concat(t.options.max)),n=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=s-n,d=t=>{let e=l;return h&&(e-=(t-n)/h*l),e+a/2};let p=d(Math.max(n,0)),c=[0,p];for(var m=0;m<i.length;m++)c.push(m*(r/(i.length-1)),d(i[m]));c.push(r,p),t.options.fill&&o.append(e("polygon",{fill:t.options.fill,points:c.join(" ")})),a&&o.append(e("polyline",{fill:"none",points:c.slice(2,c.length-2).join(" "),stroke:t.options.stroke,"stroke-width":a,"stroke-linecap":"square"}))}));const a=function(t,e,i){const n=new s(t,e,i);return n.mount(),n};a.defaults=s.defaults,a.graphers=s.graphers;const r=t=>t.matches("[peity]")?[t]:Array.from(t.querySelectorAll("[peity]")),l=t=>t.getAttribute("peity"),h=t=>{if(t.nodeType==Node.ELEMENT_NODE)return t};return(new class{constructor(){this.elements=new Set}async start(){await new Promise((t=>{"loading"==document.readyState?document.addEventListener("DOMContentLoaded",t):t()})),this.element=document.documentElement;new MutationObserver(this.callback.bind(this)).observe(this.element,{childList:!0,attributes:!0,subtree:!0}),this.processNodeAdded(this.element)}processNodeAdded(t){for(const e of r(t))this.elements.has(e)||(this.elements.add(e),a(e,l(e)))}processNodeRemoved(t){const e=new Set(r(t));for(const t of this.elements)e.has(t)&&(this.elements.delete(t),t._peity&&t._peity.destroy())}processAttributeChanged(t){const e=t.target;if(this.elementIsActive(e))switch(t.attributeName){case"peity":const t=l(e);t?(this.elements.has(e)||this.elements.add(e),a(e,t)):this.elements.has(e)&&(this.elements.delete(e),e._peity&&e._peity.destroy());break;case"data-peity":e._peity&&a(e,e._peity.type)}}callback(t,e){t.forEach((t=>{switch(t.type){case"childList":for(const e of Array.from(t.removedNodes)){const t=h(e);t&&this.processNodeRemoved(t)}for(const e of Array.from(t.addedNodes)){const t=h(e);t&&this.elementIsActive(t)&&this.processNodeAdded(t)}break;case"attributes":this.processAttributeChanged(t)}}))}elementIsActive(t){return this.element.contains(t)}}).start(),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.2
|
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-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|