-
Notifications
You must be signed in to change notification settings - Fork 9
/
chartlets.min.js
6 lines (6 loc) · 6.39 KB
/
chartlets.min.js
1
2
3
4
5
6
/*
Chartlets v0.9.10: http://chartlets.com
MIT License
(c) 2013 Adam Mark
*/
(function(Q){var E,X,u,a,c,l,m,w,C,P,d,t,S;X=null;u=null;a=0;c=0;l=false;m=[0,0];w=[];C={};t={line:R,bar:s,pie:O};d={blues:["#7eb5d6","#2a75a9","#214b6b","#dfc184","#8f6048"],money:["#009b6d","#89d168","#d3eb87","#666666","#aaaaaa"],circus:["#9351a4","#ff99cc","#e31a1c","#66cdaa","#ffcc33"],party:["#ffcc00","#ff66cc","#3375cd","#e43b3b","#96cb3f"],garden:["#3c7bb0","#ffa07a","#2e8b57","#7eb5d6","#89d168"],crayon:["#468ff0","#ff8000","#00c000","#ffd700","#ff4500"],ocean:["#3375cd","#62ccb2","#4aa5d5","#a6cee3","#ffcc33"],spring:["#ed729d","#72caed","#9e9ac8","#a6d854","#f4a582"],beach:["#f92830","#2fb4b1","#ffa839","#3375cd","#5fd1d5"],fire:["#dc143c","#ff8c00","#ffcc33","#b22222","#cd8540"]};S=Q.requestAnimationFrame||Q.webkitRequestAnimationFrame||Q.mozRequestAnimationFrame||Q.msRequestAnimationFrame||function(Y){Q.setTimeout(Y,1000/60)};function B(Z,Y){var aa=Z.getAttribute(Y);return aa?aa.replace(/, +/g,",").split(/ +/g):null}function K(aa){var ab,ac,Z,Y;ab=B(aa,"data-opts")||[];Z={};for(Y=0;Y<ab.length;Y++){ac=ab[Y].split(":");Z[ac[0]]=ac[1]}return Z}function H(ab){var aa=ab.match(/\[[^\[]+\]/g)||[],Z,Y;for(Z=0;Z<aa.length;Z++){aa[Z]=aa[Z].match(/[-\d\.]+/g);for(Y=0;Y<aa[Z].length;Y++){aa[Z][Y]=+aa[Z][Y]}}return aa}function A(){return C.transform==="stack"}function J(){return C.fill!==undefined}function h(Z,Y){return Y?r(Z):L(Z)}function L(Z){var Y=Array.prototype.concat.apply([],Z);if(X==="bar"||A()){Y.push(0)}return[Math.min.apply(null,Y),Math.max.apply(null,Y)]}function r(Y){return L(v(Y).concat(Y))}function n(Z){var Y={r:0,g:0,b:0,a:1};if(Z.match(/#/)){Y=p(Z)}else{if(Z.match(/rgb/)){Y=x(Z)}else{if(Z.match(/hsl/)){Y=G(Z)}}}return Y}function x(Y){var Z=Y.match(/[\d\.]+/g);return{r:+Z[0],g:+Z[1],b:+Z[2],a:+Z[3]||1}}function p(Y){var aa=Y.match(/\w/g),Z;if(aa.length===3){aa=[aa[0],aa[0],aa[1],aa[1],aa[2],aa[2]]}Z=+("0x"+aa.join(""));return{r:(Z&16711680)>>16,g:(Z&65280)>>8,b:(Z&255),a:1}}function G(ag){var af,ad,aj,ac,Y,ae,ah,Z,aa,ai;af=ag.match(/[\d\.]+/g);ad=+af[0]/360;aj=+af[1]/100;ac=+af[2]/100;ai=(+af[3]||1)/1;function ab(am,al,ak){if(ak<0){ak+=1}if(ak>1){ak-=1}if(ak<1/6){return am+(al-am)*6*ak}if(ak<1/2){return al}if(ak<2/3){return am+(al-am)*(2/3-ak)*6}return am}if(aj===0){Y=ae=ah=ac}else{Z=ac<0.5?ac*(1+aj):ac+aj-ac*aj;aa=2*ac-Z;Y=ab(aa,Z,ad+1/3);ae=ab(aa,Z,ad);ah=ab(aa,Z,ad-1/3)}return{r:Y*255,g:ae*255,b:ah*255,a:ai}}function z(Y,Z){Y.a*=Z;return Y}function f(Y){return"rgba("+[Math.round(Y.r),Math.round(Y.g),Math.round(Y.b),Y.a].join(",")+")"}function V(){l=true;u.translate(a,0);u.rotate(Math.PI/2)}function F(Y){return(l?c:a)/(Y-1)}function i(Z,Y){return Z*F(Y)}function M(Z){var Y=l?a:c;return Y-(Y*((Z-m[0])/(m[1]-m[0])))}function q(aa){var Y,Z=0;for(Y=0;Y<aa.length;Y++){Z+=aa[Y]}return Z}function j(aa,Y){var Z,ab=0;for(Z=0;Z<aa.length;Z++){ab+=aa[Z][Y]}return ab}function v(Z){var Y,aa=[];for(Y=0;Y<Z[0].length;Y++){aa.push(j(Z,Y))}return aa}function y(Y){return P[Y]||"#000"}function k(af,ac,ab,ag,Z){var aa=0,ae,ad,Y;Y=F(af.length);u.lineWidth=Math.min(3,ab);u.lineJoin="round";u.beginPath();u.strokeStyle=ac;u.moveTo(0,M(af[0]));while(++aa<af.length){ae=i(aa,af.length);ad=M(af[aa]);if(A()){C.shape="straight"}o(af,aa,ae,ad,Y,C.shape)}if(ag){u.fillStyle=ag;if(Z){while(--aa>=0){ae=i(aa,Z.length);ad=M(Z[aa]);o(Z,aa,ae,ad,Y,C.shape)}}else{u.lineTo(ae,M(0));u.lineTo(0,M(0))}u.fill()}else{u.stroke()}}function o(af,ab,Z,ae,ac,aa){var Y,ad;if(aa==="smooth"){Y=i(ab-0.5,af.length);ad=M(af[ab-1]);u.bezierCurveTo(Y,ad,Y,ae,Z,ae)}else{if(aa==="step"){u.lineTo(Z-(ac/2),M(af[ab-1]));u.lineTo(Z-(ac/2),ae)}u.lineTo(Z,ae)}}function g(af,ad,ab,Z){var ac=-1,Y,ae,aa;while(++ac<af.length){Y=i(ac,af.length);ae=M(af[ac]);if(ad==="square"){aa=Math.max(2,Z)*2.5;b(ab,Y-(aa/2),ae+(aa/2),aa,aa)}else{aa=Z+1;e(ab,Y,ae,aa)}}}function e(Z,Y,ab,aa){u.fillStyle=Z;u.beginPath();u.arc(Y,ab,aa,2*Math.PI,false);u.fill()}function b(aa,Y,ac,Z,ab){u.fillStyle=aa;u.fillRect(Y,ac-ab,Z,ab)}function U(){var Y,Z;if(!isNaN(+C.axis)){Y=0;Z=Math.round(M(C.axis));u.lineWidth=1;u.lineJoin="round";u.strokeStyle="#bbb";u.moveTo(Y,Z);while(Y<a){u.lineTo(Y+5,Z);u.moveTo(Y+8,Z);Y+=8}u.stroke()}}function W(aa,Z,Y,ab){return +aa+((+Z-+aa)*(Y/ab))}function I(Z,Y,ad){var ab,aa,ac=[Z];for(ab=0;ab<Z.length;ab++){for(aa=1;aa<ad;aa++){if(!ac[aa]){ac[aa]=[]}ac[aa][ab]=W(Z[ab],Y[ab],aa,ad)}}return ac.concat([Y])}function N(Z,Y,ac){var aa,ab=[];for(aa=0;aa<Z.length;aa++){ab.push(I(Z[aa],Y[aa],ac))}return ab}function D(ac,ab,af){var aa=1,Z=0,ae=8,Y=N(ab,af,ae);if(!ab.length){return E.update(ac,af)}function ad(){var ag=[];for(Z=0;Z<Y.length;Z++){ag.push(Y[Z][aa])}E.update(ac,ag);if(++aa<=ae){S(ad)}}S(ad)}function R(){var Z,ad,ac,Y,ab,aa;U();for(Z=0;Z<w.length;Z++){ad=w[Z];ac=y(Z);if(A()){ad=v(w.slice(0,Z+1));aa=Z>0?v(w.slice(0,Z)):null}k(ad,ac,C.stroke||1.5,null);if(A()||J()){ab=C.alpha||(A()?1:0.5);Y=f(z(n(ac),ab));k(ad,ac,0,Y,aa)}if(C.cap){g(ad,C.cap,ac,u.lineWidth)}}}function s(){var aa,Z,Y,ae,af,ad,ag,ab,ac;if(C.orient==="horiz"){V()}U();u.lineWidth=C.stroke||1;u.lineJoin="miter";ac=w[0].length;for(aa=0;aa<w.length;aa++){for(Z=0;Z<ac;Z++){Y=1;ae=l?c:a;ag=((ae/ac)/w.length)-((Y/w.length)*aa)-1;af=(Y/2)+i(Z,ac+1)+(ag*aa)+1;ad=M(w[aa][Z]);ab=ad-M(0)||1;if(A()){ag=(ae/ac)-2;af=i(Z,ac+1);ad=M(j(w.slice(0,aa+1),Z))}b(y(aa),af,ad,ag,ab)}}}function O(){var ab,Z,af,ad,aa,Y,ae,ac;Z=a/2;af=c/2;ad=Math.min(Z,af)-2;aa=1.5*Math.PI;Y=0;ae=w[0];ac=q(ae);for(ab=0;ab<ae.length;ab++){u.fillStyle=y(ab);u.beginPath();Y=aa+(ae[ab]/ac)*(2*Math.PI);u.arc(Z,af,ad,aa,Y,false);u.lineTo(Z,af);u.fill();aa=Y}}function T(Y){if(Q.devicePixelRatio>1){if(!Y.__resized){Y.style.width=Y.width+"px";Y.style.height=Y.height+"px";Y.width=2*Y.width;Y.height=2*Y.height;Y.__resized=true}}X=B(Y,"data-type")[0];w=H(Y.getAttribute("data-sets"));C=K(Y);u=Y.getContext("2d");a=Y.width;c=Y.height;P=d[C.theme]||B(Y,"data-colors")||d.basic;m=B(Y,"data-range")||h(w,A());l=false;Y.width=Y.width;if(C.bgcolor){b(C.bgcolor||"#fff",0,0,a,-c)}try{t[X](u,a,c,w,C)}catch(Z){console.error(Z.message)}}E={render:function(Y){var Z;if(!Y){Y=document.querySelectorAll(".chartlet")}for(Z=0;Z<Y.length;Z++){T(Y[Z])}},setTheme:function(Z,Y){d[Z]=Y},getTheme:function(Y){return Y?d[Y]:P},setRenderer:function(Y,Z){t[Y]=Z},update:function(aa,Z,Y){if(typeof aa==="string"){aa=document.getElementById(aa)}if(Y&&Y.transition==="linear"){new D(aa,H(aa.getAttribute("data-sets")),Z);return}aa.setAttribute("data-sets",JSON.stringify(Z));this.render([aa])}};Q.Chartlets=E}(window));