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

Layout with HiDPI #281

Merged
merged 56 commits into from
Jun 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
5cc305b
Init HiDPI layout tests
jzy3d May 31, 2022
a8cae24
Add test on ViewAndColorbarsLayout
jzy3d May 31, 2022
5b21418
Using the same test for Native and EmulGL view layout
jzy3d May 31, 2022
c677f16
Add tests
jzy3d May 31, 2022
bd4baa7
.
jzy3d Jun 1, 2022
4eba82f
Adding new margin class, added tests, let colorbar width be scaled wi…
jzy3d Jun 2, 2022
38961dd
Scaling 2D margin with pixel scale for native
jzy3d Jun 2, 2022
df1dbe2
AWT 2D chart perfectly support pixelscale change
jzy3d Jun 2, 2022
d5629c0
pre del chart view
jzy3d Jun 7, 2022
19d4a02
Considering colorbar margins, started to deal with asymetric margin
jzy3d Jun 7, 2022
46cc7f9
.
jzy3d Jun 8, 2022
6ebaa03
Margins with integers instead
jzy3d Jun 9, 2022
8725195
properly show right margin in debug mode for emulgl
jzy3d Jun 9, 2022
1f5a402
Fix EmulGL view size bug
jzy3d Jun 9, 2022
78dc0d9
Fixed colorbar margins in the native case
jzy3d Jun 9, 2022
aef5f3a
.
jzy3d Jun 9, 2022
60951e7
.
jzy3d Jun 9, 2022
f99e90f
.
jzy3d Jun 9, 2022
5d89ed9
AWTImageViewport able to apply margin properly in HiDPI and non HiDPI…
jzy3d Jun 10, 2022
7007c61
fix test
jzy3d Jun 10, 2022
847aa46
Remove view.shoot conditions to keep renderer.init method invocable
jzy3d Jun 11, 2022
c145ad5
Remove view.shoot conditions to keep renderer.init method invocable
jzy3d Jun 11, 2022
42a4f96
Added font size selector
jzy3d Jun 12, 2022
75fbdb5
.
jzy3d Jun 12, 2022
87de896
.
jzy3d Jun 13, 2022
cf1f8d0
A bit more test
jzy3d Jun 13, 2022
c755902
EmulGL colorbar margin almost working in HiDPI
jzy3d Jun 13, 2022
f45f431
.
jzy3d Jun 13, 2022
5126ac0
remove shrink colorbar
jzy3d Jun 13, 2022
3e67484
Add layout settings clone methods
jzy3d Jun 13, 2022
fbbba30
debug in progress
jzy3d Jun 14, 2022
a996d95
Fix X tick and axis labels overlapping with EmulGL
jzy3d Jun 15, 2022
d1c8737
Fix few tests
jzy3d Jun 15, 2022
d62ae7a
Improve tests
jzy3d Jun 15, 2022
e3fcfbe
Fixed emulGL margin processing with/without HiDPI
jzy3d Jun 15, 2022
0e9a6c1
Configure mutation testing
jzy3d Jun 16, 2022
1d8a462
Fix EmulGL Y axis label position
jzy3d Jun 16, 2022
68aed9c
Fixed EmulGL colorbar layout
jzy3d Jun 16, 2022
069cce7
Fix EMulGL test
jzy3d Jun 16, 2022
4d06d2a
bundle
jzy3d Jun 16, 2022
4d1fed6
bundle
jzy3d Jun 16, 2022
2b07093
clean
jzy3d Jun 17, 2022
dcc268f
Fix vertical colorbar position for EMulGL charts
jzy3d Jun 17, 2022
a633094
Better canvas pixel scale getters. Add checks to view pixel scale lis…
jzy3d Jun 17, 2022
96ade95
Update baseline images
jzy3d Jun 17, 2022
75ea6a4
Merge branch 'feature/layoutWithHiDPI' of github.com:jzy3d/jzy3d-api …
jzy3d Jun 17, 2022
7ea7e2e
Allow reconfiguring legend's pixel scale upon view pixel scale update
jzy3d Jun 17, 2022
7cb85ae
Add pauses to let test pass on Linux. Weird edit
jzy3d Jun 17, 2022
feee2c7
.
jzy3d Jun 17, 2022
f3c7f72
Wait a bit more
jzy3d Jun 20, 2022
2c02543
Let windows test work
jzy3d Jun 20, 2022
86d7d74
Merge branch 'feature/layoutWithHiDPI' of
jzy3d Jun 20, 2022
195b758
Hack layout for the AWT+Windows+HiDPI case
jzy3d Jun 20, 2022
07c4349
add bin to gitignore
jzy3d Jun 20, 2022
7bae9df
Merge branch 'feature/layoutWithHiDPI' of github.com:jzy3d/jzy3d-api …
jzy3d Jun 20, 2022
9e27582
Comment part of the Windows fix
jzy3d Jun 20, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ target/
.settings
.idea/
**/.idea/

