Search in sources :

Example 1 with BaseChartDrawingSupplier

use of org.jkiss.dbeaver.ui.charts.BaseChartDrawingSupplier 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 BaseChartDrawingSupplier

use of org.jkiss.dbeaver.ui.charts.BaseChartDrawingSupplier 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)

Aggregations

java.awt (java.awt)2 SimpleDateFormat (java.text.SimpleDateFormat)2 ChartPanel (org.jfree.chart.ChartPanel)2 JFreeChart (org.jfree.chart.JFreeChart)2 XYPlot (org.jfree.chart.plot.XYPlot)2 XYItemRenderer (org.jfree.chart.renderer.xy.XYItemRenderer)2 RectangleInsets (org.jfree.ui.RectangleInsets)2 BaseChartDrawingSupplier (org.jkiss.dbeaver.ui.charts.BaseChartDrawingSupplier)2 DashboardChartComposite (org.jkiss.dbeaver.ui.dashboard.control.DashboardChartComposite)2