Example usage for org.jfree.chart.plot Marker setLabel

List of usage examples for org.jfree.chart.plot Marker setLabel

Introduction

In this page you can find the example usage for org.jfree.chart.plot Marker setLabel.

Prototype

public void setLabel(String label) 

Source Link

Document

Sets the label (if null no label is displayed) and sends a MarkerChangeEvent to all registered listeners.

Usage

From source file:org.gwaspi.gui.reports.ManhattanPlotZoom.java

private JFreeChart createChart(XYDataset dataset, ChromosomeKey chr) {
    JFreeChart chart = ChartFactory.createScatterPlot(null, "", "P value", dataset, PlotOrientation.VERTICAL,
            true, false, false);/*from   w ww  .j ava 2  s  . c o m*/

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setNoDataMessage("NO DATA");
    plot.setDomainZeroBaselineVisible(true);
    plot.setRangeZeroBaselineVisible(true);

    // CHART BACKGROUD COLOR
    chart.setBackgroundPaint(Color.getHSBColor(0.1f, 0.1f, 1.0f)); // Hue, saturation, brightness
    plot.setBackgroundPaint(manhattan_back); // Hue, saturation, brightness 9

    // GRIDLINES
    plot.setDomainGridlineStroke(new BasicStroke(0.0f));
    plot.setDomainMinorGridlineStroke(new BasicStroke(0.0f));
    plot.setDomainGridlinePaint(manhattan_back.darker().darker()); // Hue, saturation, brightness 7
    plot.setDomainMinorGridlinePaint(manhattan_back); // Hue, saturation, brightness 9
    plot.setRangeGridlineStroke(new BasicStroke(0.0f));
    plot.setRangeMinorGridlineStroke(new BasicStroke(0.0f));
    plot.setRangeGridlinePaint(manhattan_back.darker().darker()); // Hue, saturation, brightness 7
    plot.setRangeMinorGridlinePaint(manhattan_back.darker()); // Hue, saturation, brightness 8

    plot.setDomainMinorGridlinesVisible(true);
    plot.setRangeMinorGridlinesVisible(true);

    // DOTS RENDERER
    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
    renderer.setSeriesPaint(0, manhattan_dot);
    //      renderer.setSeriesOutlinePaint(0, Color.DARK_GRAY);
    //      renderer.setUseOutlinePaint(true);
    // Set dot shape of the currently appended Series
    renderer.setSeriesShape(0, new Rectangle2D.Double(0.0, 0.0, 2, 2));

    renderer.setSeriesVisibleInLegend(0, false);

    NumberAxis positionAxis = (NumberAxis) plot.getDomainAxis();
    //      domainAxis.setAutoRangeIncludesZero(false);
    //      domainAxis.setTickMarkInsideLength(2.0f);
    //      domainAxis.setTickMarkOutsideLength(2.0f);
    //      domainAxis.setMinorTickCount(2);
    //      domainAxis.setMinorTickMarksVisible(true);
    positionAxis.setLabelAngle(1.0);
    positionAxis.setAutoRangeIncludesZero(false);
    positionAxis.setAxisLineVisible(true);
    positionAxis.setTickLabelsVisible(true);
    positionAxis.setTickMarksVisible(true);

    // ADD INVERSE LOG(10) Y AXIS
    LogAxis logPAxis = new LogAxis("P value");
    logPAxis.setBase(10);
    logPAxis.setInverted(true);
    logPAxis.setNumberFormatOverride(GenericReportGenerator.FORMAT_P_VALUE);

    logPAxis.setTickMarkOutsideLength(2.0f);
    logPAxis.setMinorTickCount(2);
    logPAxis.setMinorTickMarksVisible(true);
    logPAxis.setAxisLineVisible(true);
    logPAxis.setUpperMargin(0);

    TickUnitSource units = NumberAxis.createIntegerTickUnits();
    logPAxis.setStandardTickUnits(units);
    plot.setRangeAxis(0, logPAxis);

    // Add significance Threshold to subplot
    //threshold = 0.5/rdMatrixMetadata.getMarkerSetSize();  // (0.05/10? SNPs => 5*10-?)
    final Marker thresholdLine = new ValueMarker(threshold);
    thresholdLine.setPaint(Color.red);
    // Add legend to threshold
    thresholdLine.setLabel("P = " + GenericReportGenerator.FORMAT_P_VALUE.format(threshold));
    thresholdLine.setLabelAnchor(RectangleAnchor.TOP_RIGHT);
    thresholdLine.setLabelTextAnchor(TextAnchor.BOTTOM_RIGHT);
    plot.addRangeMarker(thresholdLine);

    // Marker label if below threshold
    XYItemRenderer lblRenderer = plot.getRenderer();

    // THRESHOLD AND SELECTED LABEL GENERATOR
    MySeriesItemLabelGenerator lblGenerator = new MySeriesItemLabelGenerator(threshold, chr);
    lblRenderer.setSeriesItemLabelGenerator(0, lblGenerator);
    lblRenderer.setSeriesItemLabelFont(0, new Font("SansSerif", Font.PLAIN, 12));
    lblRenderer.setSeriesPositiveItemLabelPosition(0, new ItemLabelPosition(ItemLabelAnchor.CENTER,
            TextAnchor.TOP_LEFT, TextAnchor.BOTTOM_LEFT, Math.PI / 4.0));

    // TOOLTIP GENERATOR
    MyXYToolTipGenerator tooltipGenerator = new MyXYToolTipGenerator(chr);

    lblRenderer.setBaseToolTipGenerator(tooltipGenerator);

    lblRenderer.setSeriesItemLabelsVisible(0, true);

    return chart;
}

From source file:net.liuxuan.device.VACVBS.JIF_DrawChart_vacvbs.java

private void chartDrawHerizonLine(VACVBSMetaData data, Color color, String Labelstr) {
    XYPlot plot = (XYPlot) chartPanel.getChart().getPlot();
    final Marker start = new ValueMarker(0);
    start.setPaint(color);//from  www. j a  v a2  s  .c o m
    start.setLabel(Labelstr);
    start.setLabelAnchor(RectangleAnchor.BOTTOM_LEFT);
    start.setLabelTextAnchor(TextAnchor.TOP_LEFT);
    start.setLabelPaint(color);
    plot.addRangeMarker(start);
}

From source file:net.liuxuan.device.VACVBS.JIF_DrawChart_vacvbs.java

private void chartDrawVerticalLine(VACVBSMetaData data, Color color, String Labelstr) {
    XYPlot plot = (XYPlot) chartPanel.getChart().getPlot();
    final Marker start = new ValueMarker(data.date1.getTime());
    start.setPaint(color);/* w w  w  . j  a  va  2 s.c  o  m*/
    start.setLabel(Labelstr);
    start.setLabelAnchor(RectangleAnchor.TOP_LEFT);
    start.setLabelTextAnchor(TextAnchor.TOP_LEFT);
    start.setLabelPaint(color);
    plot.addDomainMarker(start);
}

From source file:org.jfree.chart.demo.DifferenceChartDemo2.java

/**
 * Creates a chart.//from w  ww.  ja v a  2  s.  c  om
 * 
 * @param dataset  the dataset.
 * 
 * @return The chart.
 */
private JFreeChart createChart(final XYDataset dataset) {
    final JFreeChart chart = ChartFactory.createTimeSeriesChart("Daylight Hours - London, UK", "Date", "Time",
            dataset, true, // legend
            true, // tool tips
            false // URLs
    );
    chart.setBackgroundPaint(Color.white);

    final XYDifferenceRenderer renderer = new XYDifferenceRenderer(Color.blue, Color.blue, false);
    renderer.setStroke(new BasicStroke(2.0f));
    renderer.setSeriesPaint(0, Color.yellow);
    renderer.setSeriesPaint(1, Color.red);
    final XYPlot plot = chart.getXYPlot();
    plot.setRenderer(renderer);
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    //        plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0));

    final DateAxis domainAxis = new DateAxis("Time");
    domainAxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE);
    domainAxis.setLowerMargin(0.0);
    domainAxis.setUpperMargin(0.0);
    plot.setDomainAxis(domainAxis);
    plot.setForegroundAlpha(0.5f);

    final Color c = new Color(255, 60, 24, 63);
    final Marker bst = new IntervalMarker(new Day(28, 3, 2004).getFirstMillisecond(),
            new Day(30, 10, 2004).getFirstMillisecond(), c, new BasicStroke(2.0f), null, null, 1.0f);
    bst.setLabel("British Summer Time");
    bst.setLabelAnchor(RectangleAnchor.BOTTOM_RIGHT);
    bst.setLabelFont(new Font("SansSerif", Font.ITALIC + Font.BOLD, 10));
    bst.setLabelTextAnchor(TextAnchor.BASELINE_RIGHT);
    plot.addDomainMarker(bst, Layer.BACKGROUND);

    final DateAxis rangeAxis = new DateAxis("Time");
    rangeAxis.setLowerMargin(0.15);
    rangeAxis.setUpperMargin(0.15);
    plot.setRangeAxis(rangeAxis);
    return chart;
}

