public void paintExpression(Graphics g, Expression e, double xmid, double xfactor, double ymid, double yfactor) throws UnresolvedNameException {
        HashMap<String, Double> h = new HashMap<String, Double>();
        double lastX = 0, lastY = 0;
        boolean hasBegan = false;

        for (double x = xbl; x < xbh; x += xscale) {
            h.put("x", Math.round(x / xscale) * xscale);
            double y = e.solve(h);

            //System.out.println("x = "+Math.round(x/xscale)*xscale+", y = "+y);
            if (Double.isInfinite(y) || Double.isInfinite(lastY) || Double.isNaN(y) || Double.isNaN(lastY))
                hasBegan = false;

            if (hasBegan) {
                double xt1 = xmid + x * xfactor, yt1 = ymid - y * yfactor, xt2 = xmid + lastX * xfactor, yt2 = ymid - lastY * yfactor;
                g.drawLine((int)xt1, (int)yt1, (int)xt2, (int)yt2);
            } else
                hasBegan = true;

            lastX = x;
            lastY = y;
        }
    }