Mercurial > dive4elements > river
diff flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/OverviewOutputTab.java @ 2977:5161e25392ea
Added chart overview to sq relation in minfo module.
flys-client/trunk@4974 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Raimund Renkert <raimund.renkert@intevation.de> |
---|---|
date | Fri, 13 Jul 2012 08:54:57 +0000 |
parents | |
children | d2a54ae0016b |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/OverviewOutputTab.java Fri Jul 13 08:54:57 2012 +0000 @@ -0,0 +1,200 @@ +package de.intevation.flys.client.client.ui.chart; + +import java.util.Date; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; + +import com.google.gwt.core.client.GWT; + +import com.smartgwt.client.widgets.Canvas; +import com.smartgwt.client.widgets.Img; +import com.smartgwt.client.widgets.events.ResizedEvent; +import com.smartgwt.client.widgets.events.ResizedHandler; +import com.smartgwt.client.widgets.layout.HLayout; +import com.smartgwt.client.widgets.layout.VLayout; + +import de.intevation.flys.client.client.Config; +import de.intevation.flys.client.client.ui.CollectionView; +import de.intevation.flys.client.client.ui.OutputTab; + +import de.intevation.flys.client.shared.model.Collection; +import de.intevation.flys.client.shared.model.OutputMode; + + +/** + * An overview output tab. This tab displays an overview of all charts + * integrated in the current calculation mode. + * + * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> + */ +public class OverviewOutputTab +extends OutputTab +implements ResizedHandler +{ + /** The collection view.*/ + protected CollectionView view; + + /** The root layout. */ + protected HLayout root; + + /** The columns */ + protected VLayout[] columns; + + /** The chart container.*/ + protected Canvas[][] charts; + + /** All relevant output modes. */ + protected Map<String, OutputMode> relModes; + + + public OverviewOutputTab( + String title, + Collection collection, + OutputMode mode, + CollectionView collectionView) + { + super(title, collection, collectionView, mode); + + relModes = new HashMap<String, OutputMode>(); + + Map<String, OutputMode> modes = collection.getOutputModes(); + Set<String> keys = modes.keySet(); + + // Get all relevant outputs. + for (String key: keys) { + OutputMode m = modes.get(key); + if (m.getType().equals("chart")) { + relModes.put(key, m); + } + } + + root = new HLayout(); + setPane(root); + root.addResizedHandler(this); + + // Get the column and row count and initialize the grid. + int width = getColumnCount(relModes.size()); + int height = getRowCount(relModes.size()); + charts = new Canvas[width][height]; + columns = new VLayout[width]; + + for (int i = 0; i < width; i++) { + columns[i] = new VLayout(); + root.addMember(columns[i]); + + for (int j = 0; j < height; j++) { + charts[i][j] = new Canvas(); + + // This is for 3, 6 or 9 charts only! + // TODO: Calculate the height. + charts[i][j].setHeight("30%"); + + String type = + ((OutputMode)relModes.values() + .toArray()[j + i * height]).getName(); + columns[i].addMember(charts[i][j]); + charts[i][j].addChild( + new Img(getImgUrl( + charts[i][j].getWidth(), + charts[i][j].getHeight(), type))); + + } + } + } + + + /** + * Resize handler. + * + * @param event The resize event. + */ + @Override + public void onResized(ResizedEvent event) { + for (int i = 0; i < charts.length; i++) { + columns[i].setWidth(root.getWidth()/2); + for (int j = 0; j < charts[i].length; j++) { + String type = + ((OutputMode)relModes.values() + .toArray()[j + i * charts[i].length]).getName(); + Canvas[] children = charts[i][j].getChildren(); + for (int k = 0; k < children.length; k++) { + charts[i][j].removeChild(children[k]); + } + charts[i][j].addChild(new Img( + getImgUrl( + charts[i][j].getWidth(), + charts[i][j].getHeight(), + type), + charts[i][j].getWidth(), + charts[i][j].getHeight() + )); + } + } + } + + + /** + * Returns the column count for the grid. + * + * @param count all fields + * @return the column count + */ + protected int getColumnCount(int count) { + if (count <= 3) { + return 1; + } + else if (count > 3 && count < 9) { + return 2; + } + else { + return 3; + } + } + + + /** + * Returns the row count for the grid. + * + * @param count all fields + * @return the row count + */ + protected int getRowCount(int count) { + if(count <= 3) { + return count; + } + else if(count > 3 && count < 9) { + return ((count + (count % 2))/getColumnCount(count)); + } + else { + return (count + (3 - (count % 3))/getColumnCount(count)); + } + } + + + /** + * Builds the URL that points to the chart image. + * + * @param width The width of the requested chart. + * @param height The height of the requested chart. + * @param xr Optional x range (used for zooming). + * @param yr Optional y range (used for zooming). + * + * @return the URL to the chart image. + */ + protected String getImgUrl(int width, int height, String type) { + Config config = Config.getInstance(); + + String imgUrl = GWT.getModuleBaseURL(); + imgUrl += "chart"; + imgUrl += "?uuid=" + collection.identifier(); + imgUrl += "&type=" + type; + imgUrl += "&locale=" + config.getLocale(); + imgUrl += "×tamp=" + new Date().getTime(); + imgUrl += "&width=" + Integer.toString(width); + imgUrl += "&height=" + Integer.toString(height); + + return imgUrl; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :