Skip to content

Commit

Permalink
cleaned up axis style nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
ennerf committed Jun 29, 2023
1 parent 0a33bbc commit 5d3330b
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.util.concurrent.atomic.AtomicBoolean;

import io.fair_acc.chartfx.ui.layout.ChartPane;
import io.fair_acc.chartfx.utils.FXUtils;
import javafx.beans.property.*;
import javafx.beans.value.ChangeListener;
import javafx.collections.FXCollections;
Expand Down Expand Up @@ -55,14 +56,20 @@ public abstract class AbstractAxisParameter extends Pane implements Axis {
private final transient List<EventListener> updateListeners = Collections.synchronizedList(new LinkedList<>());

private final transient StyleableIntegerProperty dimIndex = CSS.createIntegerProperty(this, "dimIndex", -1, this::requestAxisLayout);

/**
* Paths used for css-type styling. Not used for actual drawing. Used as a storage container for the settings
* applied to GraphicsContext which allow much faster (and less complex) drawing routines but do no not allow
* CSS-type styling.
*/
private final transient Path majorTickStyle = new Path();
private final transient Path minorTickStyle = new Path();
private final transient AxisLabel axisLabel = new AxisLabel();
private final transient Path majorTickStyle = FXUtils.hiddenStyleNode(new Path(), "axis-tick-mark");
private final transient Path minorTickStyle = FXUtils.hiddenStyleNode(new Path(), "axis-minor-tick-mark");
private final transient Text axisLabel = FXUtils.hiddenStyleNode(new Text(), "axis-label");
{
FXUtils.addStyles(this, "axis");
getChildren().addAll(axisLabel, majorTickStyle, minorTickStyle);
}

/**
* This is the minimum/maximum current data value and it is used while auto ranging. Package private solely for test purposes
*
Expand Down Expand Up @@ -367,10 +374,6 @@ protected void invalidated() {
*/
public AbstractAxisParameter() {
super();
getStyleClass().setAll("axis");
majorTickStyle.getStyleClass().add("axis-tick-mark");
minorTickStyle.getStyleClass().add("axis-minor-tick-mark");
getChildren().addAll(axisLabel, majorTickStyle, minorTickStyle);
autoRangingProperty().addListener(ch -> {
// disable auto grow if auto range is enabled
if (isAutoRanging()) {
Expand Down Expand Up @@ -408,9 +411,6 @@ public AbstractAxisParameter() {
};
minProperty().addListener(userLimitChangeListener);
maxProperty().addListener(userLimitChangeListener);
majorTickStyle.applyCss();
minorTickStyle.applyCss();
axisLabel.applyCss();

minProperty().addListener(scaleChangeListener);
maxProperty().addListener(scaleChangeListener);
Expand Down

This file was deleted.

17 changes: 17 additions & 0 deletions chartfx-chart/src/main/java/io/fair_acc/chartfx/utils/FXUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,23 @@ public void run() {
}
}

public static <NODE extends Node> NODE hiddenStyleNode(NODE node, String... styles) {
hide(node);
addStyles(node, styles);
return node;
}

public static <NODE extends Node> NODE addStyles(NODE node, String... styles) {
node.getStyleClass().addAll(styles);
return node;
}

public static <NODE extends Node> NODE hide(NODE node) {
node.setVisible(false);
node.setManaged(false);
return node;
}

// Similar to internal Pane::setConstraint
public static <NODE extends Node> NODE setConstraint(NODE node, Object key, Object value) {
if (value == null) {
Expand Down

0 comments on commit 5d3330b

Please sign in to comment.