private Endmember[] convertGraphsToEndmembers(DiagramGraph[] diagramGraphs) { Endmember[] endmembers = new Endmember[diagramGraphs.length]; for (int i = 0; i < diagramGraphs.length; i++) { DiagramGraph diagramGraph = diagramGraphs[i]; int numValues = diagramGraph.getNumValues(); double[] wavelengths = new double[numValues]; double[] radiations = new double[numValues]; for (int j = 0; j < numValues; j++) { wavelengths[j] = diagramGraph.getXValueAt(j); radiations[j] = diagramGraph.getYValueAt(j); } endmembers[i] = new Endmember(diagramGraph.getYName(), wavelengths, radiations); } return endmembers; } }
public static boolean equalXValues(DiagramGraph g1, DiagramGraph g2) { if (g1.getNumValues() != g2.getNumValues()) { return false; } for (int i = 0; i < g1.getNumValues(); i++) { if (Math.abs(g1.getXValueAt(i) - g2.getXValueAt(i)) > 1.0e-10) { return false; } } return true; }
public double getY(DiagramGraph graph, double x) { int n = graph.getNumValues(); double x1, y1, x2 = 0, y2 = 0; for (int i = 0; i < n; i++) { x1 = x2; y1 = y2; x2 = graph.getXValueAt(i); y2 = graph.getYValueAt(i); if (i > 0) { if (x >= x1 && x <= x2) { return y1 + (x - x1) / (x2 - x1) * (y2 - y1); } } } throw new IllegalArgumentException("x out of bounds: " + x); }
b1 = new Point2D.Double(); b2 = new Point2D.Double(); g2d.setStroke(graph.getStyle().getOutlineStroke()); g2d.setColor(graph.getStyle().getOutlineColor()); int n = graph.getNumValues(); for (int i = 0; i < n; i++) { double xa = graph.getXValueAt(i); double ya = graph.getYValueAt(i); if (!Double.isNaN(ya)) { a.setLocation(xa, ya); if (graph.getStyle().isShowingPoints()) { for (int i = 0; i < n; i++) { double xa = graph.getXValueAt(i); double ya = graph.getYValueAt(i); if (!Double.isNaN(ya)) { a.setLocation(xa, ya); b1.getY() - 1.5, 3.0, 3.0); g2d.setPaint(graph.getStyle().getFillPaint()); g2d.fill(r); g2d.setColor(graph.getStyle().getOutlineColor()); g2d.draw(r);
private void drawValueIndicator(Graphics2D g2d) { Diagram.RectTransform transform = diagram.getTransform(); Point2D a = transform.transformB2A(dragPoint, null); double x = a.getX(); if (x < selectedGraph.getXMin()) { x = selectedGraph.getXMin(); } if (x > selectedGraph.getXMax()) { x = selectedGraph.getXMax(); } final Stroke oldStroke = g2d.getStroke(); final Color oldColor = g2d.getColor(); double y = getY(selectedGraph, x); Point2D b = transform.transformA2B(new Point2D.Double(x, y), null); g2d.setStroke(new BasicStroke(1.0f)); g2d.setColor(diagram.getForegroundColor()); Ellipse2D.Double marker = new Ellipse2D.Double(b.getX() - 4.0, b.getY() - 4.0, 8.0, 8.0); g2d.draw(marker); g2d.setStroke(new BasicStroke(1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, new float[]{6, 6}, 12)); g2d.setColor(diagram.getForegroundColor()); final Rectangle graphArea = diagram.getGraphArea(); g2d.draw(new Line2D.Double(b.getX(), graphArea.y + graphArea.height, b.getX(), b.getY())); g2d.draw(new Line2D.Double(graphArea.x, b.getY(), b.getX(), b.getY())); DecimalFormat decimalFormat = new DecimalFormat("0.#####E0"); String text = selectedGraph.getYName() + ": x = " + decimalFormat.format(x) + ", y = " + decimalFormat.format(y); g2d.setStroke(oldStroke); g2d.setColor(oldColor); drawTextBox(g2d, text, graphArea.x + 6, graphArea.y + 6 + 16, new Color(255, 255, 255, 128)); }
protected void adjustAxes(DiagramGraph graph) { try { enableChangeEventMerging(); final DiagramAxis xAxis = getXAxis(); xMinAccum = Math.min(xMinAccum, graph.getXMin()); xMaxAccum = Math.max(xMaxAccum, graph.getXMax()); boolean xRangeValid = xMaxAccum > xMinAccum; if (xRangeValid) { xAxis.setValueRange(xMinAccum, xMaxAccum); xAxis.setOptimalSubDivision(4, 6, 5); } final DiagramAxis yAxis = getYAxis(); yMinAccum = Math.min(yMinAccum, graph.getYMin()); yMaxAccum = Math.max(yMaxAccum, graph.getYMax()); boolean yRangeValid = yMaxAccum > yMinAccum; if (yRangeValid) { yAxis.setValueRange(yMinAccum, yMaxAccum); yAxis.setOptimalSubDivision(3, 6, 5); } } finally { disableChangeEventMerging(); } }
public void setSelectedEndmemberIndex(int index) { int oldIndex = selectedEndmemberIndex; if (oldIndex == index) { return; } if (oldIndex >= 0 && endmemberDiagram.getGraphCount() > 0) { final DiagramGraph endmemberGraph = endmemberDiagram.getGraph(oldIndex); ((DefaultDiagramGraphStyle) endmemberGraph.getStyle()).setOutlineStroke(new BasicStroke(1.0f)); } selectedEndmemberIndex = index; if (selectedEndmemberIndex >= 0 && endmemberDiagram.getGraphCount() > 0) { final DiagramGraph endmemberGraph = endmemberDiagram.getGraph(selectedEndmemberIndex); ((DefaultDiagramGraphStyle) endmemberGraph.getStyle()).setOutlineStroke(new BasicStroke(2.0f)); } endmemberDiagram.invalidate(); propertyChangeSupport.firePropertyChange("selectedEndmemberIndex", oldIndex, selectedEndmemberIndex); }
public DiagramGraph getClosestGraph(int x, int y) { double minDist = Double.MAX_VALUE; Point2D.Double a = new Point2D.Double(); Point2D.Double b1 = new Point2D.Double(); Point2D.Double b2 = new Point2D.Double(); DiagramGraph closestGraph = null; for (DiagramGraph graph : getGraphs()) { double minDistGraph = Double.MAX_VALUE; int n = graph.getNumValues(); for (int i = 0; i < n; i++) { a.setLocation(graph.getXValueAt(i), graph.getYValueAt(i)); b1.setLocation(b2); transform.transformA2B(a, b2); if (i > 0) { Line2D.Double segment = new Line2D.Double(b1, b2); double v = segment.ptSegDist(x, y); if (v < minDistGraph) { minDistGraph = v; } } } if (minDistGraph < minDist) { minDist = minDistGraph; closestGraph = graph; } } return closestGraph; }
public static boolean equalXValues(DiagramGraph g1, DiagramGraph g2) { if (g1.getNumValues() != g2.getNumValues()) { return false; } for (int i = 0; i < g1.getNumValues(); i++) { if (Math.abs(g1.getXValueAt(i) - g2.getXValueAt(i)) > 1.0e-10) { return false; } } return true; }
private static void writeGraphGroup(List<DiagramGraph> graphGroup, Writer writer) throws IOException { DiagramGraph graph0 = graphGroup.get(0); writer.write(graph0.getXName()); for (DiagramGraph graph : graphGroup) { writer.write((int) '\t'); writer.write(graph.getYName()); } writer.write((int) '\n'); int numValues = graph0.getNumValues(); for (int i = 0; i < numValues; i++) { writer.write(String.valueOf(graph0.getXValueAt(i))); for (DiagramGraph graph : graphGroup) { writer.write((int) '\t'); writer.write(String.valueOf(graph.getYValueAt(i))); } writer.write((int) '\n'); } }
private void writeGraphGroup(List<DiagramGraph> graphGroup, Writer writer) throws IOException { DiagramGraph graph0 = graphGroup.get(0); writer.write("Date"); writer.write((int) '\t'); writer.write(graph0.getXName()); for (DiagramGraph graph : graphGroup) { writer.write((int) '\t'); writer.write(graph.getYName()); } writer.write((int) '\n'); int numValues = graph0.getNumValues(); for (int i = 0; i < numValues; i++) { writer.write(toDate(graph0.getXValueAt(i))); writer.write((int) '\t'); writer.write(String.valueOf(graph0.getXValueAt(i))); for (DiagramGraph graph : graphGroup) { writer.write((int) '\t'); writer.write(String.valueOf(graph.getYValueAt(i))); } writer.write((int) '\n'); } }
private void assertEqualGraphs(DiagramGraph expectedGraph, DiagramGraph actualGraph) { assertNotNull(actualGraph); assertEquals(expectedGraph.getXName(), actualGraph.getXName()); assertEquals(expectedGraph.getYName(), actualGraph.getYName()); assertEquals(expectedGraph.getNumValues(), actualGraph.getNumValues()); for (int i = 0; i < expectedGraph.getNumValues(); i++) { assertEquals(expectedGraph.getXValueAt(i), actualGraph.getXValueAt(i), 1e-10); assertEquals(expectedGraph.getYValueAt(i), actualGraph.getYValueAt(i), 1e-10); } }