From source file:net.liuxuan.device.w3330.JIF_DrawChart_w3330.java

private void chartDrawHerizonLine(W3330MetaData data, Color color, String Labelstr) {
    XYPlot plot = (XYPlot) chartPanel.getChart().getPlot();
    final Marker start = new ValueMarker(data.zero);
    start.setPaint(color);/* w ww .ja  va  2  s.c o m*/
    start.setLabel(Labelstr);
    start.setLabelAnchor(RectangleAnchor.BOTTOM_LEFT);
    start.setLabelTextAnchor(TextAnchor.TOP_LEFT);
    start.setLabelPaint(color);
    plot.addRangeMarker(start);
}

From source file:net.liuxuan.device.w3330.JIF_DrawChart_w3330.java

private void chartDrawVerticalLine(W3330MetaData data, Color color, String Labelstr) {
    XYPlot plot = (XYPlot) chartPanel.getChart().getPlot();
    final Marker start = new ValueMarker(data.time.getTime());
    start.setPaint(color);//from  w  ww .  j  av  a 2s . co  m
    start.setLabel(Labelstr);
    start.setLabelAnchor(RectangleAnchor.TOP_LEFT);
    start.setLabelTextAnchor(TextAnchor.TOP_LEFT);
    start.setLabelPaint(color);
    plot.addDomainMarker(start);
}

From source file:no.met.jtimeseries.chart.ChartPlotter.java

public void addDomainMarkers(Date start, Date stop, TimeZone timeZone, Locale locale) {
    if (!addedDomainMarkers) {
        //make a one hour by one hour time list
        //The reason is that not all the data are hour by hour
        //domainMarkers will not mark labels when no date at clock 00:00

        List<Date> time = getTimeHourByHour(start, stop);
        // set the markers
        Map<Long, String> domainMarkers = getDomainMarkersWithLabel(time, timeZone, locale);
        for (Map.Entry<Long, String> entry : domainMarkers.entrySet()) {
            Long timeInMilli = entry.getKey();
            String label = entry.getValue();
            final Marker originalEnd = new ValueMarker(timeInMilli);
            originalEnd.setPaint(Color.DARK_GRAY);
            originalEnd.setStroke(new BasicStroke(1.0f));
            originalEnd.setLabel(label);//Arial Hebrew, SansSerif
            originalEnd.setLabelFont(new Font("Arial", Font.PLAIN, 14));
            originalEnd.setLabelAnchor(RectangleAnchor.TOP_RIGHT);
            originalEnd.setLabelTextAnchor(TextAnchor.TOP_LEFT);
            plot.addDomainMarker(originalEnd, Layer.BACKGROUND);
            setAddedDomainMarkers(true);
        }//from  w ww  .j  ava  2s.c  om

    }
}

From source file:ch.algotrader.client.chart.ChartTab.java

private void initMarker(SeriesDefinitionVO seriesDefinition) {

    final MarkerDefinitionVO markerDefinition = (MarkerDefinitionVO) seriesDefinition;

    final Marker marker;
    if (markerDefinition.isInterval()) {
        marker = new IntervalMarker(0, 0);
        marker.setLabelAnchor(RectangleAnchor.BOTTOM_RIGHT); // position of the label
        marker.setLabelTextAnchor(TextAnchor.BOTTOM_RIGHT); // position of the text within the label
    } else {/*from w  w  w.j  a  va  2s.c  om*/
        marker = new ValueMarker(0);
        marker.setLabelAnchor(RectangleAnchor.TOP_RIGHT);
        marker.setLabelTextAnchor(TextAnchor.BOTTOM_RIGHT);
    }

    marker.setPaint(getColor(markerDefinition.getColor()));
    marker.setLabel(markerDefinition.getLabel());
    marker.setLabelFont(new Font("SansSerif", 0, 9));

    if (seriesDefinition.isDashed()) {
        marker.setStroke(new BasicStroke(1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f,
                new float[] { 5.0f }, 0.0f));
    } else {
        marker.setStroke(new BasicStroke(1.0f));
    }

    getPlot().addRangeMarker(marker, markerDefinition.isInterval() ? Layer.BACKGROUND : Layer.FOREGROUND);

    this.markers.put(markerDefinition.getName(), marker);
    this.markersSelectionStatus.put(markerDefinition.getName(), seriesDefinition.isSelected());

    // add the menu item
    JCheckBoxMenuItem menuItem = new JCheckBoxMenuItem(seriesDefinition.getLabel());
    menuItem.setSelected(seriesDefinition.isSelected());
    menuItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            resetAxis();
            boolean selected = ((JCheckBoxMenuItem) e.getSource()).isSelected();
            ChartTab.this.markersSelectionStatus.put(markerDefinition.getName(), selected);
            if (selected) {
                if (marker instanceof ValueMarker) {
                    marker.setAlpha(1.0f);
                } else {
                    marker.setAlpha(0.5f);
                }
            } else {
                marker.setAlpha(0);
            }
            initAxis();
        }
    });
    this.getPopupMenu().add(menuItem);
}

