Created
August 4, 2010 16:16
-
-
Save jboesch/508369 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Have you ever used Graphael Pie chart (http://g.raphaeljs.com/) and found that when you use a really long legend label, it sometimes goes right off the screen and your chart doesn't align with it? This fixes that. | |
It calculates the graph x to center align the labels with the chart. This only works if you position the pie chart 'south' or 'north' in the 'legendpos' option. | |
*/ | |
var legend = ['Awesome', 'Legend', 'Labels whoa this is long']; | |
legend.sort(function(a, b){ return a.length < b.length; }); | |
var longest_word = legend[0].length; | |
var x_offset = 1.5; // This might be different in your case. Mess around with it. | |
var graph_x = (graph_x / longest_word) * (longest_word / x_offset); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment