use of org.jfree.data.time.TimeSeries in project AndrOBD by fr3ts0n.
the class ObdDataPanel method valueChanged.
/**
* handle change in table selection
* activate / deactivate graphing of selected data items
*/
public void valueChanged(ListSelectionEvent e) {
TimeSeries ts;
int[] selIDs;
// clean up dataset
plotter.removeAllSeries();
// get selected items as list of data
// rather than array of ID's'
selIDs = tblPids.getSelectedRows();
for (int i = 0; i < selIDs.length; i++) {
/* since table model changed, it returns the complete object for any field */
EcuDataPv currPid = (EcuDataPv) tblPids.getModel().getValueAt(selIDs[i], EcuDataPv.FID_PID);
ts = selPids.get(currPid.get(EcuDataPv.FID_PID));
// if Series found
if (ts != null) {
// add new series to plotter ..
plotter.addSeries(ts);
}
}
}
use of org.jfree.data.time.TimeSeries in project AndrOBD by fr3ts0n.
the class VagTestFrame method miLoadActionPerformed.
// GEN-LAST:event_miSaveActionPerformed
@SuppressWarnings({ "unchecked" })
private // GEN-FIRST:event_miLoadActionPerformed
void miLoadActionPerformed(// GEN-FIRST:event_miLoadActionPerformed
java.awt.event.ActionEvent evt) {
// GEN-HEADEREND:event_miLoadActionPerformed
if (fChoose.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
File file = fChoose.getSelectedFile();
try {
FileInputStream in = new FileInputStream(file);
ObjectInputStream oIn = new ObjectInputStream(in);
/* ensure that measurement page is activated
to avoid deletion of loaded data afterwards */
Integer currPage = (Integer) oIn.readObject();
tabMain.setSelectedIndex(currPage);
/* read in the data */
Kw1281Prot.VidPvs = (PvList) oIn.readObject();
Kw1281Prot.PidPvs = (PvList) oIn.readObject();
Kw1281Prot.tCodes = (PvList) oIn.readObject();
// re-setup data connection
panObdData.setPidPvs(Kw1281Prot.PidPvs);
panObdDtc.setTcList(Kw1281Prot.tCodes);
TblVehIDs.setProcessVar(Kw1281Prot.VidPvs);
// read measurement history
panObdData.selPids = (HashMap<Object, TimeSeries>) oIn.readObject();
oIn.close();
} catch (Exception ex) {
ex.printStackTrace();
JOptionPane.showMessageDialog(this, ex.getMessage(), "Load ERROR", JOptionPane.ERROR_MESSAGE);
}
}
}
use of org.jfree.data.time.TimeSeries in project Gemma by PavlidisLab.
the class ExpressionExperimentQCController method writeDetailedFactorAnalysis.
private boolean writeDetailedFactorAnalysis(ExpressionExperiment ee, OutputStream os) throws Exception {
SVDValueObject svdo = svdService.getSvdFactorAnalysis(ee.getId());
if (svdo == null)
return false;
if (svdo.getFactors().isEmpty() && svdo.getDates().isEmpty()) {
return false;
}
Map<Integer, Map<Long, Double>> factorCorrelations = svdo.getFactorCorrelations();
// Map<Integer, Map<Long, Double>> factorPvalues = svdo.getFactorPvalues();
Map<Integer, Double> dateCorrelations = svdo.getDateCorrelations();
assert ee.getId().equals(svdo.getId());
// need the experimental design
ee = expressionExperimentService.thawLite(ee);
int maxWidth = 30;
Map<Long, String> efs = this.getFactorNames(ee, maxWidth);
Map<Long, ExperimentalFactor> efIdMap = EntityUtils.getIdMap(ee.getExperimentalDesign().getExperimentalFactors());
Collection<Long> continuousFactors = new HashSet<>();
for (ExperimentalFactor ef : ee.getExperimentalDesign().getExperimentalFactors()) {
boolean isContinous = ExperimentalDesignUtils.isContinuous(ef);
if (isContinous) {
continuousFactors.add(ef.getId());
}
}
/*
* Make plots of the dates vs. PCs, factors vs. PCs.
*/
int MAX_COMP = 3;
Map<Long, List<JFreeChart>> charts = new LinkedHashMap<>();
ChartFactory.setChartTheme(StandardChartTheme.createLegacyTheme());
/*
* FACTORS
*/
String componentShorthand = "PC";
for (Integer component : factorCorrelations.keySet()) {
if (component >= MAX_COMP)
break;
String xaxisLabel = componentShorthand + (component + 1);
for (Long efId : factorCorrelations.get(component).keySet()) {
/*
* Should not happen.
*/
if (!efs.containsKey(efId)) {
log.warn("No experimental factor with id " + efId);
continue;
}
if (!svdo.getFactors().containsKey(efId)) {
// this should not happen.
continue;
}
boolean isCategorical = !continuousFactors.contains(efId);
Map<Long, String> categories = new HashMap<>();
if (isCategorical) {
this.getCategories(efIdMap, efId, categories);
}
if (!charts.containsKey(efId)) {
charts.put(efId, new ArrayList<JFreeChart>());
}
Double a = factorCorrelations.get(component).get(efId);
// unique?
String plotname = (efs.get(efId) == null ? "?" : efs.get(efId)) + " " + xaxisLabel;
if (a != null && !Double.isNaN(a)) {
String title = plotname + " " + String.format("%.2f", a);
List<Double> values = svdo.getFactors().get(efId);
Double[] eigenGene = this.getEigenGene(svdo, component);
assert values.size() == eigenGene.length;
/*
* Plot eigengene vs values, add correlation to the plot
*/
JFreeChart chart;
if (isCategorical) {
/*
* Categorical factor
*/
// use the absolute value of the correlation, since direction is arbitrary.
title = plotname + " " + String.format("r=%.2f", Math.abs(a));
DefaultMultiValueCategoryDataset dataset = new DefaultMultiValueCategoryDataset();
/*
* What this code does is organize the factor values by the groups.
*/
Map<String, List<Double>> groupedValues = new TreeMap<>();
for (int i = 0; i < values.size(); i++) {
Long fvId = values.get(i).longValue();
String fvValue = categories.get(fvId);
if (fvValue == null) {
// is this all we need to do?
continue;
}
if (!groupedValues.containsKey(fvValue)) {
groupedValues.put(fvValue, new ArrayList<Double>());
}
groupedValues.get(fvValue).add(eigenGene[i]);
if (log.isDebugEnabled())
log.debug(fvValue + " " + values.get(i));
}
for (String key : groupedValues.keySet()) {
dataset.add(groupedValues.get(key), plotname, key);
}
// don't show the name of the X axis: it's redundant with the title.
NumberAxis rangeAxis = new NumberAxis(xaxisLabel);
rangeAxis.setAutoRangeIncludesZero(false);
// rangeAxis.setAutoRange( false );
rangeAxis.setAutoRangeMinimumSize(4.0);
// rangeAxis.setRange( new Range( -2, 2 ) );
CategoryPlot plot = new CategoryPlot(dataset, new CategoryAxis(null), rangeAxis, new ScatterRenderer());
plot.setRangeGridlinesVisible(false);
plot.setDomainGridlinesVisible(false);
chart = new JFreeChart(title, new Font("SansSerif", Font.BOLD, 12), plot, false);
ScatterRenderer renderer = (ScatterRenderer) plot.getRenderer();
float saturationDrop = (float) Math.min(1.0, component * 0.8f / MAX_COMP);
renderer.setSeriesFillPaint(0, Color.getHSBColor(0.0f, 1.0f - saturationDrop, 0.7f));
renderer.setSeriesShape(0, new Ellipse2D.Double(0, 0, 3, 3));
renderer.setUseOutlinePaint(false);
renderer.setUseFillPaint(true);
renderer.setBaseFillPaint(Color.white);
CategoryAxis domainAxis = plot.getDomainAxis();
domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);
} else {
/*
* Continuous value factor
*/
DefaultXYDataset series = new DefaultXYDataset();
series.addSeries(plotname, new double[][] { ArrayUtils.toPrimitive(values.toArray(new Double[] {})), ArrayUtils.toPrimitive(eigenGene) });
// don't show x-axis label, which would otherwise be efs.get( efId )
chart = ChartFactory.createScatterPlot(title, null, xaxisLabel, series, PlotOrientation.VERTICAL, false, false, false);
XYPlot plot = chart.getXYPlot();
plot.setRangeGridlinesVisible(false);
plot.setDomainGridlinesVisible(false);
XYItemRenderer renderer = plot.getRenderer();
renderer.setBasePaint(Color.white);
renderer.setSeriesShape(0, new Ellipse2D.Double(0, 0, 3, 3));
float saturationDrop = (float) Math.min(1.0, component * 0.8f / MAX_COMP);
renderer.setSeriesPaint(0, Color.getHSBColor(0.0f, 1.0f - saturationDrop, 0.7f));
plot.setRenderer(renderer);
}
chart.getTitle().setFont(new Font("SansSerif", Font.BOLD, 12));
charts.get(efId).add(chart);
}
}
}
/*
* DATES
*/
charts.put(-1L, new ArrayList<JFreeChart>());
for (Integer component : dateCorrelations.keySet()) {
String xaxisLabel = componentShorthand + (component + 1);
List<Date> dates = svdo.getDates();
if (dates.isEmpty())
break;
long secspan = ubic.basecode.util.DateUtil.numberOfSecondsBetweenDates(dates);
if (component >= MAX_COMP)
break;
Double a = dateCorrelations.get(component);
if (a != null && !Double.isNaN(a)) {
Double[] eigenGene = svdo.getvMatrix().getColObj(component);
/*
* Plot eigengene vs values, add correlation to the plot
*/
TimeSeries series = new TimeSeries("Dates vs. eigen" + (component + 1));
int i = 0;
for (Date d : dates) {
// if span is less than an hour, retain the minute.
if (secspan < 60 * 60) {
series.addOrUpdate(new Minute(d), eigenGene[i++]);
} else {
series.addOrUpdate(new Hour(d), eigenGene[i++]);
}
}
TimeSeriesCollection dataset = new TimeSeriesCollection();
dataset.addSeries(series);
JFreeChart chart = ChartFactory.createTimeSeriesChart("Dates: " + xaxisLabel + " " + String.format("r=%.2f", a), null, xaxisLabel, dataset, false, false, false);
XYPlot xyPlot = chart.getXYPlot();
chart.getTitle().setFont(new Font("SansSerif", Font.BOLD, 12));
// standard renderer makes lines.
XYDotRenderer renderer = new XYDotRenderer();
renderer.setBaseFillPaint(Color.white);
renderer.setDotHeight(3);
renderer.setDotWidth(3);
// has no effect, need dotheight.
renderer.setSeriesShape(0, new Ellipse2D.Double(0, 0, 3, 3));
float saturationDrop = (float) Math.min(1.0, component * 0.8f / MAX_COMP);
renderer.setSeriesPaint(0, Color.getHSBColor(0.0f, 1.0f - saturationDrop, 0.7f));
ValueAxis domainAxis = xyPlot.getDomainAxis();
domainAxis.setVerticalTickLabels(true);
xyPlot.setRenderer(renderer);
xyPlot.setRangeGridlinesVisible(false);
xyPlot.setDomainGridlinesVisible(false);
charts.get(-1L).add(chart);
}
}
/*
* Plot in a grid, with each factor as a column. FIXME What if we have too many factors to fit on the screen?
*/
int columns = (int) Math.ceil(charts.size());
int perChartSize = ExpressionExperimentQCController.DEFAULT_QC_IMAGE_SIZE_PX;
BufferedImage image = new BufferedImage(columns * perChartSize, MAX_COMP * perChartSize, BufferedImage.TYPE_INT_ARGB);
Graphics2D g2 = image.createGraphics();
int currentX = 0;
int currentY = 0;
for (Long id : charts.keySet()) {
for (JFreeChart chart : charts.get(id)) {
this.addChartToGraphics(chart, g2, currentX, currentY, perChartSize, perChartSize);
if (currentY + perChartSize < MAX_COMP * perChartSize) {
currentY += perChartSize;
} else {
currentY = 0;
currentX += perChartSize;
}
}
}
os.write(ChartUtilities.encodeAsPNG(image));
return true;
}
use of org.jfree.data.time.TimeSeries in project zaproxy by zaproxy.
the class ScanProgressDialog method initialize.
private void initialize() {
JTabbedPane tabbedPane = new JTabbedPane();
JPanel tab1 = new JPanel();
tab1.setLayout(new GridBagLayout());
JPanel hostPanel = new JPanel();
hostPanel.setLayout(new GridBagLayout());
hostPanel.add(new JLabel(Constant.messages.getString("ascan.progress.label.host")), LayoutHelper.getGBC(0, 0, 1, 0.4D));
hostPanel.add(getHostSelect(), LayoutHelper.getGBC(1, 0, 1, 0.6D));
tab1.add(hostPanel, LayoutHelper.getGBC(0, 0, 3, 1.0D, 0.0D));
tab1.add(getJScrollPane(), LayoutHelper.getGBC(0, 1, 3, 1.0D, 1.0D));
JPanel buttonsPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 5, 0));
buttonsPanel.add(getCopyToClipboardButton());
buttonsPanel.add(getCloseButton());
tab1.add(buttonsPanel, LayoutHelper.getGBC(0, 2, 3, 1.0D));
tabbedPane.insertTab(Constant.messages.getString("ascan.progress.tab.progress"), null, tab1, null, 0);
this.add(tabbedPane);
int mins = extension.getScannerParam().getMaxChartTimeInMins();
if (mins > 0) {
// Treat zero mins as disabled
JPanel tab2 = new JPanel();
tab2.setLayout(new GridBagLayout());
this.seriesTotal = // Name not shown, so no need to i18n
new TimeSeries("TotalResponses");
final TimeSeriesCollection dataset = new TimeSeriesCollection(this.seriesTotal);
this.series100 = new TimeSeries(Constant.messages.getString("ascan.progress.chart.1xx"));
this.series200 = new TimeSeries(Constant.messages.getString("ascan.progress.chart.2xx"));
this.series300 = new TimeSeries(Constant.messages.getString("ascan.progress.chart.3xx"));
this.series400 = new TimeSeries(Constant.messages.getString("ascan.progress.chart.4xx"));
this.series500 = new TimeSeries(Constant.messages.getString("ascan.progress.chart.5xx"));
long maxAge = mins * 60L;
this.seriesTotal.setMaximumItemAge(maxAge);
this.series100.setMaximumItemAge(maxAge);
this.series200.setMaximumItemAge(maxAge);
this.series300.setMaximumItemAge(maxAge);
this.series400.setMaximumItemAge(maxAge);
this.series500.setMaximumItemAge(maxAge);
dataset.addSeries(series100);
dataset.addSeries(series200);
dataset.addSeries(series300);
dataset.addSeries(series400);
dataset.addSeries(series500);
chart = createChart(dataset);
// Set up some vaguely sensible colours
// Totals
chart.getXYPlot().getRenderer(0).setSeriesPaint(0, Color.BLACK);
// 100: Info
chart.getXYPlot().getRenderer(0).setSeriesPaint(1, Color.GRAY);
// 200: OK
chart.getXYPlot().getRenderer(0).setSeriesPaint(2, Color.GREEN);
// 300: Info
chart.getXYPlot().getRenderer(0).setSeriesPaint(3, Color.BLUE);
// 400: Bad req
chart.getXYPlot().getRenderer(0).setSeriesPaint(4, Color.MAGENTA);
// 500: Internal error
chart.getXYPlot().getRenderer(0).setSeriesPaint(5, Color.RED);
final ChartPanel chartPanel = new ChartPanel(chart);
tab2.add(chartPanel, LayoutHelper.getGBC(0, 0, 1, 1.0D, 1.0D));
tabbedPane.insertTab(Constant.messages.getString("ascan.progress.tab.chart"), null, tab2, null, 1);
}
// Stop the updating thread when the window is closed
this.addWindowListener(new WindowAdapter() {
@Override
public void windowClosed(WindowEvent e) {
stopThread = true;
}
});
pack();
}
use of org.jfree.data.time.TimeSeries in project dbeaver by serge-rider.
the class DashboardRendererBase method generateSampleSeries.
protected void generateSampleSeries(DashboardContainer container, TimeSeriesCollection dataset) {
TimeSeries seriesSin = new TimeSeries("Sin");
long startTime = System.currentTimeMillis() - 1000 * 60 * 60 * 2;
for (int i = 0; i < 100; i++) {
seriesSin.add(new TimeSeriesDataItem(new FixedMillisecond(startTime + i * 60 * 1000), Math.sin(0.1 * i) * 100));
}
dataset.addSeries(seriesSin);
TimeSeries seriesCos = new TimeSeries("Cos");
for (int i = 0; i < 100; i++) {
seriesCos.add(new TimeSeriesDataItem(new FixedMillisecond(startTime + i * 60 * 1000), Math.cos(0.1 * i) * 100));
}
dataset.addSeries(seriesCos);
}
Aggregations