Skip to content

Fixes #886 #888

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

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Empty file added ReadMe.txt
Empty file.
74 changes: 41 additions & 33 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@
</license>
</licenses>

<repositories>
<repository>
<id>central</id>
<url>https://repo.maven.apache.org/maven2</url>
</repository>
</repositories>

<issueManagement>
<system>GitHub</system>
<url>https://github.com/knowm/XChart/issues</url>
Expand Down Expand Up @@ -122,31 +129,32 @@
<value>true</value>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>3.2.4</version>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
<configuration>
<!-- This is necessary for gpg to not try to use the pinentry programs -->
<gpgArguments>
<arg>--pinentry-mode</arg>
<arg>loopback</arg>
</gpgArguments>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<!-- <build>-->
<!-- <plugins>-->
<!-- <plugin>-->
<!-- <groupId>org.apache.maven.plugins</groupId>-->
<!-- <artifactId>maven-gpg-plugin</artifactId>-->
<!--&lt;!&ndash; <version>1.6</version>&ndash;&gt;-->
<!-- <version>3.2.4</version>-->
<!-- <executions>-->
<!-- <execution>-->
<!-- <id>sign-artifacts</id>-->
<!-- <phase>verify</phase>-->
<!-- <goals>-->
<!-- <goal>sign</goal>-->
<!-- </goals>-->
<!-- <configuration>-->
<!-- &lt;!&ndash; This is necessary for gpg to not try to use the pinentry programs &ndash;&gt;-->
<!-- <gpgArguments>-->
<!-- <arg>&#45;&#45;pinentry-mode</arg>-->
<!-- <arg>loopback</arg>-->
<!-- </gpgArguments>-->
<!-- </configuration>-->
<!-- </execution>-->
<!-- </executions>-->
<!-- </plugin>-->
<!-- </plugins>-->
<!-- </build>-->
</profile>

</profiles>
Expand Down Expand Up @@ -212,14 +220,14 @@
<doclint>none</doclint>
<source>1.8</source>
</configuration>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
<!-- <executions>-->
<!-- <execution>-->
<!-- <id>attach-javadocs</id>-->
<!-- <goals>-->
<!-- <goal>jar</goal>-->
<!-- </goals>-->
<!-- </execution>-->
<!-- </executions>-->
</plugin>
<!-- for deploying to Maven Central -->
<plugin>
Expand Down
5 changes: 5 additions & 0 deletions xchart-demo/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@
<artifactId>javafx-controls</artifactId>
<version>11.0.2</version>
</dependency>
<dependency>
<groupId>backport-util-concurrent</groupId>
<artifactId>backport-util-concurrent</artifactId>
<version>3.1</version>
</dependency>
</dependencies>
<build>
<plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ public abstract class AxisTickCalculator_ implements AxisTickCalculator {

Format axisFormat;

private static final int MAX_LABEL_LENGTH = 20;

/**
* Constructor
*
Expand Down Expand Up @@ -118,35 +120,51 @@ public List<String> getTickLabels() {
*/
boolean willLabelsFitInTickSpaceHint(List<String> tickLabels, int tickSpacingHint) {

if (tickSpacingHint <= 0 || tickLabels.isEmpty()) {
return false;
}

int MAX_CHECK = 3;
for (int i = 0; i < Math.min(MAX_CHECK, tickLabels.size()); i++) {
String tickLabel = tickLabels.get(i);
if (tickLabel != null && tickLabel.length() > MAX_LABEL_LENGTH) {
return false;
}
}

String sampleLabel = "Y";
if (Direction.X.equals(this.axisDirection)) {
// find the longest String in all the labels

if (tickSpacingHint <= 0) {
return false;
}

for (String tickLabel : tickLabels) {
if (tickLabel != null && tickLabel.length() > sampleLabel.length()) {
sampleLabel = tickLabel;
if (tickLabel != null) {
if (tickLabel.length() > MAX_LABEL_LENGTH) {
return false;
}
if (tickLabel.length() > sampleLabel.length()) {
sampleLabel = tickLabel;
}
}
}
}
// System.out.println("longestLabel: " + sampleLabel);

TextLayout textLayout =
new TextLayout(
sampleLabel, styler.getAxisTickLabelsFont(), new FontRenderContext(null, true, false));
AffineTransform rot =
styler.getXAxisLabelRotation() == 0
? null
: AffineTransform.getRotateInstance(
-1 * Math.toRadians(styler.getXAxisLabelRotation()));

Font font = styler.getAxisTickLabelsFont();
FontRenderContext frc = new FontRenderContext(null, true, false);
TextLayout textLayout = new TextLayout(sampleLabel, font, frc);

AffineTransform rot = null;
if (styler.getXAxisLabelRotation() != 0) {
rot = AffineTransform.getRotateInstance(
-1 * Math.toRadians(styler.getXAxisLabelRotation()));
}

Shape shape = textLayout.getOutline(rot);
Rectangle2D rectangle = shape.getBounds();
double largestLabelWidth =
Direction.X.equals(this.axisDirection) ? rectangle.getWidth() : rectangle.getHeight();
// System.out.println("largestLabelWidth: " + largestLabelWidth);
// System.out.println("tickSpacingHint: " + tickSpacingHint);

// if (largestLabelWidth * 1.1 >= tickSpacingHint) {
// System.out.println("WILL NOT FIT!!!");
// }
double largestLabelWidth = Direction.X.equals(this.axisDirection)
? rectangle.getWidth() : rectangle.getHeight();

return (largestLabelWidth * 1.1 < tickSpacingHint);
}
Expand Down Expand Up @@ -380,6 +398,10 @@ private void calculateForEquallySpacedAxisValues(double tickSpace, double margin
List<Double> tickLabelValues;
double tickLabelMaxValue;
double tickLabelMinValue;
double range = maxValue - minValue;
if (range < 1e-10) {
return;
}
do {
tickValuesHint++;
tickLabels.clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,18 @@ public StringBuffer format(Object obj, StringBuffer toAppendTo, FieldPosition po

DecimalFormat normalFormat = (DecimalFormat) numberFormat;
normalFormat.applyPattern(decimalPattern);

if (styler.getDecimalPattern() == null
&& (axisDirection == Axis.Direction.X && styler.getXAxisDecimalPattern() == null)
&& (axisDirection != Axis.Direction.Y || styler.getYAxisGroupDecimalPatternMap().get(yIndex) == null)) {

double value = number.doubleValue();
int maxFractionDigits = 4;
if (Math.abs(value) < 0.0001 && Math.abs(value) > 1e-16) {
maxFractionDigits = 6;
}
normalFormat.setMaximumFractionDigits(maxFractionDigits);
}
toAppendTo.append(normalFormat.format(number));

return toAppendTo;
Expand Down