X-Git-Url: https://adrianiainlam.tk/git/?a=blobdiff_plain;ds=sidebyside;f=src%2Fplugins%2Flegend.js;h=40a486344c5124bf0e303d29fc86bfdef6c66bf4;hb=refs%2Fheads%2Fmaster;hp=9644576f4ee953d92fd73431a283be23a849069c;hpb=7454418463735d68643ee25f112ec2e8288b859c;p=dygraphs.git diff --git a/src/plugins/legend.js b/src/plugins/legend.js index 9644576..40a4863 100644 --- a/src/plugins/legend.js +++ b/src/plugins/legend.js @@ -35,9 +35,6 @@ Legend.prototype.toString = function() { return "Legend Plugin"; }; -// (defined below) -var generateLegendDashHTML; - /** * This is called during the dygraph constructor, after options have been set * but before the data is available. @@ -52,7 +49,6 @@ var generateLegendDashHTML; */ Legend.prototype.activate = function(g) { var div; - var divWidth = g.getOption('labelsDivWidth'); var userLabelsDiv = g.getOption('labelsDiv'); if (userLabelsDiv && null !== userLabelsDiv) { @@ -62,35 +58,8 @@ Legend.prototype.activate = function(g) { div = userLabelsDiv; } } else { - // Default legend styles. These can be overridden in CSS by adding - // "!important" after your rule, e.g. "left: 30px !important;" - var messagestyle = { - "position": "absolute", - "fontSize": "14px", - "zIndex": 10, - "width": divWidth + "px", - "top": "0px", - "left": (g.size().width - divWidth - 2) + "px", - "background": "white", - "lineHeight": "normal", - "textAlign": "left", - "overflow": "hidden"}; - - // TODO(danvk): get rid of labelsDivStyles? CSS is better. - utils.update(messagestyle, g.getOption('labelsDivStyles')); div = document.createElement("div"); div.className = "dygraph-legend"; - for (var name in messagestyle) { - if (!messagestyle.hasOwnProperty(name)) continue; - - try { - div.style[name] = messagestyle[name]; - } catch (e) { - console.warn("You are using unsupported css properties for your " + - "browser in labelsDivStyles"); - } - } - // TODO(danvk): come up with a cleaner way to expose this. g.graphDiv.appendChild(div); this.is_generated_div_ = true; @@ -136,7 +105,7 @@ Legend.prototype.select = function(e) { if (legendMode === 'follow') { // create floating legend div var area = e.dygraph.plotter_.area; - var labelsDivWidth = e.dygraph.getOption('labelsDivWidth'); + var labelsDivWidth = this.legend_div_.offsetWidth; var yAxisLabelWidth = e.dygraph.getOptionForAxis('axisLabelWidth', 'y'); // determine floating [left, top] coordinates of the legend div // within the plotter_ area @@ -195,10 +164,9 @@ Legend.prototype.predraw = function(e) { // TODO(danvk): only use real APIs for this. e.dygraph.graphDiv.appendChild(this.legend_div_); var area = e.dygraph.getArea(); - var labelsDivWidth = e.dygraph.getOption("labelsDivWidth"); + var labelsDivWidth = this.legend_div_.offsetWidth; this.legend_div_.style.left = area.x + area.w - labelsDivWidth - 1 + "px"; this.legend_div_.style.top = area.y + "px"; - this.legend_div_.style.width = labelsDivWidth + "px"; }; /** @@ -268,7 +236,7 @@ Legend.generateLegendHTML = function(g, x, sel_points, oneEmWidth, row) { var seriesData = labelToSeries[pt.name]; seriesData.y = pt.yval; - if ((pt.yval === 0 && !showZeros) || isNaN(pt.canvasy) || pt.canvasy === null || pt.canvasy === undefined) { + if ((pt.yval === 0 && !showZeros) || isNaN(pt.canvasy)) { seriesData.isVisible = false; continue; } @@ -341,12 +309,10 @@ Legend.defaultFormatter = function(data) { * @private */ // TODO(danvk): cache the results of this -generateLegendDashHTML = function(strokePattern, color, oneEmWidth) { +function generateLegendDashHTML(strokePattern, color, oneEmWidth) { // Easy, common case: a solid line if (!strokePattern || strokePattern.length <= 1) { - return "
"; + return ``; } var i, j, paddingLeft, marginRight; @@ -393,10 +359,7 @@ generateLegendDashHTML = function(strokePattern, color, oneEmWidth) { // The repeated first segment has no right margin. marginRight = 0; } - dash += ""; + dash += ``; } } return dash;