Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
hageldave committed Oct 18, 2024
2 parents 28d6b48 + 7859fa8 commit 4b133da
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ public class CoordSysRenderer implements Renderer {

protected Rectangle2D coordinateView = new Rectangle2D.Double(-1,-1,2,2);

protected TickMarkGenerator tickMarkGenerator = new ExtendedWilkinson();
protected TickMarkGenerator tickMarkGeneratorX = new ExtendedWilkinson();
protected TickMarkGenerator tickMarkGeneratorY = tickMarkGeneratorX;

protected Lines axes = new Lines().setVertexRoundingEnabled(true);
protected Lines ticks = new Lines().setVertexRoundingEnabled(true);
Expand Down Expand Up @@ -477,12 +478,12 @@ public int getLegendBottomHeight() {
* </ul>
*/
protected void setupAndLayout() {
Pair<double[],String[]> xticksAndLabels = tickMarkGenerator.genTicksAndLabels(
Pair<double[],String[]> xticksAndLabels = tickMarkGeneratorX.genTicksAndLabels(
coordinateView.getMinX(),
coordinateView.getMaxX(),
5,
false);
Pair<double[],String[]> yticksAndLabels = tickMarkGenerator.genTicksAndLabels(
Pair<double[],String[]> yticksAndLabels = tickMarkGeneratorY.genTicksAndLabels(
coordinateView.getMinY(),
coordinateView.getMaxY(),
5,
Expand Down Expand Up @@ -656,23 +657,61 @@ public CoordSysRenderer setyAxisLabel(String yAxisLabel) {
/**
* @return the current {@link TickMarkGenerator} which is {@link ExtendedWilkinson} by default.
*/
public TickMarkGenerator getTickMarkGenerator() {
return tickMarkGenerator;
public TickMarkGenerator getTickMarkGeneratorX() {
return tickMarkGeneratorX;
}

/**
* @return the current {@link TickMarkGenerator} which is {@link ExtendedWilkinson} by default.
*/
public TickMarkGenerator getTickMarkGeneratorY() {
return tickMarkGeneratorX;
}

/**
* Sets the specified {@link TickMarkGenerator} for this {@link CoordSysRenderer}.
* This sets the same generator for x- and y-axis.
* Sets the {@link #isDirty} state of this {@link CoordSysRenderer} to true.
* @param tickMarkGenerator to be used for determining tick locations
* and corresponding labels
* @return this for chaining
*/
public CoordSysRenderer setTickMarkGenerator(TickMarkGenerator tickMarkGenerator) {
this.tickMarkGenerator = tickMarkGenerator;
this.tickMarkGeneratorX = this.tickMarkGeneratorY = tickMarkGenerator;
setDirty();
return this;
}

/**
* Sets the specified {@link TickMarkGenerator} for the x-axis of this {@link CoordSysRenderer}.
* Sets the {@link #isDirty} state of this {@link CoordSysRenderer} to true.
* @param tickMarkGenerator to be used for determining tick locations
* and corresponding labels
* @return this for chaining
*/
public CoordSysRenderer setTickMarkGeneratorX(TickMarkGenerator tickMarkGenerator) {
this.tickMarkGeneratorX = tickMarkGenerator;
setDirty();
return this;
}

/**
* Sets the specified {@link TickMarkGenerator} for the y-axis of this {@link CoordSysRenderer}.
* Sets the {@link #isDirty} state of this {@link CoordSysRenderer} to true.
* @param tickMarkGenerator to be used for determining tick locations
* and corresponding labels
* @return this for chaining
*/
public CoordSysRenderer setTickMarkGeneratorY(TickMarkGenerator tickMarkGenerator) {
this.tickMarkGeneratorY = tickMarkGenerator;
setDirty();
return this;
}





@Override
public void glInit() {
preContentLinesR.glInit();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,7 @@ public static void oldWay() {
// set the content renderer of the coordinate system
coordsys.setContent(barRenderer);
// we need to change the tick marks labeling for the y axis
TickMarkGenerator oldTickGen = coordsys.getTickMarkGenerator();
coordsys.setTickMarkGenerator((min,max,desired,vert)->{
if(!vert){
return oldTickGen.genTicksAndLabels(min,max,desired,vert);
}
coordsys.setTickMarkGeneratorY((min,max,desired,vert)->{
// make ticks at integer values (0,1,2,...)
double[] ticks = IntStream.range(0, cases.length)
.mapToDouble(i -> (double)i)
Expand Down

0 comments on commit 4b133da

Please sign in to comment.