Added support for exporting a scatterplot facet's image as a large image.
git-svn-id: http://google-refine.googlecode.com/svn/trunk@614 7d457c2a-affb-35e4-300a-418c747d4874
This commit is contained in:
parent
066fed7f3d
commit
fae6701493
@ -32,6 +32,10 @@ public class Engine implements Jsonizable {
|
||||
_project = project;
|
||||
}
|
||||
|
||||
public FilteredRows getAllRows() {
|
||||
return new ConjunctiveFilteredRows(false, false);
|
||||
}
|
||||
|
||||
public FilteredRows getAllFilteredRows(boolean includeContextual) {
|
||||
return getFilteredRows(null, includeContextual);
|
||||
}
|
||||
|
@ -80,6 +80,11 @@ public class ScatterplotDrawingRowVisitor implements RowVisitor {
|
||||
}
|
||||
}
|
||||
|
||||
public void setColor(Color color) {
|
||||
g2.setColor(color);
|
||||
g2.setPaint(color);
|
||||
}
|
||||
|
||||
public boolean visit(Project project, int rowIndex, Row row, boolean includeContextual, boolean includeDependent) {
|
||||
Cell cellx = row.getCell(col_x);
|
||||
Cell celly = row.getCell(col_y);
|
||||
|
@ -86,6 +86,7 @@ public class ScatterplotFacet implements Facet {
|
||||
public static final String NAME = "name";
|
||||
public static final String IMAGE = "image";
|
||||
public static final String COLOR = "color";
|
||||
public static final String BASE_COLOR = "base_color";
|
||||
public static final String SIZE = "l";
|
||||
public static final String ROTATION = "r";
|
||||
public static final String DOT = "dot";
|
||||
|
@ -85,6 +85,9 @@ public class GetScatterplotCommand extends Command {
|
||||
String color_str = (o.has(ScatterplotFacet.COLOR)) ? o.getString(ScatterplotFacet.COLOR) : "000000";
|
||||
Color color = new Color(Integer.parseInt(color_str,16));
|
||||
|
||||
String base_color_str = (o.has(ScatterplotFacet.BASE_COLOR)) ? o.getString(ScatterplotFacet.BASE_COLOR) : null;
|
||||
Color base_color = base_color_str != null ? new Color(Integer.parseInt(base_color_str,16)) : null;
|
||||
|
||||
String columnName_x = o.getString(ScatterplotFacet.X_COLUMN_NAME);
|
||||
String expression_x = (o.has(ScatterplotFacet.X_EXPRESSION)) ? o.getString(ScatterplotFacet.X_EXPRESSION) : "value";
|
||||
|
||||
@ -147,8 +150,20 @@ public class GetScatterplotCommand extends Command {
|
||||
columnIndex_x, columnIndex_y, min_x, max_x, min_y, max_y,
|
||||
size, dim_x, dim_y, rotation, dot, color
|
||||
);
|
||||
|
||||
if (base_color != null) {
|
||||
drawer.setColor(base_color);
|
||||
|
||||
FilteredRows filteredRows = engine.getAllRows();
|
||||
filteredRows.accept(project, drawer);
|
||||
|
||||
drawer.setColor(color);
|
||||
}
|
||||
|
||||
{
|
||||
FilteredRows filteredRows = engine.getAllFilteredRows(false);
|
||||
filteredRows.accept(project, drawer);
|
||||
}
|
||||
|
||||
ImageIO.write(drawer.getImage(), "png", output);
|
||||
} else {
|
||||
|
@ -94,6 +94,7 @@ ScatterplotFacet.prototype._initializeUI = function() {
|
||||
'<input type="radio" id="' + facet_id + '-dot-regular" name="' + facet_id + '-dot" value="regular"/><label class="dot-regular-label" for="' + facet_id + '-dot-regular" title="Regular Dot Size"> </label>' +
|
||||
'<input type="radio" id="' + facet_id + '-dot-big" name="' + facet_id + '-dot" value="big"/><label class="dot-big-label" for="' + facet_id + '-dot-big" title="Big Dot Size"> </label>' +
|
||||
'</div>' +
|
||||
'<div><a bind="exportPlotLink" class="action" target="_blank">export plot</a></div>' +
|
||||
'</div>' +
|
||||
'</td>' +
|
||||
'</tr></table>' +
|
||||
@ -218,16 +219,26 @@ ScatterplotFacet.prototype._formulateBaseImageUrl = function() {
|
||||
return this._formulateImageUrl({},{ color: "888888", dot : this._config.dot * 0.9 });
|
||||
};
|
||||
|
||||
ScatterplotFacet.prototype._formulateExportImageUrl = function() {
|
||||
return this._formulateImageUrl(ui.browsingEngine.getJSON(false, this), { dot : this._config.dot * 5, l: 500, base_color: "888888" });
|
||||
};
|
||||
|
||||
ScatterplotFacet.prototype._formulateImageUrl = function(engineConfig, conf) {
|
||||
var options = {};
|
||||
for (var p in this._config) {
|
||||
if (this._config.hasOwnProperty(p)) {
|
||||
options[p] = this._config[p];
|
||||
}
|
||||
}
|
||||
for (var p in conf) {
|
||||
if (conf.hasOwnProperty(p)) {
|
||||
this._config[p] = conf[p];
|
||||
options[p] = conf[p];
|
||||
}
|
||||
}
|
||||
var params = {
|
||||
project: theProject.id,
|
||||
engine: JSON.stringify(engineConfig),
|
||||
plotter: JSON.stringify(this._config)
|
||||
plotter: JSON.stringify(options)
|
||||
};
|
||||
return "/command/get-scatterplot?" + $.param(params);
|
||||
};
|
||||
@ -276,6 +287,7 @@ ScatterplotFacet.prototype.updateState = function(data) {
|
||||
ScatterplotFacet.prototype.changePlot = function() {
|
||||
this._elmts.plotBaseImg.attr("src", this._formulateBaseImageUrl());
|
||||
this._elmts.plotImg.attr("src", this._formulateCurrentImageUrl());
|
||||
this._elmts.exportPlotLink.attr("href", this._formulateExportImageUrl());
|
||||
};
|
||||
|
||||
ScatterplotFacet.prototype.render = function() {
|
||||
@ -296,6 +308,7 @@ ScatterplotFacet.prototype.render = function() {
|
||||
this._elmts.statusDiv.show();
|
||||
|
||||
this._elmts.plotImg.attr("src", this._formulateCurrentImageUrl());
|
||||
this._elmts.exportPlotLink.attr("href", this._formulateExportImageUrl());
|
||||
};
|
||||
|
||||
ScatterplotFacet.prototype._remove = function() {
|
||||
|
Loading…
Reference in New Issue
Block a user