Search in sources :

Example 6 with DashboardChartComposite

use of org.jkiss.dbeaver.ui.dashboard.control.DashboardChartComposite in project dbeaver by serge-rider.

the class DashboardRendererTimeseries method getDashboardPlot.

private XYPlot getDashboardPlot(DashboardContainer container) {
    DashboardChartComposite chartComposite = getChartComposite(container);
    JFreeChart chart = chartComposite.getChart();
    return chart == null ? null : (XYPlot) chart.getPlot();
}
Also used : DashboardChartComposite(org.jkiss.dbeaver.ui.dashboard.control.DashboardChartComposite) JFreeChart(org.jfree.chart.JFreeChart)

Example 7 with DashboardChartComposite

use of org.jkiss.dbeaver.ui.dashboard.control.DashboardChartComposite in project dbeaver by serge-rider.

the class DashboardRendererTimeseries method updateDashboardData.

@Override
public void updateDashboardData(DashboardContainer container, Date lastUpdateTime, DashboardDataset dataset) {
    DashboardChartComposite chartComposite = getChartComposite(container);
    if (chartComposite.isDisposed()) {
        return;
    }
    JFreeChart chart = chartComposite.getChart();
    XYPlot plot = (XYPlot) chart.getPlot();
    TimeSeriesCollection chartDataset = (TimeSeriesCollection) plot.getDataset();
    if (container.getDashboardFetchType() == DashboardFetchType.stats) {
        // Clean previous data before stats update
        chartDataset.removeAllSeries();
    }
    long currentTime = System.currentTimeMillis();
    long secondsPassed = lastUpdateTime == null ? 1 : (currentTime - lastUpdateTime.getTime()) / 1000;
    if (secondsPassed <= 0) {
        secondsPassed = 1;
    }
    DashboardDatasetRow lastRow = (DashboardDatasetRow) chartComposite.getData("last_row");
    List<DashboardDatasetRow> rows = dataset.getRows();
    String[] srcSeries = dataset.getColumnNames();
    for (int i = 0; i < srcSeries.length; i++) {
        String seriesName = srcSeries[i];
        TimeSeries series = chartDataset.getSeries(seriesName);
        if (series == null) {
            series = new TimeSeries(seriesName);
            series.setMaximumItemCount(container.getDashboardMaxItems());
            series.setMaximumItemAge(container.getDashboardMaxAge());
            chartDataset.addSeries(series);
            plot.getRenderer().setSeriesStroke(chartDataset.getSeriesCount() - 1, plot.getRenderer().getBaseStroke());
        }
        switch(container.getDashboardCalcType()) {
            case value:
                {
                    int maxDP = 200;
                    Date startTime = null;
                    for (DashboardDatasetRow row : rows) {
                        if (startTime == null) {
                            startTime = row.getTimestamp();
                        } else {
                            if (container.getDashboardInterval() == DashboardInterval.second || container.getDashboardInterval() == DashboardInterval.millisecond) {
                                long diffSeconds = (row.getTimestamp().getTime() - startTime.getTime()) / 1000;
                                if (diffSeconds > maxDP) {
                                    // Too big difference between start and end points. Stop here otherwise we'll flood chart with too many ticks
                                    break;
                                }
                            }
                        }
                        Object value = row.getValues()[i];
                        if (value instanceof Number) {
                            series.addOrUpdate(makeDataItem(container, row), (Number) value);
                        }
                    }
                    break;
                }
            case delta:
                {
                    if (lastUpdateTime == null) {
                        return;
                    }
                    // System.out.println("LAST=" + lastUpdateTime + "; CUR=" + new Date());
                    for (DashboardDatasetRow row : rows) {
                        if (lastRow != null) {
                            Object prevValue = lastRow.getValues()[i];
                            Object newValue = row.getValues()[i];
                            if (newValue instanceof Number && prevValue instanceof Number) {
                                double deltaValue = ((Number) newValue).doubleValue() - ((Number) prevValue).doubleValue();
                                deltaValue /= secondsPassed;
                                if (container.getDashboardValueType() != DashboardValueType.decimal) {
                                    deltaValue = Math.round(deltaValue);
                                }
                                series.addOrUpdate(makeDataItem(container, row), deltaValue);
                            }
                        }
                    }
                    break;
                }
        }
    }
    if (!rows.isEmpty()) {
        chartComposite.setData("last_row", rows.get(rows.size() - 1));
    }
}
Also used : DashboardDatasetRow(org.jkiss.dbeaver.ui.dashboard.model.data.DashboardDatasetRow) JFreeChart(org.jfree.chart.JFreeChart) Point(org.eclipse.swt.graphics.Point) Date(java.util.Date) XYPlot(org.jfree.chart.plot.XYPlot) DashboardChartComposite(org.jkiss.dbeaver.ui.dashboard.control.DashboardChartComposite)

Example 8 with DashboardChartComposite

use of org.jkiss.dbeaver.ui.dashboard.control.DashboardChartComposite in project dbeaver by dbeaver.

the class DashboardRendererTimeseries method getDashboardPlot.

private XYPlot getDashboardPlot(DashboardContainer container) {
    DashboardChartComposite chartComposite = getChartComposite(container);
    JFreeChart chart = chartComposite.getChart();
    return chart == null ? null : (XYPlot) chart.getPlot();
}
Also used : DashboardChartComposite(org.jkiss.dbeaver.ui.dashboard.control.DashboardChartComposite) JFreeChart(org.jfree.chart.JFreeChart)

Aggregations

DashboardChartComposite (org.jkiss.dbeaver.ui.dashboard.control.DashboardChartComposite)8 JFreeChart (org.jfree.chart.JFreeChart)6 XYPlot (org.jfree.chart.plot.XYPlot)6 Point (org.eclipse.swt.graphics.Point)4 java.awt (java.awt)2 SimpleDateFormat (java.text.SimpleDateFormat)2 Date (java.util.Date)2 ChartPanel (org.jfree.chart.ChartPanel)2 XYItemRenderer (org.jfree.chart.renderer.xy.XYItemRenderer)2 RectangleInsets (org.jfree.ui.RectangleInsets)2 BaseChartDrawingSupplier (org.jkiss.dbeaver.ui.charts.BaseChartDrawingSupplier)2 DashboardDatasetRow (org.jkiss.dbeaver.ui.dashboard.model.data.DashboardDatasetRow)2