IDEMPIERE-1583 Zk: Pluggable Chart Renderer Service. Fixed sizing of performance indicator chart. Allow partial implementation of chart renderer service - return false to ignore chart that a service can't render.
This commit is contained in:
parent
4eb3ef097c
commit
1068f189ca
|
@ -31,8 +31,9 @@ public interface IChartRendererService {
|
|||
* @param chartWidth
|
||||
* @param chartHeight
|
||||
* @param model
|
||||
* @return true if render successfully
|
||||
*/
|
||||
public void renderPerformanceIndicator(Component parent, int chartWidth, int chartHeight, IndicatorModel model);
|
||||
public boolean renderPerformanceIndicator(Component parent, int chartWidth, int chartHeight, IndicatorModel model);
|
||||
|
||||
/**
|
||||
* render chart for PA_Goal
|
||||
|
@ -40,8 +41,9 @@ public interface IChartRendererService {
|
|||
* @param chartWidth
|
||||
* @param chartHeight
|
||||
* @param goalModel
|
||||
* @return true if render successfully
|
||||
*/
|
||||
public void renderPerformanceGraph(Component parent, int chartWidth, int chartHeight, GoalModel goalModel);
|
||||
public boolean renderPerformanceGraph(Component parent, int chartWidth, int chartHeight, GoalModel goalModel);
|
||||
|
||||
/**
|
||||
* render chart for AD_Chart
|
||||
|
@ -49,6 +51,7 @@ public interface IChartRendererService {
|
|||
* @param width
|
||||
* @param height
|
||||
* @param chartModel
|
||||
* @return true if render successfully
|
||||
*/
|
||||
public void renderChart(Component parent, int width, int height, ChartModel chartModel);
|
||||
public boolean renderChart(Component parent, int width, int height, ChartModel chartModel);
|
||||
}
|
|
@ -17,6 +17,7 @@ import java.awt.Point;
|
|||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.adempiere.apps.graph.GraphColumn;
|
||||
import org.adempiere.base.Service;
|
||||
|
@ -250,7 +251,6 @@ public class WGraph extends Div implements IdSpace {
|
|||
Panelchildren pc = new Panelchildren();
|
||||
panel.appendChild(pc);
|
||||
}
|
||||
IChartRendererService renderer = Service.locator().locate(IChartRendererService.class).getService();
|
||||
GoalModel goalModel = new GoalModel();
|
||||
goalModel.goal = m_goal;
|
||||
goalModel.chartType = type != null ? type : m_goal.getChartType();
|
||||
|
@ -259,7 +259,11 @@ public class WGraph extends Div implements IdSpace {
|
|||
goalModel.xAxisLabel = m_xAxisLabel;
|
||||
goalModel.yAxisLabel = m_yAxisLabel;
|
||||
goalModel.zoomFactor = zoomFactor;
|
||||
renderer.renderPerformanceGraph(panel.getPanelchildren(), width, height, goalModel);
|
||||
List<IChartRendererService> list = Service.locator().list(IChartRendererService.class).getServices();
|
||||
for (IChartRendererService renderer : list) {
|
||||
if (renderer.renderPerformanceGraph(panel.getPanelchildren(), width, height, goalModel))
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -15,6 +15,7 @@ package org.adempiere.webui.apps.graph;
|
|||
|
||||
import java.awt.Color;
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.adempiere.base.Service;
|
||||
|
@ -26,6 +27,7 @@ import org.compiere.util.DisplayType;
|
|||
import org.compiere.util.Env;
|
||||
import org.compiere.util.Msg;
|
||||
import org.jfree.chart.ChartPanel;
|
||||
import org.zkoss.zk.ui.event.AfterSizeEvent;
|
||||
import org.zkoss.zk.ui.event.Event;
|
||||
import org.zkoss.zk.ui.event.EventListener;
|
||||
import org.zkoss.zk.ui.event.Events;
|
||||
|
@ -60,10 +62,6 @@ public class WPerformanceIndicator extends Panel implements EventListener<Event>
|
|||
public WPerformanceIndicator(MGoal goal, Options options)
|
||||
{
|
||||
if (options != null) {
|
||||
if (options.chartHeight > 0)
|
||||
chartHeight = options.chartHeight;
|
||||
if (options.chartWidth > 0)
|
||||
chartWidth = options.chartWidth;
|
||||
if (options.colorMap != null) {
|
||||
Color color = options.colorMap.get(CHART_BACKGROUND);
|
||||
if (color != null)
|
||||
|
@ -104,8 +102,6 @@ public class WPerformanceIndicator extends Panel implements EventListener<Event>
|
|||
private Menuitem mRefresh = new Menuitem(Msg.getMsg(Env.getCtx(), "Refresh"), ThemeManager.getThemeResource("images/Refresh16.png"));
|
||||
|
||||
private Color chartBackground = new Color(0.0f, 0.0f, 0.0f, 0.0f);
|
||||
private int chartWidth = 120;
|
||||
private int chartHeight = 120;
|
||||
private Color dialBackground = Color.white;
|
||||
private Color needleColor = Color.darkGray;
|
||||
private Color tickColor = Color.darkGray;
|
||||
|
@ -126,18 +122,7 @@ public class WPerformanceIndicator extends Panel implements EventListener<Event>
|
|||
* Kinamo (pelgrim)
|
||||
*/
|
||||
private void init()
|
||||
{
|
||||
IChartRendererService renderer = Service.locator().locate(IChartRendererService.class).getService();
|
||||
IndicatorModel model = new IndicatorModel();
|
||||
model.goalModel = m_goal;
|
||||
model.chartBackground = chartBackground;
|
||||
model.dialBackground = dialBackground;
|
||||
model.needleColor = needleColor;
|
||||
model.tickColor = tickColor;
|
||||
renderer.renderPerformanceIndicator(this, chartWidth, chartHeight, model);
|
||||
|
||||
this.getFirstChild().addEventListener(Events.ON_CLICK, this);
|
||||
|
||||
{
|
||||
// Set Text
|
||||
StringBuilder text = new StringBuilder(m_goal.getName());
|
||||
if (m_goal.isTarget())
|
||||
|
@ -157,26 +142,62 @@ public class WPerformanceIndicator extends Panel implements EventListener<Event>
|
|||
.append(s_format.format(m_goal.getMeasureTarget()));
|
||||
setTooltiptext(text.toString());
|
||||
|
||||
invalidate();
|
||||
addEventListener(Events.ON_AFTER_SIZE, this);
|
||||
}
|
||||
|
||||
public void onEvent(Event event) throws Exception
|
||||
{
|
||||
if (event.getTarget() == this.getFirstChild())
|
||||
if (Events.ON_AFTER_SIZE.equals(event.getName()))
|
||||
{
|
||||
onAfterSize((AfterSizeEvent) event);
|
||||
}
|
||||
else if (event.getTarget() == this.getFirstChild())
|
||||
{
|
||||
event.stopPropagation();
|
||||
Events.sendEvent(Events.ON_CLICK, this, event.getData());
|
||||
}
|
||||
}
|
||||
|
||||
private void onAfterSize(AfterSizeEvent event) {
|
||||
int width = event.getWidth();
|
||||
int height = event.getHeight();
|
||||
//set normal height
|
||||
if (height == 0) {
|
||||
height = width > 300 ? width * 40 / 100 : width * 85 / 100;
|
||||
this.setHeight(height+"px");
|
||||
} else {
|
||||
int ratio = (height * 100) / width;
|
||||
if (ratio > 85 || ratio < 50) {
|
||||
height = width > 300 ? width * 40 / 100 : width * 85 / 100;
|
||||
this.setHeight(height+"px");
|
||||
}
|
||||
}
|
||||
this.getChildren().clear();
|
||||
renderChart(width, height);
|
||||
}
|
||||
|
||||
public String getTitle()
|
||||
{
|
||||
return m_text;
|
||||
}
|
||||
|
||||
private void renderChart(int chartWidth, int chartHeight)
|
||||
{
|
||||
IndicatorModel model = new IndicatorModel();
|
||||
model.goalModel = m_goal;
|
||||
model.chartBackground = chartBackground;
|
||||
model.dialBackground = dialBackground;
|
||||
model.needleColor = needleColor;
|
||||
model.tickColor = tickColor;
|
||||
List<IChartRendererService> list = Service.locator().list(IChartRendererService.class).getServices();
|
||||
for (IChartRendererService renderer : list) {
|
||||
if (renderer.renderPerformanceIndicator(this, chartWidth, chartHeight, model))
|
||||
break;
|
||||
}
|
||||
this.getFirstChild().addEventListener(Events.ON_CLICK, this);
|
||||
}
|
||||
|
||||
public static class Options {
|
||||
public Map<String, Color> colorMap;
|
||||
public int chartWidth;
|
||||
public int chartHeight;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,10 +13,7 @@ public class WViewPI extends ADForm {
|
|||
protected void initForm() {
|
||||
this.setSclass("window-view-pi");
|
||||
WPerformanceIndicator.Options options = new WPerformanceIndicator.Options();
|
||||
options.chartHeight = 180;
|
||||
options.chartWidth = 180;
|
||||
WPAPanel paPanel = WPAPanel.get(options);
|
||||
appendChild(paPanel);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -53,7 +53,7 @@ public class ChartRendererServiceImpl implements IChartRendererService {
|
|||
private final static CLogger log = CLogger.getCLogger(ChartRendererServiceImpl.class);
|
||||
|
||||
@Override
|
||||
public void renderPerformanceIndicator(Component parent, int chartWidth, int chartHeight, IndicatorModel model) {
|
||||
public boolean renderPerformanceIndicator(Component parent, int chartWidth, int chartHeight, IndicatorModel model) {
|
||||
PerformanceGraphBuilder builder = new PerformanceGraphBuilder();
|
||||
JFreeChart chart = builder.createIndicatorChart(model);
|
||||
chart.setBackgroundPaint(model.chartBackground);
|
||||
|
@ -70,11 +70,13 @@ public class ChartRendererServiceImpl implements IChartRendererService {
|
|||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderPerformanceGraph(Component parent, int chartWidth, int chartHeight, final GoalModel goalModel) {
|
||||
public boolean renderPerformanceGraph(Component parent, int chartWidth, int chartHeight, final GoalModel goalModel) {
|
||||
GraphBuilder builder = new GraphBuilder();
|
||||
builder.setMGoal(goalModel.goal);
|
||||
builder.setXAxisLabel(goalModel.xAxisLabel);
|
||||
|
@ -151,7 +153,9 @@ public class ChartRendererServiceImpl implements IChartRendererService {
|
|||
});
|
||||
} catch (Exception e) {
|
||||
log.log(Level.SEVERE, "", e);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void chartMouseClicked(MGoal goal, GraphColumn bgc) {
|
||||
|
@ -165,9 +169,10 @@ public class ChartRendererServiceImpl implements IChartRendererService {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void renderChart(Component parent, int width, int height,
|
||||
public boolean renderChart(Component parent, int width, int height,
|
||||
ChartModel chartModel) {
|
||||
ChartRenderer renderer = new ChartRenderer(chartModel.chart);
|
||||
renderer.render(parent, width, height);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -393,8 +393,11 @@ public class DashboardController implements EventListener<Event> {
|
|||
chartPanel.getChildren().clear();
|
||||
ChartModel model = new ChartModel();
|
||||
model.chart = chartModel;
|
||||
IChartRendererService renderer = Service.locator().locate(IChartRendererService.class).getService();
|
||||
renderer.renderChart(chartPanel, width, height, model);
|
||||
List<IChartRendererService> list = Service.locator().list(IChartRendererService.class).getServices();
|
||||
for (IChartRendererService renderer : list) {
|
||||
if (renderer.renderChart(chartPanel, width, height, model))
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -14,6 +14,8 @@
|
|||
package org.adempiere.webui.editor;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.adempiere.base.Service;
|
||||
import org.adempiere.webui.apps.graph.IChartRendererService;
|
||||
import org.adempiere.webui.apps.graph.model.ChartModel;
|
||||
|
@ -62,8 +64,11 @@ public class WChartEditor extends WEditor
|
|||
}
|
||||
ChartModel model = new ChartModel();
|
||||
model.chart = chartModel;
|
||||
IChartRendererService renderer = Service.locator().locate(IChartRendererService.class).getService();
|
||||
renderer.renderChart(panel.getPanelchildren(), 400, chartModel.getWinHeight(), model);
|
||||
List<IChartRendererService> list = Service.locator().list(IChartRendererService.class).getServices();
|
||||
for (IChartRendererService renderer : list) {
|
||||
if (renderer.renderChart(panel.getPanelchildren(), 400, chartModel.getWinHeight(), model))
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1663,14 +1663,11 @@ table.z-vbox > tbody > tr > td > table {
|
|||
}
|
||||
|
||||
.performance-indicator img {
|
||||
height: 120px;
|
||||
width: 120px;
|
||||
display: block;
|
||||
margin: auto;
|
||||
}
|
||||
|
||||
.window-view-pi .performance-indicator img {
|
||||
width: 180px !important;
|
||||
}
|
||||
|
||||
.performance-indicator-box {
|
||||
|
|
Loading…
Reference in New Issue