Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2D charts improvements #267

Merged
merged 39 commits into from
May 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
43119ef
Fix up side down 2D chart and double axis labels with EmulGL
jzy3d May 10, 2022
3a7a076
Working 2D layout with pixel based margins
jzy3d May 10, 2022
ebf6b21
Working 2D layout with pixel based margins
jzy3d May 10, 2022
a1b67df
Working 2D layout with text based margins
jzy3d May 10, 2022
2b385d2
improve 2D layout precision and add doc
jzy3d May 10, 2022
0ebd913
improve 2D layout precision
jzy3d May 10, 2022
ba72f45
Adding integration tests for 2D parameter effects verifications
jzy3d May 11, 2022
242655a
Refactor existings tests with forEach operator
jzy3d May 11, 2022
e6df089
using lambda style for test iterators
jzy3d May 11, 2022
17fc07e
adding M1 baseline images
jzy3d May 11, 2022
1b01dae
Remove useless IAxisLayout interface
jzy3d May 11, 2022
0079851
Include Axis Label distance in 2D chart margin calculations
jzy3d May 11, 2022
333650f
Refactor a bit
jzy3d May 11, 2022
3dd4349
Allow symetric margins, WIP: Y axis layout rotated in 2D with accurat…
jzy3d May 12, 2022
875e583
Adding an exact function for processing 2D margins accurately
jzy3d May 13, 2022
5c9d389
Code cleanup and more unit tests
jzy3d May 16, 2022
3737ab5
fix tests
jzy3d May 16, 2022
7806a28
clean
jzy3d May 16, 2022
937f106
fix bug
jzy3d May 16, 2022
8a16b1e
Save changes related to chart2D changes
jzy3d May 17, 2022
0d95458
tiny changes
jzy3d May 17, 2022
ab12bb0
merge
jzy3d May 17, 2022
e0a10c6
fix
jzy3d May 17, 2022
10d92e1
Let axis appear better for 2D charts. Added 2 tutorials for surface a…
jzy3d May 17, 2022
58914b8
Adding an image post renderer to 3D charts
jzy3d May 17, 2022
2b5edb6
Working colorbar mixing with 2D margins, update UI tests to verify ov…
jzy3d May 17, 2022
e422246
Handling logo properly on native chart. Colorbar margin properly edit…
jzy3d May 18, 2022
95635d4
Clarify and simplify colorbar layout for HiDPI mode
jzy3d May 19, 2022
1c1dc36
Improve 3D to 2D switch
jzy3d May 19, 2022
60766d7
continue colorbar cleanup, mouse camera controller bypassed when 2D
jzy3d May 20, 2022
c5d7c52
disable testing on mac m1
jzy3d May 20, 2022
20df19d
Let colobar and overlay layout be similar among emulgl/native and hid…
jzy3d May 23, 2022
fee612d
more tests on colormaps and colorbars
jzy3d May 23, 2022
cc3bbff
Fixed OverlayImageRenderer not displaying images of right side of cha…
jzy3d May 23, 2022
7c00411
Finalize 2D layout verifications
jzy3d May 23, 2022
45c9c03
Add experimental shape renderer
jzy3d May 23, 2022
2399dcb
Try to fix rate limit test on windows
jzy3d May 24, 2022
091654a
remove a demo not working properly
jzy3d May 24, 2022
ca2cdd2
merge
jzy3d May 24, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ jobs:


macos-11-4-arm64:
#if: ${{ false }} # disable for now
if: ${{ false }} # disable for now

runs-on: ${{ matrix.os }}
strategy:
Expand Down
1 change: 1 addition & 0 deletions jzy3d-core-awt/doc/core-awt.drawio

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion jzy3d-core-awt/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
<artifactId>jzy3d-core</artifactId>
<version>${project.version}</version>
</dependency>

</dependencies>

