Updates to the data map for JavaFX

This commit is contained in:
Jamie Mac 2024-07-29 16:04:46 +01:00
parent 9e65fb18f4
commit 7e4ee768d2
4 changed files with 227 additions and 110 deletions

View File

@ -0,0 +1,101 @@
package dataMap.layoutFX;
import java.util.ArrayList;
import PamController.OfflineDataStore;
import PamController.PamController;
import dataMap.DataMapControl;
import dataMap.OfflineDataMap;
import dataMap.OfflineDataMapPoint;
import javafx.scene.paint.Color;
import pamViewFX.fxNodes.pamScrollers.acousticScroller.ScrollBarPane;
/**
* A scroll bar whihc shows a summary fo the data.
*/
public class DataMapScrollPane extends ScrollBarPane {
private DataMapControl dataMapControl;
public DataMapScrollPane(DataMapControl dataMapControl) {
super();
this.dataMapControl=dataMapControl;
}
/**
* Paint a summary of the data
*/
public void paintDataSummary() {
ArrayList<OfflineDataStore> offlineDataStores = PamController.getInstance().findOfflineDataStores();
OfflineDataStore aSource;
Color color = Color.DODGERBLUE;
this.getDrawCanvas().getGraphicsContext2D().setStroke(color);
this.getDrawCanvas().getGraphicsContext2D().setGlobalAlpha(0.3);
for (int i = 0; i < offlineDataStores.size(); i++) {
aSource = offlineDataStores.get(i);
paintOfflineDataSource(aSource);
}
}
/**
* Paint the data on the canvas.
* @param dataSource - the dta source.
*/
private void paintOfflineDataSource(OfflineDataStore dataSource) {
if (dataMapControl.getMappedDataBlocks()==null) return;
OfflineDataMap aMap;
for (int i = 0; i < dataMapControl.getMappedDataBlocks().size(); i++) {
aMap = dataMapControl.getMappedDataBlocks().get(i).getOfflineDataMap(dataSource);
if (aMap == null) {
continue;
}
long lastTime;
OfflineDataMapPoint aPoint;
for (int j=0; j<aMap.getMapPoints().size(); j++) {
aPoint= (OfflineDataMapPoint) aMap.getMapPoints().get(j);
//now have to paint the canvas. To be efficient find the start pixel, then iterate through all the
//the other pixels.
double startPixel = time2Pixel(aPoint.getStartTime());
double endPixel = time2Pixel(aPoint.getEndTime());
for (double k=startPixel; k<endPixel ; k++) {
this.getDrawCanvas().getGraphicsContext2D().strokeLine(k, 0, k, this.getDrawCanvas().getHeight());
}
}
}
}
/**
* Convert a time in millis to a pixel on the canvas.
* @param time
* @return
*/
private double time2Pixel(long time) {
double timeRangemillis = this.getMaxVal() - this.getMinVal();
double frac = ((double) (time - dataMapControl.getFirstTime()))/timeRangemillis;
return frac*this.getDrawCanvas().getWidth();
}
private long pixel2Time(double pixel) {
double frac = pixel/this.getDrawCanvas().getWidth();
double timeRangemillis = this.getMaxVal() - this.getMinVal();
long timeMillis = (long) (frac*timeRangemillis) + dataMapControl.getFirstTime();
return timeMillis;
}
}

View File

@ -242,6 +242,8 @@ public class DataStreamPaneFX extends PamBorderPane {
private DataGraphFX() {
createDataGraph();
addDataGraphMouse();
}
@ -311,6 +313,8 @@ public class DataStreamPaneFX extends PamBorderPane {
//create canvas for overlaid drawings
drawCanvas=new Canvas(90,90);
plotCanvas. getGraphicsContext2D(). setImageSmoothing(false);
Pane pane = new Pane();
pane.getChildren().add(plotCanvas);
pane.getChildren().add(drawCanvas);

View File

@ -78,7 +78,7 @@ public class ScrollingDataPaneFX extends PamBorderPane {
/**
* Scroll bar for time (horizontal)
*/
private ScrollBarPane timeScrollBar;
private DataMapScrollPane timeScrollBar;
/**
* Settings strip at top of the display. Shows all sorts of detailed info such cursor position and start and end times.
@ -215,7 +215,7 @@ public class ScrollingDataPaneFX extends PamBorderPane {
//create the scroll bar and listeners.
timeScrollBar=new ScrollBarPane();
timeScrollBar=new DataMapScrollPane(this.dataMapControl);
timeScrollBar.addValueListener((obs_val, old_val, new_val)->{
System.out.println("Scroll bar seconds: " + timeScrollBar.getCurrentValue() + " vis amount: " + timeScrollBar.visibleAmountProperty().get());
calcStartEndMillis();
@ -365,13 +365,14 @@ public class ScrollingDataPaneFX extends PamBorderPane {
long dataEnd = dataMapControl.getLastTime();
double dataSeconds = ((dataEnd-dataStart)/1000) + 1;
double pixsPerHour = getPixelsPerHour();
double pixsPerSecond = pixsPerHour / 3600;
double screenWidth = getPlotWidth();
screenSeconds = screenWidth / Math.min(600. / 3600, pixsPerSecond);
// if (dataStart == Long.MAX_VALUE || screenSeconds >= dataSeconds) {
// System.out.println("dataSeconds1: "+dataSeconds+ " pixsPerHour: " +pixsPerHour+" screenWidth: "+screenWidth+" screenSeconds "+screenSeconds+ " holder width: "+holder.getWidth());
// /*
@ -390,7 +391,14 @@ public class ScrollingDataPaneFX extends PamBorderPane {
// timeScrollBar.setUnitIncrement(Math.max(1, screenSeconds / 20));
timeScrollBar.setVisibleAmount(screenSeconds*1000L);
timeScrollBar.setCurrentValue(currentPos);
// }
//now paint the canvas to show the data.
try {
timeScrollBar.paintDataSummary();
}
catch (Exception e) {
e.printStackTrace();
}
}

View File

@ -312,6 +312,7 @@ public class ScrollBarPane extends PamBorderPane {
rightDrag.getChildren().add(rightdragLine);
rectangle.getChildren().add(rightDrag);
rectangle.setCursor(Cursor.OPEN_HAND); //Change cursor to hand
//now set behaviours
leftDrag.setOnMousePressed((event)->{
@ -369,12 +370,14 @@ public class ScrollBarPane extends PamBorderPane {
rightDrag.setOnMousePressed((event)->{
leftLayoutX=rectangle.getLayoutX();
isChanging.set(true);
rectangle.setCursor(Cursor.CLOSED_HAND); //Change cursor to hand
dragStarted(event, rightDrag);
});
rightDrag.setOnMouseReleased((event)->{
currentValueProperty.setValue(calcScrollBarVal(rectangle.getLayoutX()));
isChanging.set(false);
rectangle.setCursor(Cursor.OPEN_HAND); //Change cursor to hand
dragging(event);
});
@ -427,6 +430,7 @@ public class ScrollBarPane extends PamBorderPane {
rectangleDragged(event);
});
return rectangle;
}