IDEMPIERE-1265 Add Adaxa Sales Management. Improve the sizing of dashboard chart gadget.

This commit is contained in:
Heng Sin Low 2013-10-07 13:36:21 +08:00
parent 8a31f38f1a
commit bb1fbcf7e8
4 changed files with 39 additions and 21 deletions

View File

@ -62,6 +62,7 @@ import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.Desktop; import org.zkoss.zk.ui.Desktop;
import org.zkoss.zk.ui.Executions; import org.zkoss.zk.ui.Executions;
import org.zkoss.zk.ui.Page; 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.DropEvent;
import org.zkoss.zk.ui.event.Event; import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.event.EventListener; import org.zkoss.zk.ui.event.EventListener;
@ -371,14 +372,28 @@ public class DashboardController implements EventListener<Event> {
} }
//chart //chart
int AD_Chart_ID = dc.getAD_Chart_ID(); final int AD_Chart_ID = dc.getAD_Chart_ID();
if (AD_Chart_ID > 0) { if (AD_Chart_ID > 0) {
Panel chartPanel = new Panel(); final Div chartPanel = new Div();
MChart chartModel = new MChart(Env.getCtx(), AD_Chart_ID, null); chartPanel.setSclass("chart-gadget");
ChartRenderer renderer = new ChartRenderer(chartModel); final MChart chartModel = new MChart(Env.getCtx(), AD_Chart_ID, null);
renderer.render(chartPanel, 300);
content.appendChild(chartPanel); content.appendChild(chartPanel);
panelEmpty = false; panelEmpty = false;
chartPanel.addEventListener(Events.ON_AFTER_SIZE, new EventListener<AfterSizeEvent>() {
@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) if (panelEmpty)

View File

@ -22,6 +22,7 @@ import org.compiere.util.Env;
import org.zkoss.zk.ui.event.Event; import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.event.Events; import org.zkoss.zk.ui.event.Events;
import org.zkoss.zul.Panel; 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. * 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() { private void createChart() {
ChartRenderer renderer = new ChartRenderer(chartModel); 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 @Override

View File

@ -20,14 +20,13 @@ import org.jfree.data.time.TimeSeries;
import org.jfree.data.time.TimeSeriesCollection; import org.jfree.data.time.TimeSeriesCollection;
import org.jfree.data.time.TimeSeriesDataItem; import org.jfree.data.time.TimeSeriesDataItem;
import org.zkoss.image.AImage; import org.zkoss.image.AImage;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.event.Event; import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.event.EventListener; import org.zkoss.zk.ui.event.EventListener;
import org.zkoss.zk.ui.event.Events; import org.zkoss.zk.ui.event.Events;
import org.zkoss.zk.ui.event.MouseEvent; import org.zkoss.zk.ui.event.MouseEvent;
import org.zkoss.zul.Area; import org.zkoss.zul.Area;
import org.zkoss.zul.Imagemap; import org.zkoss.zul.Imagemap;
import org.zkoss.zul.Panel;
import org.zkoss.zul.Panelchildren;
/** /**
* @author Paul Bowden, Adaxa Pty Ltd * @author Paul Bowden, Adaxa Pty Ltd
@ -52,11 +51,10 @@ public class ChartRenderer {
* @param panel * @param panel
* @param width * @param width
*/ */
public void render(Panel panel, int width) { public void render(Component parent, int width, int height) {
JFreeChart chart = chartModel.createChart(); JFreeChart chart = chartModel.createChart();
ChartRenderingInfo info = new ChartRenderingInfo(); ChartRenderingInfo info = new ChartRenderingInfo();
int height = chartModel.getWinHeight();
BufferedImage bi = chart.createBufferedImage(width, height, BufferedImage bi = chart.createBufferedImage(width, height,
BufferedImage.TRANSLUCENT, info); BufferedImage.TRANSLUCENT, info);
try { try {
@ -66,15 +64,7 @@ public class ChartRenderer {
Imagemap myImage = new Imagemap(); Imagemap myImage = new Imagemap();
myImage.setContent(image); myImage.setContent(image);
if (panel.getPanelchildren() != null) { parent.appendChild(myImage);
panel.getPanelchildren().getChildren().clear();
panel.getPanelchildren().appendChild(myImage);
} else {
Panelchildren pc = new Panelchildren();
panel.appendChild(pc);
pc.appendChild(myImage);
pc.setSclass("chart-field");
}
int count = 0; int count = 0;
for (Iterator<?> it = info.getEntityCollection().getEntities() for (Iterator<?> it = info.getEntityCollection().getEntities()

View File

@ -1931,7 +1931,11 @@ table.z-vbox > tbody > tr > td > table {
background-color: #ddd; background-color: #ddd;
} }
<%-- chart --%>
.chart-field { .chart-field {
padding: 10px; padding: 10px;
border: 1px solid lightgray !important; border: 1px solid lightgray !important;
} }
.dashboard-widget.dashboard-widget-max .chart-gadget {
height: 100% !important;
}