Commit a709b3d1 authored by olau@iola.dk's avatar olau@iola.dk

Fixed more things preventing the packed version from working

git-svn-id: https://flot.googlecode.com/svn/trunk@6 1e0a6537-2640-0410-bfb7-f154510ff394
parent 64084d1a
...@@ -112,6 +112,8 @@ ...@@ -112,6 +112,8 @@
this.getCanvas = function() { return canvas; }; this.getCanvas = function() { return canvas; };
this.getPlotOffset = function() { return plotOffset; }; this.getPlotOffset = function() { return plotOffset; };
this.clearSelection = clearSelection;
this.setSelection = setSelection;
function parseData(d) { function parseData(d) {
var res = []; var res = [];
...@@ -147,13 +149,13 @@ ...@@ -147,13 +149,13 @@
// the canvas // the canvas
canvas = jQuery('<canvas width="' + canvasWidth + '" height="' + canvasHeight + '"></canvas>').appendTo(target).get(0); canvas = jQuery('<canvas width="' + canvasWidth + '" height="' + canvasHeight + '"></canvas>').appendTo(target).get(0);
if (jQuery.browser.msie) // excanvas hack if (jQuery.browser.msie) // excanvas hack
canvas = window.G_vmlCanvasManager.initElement(canvas) canvas = window.G_vmlCanvasManager.initElement(canvas);
ctx = canvas.getContext("2d"); ctx = canvas.getContext("2d");
// overlay canvas for interactive features // overlay canvas for interactive features
overlay = jQuery('<canvas style="position:absolute;left:0px;top:0px;" width="' + canvasWidth + '" height="' + canvasHeight + '"></canvas>').appendTo(target).get(0); overlay = jQuery('<canvas style="position:absolute;left:0px;top:0px;" width="' + canvasWidth + '" height="' + canvasHeight + '"></canvas>').appendTo(target).get(0);
if (jQuery.browser.msie) // excanvas hack if (jQuery.browser.msie) // excanvas hack
overlay = window.G_vmlCanvasManager.initElement(overlay) overlay = window.G_vmlCanvasManager.initElement(overlay);
octx = overlay.getContext("2d"); octx = overlay.getContext("2d");
} }
...@@ -248,9 +250,10 @@ ...@@ -248,9 +250,10 @@
axis.tickSize = getTickSize(axisOptions.noTicks, min, max, axisOptions.tickDecimals); axis.tickSize = getTickSize(axisOptions.noTicks, min, max, axisOptions.tickDecimals);
// consider autoscaling // consider autoscaling
var margin;
if (axisOptions.min == null) { if (axisOptions.min == null) {
// first add in a little margin // first add in a little margin
var margin = axisOptions.autoscaleMargin; margin = axisOptions.autoscaleMargin;
if (margin != 0) { if (margin != 0) {
min -= axis.tickSize * margin; min -= axis.tickSize * margin;
// make sure we don't go below zero if all // make sure we don't go below zero if all
...@@ -262,7 +265,7 @@ ...@@ -262,7 +265,7 @@
} }
} }
if (axisOptions.max == null) { if (axisOptions.max == null) {
var margin = axisOptions.autoscaleMargin; margin = axisOptions.autoscaleMargin;
if (margin != 0) { if (margin != 0) {
max += axis.tickSize * margin; max += axis.tickSize * margin;
if (max > 0 && axis.datamax <= 0) if (max > 0 && axis.datamax <= 0)
...@@ -290,11 +293,12 @@ ...@@ -290,11 +293,12 @@
} }
function calculateTicks(axis, axisOptions) { function calculateTicks(axis, axisOptions) {
var i;
axis.ticks = []; axis.ticks = [];
if (axisOptions.ticks) { if (axisOptions.ticks) {
// user-supplied ticks, just copy them // user-supplied ticks, just copy them
for (var i = 0; i < axisOptions.ticks.length; ++i) { for (i = 0; i < axisOptions.ticks.length; ++i) {
var v, label; var v, label;
var t = axisOptions.ticks[i]; var t = axisOptions.ticks[i];
if (typeof(t) == "object") { if (typeof(t) == "object") {
...@@ -315,7 +319,7 @@ ...@@ -315,7 +319,7 @@
// round to nearest multiple of tick size // round to nearest multiple of tick size
var start = axis.tickSize * Math.ceil(axis.min / axis.tickSize); var start = axis.tickSize * Math.ceil(axis.min / axis.tickSize);
// then spew out all possible ticks // then spew out all possible ticks
for (var i = 0; start + i * axis.tickSize <= axis.max; ++i) { for (i = 0; start + i * axis.tickSize <= axis.max; ++i) {
v = start + i * axis.tickSize; v = start + i * axis.tickSize;
// round (this is always needed to fix numerical instability) // round (this is always needed to fix numerical instability)
...@@ -345,7 +349,7 @@ ...@@ -345,7 +349,7 @@
// measure it // measure it
var dummyDiv = $('<div style="position:absolute;top:-10000px;font-size:smaller" class="gridLabel">' + max_label + '</div>').appendTo(target); var dummyDiv = $('<div style="position:absolute;top:-10000px;font-size:smaller" class="gridLabel">' + max_label + '</div>').appendTo(target);
labelMaxWidth = dummyDiv.width(); labelMaxWidth = dummyDiv.width();
labelMaxHeight = dummyDiv.height() labelMaxHeight = dummyDiv.height();
dummyDiv.remove(); dummyDiv.remove();
var maxOutset = 2; // grid outline line width var maxOutset = 2; // grid outline line width
...@@ -435,8 +439,9 @@ ...@@ -435,8 +439,9 @@
// easy to mid-align // easy to mid-align
var noLabels = 0; var noLabels = 0;
for (i = 0; i < xaxis.ticks.length; ++i) { for (i = 0; i < xaxis.ticks.length; ++i) {
if (xaxis.ticks[i].label) if (xaxis.ticks[i].label) {
++noLabels; ++noLabels;
}
} }
var xBoxWidth = plotWidth / noLabels; var xBoxWidth = plotWidth / noLabels;
...@@ -456,7 +461,7 @@ ...@@ -456,7 +461,7 @@
html += '<div style="position:absolute;top:' + (plotOffset.top + translateVert(tick.v) - labelMaxHeight/2) + 'px;left:0;width:' + labelMaxWidth + 'px;text-align:right" class="gridLabel">' + tick.label + "</div>"; html += '<div style="position:absolute;top:' + (plotOffset.top + translateVert(tick.v) - labelMaxHeight/2) + 'px;left:0;width:' + labelMaxWidth + 'px;text-align:right" class="gridLabel">' + tick.label + "</div>";
} }
html += '</div>' html += '</div>';
target.append(html); target.append(html);
} }
...@@ -937,7 +942,7 @@ ...@@ -937,7 +942,7 @@
if (i % options.legend.noColumns == 0) { if (i % options.legend.noColumns == 0) {
if (rowStarted) if (rowStarted)
fragments.push('</tr>') fragments.push('</tr>');
fragments.push('<tr>'); fragments.push('<tr>');
rowStarted = true; rowStarted = true;
} }
...@@ -974,11 +979,9 @@ ...@@ -974,11 +979,9 @@
var prevSelection = null; var prevSelection = null;
var selectionInterval = null; var selectionInterval = null;
function onMouseMove(e) { function onMouseMove(ev) {
// FIXME: temp. work-around until jQuery bug 1871 is fixed // FIXME: temp. work-around until jQuery bug 1871 is fixed
var e = e || window.event; var e = ev || window.event;
var de = document.documentElement;
var b = document.body;
if (e.pageX == null && e.clientX != null) { if (e.pageX == null && e.clientX != null) {
var de = document.documentElement, b = document.body; var de = document.documentElement, b = document.body;
lastMousePos.pageX = e.clientX + (de && de.scrollLeft || b.scrollLeft || 0); lastMousePos.pageX = e.clientX + (de && de.scrollLeft || b.scrollLeft || 0);
...@@ -1041,7 +1044,7 @@ ...@@ -1041,7 +1044,7 @@
setSelectionPos(selection.second, e); setSelectionPos(selection.second, e);
clearSelection(); clearSelection();
if (!selectionIsSane() || e.which != 1) if (!selectionIsSane() || e.which != 1)
return; return false;
drawSelection(); drawSelection();
triggerSelectedEvent(); triggerSelectedEvent();
...@@ -1050,7 +1053,7 @@ ...@@ -1050,7 +1053,7 @@
} }
function setSelectionPos(pos, e) { function setSelectionPos(pos, e) {
var offset = $(overlay).offset() var offset = $(overlay).offset();
if (options.selection.mode == "y") { if (options.selection.mode == "y") {
if (pos == selection.first) if (pos == selection.first)
pos.x = 0; pos.x = 0;
...@@ -1101,9 +1104,7 @@ ...@@ -1101,9 +1104,7 @@
prevSelection = null; prevSelection = null;
} }
this.clearSelection = clearSelection; function setSelection(area) {
this.setSelection = function(area) {
clearSelection(); clearSelection();
if (options.selection.mode == "x") { if (options.selection.mode == "x") {
...@@ -1111,28 +1112,28 @@ ...@@ -1111,28 +1112,28 @@
selection.second.y = plotHeight; selection.second.y = plotHeight;
} }
else { else {
selection.first.y = (yaxis.max - area.y1) * vertScale selection.first.y = (yaxis.max - area.y1) * vertScale;
selection.second.y = (yaxis.max - area.y2) * vertScale selection.second.y = (yaxis.max - area.y2) * vertScale;
} }
if (options.selection.mode == "y") { if (options.selection.mode == "y") {
selection.first.x = 0; selection.first.x = 0;
selection.second.x = plotWidth; selection.second.x = plotWidth;
} }
else { else {
selection.first.x = (area.x1 - xaxis.min) * hozScale selection.first.x = (area.x1 - xaxis.min) * hozScale;
selection.second.x = (area.x2 - xaxis.min) * hozScale selection.second.x = (area.x2 - xaxis.min) * hozScale;
} }
drawSelection(); drawSelection();
triggerSelectedEvent(); triggerSelectedEvent();
}; }
function drawSelection() { function drawSelection() {
if (prevSelection != null if (prevSelection != null &&
&& selection.first.x == prevSelection.first.x selection.first.x == prevSelection.first.x &&
&& selection.first.y == prevSelection.first.y selection.first.y == prevSelection.first.y &&
&& selection.second.x == prevSelection.second.x selection.second.x == prevSelection.second.x &&
&& selection.second.y == prevSelection.second.y) selection.second.y == prevSelection.second.y)
return; return;
octx.strokeStyle = parseColor(options.selection.color).scale(null, null, null, 0.8).toString(); octx.strokeStyle = parseColor(options.selection.color).scale(null, null, null, 0.8).toString();
...@@ -1188,10 +1189,10 @@ ...@@ -1188,10 +1189,10 @@
// color helpers, inspiration from the jquery color animation // color helpers, inspiration from the jquery color animation
// plugin by John Resig // plugin by John Resig
function Color (r, g, b, a) { function Color (r, g, b, a) {
this.r = r != null ? r: 0; this.r = (r != null) ? r: 0;
this.g = g != null ? g: 0; this.g = (g != null) ? g: 0;
this.b = b != null ? b: 0; this.b = (b != null) ? b: 0;
this.a = a != null ? a: 1.0; this.a = (a != null) ? a: 1.0;
this.toString = function() { this.toString = function() {
if (this.a >= 1.0) if (this.a >= 1.0)
...@@ -1202,7 +1203,7 @@ ...@@ -1202,7 +1203,7 @@
return "rgba(" + [ return "rgba(" + [
this.r, this.g, this.b, this.a this.r, this.g, this.b, this.a
].join(",") + ")"; ].join(",") + ")";
} };
this.scale = function(rf, gf, bf, af) { this.scale = function(rf, gf, bf, af) {
if (rf != null) if (rf != null)
...@@ -1214,7 +1215,7 @@ ...@@ -1214,7 +1215,7 @@
if (af != null) if (af != null)
this.a *= af; this.a *= af;
return this.normalize(); return this.normalize();
} };
this.adjust = function(rd, gd, bd, ad) { this.adjust = function(rd, gd, bd, ad) {
if (rd != null) if (rd != null)
...@@ -1226,11 +1227,11 @@ ...@@ -1226,11 +1227,11 @@
if (ad != null) if (ad != null)
this.a += ad; this.a += ad;
return this.normalize(); return this.normalize();
} };
this.clone = function() { this.clone = function() {
return new Color(this.r, this.b, this.g, this.a); return new Color(this.r, this.b, this.g, this.a);
} };
this.normalize = function() { this.normalize = function() {
this.r = Math.max(Math.min(parseInt(this.r), 255), 0); this.r = Math.max(Math.min(parseInt(this.r), 255), 0);
...@@ -1238,7 +1239,7 @@ ...@@ -1238,7 +1239,7 @@
this.b = Math.max(Math.min(parseInt(this.b), 255), 0); this.b = Math.max(Math.min(parseInt(this.b), 255), 0);
this.a = Math.max(Math.min(this.a, 1), 0); this.a = Math.max(Math.min(this.a, 1), 0);
return this; return this;
} };
this.normalize(); this.normalize();
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment