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 chartWidth
|
||||||
* @param chartHeight
|
* @param chartHeight
|
||||||
* @param model
|
* @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
|
* render chart for PA_Goal
|
||||||
|
|
@ -40,8 +41,9 @@ public interface IChartRendererService {
|
||||||
* @param chartWidth
|
* @param chartWidth
|
||||||
* @param chartHeight
|
* @param chartHeight
|
||||||
* @param goalModel
|
* @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
|
* render chart for AD_Chart
|
||||||
|
|
@ -49,6 +51,7 @@ public interface IChartRendererService {
|
||||||
* @param width
|
* @param width
|
||||||
* @param height
|
* @param height
|
||||||
* @param chartModel
|
* @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.math.BigDecimal;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.adempiere.apps.graph.GraphColumn;
|
import org.adempiere.apps.graph.GraphColumn;
|
||||||
import org.adempiere.base.Service;
|
import org.adempiere.base.Service;
|
||||||
|
|
@ -250,7 +251,6 @@ public class WGraph extends Div implements IdSpace {
|
||||||
Panelchildren pc = new Panelchildren();
|
Panelchildren pc = new Panelchildren();
|
||||||
panel.appendChild(pc);
|
panel.appendChild(pc);
|
||||||
}
|
}
|
||||||
IChartRendererService renderer = Service.locator().locate(IChartRendererService.class).getService();
|
|
||||||
GoalModel goalModel = new GoalModel();
|
GoalModel goalModel = new GoalModel();
|
||||||
goalModel.goal = m_goal;
|
goalModel.goal = m_goal;
|
||||||
goalModel.chartType = type != null ? type : m_goal.getChartType();
|
goalModel.chartType = type != null ? type : m_goal.getChartType();
|
||||||
|
|
@ -259,7 +259,11 @@ public class WGraph extends Div implements IdSpace {
|
||||||
goalModel.xAxisLabel = m_xAxisLabel;
|
goalModel.xAxisLabel = m_xAxisLabel;
|
||||||
goalModel.yAxisLabel = m_yAxisLabel;
|
goalModel.yAxisLabel = m_yAxisLabel;
|
||||||
goalModel.zoomFactor = zoomFactor;
|
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.awt.Color;
|
||||||
import java.text.DecimalFormat;
|
import java.text.DecimalFormat;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.adempiere.base.Service;
|
import org.adempiere.base.Service;
|
||||||
|
|
@ -26,6 +27,7 @@ import org.compiere.util.DisplayType;
|
||||||
import org.compiere.util.Env;
|
import org.compiere.util.Env;
|
||||||
import org.compiere.util.Msg;
|
import org.compiere.util.Msg;
|
||||||
import org.jfree.chart.ChartPanel;
|
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.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;
|
||||||
|
|
@ -60,10 +62,6 @@ public class WPerformanceIndicator extends Panel implements EventListener<Event>
|
||||||
public WPerformanceIndicator(MGoal goal, Options options)
|
public WPerformanceIndicator(MGoal goal, Options options)
|
||||||
{
|
{
|
||||||
if (options != null) {
|
if (options != null) {
|
||||||
if (options.chartHeight > 0)
|
|
||||||
chartHeight = options.chartHeight;
|
|
||||||
if (options.chartWidth > 0)
|
|
||||||
chartWidth = options.chartWidth;
|
|
||||||
if (options.colorMap != null) {
|
if (options.colorMap != null) {
|
||||||
Color color = options.colorMap.get(CHART_BACKGROUND);
|
Color color = options.colorMap.get(CHART_BACKGROUND);
|
||||||
if (color != null)
|
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 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 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 dialBackground = Color.white;
|
||||||
private Color needleColor = Color.darkGray;
|
private Color needleColor = Color.darkGray;
|
||||||
private Color tickColor = Color.darkGray;
|
private Color tickColor = Color.darkGray;
|
||||||
|
|
@ -127,17 +123,6 @@ public class WPerformanceIndicator extends Panel implements EventListener<Event>
|
||||||
*/
|
*/
|
||||||
private void init()
|
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
|
// Set Text
|
||||||
StringBuilder text = new StringBuilder(m_goal.getName());
|
StringBuilder text = new StringBuilder(m_goal.getName());
|
||||||
if (m_goal.isTarget())
|
if (m_goal.isTarget())
|
||||||
|
|
@ -157,26 +142,62 @@ public class WPerformanceIndicator extends Panel implements EventListener<Event>
|
||||||
.append(s_format.format(m_goal.getMeasureTarget()));
|
.append(s_format.format(m_goal.getMeasureTarget()));
|
||||||
setTooltiptext(text.toString());
|
setTooltiptext(text.toString());
|
||||||
|
|
||||||
invalidate();
|
addEventListener(Events.ON_AFTER_SIZE, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onEvent(Event event) throws Exception
|
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();
|
event.stopPropagation();
|
||||||
Events.sendEvent(Events.ON_CLICK, this, event.getData());
|
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()
|
public String getTitle()
|
||||||
{
|
{
|
||||||
return m_text;
|
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 static class Options {
|
||||||
public Map<String, Color> colorMap;
|
public Map<String, Color> colorMap;
|
||||||
public int chartWidth;
|
|
||||||
public int chartHeight;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,10 +13,7 @@ public class WViewPI extends ADForm {
|
||||||
protected void initForm() {
|
protected void initForm() {
|
||||||
this.setSclass("window-view-pi");
|
this.setSclass("window-view-pi");
|
||||||
WPerformanceIndicator.Options options = new WPerformanceIndicator.Options();
|
WPerformanceIndicator.Options options = new WPerformanceIndicator.Options();
|
||||||
options.chartHeight = 180;
|
|
||||||
options.chartWidth = 180;
|
|
||||||
WPAPanel paPanel = WPAPanel.get(options);
|
WPAPanel paPanel = WPAPanel.get(options);
|
||||||
appendChild(paPanel);
|
appendChild(paPanel);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,7 @@ public class ChartRendererServiceImpl implements IChartRendererService {
|
||||||
private final static CLogger log = CLogger.getCLogger(ChartRendererServiceImpl.class);
|
private final static CLogger log = CLogger.getCLogger(ChartRendererServiceImpl.class);
|
||||||
|
|
||||||
@Override
|
@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();
|
PerformanceGraphBuilder builder = new PerformanceGraphBuilder();
|
||||||
JFreeChart chart = builder.createIndicatorChart(model);
|
JFreeChart chart = builder.createIndicatorChart(model);
|
||||||
chart.setBackgroundPaint(model.chartBackground);
|
chart.setBackgroundPaint(model.chartBackground);
|
||||||
|
|
@ -70,11 +70,13 @@ public class ChartRendererServiceImpl implements IChartRendererService {
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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();
|
GraphBuilder builder = new GraphBuilder();
|
||||||
builder.setMGoal(goalModel.goal);
|
builder.setMGoal(goalModel.goal);
|
||||||
builder.setXAxisLabel(goalModel.xAxisLabel);
|
builder.setXAxisLabel(goalModel.xAxisLabel);
|
||||||
|
|
@ -151,7 +153,9 @@ public class ChartRendererServiceImpl implements IChartRendererService {
|
||||||
});
|
});
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.log(Level.SEVERE, "", e);
|
log.log(Level.SEVERE, "", e);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void chartMouseClicked(MGoal goal, GraphColumn bgc) {
|
private void chartMouseClicked(MGoal goal, GraphColumn bgc) {
|
||||||
|
|
@ -165,9 +169,10 @@ public class ChartRendererServiceImpl implements IChartRendererService {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void renderChart(Component parent, int width, int height,
|
public boolean renderChart(Component parent, int width, int height,
|
||||||
ChartModel chartModel) {
|
ChartModel chartModel) {
|
||||||
ChartRenderer renderer = new ChartRenderer(chartModel.chart);
|
ChartRenderer renderer = new ChartRenderer(chartModel.chart);
|
||||||
renderer.render(parent, width, height);
|
renderer.render(parent, width, height);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -393,8 +393,11 @@ public class DashboardController implements EventListener<Event> {
|
||||||
chartPanel.getChildren().clear();
|
chartPanel.getChildren().clear();
|
||||||
ChartModel model = new ChartModel();
|
ChartModel model = new ChartModel();
|
||||||
model.chart = chartModel;
|
model.chart = chartModel;
|
||||||
IChartRendererService renderer = Service.locator().locate(IChartRendererService.class).getService();
|
List<IChartRendererService> list = Service.locator().list(IChartRendererService.class).getServices();
|
||||||
renderer.renderChart(chartPanel, width, height, model);
|
for (IChartRendererService renderer : list) {
|
||||||
|
if (renderer.renderChart(chartPanel, width, height, model))
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,8 @@
|
||||||
package org.adempiere.webui.editor;
|
package org.adempiere.webui.editor;
|
||||||
|
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.adempiere.base.Service;
|
import org.adempiere.base.Service;
|
||||||
import org.adempiere.webui.apps.graph.IChartRendererService;
|
import org.adempiere.webui.apps.graph.IChartRendererService;
|
||||||
import org.adempiere.webui.apps.graph.model.ChartModel;
|
import org.adempiere.webui.apps.graph.model.ChartModel;
|
||||||
|
|
@ -62,8 +64,11 @@ public class WChartEditor extends WEditor
|
||||||
}
|
}
|
||||||
ChartModel model = new ChartModel();
|
ChartModel model = new ChartModel();
|
||||||
model.chart = chartModel;
|
model.chart = chartModel;
|
||||||
IChartRendererService renderer = Service.locator().locate(IChartRendererService.class).getService();
|
List<IChartRendererService> list = Service.locator().list(IChartRendererService.class).getServices();
|
||||||
renderer.renderChart(panel.getPanelchildren(), 400, chartModel.getWinHeight(), model);
|
for (IChartRendererService renderer : list) {
|
||||||
|
if (renderer.renderChart(panel.getPanelchildren(), 400, chartModel.getWinHeight(), model))
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -1663,14 +1663,11 @@ table.z-vbox > tbody > tr > td > table {
|
||||||
}
|
}
|
||||||
|
|
||||||
.performance-indicator img {
|
.performance-indicator img {
|
||||||
height: 120px;
|
|
||||||
width: 120px;
|
|
||||||
display: block;
|
display: block;
|
||||||
margin: auto;
|
margin: auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
.window-view-pi .performance-indicator img {
|
.window-view-pi .performance-indicator img {
|
||||||
width: 180px !important;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.performance-indicator-box {
|
.performance-indicator-box {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue