Skip to content
Browse files

Version 0.3

  • Loading branch information...
1 parent dae8719 commit 0321eb7edf499995588f81e3f28df746c9ab8620 Valentin Vasilyev committed May 2, 2012
Showing with 17 additions and 28 deletions.
  1. +10 −17 g.radar.js
  2. +7 −11 g.radar.min.js
View
27 g.radar.js
@@ -1,5 +1,5 @@
/*
-* g.raphael-radar 0.2 - Radar chart, based on Raphaël.js
+* g.raphael-radar 0.3 - Radar chart, based on Raphaël.js
* https://github.com/Valve/g.raphael-radar
* Copyright (c) 2012 Valentin Vasilyev (iamvalentin@gmail.com)
* Licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) license.
@@ -9,8 +9,7 @@
var $r = Raphael; //for minification;
if (!values || values.length == 0) throw 'Values array is required';
opts = opts || {};
- var
- startAngle = 270,
+ var startAngle = 270,
angle = 360 / values.length;
var defaultOpts = {
meshSize: 30,
@@ -161,15 +160,10 @@
// values
if (opts.drawValues) {
var i = values.length;
- while (i--) {
- //i--;
+ while (i--) {
var textObject = labelvalue(cx, cy, r, startAngle + angle * i, values[i], opts.max);
- //paper.text(textObject.x, textObject.y, opts.labels[i] + " (" + values[i] + ")").attr(textObject.attr);
-
- var fulltext = values[i]; // +" (" + values[i] + ")";
- var text = paper.text(textObject.x, textObject.y, fulltext).attr(textObject.attr);
- //var fontSize = opts.labelFontSize;
- //text.attr("font-size", fontSize);
+ var fulltext = values[i];
+ var text = paper.text(textObject.x, textObject.y, fulltext).attr(textObject.attr);
}
}
@@ -178,9 +172,8 @@
var i = opts.labels.length;
while (i--) {
var textObject = label(cx, cy, r, startAngle + angle * i);
- //paper.text(textObject.x, textObject.y, opts.labels[i] + " (" + values[i] + ")").attr(textObject.attr);
- var fulltext = opts.labels[i]; // +" (" + values[i] + ")";
+ var fulltext = opts.labels[i];
var text = paper.text(textObject.x, textObject.y, fulltext).attr(textObject.attr);
fulltext = fulltext.replace("-", "- ").replace("/", "/ ");
@@ -190,9 +183,9 @@
var maxwidth = Math.min(textObject.x, paper.width - textObject.x);
var maxheight = Math.min(textObject.y, paper.height - textObject.y);
- var fontSize = opts.labelFontSize;
- var FontSizeMin = 8;
- for (fontSize; fontSize >= FontSizeMin; --fontSize) {
+
+ var fontSizeMin = 8;
+ for (var fontSize = opts.labelFontSize; fontSize >= fontSizeMin; --fontSize) {
text.attr("font-size", fontSize);
var tempText = "";
for (var i1 = 0; i1 < wordsCount; ++i1) {
@@ -208,7 +201,7 @@
tempText = tempText.replace("-", "-\n");
text.attr("text", tempText);
}
- if (fontSize == FontSizeMin ||
+ if (fontSize == fontSizeMin ||
(text.getBBox().height <= maxheight &&
(text.getBBox().width <= maxwidth || wordsCount > 1))) {
var titleCountLines = tempText.split("\n").length;
View
18 g.radar.min.js
@@ -1,11 +1,7 @@
-/*
- * g.raphael-radar 0.2.3 - Radar chart, based on Raphaël.js
- * https://github.com/Valve/g.raphael-radar
- * Copyright (c) 2012 Valentin Vasilyev (iamvalentin@gmail.com)
- * Licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) license.
- */
-(function(){function t(j,i,h,g,d,b){var n=Raphael;if(!d||0==d.length)throw"Values array is required";var b=b||{},r=360/d.length,m={meshSize:30,labels:[],labelFontSize:14,drawLabels:!0,armFill:"none",armStroke:"rgba(255, 106, 0, .5)",armStrokeWidth:1,drawArms:!0,meshFill:"none",meshStroke:"rgba(120, 120, 120, .5)",meshStrokeWidth:1,drawMesh:!0,max:Math.max.apply(Math,d),pathFill:"none",pathStroke:"#0026ff",pathStrokeWidth:3,pathCircleOuterRadius:4,pathCircleInnerRadius:2,drawPathCircles:!0},k;for(k in b)m[k]=
-b[k];b=m;delete m;var o=function(b,a,e,c){var f=n.rad(c),c=b+e*Math.cos(f),e=a+e*Math.sin(f);return["M",b,a,"L",c,e,"Z"].join()},p=function(b,a,e,c,f){for(var l=["M"],d=c+360;c<d;){var j=b+e*Math.cos(n.rad(c)),g=a+e*Math.sin(n.rad(c));l.push(j);l.push(g);l.push("L");c+=f}l.push("Z");return l.join(",")},m=function(a,d,e,c){var f=n.rad(c),c=a+e*Math.cos(f),e=d+e*Math.sin(f);return{x:Math.round(c)===a?c:c<a?c-10:c+10,y:Math.round(e)===d?e:e<d?e-10:e+10,attr:{"text-anchor":Math.round(c)===a?"middle":
-c<a?"end":"start","font-size":b.labelFontSize}}};k=function(a,d,e,c,f,l,g){c=n.rad(c);a+=e/l*f*Math.cos(c);d+=e/l*f*Math.sin(c);j.circle(a,d,2*b.pathCircleOuterRadius).attr({fill:b.pathStroke,stroke:"none",title:g+": "+f});j.circle(a,d,2*b.pathCircleInnerRadius).attr({fill:"#fff",stroke:"none",title:g+": "+f})};if(b.drawArms)for(var a=0,q=d.length;a<q;)j.path(o(i,h,g,270+r*a)).attr({fill:b.armFill,stroke:b.armStroke,"stroke-width":b.armStrokeWidth}),++a;if(b.drawMesh){for(var a=Math.floor(g/b.meshSize),
-s=q=g/a,o=[];a--;)o.push(p(i,h,s,270,r)),s+=q;a=0;for(q=o.length;a<q;)j.path(o[a]).attr({fill:b.meshFill,stroke:b.meshStroke,"stroke-width":b.meshStrokeWidth}),++a}if(b.drawLabels)for(a=b.labels.length;a--;)p=m(i,h,g,270+r*a),j.text(p.x,p.y,b.labels[a]).attr(p.attr);(function(a,d,e,c,f,g){for(var i=[],h=0,m=f.length;h<m;){var k=n.rad(c+360/f.length*h);i.push(0==h?"M":"L");i.push(a+e/g*f[h]*Math.cos(k));i.push(d+e/g*f[h]*Math.sin(k));++h}i.push("Z");j.path(i.join(",")).attr({stroke:b.pathStroke,fill:b.pathFill,
-"stroke-width":b.pathStrokeWidth,"stroke-linejoin":"round"})})(i,h,g,270,d,b.max);if(b.drawPathCircles)for(a=d.length;a--;)k(i,h,g,270+r*a,d[a],b.max,b.labels[a])}var u=function(){};u.prototype=Raphael.g;t.prototype=new u;Raphael.fn.radar=function(j,i,h,g,d){return new t(this,j,i,h,g,d)}})();
+(function(){function x(l,o,p,j,g,c){var q=Raphael;if(!g||0==g.length)throw"Values array is required";var c=c||{},s=360/g.length,t={meshSize:30,labels:[],labelFontSize:14,valueFontSize:14,drawLabels:!0,drawValues:!0,armFill:"none",armStroke:"rgba(255, 106, 0, .5)",armStrokeWidth:1,drawArms:!0,meshFill:"none",meshStroke:"rgba(120, 120, 120, .5)",meshStrokeWidth:1,drawMesh:!0,max:Math.max.apply(Math,g),pathFill:"none",pathStroke:"#0026ff",pathStrokeWidth:3,pathCircleOuterRadius:4,pathCircleInnerRadius:2,
+drawPathCircles:!0},u;for(u in c)t[u]=c[u];c=t;delete t;var f=function(c,a,d,e){var m=q.rad(e),e=c+d*Math.cos(m),d=a+d*Math.sin(m);return["M",c,a,"L",e,d,"Z"].join()},i=function(c,a,d,e,m){for(var b=["M"],h=e+360;e<h;){var f=c+d*Math.cos(q.rad(e)),g=a+d*Math.sin(q.rad(e));b.push(f);b.push(g);b.push("L");e+=m}b.push("Z");return b.join(",")},t=function(a,b,d,e){var m=q.rad(e),e=a+d*Math.cos(m),d=b+d*Math.sin(m);return{x:Math.round(e)===a?e:e<a?e-10:e+10,y:Math.round(d)===b?d:d<b?d-10:d+10,attr:{"text-anchor":Math.round(e)===
+a?"middle":e<a?"end":"start","font-size":c.labelFontSize}}},r=function(a,b,d,e,m,f){var e=q.rad(e),h=a+d/f*m*Math.cos(e),d=b+d/f*m*Math.sin(e);Math.round(h)===a&&(d+=10*Math.sin(e));return{x:Math.round(h)===a?h+2:h<a?h-10:h+10,y:Math.round(d)===b?d-2:d<b?d-10:d+10,attr:{"text-anchor":Math.round(h)===a?"middle":h<a?"end":"start","font-size":c.valueFontSize}}};u=function(a,b,d,e,f,g,h){e=q.rad(e);a+=d/g*f*Math.cos(e);b+=d/g*f*Math.sin(e);l.circle(a,b,2*c.pathCircleOuterRadius).attr({fill:c.pathStroke,
+stroke:"none",title:h+": "+f});l.circle(a,b,2*c.pathCircleInnerRadius).attr({fill:"#fff",stroke:"none",title:h+": "+f})};if(c.drawArms)for(var a=0,n=g.length;a<n;)l.path(f(o,p,j,270+s*a)).attr({fill:c.armFill,stroke:c.armStroke,"stroke-width":c.armStrokeWidth}),++a;if(c.drawMesh){for(var a=Math.floor(j/c.meshSize),b=n=j/a,f=[];a--;)f.push(i(o,p,b,270,s)),b+=n;a=0;for(n=f.length;a<n;)l.path(f[a]).attr({fill:c.meshFill,stroke:c.meshStroke,"stroke-width":c.meshStrokeWidth}),++a}if(c.drawValues)for(a=
+g.length;a--;)b=r(o,p,j,270+s*a,g[a],c.max),f=g[a],i=l.text(b.x,b.y,f).attr(b.attr);if(c.drawLabels)for(a=c.labels.length;a--;)for(var b=t(o,p,j,270+s*a),f=c.labels[a],i=l.text(b.x,b.y,f).attr(b.attr),f=f.replace("-","- ").replace("/","/ "),r=f.split(" "),f=r.length,n=Math.min(b.x,l.width-b.x),b=Math.min(b.y,l.height-b.y),w=c.labelFontSize;8<=w;--w){i.attr("font-size",w);for(var k="",v=0;v<f;++v)i.attr("text",k+" "+r[v]),k=i.getBBox().width>n?k+("\n"+r[v]):k+(" "+r[v]);i.attr("text",k);i.getBBox().width>
+n&&(k=k.replace("-","-\n"),i.attr("text",k));if(8==w||i.getBBox().height<=b&&(i.getBBox().width<=n||1<f)){k.split("\n");i.attr("text",k.substring(1));break}}(function(a,b,d,e,f,g){for(var h=[],i=0,k=f.length;i<k;){var j=q.rad(e+360/f.length*i);h.push(0==i?"M":"L");h.push(a+d/g*f[i]*Math.cos(j));h.push(b+d/g*f[i]*Math.sin(j));++i}h.push("Z");l.path(h.join(",")).attr({stroke:c.pathStroke,fill:c.pathFill,"stroke-width":c.pathStrokeWidth,"stroke-linejoin":"round"})})(o,p,j,270,g,c.max);if(c.drawPathCircles)for(a=
+g.length;a--;)u(o,p,j,270+s*a,g[a],c.max,c.labels[a])}var y=function(){};y.prototype=Raphael.g;x.prototype=new y;Raphael.fn.radar=function(l,o,p,j,g){return new x(this,l,o,p,j,g)}})();

0 comments on commit 0321eb7

Please sign in to comment.
Something went wrong with that request. Please try again.