Search in sources :

Example 1 with ValueMarker

use of org.jfree.chart.plot.ValueMarker in project pinot by linkedin.

the class AnomalyGraphGenerator method createGraphMarker.

/**
   * Returns either a value marker (point) or a interval marker (range) depending on provided
   * inputs. By default values are gray or transparent gray.
   * @param intervalStart
   * @param intervalEnd
   * @return
   */
private Marker createGraphMarker(Long intervalStart, Long intervalEnd, String label) {
    Marker anomalyMarker;
    if (intervalEnd == null || intervalStart.equals(intervalEnd)) {
        // Point
        anomalyMarker = new ValueMarker(intervalStart);
        anomalyMarker.setPaint(Color.LIGHT_GRAY);
    } else {
        // Range
        anomalyMarker = new IntervalMarker(intervalStart, intervalEnd);
        anomalyMarker.setPaint(TRANSPARENT_GRAY);
    }
    anomalyMarker.setLabel(label);
    LOG.info("Anomaly marker generated for: {}, {}", intervalStart, intervalEnd);
    return anomalyMarker;
}
Also used : IntervalMarker(org.jfree.chart.plot.IntervalMarker) ValueMarker(org.jfree.chart.plot.ValueMarker) Marker(org.jfree.chart.plot.Marker) IntervalMarker(org.jfree.chart.plot.IntervalMarker) ValueMarker(org.jfree.chart.plot.ValueMarker)

Example 2 with ValueMarker

use of org.jfree.chart.plot.ValueMarker in project zaproxy by zaproxy.

the class ScanProgressDialog method updateProgress.

/**
     * Updates the scan progress shown by the dialogue (scanners' progress/state and chart).
     */
private void updateProgress() {
    // Start panel data settings
    HostProcess hp = getSelectedHostProcess();
    if (scan.getHostProcesses() != null && hp != null) {
        // Update the main table entries
        model.updateValues(scan, hp);
        if (scan.isStopped()) {
            this.stopThread = true;
        }
        if (chart != null) {
            ResponseCountSnapshot snapshot = scan.getRequestHistory();
            while (snapshot != null) {
                try {
                    Second second = new Second(snapshot.getDate());
                    this.seriesTotal.add(second, snapshot.getTotal());
                    this.series100.add(second, snapshot.getResp100());
                    this.series200.add(second, snapshot.getResp200());
                    this.series300.add(second, snapshot.getResp300());
                    this.series400.add(second, snapshot.getResp400());
                    this.series500.add(second, snapshot.getResp500());
                    snapshot = scan.getRequestHistory();
                    for (Plugin plugin : scan.getHostProcesses().get(0).getRunning()) {
                        if (!labelsAdded.contains(plugin.getName())) {
                            // Add a vertical line with the plugin name
                            ValueMarker vm = new ValueMarker(plugin.getTimeStarted().getTime());
                            double center = chart.getXYPlot().getRangeAxis().getRange().getCentralValue();
                            if (lastCentre != center) {
                                if (lastCentre != -1) {
                                    // Move the existing labels so they stay in the centre
                                    @SuppressWarnings("rawtypes") List annotations = chart.getXYPlot().getAnnotations();
                                    for (Object o : annotations) {
                                        if (o instanceof XYTextAnnotation) {
                                            XYTextAnnotation annotation = (XYTextAnnotation) o;
                                            annotation.setY(center);
                                        }
                                    }
                                }
                                lastCentre = center;
                            }
                            XYTextAnnotation updateLabel = new XYTextAnnotation(plugin.getName(), plugin.getTimeStarted().getTime(), center);
                            updateLabel.setFont(FontUtils.getFont("Sans Serif"));
                            updateLabel.setRotationAnchor(TextAnchor.BASELINE_CENTER);
                            updateLabel.setTextAnchor(TextAnchor.BASELINE_CENTER);
                            updateLabel.setRotationAngle(-3.14 / 2);
                            updateLabel.setPaint(Color.black);
                            chart.getXYPlot().addDomainMarker(vm, Layer.BACKGROUND);
                            chart.getXYPlot().addAnnotation(updateLabel);
                            labelsAdded.add(plugin.getName());
                        }
                    }
                } catch (Exception e) {
                    log.error(e.getMessage(), e);
                    snapshot = null;
                }
            }
        }
    }
}
Also used : HostProcess(org.parosproxy.paros.core.scanner.HostProcess) XYTextAnnotation(org.jfree.chart.annotations.XYTextAnnotation) Second(org.jfree.data.time.Second) List(java.util.List) ArrayList(java.util.ArrayList) ValueMarker(org.jfree.chart.plot.ValueMarker) HeadlessException(java.awt.HeadlessException) Plugin(org.parosproxy.paros.core.scanner.Plugin)

