use of org.jfree.chart.axis.NumberAxis in project mafscaling by vimsh.
the class VVTCalc method createChart.
protected void createChart(int index, JPanel plotPanel, String xAxisName, String yAxisName) {
JFreeChart chart = ChartFactory.createXYLineChart(null, null, null, null, PlotOrientation.VERTICAL, false, true, false);
chart.setBorderVisible(true);
ChartPanel chartPanel = new ChartPanel(chart, true, true, true, true, true);
chartPanels[index] = chartPanel;
chartPanel.setFocusable(true);
chartPanel.setAutoscrolls(true);
GridBagConstraints gbl_chartPanel = new GridBagConstraints();
gbl_chartPanel.anchor = GridBagConstraints.CENTER;
gbl_chartPanel.insets = new Insets(3, 3, 3, 3);
gbl_chartPanel.weightx = 1.0;
gbl_chartPanel.weighty = 1.0;
gbl_chartPanel.fill = GridBagConstraints.BOTH;
gbl_chartPanel.gridx = 0;
gbl_chartPanel.gridy = index;
plotPanel.add(chartPanel, gbl_chartPanel);
XYLineAndShapeRenderer lineRenderer = new XYLineAndShapeRenderer();
lineRenderer.setUseFillPaint(true);
lineRenderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT, new DecimalFormat("0.00"), new DecimalFormat("0.00")));
lineRenderer.setLegendItemLabelGenerator(new StandardXYSeriesLabelGenerator() {
private static final long serialVersionUID = 7593430826693873496L;
public String generateLabel(XYDataset dataset, int series) {
XYSeries xys = ((XYSeriesCollection) dataset).getSeries(series);
return xys.getDescription();
}
});
XYLineAndShapeRenderer lineRendererBest = new XYLineAndShapeRenderer();
lineRendererBest.setUseFillPaint(true);
lineRendererBest.setBaseToolTipGenerator(new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT, new DecimalFormat("0.00"), new DecimalFormat("0.00")));
lineRendererBest.setLegendItemLabelGenerator(new StandardXYSeriesLabelGenerator() {
private static final long serialVersionUID = -5917538704894141801L;
public String generateLabel(XYDataset dataset, int series) {
XYSeries xys = ((XYSeriesCollection) dataset).getSeries(series);
return xys.getDescription();
}
});
Stroke stroke = new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, null, 0.0f);
lineRendererBest.setSeriesPaint(0, Color.DARK_GRAY);
lineRendererBest.setSeriesStroke(0, stroke);
lineRendererBest.setSeriesPaint(1, Color.BLACK);
lineRendererBest.setSeriesStroke(1, stroke);
NumberAxis xAxis = new NumberAxis(xAxisName);
xAxis.setAutoRangeIncludesZero(false);
NumberAxis yAxis = new NumberAxis(yAxisName);
yAxis.setAutoRangeIncludesZero(false);
XYPlot plot = chart.getXYPlot();
plot.setRangePannable(true);
plot.setDomainPannable(true);
plot.setDomainGridlinePaint(Color.DARK_GRAY);
plot.setRangeGridlinePaint(Color.DARK_GRAY);
plot.setBackgroundPaint(new Color(224, 224, 224));
plot.setDataset(0, new XYSeriesCollection());
plot.setRenderer(0, lineRenderer);
plot.setDomainAxis(0, xAxis);
plot.setRangeAxis(0, yAxis);
plot.mapDatasetToDomainAxis(0, 0);
plot.mapDatasetToRangeAxis(0, 0);
XYSeriesCollection bestVVTDataset = new XYSeriesCollection();
plot.setDataset(1, bestVVTDataset);
plot.setRenderer(1, lineRendererBest);
plot.mapDatasetToDomainAxis(0, 0);
plot.mapDatasetToRangeAxis(0, 0);
LegendTitle legend = new LegendTitle(plot);
legend.setItemFont(new Font("Arial", 0, 10));
legend.setPosition(RectangleEdge.TOP);
chart.addLegend(legend);
}
use of org.jfree.chart.axis.NumberAxis in project mafscaling by vimsh.
the class ACompCalc method createChart.
protected void createChart(JPanel plotPanel, String xAxisName, String yAxisName) {
JFreeChart chart = ChartFactory.createScatterPlot(null, null, null, null, PlotOrientation.VERTICAL, false, true, false);
chart.setBorderVisible(true);
chartPanel = new ChartPanel(chart, true, true, true, true, true);
chartPanel.setAutoscrolls(true);
chartPanel.setMouseZoomable(false);
GridBagConstraints gbl_chartPanel = new GridBagConstraints();
gbl_chartPanel.anchor = GridBagConstraints.CENTER;
gbl_chartPanel.insets = new Insets(3, 3, 3, 3);
gbl_chartPanel.weightx = 1.0;
gbl_chartPanel.weighty = 1.0;
gbl_chartPanel.fill = GridBagConstraints.BOTH;
gbl_chartPanel.gridx = 0;
gbl_chartPanel.gridy = 1;
plotPanel.add(chartPanel, gbl_chartPanel);
XYDotRenderer dotRenderer = new XYDotRenderer();
dotRenderer.setSeriesPaint(0, new Color(0, 51, 102));
dotRenderer.setDotHeight(3);
dotRenderer.setDotWidth(3);
XYLineAndShapeRenderer lineRenderer = new XYLineAndShapeRenderer();
lineRenderer.setUseFillPaint(true);
lineRenderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT, new DecimalFormat("0.00"), new DecimalFormat("0.00")));
Stroke stroke = new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, null, 0.0f);
lineRenderer.setSeriesStroke(0, stroke);
lineRenderer.setSeriesPaint(0, Color.RED);
lineRenderer.setSeriesShape(0, ShapeUtilities.createDiamond((float) 2.5));
lineRenderer.setLegendItemLabelGenerator(new StandardXYSeriesLabelGenerator() {
private static final long serialVersionUID = 7593430826693873496L;
public String generateLabel(XYDataset dataset, int series) {
XYSeries xys = ((XYSeriesCollection) dataset).getSeries(series);
return xys.getDescription();
}
});
NumberAxis xAxis = new NumberAxis(xAxisName);
xAxis.setAutoRangeIncludesZero(false);
NumberAxis yAxis = new NumberAxis(yAxisName);
yAxis.setAutoRangeIncludesZero(false);
XYSeriesCollection scatterDataset = new XYSeriesCollection(runData);
XYSeriesCollection lineDataset = new XYSeriesCollection();
trendData.setDescription(trendDataName);
lineDataset.addSeries(trendData);
XYPlot plot = chart.getXYPlot();
plot.setRangePannable(true);
plot.setDomainPannable(true);
plot.setDomainGridlinePaint(Color.DARK_GRAY);
plot.setRangeGridlinePaint(Color.DARK_GRAY);
plot.setBackgroundPaint(new Color(224, 224, 224));
plot.setDataset(0, lineDataset);
plot.setRenderer(0, lineRenderer);
plot.setDomainAxis(0, xAxis);
plot.setRangeAxis(0, yAxis);
plot.mapDatasetToDomainAxis(0, 0);
plot.mapDatasetToRangeAxis(0, 0);
plot.setDataset(1, scatterDataset);
plot.setRenderer(1, dotRenderer);
plot.mapDatasetToDomainAxis(1, 0);
plot.mapDatasetToRangeAxis(1, 0);
LegendTitle legend = new LegendTitle(plot.getRenderer());
legend.setItemFont(new Font("Arial", 0, 10));
legend.setPosition(RectangleEdge.TOP);
chart.addLegend(legend);
}
use of org.jfree.chart.axis.NumberAxis in project mafscaling by vimsh.
the class LogView method viewWotPlotsByRpm.
private void viewWotPlotsByRpm(boolean skipDrops) {
getWotYAxisGroups();
if (wotYAxisGroups.size() == 0) {
JOptionPane.showMessageDialog(null, "Please select columns to plot", "Invalid parameters", JOptionPane.ERROR_MESSAGE);
return;
}
clearWotPlots();
ArrayList<HashMap<String, ArrayList<Double>>> filePulls;
HashMap<String, ArrayList<Double>> pullData;
ArrayList<Double> rpmData;
ArrayList<Double> colData;
DefaultMutableTreeNode fileNode;
CheckBoxNodeData pullNode;
String fileName;
String pullName;
int pullIdx;
setCursor(new Cursor(Cursor.WAIT_CURSOR));
try {
for (int i = 0; i < wotYAxisGroups.size(); ++i) {
TreeSet<String> group = wotYAxisGroups.get(i);
XYSeriesCollection dataset = new XYSeriesCollection();
String yAxisName = "";
for (String yAxisColName : group) {
yAxisName += (yAxisName.isEmpty() ? yAxisColName : ", " + yAxisColName);
DefaultMutableTreeNode root = (DefaultMutableTreeNode) wotTree.getModel().getRoot();
for (int idx = 0; idx < root.getChildCount(); ++idx) {
fileNode = (DefaultMutableTreeNode) root.getChildAt(idx);
fileName = fileNode.getUserObject().toString().replaceAll(fileNameReplaceString, "");
for (int j = 0; j < fileNode.getChildCount(); ++j) {
pullNode = (CheckBoxNodeData) ((DefaultMutableTreeNode) fileNode.getChildAt(j)).getUserObject();
if (!pullNode.isChecked())
continue;
pullName = pullNode.getText();
filePulls = filesData.get(fileName);
pullIdx = Integer.parseInt(pullName.replaceAll(pullIndexReplaceString, "")) - 1;
pullData = filePulls.get(pullIdx);
rpmData = pullData.get(logRpmColName);
colData = pullData.get(yAxisColName);
if (colData != null) {
pullName = yAxisColName + " [" + pullName + ": " + fileName + "]";
XYSeries series = new XYSeries(pullName);
series.setDescription(pullName);
for (int k = 0; k < rpmData.size(); ++k) {
if (skipDrops) {
if (k > 0 && rpmData.get(k) > rpmData.get(k - 1))
series.add(Double.valueOf(rpmData.get(k)), Double.valueOf(colData.get(k)));
} else
series.add(Double.valueOf(rpmData.get(k)), Double.valueOf(colData.get(k)));
}
dataset.addSeries(series);
}
}
}
}
NumberAxis yAxis = new NumberAxis(yAxisName);
yAxis.setAutoRangeIncludesZero(false);
yAxis.setTickLabelPaint(Color.WHITE);
yAxis.setLabelPaint(Color.LIGHT_GRAY);
XYLineAndShapeRenderer lineRenderer = new XYLineAndShapeRenderer();
lineRenderer.setBaseShapesVisible(showWotCurvePoints);
wotPlot.setRenderer(i, lineRenderer);
wotPlot.setRangeAxis(i, yAxis, false);
wotPlot.setDataset(i, dataset);
wotPlot.mapDatasetToRangeAxis(i, i);
wotPlot.mapDatasetToDomainAxis(i, 0);
wotPlot.setRangeAxisLocation(i, (i % 2 == 0 ? AxisLocation.BOTTOM_OR_LEFT : AxisLocation.BOTTOM_OR_RIGHT));
}
} finally {
setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
}
}
use of org.jfree.chart.axis.NumberAxis in project mafscaling by vimsh.
the class LogView method createGraghPanel.
private void createGraghPanel() {
JFreeChart chart = ChartFactory.createXYLineChart(null, null, null, null, PlotOrientation.VERTICAL, false, true, false);
chartPanel = new ChartPanel(chart, true, true, true, true, true);
chartPanel.setFocusable(true);
chartPanel.setAutoscrolls(true);
chartPanel.setPopupMenu(null);
chart.setBackgroundPaint(chartColor);
rpmDataset = new XYSeriesCollection();
rpmPlotRenderer = new XYLineAndShapeRenderer();
dataset = new XYSeriesCollection();
plotRenderer = new XYLineAndShapeRenderer();
NumberAxis xAxis = new NumberAxis();
xAxis.setTickLabelsVisible(false);
xAxis.setTickLabelPaint(Color.WHITE);
xAxis.setAutoRangeIncludesZero(false);
NumberAxis yAxis = new NumberAxis();
yAxis.setTickLabelsVisible(false);
yAxis.setTickLabelPaint(Color.WHITE);
yAxis.setAutoRangeIncludesZero(false);
NumberAxis y2Axis = new NumberAxis();
y2Axis.setTickLabelsVisible(false);
y2Axis.setTickLabelPaint(Color.WHITE);
y2Axis.setAutoRangeIncludesZero(false);
plot = chartPanel.getChart().getXYPlot();
plot.setRangePannable(true);
plot.setDomainPannable(true);
plot.setDomainGridlinePaint(Color.LIGHT_GRAY);
plot.setRangeGridlinePaint(Color.LIGHT_GRAY);
plot.setBackgroundPaint(chartBgColor);
plot.setDataset(0, rpmDataset);
plot.setRenderer(0, rpmPlotRenderer);
plot.setDomainAxis(0, xAxis);
plot.setRangeAxis(0, yAxis);
plot.mapDatasetToDomainAxis(0, 0);
plot.mapDatasetToRangeAxis(0, 0);
plot.setDataset(1, dataset);
plot.setRenderer(1, plotRenderer);
plot.setRangeAxis(1, y2Axis);
plot.mapDatasetToDomainAxis(1, 0);
plot.mapDatasetToRangeAxis(1, 1);
LegendTitle legend = new LegendTitle(plot);
legend.setItemFont(new Font("Arial", 0, 10));
legend.setPosition(RectangleEdge.TOP);
legend.setItemPaint(Color.WHITE);
chart.addLegend(legend);
xMarker = new XYDomainMutilineAnnotation();
xMarker.setDefaultPaint(Color.WHITE);
plot.addAnnotation(xMarker);
chartMouseListener = new ChartMouseListener() {
@Override
public void chartMouseMoved(ChartMouseEvent event) {
try {
Rectangle2D dataArea = chartPanel.getChartRenderingInfo().getPlotInfo().getDataArea();
Point2D p = chartPanel.translateScreenToJava2D(event.getTrigger().getPoint());
double x = plot.getDomainAxis().java2DToValue(p.getX(), dataArea, plot.getDomainAxisEdge());
boolean isLeft = (p.getX() < (dataArea.getMaxX() - dataArea.getMinX()) / 2) ? true : false;
if (setMarkers(x, isLeft)) {
try {
int selectedCol = logDataTable.getTable().getSelectedColumn();
if (selectedCol < 0)
selectedCol = 0;
if (logPlayWindow == null || startMarker != null || endMarker != null) {
logDataTable.getTable().setRowSelectionInterval((int) x, (int) x);
logDataTable.getTable().changeSelection((int) x, selectedCol, false, false);
} else {
logPlayWindow.setProgressBar((int) x);
}
} catch (Exception e) {
e.printStackTrace();
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void chartMouseClicked(ChartMouseEvent event) {
chartPanel.requestFocusInWindow();
if (logPlayWindow == null)
return;
if (xMarker.count() == 0)
return;
Rectangle2D dataArea = chartPanel.getChartRenderingInfo().getPlotInfo().getDataArea();
Point2D p = chartPanel.translateScreenToJava2D(event.getTrigger().getPoint());
double x = plot.getDomainAxis().java2DToValue(p.getX(), dataArea, plot.getDomainAxisEdge());
if (x < 0 || (int) x >= logDataTable.getRowCount())
return;
if (SwingUtilities.isLeftMouseButton(event.getTrigger())) {
if (startMarker == null) {
startMarker = new ValueMarker(x);
startMarker.setPaint(Color.GREEN);
startMarker.setStroke(new BasicStroke(1.5f));
plot.addDomainMarker(startMarker);
} else {
plot.removeDomainMarker(startMarker);
startMarker = null;
}
} else if (SwingUtilities.isRightMouseButton(event.getTrigger())) {
if (endMarker == null) {
endMarker = new ValueMarker(x);
endMarker.setPaint(Color.GREEN);
endMarker.setStroke(new BasicStroke(1.5f));
plot.addDomainMarker(endMarker);
} else {
plot.removeDomainMarker(endMarker);
endMarker = null;
}
}
chartPanel.repaint();
logPlayWindow.setStartEndArea(startMarker, endMarker);
}
};
chartPanel.addChartMouseListener(chartMouseListener);
chartPanel.addKeyListener(new KeyListener() {
public void keyPressed(KeyEvent e) {
if (!chartPanel.hasFocus())
return;
int keyCode = e.getKeyCode();
if (keyCode < KeyEvent.VK_LEFT || keyCode > KeyEvent.VK_DOWN)
return;
ValueAxis axis = null;
if (keyCode == KeyEvent.VK_LEFT || keyCode == KeyEvent.VK_RIGHT)
axis = ((XYPlot) chartPanel.getChart().getXYPlot()).getDomainAxis();
else
axis = ((XYPlot) chartPanel.getChart().getXYPlot()).getRangeAxis();
if (axis != null) {
double delta = (axis.getUpperBound() - axis.getLowerBound()) / 100.0;
if (keyCode == KeyEvent.VK_LEFT || keyCode == KeyEvent.VK_DOWN)
axis.setRange(axis.getLowerBound() - delta, axis.getUpperBound() - delta);
else if (keyCode == KeyEvent.VK_UP || keyCode == KeyEvent.VK_RIGHT)
axis.setRange(axis.getLowerBound() + delta, axis.getUpperBound() + delta);
}
}
public void keyReleased(KeyEvent arg0) {
}
public void keyTyped(KeyEvent arg0) {
}
});
}
use of org.jfree.chart.axis.NumberAxis in project mafscaling by vimsh.
the class LogView method viewWotPlotsByTime.
private void viewWotPlotsByTime() {
getWotYAxisGroups();
if (wotYAxisGroups.size() == 0) {
JOptionPane.showMessageDialog(null, "Please select columns to plot", "Invalid parameters", JOptionPane.ERROR_MESSAGE);
return;
}
clearWotPlots();
ArrayList<HashMap<String, ArrayList<Double>>> filePulls;
HashMap<String, ArrayList<Double>> pullData;
ArrayList<Double> rpmData;
ArrayList<Double> timeData;
ArrayList<Double> colData = null;
DefaultMutableTreeNode fileNode;
CheckBoxNodeData pullNode;
String fileName;
String pullName;
int pullIdx;
int idx;
int rpm;
int maxrpm = 0;
double time = 0;
double newtime = 0;
double maxtime = 0;
double timeOffset = 0;
setCursor(new Cursor(Cursor.WAIT_CURSOR));
try {
// sort all pulls by RPM
TreeMap<Integer, ArrayList<HashMap<String, HashMap<String, ArrayList<Double>>>>> pullsByRpm = new TreeMap<Integer, ArrayList<HashMap<String, HashMap<String, ArrayList<Double>>>>>();
ArrayList<HashMap<String, HashMap<String, ArrayList<Double>>>> pulls;
DefaultMutableTreeNode root = (DefaultMutableTreeNode) wotTree.getModel().getRoot();
for (idx = 0; idx < root.getChildCount(); ++idx) {
fileNode = (DefaultMutableTreeNode) root.getChildAt(idx);
fileName = fileNode.getUserObject().toString().replaceAll(fileNameReplaceString, "");
for (int j = 0; j < fileNode.getChildCount(); ++j) {
pullNode = (CheckBoxNodeData) ((DefaultMutableTreeNode) fileNode.getChildAt(j)).getUserObject();
if (!pullNode.isChecked())
continue;
pullName = pullNode.getText();
filePulls = filesData.get(fileName);
pullIdx = Integer.parseInt(pullName.replaceAll(pullIndexReplaceString, "")) - 1;
pullData = filePulls.get(pullIdx);
pullName = " [" + pullName + ": " + fileName + "]";
HashMap<String, HashMap<String, ArrayList<Double>>> pullDataByName = new HashMap<String, HashMap<String, ArrayList<Double>>>();
pullDataByName.put(pullName, pullData);
rpmData = pullData.get(logRpmColName);
rpm = rpmData.get(0).intValue();
pulls = pullsByRpm.get(rpm);
if (pulls == null) {
pulls = new ArrayList<HashMap<String, HashMap<String, ArrayList<Double>>>>();
pullsByRpm.put(rpm, pulls);
}
pulls.add(pullDataByName);
}
}
// Reset pulls time by aligning RPM
ArrayList<HashMap<String, HashMap<String, ArrayList<Double>>>> allpulls = new ArrayList<HashMap<String, HashMap<String, ArrayList<Double>>>>();
while (pullsByRpm.size() > 0) {
time = newtime;
newtime = 0;
rpm = pullsByRpm.firstKey();
maxrpm = rpm;
pulls = pullsByRpm.remove(rpm);
for (idx = 0; idx < pulls.size(); ++idx) {
pullData = (pulls.get(idx)).entrySet().iterator().next().getValue();
rpmData = pullData.get(logRpmColName);
timeData = pullData.get(logTimeColName);
colData = new ArrayList<Double>();
for (int j = 0; j < rpmData.size(); ++j) {
double tm = timeData.get(j);
if (j == 0)
timeOffset = tm - time;
tm = tm - timeOffset;
colData.add(tm);
rpm = rpmData.get(j).intValue();
if (pullsByRpm.size() > 0 && newtime == 0 && rpm >= pullsByRpm.firstKey())
newtime = tm;
}
maxrpm = Math.max(maxrpm, rpmData.get(rpmData.size() - 1).intValue());
maxtime = Math.max(maxtime, colData.get(colData.size() - 1));
pullData.put("xaxis", colData);
}
if (pullsByRpm.size() > 0 && newtime == 0)
newtime = (maxtime * pullsByRpm.firstKey()) / maxrpm;
allpulls.addAll(pulls);
}
// Plot data
for (int i = 0; i < wotYAxisGroups.size(); ++i) {
TreeSet<String> group = wotYAxisGroups.get(i);
XYSeriesCollection dataset = new XYSeriesCollection();
String yAxisName = "";
for (String yAxisColName : group) {
yAxisName += (yAxisName.isEmpty() ? yAxisColName : ", " + yAxisColName);
for (idx = 0; idx < allpulls.size(); ++idx) {
Map.Entry<String, HashMap<String, ArrayList<Double>>> keyval = allpulls.get(idx).entrySet().iterator().next();
pullName = yAxisColName + keyval.getKey();
pullData = keyval.getValue();
timeData = pullData.get("xaxis");
colData = pullData.get(yAxisColName);
if (colData != null) {
XYSeries series = new XYSeries(pullName);
series.setDescription(pullName);
for (int k = 0; k < timeData.size(); ++k) series.add(Double.valueOf(timeData.get(k)), Double.valueOf(colData.get(k)));
dataset.addSeries(series);
}
}
}
NumberAxis yAxis = new NumberAxis(yAxisName);
yAxis.setAutoRangeIncludesZero(false);
yAxis.setTickLabelPaint(Color.WHITE);
yAxis.setLabelPaint(Color.LIGHT_GRAY);
XYLineAndShapeRenderer lineRenderer = new XYLineAndShapeRenderer();
lineRenderer.setBaseShapesVisible(showWotCurvePoints);
wotPlot.setRenderer(i, lineRenderer);
wotPlot.setRangeAxis(i, yAxis, false);
wotPlot.setDataset(i, dataset);
wotPlot.mapDatasetToRangeAxis(i, i);
wotPlot.mapDatasetToDomainAxis(i, 0);
wotPlot.setRangeAxisLocation(i, (i % 2 == 0 ? AxisLocation.BOTTOM_OR_LEFT : AxisLocation.BOTTOM_OR_RIGHT));
}
} finally {
setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
}
}
Aggregations