From: mbghsource Date: Fri, 20 Jan 2012 20:48:23 +0000 (-0500) Subject: Fix issue 264 - non-alpha chars in GViz annotation labels. X-Git-Tag: v1.0.0~340 X-Git-Url: https://adrianiainlam.tk/git/?a=commitdiff_plain;h=5829af3d787ba109c25f45fa8af125bb0cac046e;p=dygraphs.git Fix issue 264 - non-alpha chars in GViz annotation labels. --- diff --git a/dygraph.js b/dygraph.js index 66432f7..601967a 100644 --- a/dygraph.js +++ b/dygraph.js @@ -2774,6 +2774,19 @@ Dygraph.prototype.parseArray_ = function(data) { * @private */ Dygraph.prototype.parseDataTable_ = function(data) { + var shortTextForAnnotationNum = function(num) { + // converts [0-9]+ [A-Z][a-z]* + // example: 0=A, 1=B, 25=Z, 26=Aa, 27=Ab + // and continues like.. Ba Bb .. Za .. Zz..Aaa...Zzz Aaaa Zzzz + var shortText = String.fromCharCode(65 /* A */ + num % 26); + num = Math.floor(num / 26); + while ( num > 0 ) { + shortText = String.fromCharCode(65 /* A */ + (num - 1) % 26 ) + shortText.toLowerCase(); + num = Math.floor((num - 1) / 26); + } + return shortText; + } + var cols = data.getNumberOfColumns(); var rows = data.getNumberOfRows(); @@ -2855,7 +2868,7 @@ Dygraph.prototype.parseDataTable_ = function(data) { var ann = {}; ann.series = data.getColumnLabel(col); ann.xval = row[0]; - ann.shortText = String.fromCharCode(65 /* A */ + annotations.length); + ann.shortText = shortTextForAnnotationNum(annotations.length); ann.text = ''; for (var k = 0; k < annotationCols[col].length; k++) { if (k) ann.text += "\n"; diff --git a/tests/annotation-gviz.html b/tests/annotation-gviz.html index c043894..ec458b0 100644 --- a/tests/annotation-gviz.html +++ b/tests/annotation-gviz.html @@ -25,14 +25,20 @@ data.addColumn('string', 'title2'); data.addColumn('string', 'text2'); data.addRows([ - [new Date(2008, 1 ,1), 30000, undefined, undefined, 40645, undefined, undefined], - [new Date(2008, 1 ,2), 14045, undefined, undefined, 20374, undefined, undefined], - [new Date(2008, 1 ,3), 55022, undefined, undefined, 50766, undefined, undefined], - [new Date(2008, 1 ,4), 75284, undefined, undefined, 14334, 'Out of Stock','Ran out of stock on pens at 4pm'], - [new Date(2008, 1 ,5), 41476, 'Bought Pens','Bought 200k pens', 66467, undefined, undefined], - [new Date(2008, 1 ,6), 33322, undefined, undefined, 39463, undefined, undefined] + [new Date(2008, 11 ,1), 30000, undefined, undefined, 40645, undefined, undefined], + [new Date(2008, 11 ,2), 14045, undefined, undefined, 20374, undefined, undefined], + [new Date(2008, 11 ,3), 55022, undefined, undefined, 50766, undefined, undefined], + [new Date(2008, 11 ,4), 75284, undefined, undefined, 14334, 'Out of Stock','Ran out of stock on pens at 4pm'], + [new Date(2008, 11 ,5), 41476, 'Bought Pens','Bought 200k pens', 66467, undefined, undefined], + [new Date(2008, 11 ,6), 33322, undefined, undefined, 39463, undefined, undefined] ]); + for (var i = 1; i < 14; i++) { + data.addRows([ + [new Date(2008, 11 , 6 + i), i * 1000, 'title1-' + i, 'text1 ' + (i * 1000 - i), (i * 2000 + i), 'title2-' + i, 'text2' + i * 1000], + ]); + } + var chart = new google.visualization.AnnotatedTimeLine(document.getElementById('gviz_div')); chart.draw(data, {displayAnnotations: true}); @@ -50,4 +56,3 @@
-