Example 3 with ValueMarker

use of org.jfree.chart.plot.ValueMarker in project crypto-bot by jnidzwetzki.

the class Chart method addBuySellSignals.

private static void addBuySellSignals(TimeSeries series, Strategy strategy, XYPlot plot) {
    // Running the strategy
    TimeSeriesManager seriesManager = new TimeSeriesManager(series);
    List<Trade> trades = seriesManager.run(strategy).getTrades();
    // Adding markers to plot
    for (Trade trade : trades) {
        // Buy signal
        double buySignalTickTime = new Minute(Date.from(series.getBar(trade.getEntry().getIndex()).getEndTime().toInstant())).getFirstMillisecond();
        Marker buyMarker = new ValueMarker(buySignalTickTime);
        buyMarker.setPaint(Color.GREEN);
        buyMarker.setLabel("B");
        plot.addDomainMarker(buyMarker);
        // Sell signal
        double sellSignalTickTime = new Minute(Date.from(series.getBar(trade.getExit().getIndex()).getEndTime().toInstant())).getFirstMillisecond();
        Marker sellMarker = new ValueMarker(sellSignalTickTime);
        sellMarker.setPaint(Color.RED);
        sellMarker.setLabel("S");
        plot.addDomainMarker(sellMarker);
    }
}
Also used : Trade(org.ta4j.core.Trade) Minute(org.jfree.data.time.Minute) TimeSeriesManager(org.ta4j.core.TimeSeriesManager) ValueMarker(org.jfree.chart.plot.ValueMarker) Marker(org.jfree.chart.plot.Marker) ValueMarker(org.jfree.chart.plot.ValueMarker)

Example 4 with ValueMarker

use of org.jfree.chart.plot.ValueMarker in project ta4j by ta4j.

the class BuyAndSellSignalsToChart method addBuySellSignals.

/**
 * Runs a strategy over a time series and adds the value markers
 * corresponding to buy/sell signals to the plot.
 * @param series a time series
 * @param strategy a trading strategy
 * @param plot the plot
 */
private static void addBuySellSignals(TimeSeries series, Strategy strategy, XYPlot plot) {
    // Running the strategy
    TimeSeriesManager seriesManager = new TimeSeriesManager(series);
    List<Trade> trades = seriesManager.run(strategy).getTrades();
    // Adding markers to plot
    for (Trade trade : trades) {
        // Buy signal
        double buySignalBarTime = new Minute(Date.from(series.getBar(trade.getEntry().getIndex()).getEndTime().toInstant())).getFirstMillisecond();
        Marker buyMarker = new ValueMarker(buySignalBarTime);
        buyMarker.setPaint(Color.GREEN);
        buyMarker.setLabel("B");
        plot.addDomainMarker(buyMarker);
        // Sell signal
        double sellSignalBarTime = new Minute(Date.from(series.getBar(trade.getExit().getIndex()).getEndTime().toInstant())).getFirstMillisecond();
        Marker sellMarker = new ValueMarker(sellSignalBarTime);
        sellMarker.setPaint(Color.RED);
        sellMarker.setLabel("S");
        plot.addDomainMarker(sellMarker);
    }
}
Also used : Minute(org.jfree.data.time.Minute) ValueMarker(org.jfree.chart.plot.ValueMarker) Marker(org.jfree.chart.plot.Marker) ValueMarker(org.jfree.chart.plot.ValueMarker)

Example 5 with ValueMarker

use of org.jfree.chart.plot.ValueMarker in project mafscaling by vimsh.

the class LogView method createGraghPanel.

