Several bug fixes and small improvements
This commit is contained in:
@@ -17,9 +17,11 @@ public class LinePlotSeries extends PlotSeries<LinePlot> {
|
||||
|
||||
void onSeriesAppendData(LinePlotSeries series, double x, double y);
|
||||
}
|
||||
|
||||
public LinePlotSeries(String name) {
|
||||
this(name, SwingUtils.generateRandomColor());
|
||||
//If create a random color in none is provided - but it is deterministic if name is provided
|
||||
this(name, ((name!=null)&& (name.length()>0)) ?
|
||||
SwingUtils.generateRandomColor(name.hashCode()) :
|
||||
SwingUtils.generateRandomColor());
|
||||
}
|
||||
|
||||
public LinePlotSeries(String name, Color color) {
|
||||
|
||||
@@ -132,7 +132,7 @@ public class MatrixPlotSeries extends PlotSeries<MatrixPlot> {
|
||||
|
||||
//Utilities
|
||||
public boolean contains(int indexX, int indexY) {
|
||||
return ((indexX <= numberOfBinsX) && (indexX >= 0) && (indexY <= numberOfBinsY) && (indexY >= 0));
|
||||
return ((indexX < numberOfBinsX) && (indexX >= 0) && (indexY < numberOfBinsY) && (indexY >= 0));
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -29,9 +29,13 @@ abstract public class PlotBase<T extends PlotSeries> implements Plot<T> {
|
||||
|
||||
final String LINE_SEPARATOR = System.lineSeparator();
|
||||
final String FIELD_SEPARATOR = "\t";
|
||||
|
||||
protected static final int PREFERRED_WIDTH = 500;
|
||||
protected static final int PREFERRED_HEIGHT = 270;
|
||||
|
||||
|
||||
final Class seriesType;
|
||||
|
||||
|
||||
protected PlotBase(Class<T> seriesType) {
|
||||
this(seriesType, null);
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ import java.awt.BorderLayout;
|
||||
import java.awt.Component;
|
||||
import java.awt.Dimension;
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
@@ -142,11 +143,11 @@ public class LinePlot extends ch.psi.plot.LinePlotBase {
|
||||
}
|
||||
}
|
||||
|
||||
private static JFXPanel fxContainer;
|
||||
private JFXPanel fxContainer;
|
||||
|
||||
@Override
|
||||
protected JPanel createChartPanel() {
|
||||
fxContainer.setPreferredSize(new Dimension(480, 240));
|
||||
fxContainer.setPreferredSize(new Dimension(PREFERRED_WIDTH, PREFERRED_HEIGHT));
|
||||
JPanel panel = new JPanel();
|
||||
panel.setLayout(new BorderLayout());
|
||||
panel.add(fxContainer);
|
||||
@@ -300,7 +301,8 @@ public class LinePlot extends ch.psi.plot.LinePlotBase {
|
||||
AnimationTimer mTimerFX;
|
||||
|
||||
void onTimerFX(long start) {
|
||||
|
||||
//if (!isUpdatesEnabled())
|
||||
// return;
|
||||
synchronized (seriesList) {
|
||||
for (Iterator<Series> it = seriesList.keySet().iterator(); it.hasNext();) {
|
||||
XYChart.Series series = it.next();
|
||||
@@ -394,12 +396,15 @@ public class LinePlot extends ch.psi.plot.LinePlotBase {
|
||||
}
|
||||
|
||||
void removeSeriesFromChart() {
|
||||
ArrayList<XYChart.Series> list=new ArrayList<>();
|
||||
for (Iterator<Series<Number, Number>> it = chart.getData().iterator(); it.hasNext();) {
|
||||
XYChart.Series series = it.next();
|
||||
if (!seriesList.keySet().contains(series)) {
|
||||
chart.getData().remove(series);
|
||||
list.add(series);
|
||||
}
|
||||
}
|
||||
for (XYChart.Series series:list)
|
||||
chart.getData().remove(series);
|
||||
}
|
||||
|
||||
boolean isPlottingSeries(Series series) {
|
||||
|
||||
@@ -49,9 +49,6 @@ public class LinePlot extends LinePlotBase {
|
||||
|
||||
private ChartPanel chartPanel;
|
||||
|
||||
private static final int chartPanelWidth = 500;
|
||||
private static final int chartPanelHeight = 270;
|
||||
|
||||
//Defining Context Menu Label
|
||||
private static final String showLegendMenuLabel = "Show Legend";
|
||||
private static final String hideLegendMenuLabel = "Hide Legend";
|
||||
@@ -186,7 +183,7 @@ public class LinePlot extends LinePlotBase {
|
||||
chartPanel.getChart().setBorderVisible(false);
|
||||
|
||||
// Set size of chart
|
||||
chartPanel.setPreferredSize(new java.awt.Dimension(chartPanelWidth, chartPanelHeight));
|
||||
chartPanel.setPreferredSize(new java.awt.Dimension(PREFERRED_WIDTH, PREFERRED_HEIGHT));
|
||||
|
||||
// Add more items to the context menu
|
||||
amendContextMenu();
|
||||
|
||||
@@ -35,9 +35,6 @@ import org.jfree.ui.RectangleInsets;
|
||||
*/
|
||||
public class MatrixPlot extends MatrixPlotBase {
|
||||
|
||||
private static final int chartPanelWidth = 500;
|
||||
private static final int chartPanelHeight = 270;
|
||||
|
||||
private boolean grayScale = false;
|
||||
|
||||
private MatrixPlotSeries series;
|
||||
@@ -448,7 +445,7 @@ public class MatrixPlot extends MatrixPlotBase {
|
||||
//Create the Chartpanel where the chart will be plotted
|
||||
chartPanel = new ChartPanel(chart);
|
||||
|
||||
chartPanel.setPreferredSize(new java.awt.Dimension(chartPanelWidth, chartPanelHeight));
|
||||
chartPanel.setPreferredSize(new java.awt.Dimension(PREFERRED_WIDTH, PREFERRED_HEIGHT));
|
||||
|
||||
//All interactive menu items
|
||||
adaptContextMenu(chartPanel);
|
||||
|
||||
@@ -123,9 +123,12 @@ public class LinePlot extends LinePlotBase {
|
||||
@Override
|
||||
protected void onAppendData(LinePlotSeries series, double x, double y) {
|
||||
JLDataView view = getDataView(series);
|
||||
if (view != null) //view.add(x, y);
|
||||
if (view != null)
|
||||
{
|
||||
plot.addData(view, x, y);
|
||||
if (isUpdatesEnabled())
|
||||
plot.addData(view, x, y);
|
||||
else
|
||||
view.add(x, y);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -168,7 +171,7 @@ public class LinePlot extends LinePlotBase {
|
||||
|
||||
chartPanel.setLayout(new BorderLayout());
|
||||
chartPanel.add(plot);
|
||||
chartPanel.setPreferredSize(new Dimension(480, 240));
|
||||
chartPanel.setPreferredSize(new Dimension(PREFERRED_WIDTH, PREFERRED_HEIGHT));
|
||||
|
||||
plot.setHeader(getTitle());
|
||||
plot.getY1Axis().setName(getAxis(AxisId.Y).getLabel());
|
||||
|
||||
@@ -87,9 +87,16 @@ public class MatrixPlot extends MatrixPlotBase {
|
||||
panel = new MonitoredPanel() {
|
||||
@Override
|
||||
protected void onShown() {
|
||||
if ((chart == null) && (series != null)) {
|
||||
createGraph();
|
||||
}
|
||||
// if ((chart == null) && (series != null)) {
|
||||
if (series != null) {
|
||||
SwingUtilities.invokeLater(new Runnable() { //Invoking later because was not rendering when setting date with FDA
|
||||
@Override
|
||||
public void run() {
|
||||
createGraph();
|
||||
}
|
||||
});
|
||||
}
|
||||
else
|
||||
checkBounds(true);
|
||||
}
|
||||
|
||||
@@ -108,7 +115,7 @@ public class MatrixPlot extends MatrixPlotBase {
|
||||
if (getHardwareAccelerated() != Settings.getInstance().isHardwareAccelerated()) {
|
||||
Settings.getInstance().setHardwareAccelerated(getHardwareAccelerated());
|
||||
}
|
||||
panel.setPreferredSize(new Dimension(640, 480));
|
||||
panel.setPreferredSize(new Dimension(PREFERRED_WIDTH, PREFERRED_HEIGHT));
|
||||
setupPopupMenu();
|
||||
}
|
||||
|
||||
@@ -142,16 +149,26 @@ public class MatrixPlot extends MatrixPlotBase {
|
||||
series = null;
|
||||
data = null;
|
||||
} else {
|
||||
if (getAxis(AxisId.X).isAutoRange()) {
|
||||
// if (getAxis(AxisId.X).isAutoRange()) {
|
||||
rangeX = new Range(s.getMinX(), s.getMaxX());
|
||||
} else {
|
||||
rangeX = new Range(getAxis(AxisId.X).getMin(), getAxis(AxisId.X).getMax());
|
||||
}
|
||||
if (getAxis(AxisId.Y).isAutoRange()) {
|
||||
// } else {
|
||||
// rangeX = new Range(getAxis(AxisId.X).getMin(), getAxis(AxisId.X).getMax());
|
||||
// }
|
||||
// if (getAxis(AxisId.Y).isAutoRange()) {
|
||||
rangeY = new Range(s.getMinY(), s.getMaxY());
|
||||
} else {
|
||||
rangeY = new Range(getAxis(AxisId.Y).getMin(), getAxis(AxisId.Y).getMax());
|
||||
}
|
||||
// } else {
|
||||
// rangeY = new Range(getAxis(AxisId.Y).getMin(), getAxis(AxisId.Y).getMax());
|
||||
// }
|
||||
/*
|
||||
if (!getHideEmptyRows ()){
|
||||
if (getAxis(AxisId.X).isAutoRange()){
|
||||
getAxis(AxisId.X).setRange(s.getMinX(), s.getMaxX());
|
||||
}
|
||||
if (getAxis(AxisId.Y).isAutoRange()){
|
||||
getAxis(AxisId.Y).setRange(s.getMinY(), s.getMaxY());
|
||||
}
|
||||
}
|
||||
*/
|
||||
//If same series & same dimensions then preserve data
|
||||
if ((data == null) || (series != s) || (s.getNumberOfBinsY() != data.length) || (s.getNumberOfBinsX() != data[0].length)) {
|
||||
data = new double[s.getNumberOfBinsY()][s.getNumberOfBinsX()];
|
||||
@@ -162,7 +179,9 @@ public class MatrixPlot extends MatrixPlotBase {
|
||||
series = s;
|
||||
}
|
||||
}
|
||||
createGraph();
|
||||
if ((panel != null) && (panel.isShowing())) {
|
||||
createGraph();
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -193,7 +212,8 @@ public class MatrixPlot extends MatrixPlotBase {
|
||||
|
||||
@Override
|
||||
public void doUpdate() {
|
||||
updateGraph(false);
|
||||
//createGraph();
|
||||
updateGraph(true);
|
||||
}
|
||||
|
||||
public void updateSeries(MatrixPlotSeries s) {
|
||||
@@ -279,7 +299,9 @@ public class MatrixPlot extends MatrixPlotBase {
|
||||
public void setContinuousRendering(boolean value) {
|
||||
if (value != continuousRendering) {
|
||||
continuousRendering = value;
|
||||
createGraph();
|
||||
if ((panel != null) && (panel.isShowing())) {
|
||||
createGraph();
|
||||
}
|
||||
}
|
||||
}
|
||||
public boolean getContinuousRendering() {
|
||||
@@ -332,7 +354,9 @@ public class MatrixPlot extends MatrixPlotBase {
|
||||
public void setQuality(Quality quality) {
|
||||
this.quality = quality;
|
||||
if (series != null) {
|
||||
createGraph();
|
||||
if ((panel != null) && (panel.isShowing())) {
|
||||
createGraph();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -385,7 +409,9 @@ public class MatrixPlot extends MatrixPlotBase {
|
||||
public void setContour(Contour contour) {
|
||||
this.contour = contour;
|
||||
if (series != null) {
|
||||
createGraph();
|
||||
if ((panel != null) && (panel.isShowing())) {
|
||||
createGraph();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -425,6 +451,21 @@ public class MatrixPlot extends MatrixPlotBase {
|
||||
public java.awt.Color getFrameColor() {
|
||||
return frameColor;
|
||||
}
|
||||
|
||||
boolean hideEmptyRows = true;
|
||||
|
||||
/**
|
||||
* By default empty lines (containing only NaN) are not plotted.
|
||||
*/
|
||||
public void setHideEmptyRows(boolean value) {
|
||||
hideEmptyRows = value;
|
||||
updateGraph(true);
|
||||
}
|
||||
|
||||
public boolean getHideEmptyRows() {
|
||||
return hideEmptyRows;
|
||||
}
|
||||
|
||||
|
||||
JPopupMenu menuPopup;
|
||||
|
||||
@@ -435,6 +476,7 @@ public class MatrixPlot extends MatrixPlotBase {
|
||||
final JCheckBoxMenuItem menuShowLegend = new JCheckBoxMenuItem("Show Legend");
|
||||
final JCheckBoxMenuItem menuShowFace = new JCheckBoxMenuItem("Show Face");
|
||||
final JCheckBoxMenuItem menuShowFrame = new JCheckBoxMenuItem("Show Frame");
|
||||
//final JCheckBoxMenuItem menuHideEmptyRows = new JCheckBoxMenuItem("Hide Empty Rows");
|
||||
//final JCheckBoxMenuItem menuContinuous = new JCheckBoxMenuItem("Continuous Rendering");
|
||||
JMenuItem frameColor = new JMenuItem("Set Frame Color");
|
||||
|
||||
@@ -446,6 +488,7 @@ public class MatrixPlot extends MatrixPlotBase {
|
||||
menuPopup.add(menuShowLegend);
|
||||
menuPopup.add(menuShowFace);
|
||||
menuPopup.add(menuShowFrame);
|
||||
//menuPopup.add(menuHideEmptyRows);
|
||||
//menuPopup.add(menuContinuous);
|
||||
menuPopup.add(frameColor);
|
||||
menuPopup.add(menuColormap);
|
||||
@@ -456,7 +499,7 @@ public class MatrixPlot extends MatrixPlotBase {
|
||||
menuUpdate.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
try {
|
||||
updateGraph(true);
|
||||
update(true);
|
||||
} catch (Exception ex) {
|
||||
}
|
||||
}
|
||||
@@ -504,7 +547,15 @@ public class MatrixPlot extends MatrixPlotBase {
|
||||
}
|
||||
});
|
||||
menuContinuous.setSelected(getShowFrame());
|
||||
menuHideEmptyRows.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
setHideEmptyRows(!getHideEmptyRows());
|
||||
menuHideEmptyRows.setSelected(getHideEmptyRows());
|
||||
}
|
||||
});
|
||||
menuHideEmptyRows.setSelected(getHideEmptyRows());
|
||||
*/
|
||||
|
||||
menuShowLegend.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
setShowLegend(!getShowLegend());
|
||||
@@ -675,7 +726,6 @@ public class MatrixPlot extends MatrixPlotBase {
|
||||
return ret;
|
||||
}
|
||||
};
|
||||
|
||||
animatorControl = null;
|
||||
screenCanvas=null;
|
||||
Component canvas = (Component) chart.getCanvas();
|
||||
@@ -802,6 +852,8 @@ public class MatrixPlot extends MatrixPlotBase {
|
||||
}
|
||||
//long start = System.currentTimeMillis();
|
||||
synchronized (chartLock) {
|
||||
if (chart==null)
|
||||
return;
|
||||
Shape former = surface;
|
||||
if (series == null) {
|
||||
if (surface != null) {
|
||||
@@ -831,10 +883,10 @@ public class MatrixPlot extends MatrixPlotBase {
|
||||
surface.setLegend(cbar);
|
||||
}
|
||||
|
||||
if (getContour() != Contour.NONE) {
|
||||
if (getContour() != Contour.NONE) {
|
||||
int xRes = getContourDensity();
|
||||
int yRes = getContourDensity();
|
||||
|
||||
|
||||
MapperContourPictureGenerator contour = new MapperContourPictureGenerator(mapper, rangeX, rangeY);
|
||||
IContourColoringPolicy policy = new DefaultContourColoringPolicy(colorMapper);
|
||||
ContourAxeBox cab = (getContour() == Contour.CONTOUR_3D) ? null : (ContourAxeBox) chart.getView().getAxe();
|
||||
@@ -862,7 +914,8 @@ public class MatrixPlot extends MatrixPlotBase {
|
||||
for (int x = 0; x < xRes; x++) {
|
||||
for (int y = 0; y < yRes; y++) {
|
||||
float px = (float) ((float) x * dx * series.getBinWidthX() + series.getMinX());
|
||||
float py = (float) ((float) y * dy * series.getBinWidthY() + series.getMinY());
|
||||
//float py = (float) ((float) y * dy * series.getBinWidthY() + series.getMinY());
|
||||
float py = (float) (series.getMaxY() - (float) y * dy * series.getBinWidthY());
|
||||
|
||||
if (contours[x][y] > -Double.MAX_VALUE) { // Non contours points are -Double.MAX_VALUE and are not painted
|
||||
points[x * yRes + y] = new Coord3d(px, py, (float) contours[x][y]);
|
||||
@@ -909,32 +962,59 @@ public class MatrixPlot extends MatrixPlotBase {
|
||||
return false;
|
||||
}
|
||||
boolean changed = false;
|
||||
boolean hasContour=(getContour() != Contour.NONE) ;
|
||||
boolean auto_range = getAxis(AxisId.X).isAutoRange() && getAxis(AxisId.Y).isAutoRange() && getAxis(AxisId.Z).isAutoRange();
|
||||
boolean force_series_range = getAxis(AxisId.X).isAutoRange() && getAxis(AxisId.Y).isAutoRange() && (!getHideEmptyRows());
|
||||
boolean manual_bounds= (!auto_range) || hasContour || force_series_range;
|
||||
|
||||
//If manual bounds
|
||||
if (!getAxis(AxisId.X).isAutoRange() || !getAxis(AxisId.Y).isAutoRange() || !getAxis(AxisId.Z).isAutoRange()) {
|
||||
if ( manual_bounds) {
|
||||
//Deferring setting bounds untiul the panel is displayed
|
||||
if (panel.isShowing() && (chart != null)) {
|
||||
if (chart.getView().getBoundsMode() != ViewBoundMode.MANUAL) {
|
||||
changed = true;
|
||||
}
|
||||
BoundingBox3d bounds = chart.getView().getBounds();
|
||||
if (!getAxis(AxisId.X).isAutoRange()) {
|
||||
if (bounds.getXmin() != getAxis(AxisId.X).getMin()) {
|
||||
bounds.setXmin((float) getAxis(AxisId.X).getMin());
|
||||
if (hasContour || force_series_range){
|
||||
//TODO: Auto-range will not plot points=NaN, and bounds can be smaller. It will break the contour plot.
|
||||
//Cant I find a way to plot only the visible contour instead of foercing the full range?
|
||||
if (bounds.getXmin() != rangeX.getMin()) {
|
||||
bounds.setXmin((float) rangeX.getMin());
|
||||
changed = true;
|
||||
}
|
||||
if (bounds.getXmax() != getAxis(AxisId.X).getMax()) {
|
||||
bounds.setXmax((float) getAxis(AxisId.X).getMax());
|
||||
if (bounds.getXmax() != rangeX.getMax()) {
|
||||
bounds.setXmax((float) rangeX.getMax());
|
||||
changed = true;
|
||||
}
|
||||
if (bounds.getYmin() != rangeY.getMin()) {
|
||||
bounds.setYmin((float) rangeY.getMin());
|
||||
changed = true;
|
||||
}
|
||||
if (bounds.getYmax() != rangeY.getMax()) {
|
||||
bounds.setYmax((float) rangeY.getMax());
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
if (!getAxis(AxisId.Y).isAutoRange()) {
|
||||
if (bounds.getYmin() != getAxis(AxisId.Y).getMin()) {
|
||||
bounds.setYmin((float) getAxis(AxisId.Y).getMin());
|
||||
changed = true;
|
||||
else {
|
||||
if (!getAxis(AxisId.X).isAutoRange()) {
|
||||
if (bounds.getXmin() != getAxis(AxisId.X).getMin()) {
|
||||
bounds.setXmin((float) getAxis(AxisId.X).getMin());
|
||||
changed = true;
|
||||
}
|
||||
if (bounds.getXmax() != getAxis(AxisId.X).getMax()) {
|
||||
bounds.setXmax((float) getAxis(AxisId.X).getMax());
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
if (bounds.getYmax() != getAxis(AxisId.Y).getMax()) {
|
||||
bounds.setYmax((float) getAxis(AxisId.Y).getMax());
|
||||
changed = true;
|
||||
if (!getAxis(AxisId.Y).isAutoRange()) {
|
||||
if (bounds.getYmin() != getAxis(AxisId.Y).getMin()) {
|
||||
bounds.setYmin((float) getAxis(AxisId.Y).getMin());
|
||||
changed = true;
|
||||
}
|
||||
if (bounds.getYmax() != getAxis(AxisId.Y).getMax()) {
|
||||
bounds.setYmax((float) getAxis(AxisId.Y).getMax());
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!getAxis(AxisId.Z).isAutoRange()) {
|
||||
@@ -946,13 +1026,13 @@ public class MatrixPlot extends MatrixPlotBase {
|
||||
bounds.setZmax((float) getAxis(AxisId.Z).getMax());
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (changed && updateBounds) {
|
||||
chart.getView().setBoundManual(bounds);
|
||||
}
|
||||
}
|
||||
} else if (chart.getView().getBoundsMode() != ViewBoundMode.AUTO_FIT) {
|
||||
if (updateBounds) {
|
||||
if (updateBounds) {
|
||||
chart.getView().setBoundMode(ViewBoundMode.AUTO_FIT);
|
||||
}
|
||||
changed = true;
|
||||
|
||||
@@ -31,8 +31,17 @@ public class SwingUtils {
|
||||
component.setLocation(dim.width / 2 - component.getSize().width / 2, dim.height / 2 - component.getSize().height / 2);
|
||||
}
|
||||
|
||||
public static Color generateRandomColor() {
|
||||
public static Color generateRandomColor(long seed) {
|
||||
Random random = new Random(seed);
|
||||
return generateRandomColor(random);
|
||||
}
|
||||
|
||||
public static Color generateRandomColor() {
|
||||
Random random = new Random();
|
||||
return generateRandomColor(random);
|
||||
}
|
||||
|
||||
static Color generateRandomColor(Random random) {
|
||||
|
||||
Color mix = Color.WHITE;
|
||||
int red = (random.nextInt(256) + mix.getRed()) / 2;
|
||||
|
||||
@@ -15,8 +15,7 @@ import javax.swing.WindowConstants;
|
||||
*
|
||||
*/
|
||||
public class MatrixPlotTest {
|
||||
|
||||
final static int sleepTime = 0;
|
||||
final static int sleepTime = 1;
|
||||
final static double startX = 10;
|
||||
final static double stepSizeX = 1;
|
||||
final static int stepsX = 100;
|
||||
@@ -53,11 +52,9 @@ public class MatrixPlotTest {
|
||||
//plot.getAxis(Plot.AxisId.Y).setRange(400, 600);
|
||||
|
||||
Thread.sleep(1000);
|
||||
plot.addSeries(data);
|
||||
|
||||
plot.addSeries(data);
|
||||
Thread t = new Thread(runnable);
|
||||
t.start();
|
||||
|
||||
/*
|
||||
plot.setUpdatesEnabled(false);
|
||||
for (int i=0;i<20;i++){
|
||||
|
||||
63
ch.psi.plot/src/test/java/MatrixPlotTest2.java
Normal file
63
ch.psi.plot/src/test/java/MatrixPlotTest2.java
Normal file
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright (c) 2014 Paul Scherrer Institute. All rights reserved.
|
||||
*/
|
||||
import ch.psi.plot.MatrixPlotSeries;
|
||||
import ch.psi.plot.Plot;
|
||||
import ch.psi.plot.xyz.generator.Gauss2D;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
//import ch.psi.sls.xasec.data.DataSet;
|
||||
//import ch.psi.sls.xasec.data.DataSetUtils;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.WindowConstants;
|
||||
|
||||
/**
|
||||
* Test case for MatrixPlot class
|
||||
*
|
||||
*/
|
||||
public class MatrixPlotTest2 {
|
||||
|
||||
final static double startX = 10;
|
||||
final static double stepSizeX = 1;
|
||||
final static int stepsX = 100;
|
||||
final static double startY = 300;
|
||||
final static double stepSizeY = 2;
|
||||
final static int stepsY = 200;
|
||||
final static MatrixPlotSeries data = new MatrixPlotSeries("", startX, startX + stepsX * stepSizeX, stepsX + 1, startY, startY + stepsY * stepSizeY, stepsY + 1);
|
||||
final static Gauss2D generator = new Gauss2D(50, 500, 40, 800, 2);
|
||||
|
||||
public static void main(final String[] args) throws InterruptedException, InvocationTargetException {
|
||||
final ch.psi.plot.MatrixPlot plot = new ch.psi.plot.jzy3d.MatrixPlot();
|
||||
plot.setTitle("Matrix Plot Test");
|
||||
|
||||
|
||||
double[][] d= new double[201][101];
|
||||
int indexX=0,indexY=0;
|
||||
for (double y = startY; y <= startY + stepsY * stepSizeY; y += stepSizeY, indexY++) {
|
||||
indexX=0;
|
||||
for (double x = startX; x <= startX + stepsX * stepSizeX; x += stepSizeX, indexX++) {
|
||||
d[indexY][indexX]= generator.generate(x, y) + 5.0;
|
||||
}
|
||||
}
|
||||
|
||||
plot.addSeries(data);
|
||||
data.setData(d);
|
||||
|
||||
|
||||
|
||||
|
||||
final JFrame frame = new JFrame("");
|
||||
frame.setContentPane(plot.getChartPanel());
|
||||
frame.pack();
|
||||
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); // Close application if frame is closed
|
||||
java.awt.EventQueue.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
frame.setVisible(true);
|
||||
//runnable.run();
|
||||
}
|
||||
});
|
||||
//Thread.sleep(360000);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user