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();
}
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));
}
}
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();
}
Aggregations