I'm trying to format range labels on my graph so they sit inside the plotting area to maximize my real estate.
The problem I have is I can't figure out how to position the range labels vertical leaving me with the labels getting cut of as so: To get the graph pictured I use the following:
plot.setRangeBoundaries(-300, 300, BoundaryMode.FIXED);
plot.getGraph().setMargins(-100,0,0,-80);
plot.getGraph().getLineLabelInsets().setLeft(PixelUtils.dpToPix(60));
What's the best way of positioning labels internally?
So I was never quite able to get the labels to format correctly, as a workaround I added my own custom labels.
There is a way to set custom labels via LineLabelStyle but if we were to use that we would end up in the same situation.
So instead we use TextView with the xml attribute android:elevation="1dp". Because I implement PanZoom we have to intercept the touch events and update the labels accordinly based on PanZoom changes.
Here is a basic implementation of updating TextView labels when the user PanZooms:
PanZoom.attach(plot).setDelegate(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
switch (motionEvent.getAction()) {
case MotionEvent.ACTION_DOWN: {
//Update graph labels with plot.getBounds().asRectF();
rangeLabel1.setText("My TextView rangeLabel gets updated here!");
rangeLabel2.setText("You have to calculate value for each label")
domainLabel1.setText("Do the same for domain labels also");
domainLabel2.setText("etc...");
break;
}
case MotionEvent.ACTION_MOVE: {
//Update graph labels with plot.getBounds().asRectF();
rangeLabel1.setText("My TextView rangeLabel gets updated here!");
rangeLabel2.setText("You have to calculate value for each label")
domainLabel1.setText("Do the same for domain labels also");
domainLabel2.setText("etc...");
break;
}
case MotionEvent.ACTION_UP: {
//Update graph labels with plot.getBounds().asRectF();
rangeLabel1.setText("My TextView rangeLabel gets updated here!");
rangeLabel2.setText("You have to calculate value for each label")
domainLabel1.setText("Do the same for domain labels also");
domainLabel2.setText("etc...");
break;
}
}
//Return false to allow PanZoom to receive control
return false;
}
});