Global refactoring of plots
This commit is contained in:
parent
84338de011
commit
c8651e0f26
@ -28,8 +28,8 @@ import hep.dataforge.meta.ConfigChangeListener;
|
|||||||
import hep.dataforge.meta.Configuration;
|
import hep.dataforge.meta.Configuration;
|
||||||
import hep.dataforge.meta.Meta;
|
import hep.dataforge.meta.Meta;
|
||||||
import hep.dataforge.meta.MetaBuilder;
|
import hep.dataforge.meta.MetaBuilder;
|
||||||
import hep.dataforge.plots.data.DynamicPlottable;
|
import hep.dataforge.plots.data.TimePlottable;
|
||||||
import hep.dataforge.plots.data.DynamicPlottableGroup;
|
import hep.dataforge.plots.data.TimePlottableGroup;
|
||||||
import hep.dataforge.plots.fx.PlotContainer;
|
import hep.dataforge.plots.fx.PlotContainer;
|
||||||
import hep.dataforge.plots.jfreechart.JFreeChartFrame;
|
import hep.dataforge.plots.jfreechart.JFreeChartFrame;
|
||||||
import hep.dataforge.storage.api.Storage;
|
import hep.dataforge.storage.api.Storage;
|
||||||
@ -77,7 +77,7 @@ public class MspViewController implements Initializable, MspListener {
|
|||||||
public static final String MSP_DEVICE_TYPE = "msp";
|
public static final String MSP_DEVICE_TYPE = "msp";
|
||||||
|
|
||||||
public static final String DEFAULT_CONFIG_LOCATION = "msp-config.xml";
|
public static final String DEFAULT_CONFIG_LOCATION = "msp-config.xml";
|
||||||
private final DynamicPlottableGroup plottables = new DynamicPlottableGroup();
|
private final TimePlottableGroup plottables = new TimePlottableGroup();
|
||||||
private final String mspName = "msp";
|
private final String mspName = "msp";
|
||||||
private MspDevice device;
|
private MspDevice device;
|
||||||
private Configuration viewConfig;
|
private Configuration viewConfig;
|
||||||
@ -257,7 +257,7 @@ public class MspViewController implements Initializable, MspListener {
|
|||||||
String mass = an.getString("mass");
|
String mass = an.getString("mass");
|
||||||
|
|
||||||
if (!this.plottables.hasPlottable(mass)) {
|
if (!this.plottables.hasPlottable(mass)) {
|
||||||
DynamicPlottable newPlottable = new DynamicPlottable(mass, mass);
|
TimePlottable newPlottable = new TimePlottable(mass, mass);
|
||||||
newPlottable.configure(an);
|
newPlottable.configure(an);
|
||||||
this.plottables.addPlottable(newPlottable);
|
this.plottables.addPlottable(newPlottable);
|
||||||
plot.add(newPlottable);
|
plot.add(newPlottable);
|
||||||
|
@ -17,8 +17,8 @@ import hep.dataforge.exceptions.MeasurementException;
|
|||||||
import hep.dataforge.fx.ConsoleFragment;
|
import hep.dataforge.fx.ConsoleFragment;
|
||||||
import hep.dataforge.meta.Meta;
|
import hep.dataforge.meta.Meta;
|
||||||
import hep.dataforge.meta.MetaBuilder;
|
import hep.dataforge.meta.MetaBuilder;
|
||||||
import hep.dataforge.plots.data.DynamicPlottable;
|
import hep.dataforge.plots.data.TimePlottable;
|
||||||
import hep.dataforge.plots.data.DynamicPlottableGroup;
|
import hep.dataforge.plots.data.TimePlottableGroup;
|
||||||
import hep.dataforge.plots.fx.FXPlotFrame;
|
import hep.dataforge.plots.fx.FXPlotFrame;
|
||||||
import hep.dataforge.plots.fx.PlotContainer;
|
import hep.dataforge.plots.fx.PlotContainer;
|
||||||
import hep.dataforge.plots.jfreechart.JFreeChartFrame;
|
import hep.dataforge.plots.jfreechart.JFreeChartFrame;
|
||||||
@ -75,7 +75,7 @@ public class VacCollectorController implements Initializable, DeviceListener, Me
|
|||||||
private LoaderConnection storageConnection;
|
private LoaderConnection storageConnection;
|
||||||
private VacCollectorDevice device;
|
private VacCollectorDevice device;
|
||||||
private PlotContainer plotContainer;
|
private PlotContainer plotContainer;
|
||||||
private DynamicPlottableGroup plottables;
|
private TimePlottableGroup plottables;
|
||||||
private BiFunction<VacCollectorDevice, Storage, PointLoader> loaderFactory;
|
private BiFunction<VacCollectorDevice, Storage, PointLoader> loaderFactory;
|
||||||
@FXML
|
@FXML
|
||||||
private AnchorPane plotHolder;
|
private AnchorPane plotHolder;
|
||||||
@ -161,10 +161,10 @@ public class VacCollectorController implements Initializable, DeviceListener, Me
|
|||||||
|
|
||||||
private void setupView() {
|
private void setupView() {
|
||||||
vacBoxHolder.getChildren().clear();
|
vacBoxHolder.getChildren().clear();
|
||||||
plottables = new DynamicPlottableGroup();
|
plottables = new TimePlottableGroup();
|
||||||
views.stream().forEach((controller) -> {
|
views.stream().forEach((controller) -> {
|
||||||
vacBoxHolder.getChildren().add(controller.getComponent());
|
vacBoxHolder.getChildren().add(controller.getComponent());
|
||||||
DynamicPlottable plot = new DynamicPlottable(controller.getTitle(),
|
TimePlottable plot = new TimePlottable(controller.getTitle(),
|
||||||
controller.getName());
|
controller.getName());
|
||||||
plot.configure(controller.meta());
|
plot.configure(controller.meta());
|
||||||
plottables.addPlottable(plot);
|
plottables.addPlottable(plot);
|
||||||
@ -175,7 +175,7 @@ public class VacCollectorController implements Initializable, DeviceListener, Me
|
|||||||
plotContainer.setPlot(setupPlot(plottables));
|
plotContainer.setPlot(setupPlot(plottables));
|
||||||
}
|
}
|
||||||
|
|
||||||
private FXPlotFrame setupPlot(DynamicPlottableGroup plottables) {
|
private FXPlotFrame setupPlot(TimePlottableGroup plottables) {
|
||||||
Meta plotConfig = new MetaBuilder("plotFrame")
|
Meta plotConfig = new MetaBuilder("plotFrame")
|
||||||
.setNode(new MetaBuilder("yAxis")
|
.setNode(new MetaBuilder("yAxis")
|
||||||
.setValue("type", "log")
|
.setValue("type", "log")
|
||||||
|
@ -273,8 +273,8 @@ public class NumassPlugin extends BasicPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private XYAdapter getAdapter(Meta an) {
|
private XYAdapter getAdapter(Meta an) {
|
||||||
if (an.hasNode(PointAdapter.DATA_ADAPTER_ANNOTATION_NAME)) {
|
if (an.hasNode(PointAdapter.DATA_ADAPTER_KEY)) {
|
||||||
return new XYAdapter(an.getNode(PointAdapter.DATA_ADAPTER_ANNOTATION_NAME));
|
return new XYAdapter(an.getNode(PointAdapter.DATA_ADAPTER_KEY));
|
||||||
} else {
|
} else {
|
||||||
return new XYAdapter("Uread", "CR", "CRerr");
|
return new XYAdapter("Uread", "CR", "CRerr");
|
||||||
}
|
}
|
||||||
|
@ -66,9 +66,9 @@ public class MergeDataAction extends ManyToOneAction<Table, Table> {
|
|||||||
@Override
|
@Override
|
||||||
protected MetaBuilder outputMeta(DataNode<Table> input) {
|
protected MetaBuilder outputMeta(DataNode<Table> input) {
|
||||||
|
|
||||||
String numassPath = input.dataStream().<String>map(data -> data.meta().getString("numass.path", null))
|
String numassPath = input.dataStream().<String>map(data -> data.meta().getString("numass.path", ""))
|
||||||
.reduce("", (String path, String newPath) -> {
|
.reduce("", (String path, String newPath) -> {
|
||||||
if (path == null) {
|
if (path.isEmpty()) {
|
||||||
return null;
|
return null;
|
||||||
} else if (path.isEmpty()) {
|
} else if (path.isEmpty()) {
|
||||||
return newPath;
|
return newPath;
|
||||||
|
@ -13,7 +13,7 @@ import hep.dataforge.meta.Meta;
|
|||||||
import hep.dataforge.meta.MetaBuilder;
|
import hep.dataforge.meta.MetaBuilder;
|
||||||
import hep.dataforge.plots.PlotsPlugin;
|
import hep.dataforge.plots.PlotsPlugin;
|
||||||
import hep.dataforge.plots.XYPlotFrame;
|
import hep.dataforge.plots.XYPlotFrame;
|
||||||
import hep.dataforge.plots.XYPlottable;
|
import hep.dataforge.plots.data.XYPlottable;
|
||||||
import hep.dataforge.plots.data.PlottableData;
|
import hep.dataforge.plots.data.PlottableData;
|
||||||
import hep.dataforge.tables.*;
|
import hep.dataforge.tables.*;
|
||||||
import hep.dataforge.values.ValueType;
|
import hep.dataforge.values.ValueType;
|
||||||
|
@ -41,19 +41,19 @@ public class SpectrumDataAdapter extends XYAdapter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public SpectrumDataAdapter(String xName, String yName, String yErrName, String measurementTime) {
|
public SpectrumDataAdapter(String xName, String yName, String yErrName, String measurementTime) {
|
||||||
super(new MetaBuilder(PointAdapter.DATA_ADAPTER_ANNOTATION_NAME)
|
super(new MetaBuilder(PointAdapter.DATA_ADAPTER_KEY)
|
||||||
.setValue(X_NAME, xName)
|
.setValue(X_VALUE_KEY, xName)
|
||||||
.setValue(Y_NAME, yName)
|
.setValue(Y_VALUE_KEY, yName)
|
||||||
.setValue(Y_ERR_NAME, yErrName)
|
.setValue(Y_ERROR_KEY, yErrName)
|
||||||
.setValue(POINT_LENGTH_NAME, measurementTime)
|
.setValue(POINT_LENGTH_NAME, measurementTime)
|
||||||
.build()
|
.build()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public SpectrumDataAdapter(String xName, String yName, String measurementTime) {
|
public SpectrumDataAdapter(String xName, String yName, String measurementTime) {
|
||||||
super(new MetaBuilder(PointAdapter.DATA_ADAPTER_ANNOTATION_NAME)
|
super(new MetaBuilder(PointAdapter.DATA_ADAPTER_KEY)
|
||||||
.setValue(X_NAME, xName)
|
.setValue(X_VALUE_KEY, xName)
|
||||||
.setValue(Y_NAME, yName)
|
.setValue(Y_VALUE_KEY, yName)
|
||||||
.setValue(POINT_LENGTH_NAME, measurementTime)
|
.setValue(POINT_LENGTH_NAME, measurementTime)
|
||||||
.build()
|
.build()
|
||||||
);
|
);
|
||||||
@ -64,14 +64,14 @@ public class SpectrumDataAdapter extends XYAdapter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public DataPoint buildSpectrumDataPoint(double x, long count, double t) {
|
public DataPoint buildSpectrumDataPoint(double x, long count, double t) {
|
||||||
return new MapPoint(new String[]{getValueName(X_NAME), getValueName(Y_NAME),
|
return new MapPoint(new String[]{getValueName(X_VALUE_KEY), getValueName(Y_VALUE_KEY),
|
||||||
getValueName(POINT_LENGTH_NAME)},
|
getValueName(POINT_LENGTH_NAME)},
|
||||||
x, count, t);
|
x, count, t);
|
||||||
}
|
}
|
||||||
|
|
||||||
public DataPoint buildSpectrumDataPoint(double x, long count, double countErr, double t) {
|
public DataPoint buildSpectrumDataPoint(double x, long count, double countErr, double t) {
|
||||||
return new MapPoint(new String[]{getValueName(X_NAME), getValueName(Y_NAME),
|
return new MapPoint(new String[]{getValueName(X_VALUE_KEY), getValueName(Y_VALUE_KEY),
|
||||||
getValueName(Y_ERR_NAME), getValueName(POINT_LENGTH_NAME)},
|
getValueName(Y_ERROR_KEY), getValueName(POINT_LENGTH_NAME)},
|
||||||
x, count, countErr, t);
|
x, count, countErr, t);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,7 +100,7 @@ public class NumassRootHandler implements Handler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void renderLoader(Context ctx, StringBuilder b, Loader loader) {
|
private void renderLoader(Context ctx, StringBuilder b, Loader loader) {
|
||||||
String href = "/storage?path=" + loader.getFullPath();
|
String href = "/storage?path=" + loader.getPath();
|
||||||
b.append(String.format("<p><a href=\"%s\">%s</a> (%s)</p>", href, loader.getName(), loader.getType()));
|
b.append(String.format("<p><a href=\"%s\">%s</a> (%s)</p>", href, loader.getName(), loader.getType()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,10 +23,10 @@ package inr.numass.viewer;
|
|||||||
|
|
||||||
import hep.dataforge.context.Context;
|
import hep.dataforge.context.Context;
|
||||||
import hep.dataforge.context.Encapsulated;
|
import hep.dataforge.context.Encapsulated;
|
||||||
|
import hep.dataforge.names.AlphanumComparator;
|
||||||
import hep.dataforge.names.Name;
|
import hep.dataforge.names.Name;
|
||||||
import hep.dataforge.plots.PlotUtils;
|
import hep.dataforge.plots.PlotUtils;
|
||||||
import hep.dataforge.plots.data.DynamicPlottable;
|
import hep.dataforge.plots.data.*;
|
||||||
import hep.dataforge.plots.data.DynamicPlottableGroup;
|
|
||||||
import hep.dataforge.plots.fx.PlotContainer;
|
import hep.dataforge.plots.fx.PlotContainer;
|
||||||
import hep.dataforge.plots.jfreechart.JFreeChartFrame;
|
import hep.dataforge.plots.jfreechart.JFreeChartFrame;
|
||||||
import hep.dataforge.storage.api.PointLoader;
|
import hep.dataforge.storage.api.PointLoader;
|
||||||
@ -43,8 +43,7 @@ import javafx.scene.layout.BorderPane;
|
|||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.List;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
import java.util.stream.StreamSupport;
|
import java.util.stream.StreamSupport;
|
||||||
@ -86,16 +85,18 @@ public class MspViewController implements Encapsulated {
|
|||||||
/**
|
/**
|
||||||
* update detector pane with new data
|
* update detector pane with new data
|
||||||
*/
|
*/
|
||||||
private void updateMspPane(DynamicPlottableGroup mspData) {
|
private void updateMspPane(Iterable<? extends XYPlottable> mspData) {
|
||||||
JFreeChartFrame frame = new JFreeChartFrame();
|
JFreeChartFrame frame = new JFreeChartFrame();
|
||||||
PlotUtils.setYAxis(frame, "partial pressure", "mbar", "log");
|
PlotUtils.setYAxis(frame, "partial pressure", "mbar", "log");
|
||||||
frame.getConfig().setValue("yAxis.range.lower", 1e-10);
|
frame.getConfig().setValue("yAxis.range.lower", 1e-10);
|
||||||
frame.getConfig().setValue("yAxis.range.upper", 1e-3);
|
frame.getConfig().setValue("yAxis.range.upper", 1e-3);
|
||||||
PlotUtils.setXAxis(frame, "time", null, "time");
|
PlotUtils.setXAxis(frame, "time", null, "time");
|
||||||
|
|
||||||
StreamSupport.stream(mspData.spliterator(), false)
|
// StreamSupport.stream(mspData.spliterator(), false)
|
||||||
.sorted((DynamicPlottable o1, DynamicPlottable o2)
|
// .sorted((XYPlottable o1, XYPlottable o2)
|
||||||
-> Integer.valueOf(o1.getName()).compareTo(Integer.valueOf(o2.getName()))).forEach((pl) -> frame.add(pl));
|
// -> Integer.valueOf(o1.getName()).compareTo(Integer.valueOf(o2.getName()))).forEach((pl) -> frame.add(pl));
|
||||||
|
|
||||||
|
frame.addAll(mspData);
|
||||||
Platform.runLater(() -> {
|
Platform.runLater(() -> {
|
||||||
mspPlotPane.getChildren().clear();
|
mspPlotPane.getChildren().clear();
|
||||||
PlotContainer container = PlotContainer.anchorTo(mspPlotPane);
|
PlotContainer container = PlotContainer.anchorTo(mspPlotPane);
|
||||||
@ -114,22 +115,43 @@ public class MspViewController implements Encapsulated {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void plotData(List<PointLoader> loaders) {
|
public void plotData(List<PointLoader> loaders) {
|
||||||
DynamicPlottableGroup plottables = new DynamicPlottableGroup();
|
// TimePlottableGroup plottables = new TimePlottableGroup();
|
||||||
loaders.stream()
|
// loaders.stream()
|
||||||
.flatMap(loader -> getLoaderData(loader))
|
// .flatMap(loader -> getLoaderData(loader))
|
||||||
.distinct()
|
// .distinct()
|
||||||
.forEach(point -> {
|
// .forEach(point -> {
|
||||||
for (String name : point.names()) {
|
// for (String name : point.names()) {
|
||||||
if (!name.equals("timestamp")) {
|
// if (!name.equals("timestamp")) {
|
||||||
if (!plottables.hasPlottable(name)) {
|
// if (!plottables.hasPlottable(name)) {
|
||||||
plottables.addPlottable(new DynamicPlottable(name, name));
|
// plottables.addPlottable(new TimePlottable(name, name));
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// plottables.put(point);
|
||||||
|
// }
|
||||||
|
// );
|
||||||
|
|
||||||
|
Collection<String> names = joinNames(loaders);
|
||||||
|
|
||||||
|
Stream<DataPoint> stream = loaders.stream().flatMap(loader -> getLoaderData(loader));
|
||||||
|
|
||||||
|
|
||||||
|
updateMspPane(PlotDataUtils.buildGroup("timestamp", names, stream));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Combine names of different point loaders
|
||||||
|
*
|
||||||
|
* @param loaders
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private Collection<String> joinNames(List<PointLoader> loaders) {
|
||||||
|
Set<String> nameSet = new TreeSet<>(new AlphanumComparator());
|
||||||
|
for (PointLoader loader : loaders) {
|
||||||
|
nameSet.addAll(loader.getFormat().names().asList());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
plottables.put(point);
|
return nameSet;
|
||||||
}
|
|
||||||
);
|
|
||||||
updateMspPane(plottables);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Stream<DataPoint> getLoaderData(PointLoader loader) {
|
private Stream<DataPoint> getLoaderData(PointLoader loader) {
|
||||||
@ -194,13 +216,13 @@ public class MspViewController implements Encapsulated {
|
|||||||
//// List<DataPoint> mspData = (List<DataPoint>) loadProcess.getTask().get();
|
//// List<DataPoint> mspData = (List<DataPoint>) loadProcess.getTask().get();
|
||||||
//
|
//
|
||||||
// if (!mspData.isEmpty()) {
|
// if (!mspData.isEmpty()) {
|
||||||
// DynamicPlottableGroup plottables = new DynamicPlottableGroup();
|
// TimePlottableGroup plottables = new TimePlottableGroup();
|
||||||
//
|
//
|
||||||
// for (DataPoint point : mspData) {
|
// for (DataPoint point : mspData) {
|
||||||
// for (String name : point.names()) {
|
// for (String name : point.names()) {
|
||||||
// if (!name.equals("timestamp")) {
|
// if (!name.equals("timestamp")) {
|
||||||
// if (!plottables.hasPlottable(name)) {
|
// if (!plottables.hasPlottable(name)) {
|
||||||
// plottables.addPlottable(new DynamicPlottable(name, name));
|
// plottables.addPlottable(new TimePlottable(name, name));
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
@ -229,4 +251,5 @@ public class MspViewController implements Encapsulated {
|
|||||||
}
|
}
|
||||||
return p.build();
|
return p.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -244,11 +244,11 @@ public class NumassLoaderViewComponent extends AnchorPane implements Initializab
|
|||||||
Platform.runLater(() -> {
|
Platform.runLater(() -> {
|
||||||
if (t != null) {
|
if (t != null) {
|
||||||
hvPlot.getPlot().plottables().clear();
|
hvPlot.getPlot().plottables().clear();
|
||||||
DynamicPlottableGroup set = new DynamicPlottableGroup();
|
TimePlottableGroup set = new TimePlottableGroup();
|
||||||
for (DataPoint dp : t) {
|
for (DataPoint dp : t) {
|
||||||
String block = dp.getString("block", "default");
|
String block = dp.getString("block", "default");
|
||||||
if (!set.hasPlottable(block)) {
|
if (!set.hasPlottable(block)) {
|
||||||
set.addPlottable(new DynamicPlottable(block, block));
|
set.addPlottable(new TimePlottable(block, block));
|
||||||
}
|
}
|
||||||
set.getPlottable(block).put(dp.getValue("timestamp").timeValue(), dp.getValue("value"));
|
set.getPlottable(block).put(dp.getValue("timestamp").timeValue(), dp.getValue("value"));
|
||||||
}
|
}
|
||||||
|
@ -21,8 +21,6 @@ repositories {
|
|||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
// Adding dependencies here will add the dependencies to each subproject.
|
// Adding dependencies here will add the dependencies to each subproject.
|
||||||
compile 'org.codehaus.groovy:groovy-all:2.4.+'
|
|
||||||
shadow 'org.codehaus.groovy:groovy-all:2.4.+'
|
|
||||||
testCompile group: 'junit', name: 'junit', version:'4.+'
|
testCompile group: 'junit', name: 'junit', version:'4.+'
|
||||||
deployerJars "org.apache.maven.wagon:wagon-ssh:2.8"
|
deployerJars "org.apache.maven.wagon:wagon-ssh:2.8"
|
||||||
}
|
}
|
||||||
@ -38,7 +36,6 @@ uploadArchives {
|
|||||||
|
|
||||||
shadowJar {
|
shadowJar {
|
||||||
dependencies {
|
dependencies {
|
||||||
exclude(dependency('org.codehaus.groovy:groovy-all:2.4.+'))
|
|
||||||
mergeServiceFiles()
|
mergeServiceFiles()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user