Search in sources :

Example 1 with DashboardChartComposite

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

the class DashboardRendererTimeseries method createDashboard.

@Override
public DashboardChartComposite createDashboard(Composite composite, DashboardContainer container, DashboardViewContainer viewContainer, Point preferredSize) {
    TimeSeriesCollection dataset = new TimeSeriesCollection();
    // generateSampleSeries(container, dataset);
    DashboardItemViewConfiguration viewConfig = viewContainer.getViewConfiguration().getDashboardConfig(container.getDashboardId());
    Color gridColor = AWTUtils.makeAWTColor(UIStyles.getDefaultTextForeground());
    JFreeChart histogramChart = ChartFactory.createXYLineChart(null, UIDashboardMessages.histogram_timeseries_x_axis_label, UIDashboardMessages.histogram_timeseries_y_axis_label, dataset, PlotOrientation.VERTICAL, true, true, false);
    histogramChart.setBorderVisible(false);
    histogramChart.setPadding(new RectangleInsets(0, 0, 0, 0));
    histogramChart.setTextAntiAlias(true);
    histogramChart.setBackgroundPaint(AWTUtils.makeAWTColor(UIStyles.getDefaultTextBackground()));
    createDefaultLegend(viewConfig, histogramChart);
    ChartPanel chartPanel = new ChartPanel(histogramChart);
    chartPanel.setPreferredSize(new java.awt.Dimension(preferredSize.x, preferredSize.y));
    final XYPlot plot = histogramChart.getXYPlot();
    // Remove border
    plot.setOutlinePaint(null);
    // Remove background
    plot.setShadowGenerator(null);
    plot.setDrawingSupplier(new BaseChartDrawingSupplier());
    // XYItemRenderer renderer = new XYLine3DRenderer();
    // plot.setRenderer(renderer);
    // renderer.setSeriesOutlinePaint(0, Color.black);
    // renderer.setSeriesOutlineStroke(0, new BasicStroke(0.5f));
    {
        DateAxis domainAxis = new DateAxis(UIDashboardMessages.histogram_timeseries_date_axis_label);
        domainAxis.setDateFormatOverride(new SimpleDateFormat("HH:mm:ss"));
        domainAxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE);
        domainAxis.setAutoRange(true);
        domainAxis.setLabel(null);
        domainAxis.setLowerMargin(0);
        domainAxis.setUpperMargin(0);
        domainAxis.setTickLabelPaint(gridColor);
        domainAxis.setTickLabelFont(DEFAULT_TICK_LABEL_FONT);
        domainAxis.setTickLabelInsets(RectangleInsets.ZERO_INSETS);
        DateTickUnitType unitType;
        switch(container.getDashboardInterval()) {
            case minute:
                unitType = DateTickUnitType.MINUTE;
                break;
            case hour:
                unitType = DateTickUnitType.HOUR;
                break;
            case day:
            case week:
                unitType = DateTickUnitType.DAY;
                break;
            case month:
                unitType = DateTickUnitType.MONTH;
                break;
            case year:
                unitType = DateTickUnitType.YEAR;
                break;
            default:
                unitType = DateTickUnitType.SECOND;
                break;
        }
        int tickCount = container.getDashboardMaxItems();
        if (tickCount > 40) {
            tickCount = container.getDashboardMaxItems() / 5;
        }
        if (tickCount <= 1) {
            tickCount = 10;
        }
        domainAxis.setTickUnit(new DateTickUnit(unitType, Math.min(MAX_TIMESERIES_RANGE_LABELS, tickCount)));
        if (viewConfig != null && !viewConfig.isDomainTicksVisible()) {
            domainAxis.setVisible(false);
        }
        plot.setDomainAxis(domainAxis);
    }
    {
        ValueAxis rangeAxis = plot.getRangeAxis();
        rangeAxis.setLabel(null);
        rangeAxis.setTickLabelPaint(gridColor);
        rangeAxis.setTickLabelFont(DEFAULT_TICK_LABEL_FONT);
        rangeAxis.setTickLabelInsets(RectangleInsets.ZERO_INSETS);
        rangeAxis.setStandardTickUnits(DashboardUtils.getTickUnitsSource(container.getDashboardValueType()));
        if (container.getDashboardValueType() == DashboardValueType.percent) {
            rangeAxis.setLowerBound(0);
            rangeAxis.setUpperBound(100);
        }
        if (viewConfig != null && !viewConfig.isRangeTicksVisible()) {
            rangeAxis.setVisible(false);
        }
    // rangeAxis.setLowerMargin(0.2);
    // rangeAxis.setLowerBound(.1);
    }
    XYItemRenderer plotRenderer = plot.getRenderer();
    plotRenderer.setBaseItemLabelPaint(gridColor);
    BasicStroke stroke = new BasicStroke(2.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND, 10.0f, null, 0.0f);
    plot.getRenderer().setBaseStroke(stroke);
    // Set background
    plot.setBackgroundPaint(histogramChart.getBackgroundPaint());
    /*
        Stroke gridStroke = new BasicStroke(0.1f,
            BasicStroke.CAP_SQUARE, BasicStroke.JOIN_MITER, 1.0f,
            new float[] {1.0f, 1.0f}, 0.0f);
*/
    plot.setDomainGridlinePaint(gridColor);
    // plot.setDomainGridlineStroke(gridStroke);
    plot.setDomainGridlinesVisible(viewConfig == null || viewConfig.isGridVisible());
    plot.setRangeGridlinePaint(gridColor);
    // plot.setRangeGridlineStroke(gridStroke);
    plot.setRangeGridlinesVisible(viewConfig == null || viewConfig.isGridVisible());
    DashboardChartComposite chartComposite = createChartComposite(composite, container, viewContainer, preferredSize);
    chartComposite.setChart(histogramChart);
    return chartComposite;
}
Also used : ChartPanel(org.jfree.chart.ChartPanel) BaseChartDrawingSupplier(org.jkiss.dbeaver.ui.charts.BaseChartDrawingSupplier) JFreeChart(org.jfree.chart.JFreeChart) XYPlot(org.jfree.chart.plot.XYPlot) DashboardChartComposite(org.jkiss.dbeaver.ui.dashboard.control.DashboardChartComposite) RectangleInsets(org.jfree.ui.RectangleInsets) XYItemRenderer(org.jfree.chart.renderer.xy.XYItemRenderer) SimpleDateFormat(java.text.SimpleDateFormat) java.awt(java.awt)

