mirror of https://github.com/rusefi/jzy3d-api.git
cleanup legends
This commit is contained in:
parent
1d1e519320
commit
03803b4369
|
@ -33,11 +33,22 @@ public class Chart2d extends AWTChart {
|
|||
}
|
||||
|
||||
public Chart2d(Toolkit toolkit) {
|
||||
this(new Chart2dComponentFactory(), Quality.Intermediate, toolkit.toString());
|
||||
this(new Chart2dComponentFactory(), toolkit);
|
||||
}
|
||||
|
||||
public Chart2d(Chart2dComponentFactory factory, Toolkit toolkit) {
|
||||
this(factory, Quality.Intermediate, toolkit);
|
||||
}
|
||||
public Chart2d(Chart2dComponentFactory factory, Quality quality) {
|
||||
this(factory, quality, Toolkit.newt);
|
||||
}
|
||||
|
||||
public Chart2d(Chart2dComponentFactory factory, Quality quality, Toolkit toolkit) {
|
||||
this(factory, quality, toolkit.toString());
|
||||
layout2d();
|
||||
}
|
||||
|
||||
|
||||
public void layout2d() {
|
||||
IAxeLayout axe = getAxeLayout();
|
||||
axe.setZAxeLabelDisplayed(false);
|
||||
|
|
|
@ -60,7 +60,7 @@ abstract class AbstractViewportManager {
|
|||
*/
|
||||
public void setViewPort(int width, int height, float left, float right) {
|
||||
if (left >= right)
|
||||
throw new IllegalArgumentException("left must be inferior to right");
|
||||
throw new IllegalArgumentException("left must be inferior to right : " + left + " | " + right);
|
||||
|
||||
this.screenWidth = (int) ((right - left) * (float) width);
|
||||
this.screenHeight = height;
|
||||
|
|
|
@ -56,7 +56,7 @@ public abstract class AWTAbstractImageGenerator implements AWTImageGenerator{
|
|||
|
||||
|
||||
protected Font font;
|
||||
protected int txtSize;
|
||||
protected int textSize;
|
||||
|
||||
protected Color backgroundColor;
|
||||
protected Color foregroundColor = Color.BLACK;
|
||||
|
|
|
@ -30,8 +30,8 @@ public class AWTColorbarImageGenerator extends AWTAbstractImageGenerator impleme
|
|||
this.renderer = renderer;
|
||||
this.min = mapper.getMin();
|
||||
this.max = mapper.getMax();
|
||||
this.txtSize = 12;
|
||||
this.font = new java.awt.Font("Arial",0,txtSize);
|
||||
this.textSize = 12;
|
||||
this.font = new java.awt.Font("Arial",0,textSize);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -55,13 +55,13 @@ public class AWTColorbarImageGenerator extends AWTAbstractImageGenerator impleme
|
|||
|
||||
public void drawBarContour(int height, int barWidth, Graphics2D graphic) {
|
||||
graphic.setColor(ColorAWT.toAWT(foregroundColor));
|
||||
graphic.drawRect(0, txtSize/2, barWidth, height-txtSize);
|
||||
graphic.drawRect(0, textSize/2, barWidth, height-textSize);
|
||||
}
|
||||
|
||||
public void drawBarColors(int height, int barWidth, Graphics2D graphic) {
|
||||
for(int h=txtSize/2; h<=(height-txtSize/2); h++){
|
||||
for(int h=textSize/2; h<=(height-textSize/2); h++){
|
||||
// Compute value & color
|
||||
double v = min + (max-min) * ((float)h)/((float)(height-txtSize));
|
||||
double v = min + (max-min) * ((float)h)/((float)(height-textSize));
|
||||
Color c = mapper.getColor(v); //To allow the Color to be a variable independent of the coordinates
|
||||
|
||||
// Draw line
|
||||
|
@ -77,7 +77,7 @@ public class AWTColorbarImageGenerator extends AWTAbstractImageGenerator impleme
|
|||
String txt;
|
||||
for(int t=0; t<ticks.length; t++){
|
||||
// ypos = (int)(height-height*((ticks[t]-min)/(max-min)));
|
||||
ypos = (int)(txtSize+(height-txtSize-(height-txtSize)*((ticks[t]-min)/(max-min)))); //Making sure that the first and last tick appear in the colorbar
|
||||
ypos = (int)(textSize+(height-textSize-(height-textSize)*((ticks[t]-min)/(max-min)))); //Making sure that the first and last tick appear in the colorbar
|
||||
txt = renderer.format(ticks[t]);
|
||||
graphic.drawString(txt, barWidth+1, ypos);
|
||||
}
|
||||
|
|
|
@ -110,8 +110,33 @@ public abstract class AWTLegend extends AWTImageViewport implements IDrawableLis
|
|||
} else
|
||||
imageGenerator.setHasBackground(false);
|
||||
}
|
||||
|
||||
|
||||
public Color getForeground() {
|
||||
return foreground;
|
||||
}
|
||||
|
||||
public void setForeground(Color foreground) {
|
||||
this.foreground = foreground;
|
||||
}
|
||||
|
||||
public Color getBackground() {
|
||||
return background;
|
||||
}
|
||||
|
||||
public void setBackground(Color background) {
|
||||
this.background = background;
|
||||
}
|
||||
|
||||
public Dimension getMinimumDimension() {
|
||||
return minimumDimension;
|
||||
}
|
||||
|
||||
public void setMinimumDimension(Dimension minimumDimension) {
|
||||
this.minimumDimension = minimumDimension;
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected AbstractDrawable drawable;
|
||||
protected Color foreground;
|
||||
protected Color background;
|
||||
|
|
|
@ -30,7 +30,12 @@ public class ColorbarViewportLayout implements IViewportLayout{
|
|||
final ICanvas canvas = chart.getCanvas();
|
||||
final List<ILegend> list = scene.getGraph().getLegends();
|
||||
|
||||
// Compute an optimal layout so that we use the minimal area for metadata
|
||||
computeSeparator(canvas, list);
|
||||
sceneViewPort = ViewportBuilder.column(canvas, 0, screenSeparator);
|
||||
backgroundViewPort = new ViewportConfiguration(canvas);
|
||||
}
|
||||
|
||||
public void computeSeparator(final ICanvas canvas, final List<ILegend> list) {
|
||||
hasMeta = list.size() > 0;
|
||||
if (hasMeta) {
|
||||
int minwidth = 0;
|
||||
|
@ -42,11 +47,7 @@ public class ColorbarViewportLayout implements IViewportLayout{
|
|||
else{
|
||||
screenSeparator = 1.0f;
|
||||
}
|
||||
|
||||
sceneViewPort = ViewportBuilder.column(canvas, 0, screenSeparator);
|
||||
backgroundViewPort = new ViewportConfiguration(canvas);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void render(GL gl, GLU glu, Chart chart){
|
||||
|
@ -54,15 +55,20 @@ public class ColorbarViewportLayout implements IViewportLayout{
|
|||
view.renderBackground(gl, glu, backgroundViewPort);
|
||||
view.renderScene(gl, glu, sceneViewPort);
|
||||
|
||||
Scene scene = chart.getScene();
|
||||
if (hasMeta)
|
||||
renderLegends(gl, glu, screenSeparator, 1.0f, scene.getGraph().getLegends(), chart.getCanvas());
|
||||
|
||||
|
||||
// fix overlay on top of chart
|
||||
//System.out.println(scenePort);
|
||||
view.renderOverlay(gl, view.getCamera().getLastViewPort());
|
||||
}
|
||||
|
||||
protected void renderLegends(GL gl, GLU glu, Chart chart){
|
||||
if (hasMeta){
|
||||
Scene scene = chart.getScene();
|
||||
|
||||
renderLegends(gl, glu, screenSeparator, 1.0f, scene.getGraph().getLegends(), chart.getCanvas());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the legend within the screen slice given by the left and right parameters.
|
||||
*/
|
||||
|
@ -81,22 +87,18 @@ public class ColorbarViewportLayout implements IViewportLayout{
|
|||
public void paint(Graphics g) {
|
||||
if (pencil == null)
|
||||
pencil = new CanvasAWT((Graphics2D) g);
|
||||
|
||||
if (zone1.width > 0)
|
||||
pencil.drawRect(null, zone1.x, zone1.y, zone1.width, zone1.height, true);
|
||||
if (zone2.width > 0)
|
||||
pencil.drawRect(null, zone2.x, zone2.y, zone2.width, zone2.height, true);
|
||||
}
|
||||
|
||||
CanvasAWT pencil = null;
|
||||
};
|
||||
view.addRenderer2d(layoutBorder);
|
||||
}
|
||||
|
||||
|
||||
Rectangle zone1 = new Rectangle(0, 0, 0, 0);
|
||||
Rectangle zone2 = new Rectangle(0, 0, 0, 0);
|
||||
|
||||
protected Rectangle zone1 = new Rectangle(0, 0, 0, 0);
|
||||
protected Rectangle zone2 = new Rectangle(0, 0, 0, 0);
|
||||
protected ViewportConfiguration sceneViewPort;
|
||||
protected ViewportConfiguration backgroundViewPort;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue