From a0d8a02625ef8aa76772ff839d1143867f7c1d55 Mon Sep 17 00:00:00 2001
From: Tim Molter <tim.molter@gmail.com>
Date: Mon, 11 Jul 2011 18:00:46 +0200
Subject: [PATCH] added scientific notation

---
 src/com/xeiam/swing/SwingHelper.java           |  1 +
 src/com/xeiam/xcharts/AxisTick.java            | 17 +++++++++++------
 src/com/xeiam/xcharts/AxisTickLabels.java      |  1 -
 src/com/xeiam/xcharts/example/SwingChart3.java | 10 ++--------
 src/com/xeiam/xcharts/example/SwingChart4.java | 10 ++--------
 5 files changed, 16 insertions(+), 23 deletions(-)

diff --git a/src/com/xeiam/swing/SwingHelper.java b/src/com/xeiam/swing/SwingHelper.java
index 09076b76..c87def48 100644
--- a/src/com/xeiam/swing/SwingHelper.java
+++ b/src/com/xeiam/swing/SwingHelper.java
@@ -21,6 +21,7 @@ public class SwingHelper {
     }
 
     public void displayChart() {
+
         // Schedule a job for the event-dispatching thread:
         // creating and showing this application's GUI.
         javax.swing.SwingUtilities.invokeLater(new Runnable() {
diff --git a/src/com/xeiam/xcharts/AxisTick.java b/src/com/xeiam/xcharts/AxisTick.java
index 6a09f193..6259e360 100644
--- a/src/com/xeiam/xcharts/AxisTick.java
+++ b/src/com/xeiam/xcharts/AxisTick.java
@@ -38,15 +38,16 @@ public class AxisTick implements IChartPart {
 
     private int workingSpace;
 
-    // private double[] data;
-
-    // /** the default tick mark step hint */
+    /** the default tick mark step hint */
     private static final int DEFAULT_TICK_MARK_STEP_HINT = 64;
 
     protected final static int AXIS_TICK_PADDING = 4;
 
-    /** the format for tick labels */
-    private Format format = new DecimalFormat("#.###########");
+    /** the normal format for tick labels */
+    private Format normalFormat = new DecimalFormat("#.###########");
+
+    /** the scientific format for tick labels */
+    private Format scientificFormat = new DecimalFormat("0.###E0");
 
     /** the bounds */
     private Rectangle bounds = new Rectangle(); // default all-zero rectangle
@@ -226,7 +227,11 @@ public class AxisTick implements IChartPart {
 
     private String format(double value) {
 
-        return this.format.format(value);
+        if (Math.abs(value) < 9999 && Math.abs(value) > .0001) {
+            return this.normalFormat.format(value);
+        } else {
+            return this.scientificFormat.format(value);
+        }
     }
 
 }
diff --git a/src/com/xeiam/xcharts/AxisTickLabels.java b/src/com/xeiam/xcharts/AxisTickLabels.java
index 9889408c..649e30fe 100644
--- a/src/com/xeiam/xcharts/AxisTickLabels.java
+++ b/src/com/xeiam/xcharts/AxisTickLabels.java
@@ -42,7 +42,6 @@ public class AxisTickLabels implements IChartPart {
     protected AxisTickLabels(Axis axis, AxisTick axisTick) {
 
         this.axis = axis;
-
         this.axisTick = axisTick;
     }
 
diff --git a/src/com/xeiam/xcharts/example/SwingChart3.java b/src/com/xeiam/xcharts/example/SwingChart3.java
index c78652b7..5abaf0b9 100644
--- a/src/com/xeiam/xcharts/example/SwingChart3.java
+++ b/src/com/xeiam/xcharts/example/SwingChart3.java
@@ -55,13 +55,7 @@ public class SwingChart3 {
 
     public static void main(String[] args) {
 
-        // Schedule a job for the event-dispatching thread:
-        // creating and showing this application's GUI.
-        javax.swing.SwingUtilities.invokeLater(new Runnable() {
-            @Override
-            public void run() {
-                createAndShowGUI();
-            }
-        });
+        createAndShowGUI();
+
     }
 }
diff --git a/src/com/xeiam/xcharts/example/SwingChart4.java b/src/com/xeiam/xcharts/example/SwingChart4.java
index a294877c..6a0e9664 100644
--- a/src/com/xeiam/xcharts/example/SwingChart4.java
+++ b/src/com/xeiam/xcharts/example/SwingChart4.java
@@ -54,13 +54,7 @@ public class SwingChart4 {
 
     public static void main(String[] args) {
 
-        // Schedule a job for the event-dispatching thread:
-        // creating and showing this application's GUI.
-        javax.swing.SwingUtilities.invokeLater(new Runnable() {
-            @Override
-            public void run() {
-                createAndShowGUI();
-            }
-        });
+        createAndShowGUI();
+
     }
 }
-- 
GitLab