Example 2 with DashboardChartComposite

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

the class DashboardRendererTimeseries method updateDashboardView.

@Override
public void updateDashboardView(DashboardItem dashboardItem) {
    XYPlot plot = getDashboardPlot(dashboardItem);
    if (plot != null) {
        DashboardChartComposite chartComposite = getChartComposite(dashboardItem);
        DashboardViewConfiguration viewConfiguration = chartComposite.getViewContainer().getViewConfiguration();
        DashboardItemViewConfiguration dashboardConfig = viewConfiguration.getDashboardConfig(dashboardItem.getDashboardId());
        if (dashboardConfig != null) {
            plot.getRangeAxis().setVisible(dashboardConfig.isRangeTicksVisible());
            plot.getDomainAxis().setVisible(dashboardConfig.isDomainTicksVisible());
            plot.setDomainGridlinesVisible(dashboardConfig.isGridVisible());
            plot.setRangeGridlinesVisible(dashboardConfig.isGridVisible());
            chartComposite.getChart().getLegend().setVisible(dashboardConfig.isLegendVisible());
            TimeSeriesCollection chartDataset = (TimeSeriesCollection) plot.getDataset();
            for (int i = 0; i < chartDataset.getSeriesCount(); i++) {
                TimeSeries series = chartDataset.getSeries(i);
                series.setMaximumItemCount(dashboardConfig.getMaxItems());
                series.setMaximumItemAge(dashboardConfig.getMaxAge());
            }
        }
    }
    dashboardItem.getParent().layout(true, true);
}
Also used : XYPlot(org.jfree.chart.plot.XYPlot) DashboardChartComposite(org.jkiss.dbeaver.ui.dashboard.control.DashboardChartComposite) Point(org.eclipse.swt.graphics.Point)

