From bb1fbcf7e81d4321f3cd70de7124767d0a772841 Mon Sep 17 00:00:00 2001 From: Heng Sin Low Date: Mon, 7 Oct 2013 13:36:21 +0800 Subject: [PATCH] IDEMPIERE-1265 Add Adaxa Sales Management. Improve the sizing of dashboard chart gadget. --- .../webui/desktop/DashboardController.java | 29 ++++++++++++++----- .../adempiere/webui/editor/WChartEditor.java | 11 ++++++- .../adempiere/webui/util/ChartRenderer.java | 16 ++-------- .../theme/default/css/theme.css.dsp | 4 +++ 4 files changed, 39 insertions(+), 21 deletions(-) diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/desktop/DashboardController.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/desktop/DashboardController.java index 76916ea5d7..865d40b108 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/desktop/DashboardController.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/desktop/DashboardController.java @@ -62,6 +62,7 @@ import org.zkoss.zk.ui.Component; import org.zkoss.zk.ui.Desktop; import org.zkoss.zk.ui.Executions; import org.zkoss.zk.ui.Page; +import org.zkoss.zk.ui.event.AfterSizeEvent; import org.zkoss.zk.ui.event.DropEvent; import org.zkoss.zk.ui.event.Event; import org.zkoss.zk.ui.event.EventListener; @@ -371,18 +372,32 @@ public class DashboardController implements EventListener { } //chart - int AD_Chart_ID = dc.getAD_Chart_ID(); + final int AD_Chart_ID = dc.getAD_Chart_ID(); if (AD_Chart_ID > 0) { - Panel chartPanel = new Panel(); - MChart chartModel = new MChart(Env.getCtx(), AD_Chart_ID, null); - ChartRenderer renderer = new ChartRenderer(chartModel); - renderer.render(chartPanel, 300); + final Div chartPanel = new Div(); + chartPanel.setSclass("chart-gadget"); + final MChart chartModel = new MChart(Env.getCtx(), AD_Chart_ID, null); content.appendChild(chartPanel); - panelEmpty = false; + panelEmpty = false; + chartPanel.addEventListener(Events.ON_AFTER_SIZE, new EventListener() { + @Override + public void onEvent(AfterSizeEvent event) throws Exception { + ChartRenderer renderer = new ChartRenderer(chartModel); + int width = event.getWidth()*90/100; + int height = event.getHeight(); + //set normal height + if (height == 0) { + height = width * 85 / 100; + chartPanel.setHeight(height+"px"); + } + chartPanel.getChildren().clear(); + renderer.render(chartPanel, width, height); + } + }); } if (panelEmpty) - panel.detach(); + panel.detach(); } if (dps.length == 0) diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/editor/WChartEditor.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/editor/WChartEditor.java index a46a12f632..f0b2d394e8 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/editor/WChartEditor.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/editor/WChartEditor.java @@ -22,6 +22,7 @@ import org.compiere.util.Env; import org.zkoss.zk.ui.event.Event; import org.zkoss.zk.ui.event.Events; import org.zkoss.zul.Panel; +import org.zkoss.zul.Panelchildren; /** * This class is based on org.compiere.grid.ed.WImageEditor and WGraph written by Low Heng Sin. @@ -50,7 +51,15 @@ public class WChartEditor extends WEditor private void createChart() { ChartRenderer renderer = new ChartRenderer(chartModel); - renderer.render(getComponent(), 400); + Panel panel = getComponent(); + if (panel.getPanelchildren() != null) { + panel.getPanelchildren().getChildren().clear(); + } else { + Panelchildren pc = new Panelchildren(); + panel.appendChild(pc); + pc.setSclass("chart-field"); + } + renderer.render(panel.getPanelchildren(), 400, chartModel.getWinHeight()); } @Override diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/util/ChartRenderer.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/util/ChartRenderer.java index 377d3db3b2..2667830cd8 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/util/ChartRenderer.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/util/ChartRenderer.java @@ -20,14 +20,13 @@ import org.jfree.data.time.TimeSeries; import org.jfree.data.time.TimeSeriesCollection; import org.jfree.data.time.TimeSeriesDataItem; import org.zkoss.image.AImage; +import org.zkoss.zk.ui.Component; import org.zkoss.zk.ui.event.Event; import org.zkoss.zk.ui.event.EventListener; import org.zkoss.zk.ui.event.Events; import org.zkoss.zk.ui.event.MouseEvent; import org.zkoss.zul.Area; import org.zkoss.zul.Imagemap; -import org.zkoss.zul.Panel; -import org.zkoss.zul.Panelchildren; /** * @author Paul Bowden, Adaxa Pty Ltd @@ -52,11 +51,10 @@ public class ChartRenderer { * @param panel * @param width */ - public void render(Panel panel, int width) { + public void render(Component parent, int width, int height) { JFreeChart chart = chartModel.createChart(); ChartRenderingInfo info = new ChartRenderingInfo(); - int height = chartModel.getWinHeight(); BufferedImage bi = chart.createBufferedImage(width, height, BufferedImage.TRANSLUCENT, info); try { @@ -66,15 +64,7 @@ public class ChartRenderer { Imagemap myImage = new Imagemap(); myImage.setContent(image); - if (panel.getPanelchildren() != null) { - panel.getPanelchildren().getChildren().clear(); - panel.getPanelchildren().appendChild(myImage); - } else { - Panelchildren pc = new Panelchildren(); - panel.appendChild(pc); - pc.appendChild(myImage); - pc.setSclass("chart-field"); - } + parent.appendChild(myImage); int count = 0; for (Iterator it = info.getEntityCollection().getEntities() diff --git a/org.adempiere.ui.zk/theme/default/css/theme.css.dsp b/org.adempiere.ui.zk/theme/default/css/theme.css.dsp index d83146a20e..462c65e740 100644 --- a/org.adempiere.ui.zk/theme/default/css/theme.css.dsp +++ b/org.adempiere.ui.zk/theme/default/css/theme.css.dsp @@ -1931,7 +1931,11 @@ table.z-vbox > tbody > tr > td > table { background-color: #ddd; } +<%-- chart --%> .chart-field { padding: 10px; border: 1px solid lightgray !important; } +.dashboard-widget.dashboard-widget-max .chart-gadget { + height: 100% !important; +}