private JFreeChart createChart(CheapTimeSolution solution) { TangoColorFactory tangoColorFactory = new TangoColorFactory(); NumberAxis rangeAxis = new NumberAxis("Period"); rangeAxis.setRange(-0.5, solution.getGlobalPeriodRangeTo() + 0.5); XYPlot taskAssignmentPlot = createTaskAssignmentPlot(tangoColorFactory, solution); XYPlot periodCostPlot = createPeriodCostPlot(tangoColorFactory, solution); XYPlot capacityPlot = createAvailableCapacityPlot(tangoColorFactory, solution); CombinedRangeXYPlot combinedPlot = new CombinedRangeXYPlot(rangeAxis); combinedPlot.add(taskAssignmentPlot, 5); combinedPlot.add(periodCostPlot, 1); combinedPlot.add(capacityPlot, 1); combinedPlot.setOrientation(PlotOrientation.HORIZONTAL); return new JFreeChart("Cheap Power Time Scheduling", JFreeChart.DEFAULT_TITLE_FONT, combinedPlot, true); }
RectangleInsets insets = getInsets(); insets.trim(area); AxisSpace space = calculateAxisSpace(g2, area); Rectangle2D dataArea = space.shrink(area, null); setFixedDomainAxisSpaceForSubplots(space); ValueAxis axis = getRangeAxis(); RectangleEdge edge = getRangeAxisEdge(); double cursor = RectangleEdge.coordinate(dataArea, edge); AxisState axisState = axis.draw(g2, cursor, area, dataArea, edge, info);
PlotOrientation orientation = getOrientation(); AxisSpace fixed = getFixedRangeAxisSpace(); if (fixed != null) { if (orientation == PlotOrientation.VERTICAL) { ValueAxis valueAxis = getRangeAxis(); RectangleEdge valueEdge = Plot.resolveRangeAxisLocation( getRangeAxisLocation(), orientation ); if (valueAxis != null) {
/** * Removes a subplot from the combined chart. * * @param subplot the subplot (<code>null</code> not permitted). */ public void remove(XYPlot subplot) { if (subplot == null) { throw new IllegalArgumentException(" Null 'subplot' argument."); } int position = -1; int size = this.subplots.size(); int i = 0; while (position == -1 && i < size) { if (this.subplots.get(i) == subplot) { position = i; } i++; } if (position != -1) { this.subplots.remove(position); subplot.setParent(null); subplot.removeChangeListener(this); configureRangeAxes(); fireChangeEvent(); } }
/** * Zooms in on the domain axes. * * @param lowerPercent the lower bound. * @param upperPercent the upper bound. * @param info the plot rendering info ({@code null} not permitted). * @param source the source point ({@code null} not permitted). */ @Override public void zoomDomainAxes(double lowerPercent, double upperPercent, PlotRenderingInfo info, Point2D source) { // delegate 'info' and 'source' argument checks... XYPlot subplot = findSubplot(info, source); if (subplot != null) { subplot.zoomDomainAxes(lowerPercent, upperPercent, info, source); } else { // if the source point doesn't fall within a subplot, we do the // zoom on all subplots... Iterator iterator = getSubplots().iterator(); while (iterator.hasNext()) { subplot = (XYPlot) iterator.next(); subplot.zoomDomainAxes(lowerPercent, upperPercent, info, source); } } }
/** * Adds a subplot, with a default 'weight' of 1. * <br><br> * You must ensure that the subplot has a non-null domain axis. The range * axis for the subplot will be set to {@code null}. * * @param subplot the subplot. */ public void add(XYPlot subplot) { add(subplot, 1); }
/** * Returns a collection of legend items for the plot. * * @return The legend items. */ @Override public LegendItemCollection getLegendItems() { LegendItemCollection result = getFixedLegendItems(); if (result == null) { result = new LegendItemCollection(); if (this.subplots != null) { Iterator iterator = this.subplots.iterator(); while (iterator.hasNext()) { XYPlot plot = (XYPlot) iterator.next(); LegendItemCollection more = plot.getLegendItems(); result.addAll(more); } } } return result; }
/** * Returns a clone of the plot. * * @return A clone. * * @throws CloneNotSupportedException this class will not throw this * exception, but subclasses (if any) might. */ public Object clone() throws CloneNotSupportedException { CombinedRangeXYPlot result = (CombinedRangeXYPlot) super.clone(); result.subplots = (List) ObjectUtilities.deepClone(this.subplots); for (Iterator it = result.subplots.iterator(); it.hasNext();) { Plot child = (Plot) it.next(); child.setParent(result); } // after setting up all the subplots, the shared range axis may need // reconfiguring ValueAxis rangeAxis = result.getRangeAxis(); if (rangeAxis != null) { rangeAxis.configure(); } return result; }
Point2D source) { XYPlot subplot = findSubplot(info, source); if (subplot == null) { return;
RectangleInsets insets = getInsets(); insets.trim(area); AxisSpace space = calculateAxisSpace(g2, area); Rectangle2D dataArea = space.shrink(area, null); setFixedDomainAxisSpaceForSubplots(space); ValueAxis axis = getRangeAxis(); RectangleEdge edge = getRangeAxisEdge(); double cursor = RectangleEdge.coordinate(dataArea, edge); AxisState axisState = axis.draw(g2, cursor, area, dataArea, edge, info);
PlotOrientation orientation = getOrientation(); AxisSpace fixed = getFixedRangeAxisSpace(); if (fixed != null) { if (orientation == PlotOrientation.VERTICAL) { ValueAxis valueAxis = getRangeAxis(); RectangleEdge valueEdge = Plot.resolveRangeAxisLocation( getRangeAxisLocation(), orientation ); if (valueAxis != null) {
/** * Removes a subplot from the combined chart. * * @param subplot the subplot ({@code null} not permitted). */ public void remove(XYPlot subplot) { Args.nullNotPermitted(subplot, "subplot"); int position = -1; int size = this.subplots.size(); int i = 0; while (position == -1 && i < size) { if (this.subplots.get(i) == subplot) { position = i; } i++; } if (position != -1) { this.subplots.remove(position); subplot.setParent(null); subplot.removeChangeListener(this); configureRangeAxes(); fireChangeEvent(); } }
/** * Multiplies the range on the domain axis/axes by the specified factor. * * @param factor the zoom factor. * @param info the plot rendering info ({@code null} not permitted). * @param source the source point ({@code null} not permitted). * @param useAnchor zoom about the anchor point? */ @Override public void zoomDomainAxes(double factor, PlotRenderingInfo info, Point2D source, boolean useAnchor) { // delegate 'info' and 'source' argument checks... XYPlot subplot = findSubplot(info, source); if (subplot != null) { subplot.zoomDomainAxes(factor, info, source, useAnchor); } else { // if the source point doesn't fall within a subplot, we do the // zoom on all subplots... Iterator iterator = getSubplots().iterator(); while (iterator.hasNext()) { subplot = (XYPlot) iterator.next(); subplot.zoomDomainAxes(factor, info, source, useAnchor); } } }
/** * Adds a subplot, with a default 'weight' of 1. * <br><br> * You must ensure that the subplot has a non-null domain axis. The range * axis for the subplot will be set to <code>null</code>. * * @param subplot the subplot. */ public void add(XYPlot subplot) { add(subplot, 1); }
/** * Returns a collection of legend items for the plot. * * @return The legend items. */ public LegendItemCollection getLegendItems() { LegendItemCollection result = getFixedLegendItems(); if (result == null) { result = new LegendItemCollection(); if (this.subplots != null) { Iterator iterator = this.subplots.iterator(); while (iterator.hasNext()) { XYPlot plot = (XYPlot) iterator.next(); LegendItemCollection more = plot.getLegendItems(); result.addAll(more); } } } return result; }
/** * Returns a clone of the plot. * * @return A clone. * * @throws CloneNotSupportedException this class will not throw this * exception, but subclasses (if any) might. */ @Override public Object clone() throws CloneNotSupportedException { CombinedRangeXYPlot result = (CombinedRangeXYPlot) super.clone(); result.subplots = (List) ObjectUtils.deepClone(this.subplots); for (Iterator it = result.subplots.iterator(); it.hasNext();) { Plot child = (Plot) it.next(); child.setParent(result); } // after setting up all the subplots, the shared range axis may need // reconfiguring ValueAxis rangeAxis = result.getRangeAxis(); if (rangeAxis != null) { rangeAxis.configure(); } return result; }
/** * Adds a subplot with a particular weight (greater than or equal to one). * The weight determines how much space is allocated to the subplot * relative to all the other subplots. * <br><br> * You must ensure that the subplot has a non-null domain axis. The range * axis for the subplot will be set to <code>null</code>. * * @param subplot the subplot. * @param weight the weight (must be 1 or greater). */ public void add(XYPlot subplot, int weight) { // verify valid weight if (weight <= 0) { String msg = "The 'weight' must be positive."; throw new IllegalArgumentException(msg); } // store the plot and its weight subplot.setParent(this); subplot.setWeight(weight); subplot.setInsets(new RectangleInsets(0.0, 0.0, 0.0, 0.0)); subplot.setRangeAxis(null); subplot.addChangeListener(this); this.subplots.add(subplot); configureRangeAxes(); fireChangeEvent(); }
/** * Multiplies the range on the domain axis/axes by the specified factor. * * @param factor the zoom factor. * @param info the plot rendering info (<code>null</code> not permitted). * @param source the source point (<code>null</code> not permitted). * @param useAnchor zoom about the anchor point? */ public void zoomDomainAxes(double factor, PlotRenderingInfo info, Point2D source, boolean useAnchor) { // delegate 'info' and 'source' argument checks... XYPlot subplot = findSubplot(info, source); if (subplot != null) { subplot.zoomDomainAxes(factor, info, source, useAnchor); } else { // if the source point doesn't fall within a subplot, we do the // zoom on all subplots... Iterator iterator = getSubplots().iterator(); while (iterator.hasNext()) { subplot = (XYPlot) iterator.next(); subplot.zoomDomainAxes(factor, info, source, useAnchor); } } }
private JFreeChart createChart(CheapTimeSolution solution) { TangoColorFactory tangoColorFactory = new TangoColorFactory(); NumberAxis rangeAxis = new NumberAxis("Period"); rangeAxis.setRange(-0.5, solution.getGlobalPeriodRangeTo() + 0.5); XYPlot taskAssignmentPlot = createTaskAssignmentPlot(tangoColorFactory, solution); XYPlot periodCostPlot = createPeriodCostPlot(tangoColorFactory, solution); XYPlot capacityPlot = createAvailableCapacityPlot(tangoColorFactory, solution); CombinedRangeXYPlot combinedPlot = new CombinedRangeXYPlot(rangeAxis); combinedPlot.add(taskAssignmentPlot, 5); combinedPlot.add(periodCostPlot, 1); combinedPlot.add(capacityPlot, 1); combinedPlot.setOrientation(PlotOrientation.HORIZONTAL); return new JFreeChart("Cheap Power Time Scheduling", JFreeChart.DEFAULT_TITLE_FONT, combinedPlot, true); }
/** * Adds a subplot with a particular weight (greater than or equal to one). * The weight determines how much space is allocated to the subplot * relative to all the other subplots. * <br><br> * You must ensure that the subplot has a non-null domain axis. The range * axis for the subplot will be set to {@code null}. * * @param subplot the subplot ({@code null} not permitted). * @param weight the weight (must be 1 or greater). */ public void add(XYPlot subplot, int weight) { Args.nullNotPermitted(subplot, "subplot"); if (weight <= 0) { String msg = "The 'weight' must be positive."; throw new IllegalArgumentException(msg); } // store the plot and its weight subplot.setParent(this); subplot.setWeight(weight); subplot.setInsets(new RectangleInsets(0.0, 0.0, 0.0, 0.0)); subplot.setRangeAxis(null); subplot.addChangeListener(this); this.subplots.add(subplot); configureRangeAxes(); fireChangeEvent(); }