[no commit message]

This commit is contained in:
Alexander Nozik 2016-05-26 12:21:04 +03:00
parent ec76341522
commit a38a770f5e

View File

@ -25,14 +25,13 @@ import hep.dataforge.context.ProcessManager;
import hep.dataforge.io.ColumnedDataWriter; import hep.dataforge.io.ColumnedDataWriter;
import hep.dataforge.meta.Meta; import hep.dataforge.meta.Meta;
import hep.dataforge.meta.MetaBuilder; import hep.dataforge.meta.MetaBuilder;
import hep.dataforge.plots.PlotFrame;
import hep.dataforge.plots.XYPlotFrame; import hep.dataforge.plots.XYPlotFrame;
import hep.dataforge.plots.XYPlottable;
import hep.dataforge.plots.data.ChangeablePlottableData; import hep.dataforge.plots.data.ChangeablePlottableData;
import hep.dataforge.plots.data.DynamicPlottable; import hep.dataforge.plots.data.DynamicPlottable;
import hep.dataforge.plots.data.DynamicPlottableSet; import hep.dataforge.plots.data.DynamicPlottableSet;
import hep.dataforge.plots.data.PlotDataUtils; import hep.dataforge.plots.data.PlotDataUtils;
import hep.dataforge.plots.data.PlottableData; import hep.dataforge.plots.data.PlottableData;
import hep.dataforge.plots.data.PlottableSet;
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.commons.JSONMetaWriter; import hep.dataforge.storage.commons.JSONMetaWriter;
@ -46,7 +45,6 @@ import inr.numass.storage.NumassData;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.net.URL; import java.net.URL;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.ResourceBundle; import java.util.ResourceBundle;
import java.util.function.Predicate; import java.util.function.Predicate;
@ -280,15 +278,15 @@ public class NumassLoaderViewComponent extends AnchorPane implements Initializab
private void setupDetectorPane(List<NMPoint> points) { private void setupDetectorPane(List<NMPoint> points) {
boolean normalize = detectorNormalizeSwitch.isSelected(); boolean normalize = detectorNormalizeSwitch.isSelected();
int binning = detectorBinningSelector.getValue(); int binning = detectorBinningSelector.getValue();
updateDetectorPane(fillDetectorData(points, binning, normalize)); updateDetectorPane(points, binning, normalize);
detectorBinningSelector.getSelectionModel().selectedItemProperty() detectorBinningSelector.getSelectionModel().selectedItemProperty()
.addListener((ObservableValue<? extends Integer> observable, Integer oldValue, Integer newValue) -> { .addListener((ObservableValue<? extends Integer> observable, Integer oldValue, Integer newValue) -> {
boolean norm = detectorNormalizeSwitch.isSelected(); boolean norm = detectorNormalizeSwitch.isSelected();
updateDetectorPane(fillDetectorData(NumassLoaderViewComponent.this.points, newValue, norm)); updateDetectorPane(NumassLoaderViewComponent.this.points, newValue, norm);
}); });
detectorNormalizeSwitch.selectedProperty().addListener((ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) -> { detectorNormalizeSwitch.selectedProperty().addListener((ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) -> {
int bin = detectorBinningSelector.getValue(); int bin = detectorBinningSelector.getValue();
updateDetectorPane(fillDetectorData(NumassLoaderViewComponent.this.points, bin, newValue)); updateDetectorPane(NumassLoaderViewComponent.this.points, bin, newValue);
}); });
detectorDataExportButton.setDisable(false); detectorDataExportButton.setDisable(false);
} }
@ -334,16 +332,11 @@ public class NumassLoaderViewComponent extends AnchorPane implements Initializab
/** /**
* update detector pane with new data * update detector pane with new data
*/ */
private void updateDetectorPane(List<XYPlottable> detectorData) { private void updateDetectorPane(List<NMPoint> points, int binning, boolean normalize) {
Platform.runLater(() -> { PlotFrame detectorPlotFrame;
if (detectorData == null) { if (detectorPlot.getPlot() == null) {
throw new IllegalArgumentException("Detector data not defined");
}
// detectorPointListView.getItems().clear();//removing all checkboxes
// detectorPlotPane.getChildren().clear();//removing plot
Meta frameMeta = new MetaBuilder("frame") Meta frameMeta = new MetaBuilder("frame")
.setValue("frameTitle", "Detector response plot") .setValue("title", "Detector response plot")
.setNode(new MetaBuilder("xAxis") .setNode(new MetaBuilder("xAxis")
.setValue("axisTitle", "ADC") .setValue("axisTitle", "ADC")
.setValue("axisUnits", "channels") .setValue("axisUnits", "channels")
@ -355,20 +348,13 @@ public class NumassLoaderViewComponent extends AnchorPane implements Initializab
.setNode(new MetaBuilder("legend") .setNode(new MetaBuilder("legend")
.setValue("show", false)) .setValue("show", false))
.build(); .build();
detectorPlotFrame = new JFreeChartFrame(frameMeta);
// detectorPlot = PlotContainer.anchorTo(detectorPlotPane); } else {
XYPlotFrame detectorPlotFrame = new JFreeChartFrame(frameMeta); detectorPlotFrame = detectorPlot.getPlot();
detectorPlot.removePlot();
for (XYPlottable pl : detectorData) {
detectorPlotFrame.add(pl);
//TODO add update instead of replace action
}
detectorPlot.setPlot(detectorPlotFrame);
});
} }
private List<XYPlottable> fillDetectorData(List<NMPoint> points, int binning, boolean normalize) { context.processManager().post("viewer.numass.load.detector", (ProcessManager.Callback callback) -> {
List<XYPlottable> plottables = new ArrayList<>();
Meta plottableConfig = new MetaBuilder("plot") Meta plottableConfig = new MetaBuilder("plot")
.setValue("connectionType", "step") .setValue("connectionType", "step")
.setValue("thickness", 2) .setValue("thickness", 2)
@ -377,14 +363,20 @@ public class NumassLoaderViewComponent extends AnchorPane implements Initializab
.setValue("showErrors", false) .setValue("showErrors", false)
.build(); .build();
// detectorPlotFrame.clear();
callback.setMaxProgress(points.size());
callback.setProgress(0);
for (NMPoint point : points) { for (NMPoint point : points) {
String seriesName = String.format("%d: %.2f (%.2f)", points.indexOf(point), point.getUset(), point.getUread()); String seriesName = String.format("%d: %.2f", points.indexOf(point), point.getUset());
PlottableData datum = PlottableData.plot(seriesName, new XYAdapter("chanel", "count"), point.getData(binning, normalize)); PlottableData datum = PlottableData.plot(seriesName, new XYAdapter("chanel", "count"), point.getData(binning, normalize));
datum.configure(plottableConfig); datum.configure(plottableConfig);
plottables.add(datum); detectorPlotFrame.add(datum);
callback.increaseProgress(1d);
//TODO add update instead of replace action
} }
return plottables; detectorPlot.setPlot(detectorPlotFrame);
});
} }
@FXML @FXML