Package nz.co.abrahams.asithappens.storage

Examples of nz.co.abrahams.asithappens.storage.SummaryData


        int panelWidth, panelHeight;
        //int pixelInterval;
        double graphTop;
        double value, valueSum;
        boolean graphBreak;
        SummaryData summary;
        DataLabel label;
        int labelWidth, labelHeight, labelPadding;
       
        panelWidth = getWidth();
        panelHeight = getHeight();
        if ( panelWidth != context.getPanelWidth() || panelHeight != context.getPanelHeight() ) {
            logger.debug("Adjusting panel width to " + panelWidth + " and panel height to " + panelHeight);
            context.setPanelWidth(panelWidth);
            context.setPanelHeight(panelHeight);
            context.generateSummaryData();
            revalidate();
        }
        //logger.debug("Painting TimeSeriesDataPanel: panelWidth=" + panelWidth + " panelHeight=" + panelHeight);
       
        summary = context.getSummaryData();
        if ( summary == null )
            return;
       
        graphTop = context.getGraphTop();
        xOffset = panelWidth - summary.getNumberOfPoints();
        g.clearRect(0, 0, panelWidth - 1, panelHeight - 1);
       
        // Draw grid markings if behind
        if ( context.horizontalGridLines() && ! context.linesInFront() ) {
            drawHorizontalGridLines(g, panelWidth, panelHeight);
        }
        if ( context.verticalGridLines() && ! context.linesInFront() ) {
            drawVerticalGridLines(g, summary, panelWidth, panelHeight);
        }
       
        if ( context.getSetsPositioning() == SetDisplay.Positioning.Grounded ) {
           
            for ( set = 0 ; set < summary.getNumberOfSets() ; set++ ) {
                if ( context.getSetDisplayStyle(set) == SetDisplay.Style.Fill ) {
                    g.setColor(context.getSetDisplayColor(set));
                    for ( point = 0 ; point < summary.getNumberOfPoints() ; point++ ) {
                        x = xOffset + point;
                        value = summary.getValue(set, point);
                        if ( ! Double.isNaN(value) ) {
                            y = (int)(panelHeight - 1 - panelHeight * value / graphTop);
                            g.drawLine(x, panelHeight - 1, x, y);
                        }
                    }
                }
            }
           
            for ( set = 0 ; set < summary.getNumberOfSets() ; set++ ) {
                if ( context.getSetDisplayStyle(set) == SetDisplay.Style.Line ) {
                    oldx = xOffset;
                    oldy = (int)(panelHeight - 1 - panelHeight * summary.getValue(set, 0) / graphTop);
                    graphBreak = false;
                    g.setColor(context.getSetDisplayColor(set));
                    for ( point = 0 ; point < summary.getNumberOfPoints() ; point++ ) {
                        x = xOffset + point;
                        value = summary.getValue(set, point);
                        if ( ! Double.isNaN(value) ) {
                            y = (int)(panelHeight - 1 - panelHeight * value / graphTop);
                            if ( ! graphBreak )
                                g.drawLine(oldx, oldy, x, y);
                            else {
                                g.drawLine(x, y, x, y);
                                graphBreak = false;
                            }
                            oldx = x;
                            oldy = y;
                        } else
                            graphBreak = true;
                    }
                }
            }
        } else if ( context.getSetsPositioning() == SetDisplay.Positioning.Stacked ) {
           
            for ( point = 0 ; point < summary.getNumberOfPoints() ; point++ ) {
                valueSum = 0;
                for ( set = 0 ; set < summary.getNumberOfSets() ; set++ ) {
                    g.setColor(context.getSetDisplayColor(set));
                    x = xOffset + point;
                    value = summary.getValue(set, point);
                    if ( ! Double.isNaN(value) ) {
                        oldy = (int)(panelHeight - 1 - valueSum * panelHeight / graphTop);
                        valueSum += value;
                        y = (int)(panelHeight - 1 - valueSum * panelHeight / graphTop);
                        if ( value > 0 )
                            g.drawLine(x, oldy, x, y);
                       
                    }
                }
            }
        }
       
        if ( context.horizontalGridLines() && context.linesInFront() ) {
            drawHorizontalGridLines(g, panelWidth, panelHeight);
        }
        if ( context.verticalGridLines() && context.linesInFront() ) {
            drawVerticalGridLines(g, summary, panelWidth, panelHeight);
        }
       
        // Draw labels
        if ( context.getShowLabels() ) {
            g.setColor(Color.BLACK);
            for ( i = 0; i < context.getData().getLabels().getLabelCount() ; i++ ) {
                label = context.getData().getLabels().getLabel(i);
                x = context.getXPixelFromTime(label.getTime());
                y = context.getYPixelFromValue(label.getValue());
                if ( label.getTime() > summary.getOriginTime(panelWidth) && label.getTime() < summary.getLastTime() ) {
                    if ( label.getValue() < context.getGraphTop() ) {
                        labelWidth = g.getFontMetrics().stringWidth(label.getLabel());
                        //labelHeight = g.getFontMetrics().getAscent() + g.getFontMetrics().getDescent();
                        labelHeight = g.getFontMetrics().getAscent();
                        //labelPadding = g.getFontMetrics().getLeading();
View Full Code Here


        String unitLabel;
        GregorianCalendar calendar;
        SimpleDateFormat timeFormat, dateFormat;
        Font labelFont;
        long longTime;
        SummaryData summary;
        double pixelInterval;
       
        //panelWidth = context.getPanelWidth();
        panelWidth = getWidth();
        panelHeight = getHeight();
        if ( panelWidth != context.getPanelWidth() ) {
            logger.info("Creating new data summary: x-axis panel width (" + panelWidth + ") does not equal graph panel width (" + context.getPanelWidth() + ")");
            context.setPanelWidth(panelWidth);
            context.generateSummaryData();
            revalidate();
        }
        g.drawLine(0, 0, panelWidth - 1, 0);
       
        summary = context.getSummaryData();
        if ( summary == null )
            return;
       
        if ( context.getXAxisUnits() == 's' ) {
            timeFormat = TimeSeriesContext.TIME_FORMAT_SECONDS;
            //labelFont = FONT_SECONDS;
            g.setFont(FONT_SECONDS);
        }
        else {
            timeFormat = TimeSeriesContext.TIME_FORMAT_MINUTES;
            //labelFont = FONT_MINUTES;
            g.setFont(FONT_MINUTES);
        }
       
        //dateFormat = TimeSeriesContext.DATE_FORMAT;
        calendar = new GregorianCalendar();
       
        pixelInterval = context.findTimeInMillis(context.getXAxisInterval(), context.getXAxisUnits()) / summary.getPixelTime();
        if ( context.getXAxisAbsoluteTimes() == true ) {
            i = 0;
            xMajor = 0;
            while ( xMajor < panelWidth ) {
                longTime = (long)(summary.getOriginTime(panelWidth) - context.getXAxisOriginOffset() + (i * TimeSeriesContext.findTimeInMillis(context.getXAxisInterval(), context.getXAxisUnits())));
                calendar.setTimeInMillis(longTime);
                unitLabel = timeFormat.format(calendar.getTime());
                if ( unitLabel.equals("0:00") )
                    unitLabel = TimeSeriesContext.DATE_FORMAT.format(calendar.getTime());
                xMajor = (int)(pixelInterval * i - context.getXAxisOriginOffset() / summary.getPixelTime());
                g.drawLine(xMajor, 0, xMajor, Configuration.getPropertyInt("graph.axis.x.marking.major.height"));
                g.drawString(unitLabel, xMajor - ( g.getFontMetrics().stringWidth(unitLabel) / 2), Configuration.getPropertyInt("graph.axis.x.marking.label.offset") + g.getFontMetrics().getHeight());
                for ( int line = 1; line < context.getXAxisMinorMarks(); line++ ) {
                    xMinor = xMajor + (int)(line * pixelInterval / context.getXAxisMinorMarks());
                    g.drawLine(xMinor, 0, xMinor, Configuration.getPropertyInt("graph.axis.x.marking.minor.height"));
View Full Code Here

        int panelWidth, panelHeight;
        //int pixelInterval;
        double graphTop;
        double value, valueSum;
        boolean graphBreak;
        SummaryData summary;
        DataLabel label;
        int labelWidth, labelHeight, labelPadding;
        FragmentedColumn fragmentedColumn;
        int centerX;
        int centerY;
        String textString;
       
        panelWidth = getWidth();
        panelHeight = getHeight();
        if ( panelWidth != context.getPanelWidth() || panelHeight != context.getPanelHeight() ) {
            logger.debug("Adjusting panel width to " + panelWidth + " and panel height to " + panelHeight);
            context.setPanelWidth(panelWidth);
            context.setPanelHeight(panelHeight);
            context.generateSummaryData();
            revalidate();
        }
       
        synchronized(context.getData()) {
            //logger.debug("Painting TimeSeriesDataPanel: panelWidth=" + panelWidth + " panelHeight=" + panelHeight);
            synchronized(context.getSummarySemaphore()) {
               
                synchronized(game.getLandscape()) {
                   
                    summary = context.getSummaryData();
                    if ( summary == null )
                        return;
                   
                    graphTop = context.getGraphTop();
                    xOffset = panelWidth - summary.getNumberOfPoints();
                    g.clearRect(0, 0, panelWidth - 1, panelHeight - 1);
                   
                    // Draw grid markings if behind
                    if ( context.horizontalGridLines() && ! context.linesInFront() ) {
                        drawHorizontalGridLines(g, panelWidth, panelHeight);
                    }
                    if ( context.verticalGridLines() && ! context.linesInFront() ) {
                        drawVerticalGridLines(g, summary, panelWidth, panelHeight);
                    }
                   
                    if ( context.getSetsPositioning() == SetDisplay.Positioning.Grounded ) {
                        // not supported
                    } else if ( context.getSetsPositioning() == SetDisplay.Positioning.Stacked ) {
                       
                        for ( point = 0 ; point < summary.getNumberOfPoints() ; point++ ) {
                            x = xOffset + point;
                            fragmentedColumn = game.getLandscape().getFragmentedColumnAt(x);
                           
                            if ( fragmentedColumn == null || fragmentedColumn.size() == 0 ) {
                               
                                valueSum = 0;
                                for ( set = 0 ; set < summary.getNumberOfSets() ; set++ ) {
                                    g.setColor(context.getSetDisplayColor(set));
                                    value = summary.getValue(set, point);
                                    if ( ! Double.isNaN(value) ) {
                                        oldy = (int)(panelHeight - 1 - valueSum * panelHeight / graphTop);
                                        valueSum += value;
                                        y = (int)(panelHeight - 1 - valueSum * panelHeight / graphTop);
                                        if ( value > 0 )
                                            g.drawLine(x, oldy, x, y);
                                       
                                    }
                                }
                            }
                            // column is fragmented
                            else {
                                int fragmentNumber;
                                double fragmentTop;
                                Fragment fragment;
                                int startY;
                                int endY;
                                double partOfLine;
                                double initialOffset;
                               
                                valueSum = 0;
                                fragmentNumber = 0;
                                fragment = fragmentedColumn.elementAt(fragmentNumber);
                                fragmentTop = fragment.getLength();
                                startY = 0;
                                initialOffset = 0;
                               
                                for ( set = 0 ; set < summary.getNumberOfSets() ; set++ ) {
                                    g.setColor(context.getSetDisplayColor(set));
                                    value = summary.getValue(set, point);
                                    partOfLine = value;
                                    if ( ! Double.isNaN(value) ) {
                                        while ( fragmentTop < initialOffset + partOfLine && fragmentNumber < fragmentedColumn.size() ) {
                                            //startY = (int)(panelHeight - 1 - ( ( fragment.getPosition() + initialOffset ) * panelHeight / graphTop ) );
                                            //endY = (int)(panelHeight - 1 - ( ( fragment.getPosition() + fragment.getLength() ) * panelHeight / graphTop) );
                                            startY = context.getYPixelFromValue(fragment.getPosition() + initialOffset);
                                            endY = context.getYPixelFromValue(fragment.getPosition() + fragment.getLength() );
                                            g.drawLine(x, startY, x, endY);
                                            partOfLine -= (fragment.getLength() - initialOffset);
                                            initialOffset = 0;
                                            fragmentNumber++;
                                            // Fix: Next line sometimes throws an ArrayIndexOutOfBoundsException
                                            if ( fragmentNumber < fragmentedColumn.size() ) {
                                                fragment = fragmentedColumn.elementAt(fragmentNumber);
                                                fragmentTop = fragment.getLength();
                                            }
                                        }
                                        //startY = (int)(panelHeight - 1 - ( ( fragment.getPosition() + initialOffset ) * panelHeight / graphTop ) );
                                        //endY = (int)(panelHeight - 1 - ( ( fragment.getPosition() + initialOffset + partOfLine ) * panelHeight / graphTop) );
                                        startY = context.getYPixelFromValue(fragment.getPosition() + initialOffset);
                                        endY = context.getYPixelFromValue(fragment.getPosition() + initialOffset + partOfLine);
                                        g.drawLine(x, startY, x, endY);
                                        initialOffset += partOfLine;
                                        //oldy = (int)(panelHeight - 1 - valueSum * panelHeight / graphTop);
                                        //valueSum += value;
                                        //y = (int)(panelHeight - 1 - valueSum * panelHeight / graphTop);
                                        //if ( value > 0 || set == 0 )
                                        //    g.drawLine(x, oldy, x, y);
                                       
                                    }
                                }
                            }
                        }
                    }
                   
                    if ( context.horizontalGridLines() && context.linesInFront() ) {
                        drawHorizontalGridLines(g, panelWidth, panelHeight);
                    }
                    if ( context.verticalGridLines() && context.linesInFront() ) {
                        drawVerticalGridLines(g, summary, panelWidth, panelHeight);
                    }
                   
                    // Draw labels
                    if ( context.getShowLabels() ) {
                        g.setColor(Color.BLACK);
                        for ( int i = 0; i < context.getData().getLabels().getLabelCount() ; i++ ) {
                            label = context.getData().getLabels().getLabel(i);
                            x = context.getXPixelFromTime(label.getTime());
                            y = context.getYPixelFromValue(label.getValue());
                            if ( label.getTime() > summary.getOriginTime(panelWidth) && label.getTime() < summary.getLastTime() ) {
                                if ( label.getValue() < context.getGraphTop() ) {
                                    labelWidth = g.getFontMetrics().stringWidth(label.getLabel());
                                    //labelHeight = g.getFontMetrics().getAscent() + g.getFontMetrics().getDescent();
                                    labelHeight = g.getFontMetrics().getAscent();
                                    //labelPadding = g.getFontMetrics().getLeading();
View Full Code Here

TOP

Related Classes of nz.co.abrahams.asithappens.storage.SummaryData

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.