From fae6701493cd6e3e8a0f145e4172381b26dfa5ab Mon Sep 17 00:00:00 2001 From: David Huynh Date: Thu, 6 May 2010 20:44:40 +0000 Subject: [PATCH] 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 --- .../metaweb/gridworks/browsing/Engine.java | 4 +++ .../facets/ScatterplotDrawingRowVisitor.java | 5 ++++ .../browsing/facets/ScatterplotFacet.java | 1 + .../commands/info/GetScatterplotCommand.java | 29 ++++++++++++++----- .../scripts/facets/scatterplot-facet.js | 17 +++++++++-- 5 files changed, 47 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/metaweb/gridworks/browsing/Engine.java b/src/main/java/com/metaweb/gridworks/browsing/Engine.java index 6ce7dbbcd..eb268faa8 100644 --- a/src/main/java/com/metaweb/gridworks/browsing/Engine.java +++ b/src/main/java/com/metaweb/gridworks/browsing/Engine.java @@ -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); } diff --git a/src/main/java/com/metaweb/gridworks/browsing/facets/ScatterplotDrawingRowVisitor.java b/src/main/java/com/metaweb/gridworks/browsing/facets/ScatterplotDrawingRowVisitor.java index 144080c2a..b52fffc84 100644 --- a/src/main/java/com/metaweb/gridworks/browsing/facets/ScatterplotDrawingRowVisitor.java +++ b/src/main/java/com/metaweb/gridworks/browsing/facets/ScatterplotDrawingRowVisitor.java @@ -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); diff --git a/src/main/java/com/metaweb/gridworks/browsing/facets/ScatterplotFacet.java b/src/main/java/com/metaweb/gridworks/browsing/facets/ScatterplotFacet.java index d4d1abe19..8f40356f1 100644 --- a/src/main/java/com/metaweb/gridworks/browsing/facets/ScatterplotFacet.java +++ b/src/main/java/com/metaweb/gridworks/browsing/facets/ScatterplotFacet.java @@ -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"; diff --git a/src/main/java/com/metaweb/gridworks/commands/info/GetScatterplotCommand.java b/src/main/java/com/metaweb/gridworks/commands/info/GetScatterplotCommand.java index c8c7e6e4f..deba75b78 100644 --- a/src/main/java/com/metaweb/gridworks/commands/info/GetScatterplotCommand.java +++ b/src/main/java/com/metaweb/gridworks/commands/info/GetScatterplotCommand.java @@ -83,7 +83,10 @@ public class GetScatterplotCommand extends Command { int rotation = (o.has(ScatterplotFacet.ROTATION)) ? ScatterplotFacet.getRotation(o.getString(ScatterplotFacet.ROTATION)) : ScatterplotFacet.NO_ROTATION; String color_str = (o.has(ScatterplotFacet.COLOR)) ? o.getString(ScatterplotFacet.COLOR) : "000000"; - Color color = new Color(Integer.parseInt(color_str,16)); + 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"; @@ -144,12 +147,24 @@ public class GetScatterplotCommand extends Command { if (index_x != null && index_y != null && index_x.isNumeric() && index_y.isNumeric()) { ScatterplotDrawingRowVisitor drawer = new ScatterplotDrawingRowVisitor( - columnIndex_x, columnIndex_y, min_x, max_x, min_y, max_y, - size, dim_x, dim_y, rotation, dot, color - ); - FilteredRows filteredRows = engine.getAllFilteredRows(false); - filteredRows.accept(project, drawer); - + 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 { ImageIO.write(new BufferedImage(1, 1, BufferedImage.TYPE_4BYTE_ABGR), "png", output); diff --git a/src/main/webapp/scripts/facets/scatterplot-facet.js b/src/main/webapp/scripts/facets/scatterplot-facet.js index 0636508cc..208c9f31d 100644 --- a/src/main/webapp/scripts/facets/scatterplot-facet.js +++ b/src/main/webapp/scripts/facets/scatterplot-facet.js @@ -94,6 +94,7 @@ ScatterplotFacet.prototype._initializeUI = function() { '' + '' + '' + + '
export plot
' + '' + '' + '' + @@ -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() {