use of javafx.scene.chart.NumberAxis in project bisq-desktop by bisq-network.
the class VolumeChart method layoutPlotChildren.
@Override
protected void layoutPlotChildren() {
if (getData() == null) {
return;
}
for (int seriesIndex = 0; seriesIndex < getData().size(); seriesIndex++) {
XYChart.Series<Number, Number> series = getData().get(seriesIndex);
Iterator<XYChart.Data<Number, Number>> iter = getDisplayedDataIterator(series);
while (iter.hasNext()) {
XYChart.Data<Number, Number> item = iter.next();
double x = getXAxis().getDisplayPosition(getCurrentDisplayedXValue(item));
double y = getYAxis().getDisplayPosition(getCurrentDisplayedYValue(item));
Node itemNode = item.getNode();
CandleData candleData = (CandleData) item.getExtraValue();
if (itemNode instanceof VolumeBar && candleData != null) {
VolumeBar volumeBar = (VolumeBar) itemNode;
double candleWidth = -1;
if (getXAxis() instanceof NumberAxis) {
NumberAxis xa = (NumberAxis) getXAxis();
// use 90% width between ticks
candleWidth = xa.getDisplayPosition(xa.getTickUnit()) * 0.90;
}
// 97 is visible chart data height if chart height is 140.
// So we subtract 43 form the height to get the height for the bar to the bottom.
// Did not find a way how to request the chart data height
final double height = getHeight() - 43;
// We want min 5px height to allow tooltips
double upperYPos = Math.min(height - 5, y);
volumeBar.update(height - upperYPos, candleWidth, candleData);
volumeBar.setLayoutX(x);
volumeBar.setLayoutY(upperYPos);
}
}
}
}
use of javafx.scene.chart.NumberAxis in project Smartcity-Smarthouse by TechnionYP5777.
the class Controller method initialize.
/*
* (non-Javadoc)
*
* @see javafx.fxml.Initializable#initialize(java.net.URL,
* java.util.ResourceBundle)
*/
@Override
public void initialize(final URL location, final ResourceBundle __) {
pulseLabel.setDisable(false);
bpLabel.setDisable(false);
xAxis.setForceZeroInRange(false);
xAxis.setAutoRanging(false);
xAxis.setTickLabelsVisible(false);
xAxis.setTickMarkVisible(false);
xAxis.setMinorTickVisible(false);
final NumberAxis bpYAxis = new NumberAxis();
bpYAxis.setLabel("Blood Pressure (mmHg)");
final NumberAxis pulseXAxis = new NumberAxis();
pulseXAxis.setAutoRanging(false);
pulseXAxis.setVisible(false);
pulseXAxis.lowerBoundProperty().bind(xAxis.lowerBoundProperty());
pulseXAxis.upperBoundProperty().bind(xAxis.upperBoundProperty());
pulseXAxis.tickUnitProperty().bind(xAxis.tickUnitProperty());
final NumberAxis pulseYAxis = new NumberAxis();
pulseYAxis.setSide(Side.RIGHT);
pulseYAxis.setLabel("Pulse (BPM)");
final LineChart<Number, Number> bpLineChart = new LineChart<Number, Number>(xAxis, bpYAxis) {
@Override
protected void dataItemAdded(final Series<Number, Number> __1, final int itemIndex, final Data<Number, Number> item) {
// Remove symbols from data points
}
}, pulseLineChart = new LineChart<Number, Number>(xAxis, pulseYAxis) {
@Override
protected void dataItemAdded(final Series<Number, Number> __1, final int itemIndex, final Data<Number, Number> item) {
// Remove symbols from data points
}
};
bpLineChart.setDisable(false);
pulseLineChart.setDisable(false);
tmpSeries.setName("Pulse");
systolicSeries.setName("Systolic");
diastolicSeries.setName("Diastolic");
pulseLineChart.getData().add(pulseSeries);
bpLineChart.getData().add(tmpSeries);
bpLineChart.getData().add(systolicSeries);
bpLineChart.getData().add(diastolicSeries);
bpLineChart.lookup(".chart-content").lookup(".chart-plot-background").setStyle("-fx-background-color: transparent;");
bpLineChart.setVerticalGridLinesVisible(false);
bpLineChart.setHorizontalGridLinesVisible(false);
final Pane tmpBackPane = new Pane();
tmpBackPane.setMinSize(SIZE, Region.USE_COMPUTED_SIZE);
tmpBackPane.setMaxSize(SIZE, Region.USE_COMPUTED_SIZE);
final Pane tmpFrontPane = new Pane();
tmpFrontPane.setMinSize(SIZE, Region.USE_COMPUTED_SIZE);
tmpFrontPane.setMaxSize(SIZE, Region.USE_COMPUTED_SIZE);
backHBox.setMaxSize(Region.USE_COMPUTED_SIZE, Region.USE_COMPUTED_SIZE);
frontHBox.setMaxSize(Region.USE_COMPUTED_SIZE, Region.USE_COMPUTED_SIZE);
HBox.setHgrow(pulseLineChart, Priority.ALWAYS);
HBox.setHgrow(bpLineChart, Priority.ALWAYS);
VBox.setVgrow(stackPane, Priority.ALWAYS);
backHBox.getChildren().add(tmpBackPane);
backHBox.getChildren().add(pulseLineChart);
frontHBox.getChildren().add(bpLineChart);
frontHBox.getChildren().add(tmpFrontPane);
stackPane.getChildren().add(backHBox);
stackPane.getChildren().add(frontHBox);
}
use of javafx.scene.chart.NumberAxis in project tilesfx by HanSolo.
the class SmoothedChart method select.
private void select(final MouseEvent EVT) {
if (!isInteractive()) {
return;
}
final double EVENT_X = EVT.getX();
final double EVENT_Y = EVT.getY();
final double CHART_X = chartPlotBackground.getBoundsInParent().getMinX();
final double CHART_MIN_Y = chartPlotBackground.getBoundsInParent().getMinY();
final double CHART_HEIGHT = chartPlotBackground.getBoundsInParent().getHeight();
if (!(getYAxis() instanceof NumberAxis)) {
return;
}
double upperBound = ((NumberAxis) getYAxis()).getUpperBound();
double lowerBound = ((NumberAxis) getYAxis()).getLowerBound();
double range = upperBound - lowerBound;
double factor = range / getYAxis().getLayoutBounds().getHeight();
List<PathElement> elements = null;
int noOfElements = 0;
Bounds pathBounds = null;
double pathMinX = 0;
double pathWidth = 0;
PathElement lastElement = null;
Series<X, Y> series = null;
for (Series<X, Y> s : getData()) {
Path[] paths = getPaths(s);
// AREA == 0, LINE == 1 in ChartType enum
int type = getChartType().ordinal();
if (paths[type].contains(EVENT_X, EVENT_Y)) {
series = s;
elements = paths[type].getElements();
noOfElements = elements.size();
lastElement = elements.get(0);
pathBounds = paths[1].getLayoutBounds();
pathMinX = pathBounds.getMinX();
pathWidth = pathBounds.getWidth();
break;
}
}
if (null == series || series.getData().isEmpty()) {
return;
}
if (isSnapToTicks()) {
double reverseFactor = CHART_HEIGHT / range;
int noOfDataElements = series.getData().size();
double interval = pathWidth / (double) (noOfDataElements - 1);
int selectedIndex = Helper.roundDoubleToInt((EVENT_X - pathMinX) / interval);
Data<X, Y> selectedData = series.getData().get(selectedIndex);
Y selectedYValue = selectedData.getYValue();
if (!(selectedYValue instanceof Number)) {
return;
}
double selectedValue = ((Number) selectedYValue).doubleValue();
selector.setCenterX(pathMinX + CHART_X + interval * selectedIndex);
selector.setCenterY((CHART_MIN_Y + CHART_HEIGHT) - (selectedValue * reverseFactor));
selector.setVisible(true);
fadeInFadeOut.playFrom(Duration.millis(0));
Point2D tooltipLocation = selector.localToScreen(selector.getCenterX(), selector.getCenterY());
String tooltipText = new StringBuilder(selectedData.getXValue().toString()).append("\n").append(selectedData.getYValue()).toString();
selectorTooltip.setText(tooltipText);
selectorTooltip.setX(tooltipLocation.getX());
selectorTooltip.setY(tooltipLocation.getY());
selectorTooltip.show(getScene().getWindow());
fireEvent(new SmoothedChartEvent(SmoothedChart.this, null, SmoothedChartEvent.DATA_SELECTED, selectedValue));
} else {
for (int i = 1; i < noOfElements; i++) {
PathElement element = elements.get(i);
double[] xy = getXYFromPathElement(lastElement);
double[] xy1 = getXYFromPathElement(element);
if (xy[0] < 0 || xy[1] < 0 || xy1[0] < 0 || xy1[1] < 0) {
continue;
}
if (EVENT_X > xy[0] && EVENT_X < xy1[0]) {
double deltaX = xy1[0] - xy[0];
double deltaY = xy1[1] - xy[1];
double m = deltaY / deltaX;
double y = m * (EVT.getX() - xy[0]) + xy[1];
double selectedValue = ((getYAxis().getLayoutBounds().getHeight() - y) * factor + lowerBound);
selector.setCenterX(CHART_X + EVT.getX());
selector.setCenterY(CHART_MIN_Y + y);
selector.setVisible(true);
fadeInFadeOut.playFrom(Duration.millis(0));
Point2D tooltipLocation = selector.localToScreen(selector.getCenterX(), selector.getCenterY());
String tooltipText = new StringBuilder(String.format(Locale.US, formatString, selectedValue)).toString();
selectorTooltip.setText(tooltipText);
selectorTooltip.setX(tooltipLocation.getX());
selectorTooltip.setY(tooltipLocation.getY());
selectorTooltip.show(getScene().getWindow());
fireEvent(new SmoothedChartEvent(SmoothedChart.this, null, SmoothedChartEvent.DATA_SELECTED, selectedValue));
break;
}
lastElement = element;
}
}
}
use of javafx.scene.chart.NumberAxis in project jvarkit by lindenb.
the class BasesPerPositionChartFactory method build.
@Override
public StackedBarChart<String, Number> build() {
final CategoryAxis xAxis = new CategoryAxis();
xAxis.setLabel("Position in Read");
final NumberAxis yAxis = new NumberAxis();
yAxis.setLabel("Count");
final List<XYChart.Series<String, Number>> base2count = new ArrayList<>(all_chars.size());
for (final Character base : all_chars) {
final XYChart.Series<String, Number> serie = new XYChart.Series<String, Number>();
serie.setName(base.toString());
base2count.add(serie);
for (int i = 0; i < this.pos2base2count.size(); ++i) {
serie.getData().add(new XYChart.Data<String, Number>(String.valueOf(i + 1), this.pos2base2count.get(i).count(base)));
}
}
final StackedBarChart<String, Number> sbc = new StackedBarChart<String, Number>(xAxis, yAxis);
sbc.setTitle("Position/Base/Count");
sbc.getData().addAll(base2count);
sbc.setCategoryGap(0.2);
return sbc;
}
use of javafx.scene.chart.NumberAxis in project jvarkit by lindenb.
the class CigarOpPerPositionChartFactory method build.
@Override
public StackedBarChart<String, Number> build() {
final CategoryAxis xAxis = new CategoryAxis();
xAxis.setLabel("Position in Read");
final NumberAxis yAxis = new NumberAxis();
yAxis.setLabel("Count");
final List<XYChart.Series<String, Number>> base2count = new ArrayList<>();
for (final CigarOperator cigarop : CigarOperator.values()) {
if (cigarop == CigarOperator.P)
continue;
final XYChart.Series<String, Number> serie = new XYChart.Series<String, Number>();
serie.setName(cigarop.name());
base2count.add(serie);
for (int i = 0; i < this.cigar2pos2count.size(); ++i) {
serie.getData().add(new XYChart.Data<String, Number>(String.valueOf(i + 1), this.cigar2pos2count.get(i).count(cigarop)));
}
}
final StackedBarChart<String, Number> sbc = new StackedBarChart<String, Number>(xAxis, yAxis);
sbc.setTitle(getName());
sbc.getData().addAll(base2count);
sbc.setCategoryGap(0.2);
return sbc;
}
Aggregations