Example 3 with DashboardChartComposite

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

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 4 with DashboardChartComposite

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

the class DashboardRendererTimeseries method createDashboard.

@Override
public DashboardChartComposite createDashboard(Composite composite, DashboardContainer container, DashboardViewContainer viewContainer, Point preferredSize) {
    TimeSeriesCollection dataset = new TimeSeriesCollection();
    // generateSampleSeries(container, dataset);
    DashboardItemViewConfiguration viewConfig = viewContainer.getViewConfiguration().getDashboardConfig(container.getDashboardId());
    Color gridColor = AWTUtils.makeAWTColor(UIStyles.getDefaultTextForeground());
    JFreeChart histogramChart = ChartFactory.createXYLineChart(null, UIDashboardMessages.histogram_timeseries_x_axis_label, UIDashboardMessages.histogram_timeseries_y_axis_label, dataset, PlotOrientation.VERTICAL, true, true, false);
    histogramChart.setBorderVisible(false);
    histogramChart.setPadding(new RectangleInsets(0, 0, 0, 0));
    histogramChart.setTextAntiAlias(true);
    histogramChart.setBackgroundPaint(AWTUtils.makeAWTColor(UIStyles.getDefaultTextBackground()));
    createDefaultLegend(viewConfig, histogramChart);
    ChartPanel chartPanel = new ChartPanel(histogramChart);
    chartPanel.setPreferredSize(new java.awt.Dimension(preferredSize.x, preferredSize.y));
    final XYPlot plot = histogramChart.getXYPlot();
    // Remove border
    plot.setOutlinePaint(null);
    // Remove background
    plot.setShadowGenerator(null);
    plot.setDrawingSupplier(new BaseChartDrawingSupplier());
    // XYItemRenderer renderer = new XYLine3DRenderer();
    // plot.setRenderer(renderer);
    // renderer.setSeriesOutlinePaint(0, Color.black);
    // renderer.setSeriesOutlineStroke(0, new BasicStroke(0.5f));
    {
        DateAxis domainAxis = new DateAxis(UIDashboardMessages.histogram_timeseries_date_axis_label);
        domainAxis.setDateFormatOverride(new SimpleDateFormat("HH:mm:ss"));
        domainAxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE);
        domainAxis.setAutoRange(true);
        domainAxis.setLabel(null);
        domainAxis.setLowerMargin(0);
        domainAxis.setUpperMargin(0);
        domainAxis.setTickLabelPaint(gridColor);
        domainAxis.setTickLabelFont(DEFAULT_TICK_LABEL_FONT);
        domainAxis.setTickLabelInsets(RectangleInsets.ZERO_INSETS);
        DateTickUnitType unitType;
        switch(container.getDashboardInterval()) {
            case minute:
                unitType = DateTickUnitType.MINUTE;
                break;
            case hour:
                unitType = DateTickUnitType.HOUR;
                break;
            case day:
            case week:
                unitType = DateTickUnitType.DAY;
                break;
            case month:
                unitType = DateTickUnitType.MONTH;
                break;
            case year:
                unitType = DateTickUnitType.YEAR;
                break;
            default:
                unitType = DateTickUnitType.SECOND;
                break;
        }
        int tickCount = container.getDashboardMaxItems();
        if (tickCount > 40) {
            tickCount = container.getDashboardMaxItems() / 5;
        }
        if (tickCount <= 1) {
            tickCount = 10;
        }
        domainAxis.setTickUnit(new DateTickUnit(unitType, Math.min(MAX_TIMESERIES_RANGE_LABELS, tickCount)));
        if (viewConfig != null && !viewConfig.isDomainTicksVisible()) {
            domainAxis.setVisible(false);
        }
        plot.setDomainAxis(domainAxis);
    }
    {
        ValueAxis rangeAxis = plot.getRangeAxis();
        rangeAxis.setLabel(null);
        rangeAxis.setTickLabelPaint(gridColor);
        rangeAxis.setTickLabelFont(DEFAULT_TICK_LABEL_FONT);
        rangeAxis.setTickLabelInsets(RectangleInsets.ZERO_INSETS);
        rangeAxis.setStandardTickUnits(DashboardUtils.getTickUnitsSource(container.getDashboardValueType()));
        if (container.getDashboardValueType() == DashboardValueType.percent) {
            rangeAxis.setLowerBound(0);
            rangeAxis.setUpperBound(100);
        }
        if (viewConfig != null && !viewConfig.isRangeTicksVisible()) {
            rangeAxis.setVisible(false);
        }
    // rangeAxis.setLowerMargin(0.2);
    // rangeAxis.setLowerBound(.1);
    }
    XYItemRenderer plotRenderer = plot.getRenderer();
    plotRenderer.setBaseItemLabelPaint(gridColor);
    BasicStroke stroke = new BasicStroke(2.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND, 10.0f, null, 0.0f);
    plot.getRenderer().setBaseStroke(stroke);
    // Set background
    plot.setBackgroundPaint(histogramChart.getBackgroundPaint());
    /*
        Stroke gridStroke = new BasicStroke(0.1f,
            BasicStroke.CAP_SQUARE, BasicStroke.JOIN_MITER, 1.0f,
            new float[] {1.0f, 1.0f}, 0.0f);
*/
    plot.setDomainGridlinePaint(gridColor);
    // plot.setDomainGridlineStroke(gridStroke);
    plot.setDomainGridlinesVisible(viewConfig == null || viewConfig.isGridVisible());
    plot.setRangeGridlinePaint(gridColor);
    // plot.setRangeGridlineStroke(gridStroke);
    plot.setRangeGridlinesVisible(viewConfig == null || viewConfig.isGridVisible());
    DashboardChartComposite chartComposite = createChartComposite(composite, container, viewContainer, preferredSize);
    chartComposite.setChart(histogramChart);
    return chartComposite;
}
Also used : ChartPanel(org.jfree.chart.ChartPanel) BaseChartDrawingSupplier(org.jkiss.dbeaver.ui.charts.BaseChartDrawingSupplier) JFreeChart(org.jfree.chart.JFreeChart) XYPlot(org.jfree.chart.plot.XYPlot) DashboardChartComposite(org.jkiss.dbeaver.ui.dashboard.control.DashboardChartComposite) RectangleInsets(org.jfree.ui.RectangleInsets) XYItemRenderer(org.jfree.chart.renderer.xy.XYItemRenderer) SimpleDateFormat(java.text.SimpleDateFormat) java.awt(java.awt)

