2010-04-12 21:22:49 +02:00
|
|
|
function ScatterplotFacet(div, config, options) {
|
|
|
|
this._div = div;
|
|
|
|
this._config = config;
|
|
|
|
this._options = options;
|
|
|
|
|
|
|
|
this._from_x = ("from_x" in this._config) ? this._config.from_x : null;
|
|
|
|
this._to_x = ("to_x" in this._config) ? this._config.to_x : null;
|
|
|
|
this._from_y = ("from_y" in this._config) ? this._config.from_y : null;
|
|
|
|
this._to_y = ("to_y" in this._config) ? this._config.to_y : null;
|
|
|
|
|
|
|
|
this._error = false;
|
|
|
|
this._initializedUI = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
ScatterplotFacet.prototype.reset = function() {
|
|
|
|
// TODO
|
|
|
|
};
|
|
|
|
|
|
|
|
ScatterplotFacet.reconstruct = function(div, uiState) {
|
|
|
|
return new ScatterplotFacet(div, uiState.c, uiState.o);
|
|
|
|
};
|
|
|
|
|
|
|
|
ScatterplotFacet.prototype.getUIState = function() {
|
|
|
|
var json = {
|
|
|
|
c: this.getJSON(),
|
|
|
|
o: this._options
|
|
|
|
};
|
|
|
|
|
|
|
|
return json;
|
|
|
|
};
|
|
|
|
|
|
|
|
ScatterplotFacet.prototype.getJSON = function() {
|
|
|
|
var o = {
|
|
|
|
type: "scatterplot",
|
|
|
|
name: this._config.name,
|
2010-04-13 05:44:42 +02:00
|
|
|
x_columnName : this._config.x_columnName,
|
|
|
|
y_columnName : this._config.y_columnName,
|
|
|
|
x_expression: this._config.x_expression,
|
|
|
|
y_expression: this._config.y_expression,
|
2010-04-14 07:14:33 +02:00
|
|
|
dot: this._config.dot,
|
|
|
|
dim: this._config.dim,
|
2010-04-12 21:22:49 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
return o;
|
|
|
|
};
|
|
|
|
|
|
|
|
ScatterplotFacet.prototype.hasSelection = function() {
|
|
|
|
// TODO
|
|
|
|
};
|
|
|
|
|
|
|
|
ScatterplotFacet.prototype._initializeUI = function() {
|
|
|
|
var self = this;
|
|
|
|
var container = this._div.empty();
|
|
|
|
|
|
|
|
var headerDiv = $('<div></div>').addClass("facet-title").appendTo(container);
|
|
|
|
$('<span></span>').text(this._config.name).appendTo(headerDiv);
|
|
|
|
|
|
|
|
var resetButton = $('<a href="javascript:{}"></a>').addClass("facet-choice-link").text("reset").click(function() {
|
|
|
|
self.reset();
|
|
|
|
self._updateRest();
|
|
|
|
}).prependTo(headerDiv);
|
|
|
|
|
|
|
|
var removeButton = $('<img>')
|
|
|
|
.attr("src", "images/close.png")
|
|
|
|
.attr("title", "Remove this facet")
|
|
|
|
.addClass("facet-choice-link")
|
|
|
|
.click(function() {
|
|
|
|
self._remove();
|
|
|
|
}).prependTo(headerDiv);
|
|
|
|
|
|
|
|
var bodyDiv = $('<div></div>').addClass("facet-scatterplot-body").appendTo(container);
|
|
|
|
|
|
|
|
this._messageDiv = $('<div>').text("Loading...").addClass("facet-scatterplot-message").appendTo(bodyDiv);
|
|
|
|
this._plotDiv = $('<div>').addClass("facet-scatterplot-plot").appendTo(bodyDiv);
|
|
|
|
this._statusDiv = $('<div>').addClass("facet-scatterplot-status").appendTo(bodyDiv);
|
2010-04-15 20:42:41 +02:00
|
|
|
|
2010-04-13 05:44:42 +02:00
|
|
|
this._plot = new ScatterplotWidget(this._plotDiv, this._config);
|
2010-04-12 21:22:49 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
ScatterplotFacet.prototype.updateState = function(data) {
|
2010-04-13 09:26:26 +02:00
|
|
|
if ("x_min" in data && "x_max" in data && "x_max" in data && "x_min" in data) {
|
2010-04-12 21:22:49 +02:00
|
|
|
this._error = false;
|
|
|
|
|
2010-04-13 09:26:26 +02:00
|
|
|
this._config.x_min = data.x_min;
|
|
|
|
this._config.x_max = data.x_max;
|
|
|
|
this._config.y_min = data.y_min;
|
|
|
|
this._config.y_max = data.y_max;
|
2010-04-12 21:22:49 +02:00
|
|
|
|
2010-04-13 09:26:26 +02:00
|
|
|
this._from_x = Math.max(data.from_x, this._config.x_min);
|
2010-04-13 05:44:42 +02:00
|
|
|
if ("to_x" in data) {
|
2010-04-13 09:26:26 +02:00
|
|
|
this._to_x = Math.min(data.to_x, this._config.x_max);
|
2010-04-13 05:44:42 +02:00
|
|
|
} else {
|
2010-04-13 09:26:26 +02:00
|
|
|
this._to_x = data.x_max;
|
2010-04-13 05:44:42 +02:00
|
|
|
}
|
|
|
|
|
2010-04-13 09:26:26 +02:00
|
|
|
this._from_y = Math.max(data.from_y, this._config.x_min);
|
2010-04-13 05:44:42 +02:00
|
|
|
if ("to_y" in data) {
|
2010-04-13 09:26:26 +02:00
|
|
|
this._to_y = Math.min(data.to_y, this._config.x_max);
|
2010-04-13 05:44:42 +02:00
|
|
|
} else {
|
2010-04-13 09:26:26 +02:00
|
|
|
this._to_y = data.x_max;
|
2010-04-12 21:22:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
this._error = true;
|
|
|
|
this._errorMessage = "error" in data ? data.error : "Unknown error.";
|
|
|
|
}
|
|
|
|
|
|
|
|
this.render();
|
|
|
|
};
|
|
|
|
|
|
|
|
ScatterplotFacet.prototype.render = function() {
|
|
|
|
if (!this._initializedUI) {
|
|
|
|
this._initializeUI();
|
|
|
|
this._initializedUI = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this._error) {
|
|
|
|
this._messageDiv.text(this._errorMessage).show();
|
2010-04-13 05:44:42 +02:00
|
|
|
this._plotDiv.hide();
|
2010-04-12 21:22:49 +02:00
|
|
|
this._statusDiv.hide();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this._messageDiv.hide();
|
|
|
|
this._plotDiv.show();
|
|
|
|
this._statusDiv.show();
|
|
|
|
|
|
|
|
this._plot.update(
|
2010-04-13 05:44:42 +02:00
|
|
|
this._config.x_min,
|
|
|
|
this._config.x_max,
|
|
|
|
this._x_from,
|
|
|
|
this._x_to,
|
|
|
|
this._config.y_min,
|
|
|
|
this._config.y_max,
|
|
|
|
this._y_from,
|
|
|
|
this._y_to
|
2010-04-12 21:22:49 +02:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
ScatterplotFacet.prototype._remove = function() {
|
|
|
|
ui.browsingEngine.removeFacet(this);
|
|
|
|
|
|
|
|
this._div = null;
|
|
|
|
this._config = null;
|
|
|
|
};
|
|
|
|
|
|
|
|
ScatterplotFacet.prototype._updateRest = function() {
|
|
|
|
Gridworks.update({ engineChanged: true });
|
|
|
|
};
|