**/bin/

# OS specific folder data files
.DS_Store
Expand Down
11 changes: 10 additions & 1 deletion jzy3d-core-awt/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@
<artifactId>jzy3d-core</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>jzy3d-core</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>

</dependencies>

</project>
</project>
35 changes: 19 additions & 16 deletions jzy3d-core-awt/src/main/java/org/jzy3d/chart/AWTChart.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
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.legends.colorbars.IColorbarLegend;
import org.jzy3d.plot3d.rendering.view.AWTRenderer2d;
import org.jzy3d.plot3d.rendering.view.AWTView;
import org.jzy3d.plot3d.rendering.view.View;

public class AWTChart extends Chart {
public AWTChart(IChartFactory components, Quality quality) {
Expand All @@ -20,32 +22,33 @@ protected AWTChart() {
}

public void addRenderer(AWTRenderer2d renderer2d) {
getAWTView().addRenderer2d(renderer2d);
getView().addRenderer2d(renderer2d);
}

public void removeRenderer(AWTRenderer2d renderer2d) {
getAWTView().removeRenderer2d(renderer2d);
}

public AWTView getAWTView() {
return (AWTView) view;
getView().removeRenderer2d(renderer2d);
}

public AWTColorbarLegend colorbar(Drawable drawable) {
return colorbar(drawable, null, getView().getAxis().getLayout());
return colorbar(drawable, getView().getAxis().getLayout());
}

public AWTColorbarLegend colorbar(Drawable drawable, AxisLayout layout) {
return colorbar(drawable, null, layout);
}

public AWTColorbarLegend colorbar(Drawable drawable, Dimension minDimension, AxisLayout layout) {
AWTColorbarLegend colorbar = new AWTColorbarLegend(drawable, layout);

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

AWTColorbarLegend colorbar = new AWTColorbarLegend(drawable, layout, layout.getMainColor(), view.getBackgroundColor());
drawable.setLegend(colorbar);
return colorbar;
}

@Override
public AWTColorbarLegend getColorbar() {
AWTColorbarLegend bar = (AWTColorbarLegend)super.getColorbar();
return bar;
}


@Override
public AWTView getView() {
return (AWTView)super.getView();
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,17 @@ public class AWTColorbarImageGenerator extends AWTAbstractImageGenerator
public static final int MIN_BAR_HEIGHT = 100;

protected ColorMapper mapper;
protected ITickProvider provider;
protected ITickRenderer renderer;
protected ITickProvider tickProvider;
protected ITickRenderer tickRenderer;
protected double min;
protected double max;

public static int BAR_WIDTH_DEFAULT = 20;
public static int TEXT_TO_BAR_DEFAULT = 2;

protected int barWidth;
protected int textToBarHorizontalMargin = 2;
protected int textToBarHorizontalMargin = TEXT_TO_BAR_DEFAULT;
protected int maxTextWidth;

protected boolean addTextHeightToVerticalMargin = false;

Expand All @@ -45,8 +48,8 @@ public AWTColorbarImageGenerator(IColorMap map, float min, float max, ITickProvi
public AWTColorbarImageGenerator(ColorMapper mapper, ITickProvider provider,
ITickRenderer renderer) {
this.mapper = mapper;
this.provider = provider;
this.renderer = renderer;
this.tickProvider = provider;
this.tickRenderer = renderer;
this.min = mapper.getMin();
this.max = mapper.getMax();

Expand All @@ -62,8 +65,8 @@ public BufferedImage toImage(int width, int height) {

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

this.barWidth = barWidth;

Expand All @@ -75,9 +78,9 @@ public BufferedImage toImage(int width, int height, int barWidth) {

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

Expand All @@ -95,7 +98,7 @@ public BufferedImage toImage(int width, int height, int barWidth) {
protected void drawBarContour(int height, int barWidth, Graphics2D graphic) {

int finalY = 0;
int finalH = height;
int finalH = height-1; // let bottom contour appear in the image

// add little space to avoid cutting the text
// on top and bottom of colorbar
Expand All @@ -118,7 +121,7 @@ protected void drawBarContour(int height, int barWidth, Graphics2D graphic) {
protected void drawBarColors(int height, int barWidth, Graphics2D graphic) {

int finalFrom = 0;
int finalTo = height;
int finalTo = height-1;

// add little space to avoid cutting the text
// on top and bottom of colorbar
Expand All @@ -140,8 +143,8 @@ protected void drawBarColors(int height, int barWidth, Graphics2D graphic) {
}

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

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

Expand All @@ -158,7 +161,7 @@ protected void drawTextAnnotations(int height, int barWidth, Graphics2D graphic)
int ypos = (int) (height - (heightNoText * ratioOfRange));


String txt = renderer.format(ticks[t]);
String txt = tickRenderer.format(ticks[t]);
graphic.drawString(txt, xpos, ypos);
}
}
Expand All @@ -174,7 +177,7 @@ public void setPixelScale(Coord2d pixelScale) {

/* */

protected int getScaledBarWidth() {
public int getScaledBarWidth() {
if(pixelScale!=null) {
return (int)(barWidth * pixelScale.x);
}
Expand All @@ -183,18 +186,10 @@ protected int getScaledBarWidth() {
}
}

/**
* Compute the optimal image width to contain the text as defined by the tick provided and
* renderer.
*/
public int getPreferedWidth(IPainter painter) {
int maxWidth = getMaxTickLabelWidth(painter);
return getPreferedWidth(maxWidth);
public int getBarWidth() {
return barWidth;
}

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

public int getTextToBarHorizontalMargin() {
return textToBarHorizontalMargin;
Expand All @@ -204,21 +199,72 @@ public void setTextToBarHorizontalMargin(int textToBarHorizontalMargin) {
this.textToBarHorizontalMargin = textToBarHorizontalMargin;
}

protected int getMaxTickLabelWidth(IPainter painter) {
/**
* Compute the optimal image width to contain the text as defined by the tick provided and
* renderer.
*/
public int getPreferredWidth(IPainter painter) {
maxTextWidth = getMaxTickLabelWidth(painter);

//System.out.println("AWTColorbarImageGen : max txt width " + maxTextWidth);

// we unscale it : we here use a graphics2D context that consider
// text scale by itself. As font is globally magnified, mainly for JOGL
// text renderer, we will unscale it for processing the width

int maxTextActual = maxTextWidth;

if(pixelScale.x>0)
maxTextActual = Math.round(maxTextWidth / pixelScale.x);

//System.out.println("AWTColorbarImageGen : max txt act " + maxTextActual + " " + pixelScale);

return getPreferredWidth(maxTextActual);
}

protected int getPreferredWidth(int maxTextWidth) {
return maxTextWidth + getTextToBarHorizontalMargin() + getBarWidth();
}

/**
* Only valid after a call to {@link #getPreferredWidth(IPainter)}
* @return
*/
public int getMaxTextWidth() {
return maxTextWidth;
}

public int getMaxTickLabelWidth(IPainter painter) {
int maxWidth = 0;
if (provider != null) {
double[] ticks = provider.generateTicks(min, max);
if (tickProvider != null) {
double[] ticks = tickProvider.generateTicks(min, max);
String tickLabel;
for (int t = 0; t < ticks.length; t++) {
tickLabel = renderer.format(ticks[t]);
tickLabel = tickRenderer.format(ticks[t]);

int stringWidth = painter.getTextLengthInPixels(font, tickLabel);

//System.out.println("Gen : " + stringWidth + " for " + tickLabel);
if (maxWidth < stringWidth) {
maxWidth = stringWidth;
}
}
}
return maxWidth;
}

public ITickProvider getTickProvider() {
return tickProvider;
}

public void setTickProvider(ITickProvider tickProvider) {
this.tickProvider = tickProvider;
}

public ITickRenderer getTickRenderer() {
return tickRenderer;
}

public void setTickRenderer(ITickRenderer tickRenderer) {
this.tickRenderer = tickRenderer;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ public static void drawString(Graphics2D g2d, Font font, boolean useOSFontRender
}
}

public static int stringWidth(String string) {
BufferedImage i = new BufferedImage(0,0, BufferedImage.TYPE_4BYTE_ABGR);

return stringWidth(i.createGraphics(), string);
}
public static int stringWidth(Graphics2D g2d, String string) {
FontMetrics fm = g2d.getFontMetrics();
if (fm != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ public void setViewPort(int width, int height, float left, float right) {

if (imageWidth != imgWidth || imageHeight != height) {

//System.out.println("AWTLegend width:" + imgWidth + " height:" + height + " mode:" + getViewportMode());
//System.out.println("AWTLegend left:" + left + " right:" + right);
//System.out.println("AWTLegend imgWidth:" + imgWidth + " width:" + width + " height:" + height + " mode:" + getViewportMode());
setImage(toImage(imgWidth, height));
}
}
Expand All @@ -107,10 +108,16 @@ public Dimension getMinimumDimension() {
return minimumDimension;
}

/**
* Now overriden by automatic processing of minimum dimension
* @param dimension
*/
@Deprecated
public void setMinimumDimension(Dimension dimension) {
minimumDimension = dimension;
}

@Deprecated
public void setMinimumWidth(int minimumWidth) {
this.minimumDimension.width = minimumWidth;
}
Expand Down
Loading