Search in sources :

Example 1 with GraphedCartFunction

use of doc_gui.graph.GraphedCartFunction in project OpenNotebook by jaltekruse.

the class GraphObjectGUI method drawMathObject.

public void drawMathObject(GraphObject object, Graphics g, Point pageOrigin, float zoomLevel) {
    ScaledSizeAndPosition sap = getSizeAndPosition(object, pageOrigin, zoomLevel);
    graph.removeAllSingleGraphs();
    graph.removeAllPoints();
    int colorIndex = 0;
    boolean hadError = false;
    for (StringAttribute ex : object.getExpressions()) {
        if (!ex.getValue().equals("")) {
            try {
                graph.AddGraph(new GraphedCartFunction(graph, "y=" + ex.getValue(), "x", "y", true, graphColors[colorIndex]));
            } catch (NodeException e) {
                // TODO Auto-generated catch block
                hadError = true;
            }
        }
        colorIndex++;
    }
    //graph.lineGraph.linePoints = object.getPoints();
    graph.lineGraph.linePoints.removeAllElements();
    graph.removeAllPoints();
    for (GridPointAttribute pt : object.getPoints()) {
        if (pt != null) {
            graph.addPoint(pt.getValue().getx(), pt.getValue().gety());
        }
    }
    graph.barGraph.values.removeAllElements();
    for (DoubleAttribute d : object.getBarGraphValues().getValues()) {
        graph.barGraph.values.add(d.getValue());
    }
    graph.barGraph.labels.removeAllElements();
    for (StringAttribute strAttr : object.getBarGraphLabels().getValues()) {
        graph.barGraph.labels.add(strAttr.getValue());
    }
    graph.barGraph.groupSize = object.getBarGraphGroupSize();
    graph.lineGraph.setColor(object.getLineGraphColor());
    synchronized (object.getLineGraphPoints().getValues()) {
        for (GridPointAttribute pt : object.getLineGraphPoints().getValues()) {
            if (pt != null) {
                graph.lineGraph.linePoints.add(new GridPoint(pt.getValue().getx(), pt.getValue().gety()));
            }
        }
    }
    graph.repaint(g, sap.getWidth(), sap.getHeight(), zoomLevel, sap.getxOrigin(), sap.getyOrigin(), object);
    if (hadError) {
        FontMetrics fm = g.getFontMetrics();
        int errorWidth = fm.stringWidth("error");
        g.setColor(Color.WHITE);
        g.fillRect((sap.getxOrigin() + sap.getWidth() / 2) - errorWidth / 2, (sap.getyOrigin() + sap.getHeight() / 2) - fm.getHeight() / 2, errorWidth + 4, fm.getHeight() + 4);
        g.setColor(Color.BLACK);
        g.drawRect((sap.getxOrigin() + sap.getWidth() / 2) - errorWidth / 2, (sap.getyOrigin() + sap.getHeight() / 2) - fm.getHeight() / 2, errorWidth + 4, fm.getHeight() + 4);
        g.setColor(Color.RED);
        g.drawString("error", (sap.getxOrigin() + sap.getWidth() / 2) - errorWidth / 2 + 2, (sap.getyOrigin() + sap.getHeight() / 2) + fm.getHeight() / 2);
    }
}
Also used : GridPoint(doc.GridPoint) FontMetrics(java.awt.FontMetrics) GridPointAttribute(doc.attributes.GridPointAttribute) StringAttribute(doc.attributes.StringAttribute) NodeException(expression.NodeException) GraphedCartFunction(doc_gui.graph.GraphedCartFunction) Point(java.awt.Point) GridPoint(doc.GridPoint) DoubleAttribute(doc.attributes.DoubleAttribute)

Aggregations

GridPoint (doc.GridPoint)1 DoubleAttribute (doc.attributes.DoubleAttribute)1 GridPointAttribute (doc.attributes.GridPointAttribute)1 StringAttribute (doc.attributes.StringAttribute)1 GraphedCartFunction (doc_gui.graph.GraphedCartFunction)1 NodeException (expression.NodeException)1 FontMetrics (java.awt.FontMetrics)1 Point (java.awt.Point)1