private static void configureBarRenderer( BarRenderer renderer, ValueSource valueSource, PlotInstance plotInstance) { StandardBarPainter barPainter = new StandardBarPainter(); renderer.setBarPainter(barPainter); renderer.setGradientPaintTransformer(null); ValueSourceData valueSourceData = plotInstance.getPlotData().getValueSourceData(valueSource); int seriesCount = valueSourceData.getSeriesCount(); DimensionConfig domainConfig = valueSource.getDomainConfig(); DimensionConfig colorDimensionConfig = plotInstance.getCurrentPlotConfigurationClone().getDimensionConfig(PlotDimension.COLOR); SeriesFormat seriesFormat = valueSource.getSeriesFormat(); // Loop all series and set series format. // Format based on dimension configs will be set later on in initFormatDelegate(). for (int seriesIdx = 0; seriesIdx < seriesCount; ++seriesIdx) { // configure series paint if necessary if (!SeriesFormat.calculateIndividualFormatForEachItem(domainConfig, colorDimensionConfig)) { renderer.setSeriesPaint(seriesIdx, seriesFormat.getAreaFillPaint()); } // configure general style of the bars renderer.setShadowVisible(false); renderer.setSeriesOutlinePaint(seriesIdx, PlotConfiguration.DEFAULT_SERIES_OUTLINE_PAINT); } renderer.setDrawBarOutline(true); }
public static XYItemRenderer createDeviationRenderer( ValueSource valueSource, PlotInstance plotInstance) { FormattedDeviationRenderer renderer = new FormattedDeviationRenderer(); configureXYLineAndShapeRenderer(renderer, valueSource, plotInstance); renderer.setAlpha(0.5f * valueSource.getSeriesFormat().getOpacity() / 255f); initFormatDelegate(valueSource, renderer, plotInstance); return renderer; }
private static void configureAreaRenderer( AreaRenderer renderer, ValueSource valueSource, PlotInstance plotInstance) { ValueSourceData valueSourceData = plotInstance.getPlotData().getValueSourceData(valueSource); int seriesCount = valueSourceData.getSeriesCount(); SeriesFormat seriesFormat = valueSource.getSeriesFormat(); // Loop all series and set series format. // Format based on dimension configs will be set later on in initFormatDelegate(). for (int seriesIdx = 0; seriesIdx < seriesCount; ++seriesIdx) { renderer.setSeriesPaint(seriesIdx, seriesFormat.getAreaFillPaint()); } }
private static void configureXYDifferenceRenderer( FormattedXYDifferenceRenderer renderer, ValueSource valueSource, PlotConfiguration plotConfiguration) { renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); SeriesFormat seriesFormat = valueSource.getSeriesFormat(); DimensionConfig domainConfig = valueSource.getDomainConfig(); DimensionConfig colorDimensionConfig = plotConfiguration.getDimensionConfig(PlotDimension.COLOR); DimensionConfig shapeDimensionConfig = plotConfiguration.getDimensionConfig(PlotDimension.SHAPE); int seriesCount = 1; // valueSource.getSeriesDataForAllGroupCells().groupCellCount(); // Loop all series and set series format. // Format based on dimension configs will be set later on in initFormatDelegate(). for (int seriesIdx = 0; seriesIdx < seriesCount; ++seriesIdx) { // configure linestyle if (seriesFormat.getLineStyle() == LineStyle.NONE) { } else { renderer.setSeriesStroke(seriesIdx, seriesFormat.getStroke(), false); } // configure series shape if necessary if (!SeriesFormat.calculateIndividualFormatForEachItem(domainConfig, shapeDimensionConfig)) { if (seriesFormat.getItemShape() != ItemShape.NONE) { renderer.setSeriesShape(seriesIdx, seriesFormat.getItemShape().getShape()); } else { } } // configure series color if necessary if (!SeriesFormat.calculateIndividualFormatForEachItem(domainConfig, colorDimensionConfig)) { Color itemColor = seriesFormat.getItemColor(); Color halfTransparentPaint = DataStructureUtils.setColorAlpha(itemColor, itemColor.getAlpha() / 2); renderer.setSeriesPaint(0, halfTransparentPaint); renderer.setSeriesFillPaint(0, halfTransparentPaint); renderer.setPositivePaint(halfTransparentPaint); renderer.setNegativePaint( new Color( 255 - itemColor.getRed(), 255 - itemColor.getGreen(), 255 - itemColor.getBlue(), itemColor.getAlpha() / 2)); } renderer.setSeriesOutlinePaint(seriesIdx, PlotConfiguration.DEFAULT_SERIES_OUTLINE_PAINT); } }
private static void addSeriesToDefaultXYDataset( ValueSource valueSource, int seriesIdx, PlotInstance plotInstance, DefaultXYDataset dataset) throws ChartPlottimeException { final int xIdx = 0; final int yIdx = 1; ValueSourceData valueSourceData = plotInstance.getPlotData().getValueSourceData(valueSource); assertMaxValueCountNotExceededOrThrowException(valueSourceData); GroupCellSeriesData dataForAllGroupCells = valueSourceData.getSeriesDataForAllGroupCells(); GroupCellKeyAndData groupCellKeyAndData = dataForAllGroupCells.getGroupCellKeyAndData(seriesIdx); GroupCellKey groupCellKey = groupCellKeyAndData.getKey(); GroupCellData groupCellData = groupCellKeyAndData.getData(); // create series name GroupCellKey groupCellKeyClone = (GroupCellKey) groupCellKey.clone(); String seriesName = generateSeriesName( valueSource, groupCellKeyClone, plotInstance.getCurrentPlotConfigurationClone()); String differenceName = "__&%" + seriesName + "%&__"; Map<PlotDimension, double[]> mainData = groupCellData.getDataForUsageType(SeriesUsageType.MAIN_SERIES); double[] xValues = mainData.get(PlotDimension.DOMAIN); double[] yValues = mainData.get(PlotDimension.VALUE); double[][] mainSeries = new double[2][xValues.length]; mainSeries[xIdx] = xValues; mainSeries[yIdx] = yValues; dataset.addSeries(seriesName, mainSeries); if (valueSource.getSeriesFormat().getUtilityUsage() == IndicatorType.DIFFERENCE) { double[] differenceValues = valueSourceData.getAbsoluteUtilityValues(groupCellKeyAndData, true); if (differenceValues == null) { throw new ChartPlottimeException( "undefined_series", valueSource.toString(), SeriesUsageType.INDICATOR_1); } double[][] differenceSeries = new double[2][xValues.length]; differenceSeries[xIdx] = xValues; differenceSeries[yIdx] = differenceValues; dataset.addSeries(differenceName, differenceSeries); } }
private static void configureXYLineAndShapeRenderer( XYLineAndShapeRenderer renderer, ValueSource valueSource, PlotInstance plotInstance) { renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); SeriesFormat seriesFormat = valueSource.getSeriesFormat(); DimensionConfig domainConfig = valueSource.getDomainConfig(); DimensionConfig colorDimensionConfig = plotInstance.getCurrentPlotConfigurationClone().getDimensionConfig(PlotDimension.COLOR); DimensionConfig shapeDimensionConfig = plotInstance.getCurrentPlotConfigurationClone().getDimensionConfig(PlotDimension.SHAPE); ValueSourceData valueSourceData = plotInstance.getPlotData().getValueSourceData(valueSource); int seriesCount = valueSourceData.getSeriesDataForAllGroupCells().groupCellCount(); // Loop all series and set series format. // Format based on dimension configs will be set later on in initFormatDelegate(). for (int seriesIdx = 0; seriesIdx < seriesCount; ++seriesIdx) { // configure linestyle if (seriesFormat.getLineStyle() == LineStyle.NONE) { renderer.setSeriesLinesVisible(seriesIdx, false); } else { renderer.setSeriesLinesVisible(seriesIdx, true); renderer.setSeriesStroke(seriesIdx, seriesFormat.getStroke(), false); } // configure series shape if necessary if (!SeriesFormat.calculateIndividualFormatForEachItem(domainConfig, shapeDimensionConfig)) { if (seriesFormat.getItemShape() != ItemShape.NONE) { renderer.setSeriesShapesVisible(seriesIdx, true); renderer.setSeriesShape(seriesIdx, seriesFormat.getItemShape().getShape()); } else { renderer.setSeriesShapesVisible(seriesIdx, false); } } // configure series color if necessary if (!SeriesFormat.calculateIndividualFormatForEachItem(domainConfig, colorDimensionConfig)) { Color itemColor = seriesFormat.getItemColor(); renderer.setSeriesPaint(seriesIdx, itemColor); renderer.setSeriesFillPaint(seriesIdx, itemColor); } renderer.setSeriesOutlinePaint(seriesIdx, PlotConfiguration.DEFAULT_SERIES_OUTLINE_PAINT); renderer.setUseOutlinePaint(true); } }
private static void configureLineAndShapeRenderer( LineAndShapeRenderer renderer, ValueSource valueSource, PlotInstance plotInstance) { ValueSourceData valueSourceData = plotInstance.getPlotData().getValueSourceData(valueSource); int seriesCount = valueSourceData.getSeriesCount(); SeriesFormat seriesFormat = valueSource.getSeriesFormat(); DimensionConfig domainConfig = valueSource.getDomainConfig(); DimensionConfig colorDimensionConfig = plotInstance.getCurrentPlotConfigurationClone().getDimensionConfig(PlotDimension.COLOR); DimensionConfig shapeDimensionConfig = plotInstance.getCurrentPlotConfigurationClone().getDimensionConfig(PlotDimension.SHAPE); renderer.setDefaultEntityRadius(4); // loop all series and set series format for (int seriesIdx = 0; seriesIdx < seriesCount; ++seriesIdx) { // configure linestyle if (seriesFormat.getLineStyle() != LineStyle.NONE) { renderer.setSeriesLinesVisible(seriesIdx, true); renderer.setSeriesStroke(seriesIdx, seriesFormat.getStroke(), false); } else { renderer.setSeriesLinesVisible(seriesIdx, false); } // configure series shape if necessary if (!SeriesFormat.calculateIndividualFormatForEachItem(domainConfig, shapeDimensionConfig)) { if (seriesFormat.getItemShape() != ItemShape.NONE) { renderer.setSeriesShapesVisible(seriesIdx, true); renderer.setSeriesShape(seriesIdx, seriesFormat.getItemShape().getShape()); } else { renderer.setSeriesShapesVisible(seriesIdx, false); } } // configure series color if necessary if (!SeriesFormat.calculateIndividualFormatForEachItem(domainConfig, colorDimensionConfig)) { Color itemColor = seriesFormat.getItemColor(); renderer.setSeriesPaint(seriesIdx, itemColor); } renderer.setSeriesOutlinePaint(seriesIdx, PlotConfiguration.DEFAULT_SERIES_OUTLINE_PAINT); renderer.setUseOutlinePaint(true); } }
private static void configureScatterRenderer( ScatterRenderer renderer, ValueSource valueSource, PlotInstance plotInstance) throws ChartPlottimeException { ValueSourceData valueSourceData = plotInstance.getPlotData().getValueSourceData(valueSource); int seriesCount = valueSourceData.getSeriesCount(); SeriesFormat seriesFormat = valueSource.getSeriesFormat(); DimensionConfig domainConfig = valueSource.getDomainConfig(); DimensionConfig colorDimensionConfig = plotInstance.getCurrentPlotConfigurationClone().getDimensionConfig(PlotDimension.COLOR); DimensionConfig shapeDimensionConfig = plotInstance.getCurrentPlotConfigurationClone().getDimensionConfig(PlotDimension.SHAPE); renderer.setDefaultEntityRadius(4); // loop all series and set series format for (int seriesIdx = 0; seriesIdx < seriesCount; ++seriesIdx) { // lines are not supported in a ScatterRenderer, but this is already checked in // JFreeChartPlotEngine.getWarnings(). // configure series shape if necessary if (!SeriesFormat.calculateIndividualFormatForEachItem(domainConfig, shapeDimensionConfig)) { // if(seriesFormat.getItemShape() != ItemShape.NONE) { renderer.setSeriesShape(seriesIdx, seriesFormat.getItemShape().getShape()); // } else { // throw new ChartPlottimeException("unsupported_item_shape", valueSource.toString(), // seriesFormat.getItemShape()); // } } // configure series color if necessary if (!SeriesFormat.calculateIndividualFormatForEachItem(domainConfig, colorDimensionConfig)) { Color itemColor = seriesFormat.getItemColor(); renderer.setSeriesPaint(seriesIdx, itemColor); } renderer.setSeriesOutlinePaint(seriesIdx, PlotConfiguration.DEFAULT_SERIES_OUTLINE_PAINT); renderer.setUseOutlinePaint(true); renderer.setDrawOutlines(true); renderer.setUseSeriesOffset(false); } }
private CustomLegendItem createValueSourceLegendItem( PlotConfiguration plotConfig, ValueSource valueSource) { Set<PlotDimension> dimensions = new HashSet<PlotDimension>(); for (PlotDimension dimension : PlotDimension.values()) { switch (dimension) { case DOMAIN: case VALUE: break; default: if (valueSource.useSeriesFormatForDimension(plotConfig, dimension)) { dimensions.add(dimension); } } } if (dimensions.isEmpty()) { return null; } SeriesFormat format = valueSource.getSeriesFormat(); String description = ""; String toolTipText = ""; String urlText = ""; boolean shapeVisible = true; Shape shape; boolean shapeFilled = true; Paint fillPaint = UNDEFINED_COLOR_PAINT; boolean shapeOutlineVisible = true; Paint outlinePaint = PlotConfiguration.DEFAULT_OUTLINE_COLOR; Stroke outlineStroke = DEFAULT_OUTLINE_STROKE; boolean lineVisible = format.getLineStyle() != LineStyle.NONE && format.getSeriesType() == SeriesFormat.VisualizationType.LINES_AND_SHAPES; // configure fill paint and line paint Paint linePaint; String label = valueSource.toString(); if (label == null) { label = ""; } if (dimensions.contains(PlotDimension.COLOR)) { Color color = format.getItemColor(); fillPaint = format.getAreaFillPaint(color); linePaint = fillPaint; } else { if (format.getAreaFillStyle() == FillStyle.NONE) { fillPaint = new Color(0, 0, 0, 0); linePaint = fillPaint; } else if (format.getAreaFillStyle() == FillStyle.SOLID) { fillPaint = UNDEFINED_COLOR_PAINT; linePaint = UNDEFINED_LINE_COLOR; } else { fillPaint = format.getAreaFillPaint(UNDEFINED_COLOR); linePaint = fillPaint; } } VisualizationType seriesType = valueSource.getSeriesFormat().getSeriesType(); if (seriesType == VisualizationType.LINES_AND_SHAPES) { if (dimensions.contains(PlotDimension.SHAPE)) { shape = format.getItemShape().getShape(); } else if (dimensions.contains(PlotDimension.COLOR)) { shape = UNDEFINED_SHAPE; } else { shape = UNDEFINED_SHAPE_AND_COLOR; } if (dimensions.contains(PlotDimension.SIZE)) { AffineTransform transformation = new AffineTransform(); double scalingFactor = format.getItemSize(); transformation.scale(scalingFactor, scalingFactor); shape = transformation.createTransformedShape(shape); } } else if (seriesType == VisualizationType.BARS) { shape = BAR_SHAPE; } else if (seriesType == VisualizationType.AREA) { shape = AREA_SHAPE; } else { throw new RuntimeException("Unknown SeriesType. This should not happen."); } // configure line shape float lineLength = 0; if (lineVisible) { lineLength = format.getLineWidth(); if (lineLength < 1) { lineLength = 1; } if (lineLength > 1) { lineLength = 1 + (float) Math.log(lineLength) / 2; } // line at least 30 pixels long, and show at least 2 iterations of stroke lineLength = Math.max(lineLength * 30, format.getStrokeLength() * 2); // line at least 2x longer than shape width if (shape != null) { lineLength = Math.max(lineLength, (float) shape.getBounds().getWidth() * 2f); } } // now create line shape and stroke Shape line = new Line2D.Float(0, 0, lineLength, 0); BasicStroke lineStroke = format.getStroke(); if (lineStroke == null) { lineStroke = new BasicStroke(); } // unset line ending decoration to prevent drawing errors in legend { BasicStroke s = lineStroke; lineStroke = new BasicStroke( s.getLineWidth(), BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND, s.getMiterLimit(), s.getDashArray(), s.getDashPhase()); } return new CustomLegendItem( label, description, toolTipText, urlText, shapeVisible, shape, shapeFilled, fillPaint, shapeOutlineVisible, outlinePaint, outlineStroke, lineVisible, line, lineStroke, linePaint); }