From source file:lu.lippmann.cdb.ext.hydviga.ui.GapFillingFrame.java

private GapFillingCase refresh(final Algo algo, final int[] indexesOfUsedSeries, final boolean hideOthers,
        final boolean showError, final boolean zoom, final boolean showEnvelope, final boolean multAxis)
        throws Exception {
    if (!inBatchMode)
        this.centerPanel.removeAll();

    int[] arr = new int[] { attr.index(), dateIdx };
    for (final int iii : indexesOfUsedSeries) {
        arr = ArraysUtil.concat(arr, new int[] { dataSet.attribute(this.attrNames.get(iii)).index() });
    }/*ww w.ja  va2 s . c  om*/

    Instances filteredDs = WekaDataProcessingUtil.buildFilteredByAttributesDataSet(dataSet, arr);
    //System.out.println(filteredDs.toSummaryString());

    Attribute original = null;
    Instances filteredDsWithOriginal = null;
    if (this.isGapSimulated) {
        original = new Attribute("original");
        filteredDsWithOriginal = new Instances(filteredDs);
        filteredDsWithOriginal.insertAttributeAt(original, filteredDsWithOriginal.numAttributes() - 1);
        final Attribute origAttr = filteredDsWithOriginal.attribute(original.name());
        for (int ii = position - 1; ii < position + gapsize + 1; ii++) {
            filteredDsWithOriginal.instance(ii).setValue(origAttr, this.originalDataBeforeGapSimulation[ii]);
        }
    }

    filteredDs = WekaDataProcessingUtil.buildFilteredDataSet(filteredDs, 0, filteredDs.numAttributes() - 1,
            Math.max(0, this.position - this.valuesBeforeAndAfter),
            Math.min(this.position + this.gapsize + this.valuesBeforeAndAfter, filteredDs.numInstances() - 1));

    this.gapFiller = GapFillerFactory.getGapFiller(algo);

    final Instances completedds = this.gapFiller.fillGaps(filteredDs);
    final Instances diff = WekaTimeSeriesUtil.buildDiff(filteredDs, completedds);

    final int valuesToCheckForError = this.valuesBeforeAndAfter / 4;

    double maeByEnlargingGap = Double.NaN;
    double maeByAddingAGapBefore = Double.NaN;
    double maeByAddingAGapAfter = Double.NaN;
    double maeByComparingWithOriginal = Double.NaN;

    double rmseByEnlargingGap = Double.NaN;
    double rmseByAddingAGapBefore = Double.NaN;
    double rmseByAddingAGapAfter = Double.NaN;
    double rmseByComparingWithOriginal = Double.NaN;

    double rsrByEnlargingGap = Double.NaN;
    double rsrByAddingAGapBefore = Double.NaN;
    double rsrByAddingAGapAfter = Double.NaN;
    double rsrByComparingWithOriginal = Double.NaN;

    double pbiasByEnlargingGap = Double.NaN;
    double pbiasByAddingAGapBefore = Double.NaN;
    double pbiasByAddingAGapAfter = Double.NaN;
    double pbiasByComparingWithOriginal = Double.NaN;

    double nsByEnlargingGap = Double.NaN;
    double nsByAddingAGapBefore = Double.NaN;
    double nsByAddingAGapAfter = Double.NaN;
    double nsByComparingWithOriginal = Double.NaN;

    double indexOfAgreementByEnlargingGap = Double.NaN;
    double indexOfAgreementByAddingAGapBefore = Double.NaN;
    double indexOfAgreementByAddingAGapAfter = Double.NaN;
    double indexOfAgreementByComparingWithOriginal = Double.NaN;

    if (this.isGapSimulated) {
        //System.out.println(attr.index()+" begin="+(this.position)+" end="+(this.position+this.gapsize));

        final Instances correctedDataSet = buildCorrectedDataset(diff);

        final double[] cad = correctedDataSet.attributeToDoubleArray(attr.index());
        maeByComparingWithOriginal = MathsUtil.mae(this.originalDataBeforeGapSimulation, cad, this.position,
                this.position + this.gapsize);
        rmseByComparingWithOriginal = MathsUtil.rmse(this.originalDataBeforeGapSimulation, cad, this.position,
                this.position + this.gapsize);
        rsrByComparingWithOriginal = MathsUtil.rsr(this.originalDataBeforeGapSimulation, cad, this.position,
                this.position + this.gapsize);
        pbiasByComparingWithOriginal = MathsUtil.pbias(this.originalDataBeforeGapSimulation, cad, this.position,
                this.position + this.gapsize);
        nsByComparingWithOriginal = MathsUtil.nashSutcliffe(this.originalDataBeforeGapSimulation, cad,
                this.position, this.position + this.gapsize);
        indexOfAgreementByComparingWithOriginal = MathsUtil.indexOfAgreement(
                this.originalDataBeforeGapSimulation, cad, this.position, this.position + this.gapsize);
    } else {
        maeByEnlargingGap = this.gapFiller.evaluateMAEByEnlargingGap(filteredDs, valuesToCheckForError);
        maeByAddingAGapBefore = this.gapFiller.evaluateMAEByAddingAGapBefore(filteredDs, valuesToCheckForError);
        maeByAddingAGapAfter = this.gapFiller.evaluateMAEByAddingAGapAfter(filteredDs, valuesToCheckForError);

        rmseByEnlargingGap = this.gapFiller.evaluateRMSEByEnlargingGap(filteredDs, valuesToCheckForError);
        rmseByAddingAGapBefore = this.gapFiller.evaluateRMSEByAddingAGapBefore(filteredDs,
                valuesToCheckForError);
        rmseByAddingAGapAfter = this.gapFiller.evaluateRMSEByAddingAGapAfter(filteredDs, valuesToCheckForError);

        nsByEnlargingGap = this.gapFiller.evaluateNSByEnlargingGap(filteredDs, valuesToCheckForError);
        nsByAddingAGapBefore = this.gapFiller.evaluateNSByAddingAGapBefore(filteredDs, valuesToCheckForError);
        nsByAddingAGapAfter = this.gapFiller.evaluateNSByAddingAGapAfter(filteredDs, valuesToCheckForError);
    }

    if (hideOthers) {
        if (this.isGapSimulated) {
            filteredDs = WekaDataProcessingUtil.buildFilteredByAttributesDataSet(filteredDsWithOriginal,
                    new int[] { 0, 1, filteredDsWithOriginal.attribute(original.name()).index() });
            filteredDs = WekaDataProcessingUtil.buildFilteredDataSet(filteredDs, 0,
                    filteredDs.numAttributes() - 1, Math.max(0, this.position - this.valuesBeforeAndAfter),
                    Math.min(this.position + this.gapsize + this.valuesBeforeAndAfter,
                            filteredDs.numInstances() - 1));
        } else {
            filteredDs = WekaDataProcessingUtil.buildFilteredByAttributesDataSet(filteredDs,
                    new int[] { 0, 1 });
        }
    }

    final Instances decomposition = WekaTimeSeriesUtil.buildMergedDataSet(filteredDs, diff);

    final Attribute diffAttribute = decomposition.attribute(attr.name() + "_diff");

    final List<XYAnnotation> aaa = new ArrayList<XYAnnotation>();
    if (showError) {
        showError(this.isGapSimulated ? maeByComparingWithOriginal : maeByEnlargingGap, decomposition,
                diffAttribute, aaa);
    }

    if (showEnvelope) {
        final MainViewLoadingFrame loadingFrame = new MainViewLoadingFrame();
        loadingFrame.setVisible(true);
        loadingFrame.pack();
        loadingFrame.repaint();
        showEnvelope(arr, aaa);
        loadingFrame.setVisible(false);
    }

    if (!inBatchMode) {
        final ChartPanel cp;
        /*if (showError)
        {
           cp=TimeSeriesChartUtil.buildChartPanelForAllAttributesInterval(decomposition,WekaDataStatsUtil.getFirstDateAttributeIdx(decomposition),mae,diffAttribute.index());
        }
        else
        {*/
        cp = TimeSeriesChartUtil.buildChartPanelForAllAttributes(decomposition, multAxis,
                WekaDataStatsUtil.getFirstDateAttributeIdx(decomposition), null, aaa);
        /*}*/

        final Marker gapBeginMarker = new ValueMarker(
                dataSet.instance(Math.max(0, position - 1)).value(dateIdx));
        gapBeginMarker.setPaint(Color.RED);
        gapBeginMarker.setLabel("Gap begin");
        gapBeginMarker.setLabelAnchor(RectangleAnchor.TOP_LEFT);
        gapBeginMarker.setLabelTextAnchor(TextAnchor.TOP_RIGHT);
        cp.getChart().getXYPlot().addDomainMarker(gapBeginMarker);

        final Marker gapEndMarker = new ValueMarker(
                dataSet.instance(Math.min(dataSet.numInstances() - 1, position + gapsize)).value(dateIdx));
        gapEndMarker.setPaint(Color.RED);
        gapEndMarker.setLabel("Gap end");
        gapEndMarker.setLabelAnchor(RectangleAnchor.TOP_RIGHT);
        gapEndMarker.setLabelTextAnchor(TextAnchor.TOP_LEFT);
        cp.getChart().getXYPlot().addDomainMarker(gapEndMarker);

        if (!zoom) {
            final NumberAxis na = (NumberAxis) (cp.getChart().getXYPlot().getRangeAxis());
            na.setRange(0, WekaDataStatsUtil.getMaxValue(dataSet, attrNames));
        }

        String errorInfo;
        if (!this.isGapSimulated) {
            errorInfo = "By enlarging the gap:\t MAE="
                    + FormatterUtil.DECIMAL_FORMAT_4.format(maeByEnlargingGap) + "\t RMSE="
                    + FormatterUtil.DECIMAL_FORMAT_4.format(rmseByEnlargingGap) + "\t NASH-SUTCLIFFE="
                    + FormatterUtil.DECIMAL_FORMAT_4.format(nsByEnlargingGap)
                    + "\nBy adding a gap before:\t MAE="
                    + FormatterUtil.DECIMAL_FORMAT_4.format(maeByAddingAGapBefore) + "\t RMSE="
                    + FormatterUtil.DECIMAL_FORMAT_4.format(rmseByAddingAGapBefore) + "\t NASH-SUTCLIFFE="
                    + FormatterUtil.DECIMAL_FORMAT_4.format(nsByAddingAGapBefore)
                    + "\nBy adding a gap after:\t MAE="
                    + FormatterUtil.DECIMAL_FORMAT_4.format(maeByAddingAGapAfter) + "\t RMSE="
                    + FormatterUtil.DECIMAL_FORMAT_4.format(rmseByAddingAGapAfter) + "\t NASH-SUTCLIFFE="
                    + FormatterUtil.DECIMAL_FORMAT_4.format(nsByAddingAGapAfter);
        } else {
            errorInfo = "MAE: " + FormatterUtil.DECIMAL_FORMAT_4.format(maeByComparingWithOriginal);
            errorInfo += "\n";
            errorInfo += "RMSE: " + FormatterUtil.DECIMAL_FORMAT_4.format(rmseByComparingWithOriginal);
            errorInfo += "\n";
            errorInfo += "RSR: " + FormatterUtil.DECIMAL_FORMAT_4.format(rsrByComparingWithOriginal);
            errorInfo += "\n";
            errorInfo += "PBIAS: " + FormatterUtil.DECIMAL_FORMAT_4.format(pbiasByComparingWithOriginal);
            errorInfo += "\n";
            errorInfo += "NASH-SUTCLIFFE: " + FormatterUtil.DECIMAL_FORMAT_4.format(nsByComparingWithOriginal);
            errorInfo += "\n";
            errorInfo += "INDEX OF AGREEMENT: "
                    + FormatterUtil.DECIMAL_FORMAT_4.format(indexOfAgreementByComparingWithOriginal);
        }
        cp.setBorder(new TitledBorder(""));
        final JTextArea errorTextArea = new JTextArea(errorInfo);
        errorTextArea.setBorder(new TitledBorder(""));
        this.centerPanel.add(errorTextArea, BorderLayout.NORTH);
        this.centerPanel.add(cp, BorderLayout.CENTER);

        final JXPanel cmdPanel = new JXPanel();
        final JXButton okButton = new JXButton("Ok");
        okButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(final ActionEvent e) {
                final Instances correctedDataSet = buildCorrectedDataset(diff);

                final DataChange change = new DataChange(correctedDataSet, TabView.DataChangeTypeEnum.Update);
                atv.pushDataChange(change);

                setVisible(false);
            }
        });
        cmdPanel.add(okButton);
        final JXButton cancelButton = new JXButton("Cancel");
        cancelButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(final ActionEvent e) {
                setVisible(false);
            }
        });
        cmdPanel.add(cancelButton);
        this.centerPanel.add(cmdPanel, BorderLayout.SOUTH);

        this.centerPanel.updateUI();

        getContentPane().repaint();
    }

    final double globalMAE = (this.isGapSimulated) ? maeByComparingWithOriginal
            : ((maeByEnlargingGap + maeByAddingAGapBefore + maeByAddingAGapAfter) / 3);

    final double globalRMSE = (this.isGapSimulated) ? rmseByComparingWithOriginal
            : ((rmseByEnlargingGap + rmseByAddingAGapBefore + rmseByAddingAGapAfter) / 3);

    final double globalRSR = (this.isGapSimulated) ? rsrByComparingWithOriginal
            : ((rsrByEnlargingGap + rsrByAddingAGapBefore + rsrByAddingAGapAfter) / 3);

    final double globalPBIAS = (this.isGapSimulated) ? pbiasByComparingWithOriginal
            : ((pbiasByEnlargingGap + pbiasByAddingAGapBefore + pbiasByAddingAGapAfter) / 3);

    final double globalNS = (this.isGapSimulated) ? nsByComparingWithOriginal
            : ((nsByEnlargingGap + nsByAddingAGapBefore + nsByAddingAGapAfter) / 3);

    final double globalIndexOfAgreement = (this.isGapSimulated) ? indexOfAgreementByComparingWithOriginal
            : ((indexOfAgreementByEnlargingGap + indexOfAgreementByAddingAGapBefore
                    + indexOfAgreementByAddingAGapAfter) / 3);

    // usage logs for stats      
    final long firstTimestamp = (long) dataSet.instance(position).value(dateIdx);
    final boolean isDuringRising;
    if (nearest == null)
        isDuringRising = GapsUtil.isDuringRising(dataSet, position, gapsize,
                new int[] { dateIdx, attr.index() });
    else
        isDuringRising = GapsUtil.isDuringRising(dataSet, position, gapsize,
                new int[] { dateIdx, attr.index(), dataSet.attribute(nearest).index() });

    return new GapFillingCase(DateUtil.getSeason(firstTimestamp), DateUtil.getYear(firstTimestamp), algo,
            gapsize, position, attr, gcp.getCoordinates(attr.name())[0], gcp.getCoordinates(attr.name())[1],
            gcp.findDownstreamStation(attr.name()) != null, gcp.findUpstreamStation(attr.name()) != null,
            globalMAE, globalRMSE, globalRSR, globalPBIAS, globalNS, globalIndexOfAgreement,
            ArraysUtil.contains(indexesOfUsedSeries, attrNames.indexOf(mostSimilar)),
            ArraysUtil.contains(indexesOfUsedSeries, attrNames.indexOf(nearest)),
            ArraysUtil.contains(indexesOfUsedSeries, attrNames.indexOf(downstream)),
            ArraysUtil.contains(indexesOfUsedSeries, attrNames.indexOf(upstream)), isDuringRising,
            GapsUtil.measureHighMiddleLowInterval(dataSet, attr.index(), position - 1));
}

