* Copyright 2012 Dan Vanderkam (danvdk@gmail.com)
* MIT-licensed (http://opensource.org/licenses/MIT)
*/
+/*global Dygraph:false */
Dygraph.Plugins.Legend = (function() {
/*
try {
div.style[name] = messagestyle[name];
} catch (e) {
- this.warn("You are using unsupported css properties for your " +
+ Dygraph.warn("You are using unsupported css properties for your " +
"browser in labelsDivStyles");
}
}
return oneEmWidth;
};
+var escapeHTML = function(str) {
+ return str.replace(/&/g, "&").replace(/"/g, """).replace(/</g, "<").replace(/>/g, ">");
+};
+
legend.prototype.select = function(e) {
var xValue = e.selectedX;
var points = e.selectedPoints;
// If no points are selected, we display a default legend. Traditionally,
// this has been blank. But a better default would be a conventional legend,
// which provides essential information for a non-interactive chart.
- var html, sepLines, i, c, dash, strokePattern;
+ var html, sepLines, i, dash, strokePattern;
var labels = g.getLabels();
if (typeof(x) === 'undefined') {
strokePattern = g.getOption("strokePattern", labels[i]);
dash = generateLegendDashHTML(strokePattern, series.color, oneEmWidth);
html += "<span style='font-weight: bold; color: " + series.color + ";'>" +
- dash + " " + labels[i] + "</span>";
+ dash + " " + escapeHTML(labels[i]) + "</span>";
}
return html;
}
// TODO(danvk): use a template string here and make it an attribute.
html += "<span" + cls + ">" + " <b><span style='color: " + series.color + ";'>" +
- pt.name + "</span></b>:" + yval + "</span>";
+ escapeHTML(pt.name) + "</span></b>: " + yval + "</span>";
}
return html;
};