use of cbit.plot.SingleXPlot2D in project vcell by virtualcell.
the class DataProcessingResultsPanel method onVariablesChange.
private void onVariablesChange() {
try {
// keep old indices
lastSelectedIdxArray = varJList.getSelectedIndices();
Object[] selectedObjects = varJList.getSelectedValues();
int numSelectedVars = selectedObjects.length;
int totalColumns = 1;
for (int v = 0; v < numSelectedVars; v++) {
totalColumns++;
// String varName = (String)selectedObjects[v];
// ucar.nc2.Variable volVar = ncfile.findVariable(varName);
// int[] shape = volVar.getShape();
// int numColumns = shape[1];
//
// totalColumns += numColumns;
}
if (dataProcessingOutputInfo == null) {
throw new RuntimeException("dataProcessingOutInfo null, thread = " + Thread.currentThread().getName());
}
final double[] vtp = dataProcessingOutputInfo.getVariableTimePoints();
if (vtp == null) {
throw new RuntimeException("getVariableTimePoints( ) null, thread = " + Thread.currentThread().getName());
}
final int numTimes = vtp.length;
double[][] plotDatas = new double[totalColumns][numTimes];
// assumes all times same
plotDatas[0] = dataProcessingOutputInfo.getVariableTimePoints();
String[] plotNames = new String[totalColumns - 1];
int columnCount = 0;
for (int v = 0; v < numSelectedVars; v++) {
String varName = ((String) selectedObjects[v]);
// remove the unit from name if exist
if (// "_(" doesn't suppose to be the first char
varName.indexOf("_(") > 0) {
varName = varName.substring(0, varName.indexOf("_("));
}
// }
for (int i = 0; i < /*numColumns*/
1; i++) {
String plotName = varName;
if (i > 0) {
plotName += ": region " + (i - 1);
}
plotNames[columnCount] = plotName;
if (columnCount >= plotDatas.length) {
throw new RuntimeException("invalid columnCount " + columnCount + " >= " + plotDatas.length);
}
for (int j = 0; j < numTimes; j++) {
// data.get(j, i);
double[] vars = dataProcessingOutputInfo.getVariableStatValues().get(varName);
if (j >= vars.length) {
throw new RuntimeException("invalid index " + j + " on " + varName + ", greater than " + vars.length);
}
plotDatas[columnCount + 1][j] = vars[j];
}
columnCount++;
}
}
Plot2D plot2D = new SingleXPlot2D(null, null, ReservedVariable.TIME.getName(), plotNames, plotDatas, new String[] { "Time Plot", ReservedVariable.TIME.getName(), "" });
plotPane.setPlot2D(plot2D);
} catch (Exception e1) {
VCDataIdentifier id = dataProcessingOutputInfo.getVCDataIdentifier();
DialogUtils.ErrorContext ec = new DialogUtils.ErrorContext(VerboseDataIdentifier.parse(id));
DialogUtils.showErrorDialog(this, e1.getMessage(), e1, ec);
e1.printStackTrace();
}
}
use of cbit.plot.SingleXPlot2D in project vcell by virtualcell.
the class KymographPanel method configurePlotData.
/**
* Insert the method's description here.
* Creation date: (12/16/2004 10:46:05 AM)
* @param imgX int
* @param imgY int
*/
private void configurePlotData(int imgX, int imgY) {
//
// TimeScan Data
//
double[][] timeData = new double[2][currentTimes.length];
timeData[0] = currentTimes;
timeData[1] = new double[currentTimes.length];
for (int i = 0; i < currentTimes.length; i += 1) {
// timeData[1][i] = timeSeriesDataOrig[1+imgX][i];
timeData[1][i] = rawValues[imgX + (i * RESAMP_SIZE)];
}
;
localTimeDataMMMH = calcMMM(timeData[1]);
final int MAX_TITLE_VAL_LENGTH = 9;
DecimalFormat nf = new DecimalFormat();
String valS = null;
valS = currentDistances[imgX] + "";
if (valS.length() > MAX_TITLE_VAL_LENGTH) {
nf.applyPattern("#.###E0");
valS = nf.format(currentDistances[imgX]);
}
currentTimeSeriesPlot2D = new SingleXPlot2D(new SymbolTableEntry[] { currentSymbolTablEntry }, multiTimePlotHelper.getDataSymbolMetadataResolver(), "Time", new String[] { currentDataIdentifier.getName() }, timeData, new String[] { "Time Series (d=" + valS + ") Vert", "Time", /*"Time (s)"*/
"Value" });
getPlotPaneTimeSeries().setPlot2D(currentTimeSeriesPlot2D);
//
// LineScan Data
//
double[] lineData = new double[timeSeriesDataOrig.length - 1];
for (int i = 1; i < timeSeriesDataOrig.length; i += 1) {
lineData[i - 1] = timeSeriesDataOrig[i][imgY];
}
double[] lineScanDistances = accumDistancesDataOrig;
localDistDataMMMH = calcMMM(lineData);
PlotData plotData = new PlotData(lineScanDistances, lineData);
valS = currentTimes[imgY] + "";
if (valS.length() > MAX_TITLE_VAL_LENGTH) {
valS = nf.format(currentTimes[imgY]);
}
currentLineScanPlot2D = new Plot2D(new SymbolTableEntry[] { currentSymbolTablEntry }, multiTimePlotHelper.getDataSymbolMetadataResolver(), new String[] { currentDataIdentifier.getName() }, new PlotData[] { plotData }, new String[] { "Line Scan (t=" + valS + ") Horz", "Distance", /*"Distance (\u00b5m)"*/
"Value" });
getPlotPaneLineScan().setPlot2D(currentLineScanPlot2D);
Range xRangeTime = new Range(currentTimes[0], currentTimes[currentTimes.length - 1]);
Range xRangeDist = new Range(lineScanDistances[0], lineScanDistances[lineScanDistances.length - 1]);
Range yRangeTime = (allDataMMMH != null ? allDataMMMH.getRange() : null);
Range yRangeDist = yRangeTime;
if (bLocalScaling) {
yRangeTime = (localTimeDataMMMH != null ? localTimeDataMMMH.getRange() : null);
yRangeDist = (localDistDataMMMH != null ? localDistDataMMMH.getRange() : null);
}
getPlotPaneTimeSeries().forceXYRange(xRangeTime, yRangeTime);
getPlotPaneLineScan().forceXYRange(xRangeDist, yRangeDist);
configureMinMax();
getimagePaneView1().repaint();
}
use of cbit.plot.SingleXPlot2D in project vcell by virtualcell.
the class PDEDataViewer method plotSpaceStats.
void plotSpaceStats(TSJobResultsSpaceStats tsjrss) {
// Determine if Volume or Membrane
DataIdentifier[] diArr = getPdeDataContext().getDataIdentifiers();
boolean bVolume = true;
for (int i = 0; i < diArr.length; i += 1) {
if (diArr[i].getName().equals(tsjrss.getVariableNames()[0])) {
if (diArr[i].getVariableType().equals(VariableType.MEMBRANE) || diArr[i].getVariableType().equals(VariableType.MEMBRANE_REGION)) {
bVolume = false;
break;
}
}
}
SymbolTableEntry[] symbolTableEntries = null;
if (tsjrss.getVariableNames().length == 1) {
// max.mean.min,sum
symbolTableEntries = new SymbolTableEntry[3];
if (getSimulation() != null && getSimulation().getMathDescription() != null) {
symbolTableEntries[0] = getSimulation().getMathDescription().getEntry(tsjrss.getVariableNames()[0]);
} else {
symbolTableEntries[0] = new SimpleSymbolTable(tsjrss.getVariableNames()).getEntry(tsjrss.getVariableNames()[0]);
}
symbolTableEntries[1] = symbolTableEntries[0];
symbolTableEntries[2] = symbolTableEntries[0];
}
SymbolTableEntry[] finalSymbolTableEntries = symbolTableEntries;
boolean finalBVolume = bVolume;
PlotPane plotPane = new cbit.plot.gui.PlotPane();
plotPane.setPlot2D(new SingleXPlot2D(finalSymbolTableEntries, getSimulationModelInfo().getDataSymbolMetadataResolver(), "Time", new String[] { "Max", (tsjrss.getWeightedMean() != null ? "WeightedMean" : "UnweightedMean"), "Min" /*,
(tsjrss.getWeightedSum() != null?"WeightedSum":"UnweightedSum")*/
}, new double[][] { tsjrss.getTimes(), tsjrss.getMaximums()[0], (tsjrss.getWeightedMean() != null ? tsjrss.getWeightedMean()[0] : tsjrss.getUnweightedMean()[0]), tsjrss.getMinimums()[0] /*,
(tsjrss.getWeightedSum() != null?tsjrss.getWeightedSum()[0]:tsjrss.getUnweightedSum()[0])*/
}, new String[] { "Statistics Plot for " + tsjrss.getVariableNames()[0] + (tsjrss.getTotalSpace() != null ? " (ROI " + (finalBVolume ? "volume" : "area") + "=" + tsjrss.getTotalSpace()[0] + ")" : ""), ReservedVariable.TIME.getName(), "[" + tsjrss.getVariableNames()[0] + "]" }));
String title = "Statistics: (" + tsjrss.getVariableNames()[0] + ") ";
if (getSimulationModelInfo() != null) {
title += getSimulationModelInfo().getContextName() + " " + getSimulationModelInfo().getSimulationName();
}
ChildWindowManager childWindowManager = ChildWindowManager.findChildWindowManager(PDEDataViewer.this);
ChildWindow childWindow = childWindowManager.addChildWindow(plotPane, plotPane, title);
childWindow.setIsCenteredOnParent();
childWindow.pack();
childWindow.show();
}
use of cbit.plot.SingleXPlot2D in project vcell by virtualcell.
the class PlotPane method updateLegend.
/**
* Comment
*/
private void updateLegend() {
Plot2D plot = getPlot2DPanel1().getPlot2D();
SymbolTableEntry[] steList = plot.getSymbolTableEntries();
DataSymbolMetadataResolver metadataResolver = plot.getDataSymbolMetadataResolver();
String[] plotLabels = plot.getVisiblePlotColumnTitles();
int[] plotIndices = plot.getVisiblePlotIndices();
Component[] legends = getJPanelPlotLegends().getComponents();
// add legends if necessarry
if (ml == null) {
ml = new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
String name = ((JLabel) evt.getSource()).getText();
getPlot2DPanel1().setCurrentPlot(name);
}
};
}
for (int i = 0; i < plotIndices.length - legends.length / 2; i++) {
JLabel line = new JLabel();
JLabel text = new JLabel();
line.setBorder(new EmptyBorder(6, 0, 0, 0));
text.setBorder(new EmptyBorder(0, 8, 6, 0));
getJPanelPlotLegends().add(line);
getJPanelPlotLegends().add(text);
text.addMouseListener(ml);
}
legends = getJPanelPlotLegends().getComponents();
// update labels and show them,use reverse loop to generate non-repeatable colors
for (int i = (plotIndices.length - 1); i >= 0; i--) {
LineIcon icon = new LineIcon(getPlot2DPanel1().getVisiblePlotPaint(i));
String plotLabel = null;
if (plot instanceof SingleXPlot2D) {
plotLabel = plotLabels[i + 1];
} else {
plotLabel = plotLabels[2 * i + 1];
}
((JLabel) legends[2 * i]).setIcon(icon);
final int head = 20;
final int tail = 0;
String tooltipString = "";
String unitSymbol = "";
if (metadataResolver != null) {
DataSymbolMetadata metaData = metadataResolver.getDataSymbolMetadata(plotLabel);
if (metaData != null && metaData.unit != null) {
VCUnitDefinition ud = metaData.unit;
if (ud != null) {
unitSymbol += ud.getSymbolUnicode();
}
}
if (metaData != null && metaData.tooltipString != null) {
tooltipString = metaData.tooltipString;
}
}
String shortLabel = plotLabel;
if (shortLabel.length() > head + 3 + tail) {
shortLabel = shortLabel.substring(0, head) + "..." + shortLabel.substring(shortLabel.length() - tail, shortLabel.length());
}
// shortLabel = "<html>" + shortLabel + "<font color=\"red\">" + " [" + unitSymbol + "] " + "</font></html>";
shortLabel = "<html>" + shortLabel + "<font color=\"#8B0000\">" + " [" + unitSymbol + "] " + "</font></html>";
tooltipString = "<html>" + plotLabel + "<font color=\"#0000FF\">" + " " + tooltipString + " " + "</font></html>";
((JLabel) legends[2 * i + 1]).setText(shortLabel);
((JLabel) legends[2 * i + 1]).setToolTipText(tooltipString);
legends[2 * i].setVisible(true);
legends[2 * i + 1].setVisible(true);
}
// if extra ones, hide them
for (int i = 2 * plotIndices.length; i < legends.length; i++) {
legends[i].setVisible(false);
}
}
Aggregations