From 5e4ddcdfd599357667da2c1b9fe33d422e3888bb Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Sun, 16 Apr 2017 23:19:06 +0300 Subject: [PATCH] Fixing charts --- .../numass/cryotemp/PKT8PlotController.java | 2 +- .../java/inr/numass/data/PointBuilders.java | 10 ++- numass-viewer/build.gradle | 2 +- .../inr/numass/viewer/MspViewController.java | 18 ++--- .../main/kotlin/inr/numass/viewer/MainView.kt | 23 +++++-- .../inr/numass/viewer/NumassLoaderView.kt | 69 ++++++++++--------- .../kotlin/inr/numass/viewer/test/JFCTest.kt | 40 +++++++++++ .../kotlin/inr/numass/viewer/test/TestApp.kt | 9 +++ 8 files changed, 124 insertions(+), 49 deletions(-) create mode 100644 numass-viewer/src/main/kotlin/inr/numass/viewer/test/JFCTest.kt create mode 100644 numass-viewer/src/main/kotlin/inr/numass/viewer/test/TestApp.kt diff --git a/numass-control/cryotemp/src/main/java/inr/numass/cryotemp/PKT8PlotController.java b/numass-control/cryotemp/src/main/java/inr/numass/cryotemp/PKT8PlotController.java index 672ede63..b42b87f8 100644 --- a/numass-control/cryotemp/src/main/java/inr/numass/cryotemp/PKT8PlotController.java +++ b/numass-control/cryotemp/src/main/java/inr/numass/cryotemp/PKT8PlotController.java @@ -127,7 +127,7 @@ public class PKT8PlotController implements Initializable, MeasurementListener it.intValue()), block.getEventsList().stream() .mapToInt(event -> peakFinder.apply(event)) - )) + )),0 ); return new NMPoint(u, startTime, pointLength, spectrum); @@ -32,7 +32,7 @@ public class PointBuilders { private static int[] calculateSpectrum(RawNMPoint point) { assert point.getEventsCount() > 0; - return count(point.getEvents().stream().mapToInt(event -> event.getChanel())); + return count(point.getEvents().stream().mapToInt(event -> event.getChanel()),RawNMPoint.MAX_CHANEL); } @NotNull @@ -40,8 +40,12 @@ public class PointBuilders { return new NMPoint(point.getUset(), point.getStartTime(), point.getLength(), calculateSpectrum(point)); } - private static int[] count(IntStream stream) { + private static int[] count(IntStream stream, int maxChannel) { List list = new ArrayList<>(); + while (list.size() <= maxChannel) { + list.add(new AtomicInteger(0)); + } + stream.forEach(i -> { while (list.size() <= i) { list.add(new AtomicInteger(0)); diff --git a/numass-viewer/build.gradle b/numass-viewer/build.gradle index 9b626958..511ae1c6 100644 --- a/numass-viewer/build.gradle +++ b/numass-viewer/build.gradle @@ -4,7 +4,7 @@ plugins{ } if (!hasProperty('mainClass')) { - ext.mainClass = 'inr.numass.viewer.Viewer' + ext.mainClass = 'inr.numass.viewer.Viewer'//"inr.numass.viewer.test.TestApp" } mainClassName = mainClass diff --git a/numass-viewer/src/main/java/inr/numass/viewer/MspViewController.java b/numass-viewer/src/main/java/inr/numass/viewer/MspViewController.java index d9184f27..f3a72f48 100644 --- a/numass-viewer/src/main/java/inr/numass/viewer/MspViewController.java +++ b/numass-viewer/src/main/java/inr/numass/viewer/MspViewController.java @@ -115,19 +115,19 @@ public class MspViewController implements Encapsulated { } public void plotData(List loaders) { -// TimePlottableGroup plottables = new TimePlottableGroup(); +// TimePlottableGroup getPlottables = new TimePlottableGroup(); // loaders.stream() // .flatMap(loader -> getLoaderData(loader)) // .distinct() // .forEach(point -> { // for (String name : point.names()) { // if (!name.equals("timestamp")) { -// if (!plottables.has(name)) { -// plottables.addPlottable(new TimePlottable(name, name)); +// if (!getPlottables.has(name)) { +// getPlottables.addPlottable(new TimePlottable(name, name)); // } // } // } -// plottables.put(point); +// getPlottables.put(point); // } // ); @@ -216,20 +216,20 @@ public class MspViewController implements Encapsulated { //// List mspData = (List) loadProcess.getTask().get(); // // if (!mspData.isEmpty()) { -// TimePlottableGroup plottables = new TimePlottableGroup(); +// TimePlottableGroup getPlottables = new TimePlottableGroup(); // // for (DataPoint point : mspData) { // for (String name : point.names()) { // if (!name.equals("timestamp")) { -// if (!plottables.has(name)) { -// plottables.add(new TimePlottable(name, name)); +// if (!getPlottables.has(name)) { +// getPlottables.add(new TimePlottable(name, name)); // } // } // } -// plottables.put(point); +// getPlottables.put(point); // } // -// updateMspPane(plottables); +// updateMspPane(getPlottables); // } // }); // } diff --git a/numass-viewer/src/main/kotlin/inr/numass/viewer/MainView.kt b/numass-viewer/src/main/kotlin/inr/numass/viewer/MainView.kt index 929ff1dd..53b53d2b 100644 --- a/numass-viewer/src/main/kotlin/inr/numass/viewer/MainView.kt +++ b/numass-viewer/src/main/kotlin/inr/numass/viewer/MainView.kt @@ -9,6 +9,7 @@ import hep.dataforge.fx.work.Work import hep.dataforge.fx.work.WorkManager import hep.dataforge.fx.work.WorkManagerFragment import hep.dataforge.meta.Annotated +import hep.dataforge.names.AlphanumComparator import hep.dataforge.names.Named import hep.dataforge.storage.api.Storage import inr.numass.NumassProperties @@ -72,8 +73,15 @@ class MainView : View() { treePane.center { treetableview { - column("name", Item::getName) - column("time", Item::getTime) + val nameColumnt = column("name", Item::getName).apply { + sortType = TreeTableColumn.SortType.ASCENDING + } + + val timeColumn = column("time", Item::getTime).apply { + isVisible = false + } + + sortOrder.add(nameColumnt) addEventHandler(MouseEvent.MOUSE_CLICKED) { e: MouseEvent -> if (e.clickCount == 2) { @@ -85,6 +93,7 @@ class MainView : View() { } } + isTableMenuButtonVisible = true columnResizePolicy = CONSTRAINED_RESIZE_POLICY storageProperty.addListener { _, _, value -> @@ -92,11 +101,13 @@ class MainView : View() { Platform.runLater { root = TreeItem(Item(value)); + root.isExpanded = true + populate { parent -> val storage = parent.value.content; if (storage is Storage) { //TODO add legacy loaders here? - storage.shelves().map(::Item) + storage.loaders().map(::Item) + storage.shelves().map(::Item).sorted() + storage.loaders().map(::Item).sorted() } else { null } @@ -212,7 +223,11 @@ class MainView : View() { } } - class Item(val content: Named) { + class Item(val content: Named): Comparable { + override fun compareTo(other: Item): Int { + return AlphanumComparator.INSTANCE.compare(this.getName(),other.getName()) + } + fun getName(): String { return content.name; } diff --git a/numass-viewer/src/main/kotlin/inr/numass/viewer/NumassLoaderView.kt b/numass-viewer/src/main/kotlin/inr/numass/viewer/NumassLoaderView.kt index 9810695e..bac2d3d3 100644 --- a/numass-viewer/src/main/kotlin/inr/numass/viewer/NumassLoaderView.kt +++ b/numass-viewer/src/main/kotlin/inr/numass/viewer/NumassLoaderView.kt @@ -142,43 +142,45 @@ class NumassLoaderView : View() { } fun loadData(data: NumassData?) { - this.data = data - if (data != null) { - getWorkManager().startWork("viewer.numass.load") { work -> - work.title = "Load numass data (" + data.name + ")" - points.setAll(data.nmPoints) + synchronized(this) { + this.data = data + if (data != null) { + getWorkManager().startWork("viewer.numass.load") { work -> + work.title = "Load numass data (" + data.name + ")" + points.setAll(data.nmPoints) - Platform.runLater { - //setup detector data - setupDetectorPane(points) - //setup spectrum plot - setupSpectrumPane(points) + Platform.runLater { + //setup detector data + setupDetectorPane(points) + //setup spectrum plot + setupSpectrumPane(points) + } } - } - //setup hv plot - val hvData = data.hvData - if (hvData != null) { - setupHVPane(hvData) - } - setupInfo(data) + //setup hv plot + val hvData = data.hvData + if (hvData != null) { + setupHVPane(hvData) + } + setupInfo(data) - } else { - log.severe("The data model is null") + } else { + log.severe("The data model is null") + } +// tabPane.selectionModel.select(1) } - tabPane.selectionModel.select(1) } private fun setupHVPane(hvData: Supplier) { getWorkManager().startWork("viewer.numass.hv") { callback: Work -> val t = hvData.get() Platform.runLater { - hvPlot.plot.clear() +// hvPlot.plot.clear() val set = PlottableGroup() for (dp in t) { val block = dp.getString("block", "default") if (!set.has(block)) { - set.add(TimePlottable(block, block)) + set.add(TimePlottable(block)) } set.get(block).put(dp.getValue("timestamp").timeValue(), dp.getValue("value")) } @@ -268,8 +270,8 @@ class NumassLoaderView : View() { detectorPlotFrame = JFreeChartFrame(frameMeta) } else { detectorPlotFrame = detectorPlot.plot - detectorPlotFrame.clear() - detectorPlot.removePlot() +// detectorPlotFrame.clear() +// detectorPlot.removePlot() } getWorkManager().startWork("viewer.numass.load.detector") { callback: Work -> @@ -284,14 +286,19 @@ class NumassLoaderView : View() { callback.maxProgress = points.size.toDouble() callback.progress = 0.0 - for (point in points) { - val seriesName = String.format("%d: %.2f", points.indexOf(point), point.voltage) - val datum = PlottableData.plot(seriesName, XYAdapter("chanel", "count"), point.getData(binning, normalize)) - datum.configure(plottableConfig) - detectorPlotFrame.add(datum) - callback.increaseProgress(1.0) - //TODO add update instead of replace action + + runAsync { + points.map { point -> + val seriesName = String.format("%d: %.2f", points.indexOf(point), point.voltage) + val datum = PlottableData.plot(seriesName, XYAdapter("chanel", "count"), point.getData(binning, normalize)) + datum.configure(plottableConfig) + callback.increaseProgress(1.0) + datum; + } + } ui{ + detectorPlotFrame.setAll(it) } + detectorPlot.plot = detectorPlotFrame callback.setProgressToMax() } diff --git a/numass-viewer/src/main/kotlin/inr/numass/viewer/test/JFCTest.kt b/numass-viewer/src/main/kotlin/inr/numass/viewer/test/JFCTest.kt new file mode 100644 index 00000000..aab41b2f --- /dev/null +++ b/numass-viewer/src/main/kotlin/inr/numass/viewer/test/JFCTest.kt @@ -0,0 +1,40 @@ +package inr.numass.viewer.test + +import hep.dataforge.plots.data.PlottableData +import hep.dataforge.plots.fx.PlotContainer +import hep.dataforge.plots.jfreechart.JFreeChartFrame +import hep.dataforge.tables.MapPoint +import hep.dataforge.tables.XYAdapter +import tornadofx.* +import java.util.* + +/** + * Created by darksnake on 16-Apr-17. + */ +class JFCTest : View("My View") { + val rnd = Random(); + + val plot = JFreeChartFrame(); + val container = PlotContainer(); + val data = PlottableData("data"); + + val button = button("test") { + action { + + data.fillData( + (1..1000).map { MapPoint(arrayOf(XYAdapter.X_VALUE_KEY, XYAdapter.Y_VALUE_KEY), it, rnd.nextDouble()) } + ) + plot.add(data) + } + }; + + override val root = borderpane { + center { + container.plot = plot + add(container.root) + } + bottom { + add(button) + } + } +} diff --git a/numass-viewer/src/main/kotlin/inr/numass/viewer/test/TestApp.kt b/numass-viewer/src/main/kotlin/inr/numass/viewer/test/TestApp.kt new file mode 100644 index 00000000..babedfea --- /dev/null +++ b/numass-viewer/src/main/kotlin/inr/numass/viewer/test/TestApp.kt @@ -0,0 +1,9 @@ +package inr.numass.viewer.test + +import tornadofx.* + +/** + * Created by darksnake on 16-Apr-17. + */ +class TestApp: App(JFCTest::class) { +} \ No newline at end of file