private void createGraghPanel() {
    JFreeChart chart = ChartFactory.createXYLineChart(null, null, null, null, PlotOrientation.VERTICAL, false, true, false);
    chartPanel = new ChartPanel(chart, true, true, true, true, true);
    chartPanel.setFocusable(true);
    chartPanel.setAutoscrolls(true);
    chartPanel.setPopupMenu(null);
    chart.setBackgroundPaint(chartColor);
    rpmDataset = new XYSeriesCollection();
    rpmPlotRenderer = new XYLineAndShapeRenderer();
    dataset = new XYSeriesCollection();
    plotRenderer = new XYLineAndShapeRenderer();
    NumberAxis xAxis = new NumberAxis();
    xAxis.setTickLabelsVisible(false);
    xAxis.setTickLabelPaint(Color.WHITE);
    xAxis.setAutoRangeIncludesZero(false);
    NumberAxis yAxis = new NumberAxis();
    yAxis.setTickLabelsVisible(false);
    yAxis.setTickLabelPaint(Color.WHITE);
    yAxis.setAutoRangeIncludesZero(false);
    NumberAxis y2Axis = new NumberAxis();
    y2Axis.setTickLabelsVisible(false);
    y2Axis.setTickLabelPaint(Color.WHITE);
    y2Axis.setAutoRangeIncludesZero(false);
    plot = chartPanel.getChart().getXYPlot();
    plot.setRangePannable(true);
    plot.setDomainPannable(true);
    plot.setDomainGridlinePaint(Color.LIGHT_GRAY);
    plot.setRangeGridlinePaint(Color.LIGHT_GRAY);
    plot.setBackgroundPaint(chartBgColor);
    plot.setDataset(0, rpmDataset);
    plot.setRenderer(0, rpmPlotRenderer);
    plot.setDomainAxis(0, xAxis);
    plot.setRangeAxis(0, yAxis);
    plot.mapDatasetToDomainAxis(0, 0);
    plot.mapDatasetToRangeAxis(0, 0);
    plot.setDataset(1, dataset);
    plot.setRenderer(1, plotRenderer);
    plot.setRangeAxis(1, y2Axis);
    plot.mapDatasetToDomainAxis(1, 0);
    plot.mapDatasetToRangeAxis(1, 1);
    LegendTitle legend = new LegendTitle(plot);
    legend.setItemFont(new Font("Arial", 0, 10));
    legend.setPosition(RectangleEdge.TOP);
    legend.setItemPaint(Color.WHITE);
    chart.addLegend(legend);
    xMarker = new XYDomainMutilineAnnotation();
    xMarker.setDefaultPaint(Color.WHITE);
    plot.addAnnotation(xMarker);
    chartMouseListener = new ChartMouseListener() {

        @Override
        public void chartMouseMoved(ChartMouseEvent event) {
            try {
                Rectangle2D dataArea = chartPanel.getChartRenderingInfo().getPlotInfo().getDataArea();
                Point2D p = chartPanel.translateScreenToJava2D(event.getTrigger().getPoint());
                double x = plot.getDomainAxis().java2DToValue(p.getX(), dataArea, plot.getDomainAxisEdge());
                boolean isLeft = (p.getX() < (dataArea.getMaxX() - dataArea.getMinX()) / 2) ? true : false;
                if (setMarkers(x, isLeft)) {
                    try {
                        int selectedCol = logDataTable.getTable().getSelectedColumn();
                        if (selectedCol < 0)
                            selectedCol = 0;
                        if (logPlayWindow == null || startMarker != null || endMarker != null) {
                            logDataTable.getTable().setRowSelectionInterval((int) x, (int) x);
                            logDataTable.getTable().changeSelection((int) x, selectedCol, false, false);
                        } else {
                            logPlayWindow.setProgressBar((int) x);
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        @Override
        public void chartMouseClicked(ChartMouseEvent event) {
            chartPanel.requestFocusInWindow();
            if (logPlayWindow == null)
                return;
            if (xMarker.count() == 0)
                return;
            Rectangle2D dataArea = chartPanel.getChartRenderingInfo().getPlotInfo().getDataArea();
            Point2D p = chartPanel.translateScreenToJava2D(event.getTrigger().getPoint());
            double x = plot.getDomainAxis().java2DToValue(p.getX(), dataArea, plot.getDomainAxisEdge());
            if (x < 0 || (int) x >= logDataTable.getRowCount())
                return;
            if (SwingUtilities.isLeftMouseButton(event.getTrigger())) {
                if (startMarker == null) {
                    startMarker = new ValueMarker(x);
                    startMarker.setPaint(Color.GREEN);
                    startMarker.setStroke(new BasicStroke(1.5f));
                    plot.addDomainMarker(startMarker);
                } else {
                    plot.removeDomainMarker(startMarker);
                    startMarker = null;
                }
            } else if (SwingUtilities.isRightMouseButton(event.getTrigger())) {
                if (endMarker == null) {
                    endMarker = new ValueMarker(x);
                    endMarker.setPaint(Color.GREEN);
                    endMarker.setStroke(new BasicStroke(1.5f));
                    plot.addDomainMarker(endMarker);
                } else {
                    plot.removeDomainMarker(endMarker);
                    endMarker = null;
                }
            }
            chartPanel.repaint();
            logPlayWindow.setStartEndArea(startMarker, endMarker);
        }
    };
    chartPanel.addChartMouseListener(chartMouseListener);
    chartPanel.addKeyListener(new KeyListener() {

        public void keyPressed(KeyEvent e) {
            if (!chartPanel.hasFocus())
                return;
            int keyCode = e.getKeyCode();
            if (keyCode < KeyEvent.VK_LEFT || keyCode > KeyEvent.VK_DOWN)
                return;
            ValueAxis axis = null;
            if (keyCode == KeyEvent.VK_LEFT || keyCode == KeyEvent.VK_RIGHT)
                axis = ((XYPlot) chartPanel.getChart().getXYPlot()).getDomainAxis();
            else
                axis = ((XYPlot) chartPanel.getChart().getXYPlot()).getRangeAxis();
            if (axis != null) {
                double delta = (axis.getUpperBound() - axis.getLowerBound()) / 100.0;
                if (keyCode == KeyEvent.VK_LEFT || keyCode == KeyEvent.VK_DOWN)
                    axis.setRange(axis.getLowerBound() - delta, axis.getUpperBound() - delta);
                else if (keyCode == KeyEvent.VK_UP || keyCode == KeyEvent.VK_RIGHT)
                    axis.setRange(axis.getLowerBound() + delta, axis.getUpperBound() + delta);
            }
        }

        public void keyReleased(KeyEvent arg0) {
        }

        public void keyTyped(KeyEvent arg0) {
        }
    });
}
Also used : BasicStroke(java.awt.BasicStroke) ChartPanel(org.jfree.chart.ChartPanel) NumberAxis(org.jfree.chart.axis.NumberAxis) XYLineAndShapeRenderer(org.jfree.chart.renderer.xy.XYLineAndShapeRenderer) Rectangle2D(java.awt.geom.Rectangle2D) LegendTitle(org.jfree.chart.title.LegendTitle) ChartMouseEvent(org.jfree.chart.ChartMouseEvent) JFreeChart(org.jfree.chart.JFreeChart) Font(java.awt.Font) IOException(java.io.IOException) ChartMouseListener(org.jfree.chart.ChartMouseListener) KeyEvent(java.awt.event.KeyEvent) Point2D(java.awt.geom.Point2D) ValueAxis(org.jfree.chart.axis.ValueAxis) KeyListener(java.awt.event.KeyListener) ValueMarker(org.jfree.chart.plot.ValueMarker) XYSeriesCollection(org.jfree.data.xy.XYSeriesCollection)

Aggregations

ValueMarker (org.jfree.chart.plot.ValueMarker)14 Marker (org.jfree.chart.plot.Marker)6 JFreeChart (org.jfree.chart.JFreeChart)5 BasicStroke (java.awt.BasicStroke)3 Color (java.awt.Color)3 NumberAxis (org.jfree.chart.axis.NumberAxis)3 CategoryPlot (org.jfree.chart.plot.CategoryPlot)3 Font (java.awt.Font)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 XYTextAnnotation (org.jfree.chart.annotations.XYTextAnnotation)2 CategoryAxis (org.jfree.chart.axis.CategoryAxis)2 ValueAxis (org.jfree.chart.axis.ValueAxis)2 XYPlot (org.jfree.chart.plot.XYPlot)2 BarRenderer (org.jfree.chart.renderer.category.BarRenderer)2 XYLineAndShapeRenderer (org.jfree.chart.renderer.xy.XYLineAndShapeRenderer)2 Minute (org.jfree.data.time.Minute)2 TimeSeries (org.jfree.data.time.TimeSeries)2 RectangleInsets (org.jfree.ui.RectangleInsets)2