</project>
23 changes: 12 additions & 11 deletions jzy3d-core-awt/src/main/java/org/jzy3d/chart/AWTChart.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import org.jzy3d.maths.Dimension;
import org.jzy3d.plot2d.primitive.AWTColorbarImageGenerator;
import org.jzy3d.plot3d.primitives.Drawable;
import org.jzy3d.plot3d.primitives.axis.layout.IAxisLayout;
import org.jzy3d.plot3d.primitives.axis.layout.AxisLayout;
import org.jzy3d.plot3d.rendering.canvas.Quality;
import org.jzy3d.plot3d.rendering.legends.colorbars.AWTColorbarLegend;
import org.jzy3d.plot3d.rendering.view.AWTRenderer2d;
Expand Down Expand Up @@ -32,19 +32,20 @@ public AWTView getAWTView() {
}

public AWTColorbarLegend colorbar(Drawable drawable) {
return colorbar(drawable, new Dimension(AWTColorbarImageGenerator.MIN_BAR_WIDTH,
AWTColorbarImageGenerator.MIN_BAR_HEIGHT), getView().getAxis().getLayout());
return colorbar(drawable, null, getView().getAxis().getLayout());
}

public AWTColorbarLegend colorbar(Drawable drawable, IAxisLayout layout) {
return colorbar(drawable, new Dimension(AWTColorbarImageGenerator.MIN_BAR_WIDTH,
AWTColorbarImageGenerator.MIN_BAR_HEIGHT), layout);
public AWTColorbarLegend colorbar(Drawable drawable, AxisLayout layout) {
return colorbar(drawable, null, layout);
}

public AWTColorbarLegend colorbar(Drawable drawable, Dimension d, IAxisLayout layout) {
AWTColorbarLegend cbar = new AWTColorbarLegend(drawable, layout);
cbar.setMinimumSize(d);
drawable.setLegend(cbar);
return cbar;
public AWTColorbarLegend colorbar(Drawable drawable, Dimension minDimension, AxisLayout layout) {
AWTColorbarLegend colorbar = new AWTColorbarLegend(drawable, layout);

if(minDimension!=null)
colorbar.setMinimumDimension(minDimension);

drawable.setLegend(colorbar);
return colorbar;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public AWTCameraMouseController() {}

public AWTCameraMouseController(Chart chart) {
register(chart);
addSlaveThreadController(chart.getFactory().newCameraThreadController(chart));
addThread(chart.getFactory().newCameraThreadController(chart));
}

public AWTCameraMouseController(Chart chart, RateLimiter limiter) {
Expand Down Expand Up @@ -57,7 +57,10 @@ public void dispose() {
*/
@Override
public void mousePressed(MouseEvent e) {
//
if(getChart().getView().is2D()) {
return;
}

if (handleSlaveThread(e))
return;

Expand All @@ -70,6 +73,10 @@ public void mousePressed(MouseEvent e) {
/** Compute shift or rotate */
@Override
public void mouseDragged(MouseEvent e) {
if(getChart().getView().is2D()) {
return;
}

// Check if mouse rate limiter wish to forbid this mouse drag instruction
if(rateLimiter!=null && !rateLimiter.rateLimitCheck()) {
return;
Expand All @@ -96,6 +103,10 @@ else if (AWTMouseUtilities.isRightDown(e)) {
/** Compute zoom */
@Override
public void mouseWheelMoved(MouseWheelEvent e) {
if(getChart().getView().is2D()) {
return;
}

// Check if mouse rate limiter wish to forbid this mouse drag instruction
if(rateLimiter!=null && !rateLimiter.rateLimitCheck()) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.jzy3d.plot3d.rendering.scene.Scene;
import org.jzy3d.plot3d.rendering.view.AWTRenderer2d;
import org.jzy3d.plot3d.rendering.view.AWTView;
import org.jzy3d.plot3d.rendering.view.AbstractAWTRenderer2d;
import org.jzy3d.plot3d.rendering.view.AbstractViewportManager;
import org.jzy3d.plot3d.rendering.view.Camera;
import org.jzy3d.plot3d.rendering.view.View;
Expand Down Expand Up @@ -60,7 +61,7 @@ public void unregister() {
}

protected AWTRenderer2d initRenderer2d(final ICanvas c) {
return new AWTRenderer2d() {
return new AbstractAWTRenderer2d() {
@Override
public void paint(Graphics g, int canvasWidth, int canvasHeight) {
drawSelection((Graphics2D) g, c.getRendererWidth(), c.getRendererHeight());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,37 @@ public abstract class AWTAbstractImageGenerator implements AWTImageGenerator {
protected Color foregroundColor = Color.BLACK;


public void configureText(Graphics2D graphic) {
protected void configureText(Graphics2D graphic) {
graphic.setFont(awtFont); // Text for the numbers in the ColorBar is Size=12
}

public void drawBackground(int width, int height, Graphics2D graphic) {
protected void drawBackground(int width, int height, Graphics2D graphic) {
if (hasBackground) {
graphic.setColor(AWTColor.toAWT(backgroundColor));
graphic.fillRect(0, 0, width, height);
}
}

protected void drawBorder(Graphics2D graphic, int width, int height) {
graphic.setColor(AWTColor.toAWT(foregroundColor));
graphic.drawRect(0, 0, width - 1, height - 1);
}

@Override
public void setFont(Font font) {
// reset font only if necessary
if (this.font == null || !this.font.equals(font)) {
this.font = font;
this.textSize = font.getHeight();

setAWTFont(AWTFont.toAWT(font));
}
}

@Override
public Font getFont() {
return font;
}

@Override
public boolean hasBackground() {
Expand Down Expand Up @@ -60,11 +80,6 @@ public void setForegroundColor(Color foregroundColor) {
this.foregroundColor = foregroundColor;
}

public void drawLegendBorder(Graphics2D graphic, int width, int height) {
graphic.setColor(AWTColor.toAWT(foregroundColor));
graphic.drawRect(0, 0, width - 1, height - 1);
}

@Override
public java.awt.Font getAWTFont() {
return awtFont;
Expand All @@ -74,20 +89,4 @@ public java.awt.Font getAWTFont() {
public void setAWTFont(java.awt.Font font) {
this.awtFont = font;
}

@Override
public void setFont(Font font) {
// reset font only if necessary
if (this.font == null || !this.font.equals(font)) {
this.font = font;
this.textSize = font.getHeight();

setAWTFont(AWTFont.toAWT(font));
}
}

@Override
public Font getFont() {
return font;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import org.jzy3d.maths.Coord2d;
import org.jzy3d.painters.IPainter;
import org.jzy3d.plot2d.rendering.AWTGraphicsUtils;
import org.jzy3d.plot3d.primitives.axis.layout.IAxisLayout;
import org.jzy3d.plot3d.primitives.axis.layout.AxisLayout;
import org.jzy3d.plot3d.primitives.axis.layout.providers.ITickProvider;
import org.jzy3d.plot3d.primitives.axis.layout.renderers.ITickRenderer;

Expand All @@ -32,6 +32,8 @@ public class AWTColorbarImageGenerator extends AWTAbstractImageGenerator
public static int BAR_WIDTH_DEFAULT = 20;
protected int barWidth;
protected int textToBarHorizontalMargin = 2;

protected boolean addTextHeightToVerticalMargin = false;

protected Coord2d pixelScale = new Coord2d(1, 1);

Expand All @@ -48,40 +50,34 @@ public AWTColorbarImageGenerator(ColorMapper mapper, ITickProvider provider,
this.min = mapper.getMin();
this.max = mapper.getMax();

setFont(IAxisLayout.FONT_DEFAULT);
setFont(AxisLayout.FONT_DEFAULT);
}


// public

@Override
public BufferedImage toImage(int width, int height) {
return toImage(width, height, BAR_WIDTH_DEFAULT);
}

/** Renders the {@link AWTColorbarImageGenerator} to an image. */
/** Renders the colorbar to an image. */
public BufferedImage toImage(int width, int height, int barWidth) {
if (barWidth > width)
return null;

this.barWidth = width;
this.barWidth = barWidth;


BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
Graphics2D graphic = image.createGraphics();

// graphic.scale(pixelScale.x, pixelScale.y);

AWTGraphicsUtils.configureRenderingHints(graphic);

graphic.setColor(AWTColor.toAWT(Color.WHITE));
graphic.fillRect(0, 0, width, height);

configureText(graphic);
drawBackground(width, height, graphic);
drawBarColors(height, barWidth, graphic);
drawBarContour(height, barWidth, graphic);
drawTextAnnotations(height, barWidth, graphic);
drawBarColors(height, this.barWidth/*getScaledBarWidth()*/, graphic);
drawBarContour(height, this.barWidth/*getScaledBarWidth()*/, graphic);
drawTextAnnotations(height, this.barWidth/*getScaledBarWidth()*/, graphic);
return image;
}

Expand All @@ -96,9 +92,20 @@ public BufferedImage toImage(int width, int height, int barWidth) {
* @param barWidth
* @param graphic
*/
public void drawBarContour(int height, int barWidth, Graphics2D graphic) {
protected void drawBarContour(int height, int barWidth, Graphics2D graphic) {

int finalY = 0;
int finalH = height;

// add little space to avoid cutting the text
// on top and bottom of colorbar
if(addTextHeightToVerticalMargin) {
finalY = textSize/2;
finalH = height - textSize;
}

graphic.setColor(AWTColor.toAWT(foregroundColor));
graphic.drawRect(0, textSize / 2, barWidth, height - textSize);
graphic.drawRect(0, finalY, barWidth, finalH);
}

/**
Expand All @@ -108,8 +115,19 @@ public void drawBarContour(int height, int barWidth, Graphics2D graphic) {
* @param barWidth
* @param graphic
*/
public void drawBarColors(int height, int barWidth, Graphics2D graphic) {
for (int h = textSize / 2; h <= (height - textSize / 2); h++) {
protected void drawBarColors(int height, int barWidth, Graphics2D graphic) {

int finalFrom = 0;
int finalTo = height;

// add little space to avoid cutting the text
// on top and bottom of colorbar
if(addTextHeightToVerticalMargin) {
finalFrom = textSize/2;
finalTo = height - (textSize/2);
}

for (int h = finalFrom; h <= finalTo; h++) {
// Compute value & color
double v = min + (max - min) * (h) / (height - textSize);
Color c = mapper.getColor(v); // To allow the Color to be a variable independent of the
Expand All @@ -121,16 +139,27 @@ public void drawBarColors(int height, int barWidth, Graphics2D graphic) {
}
}

public void drawTextAnnotations(int height, int barWidth, Graphics2D graphic) {
protected void drawTextAnnotations(int height, int barWidth, Graphics2D graphic) {
if (provider != null) {
double[] ticks = provider.generateTicks(min, max);
int ypos;
String txt;

//System.out.println("AWTColorbarImageGen : min=" + min + " max=" + max);

int xpos = barWidth + textToBarHorizontalMargin;

for (int t = 0; t < ticks.length; t++) {
ypos = (int) (textSize
+ (height - textSize - (height - textSize) * ((ticks[t] - min) / (max - min))));
txt = renderer.format(ticks[t]);
graphic.drawString(txt, barWidth + textToBarHorizontalMargin, ypos);
// ???? HELP
double ratioOfRange = (ticks[t] - min) / (max - min);
double heightNoText = height;

//if(addTextHeightToVerticalMargin)
heightNoText -= textSize;

int ypos = (int) (height - (heightNoText * ratioOfRange));


String txt = renderer.format(ticks[t]);
graphic.drawString(txt, xpos, ypos);
}
}
}
Expand All @@ -144,6 +173,15 @@ public void setPixelScale(Coord2d pixelScale) {
}

/* */

protected int getScaledBarWidth() {
if(pixelScale!=null) {
return (int)(barWidth * pixelScale.x);
}
else {
return barWidth;
}
}

/**
* Compute the optimal image width to contain the text as defined by the tick provided and
Expand All @@ -154,7 +192,7 @@ public int getPreferedWidth(IPainter painter) {
return getPreferedWidth(maxWidth);
}

public int getPreferedWidth(int maxTextWidth) {
protected int getPreferedWidth(int maxTextWidth) {
return maxTextWidth + textToBarHorizontalMargin + BAR_WIDTH_DEFAULT;
}

Expand All @@ -166,7 +204,7 @@ public void setTextToBarHorizontalMargin(int textToBarHorizontalMargin) {
this.textToBarHorizontalMargin = textToBarHorizontalMargin;
}

public int getMaxTickLabelWidth(IPainter painter) {
protected int getMaxTickLabelWidth(IPainter painter) {
int maxWidth = 0;
if (provider != null) {
double[] ticks = provider.generateTicks(min, max);
Expand Down
Loading