Example 5 with DashboardChartComposite

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

the class DashboardRendererTimeseries method updateDashboardView.

@Override
public void updateDashboardView(DashboardItem dashboardItem) {
    XYPlot plot = getDashboardPlot(dashboardItem);
    if (plot != null) {
        DashboardChartComposite chartComposite = getChartComposite(dashboardItem);
        DashboardViewConfiguration viewConfiguration = chartComposite.getViewContainer().getViewConfiguration();
        DashboardItemViewConfiguration dashboardConfig = viewConfiguration.getDashboardConfig(dashboardItem.getDashboardId());
        if (dashboardConfig != null) {
            plot.getRangeAxis().setVisible(dashboardConfig.isRangeTicksVisible());
            plot.getDomainAxis().setVisible(dashboardConfig.isDomainTicksVisible());
            plot.setDomainGridlinesVisible(dashboardConfig.isGridVisible());
            plot.setRangeGridlinesVisible(dashboardConfig.isGridVisible());
            chartComposite.getChart().getLegend().setVisible(dashboardConfig.isLegendVisible());
            TimeSeriesCollection chartDataset = (TimeSeriesCollection) plot.getDataset();
            for (int i = 0; i < chartDataset.getSeriesCount(); i++) {
                TimeSeries series = chartDataset.getSeries(i);
                series.setMaximumItemCount(dashboardConfig.getMaxItems());
                series.setMaximumItemAge(dashboardConfig.getMaxAge());
            }
        }
    }
    dashboardItem.getParent().layout(true, true);
}
Also used : XYPlot(org.jfree.chart.plot.XYPlot) DashboardChartComposite(org.jkiss.dbeaver.ui.dashboard.control.DashboardChartComposite) Point(org.eclipse.swt.graphics.Point)

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