use of org.jfree.data.time.TimeSeriesCollection in project GULLI by rsaemann.
the class CapacityTimelinePanel method updateShownTimeSeries.
public void updateShownTimeSeries() {
if (this.collection == null) {
return;
}
if (checkboxes == null) {
return;
}
XYPlot plot = panelChart.getChart().getXYPlot();
plot.clearRangeAxes();
for (int i = 0; i < plot.getDatasetCount(); i++) {
try {
plot.setDataset(i, null);
} catch (Exception e) {
e.printStackTrace();
}
}
numberUsedDataSetSlots = 0;
yAxisMap.clear();
XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
int indexDataset = 0;
int indexSeries = 0;
int showncounter = 0;
// System.out.println("checkboxes: "+checkboxes.length);
for (int i = 0; i < checkboxes.length; i++) {
try {
if (checkboxes[i].isSelected()) {
if (this.collection.getSeries(i) == null) {
continue;
}
SeriesKey key = (SeriesKey) collection.getSeries(i).getKey();
/**
* Baue neues Dataset wenn keine Wiederekennung zu finden
* ist
*/
TimeSeriesCollection dataset = null;
if (key.axisKey == null || key.axisKey.name == null) {
/*
* No recognition (mapping to other dataset) required.
* Build a new Dataset+Yaxis for this TimeSeries
*/
indexDataset = numberUsedDataSetSlots;
numberUsedDataSetSlots++;
dataset = new TimeSeriesCollection(this.collection.getSeries(i));
plot.setDataset(indexDataset, dataset);
renderer = new XYLineAndShapeRenderer(true, false);
renderer.setDefaultToolTipGenerator(tooltipGenerator);
plot.setRenderer(indexDataset, renderer);
NumberAxis axis2 = new NumberAxis(checkboxes[i].getText());
// NumberFormat.getNumberInstance(FormatLocale));
axis2.setNumberFormatOverride(numberFormat);
yAxisMap.put(axis2.getLabel(), indexDataset);
axis2.setAutoRangeIncludesZero(false);
plot.setRangeAxis(indexDataset, axis2);
plot.mapDatasetToRangeAxis(indexDataset, indexDataset);
if (key.isVisible()) {
showncounter++;
}
} else {
NumberAxis yAxis;
if (yAxisMap.containsKey(key.axisKey.toString())) {
indexDataset = yAxisMap.get(key.axisKey.toString());
yAxis = (NumberAxis) plot.getRangeAxis(indexDataset);
// yAxis.setNumberFormatOverride(NumberFormat.getCurrencyInstance(Locale.US));
dataset = (TimeSeriesCollection) plot.getDataset(indexDataset);
indexSeries = dataset.getSeriesCount();
TimeSeries ts = (TimeSeries) this.collection.getSeries(i);
if (key.logarithmic) {
makeTimeSeriesAbsolute(ts);
}
dataset.addSeries(ts);
renderer = (XYLineAndShapeRenderer) plot.getRenderer(indexDataset);
renderer.setSeriesStroke(indexSeries, key.stroke);
} else {
// Axis key not yet in use. Build new Dataset for this Yaxis
indexDataset = numberUsedDataSetSlots;
numberUsedDataSetSlots++;
yAxisMap.put(key.axisKey.toString(), indexDataset);
indexSeries = 0;
String label = key.axisKey.label;
if (label == null || label.isEmpty()) {
label = "[" + key.unit + "]";
}
if (key.logarithmic) {
yAxis = new LogarithmicAxis(label);
} else {
yAxis = new NumberAxis(label);
}
// }
if (key.axisKey != null) {
if (key.axisKey.manualBounds) {
yAxis.setLowerBound(key.axisKey.lowerBound);
yAxis.setUpperBound(key.axisKey.upperBound);
} else {
key.axisKey.lowerBound = yAxis.getLowerBound();
key.axisKey.upperBound = yAxis.getUpperBound();
}
}
// yAxisMap.put(yAxis.getLabel(), indexDataset);
XYIntervalRenderer intervalRenderer = new XYIntervalRenderer();
intervalRenderer.drawinterval = true;
if (key.axisKey != null) {
intervalRenderer.interval = key.axisKey.drawInterval;
}
// new XYIntervalRenderer();//new XYLineAndShapeRenderer(true, false);
renderer = intervalRenderer;
renderer.setSeriesStroke(indexSeries, key.stroke);
plot.setRenderer(indexDataset, renderer);
yAxis.setAutoRangeIncludesZero(false);
plot.setRangeAxis(indexDataset, yAxis);
plot.mapDatasetToRangeAxis(indexDataset, indexDataset);
dataset = new TimeSeriesCollection(this.collection.getSeries(i));
if (key.logarithmic) {
for (Object s : dataset.getSeries()) {
if (s instanceof TimeSeries) {
TimeSeries ts = (TimeSeries) s;
makeTimeSeriesAbsolute(ts);
}
}
}
try {
plot.setDataset(indexDataset, dataset);
} catch (Exception e) {
e.printStackTrace();
}
}
try {
plot.mapDatasetToRangeAxis(indexDataset, indexDataset);
} catch (Exception e) {
}
}
renderer = (XYLineAndShapeRenderer) plot.getRenderer(indexDataset);
renderer.setDrawSeriesLineAsPath(true);
if (key.lineColor != null) {
renderer.setSeriesPaint(indexSeries, key.lineColor);
}
if (key.stroke != null) {
renderer.setSeriesStroke(indexSeries, key.stroke);
renderer.setSeriesLinesVisible(indexSeries, true);
} else {
renderer.setSeriesLinesVisible(indexSeries, false);
}
if (key.shape != null && key.shape.getShape() != null) {
renderer.setSeriesShape(indexSeries, key.shape.getShape());
renderer.setSeriesShapesFilled(indexSeries, key.shapeFilled);
renderer.setSeriesShapesVisible(indexSeries, true);
if (key.axisKey != null && key.axisKey.drawInterval > 1) {
if (renderer instanceof XYIntervalRenderer) {
((XYIntervalRenderer) renderer).interval = key.axisKey.drawInterval;
}
}
// System.out.println("Series "+key.label+" shape: "+key.shape);
} else {
renderer.setSeriesShape(indexSeries, null);
renderer.setSeriesShapesVisible(indexSeries, false);
// System.out.println("Series "+key.label+" without shape");
}
renderer.setDefaultEntityRadius(6);
renderer.setDefaultToolTipGenerator(tooltipGenerator);
indexDataset++;
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
if (matlabStyle) {
MatlabLayout.layoutToMatlab(this.panelChart.getChart());
}
}
use of org.jfree.data.time.TimeSeriesCollection in project GULLI by rsaemann.
the class MultiplePipesTimelinesPanel method updateShownTimeSeries.
@Override
public void updateShownTimeSeries() {
if (this.collection == null) {
System.err.println("collection is null");
return;
}
XYPlot plot = panelChart.getChart().getXYPlot();
plot.clearRangeAxes();
DefaultTableModel m = (DefaultTableModel) seriesCheckTable.getModel();
for (int i = 0; i < m.getColumnCount(); i++) {
plot.setDataset(i, new TimeSeriesCollection());
}
collection.removeAllSeries();
for (int i = 1; i < m.getColumnCount(); i++) {
for (int j = 0; j < m.getRowCount(); j++) {
try {
boolean b = (boolean) m.getValueAt(j, i);
if (!b) {
continue;
}
String key = list.get(j).getAutoID() + " " + m.getColumnName(i);
TimeSeries ts = storeCollection.getSeries(key);
if (ts == null) {
for (Iterator it = storeCollection.getSeries().iterator(); it.hasNext(); ) {
TimeSeries sery = (TimeSeries) it.next();
}
} else {
collection.addSeries(ts);
TimeSeriesCollection set = (TimeSeriesCollection) plot.getDataset(i);
set.addSeries(ts);
}
} catch (Exception e) {
System.err.println("error at " + j + "," + i);
System.err.println("m=" + m);
System.err.println("v=" + m.getValueAt(j, i));
e.printStackTrace();
}
}
}
XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
final double[] maxRange = new double[m.getColumnCount()];
// int index = 0;
for (int i = 0; i < m.getColumnCount(); i++) {
renderer = new XYLineAndShapeRenderer(true, false);
plot.setRenderer(i, renderer);
String columntitle = m.getColumnName(i);
Paint rendering = Color.MAGENTA;
if (columntitle.startsWith("Q")) {
rendering = (Color.darkGray);
} else if (columntitle.startsWith("V")) {
rendering = (Color.MAGENTA);
} else if (columntitle.startsWith("Water")) {
rendering = (Color.BLUE);
} else if (columntitle.startsWith("u")) {
rendering = (Color.RED);
} else if (columntitle.startsWith("h_up")) {
rendering = (Color.CYAN);
} else if (columntitle.startsWith("h_down")) {
rendering = (Color.blue.darker());
} else if (columntitle.startsWith("h ")) {
rendering = (Color.blue);
} else if (columntitle.startsWith("Reynolds")) {
rendering = (Color.green.darker());
} else if (columntitle.startsWith("HE C")) {
// (Color.orange);
rendering = new Color(255, 200, 80);
} else if (columntitle.startsWith("HE T")) {
// (Color.orange);
rendering = new Color(230, 120, 50);
} else if (columntitle.startsWith("Part")) {
rendering = (Color.GREEN);
if (columntitle.contains("Ppm")) {
rendering = new Color(150, 255, 50);
} else if (columntitle.contains("Ppcbm")) {
rendering = new Color(0, 200, 100);
}
} else if (columntitle.startsWith("ana")) {
rendering = (new Color(165, 230, 75));
}
for (int j = 0; j < m.getRowCount(); j++) {
renderer.setSeriesPaint(j, rendering);
}
try {
limitBars[i].setBackground((Color) rendering);
} catch (Exception e) {
}
if (plot.getDataset(i) != null && plot.getDataset(i).getSeriesCount() > 0) {
final NumberAxis axis2 = new NumberAxis(columntitle);
axis2.setAutoRangeIncludesZero(false);
plot.setRangeAxis(i, axis2);
plot.mapDatasetToRangeAxis(i, i);
maxRange[i] = axis2.getRange().getUpperBound();
final int j = i;
limitBars[i].addAdjustmentListener(new AdjustmentListener() {
@Override
public void adjustmentValueChanged(AdjustmentEvent ae) {
// axis2.setUpperBound(((limitBars[j].getMaximum() - ae.getValueStamp()) / 1000.) * maxRange[j]);
axis2.setUpperBound((1 + (ae.getValue() - 200.) / 1000.) * maxRange[j]);
}
});
}
}
timeend = Long.MIN_VALUE;
timestart = Long.MAX_VALUE;
for (Iterator it = collection.getSeries().iterator(); it.hasNext(); ) {
TimeSeries ser = (TimeSeries) it.next();
timeend = Math.max(timeend, ser.getTimePeriod(ser.getItemCount() - 1).getEnd().getTime());
timestart = Math.min(timestart, ser.getDataItem(0).getPeriod().getStart().getTime());
// System.out.println("Series "+ser.getDescription()+": "+ser.getDataItem(0).getPeriod().getStart()+"\t->"+ser.getTimePeriod(ser.getItemCount()-1).getStart());
}
updateDomainAxis();
// timestart = (long) plot.getDomainAxis().getRange().getLowerBound();
// timeend = (long) plot.getDomainAxis().getRange().getUpperBound();
// long newStart = timestart;
// long newend = timeend;
// long span = timeend - timestart;
//
// System.out.println("Zeitlich zwischen " + new Date(timestart) + " und " + new Date(timeend));
// //Zeit Limits anpassen
// if (limitTimeStart.getValueStamp() > 0) {
// System.out.println("schneide start weg " + limitTimeStart.getValueStamp() + "/" + limitTimeStart.getMaximum());
// double fs = limitTimeStart.getValueStamp() / (double) limitTimeStart.getMaximum();
// long weg = (long) (span * fs);
// newStart = timestart + weg;
// }
// if (limitTimeEnd.getValueStamp() < limitTimeEnd.getMaximum()) {
// double fs = 1 - (limitTimeEnd.getValueStamp() / (double) limitTimeEnd.getMaximum());
// long weg = (long) (span * fs);
// System.out.println("schneide ende weg " + weg + " " + limitTimeEnd.getValueStamp() + "/" + limitTimeEnd.getMaximum());
// newend = timeend - weg;
// }
//
// System.out.println("Zeitlich nurnoch " + new Date(newStart) + " und " + new Date(newend));
// if (newStart > newend) {
// plot.getDomainAxis().setRangeWithMargins((double) newStart, (double) newend);
// }
// System.out.println("defaultautorange:"+plot.getDomainAxis().getDefaultAutoRange());
// System.out.println("Range:"+plot.getDomainAxis().getRange());
// System.out.println("lowbound:"+plot.getDomainAxis().getLowerBound());
// System.out.println("lowmargin:"+plot.getDomainAxis().getLowerMargin());
// plot.getDomainAxis().setLowerBound((double) newStart);
}
use of org.jfree.data.time.TimeSeriesCollection in project GULLI by rsaemann.
the class PrecipitationTimelinePanel method updateShownTimeSeries.
@Override
public void updateShownTimeSeries() {
if (this.collection == null) {
return;
}
XYPlot plot = panelChart.getChart().getXYPlot();
for (int i = 0; i < plot.getDatasetCount(); i++) {
plot.setDataset(i, null);
}
plot.clearRangeAxes();
numberUsedDataSetSlots = 0;
yAxisMap.clear();
XYItemRenderer renderer = plot.getRenderer();
int indexDataset = 0;
int indexSeries = 0;
LegendItemCollection legendItems = new LegendItemCollection();
for (int i = 0; i < collection.getSeriesCount(); i++) {
TimeSeries series = collection.getSeries(i);
if (series == null) {
return;
}
SeriesKey key = (SeriesKey) series.getKey();
if (checkboxes != null) {
key.setVisible(checkboxes[i].isSelected());
}
/**
* Baue neues Dataset wenn keine Wiederekennung zu finden ist
*/
TimeSeriesCollection dataset = null;
if (key.axisKey == null || key.axisKey.name == null) {
/*
* No recognition (mapping to other dataset) required.
* Build a new Dataset+Yaxis for this TimeSeries
*/
indexDataset = numberUsedDataSetSlots;
numberUsedDataSetSlots++;
dataset = new TimeSeriesCollection(series);
plot.setDataset(indexDataset, dataset);
// System.out.println("Render "+key.name+" as linechart");
renderer = new XYLineAndShapeRenderer(true, false);
plot.setRenderer(indexDataset, renderer);
NumberAxis axis2 = new NumberAxis(key.label);
yAxisMap.put(axis2.getLabel(), indexDataset);
axis2.setAutoRangeIncludesZero(false);
plot.setRangeAxis(indexDataset, axis2);
plot.mapDatasetToRangeAxis(indexDataset, indexDataset);
} else {
NumberAxis yAxis;
if (yAxisMap.containsKey(key.axisKey.name)) {
indexDataset = yAxisMap.get(key.axisKey.name);
yAxis = (NumberAxis) plot.getRangeAxis(indexDataset);
dataset = (TimeSeriesCollection) plot.getDataset(indexDataset);
indexSeries = dataset.getSeriesCount();
dataset.addSeries(this.collection.getSeries(i));
renderer = (XYLineAndShapeRenderer) plot.getRenderer(indexDataset);
renderer.setSeriesStroke(indexSeries, key.stroke);
} else {
// Axis key not yet in use. Build new Dataset for this Yaxis
indexDataset = numberUsedDataSetSlots;
numberUsedDataSetSlots++;
yAxisMap.put(key.axisKey.name, indexDataset);
indexSeries = 0;
if (key.axisKey.label != null) {
yAxis = new NumberAxis(key.axisKey.label);
} else {
yAxis = new NumberAxis("[" + key.unit + "]");
}
yAxisMap.put(yAxis.getLabel(), indexDataset);
if (key.renderAsBar) {
// System.out.println("Render " + key.name + " as barchart");
XYBarRenderer barr = new XYBarRenderer(0);
barr.setSeriesOutlinePaint(indexSeries, Color.blue);
barr.setSeriesFillPaint(indexSeries, Color.cyan);
barr.setSeriesOutlineStroke(indexSeries, key.stroke);
barr.setSeriesPaint(indexSeries, new Color(100, 100, 255));
// barr.setBaseFillPaint(Color.red);
// barr.setBarAlignmentFactor(5);
barr.setDrawBarOutline(true);
barr.setShadowVisible(false);
// barr.setUseYInterval(true);
StandardXYBarPainter bp = new StandardXYBarPainter();
barr.setBarPainter(bp);
renderer = barr;
panelChart.getChart().getXYPlot().setRenderer(indexDataset, renderer);
} else {
renderer = new XYLineAndShapeRenderer(true, false);
renderer.setSeriesStroke(indexSeries, key.stroke);
plot.setRenderer(indexDataset, renderer);
}
yAxis.setAutoRangeIncludesZero(false);
plot.setRangeAxis(indexDataset, yAxis);
plot.mapDatasetToRangeAxis(indexDataset, indexDataset);
dataset = new TimeSeriesCollection(this.collection.getSeries(i));
plot.setDataset(indexDataset, dataset);
}
plot.mapDatasetToRangeAxis(indexDataset, indexDataset);
}
if (renderer instanceof XYLineAndShapeRenderer) {
((XYLineAndShapeRenderer) renderer).setDrawSeriesLineAsPath(true);
}
if (key.lineColor != null && !key.renderAsBar) {
renderer.setSeriesPaint(indexSeries, key.lineColor);
}
if (key.stroke != null) {
renderer.setSeriesStroke(indexSeries, key.stroke);
renderer.setSeriesVisible(indexSeries, true);
} else {
renderer.setSeriesVisible(indexSeries, false);
}
if (key.shape != null && key.shape.getShape() != null) {
renderer.setSeriesShape(indexSeries, key.shape.getShape());
if (renderer instanceof XYLineAndShapeRenderer) {
XYLineAndShapeRenderer r = (XYLineAndShapeRenderer) renderer;
r.setSeriesShapesFilled(indexSeries, key.shapeFilled);
r.setSeriesShapesVisible(i, true);
}
renderer.setSeriesVisible(indexSeries, true);
} else {
renderer.setSeriesShape(indexSeries, null);
}
indexDataset++;
LegendItem legendItem = new LegendItem(key.label, key.lineColor) {
@Override
public boolean isShapeFilled() {
return false;
}
@Override
public boolean isShapeOutlineVisible() {
return true;
}
};
legendItem.setLineStroke(key.stroke);
legendItem.setLine(lineShapeForLegend);
legendItem.setLinePaint(key.lineColor);
legendItem.setLineVisible(true);
if (key.shape != null && key.shape != ShapeEditor.SHAPES.EMPTY) {
legendItem.setShape(key.getShape());
legendItem.setShapeVisible(true);
legendItem.setOutlineStroke(new BasicStroke(1f));
legendItem.setOutlinePaint(key.lineColor);
} else {
legendItem.setShapeVisible(false);
}
// System.out.println("filled?" + legendItem.isShapeFilled() + " outline? " + legendItem.isShapeOutlineVisible());
legendItems.add(legendItem);
// System.out.println("set description of legend " + i + " to " + key.label);
}
if (showLegend) {
panelChart.getChart().getLegend().setVisible(true);
plot.setFixedLegendItems(legendItems);
} else {
plot.clearAnnotations();
panelChart.getChart().getLegend().setVisible(false);
}
if (matlabStyle) {
MatlabLayout.layoutToMatlab(this.panelChart.getChart());
this.panelChart.getChart().setBackgroundPaint(Color.white);
} else {
}
dateAxis.setDateFormatOverride(new SimpleDateFormat("HH:mm"));
// plot.getRangeAxis()
dateAxis.setTickUnit(new DateTickUnit(DateTickUnitType.MINUTE, 5));
}
use of org.jfree.data.time.TimeSeriesCollection in project spf4j by zolyfarkas.
the class Charts method createTimeSeriesCollection.
private static TimeSeriesCollection createTimeSeriesCollection(final String[] measurementNames, final long[] timestamps, final double[][] measurements) {
TimeSeriesCollection timeseriescollection = new TimeSeriesCollection();
for (int i = 0; i < measurementNames.length; i++) {
TimeSeries tseries = new TimeSeries(measurementNames[i]);
for (int j = 0; j < timestamps.length; j++) {
FixedMillisecond ts = new FixedMillisecond(timestamps[j]);
tseries.add(ts, measurements[i][j]);
}
timeseriescollection.addSeries(tseries);
}
return timeseriescollection;
}
use of org.jfree.data.time.TimeSeriesCollection in project spf4j by zolyfarkas.
the class Charts method createTimeSeriesCollection.
private static TimeSeriesCollection createTimeSeriesCollection(final String[] measurementNames, final long[][] timestamps, final double[][] measurements) {
TimeSeriesCollection timeseriescollection = new TimeSeriesCollection();
for (int i = 0; i < measurementNames.length; i++) {
TimeSeries tseries = new TimeSeries(measurementNames[i]);
for (int j = 0; j < timestamps[i].length; j++) {
FixedMillisecond ts = new FixedMillisecond(timestamps[i][j]);
tseries.add(ts, measurements[i][j]);
}
timeseriescollection.addSeries(tseries);
}
return timeseriescollection;
}
Aggregations