use of org.jfree.chart.renderer.category.LineAndShapeRenderer in project pentaho-kettle by pentaho.
the class StepPerformanceSnapShotDialog method updateCanvas.
private void updateCanvas() {
Rectangle bounds = canvas.getBounds();
if (bounds.width <= 0 || bounds.height <= 0) {
return;
}
// The list of snapshots : convert to JFreeChart dataset
//
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
String[] selectedSteps = stepsList.getSelection();
if (selectedSteps == null || selectedSteps.length == 0) {
// first step
selectedSteps = new String[] { steps[0] };
stepsList.select(0);
}
int[] dataIndices = dataList.getSelectionIndices();
if (dataIndices == null || dataIndices.length == 0) {
dataIndices = new int[] { DATA_CHOICE_WRITTEN };
dataList.select(0);
}
boolean multiStep = stepsList.getSelectionCount() > 1;
boolean multiData = dataList.getSelectionCount() > 1;
// A single metric shown for a single step
boolean calcMoving = !multiStep && !multiData;
List<Double> movingList = new ArrayList<Double>();
int movingSize = 10;
double movingTotal = 0;
int totalTimeInSeconds = 0;
for (int t = 0; t < selectedSteps.length; t++) {
String stepNameCopy = selectedSteps[t];
List<StepPerformanceSnapShot> snapShotList = stepPerformanceSnapShots.get(stepNameCopy);
if (snapShotList != null && snapShotList.size() > 1) {
totalTimeInSeconds = (int) Math.round(((double) (snapShotList.get(snapShotList.size() - 1).getDate().getTime() - snapShotList.get(0).getDate().getTime())) / 1000);
for (int i = 0; i < snapShotList.size(); i++) {
StepPerformanceSnapShot snapShot = snapShotList.get(i);
if (snapShot.getTimeDifference() != 0) {
double factor = (double) 1000 / (double) snapShot.getTimeDifference();
for (int d = 0; d < dataIndices.length; d++) {
String dataType;
if (multiStep) {
dataType = stepNameCopy;
} else {
dataType = dataChoices[dataIndices[d]];
}
String xLabel = Integer.toString(Math.round(i * timeDifference / 1000));
Double metric = null;
switch(dataIndices[d]) {
case DATA_CHOICE_INPUT:
metric = snapShot.getLinesInput() * factor;
break;
case DATA_CHOICE_OUTPUT:
metric = snapShot.getLinesOutput() * factor;
break;
case DATA_CHOICE_READ:
metric = snapShot.getLinesRead() * factor;
break;
case DATA_CHOICE_WRITTEN:
metric = snapShot.getLinesWritten() * factor;
break;
case DATA_CHOICE_UPDATED:
metric = snapShot.getLinesUpdated() * factor;
break;
case DATA_CHOICE_REJECTED:
metric = snapShot.getLinesRejected() * factor;
break;
case DATA_CHOICE_INPUT_BUFFER_SIZE:
metric = (double) snapShot.getInputBufferSize();
break;
case DATA_CHOICE_OUTPUT_BUFFER_SIZE:
metric = (double) snapShot.getOutputBufferSize();
break;
default:
break;
}
if (metric != null) {
dataset.addValue(metric, dataType, xLabel);
if (calcMoving) {
movingTotal += metric;
movingList.add(metric);
if (movingList.size() > movingSize) {
movingTotal -= movingList.get(0);
movingList.remove(0);
}
double movingAverage = movingTotal / movingList.size();
dataset.addValue(movingAverage, dataType + "(Avg)", xLabel);
// System.out.println("moving average = "+movingAverage+", movingTotal="+movingTotal+", m");
}
}
}
}
}
}
}
String chartTitle = title;
if (multiStep) {
chartTitle += " (" + dataChoices[dataIndices[0]] + ")";
} else {
chartTitle += " (" + selectedSteps[0] + ")";
}
final JFreeChart chart = // chart title
ChartFactory.createLineChart(// chart title
chartTitle, BaseMessages.getString(PKG, "StepPerformanceSnapShotDialog.TimeInSeconds.Label", Integer.toString(totalTimeInSeconds), // domain axis label
Long.toString(timeDifference)), // range axis label
BaseMessages.getString(PKG, "StepPerformanceSnapShotDialog.RowsPerSecond.Label"), // data
dataset, // orientation
PlotOrientation.VERTICAL, // include legend
true, // tooltips
true, // urls
false);
chart.setBackgroundPaint(Color.white);
CategoryPlot plot = (CategoryPlot) chart.getPlot();
plot.setBackgroundPaint(Color.white);
plot.setForegroundAlpha(0.5f);
plot.setRangeGridlinesVisible(true);
NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
CategoryAxis domainAxis = plot.getDomainAxis();
domainAxis.setTickLabelsVisible(false);
// Customize the renderer...
//
LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer();
renderer.setBaseShapesVisible(true);
renderer.setDrawOutlines(true);
renderer.setUseFillPaint(true);
renderer.setBaseFillPaint(Color.white);
renderer.setSeriesStroke(0, new BasicStroke(1.5f));
renderer.setSeriesOutlineStroke(0, new BasicStroke(1.5f));
renderer.setSeriesStroke(1, new BasicStroke(2.5f));
renderer.setSeriesOutlineStroke(1, new BasicStroke(2.5f));
renderer.setSeriesShape(0, new Ellipse2D.Double(-3.0, -3.0, 6.0, 6.0));
BufferedImage bufferedImage = chart.createBufferedImage(bounds.width, bounds.height);
ImageData imageData = ImageUtil.convertToSWT(bufferedImage);
//
if (image != null) {
image.dispose();
}
image = new Image(display, imageData);
// Draw the image on the canvas...
//
canvas.redraw();
}
use of org.jfree.chart.renderer.category.LineAndShapeRenderer in project qpid-broker-j by apache.
the class CategoryStrokeAndPaintApplier method setSeriesShape.
@Override
public void setSeriesShape(final int seriesIndex, final java.awt.Shape shape, final JFreeChart targetChart) {
CategoryItemRenderer renderer = targetChart.getCategoryPlot().getRenderer();
if (renderer instanceof LineAndShapeRenderer) {
LineAndShapeRenderer lineAndShapeRenderer = (LineAndShapeRenderer) renderer;
lineAndShapeRenderer.setSeriesShapesVisible(seriesIndex, true);
lineAndShapeRenderer.setSeriesShape(seriesIndex, shape);
}
}
use of org.jfree.chart.renderer.category.LineAndShapeRenderer in project pentaho-kettle by pentaho.
the class TransPerfDelegate method updateCanvas.
private void updateCanvas() {
Rectangle bounds = canvas.getBounds();
if (bounds.width <= 0 || bounds.height <= 0) {
return;
}
// The list of snapshots : convert to JFreeChart dataset
//
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
String[] selectedSteps = stepsList.getSelection();
if (selectedSteps == null || selectedSteps.length == 0) {
// first step
selectedSteps = new String[] { steps[0] };
stepsList.select(0);
}
int[] dataIndices = dataList.getSelectionIndices();
if (dataIndices == null || dataIndices.length == 0) {
dataIndices = new int[] { DATA_CHOICE_WRITTEN };
dataList.select(0);
}
boolean multiStep = stepsList.getSelectionCount() > 1;
boolean multiData = dataList.getSelectionCount() > 1;
// A single metric shown for a single step
boolean calcMoving = !multiStep && !multiData;
List<Double> movingList = new ArrayList<Double>();
int movingSize = 10;
double movingTotal = 0;
int totalTimeInSeconds = 0;
for (int t = 0; t < selectedSteps.length; t++) {
String stepNameCopy = selectedSteps[t];
List<StepPerformanceSnapShot> snapShotList = stepPerformanceSnapShots.get(stepNameCopy);
if (snapShotList != null && snapShotList.size() > 1) {
totalTimeInSeconds = (int) Math.round(((double) (snapShotList.get(snapShotList.size() - 1).getDate().getTime() - snapShotList.get(0).getDate().getTime())) / 1000);
for (int i = 0; i < snapShotList.size(); i++) {
StepPerformanceSnapShot snapShot = snapShotList.get(i);
if (snapShot.getTimeDifference() != 0) {
double factor = (double) 1000 / (double) snapShot.getTimeDifference();
for (int d = 0; d < dataIndices.length; d++) {
String dataType;
if (multiStep) {
dataType = stepNameCopy;
} else {
dataType = dataChoices[dataIndices[d]];
}
String xLabel = Integer.toString(Math.round(i * timeDifference / 1000));
Double metric = null;
switch(dataIndices[d]) {
case DATA_CHOICE_INPUT:
metric = snapShot.getLinesInput() * factor;
break;
case DATA_CHOICE_OUTPUT:
metric = snapShot.getLinesOutput() * factor;
break;
case DATA_CHOICE_READ:
metric = snapShot.getLinesRead() * factor;
break;
case DATA_CHOICE_WRITTEN:
metric = snapShot.getLinesWritten() * factor;
break;
case DATA_CHOICE_UPDATED:
metric = snapShot.getLinesUpdated() * factor;
break;
case DATA_CHOICE_REJECTED:
metric = snapShot.getLinesRejected() * factor;
break;
case DATA_CHOICE_INPUT_BUFFER_SIZE:
metric = (double) snapShot.getInputBufferSize();
break;
case DATA_CHOICE_OUTPUT_BUFFER_SIZE:
metric = (double) snapShot.getOutputBufferSize();
break;
default:
break;
}
if (metric != null) {
dataset.addValue(metric, dataType, xLabel);
if (calcMoving) {
movingTotal += metric;
movingList.add(metric);
if (movingList.size() > movingSize) {
movingTotal -= movingList.get(0);
movingList.remove(0);
}
double movingAverage = movingTotal / movingList.size();
dataset.addValue(movingAverage, dataType + "(Avg)", xLabel);
// System.out.println("moving average = "+movingAverage+", movingTotal="+movingTotal+", m");
}
}
}
}
}
}
}
String chartTitle = title;
if (multiStep) {
chartTitle += " (" + dataChoices[dataIndices[0]] + ")";
} else {
chartTitle += " (" + selectedSteps[0] + ")";
}
final JFreeChart chart = // chart title
ChartFactory.createLineChart(// chart title
chartTitle, BaseMessages.getString(PKG, "StepPerformanceSnapShotDialog.TimeInSeconds.Label", Integer.toString(totalTimeInSeconds), // domain axis label
Long.toString(timeDifference)), // range axis label
BaseMessages.getString(PKG, "StepPerformanceSnapShotDialog.RowsPerSecond.Label"), // data
dataset, // orientation
PlotOrientation.VERTICAL, // include legend
true, // tooltips
true, // urls
false);
chart.setBackgroundPaint(Color.white);
TextTitle title = new TextTitle(chartTitle);
// title.setExpandToFitSpace(true);
// org.eclipse.swt.graphics.Color pentahoColor = GUIResource.getInstance().getColorPentaho();
// java.awt.Color color = new java.awt.Color(pentahoColor.getRed(), pentahoColor.getGreen(),pentahoColor.getBlue());
// title.setBackgroundPaint(color);
title.setFont(new java.awt.Font("SansSerif", java.awt.Font.BOLD, 12));
chart.setTitle(title);
CategoryPlot plot = (CategoryPlot) chart.getPlot();
plot.setBackgroundPaint(Color.white);
plot.setForegroundAlpha(0.5f);
plot.setRangeGridlinesVisible(true);
NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
CategoryAxis domainAxis = plot.getDomainAxis();
domainAxis.setTickLabelsVisible(false);
// Customize the renderer...
//
LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer();
renderer.setBaseShapesVisible(true);
renderer.setDrawOutlines(true);
renderer.setUseFillPaint(true);
renderer.setBaseFillPaint(Color.white);
renderer.setSeriesStroke(0, new BasicStroke(1.5f));
renderer.setSeriesOutlineStroke(0, new BasicStroke(1.5f));
renderer.setSeriesStroke(1, new BasicStroke(2.5f));
renderer.setSeriesOutlineStroke(1, new BasicStroke(2.5f));
renderer.setSeriesShape(0, new Ellipse2D.Double(-3.0, -3.0, 6.0, 6.0));
BufferedImage bufferedImage = chart.createBufferedImage(bounds.width, bounds.height);
ImageData imageData = ImageUtil.convertToSWT(bufferedImage);
//
if (image != null) {
image.dispose();
}
image = new Image(transGraph.getDisplay(), imageData);
// Draw the image on the canvas...
//
canvas.redraw();
}
use of org.jfree.chart.renderer.category.LineAndShapeRenderer in project pentaho-platform by pentaho.
the class JFreeChartEngine method createLineChart.
private static JFreeChart createLineChart(final CategoryDatasetChartDefinition chartDefinition) {
// TODO Make the following accessible from the chartDefinition
String categoryAxisLabel = null;
String valueAxisLabel = null;
boolean tooltips = true;
boolean urls = true;
// -----------------------------------------------------------
String title = chartDefinition.getTitle();
boolean legend = chartDefinition.isLegendIncluded();
CategoryAxis categoryAxis = new CategoryAxis(categoryAxisLabel);
ValueAxis valueAxis = new NumberAxis(valueAxisLabel);
LineAndShapeRenderer renderer = chartDefinition.isThreeD() ? new LineRenderer3D() : new LineAndShapeRenderer(true, false);
if (tooltips) {
renderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());
}
if (urls) {
renderer.setBaseItemURLGenerator(new StandardCategoryURLGenerator());
}
renderer.setStroke(JFreeChartEngine.getLineStyleStroke(chartDefinition.getLineStyle(), chartDefinition.getLineWidth()));
renderer.setShapesVisible(chartDefinition.isMarkersVisible());
renderer.setBaseShapesFilled(chartDefinition.isMarkersVisible());
CategoryPlot plot = new CategoryPlot(chartDefinition, categoryAxis, valueAxis, renderer);
JFreeChartEngine.updatePlot(plot, chartDefinition);
JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
return chart;
}
use of org.jfree.chart.renderer.category.LineAndShapeRenderer in project cytoscape-impl by cytoscape.
the class LineLayer method createChart.
@Override
protected JFreeChart createChart(final CategoryDataset dataset) {
final JFreeChart chart = ChartFactory.createLineChart(// chart title
null, // domain axis label
null, // range axis label
null, // data
dataset, PlotOrientation.VERTICAL, // include legend
false, // tooltips
false, // urls
false);
chart.setAntiAlias(true);
chart.setBorderVisible(false);
chart.setBackgroundPaint(TRANSPARENT_COLOR);
chart.setBackgroundImageAlpha(0.0f);
chart.setPadding(new RectangleInsets(0.0, 0.0, 0.0, 0.0));
final CategoryPlot plot = (CategoryPlot) chart.getPlot();
plot.setOutlineVisible(false);
plot.setInsets(new RectangleInsets(0.0, 0.0, 0.0, 0.0));
plot.setAxisOffset(new RectangleInsets(1.0, 1.0, 1.0, 1.0));
plot.setDomainGridlinesVisible(false);
plot.setRangeGridlinesVisible(false);
plot.setBackgroundPaint(TRANSPARENT_COLOR);
plot.setBackgroundAlpha(0.0f);
plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
if (showRangeZeroBaseline) {
plot.setRangeZeroBaselineVisible(true);
plot.setRangeZeroBaselinePaint(axisColor);
plot.setRangeZeroBaselineStroke(new EqualDashStroke(axisWidth));
}
final BasicStroke axisStroke = new BasicStroke(axisWidth, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);
final BasicStroke gridLineStroke = new BasicStroke(axisWidth, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 0.5f, new float[] { 0.5f }, 0.0f);
plot.setRangeGridlineStroke(gridLineStroke);
final CategoryAxis domainAxis = (CategoryAxis) plot.getDomainAxis();
domainAxis.setVisible(showDomainAxis);
domainAxis.setAxisLineStroke(axisStroke);
domainAxis.setAxisLinePaint(axisColor);
domainAxis.setTickMarksVisible(true);
domainAxis.setTickMarkStroke(axisStroke);
domainAxis.setTickMarkPaint(axisColor);
domainAxis.setTickLabelsVisible(true);
domainAxis.setTickLabelFont(domainAxis.getTickLabelFont().deriveFont(axisFontSize).deriveFont(Font.PLAIN));
domainAxis.setTickLabelPaint(axisColor);
domainAxis.setCategoryLabelPositions(getCategoryLabelPosition());
domainAxis.setCategoryMargin(.1);
domainAxis.setLowerMargin(0.0);
domainAxis.setUpperMargin(0.0);
final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
rangeAxis.setVisible(showRangeAxis);
rangeAxis.setAxisLineStroke(axisStroke);
rangeAxis.setAxisLinePaint(axisColor);
rangeAxis.setTickMarkStroke(axisStroke);
rangeAxis.setTickMarkPaint(axisColor);
rangeAxis.setTickLabelFont(rangeAxis.getLabelFont().deriveFont(axisFontSize).deriveFont(Font.PLAIN));
rangeAxis.setTickLabelPaint(axisColor);
rangeAxis.setLowerMargin(0.0);
rangeAxis.setUpperMargin(0.0);
// Set axis range
if (range != null && range.size() >= 2 && range.get(0) != null && range.get(1) != null) {
rangeAxis.setLowerBound(range.get(0) * 1.1);
rangeAxis.setUpperBound(range.get(1) * 1.1);
}
final LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer();
renderer.setBaseItemLabelGenerator(showItemLabels ? new CustomCategoryItemLabelGenerator(itemLabels) : null);
renderer.setBaseItemLabelsVisible(showItemLabels);
renderer.setBaseItemLabelFont(renderer.getBaseItemLabelFont().deriveFont(itemFontSize));
renderer.setBaseItemLabelPaint(labelColor);
final BasicStroke seriesStroke = new BasicStroke(lineWidth, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);
final List<?> keys = dataset.getRowKeys();
if (colors != null && colors.size() >= keys.size()) {
for (int i = 0; i < keys.size(); i++) {
final Color c = colors.get(i);
renderer.setSeriesPaint(i, c);
renderer.setSeriesStroke(i, seriesStroke);
}
}
return chart;
}
Aggregations