From source file:ch.algotrader.client.chart.ChartTab.java

@SuppressWarnings("unchecked")
public void updateData(ChartDataVO chartData) {

    resetAxis();/*from  www. ja v a  2 s  .  c  o  m*/

    // add/update indicators
    for (IndicatorVO indicator : chartData.getIndicators()) {

        RegularTimePeriod timePeriod = getRegularTimePeriod(indicator.getDateTime());
        TimeSeries series = this.indicators.get(indicator.getName());

        if (series != null) {
            series.addOrUpdate(timePeriod, indicator.getValue());
        }
    }

    // add/update bars
    for (BarVO bar : chartData.getBars()) {

        OHLCSeries series = this.bars.get(bar.getSecurityId());

        if (series != null) {

            // remove a value if it already exists
            RegularTimePeriod timePeriod = getRegularTimePeriod(bar.getDateTime());
            if (series.indexOf(timePeriod) >= 0) {
                series.remove(timePeriod);
            }
            series.add(timePeriod, bar.getOpen().doubleValue(), bar.getHigh().doubleValue(),
                    bar.getLow().doubleValue(), bar.getClose().doubleValue());
        }
    }

    // make all invisible since they might not currently have a value
    for (Marker marker : this.markers.values()) {
        marker.setAlpha(0);
    }

    // update markers
    for (MarkerVO markerVO : chartData.getMarkers()) {

        Marker marker = this.markers.get(markerVO.getName());
        Boolean selected = this.markersSelectionStatus.get(markerVO.getName());
        String name = marker.getLabel().split(":")[0];
        if (marker instanceof ValueMarker && markerVO instanceof ValueMarkerVO) {

            ValueMarker valueMarker = (ValueMarker) marker;
            ValueMarkerVO valueMarkerVO = (ValueMarkerVO) markerVO;
            valueMarker.setValue(valueMarkerVO.getValue());
            marker.setLabel(name + ": " + valueMarkerVO.getValue());
            marker.setAlpha(selected ? 1.0f : 0.0f);

        } else if (marker instanceof IntervalMarker && markerVO instanceof IntervalMarkerVO) {

            IntervalMarker intervalMarker = (IntervalMarker) marker;
            IntervalMarkerVO intervalMarkerVO = (IntervalMarkerVO) markerVO;
            intervalMarker.setStartValue(intervalMarkerVO.getStartValue());
            intervalMarker.setEndValue(intervalMarkerVO.getEndValue());
            marker.setLabel(
                    name + ": " + intervalMarkerVO.getStartValue() + " - " + intervalMarkerVO.getEndValue());
            marker.setAlpha(selected ? 0.5f : 0.0f);

        } else {
            throw new RuntimeException(marker.getClass() + " does not match " + markerVO.getClass());
        }
    }

    // update annotations
    for (AnnotationVO annotationVO : chartData.getAnnotations()) {

        AbstractXYAnnotation annotation;
        if (annotationVO instanceof PointerAnnotationVO) {

            PointerAnnotationVO pointerAnnotationVO = (PointerAnnotationVO) annotationVO;
            XYPointerAnnotation pointerAnnotation = new XYPointerAnnotation(pointerAnnotationVO.getText(),
                    pointerAnnotationVO.getDateTime().getTime(), pointerAnnotationVO.getValue(),
                    3.926990816987241D);
            pointerAnnotation.setTipRadius(0);
            pointerAnnotation.setBaseRadius(20);
            pointerAnnotation.setTextAnchor(TextAnchor.BOTTOM_RIGHT);
            pointerAnnotation.setFont(new Font("SansSerif", 0, 9));
            pointerAnnotation.setToolTipText("<html>" + formatter.format(pointerAnnotationVO.getDateTime())
                    + "<br>" + pointerAnnotationVO.getValue() + "</html>");

            annotation = pointerAnnotation;

        } else if (annotationVO instanceof BoxAnnotationVO) {

            BoxAnnotationVO boxAnnotationVO = (BoxAnnotationVO) annotationVO;
            XYBoxAnnotation boxAnnotation = new XYBoxAnnotation(boxAnnotationVO.getStartDateTime().getTime(),
                    boxAnnotationVO.getStartValue(), boxAnnotationVO.getEndDateTime().getTime(),
                    boxAnnotationVO.getEndValue(), null, null, new java.awt.Color(0, 0, 0, 60));
            boxAnnotation.setToolTipText("<html>" + formatter.format(boxAnnotationVO.getStartDateTime()) + " - "
                    + formatter.format(boxAnnotationVO.getEndDateTime()) + "<br>"
                    + boxAnnotationVO.getStartValue() + " - " + boxAnnotationVO.getEndValue() + "</html>");

            annotation = boxAnnotation;
        } else {
            throw new RuntimeException("unkown annotation type" + annotationVO.getClass());
        }

        if (!getPlot().getAnnotations().contains(annotation)) {
            getPlot().addAnnotation(annotation);
        }
    }

    // update description
    for (Title title : (List<Title>) this.getChart().getSubtitles()) {
        if (title instanceof TextTitle) {
            TextTitle textTitle = ((TextTitle) title);
            if (chartData.getDescription() != null && !("".equals(chartData.getDescription()))) {
                textTitle.setText(chartData.getDescription());
                textTitle.setVisible(true);
            } else {
                textTitle.setVisible(false);
            }
        }
    }

    initAxis();
}