I need to move the label (Text
) of all tick marks in an Axis such that the text is right in the middle of its own tick mark and the next tick mark.
I am using Roland's GanttChart control (with some modifications) and Christian Schudt's DateAxis for my X-axis. My objective is to plot a gantt chart based on Date values (ignoring time; all time values are truncated).
My gantt chart has a "start date" and an "end date" for every single task (i.e. visually on the chart it is represented by a single bar).
Consider this:
I have a task starting on 1st Feb, and it ends on the same day (1st Feb). I have two ways to render this on the chart:
- Render it starting from 1st Feb, and ends at 1st Feb. This bar is effectively hidden, because its width is 0.
- Render it starting from 1st Feb, with the right-edge of the bar touching 2nd Feb. This can potentially confuse the users because it would look like it starts from 1st Feb and ends on 2nd Feb.
To solve the problem caused by method 2, I need to shift the text labels by half a tick mark width to the right. Doing this would make it very clear to the user.
I have tried doing this:
final DateAxis xAxis = (DateAxis) this.ganttchart.getXAxis();
xAxis.getChildrenUnmodifiable().addListener(new ListChangeListener<Node>()
{
@Override
public void onChanged(javafx.collections.ListChangeListener.Change<? extends Node> c)
{
final List<Node> labels = xAxis.getChildrenUnmodifiable().filtered(node -> node instanceof Text);
for (Node label : labels)
{
label.setTranslateX(xAxis.getWidth() / (labels.size() - 1) / 2);
}
}
});
However, doing so does not seem to shift the Text
labels to the right at all.