Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Version 1.0.0.

  • Loading branch information...
commit a79d272d5ff5aa341df8ee6cdbab3ec3bbd226c3 1 parent 021f6b8
@benpickles authored
View
8 History.md
@@ -1,5 +1,13 @@
# History
+## Version 1.0.0 - 2012/12/4
+
+ * Spacing between bars can now be configured.
+ * Pie charts can now be formed of more than 2 segments.
+ * The colours of bar and pie charts can now be set dynamically based on their value.
+ * Re-write of the internals so that the actual `<canvas>` element is only created once and `$.wrapInner` is no longer used to contain everything in a separate `<span>`.
+ * Peity now automatically reads data-* attributes and passes them as options when instantiating a chart. [@buunguyen](https://github.com/buunguyen)
+
## Version 0.6.1 - 2012/10/12
* Workaround for Linux/Chrome bug when using #arc to draw a full circle not having a zero starting angle.
View
6 index.html
@@ -111,12 +111,12 @@
</p>
</nav>
- <h2>Download <span class="version">version 0.6.1</span></h2>
+ <h2>Download <span class="version">version 1.0.0</span></h2>
<dl>
- <dt>Uncompressed 4.9Kb</dt>
+ <dt>Uncompressed 5.9Kb</dt>
<dd><a href="jquery.peity.js">jquery.peity.js</a></dd>
- <dt>Minified 2.4Kb (+gzipped 1.1Kb)</dt>
+ <dt>Minified 2.8Kb (+gzipped 1.3Kb)</dt>
<dd><a href="jquery.peity.min.js">jquery.peity.min.js</a></dd>
<dt>Source</dt>
<dd><a href="https://github.com/benpickles/peity">github.com/benpickles/peity</a></dd>
View
2  jquery.peity.js
@@ -1,4 +1,4 @@
-// Peity jQuery plugin version 0.6.1
+// Peity jQuery plugin version 1.0.0
// (c) 2012 Ben Pickles
//
// http://benpickles.github.com/peity
View
15 jquery.peity.min.js
@@ -1,11 +1,12 @@
-// Peity jQuery plugin version 0.6.1
+// Peity jQuery plugin version 1.0.0
// (c) 2012 Ben Pickles
//
-// http://benpickles.github.com/peity/
+// http://benpickles.github.com/peity
//
// Released under MIT license.
-(function(i,k){function o(a,f){var b=k.createElement("canvas");b.setAttribute("width",a*m);b.setAttribute("height",f*m);1!=m&&b.setAttribute("style","width:"+a+"px;height:"+f+"px");return b}var e=i.fn.peity=function(a,f){k.createElement("canvas").getContext&&this.each(function(){i(this).change(function(){var b=i.extend({},e.defaults[a],f),d=this;i.each(b,function(a,c){i.isFunction(c)&&(b[a]=c.call(d))});var c=i(this).html();e.graphers[a].call(this,b);i(this).trigger("chart:changed",c)}).trigger("change")});
-return this};e.graphers={};e.defaults={};e.add=function(a,f,b){e.graphers[a]=b;e.defaults[a]=f};var m=window.devicePixelRatio||1;e.add("pie",{colours:["#FFF4DD","#FF9900"],delimeter:"/",diameter:16},function(a){var f=i(this),b=f.text().split(a.delimeter),d=parseFloat(b[0]),b=parseFloat(b[1]),d=2*d/b*Math.PI,b=o(a.diameter,a.diameter),c=b.getContext("2d"),h=b.width/2;c.translate(h,h);c.rotate(-Math.PI/2);c.beginPath();c.moveTo(0,0);c.arc(0,0,h,0,0==d?2*Math.PI:d,!0);c.fillStyle=a.colours[0];c.fill();
-c.beginPath();c.moveTo(0,0);c.arc(0,0,h,0,d,!1);c.fillStyle=a.colours[1];c.fill();f.wrapInner(i("<span>").hide()).append(b)});e.add("line",{colour:"#c6d9fd",strokeColour:"#4d89f9",strokeWidth:1,delimeter:",",height:16,max:null,min:0,width:32},function(a){var f=i(this),b=o(a.width,a.height),d=f.text().split(a.delimeter);1==d.length&&d.push(d[0]);var c=Math.max.apply(Math,d.concat([a.max])),h=Math.min.apply(Math,d.concat([a.min])),g=b.getContext("2d"),e=b.width,l=b.height,q=e/(d.length-1),c=l/(c-h),
-n=[],j;g.beginPath();g.moveTo(0,l+h*c);for(j=0;j<d.length;j++){var k=j*q,p=l-c*(d[j]-h);n.push({x:k,y:p});g.lineTo(k,p)}g.lineTo(e,l+h*c);g.fillStyle=a.colour;g.fill();if(a.strokeWidth){g.beginPath();g.moveTo(0,n[0].y);for(j=0;j<n.length;j++)g.lineTo(n[j].x,n[j].y);g.lineWidth=a.strokeWidth*m;g.strokeStyle=a.strokeColour;g.stroke()}f.wrapInner(i("<span>").hide()).append(b)});e.add("bar",{colour:"#4D89F9",delimeter:",",height:16,max:null,min:0,width:32},function(a){var f=i(this),b=f.text().split(a.delimeter),
-d=Math.max.apply(Math,b.concat([a.max])),c=Math.min.apply(Math,b.concat([a.min])),h=o(a.width,a.height),g=h.getContext("2d"),e=h.height,d=e/(d-c),l=m/2,k=(h.width+l)/b.length;g.fillStyle=a.colour;for(a=0;a<b.length;a++)g.fillRect(a*k,e-d*(b[a]-c),k-l,d*b[a]);f.wrapInner(i("<span>").hide()).append(h)})})(jQuery,document);
+(function(j,k,l,n){var p=k.createElement("canvas").getContext,h=j.fn.peity=function(a,b){p&&this.each(function(){var c=h.defaults[a],d={},e=j(this);j.each(e.data(),function(a,b){a in c&&(d[a]=b)});var f=j.extend({},c,d,b),m=new o(e,a,f);m.draw();e.change(function(){m.draw()})});return this},o=function(a,b,c){this.$elem=a;this.type=b;this.opts=c},k=o.prototype;k.colours=function(){var a=this.opts.colours,b=a;j.isFunction(b)||(b=function(b,d){return a[d%a.length]});return b};k.draw=function(){h.graphers[this.type].call(this,
+this.opts)};k.prepareCanvas=function(a,b){var c=this.canvas;c?this.context.clearRect(0,0,c.width,c.height):(c=j("<canvas>").attr({height:b*n,width:a*n}),1!=n&&c.css({height:b,width:a}),this.canvas=c=c[0],this.context=c.getContext("2d"),this.$elem.hide().before(c));return c};k.values=function(){return j.map(this.$elem.text().split(this.opts.delimiter),function(a){return parseFloat(a)})};h.defaults={};h.graphers={};h.register=function(a,b,c){this.defaults[a]=b;this.graphers[a]=c};h.register("pie",{colours:["#ff9900",
+"#fff4dd","#ffc66e"],delimiter:null,diameter:16},function(a){if(!a.delimiter){var b=this.$elem.text().match(/[^0-9\.]/);a.delimiter=b?b[0]:","}b=this.values();if("/"==a.delimiter)var c=b[0],b=[c,b[1]-c];for(var d=0,c=b.length,e=0;d<c;d++)e+=b[d];var d=this.prepareCanvas(a.diameter,a.diameter),a=this.context,f=d.width/2,m=l.PI,h=this.colours();a.save();a.translate(f,f);a.rotate(-m/2);for(d=0;d<c;d++){var i=b[d],g=2*i/e*m;a.beginPath();a.moveTo(0,0);a.arc(0,0,f,0,g,!1);a.fillStyle=h.call(this,i,d,b);
+a.fill();a.rotate(g)}a.restore()});h.register("line",{colour:"#c6d9fd",strokeColour:"#4d89f9",strokeWidth:1,delimiter:",",height:16,max:null,min:0,width:32},function(a){var b=this.values();1==b.length&&b.push(b[0]);var c=l.max.apply(l,b.concat([a.max])),d=l.min.apply(l,b.concat([a.min])),e=this.prepareCanvas(a.width,a.height),f=this.context,m=e.width,e=e.height,h=m/(b.length-1),c=e/(c-d),i=[],g;f.beginPath();f.moveTo(0,e+d*c);for(g=0;g<b.length;g++){var j=g*h,k=e-c*(b[g]-d);i.push({x:j,y:k});f.lineTo(j,
+k)}f.lineTo(m,e+d*c);f.fillStyle=a.colour;f.fill();if(a.strokeWidth){f.beginPath();f.moveTo(0,i[0].y);for(g=0;g<i.length;g++)f.lineTo(i[g].x,i[g].y);f.lineWidth=a.strokeWidth*n;f.strokeStyle=a.strokeColour;f.stroke()}});h.register("bar",{colours:["#4D89F9"],delimiter:",",height:16,max:null,min:0,spacing:n,width:32},function(a){for(var b=this.values(),c=l.max.apply(l,b.concat([a.max])),d=l.min.apply(l,b.concat([a.min])),e=this.prepareCanvas(a.width,a.height),f=this.context,h=e.height,c=h/(c-d),a=a.spacing,
+e=(e.width+a)/b.length,j=this.colours(),i=0;i<b.length;i++){var g=b[i],k=i*e,n=h-c*(g-d);f.fillStyle=j.call(this,g,i,b);f.fillRect(k,n,e-a,c*b[i])}})})(jQuery,document,Math,window.devicePixelRatio||1);
Please sign in to comment.
Something went wrong with that request. Please try again.