From df7faa752d4a4b10ddea73487b1f8dc088ad742d Mon Sep 17 00:00:00 2001 From: "olau@iola.dk" Date: Wed, 29 Oct 2008 11:46:38 +0000 Subject: [PATCH] Fixed problems with not showing lines git-svn-id: https://flot.googlecode.com/svn/trunk@100 1e0a6537-2640-0410-bfb7-f154510ff394 --- NEWS.txt | 5 ++++- jquery.flot.js | 42 ++++++++++++++++++++++++------------------ 2 files changed, 28 insertions(+), 19 deletions(-) diff --git a/NEWS.txt b/NEWS.txt index ff5f1a7..0c4dd3b 100644 --- a/NEWS.txt +++ b/NEWS.txt @@ -6,7 +6,10 @@ analysis by Joshua Varner). Fix auto-adjustment code when setting min to 0 for an axis where the dataset is completely flat on that axis (report by chovy). Fixed a bug with passing in data from getData to setData when the secondary axes are used (issue 65, reported by -nperelman). +nperelman). Fixed so that it is possible to turn lines off when no +other chart type is shown (based on problem reported by Glenn +Vanderburg), and fixed so that setting lineWidth to 0 also hides the +shadow (based on problem reported by Sergio Nunes). Flot 0.5 diff --git a/jquery.flot.js b/jquery.flot.js index 1ad2059..37a6363 100644 --- a/jquery.flot.js +++ b/jquery.flot.js @@ -60,7 +60,8 @@ fillColor: "#ffffff" }, lines: { - show: false, + // we don't put in show: false so we can see + // whether the user actively disabled lines lineWidth: 2, // in pixels fill: false, fillColor: null @@ -232,6 +233,10 @@ s.lines = $.extend(true, {}, options.lines, s.lines); s.points = $.extend(true, {}, options.points, s.points); s.bars = $.extend(true, {}, options.bars, s.bars); + + // turn on lines automatically in case nothing is set + if (s.lines.show == null && !s.bars.show && !s.points.show) + s.lines.show = true; if (s.shadowSize == null) s.shadowSize = options.shadowSize; @@ -1031,7 +1036,7 @@ } function drawSeries(series) { - if (series.lines.show || (!series.bars.show && !series.points.show)) + if (series.lines.show) drawSeriesLines(series); if (series.bars.show) drawSeriesBars(series); @@ -1266,18 +1271,17 @@ ctx.translate(plotOffset.left, plotOffset.top); ctx.lineJoin = "round"; - var lw = series.lines.lineWidth; - var sw = series.shadowSize; + var lw = series.lines.lineWidth, + sw = series.shadowSize; // FIXME: consider another form of shadow when filling is turned on - if (sw > 0) { + if (lw > 0 && sw > 0) { // draw shadow in two steps - ctx.lineWidth = sw / 2; + var w = sw / 2; + ctx.lineWidth = w; ctx.strokeStyle = "rgba(0,0,0,0.1)"; - plotLine(series.data, lw/2 + sw/2 + ctx.lineWidth/2, series.xaxis, series.yaxis); - - ctx.lineWidth = sw / 2; + plotLine(series.data, lw/2 + w + w/2, series.xaxis, series.yaxis); ctx.strokeStyle = "rgba(0,0,0,0.2)"; - plotLine(series.data, lw/2 + ctx.lineWidth/2, series.xaxis, series.yaxis); + plotLine(series.data, lw/2 + w/2, series.xaxis, series.yaxis); } ctx.lineWidth = lw; @@ -1285,7 +1289,9 @@ setFillStyle(series.lines, series.color); if (series.lines.fill) plotLineArea(series.data, series.xaxis, series.yaxis); - plotLine(series.data, 0, series.xaxis, series.yaxis); + + if (lw > 0) + plotLine(series.data, 0, series.xaxis, series.yaxis); ctx.restore(); } @@ -1324,18 +1330,18 @@ ctx.save(); ctx.translate(plotOffset.left, plotOffset.top); - var lw = series.lines.lineWidth; - var sw = series.shadowSize; - if (sw > 0) { + var lw = series.lines.lineWidth, + sw = series.shadowSize; + if (lw > 0 && sw > 0) { // draw shadow in two steps - ctx.lineWidth = sw / 2; + var w = sw / 2; + ctx.lineWidth = w; ctx.strokeStyle = "rgba(0,0,0,0.1)"; - plotPointShadows(series.data, sw/2 + ctx.lineWidth/2, + plotPointShadows(series.data, w + w/2, series.points.radius, series.xaxis, series.yaxis); - ctx.lineWidth = sw / 2; ctx.strokeStyle = "rgba(0,0,0,0.2)"; - plotPointShadows(series.data, ctx.lineWidth/2, + plotPointShadows(series.data, w/2, series.points.radius, series.xaxis, series.yaxis); }