Package com.vaadin.addon.timeline.gwt.client.VCanvasPlotter

Examples of com.vaadin.addon.timeline.gwt.client.VCanvasPlotter.Graph


            markerTooltip.setVisible(true);
            return;
        }

        for (int g = 0; g < currentGraphs.size(); g++) {
            Graph graph = currentGraphs.get(g);

            if (!widget.graphIsVisible(g) || graph.getPoints().size() == 0) {
                continue;
            }

            List<Point> points = graph.getPoints();

            // Search for index of the closes point
            float minDiff = 10000000f;
            int pointIndex = 0;
            Point p;
            for (int i = 0; i < points.size(); i++) {
                p = points.get(i);
                if (p.x < 0 || p.x > canvas.getWidth()) {
                    continue;
                }

                float diff = Math.abs(x - p.x);
                if (currentMode == PlotMode.BAR) {
                    // Barchart renders to the left of the point so we have to
                    // adjust
                    diff = Math.abs(x - (p.x - p.width / 2f));
                }

                if (diff < minDiff) {
                    minDiff = diff;
                    pointIndex = i;
                }
            }

            // Retrieve the selected point
            p = points.get(pointIndex);
            if (dots.size() > g) {
                HTML dot = dots.get(g);
                dot.setVisible(true);
                if (widget.isGraphsStacked()) {
                    float pSum = 0;
                    for (int j = 0; j < g; j++) {
                        Graph graph2 = currentGraphs.get(j);
                        Point q = graph2.getPoints().get(pointIndex);
                        if (q != null) {
                            pSum += q.y - getCurrentZeroCoordinate();
                        }
                    }
View Full Code Here


        plotter.setZeroLevel(currentZeroCoordinate);

        // Create the rendering graphs
        List<Graph> graphs = new ArrayList<Graph>();
        for (int g = 0; g < widget.getNumGraphs(); g++) {
            Graph graph = new Graph();
            double fillalpha = 0;
            double alpha = 0;

            // Set Fill color
            List<Integer> fillcolors = getFillColors(g);
            if (fillcolors != null && fillcolors.size() == 4) {
                fillalpha = fillcolors.get(3) / 255.0;
                graph.setFillColor("rgba(" + fillcolors.get(0) + ","
                        + fillcolors.get(1) + "," + fillcolors.get(2) + ","
                        + fillalpha + ")");
            } else {
                VConsole.error("Could not plot graph " + g
                        + " since fill color is missing");
                continue;
            }

            // Set color
            List<Integer> colors = getColors(g);
            if (colors != null && colors.size() == 4) {
                alpha = colors.get(3) / 255.0;
                graph.setColor("rgba(" + colors.get(0) + "," + colors.get(1)
                        + "," + colors.get(2) + "," + alpha + ")");
            } else {
                VConsole.error("Could not plot graph " + g
                        + " since color is missing");
                continue;
            }

            if (fillalpha == 0 && alpha == 0) {
                // Graph is invisible, ignore drawing it
                continue;
            }

            // Set line thickness
            graph.setLineThickness(getLineThickness(g));

            // Set line caps
            graph.setLinecaps(getLineCaps(g));

            // Normalize values
            List<Float> normalizedValues = pointValues.get(g);

            // Add points to graph
            List<Date> dates = pointDates.get(g);
            if (dates != null && dates.size() > 0) {
                Date startDate = dates.get(0);
                Long timeFromStart = startDate.getTime() - startTime;
                float lastX = 0;
                int lastWidth = 0;
                for (int i = 0; i < normalizedValues.size(); i++) {
                    Float value = normalizedValues.get(i);
                    Date date = dates.get(i);
                    timeFromStart = date.getTime() - startTime;

                    float y = currentZeroCoordinate - value * yUnit;
                    float x = timeFromStart * xUnit;

                    Point p;
                    if (normalizedValues.size() == 1) {
                        /*
                         * Special behaviour for a graph with one point since we
                         * cannot calculate the width for it
                         */
                        p = new Point(Math.round(x), Math.round(y), graph, 1,
                                value);
                        lastWidth = 1;

                    } else if (i == 0) {
                        /*
                         * Setting width for the first point to zero
                         */
                        Date d = dates.get(1);
                        timeFromStart = d.getTime() - startTime;
                        lastWidth = 0;
                        p = new Point(Math.round(x), Math.round(y), graph,
                                lastWidth, value);

                    } else {
                        /*
                         * Other points calculate backwards
                         */
                        if (getPlotMode() == PlotMode.BAR) {
                            // MT 22.3.2013: I have no idea why some points are
                            // ignored. Without this bars get totally messed,
                            // but without essential points may be dropped in
                            // lines (no 1 priority)
                            int diff = Math.round(x - lastX);
                            if (diff > 2) {
                                lastWidth = diff;
                                p = new Point(Math.round(x), Math.round(y),
                                        graph, lastWidth, value);
                            } else {
                                p = null;
                            }
                        } else {
                            p = new Point(Math.round(x), Math.round(y), graph,
                                    lastWidth, value);
                        }

                    }
                    if (p != null) {
                        graph.addPoint(p);
                        lastX = x;
                    }
                }
            }

View Full Code Here

TOP

Related Classes of com.vaadin.addon.timeline.gwt.client.VCanvasPlotter.Graph

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.