![JAR search and dependency download from the Maven repository](/logo.png)
de.gsi.chart.utils.MasterSlaveAxisSynchronizer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of chartfx-chart Show documentation
Show all versions of chartfx-chart Show documentation
This charting library ${project.artifactId}- is an extension
in the spirit of Oracle's XYChart and performance/time-proven JDataViewer charting functionalities.
Emphasis was put on plotting performance for both large number of data points and real-time displays,
as well as scientific accuracies leading to error bar/surface plots, and other scientific plotting
features (parameter measurements, fitting, multiple axes, zoom, ...).
/*****************************************************************************
* *
* Common Chart - axis synchronization *
* *
* modified: 2018-08-23 Harald Braeuning *
* *
****************************************************************************/
package de.gsi.chart.utils;
import java.util.ArrayList;
import de.gsi.chart.axes.spi.AbstractAxis;
/**
* Synchronizes the axes of different slave charts to the axis of a master
* chart.
*
* @author braeun
*/
public class MasterSlaveAxisSynchronizer {
private final AbstractAxis master;
private final ArrayList slaves = new ArrayList<>();
public MasterSlaveAxisSynchronizer(AbstractAxis master) {
this.master = master;
master.upperBoundProperty().addListener((p, o, n) -> upperBoundChanged(n.doubleValue()));
master.lowerBoundProperty().addListener((p, o, n) -> lowerBoundChanged(n.doubleValue()));
}
public void add(AbstractAxis axis) {
slaves.add(axis);
axis.setAutoRanging(false);
axis.tickUnitProperty().bind(master.tickUnitProperty());
}
public void remove(AbstractAxis axis) {
slaves.remove(axis);
axis.tickUnitProperty().unbind();
axis.setAutoRanging(true);
}
private void upperBoundChanged(double value) {
if (Double.isNaN(value)) {
return;
}
for (final AbstractAxis slave : slaves) {
slave.setUpperBound(value);
// slave.setTickUnit(master.getTickUnit());
}
}
private void lowerBoundChanged(double value) {
if (Double.isNaN(value)) {
return;
}
for (final AbstractAxis slave : slaves) {
slave.setLowerBound(value);
// slave.setTickUnit(master.getTickUnit());
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy