List of usage examples for org.jfree.chart.axis ValueAxis getRange
public Range getRange()
From source file:net.sf.mzmine.chartbasics.gestures.ChartGestureHandler.java
/** * Creates a predefined consumer for drag diff events * //from www . j a va 2 s . c om * @param handler The predefined consumer * @param param Parameters for specific handlers * @return * @throws Exception */ public static Consumer<ChartGestureDragDiffEvent> createDragDiffConsumer(DragHandler handler, Object[] param) throws Exception { switch (handler) { case SCROLL_AXIS: return e -> { ValueAxis axis = e.getAxis(); if (axis != null) ChartLogics.offsetAxisAbsolute(axis, e.getDiff()); }; case SCROLL_AXIS_AND_AUTO_ZOOM: return de -> { ValueAxis axis = de.getAxis(); if (axis != null) { ChartLogics.offsetAxisAbsolute(axis, de.getDiff()); if (de.getEntity().equals(Entity.DOMAIN_AXIS)) de.getChartWrapper().autoRangeAxis(); else de.getChartWrapper().autoDomainAxis(); } }; case AUTO_ZOOM_AXIS: return de -> { ValueAxis axis = de.getAxis(); if (axis != null) ChartLogics.autoAxis(axis); }; case AUTO_ZOOM_OPPOSITE_AXIS: return de -> { ValueAxis axis = de.getAxis(); if (axis != null) { if (de.getEntity().equals(Entity.DOMAIN_AXIS)) de.getChartWrapper().autoRangeAxis(); else de.getChartWrapper().autoDomainAxis(); } }; case ZOOM_AXIS_INCLUDE_ZERO: return de -> { ValueAxis axis = de.getAxis(); if (axis != null) { double diff = de.getDiff() / axis.getRange().getLength() * 4; ChartLogics.zoomAxis(axis, diff, true); } }; case ZOOM_AXIS_CENTER: return de -> { ValueAxis axis = de.getAxis(); if (axis != null) { double diff = de.getDiff() / axis.getRange().getLength() * 4; ChartLogics.zoomAxis(axis, diff, de.getStart()); } }; default: throw new Exception("DragHandler not specified"); } }
From source file:org.kalypso.ogc.sensor.diagview.jfreechart.ObservationPlot.java
/** * Draw alarmlevels (horizontal line and text annotation) *//*from www . j av a 2s . c o m*/ private void drawAlarmLevels(final Graphics2D g2, final Rectangle2D dataArea) { for (final Object element : m_yConsts.keySet()) { final AlarmLevelPlotElement vac = m_yConsts.get(element); final ValueAxis axis = m_diag2chartAxis.get(vac.getAxis()); if (axis == null) continue; if (axis.getRange().contains(vac.getAlarm().value)) { final double yy = axis.valueToJava2D(vac.getAlarm().value, dataArea, RectangleEdge.LEFT); final Line2D line = new Line2D.Double(dataArea.getMinX(), yy, dataArea.getMaxX(), yy); // always set stroke, else we got the stroke from the last drawn line g2.setStroke(AlarmLevelPlotElement.STROKE_ALARM); g2.setPaint(vac.getAlarm().color); g2.draw(line); // and draw the text annotation: if annotation is outside (on top); label it below the line if (yy < dataArea.getMinY() + 20) vac.getAnnotation().setAngle(Math.toRadians(20)); else vac.getAnnotation().setAngle(Math.toRadians(340)); vac.getAnnotation().draw(g2, this, dataArea, getDomainAxis(), axis); } } }
From source file:org.fhcrc.cpl.viewer.gui.SpectrumComponent.java
protected void copyChartData() { if (null == _chart || null == _spectrum) return;/* w w w . j a v a2 s. c o m*/ XYPlot xyplot; if (_chart.getPlot() instanceof XYPlot) { xyplot = _chart.getXYPlot(); } else { // UNDONE: return; } ValueAxis domainAxis = xyplot.getDomainAxis(); Range range = domainAxis.getRange(); double min = range.getLowerBound(); double max = range.getUpperBound(); float[] x = _spectrum[0]; float[] y = _spectrum[1]; int start = Arrays.binarySearch(x, (float) min); if (start < 0) start = -(start + 1); int end = Arrays.binarySearch(x, (float) max); if (end < 0) end = -(end + 1); StringBuffer sb = new StringBuffer(20 * (end - start)); for (int i = start; i < end; i++) sb.append(x[i]).append('\t').append(y[i]).append('\n'); StringSelection sel = new StringSelection(sb.toString()); Toolkit.getDefaultToolkit().getSystemClipboard().setContents(sel, sel); }
From source file:org.jfree.experimental.chart.annotations.XYTitleAnnotation.java
/** * Draws the annotation. This method is called by the drawing code in the * {@link XYPlot} class, you don't normally need to call this method * directly./* ww w.j a v a 2 s . co m*/ * * @param g2 the graphics device. * @param plot the plot. * @param dataArea the data area. * @param domainAxis the domain axis. * @param rangeAxis the range axis. * @param rendererIndex the renderer index. * @param info if supplied, this info object will be populated with * entity information. */ public void draw(Graphics2D g2, XYPlot plot, Rectangle2D dataArea, ValueAxis domainAxis, ValueAxis rangeAxis, int rendererIndex, PlotRenderingInfo info) { PlotOrientation orientation = plot.getOrientation(); AxisLocation domainAxisLocation = plot.getDomainAxisLocation(); AxisLocation rangeAxisLocation = plot.getRangeAxisLocation(); RectangleEdge domainEdge = Plot.resolveDomainAxisLocation(domainAxisLocation, orientation); RectangleEdge rangeEdge = Plot.resolveRangeAxisLocation(rangeAxisLocation, orientation); Range xRange = domainAxis.getRange(); Range yRange = rangeAxis.getRange(); double anchorX = 0.0; double anchorY = 0.0; if (this.coordinateType == XYCoordinateType.RELATIVE) { anchorX = xRange.getLowerBound() + (this.x * xRange.getLength()); anchorY = yRange.getLowerBound() + (this.y * yRange.getLength()); } else { anchorX = domainAxis.valueToJava2D(this.x, dataArea, domainEdge); anchorY = rangeAxis.valueToJava2D(this.y, dataArea, rangeEdge); } float j2DX = (float) domainAxis.valueToJava2D(anchorX, dataArea, domainEdge); float j2DY = (float) rangeAxis.valueToJava2D(anchorY, dataArea, rangeEdge); float xx = 0.0f; float yy = 0.0f; if (orientation == PlotOrientation.HORIZONTAL) { xx = j2DY; yy = j2DX; } else if (orientation == PlotOrientation.VERTICAL) { xx = j2DX; yy = j2DY; } double maxW = dataArea.getWidth(); double maxH = dataArea.getHeight(); if (this.coordinateType == XYCoordinateType.RELATIVE) { if (this.maxWidth > 0.0) { maxW = maxW * this.maxWidth; } if (this.maxHeight > 0.0) { maxH = maxH * this.maxHeight; } } if (this.coordinateType == XYCoordinateType.DATA) { maxW = this.maxWidth; maxH = this.maxHeight; } RectangleConstraint rc = new RectangleConstraint(new Range(0, maxW), new Range(0, maxH)); Size2D size = this.title.arrange(g2, rc); Rectangle2D titleRect = new Rectangle2D.Double(0, 0, size.width, size.height); Point2D anchorPoint = RectangleAnchor.coordinates(titleRect, this.anchor); xx = xx - (float) anchorPoint.getX(); yy = yy - (float) anchorPoint.getY(); titleRect.setRect(xx, yy, titleRect.getWidth(), titleRect.getHeight()); BlockParams p = new BlockParams(); if (info != null) { if (info.getOwner().getEntityCollection() != null) { p.setGenerateEntities(true); } } Object result = this.title.draw(g2, titleRect, p); if (result instanceof EntityBlockResult) { EntityBlockResult ebr = (EntityBlockResult) result; info.getOwner().getEntityCollection().addAll(ebr.getEntityCollection()); } String toolTip = getToolTipText(); String url = getURL(); if (toolTip != null || url != null) { addEntity(info, new Rectangle2D.Float(xx, yy, (float) size.width, (float) size.height), rendererIndex, toolTip, url); } }
From source file:de.bund.bfr.knime.pmmlite.views.chart.ChartCreator.java
public ChartCreator(Map<String, Plotable> plotables, Map<String, String> legend) { this.plotables = plotables; this.legend = legend; colors = new LinkedHashMap<>(); shapes = new LinkedHashMap<>(); colorLists = new LinkedHashMap<>(); shapeLists = new LinkedHashMap<>(); chartPanel = new ChartPanel(new JFreeChart(new XYPlot())) { private static final long serialVersionUID = 1L; @Override//from w ww . ja v a2 s .c om public void mouseReleased(MouseEvent e) { ValueAxis domainAxis = ((XYPlot) getChart().getPlot()).getDomainAxis(); ValueAxis rangeAxis = ((XYPlot) getChart().getPlot()).getRangeAxis(); Range xRange1 = domainAxis.getRange(); Range yRange1 = rangeAxis.getRange(); super.mouseReleased(e); Range xRange2 = domainAxis.getRange(); Range yRange2 = rangeAxis.getRange(); if (!xRange1.equals(xRange2) || !yRange1.equals(yRange2)) { minX = xRange2.getLowerBound(); maxX = xRange2.getUpperBound(); minY = yRange2.getLowerBound(); maxY = yRange2.getUpperBound(); fireZoomChanged(); } } }; chartPanel.getPopupMenu().removeAll(); setLayout(new BorderLayout()); add(chartPanel, BorderLayout.CENTER); }
From source file:org.tsho.dmc2.core.chart.LyapunovRenderer.java
public boolean renderVsParameter(Graphics2D g2, Rectangle2D dataArea) { final int imageWidth = (int) dataArea.getWidth(); g2.setPaint(Color.red);/* w ww. j av a2 s .c o m*/ final double parStep; int prevX[] = new int[model.getNVar()]; int prevY[] = new int[model.getNVar()]; //? 28.7.2004 ValueAxis domainAxis = plot.getDomainAxis(); lower = domainAxis.getRange().getLowerBound(); upper = domainAxis.getRange().getUpperBound(); parStep = Math.abs(upper - lower) / imageWidth; String colNames[] = new String[model.getNVar() + 1]; colNames[0] = firstParLabel; for (int j = 1; j < (model.getNVar() + 1); j++) colNames[j] = "" + (new Integer(j)); Dataset dataset = new Dataset(colNames); lyapunovComponent.setDataobject(dataset); double tmpRow[]; if (model instanceof ODE) { double step = stepSize; // stepSize and timeStep probably mean the same thing, one for discrete another for ODE for (double i = lower; i < upper; i += parStep) { double[] result = new double[model.getNVar()];//initializing not needed but compiler too cautious. int transX, transY; parameters.put(firstParLabel, i); result = Lua.evaluateLyapunovExponentsODE(model, parameters, initialPoint, timePeriod, stepSize); tmpRow = new double[model.getNVar() + 1]; tmpRow[0] = i; for (int a1 = 1; a1 < tmpRow.length; a1++) tmpRow[a1] = result[a1 - 1]; try { dataset.addRow(tmpRow); } catch (DatasetException de) { System.out.println("" + de); } for (int j = 0; j < result.length; j++) { if (Double.isNaN(result[j])) break; transX = (int) plot.getDomainAxis().valueToJava2D(i, dataArea, RectangleEdge.BOTTOM); transY = (int) plot.getRangeAxis().valueToJava2D(result[j], dataArea, RectangleEdge.LEFT); g2.setPaint(paintSequence[j]); if (bigDots) { g2.fillRect(transX - 1, transY - 1, 3, 3); } else { g2.fillRect(transX, transY, 1, 1); } if (connectWithLines) { if (i != lower) { g2.drawLine(transX, transY, prevX[j], prevY[j]); } prevX[j] = transX; prevY[j] = transY; } } if (stopped == true) { return false; } } } //? 28.7.2004 else { for (double i = lower; i < upper; i += parStep) { double[] result; int transX, transY; parameters.put(firstParLabel, i); result = Lua.evaluateLyapunovExponents(model, parameters, initialPoint, iterations); tmpRow = new double[model.getNVar() + 1]; tmpRow[0] = i; for (int a1 = 1; a1 < tmpRow.length; a1++) tmpRow[a1] = result[a1 - 1]; try { dataset.addRow(tmpRow); } catch (DatasetException de) { System.out.println("" + de); } for (int j = 0; j < result.length; j++) { if (Double.isNaN(result[j])) break; transX = (int) plot.getDomainAxis().valueToJava2D(i, dataArea, RectangleEdge.BOTTOM); transY = (int) plot.getRangeAxis().valueToJava2D(result[j], dataArea, RectangleEdge.LEFT); g2.setPaint(paintSequence[j]); if (bigDots) { g2.fillRect(transX - 1, transY - 1, 3, 3); } else { g2.fillRect(transX, transY, 1, 1); } if (connectWithLines) { if (i != lower) { g2.drawLine(transX, transY, prevX[j], prevY[j]); } prevX[j] = transX; prevY[j] = transY; } } if (stopped == true) { return false; } } } return true; }
From source file:apidemo.PanScrollZoomDemo.java
/** * Handles a {@link ChartChangeEvent}./*ww w .j ava 2s . c om*/ * * @param event the event. */ public void chartChanged(final ChartChangeEvent event) { try { if (event.getChart() == null) { return; } final BoundedRangeModel scrollBarModel = this.scrollBar.getModel(); if (scrollBarModel == null) { return; } boolean chartIsZoomed = false; final Plot plot = event.getChart().getPlot(); if (plot instanceof XYPlot) { final XYPlot hvp = (XYPlot) plot; final ValueAxis xAxis = hvp.getDomainAxis(); final Range xAxisRange = xAxis.getRange(); // avoid recursion scrollBarModel.removeChangeListener(this); final int low = (int) (xAxisRange.getLowerBound() * this.scrollFactor); scrollBarModel.setValue(low); final int ext = (int) (xAxisRange.getUpperBound() * this.scrollFactor - low); scrollBarModel.setExtent(ext); // restore scrollBarModel.addChangeListener(this); // check if zoomed horizontally //Range hdr = hvp.getHorizontalDataRange(xAxis); final Range hdr = hvp.getDataRange(xAxis); final double len = hdr == null ? 0 : hdr.getLength(); chartIsZoomed |= xAxisRange.getLength() < len; } if (!chartIsZoomed && plot instanceof XYPlot) { // check if zoomed vertically final XYPlot vvp = (XYPlot) plot; ValueAxis yAxis = vvp.getRangeAxis(); if (yAxis != null) { chartIsZoomed = yAxis.getLowerBound() > this.primYMinMax[0] || yAxis.getUpperBound() < this.primYMinMax[1]; // right y-axis if (!chartIsZoomed && plot instanceof XYPlot) { final XYPlot xyPlot = (XYPlot) plot; yAxis = xyPlot.getRangeAxis(1); if (yAxis != null) { chartIsZoomed = yAxis.getLowerBound() > this.secondYMinMax[0] || yAxis.getUpperBound() < this.secondYMinMax[1]; } } } } // enable "zoom-out-buttons" if chart is zoomed // otherwise disable them this.panButton.setEnabled(chartIsZoomed); this.zoomOutButton.setEnabled(chartIsZoomed); this.fitButton.setEnabled(chartIsZoomed); this.scrollBar.setEnabled(chartIsZoomed); if (!chartIsZoomed) { setPanMode(false); this.zoomButton.setSelected(true); } } catch (Exception e) { e.printStackTrace(); } }
From source file:apidemo.PanScrollZoomDemo.java
/** * Recalculates the scrollbar settings./*from w ww. j av a 2s. c o m*/ * * @param plot the plot. */ private void recalcScrollBar(final Plot plot) { if (plot instanceof XYPlot) { final XYPlot hvp = (XYPlot) plot; final ValueAxis axis = hvp.getDomainAxis(); axis.setLowerMargin(0); axis.setUpperMargin(0); final Range rng = axis.getRange(); final BoundedRangeModel scrollBarModel = this.scrollBar.getModel(); final int len = scrollBarModel.getMaximum() - scrollBarModel.getMinimum(); if (rng.getLength() > 0) { this.scrollFactor = len / rng.getLength(); } final double dblow = rng.getLowerBound(); final int ilow = (int) (dblow * this.scrollFactor); scrollBarModel.setMinimum(ilow); final int val = ilow; scrollBarModel.setValue(val); final double dbup = rng.getUpperBound(); final int iup = (int) (dbup * this.scrollFactor); scrollBarModel.setMaximum(iup); final int ext = iup - ilow; scrollBarModel.setExtent(ext); scrollBarModel.addChangeListener(this); } }
From source file:de.unibayreuth.bayeos.goat.panels.timeseries.JPanelChart.java
/** * used for zooming//from ww w . ja v a2s.c o m * * @param axis the axis. * @param range the range. * @param zoomFactor the zoom factor. * @param anchorValue the anchor value. */ private void adjustRange(ValueAxis axis, Range range, double zoomFactor, double anchorValue) { if (axis == null || range == null) { return; } double rangeMinVal = range.getLowerBound() - range.getLength() * axis.getLowerMargin(); double rangeMaxVal = range.getUpperBound() + range.getLength() * axis.getUpperMargin(); double halfLength = axis.getRange().getLength() * zoomFactor / 2; double zoomedMinVal = anchorValue - halfLength; double zoomedMaxVal = anchorValue + halfLength; double adjMinVal = zoomedMinVal; if (zoomedMinVal < rangeMinVal) { adjMinVal = rangeMinVal; zoomedMaxVal += rangeMinVal - zoomedMinVal; } double adjMaxVal = zoomedMaxVal; if (zoomedMaxVal > rangeMaxVal) { adjMaxVal = rangeMaxVal; zoomedMinVal -= zoomedMaxVal - rangeMaxVal; adjMinVal = Math.max(zoomedMinVal, rangeMinVal); } Range adjusted = new Range(adjMinVal, adjMaxVal); axis.setRange(adjusted); }
From source file:com.rapidminer.gui.new_plotter.gui.dialog.ManageZoomDialog.java
/** * Sets the current {@link PlotConfiguration} for this dialog. * //ww w . j a va 2s . c om * @param plotConfig */ private void setPlotConfiguration(PlotConfiguration plotConfig) { if (plotConfig == null) { throw new IllegalArgumentException("plotConfig must not be null!"); } Vector<RangeAxisConfig> rangeConfigsVector = new Vector<RangeAxisConfig>(); String selectedItem = String.valueOf(rangeAxisSelectionCombobox.getSelectedItem()); for (RangeAxisConfig config : plotConfig.getRangeAxisConfigs()) { rangeConfigsVector.add(config); } rangeAxisSelectionCombobox.setModel(new DefaultComboBoxModel(rangeConfigsVector)); // reselect the previously selected RangeAxisConfig (if it is still there) if (selectedItem != null) { for (int i = 0; i < rangeAxisSelectionCombobox.getItemCount(); i++) { if (String.valueOf(rangeAxisSelectionCombobox.getItemAt(i)).equals(selectedItem)) { rangeAxisSelectionCombobox.setSelectedIndex(i); break; } } } // fill in values of current chart Plot plot = engine.getChartPanel().getChart().getPlot(); double domainLowerBound = 0; double domainUpperBound = 0; boolean disableDomainZoom = false; NumericalValueRange effectiveRange = engine.getPlotInstance().getPlotData().getDomainConfigManagerData() .getEffectiveRange(); if (plot instanceof XYPlot) { ValueAxis domainAxis = ((XYPlot) plot).getDomainAxis(); if (domainAxis != null) { Range range = domainAxis.getRange(); domainLowerBound = range.getLowerBound(); domainUpperBound = range.getUpperBound(); } else { if (effectiveRange != null) { domainLowerBound = effectiveRange.getLowerBound(); domainUpperBound = effectiveRange.getUpperBound(); } else { disableDomainZoom = true; } } } else { if (effectiveRange != null) { domainLowerBound = effectiveRange.getLowerBound(); domainUpperBound = effectiveRange.getUpperBound(); } else { disableDomainZoom = true; } } domainRangeLowerBoundField.setText(String.valueOf(domainLowerBound)); domainRangeUpperBoundField.setText(String.valueOf(domainUpperBound)); // happens on nominal domain axis domainRangeLowerBoundField.setEnabled(!disableDomainZoom); domainRangeUpperBoundField.setEnabled(!disableDomainZoom); updateValueRange(); updateColorValues(); }