I'm having trouble implementing this over two functions. I have a
page where the user can choose a bunch of different options (call them
1-12) which then plots a bunch of different series (call them A - Z).
So I divided my plotting and the series selection into two different
functions like this:
function makeplot(options, series, result) {
var placeholder = $("#placeholder");
var plot = $.plot(placeholder, result, options);
if ((series == "wavelength" || series == "energy") &&
(result.toSource().toString().search("xaxis") != -1 )) {
placeholder.unbind("plotselected")
placeholder.bind("plotselected", function (event, ranges) {
plot = $.plot(placeholder, result,
$.extend(true, {}, options, {
xaxis: { min: ranges.xaxis.from, max:
ranges.xaxis.to },
x2axis: { min: ranges.x2axis.from, max:
ranges.x2axis.to },
yaxis: { min: ranges.yaxis.from, max:
ranges.yaxis.to }
}));
});
}
else {
placeholder.unbind("plotselected");
placeholder.bind("plotselected", function (event, ranges) {
plot = $.plot(placeholder, result,
$.extend(true, {}, options, {
xaxis: { min: ranges.xaxis.from, max:
ranges.xaxis.to },
yaxis: { min: ranges.yaxis.from, max:
ranges.yaxis.to }
}));
});
}
placeholder.live("plotunselected", function (event) {
plot = $.plot(placeholder, result, options)
});
};
function makeCheckboxes (options, series, result) {
// insert checkboxes
$("#choices").html(" ");
var choiceContainer = $("#choices");
$.each(result, function(key, val) {
choiceContainer.append('<br/><input type="checkbox" name="' +
key +
'" checked="checked" id="id' + key +
'">' +
'<label for="id' + key + '">'
+ val.label + '</label>');
});
choiceContainer.find("input").click(plotAccordingToChoices);
function plotAccordingToChoices() {
var data = [];
choiceContainer.find("input:checked").each(function () {
var key = $(this).attr("name");
if (key && result[key])
data.push(result[key]);
});
if (data.length > 0) {
makeplot(options, series, data);
};
};
};
For example, right now when a user chooses option 1, an Ajax call to a
MySQL db is fired off and if successful, this calls the makeplot
function. If I give plot a global scope, calculate the zoom level in
plotAccordingtoChoices, pass zoomed to makeplot, then if a user zooms
and then unchecks a series, the plot no longer unzooms to the original
size because the original options for xaxis and yaxis have changed.
However options are individually defined for choice 1, 2, 3 and so on
because they all have different xaxis & yaxis restrictions.
I am stuck. How can I pass the zoom level around while maintaining
the limited scope of the options variable?
> Short answer yes.
>
> This is really independent of zooming per se. All you are doing is
> grabbing the existing settings for the axis (which had previously been
> zoomed) and then passing them in as new options for the next time you
> plot the graph. The axis are global options so individual series
> presence won't affect them.
>
> Josh
>
> On Tue, May 18, 2010 at 8:23 AM, Spencer Aloysius
>