diff --git a/README.md b/README.md
index 3ff6341..09cc358 100644
--- a/README.md
+++ b/README.md
@@ -36,13 +36,12 @@ public class App {
jplotlib.title("Line Plot");
jplotlib.xLabel("xLabel");
jplotlib.yLabel("yLabel");
- jplotlib.plot(y).build();
+ jplotlib.plot(y);
jplotlib.show();
-
}
}
```
-
+
Another Example to draw **MultiLine Plot**
@@ -59,14 +58,14 @@ public class App {
jplotlib.title("Line Plot");
jplotlib.xLabel("xLabel");
jplotlib.yLabel("yLabel");
- jplotlib.plot(y1).build();
+ jplotlib.plot(y1);
+ jplotlib.plot(y2);
jplotlib.show();
-
}
}
```
-
+
Learn More about Jplotlib in [GETTING_STARTED.md](docs/GETTING_STARTED.md)
diff --git a/docs/BAR.md b/docs/BAR.md
index 1109fc6..8a80e83 100644
--- a/docs/BAR.md
+++ b/docs/BAR.md
@@ -19,15 +19,14 @@ public class App {
Jplotlib jplotlib = new Jplotlib();
String[] x = {"A", "B", "C", "D"};
double[] y = {3, 8, 1, 10};
- jplotlib.bar(x, y)
- .build();
+ jplotlib.bar(x, y);
jplotlib.show();
}
}
```
In this example, we use the `bar()` method to create a bar graph using `x` as the labels for the x-coordinates and `y` as the y-coordinates. Each bar in the graph represents a category defined by the labels, and its height corresponds to the respective value from `y`.
-
+
Bar graphs are particularly useful for comparing the values of different categories and displaying discrete data. They are commonly used to visualize categorical data and show how different groups or items compare with each other.
@@ -40,7 +39,7 @@ In Jplotlib, similar to `.plot()`[.color()](PLOT.md) you can customize the color
```java
import io.github.manishdait.jplotlib.Jplotlib;
-import io.github.manishdait.jplotlib.style.color.BaseColor;
+import io.github.manishdait.jplotlib.defaults.color.LibColor;
public class App {
public static void main(String[] args) {
@@ -48,16 +47,45 @@ public class App {
String[] x = {"A", "B", "C", "D"};
double[] y = {3, 8, 1, 10};
jplotlib.bar(x, y)
- .color(BaseColor.PINK.getColor())
- .build();
+ .color(LibColor.PINK.getColor());
jplotlib.show();
}
}
```
-In this example, we use the `.color(BaseColor.PINK.getColor())` method with the `bar()` method to set the color of the bars in the bar graph to pink. You can use the `BaseColor` enum to choose from a variety of predefined colors like `BaseColor.RED`, `BaseColor.GREEN`, `BaseColor`.ORANGE, and more.
+In this example, we use the `.color(LibColor.PINK.getColor())` method with the `bar()` method to set the color of the bars in the bar graph to pink. You can use the `LibColor` enum to choose from a variety of predefined colors like `LibColor.RED`, `LibColor.GREEN`, `LibColorColor.ORANGE`, and more.
-
+
You can also use the java.awt.Color class to specify custom colors using RGB values, like `.color(new Color(255, 0, 0))` for red.
+# Jplotlib.barh()
+
+The `barh()` method in `Jplotlib` allows you to create Horizonta; 2D bar graphs. It has all similar features like above `bar()` method.
+
+### Method Signature:
+
+```java
+barh(String[] xLabels, double[] yPoints)
+```
+The `barh()` method requires two arrays: `xLabels` containing labels for the x-coordinates (in String format) and `yPoints` containing the corresponding y-coordinates.
+
+### Example Usage:
+
+```java
+import io.github.manishdait.jplotlib.Jplotlib;
+
+public class App {
+ public static void main(String[] args) {
+ Jplotlib jplotlib = new Jplotlib();
+ String[] x = {"A", "B", "C", "D"};
+ double[] y = {3, 8, 1, 10};
+ jplotlib.barh(x, y);
+ jplotlib.show();
+ }
+}
+```
+
+In this example, we use the `barh()` method to create a bar graph using `x` as the labels for the x-coordinates and `y` as the y-coordinates. Each bar in the graph represents a category defined by the labels, and its width corresponds to the respective value from `x`.
+
+
\ No newline at end of file
diff --git a/docs/BASE_COLOR.md b/docs/BASE_COLOR.md
deleted file mode 100644
index d2efc19..0000000
--- a/docs/BASE_COLOR.md
+++ /dev/null
@@ -1,46 +0,0 @@
-# BaseColor Enum
-
-The `BaseColor` enum in Jplotlib provides a set of predefined colors that you can use to customize the appearance of your plots.
-
-### Available BaseColor:
-
-- `BaseColor.BLUE`
-- `BaseColor.ORANGE`
-- `BaseColor.GREEN`
-- `BaseColor.RED`
-- `BaseColor.PURPLE`
-- `BaseColor.BROWN`
-- `BaseColor.PINK`
-- `BaseColor.GREY`
-- `BaseColor.LIME`
-- `BaseColor.SKY`
-
-### Example Usage:
-
-```java
- import io.github.manishdait.jplotlib.Jplotlib;
- import io.github.manishdait.jplotlib.style.color.BaseColor;
- import io.github.manishdait.jplotlib.style.marker.BaseMarker;
-
- public class App {
- public static void main(String[] args) {
- double[] x = {1, 2, 3, 4};
- double[] y = {2, 5, 3, 6};
-
- Jplotlib jplotlib = new Jplotlib();
- jplotlib.plot(x, y)
- .marker(BaseMarker.CIRCLE)
- .color(BaseColor.BLUE.getColor())
- .markerColor(BaseColor.RED.getColor())
- .build();
- jplotlib.show();
- }
- }
-```
-In this example, we use the `.color(BaseColor.BLUE.getColor())` method to set the line color to blue and `.markerColor(BaseColor.RED.getColor())` to set marker color red using `BaseColor` from Jplotlib. The `BaseColor.BLUE` constant provides the predefined blue color and `BaseColor.RED` constant provides predefine red color.
-
-
-
-You can use any of the available BaseColor constants to customize the color of lines, markers, or other visual elements in your plot according to your preferences.
-
-
diff --git a/docs/BASE_STROKE.md b/docs/BASE_STROKE.md
deleted file mode 100644
index d0dc38f..0000000
--- a/docs/BASE_STROKE.md
+++ /dev/null
@@ -1,37 +0,0 @@
-# BaseStroke Enum
-
-The `BaseStroke` enum in Jplotlib provides options to customize the style of lines in plots.
-
-### Available Styles:
-
-Currently, the `BaseStoke` enum in Jplotlib provides two values for line style:
-
-- `BaseStroke.NONE`: This value sets the line style to a solid line with no special decoration (default style).
-
-- `BaseStroke.DASHED`: This value sets the line style to a dashed line.
-
-### Example Usage:
-
-```java
-import io.github.manishdait.jplotlib.Jplotlib;
-import io.github.manishdait.jplotlib.style.line.BaseStroke;
-
-public class App {
- public static void main(String[] args) {
- double[] x = {1, 2, 3, 4};
- double[] y = {2.5, 5.1, 3.9, 6.2};
-
- Jplotlib jplotlib = new Jplotlib();
- jplotlib.plot(x, y)
- .lineStyle(BaseStroke.DASHED)
- .build();
- jplotlib.show();
- }
-}
-```
-
-In this example, we use the `.lineStyle(BaseStroke.DASHED)` method to set the line style to dashed, overriding the default style which is `BaseStroke.NONE`.
-
-
-
-You can use the `BaseStroke` enum to change the appearance of lines in your plots according to your preferences. If no specific style is set, it will use the default `BaseStroke.NONE`, which is a solid line.
\ No newline at end of file
diff --git a/docs/GETTING_STARTED.md b/docs/GETTING_STARTED.md
index 9c4ff59..2d4c9b3 100644
--- a/docs/GETTING_STARTED.md
+++ b/docs/GETTING_STARTED.md
@@ -33,7 +33,7 @@ double[] y = {2.5, 5.1, 3.9, 6.2};
```
4. Plot the data using the plot() method:
```java
-jplotlib.plot(x, y).build();
+jplotlib.plot(x, y);
```
5. Add optional elements like grid, labels, and title:
```java
@@ -56,7 +56,7 @@ For more details and additional customization options, you can refer to the [PLO
To create a 2D scatter plot using Jplotlib, follow the same steps as above, but instead of using the `plot()` method, use the `scatter()` method:
```java
-jplotlib.scatter(x, y).build();
+jplotlib.scatter(x, y);
```
You can find more information about scatter plots in the [SCATTER.md](SCATTER.md) document.
@@ -69,7 +69,7 @@ To create a 2D bar graph using Jplotlib, follow the same initial steps and then
String[] xLabels = {"A", "B", "C", "D"};
double[] yData = {25.0, 42.0, 30.5, 18.7};
-jplotlib.bar(xLabels, yData).build();
+jplotlib.bar(xLabels, yData);
```
For more details and options for bar graphs, refer to the [BAR.md](BAR.md) document.
@@ -83,7 +83,7 @@ To create a 2D pie chart using Jplotlib, follow the same initial steps and then
```java
double[] dataPoints = {35.0, 25.0, 15.0, 25.0};
-jplotlib.pie(dataPoints).build();
+jplotlib.pie(dataPoints);
```
More information about pie charts can be found in the [PIE.md](PIE.md) document.
diff --git a/docs/LIB_COLOR.md b/docs/LIB_COLOR.md
new file mode 100644
index 0000000..52a2f16
--- /dev/null
+++ b/docs/LIB_COLOR.md
@@ -0,0 +1,47 @@
+# LibColor Enum
+
+The `LibColor` enum in Jplotlib provides a set of predefined colors that you can use to customize the appearance of your plots.
+
+### Available LibColor:
+
+- `LibColor.BLUE`
+- `LibColor.ORANGE`
+- `LibColor.GREEN`
+- `LibColor.RED`
+- `LibColor.PURPLE`
+- `LibColor.BROWN`
+- `LibColor.PINK`
+- `LibColor.GREY`
+- `LibColor.LIME`
+- `LibColor.SKY`
+
+### Example Usage:
+
+```java
+ import io.github.manishdait.jplotlib.Jplotlib;
+ import io.github.manishdait.jplotlib.defaults.color.LibColor;
+ import io.github.manishdait.jplotlib.defaults.marker.Marker;
+
+ public class App {
+ public static void main(String[] args) {
+ double[] y1 = {0, 3, 4, 7};
+ double[] y2 = {2.5, 5.1, 3.9, 6.2};
+
+ Jplotlib jplotlib = new Jplotlib();
+ jplotlib.plot(y1)
+ .marker(Marker.CIRCLE)
+ .markerColor(LibColor.GREEN.getColor());
+ jplotlib.plot(y2)
+ .marker(Marker.SQUARE)
+ .markerColor(Color.MAGENTA);
+ jplotlib.show();
+ }
+ }
+```
+In this example, we use the `.color(LibColor.BLUE.getColor())` method to set the line color to blue and `.markerColor(LibColor.RED.getColor())` to set marker color red using `LibColor` from Jplotlib. The `LibColor.BLUE` constant provides the predefined blue color and `LibColor.RED` constant provides predefine red color.
+
+
+
+You can use any of the available LibColor constants to customize the color of lines, markers, or other visual elements in your plot according to your preferences.
+
+
diff --git a/docs/MARKER.md b/docs/MARKER.md
index 9f2f315..1acb473 100644
--- a/docs/MARKER.md
+++ b/docs/MARKER.md
@@ -18,7 +18,7 @@ Currently, Jplotlib provides three marker types:
```java
import io.github.manishdait.jplotlib.Jplotlib;
-import io.github.manishdait.jplotlib.style.marker.BaseMarker;
+import io.github.manishdait.jplotlib.defaults.marker.Marker;
public class App {
public static void main(String[] args) {
@@ -28,27 +28,24 @@ public class App {
Jplotlib jplotlib = new Jplotlib();
jplotlib.plot(y1)
- .marker(BaseMarker.NONE)
- .build();
+ .marker(Marker.NONE);
jplotlib.plot(y2)
- .marker(BaseMarker.CIRCLE)
- .build();
+ .marker(Marker.CIRCLE);
jplotlib.plot(y3)
- .marker(BaseMarker.SQUARE)
- .build();
+ .marker(Marker.SQUARE);
jplotlib.show();
}
}
```
-In above example we use `.marker(BaseMarker.Circle)` to set marker as circle , `.marker(BaseMarker.Square)` to set marker as square and `.marker(BaseMarker.NONE)` to set no marker, `BaseMarker.NONE` is the default marker style.
+In above example we use `.marker(Marker.Circle)` to set marker as circle , `.marker(Marker.Square)` to set marker as square and `.marker(Marker.NONE)` to set no marker, `Marker.NONE` is the default marker style.
-
+
### Setting Marker Color:
-You can customize the color of the markers using the `.markerColor()` method. This method accepts either the `BaseColor` enum or `java.awt.Color`. You can find the available colors in the [BaseColor Enum section](BASE_COLOR.md) below.
+You can customize the color of the markers using the `.markerColor()` method. This method accepts either the `LibColor` enum or `java.awt.Color`. You can find the available colors in the [LibColor Enum section](LIB_COLOR.md) below.
### Example Usage:
@@ -56,8 +53,8 @@ You can customize the color of the markers using the `.markerColor()` method. Th
import java.awt.Color;
import io.github.manishdait.jplotlib.Jplotlib;
-import io.github.manishdait.jplotlib.style.color.BaseColor;
-import io.github.manishdait.jplotlib.style.marker.BaseMarker;
+import io.github.manishdait.jplotlib.defaults.color.LibColor;
+import io.github.manishdait.jplotlib.defaults.marker.Marker;
public class App {
public static void main(String[] args) {
@@ -66,20 +63,18 @@ public class App {
Jplotlib jplotlib = new Jplotlib();
jplotlib.plot(y1)
- .marker(BaseMarker.CIRCLE)
- .markerColor(BaseColor.GREEN.getColor())
- .build();
+ .marker(Marker.CIRCLE)
+ .markerColor(LibColor.GREEN.getColor());
jplotlib.plot(y2)
- .marker(BaseMarker.SQUARE)
- .markerColor(Color.MAGENTA)
- .build();
+ .marker(Marker.SQUARE)
+ .markerColor(Color.MAGENTA);
jplotlib.show();
}
}
```
-In above we use `.markerColor(BaseColor.GREEN.getColor())` method to set the marker color to green using the `BaseColor` enum and `.markerColor(Color.MAGENTA)` from java.awt.Color.
+In above we use `.markerColor(LibColor.GREEN.getColor())` method to set the marker color to green using the `LibColor` enum and `.markerColor(Color.MAGENTA)` from java.awt.Color.
-
+
### Setting Marker Size:
@@ -90,7 +85,7 @@ To adjust the size of the markers, you can use the `.markerSize()` method, which
```java
import io.github.manishdait.jplotlib.Jplotlib;
-import io.github.manishdait.jplotlib.style.marker.BaseMarker;
+import io.github.manishdait.jplotlib.defaults.marker.Marker;
public class App {
public static void main(String[] args) {
@@ -99,13 +94,11 @@ public class App {
Jplotlib jplotlib = new Jplotlib();
jplotlib.plot(y1)
- .marker(BaseMarker.CIRCLE)
- .markerSize(4)
- .build();
+ .marker(Marker.CIRCLE)
+ .markerSize(4);
jplotlib.plot(y2)
- .marker(BaseMarker.SQUARE)
- .markerSize(10)
- .build();
+ .marker(Marker.SQUARE)
+ .markerSize(10);
jplotlib.show();
}
}
@@ -113,6 +106,6 @@ public class App {
In above we use `.markerSize(4)` and `.markerSize(10)` to set marker size and 4 and 10 respectivly.
-
+
You can use the `.marker()` feature to enhance the visibility of data points in your plots and tailor the markers according to your preferences.
diff --git a/docs/PIE.md b/docs/PIE.md
index 9803a27..7d7d417 100644
--- a/docs/PIE.md
+++ b/docs/PIE.md
@@ -4,10 +4,19 @@ The `pie()` method in `Jplotlib` allows you to create 2D pie charts with ease. T
### Method Signature:
-```java
-pie(double[] dataPoints)
-```
-The `.pie()` method requires a single array: `dataPoints`, which contains numerical values representing the data points for the pie chart.
+1. `pie(double[] datapoint)`:
+
+ ```java
+ pie(double[] dataPoints)
+ ```
+ The `.pie()` method requires a single array: `dataPoints`, which contains numerical values representing the data points for the pie chart. It plot pie chart without labels.
+
+2. `pie(double[] datapoint, String[] labels)`:
+ ```java
+ pie(double[] dataPoints, String[] labels)
+ ```
+ The `.pie()` method requires a single array: `dataPoints` nad array of `labels`, which contains numerical values representing the data points and String value for labels for the pie chart.
+
### Example Usage:
@@ -18,15 +27,14 @@ public class App {
public static void main(String[] args) {
Jplotlib jplotlib = new Jplotlib();
double[] dataPoints = {35, 25, 25, 15};
- jplotlib.pie(dataPoints)
- .build();
+ jplotlib.pie(dataPoints);
jplotlib.show();
}
}
```
In this example, we use the `pie()` method to create a pie chart using only the `dataPoints` array. The pie chart visually represents the proportion of each data point relative to the whole dataset.
-
+
Pie charts are useful for displaying parts of a whole and showing the relative distribution of different categories within a dataset.
@@ -41,24 +49,41 @@ In Jplotlib, you can customize the colors of each pie section in a pie chart by
import java.awt.Color;
import io.github.manishdait.jplotlib.Jplotlib;
-import io.github.manishdait.jplotlib.style.color.BaseColor;
+import io.github.manishdait.jplotlib.defaults.color.LibColor;
public class App {
public static void main(String[] args) {
Jplotlib jplotlib = new Jplotlib();
double[] dataPoints = {35, 25, 25, 15};
- Color[] colors = {BaseColor.GREY.getColor(), BaseColor.PINK.getColor(), Color.CYAN, Color.MAGENTA};
+ Color[] colors = {LibColor.GREY.getColor(), LibColor.PINK.getColor(), Color.CYAN, Color.MAGENTA};
jplotlib.pie(dataPoints)
- .color(colors)
- .build();
+ .color(colors);
jplotlib.show();
}
}
```
-In this example, we use the `.color(colors)` method with the `pie()` method to set different colors for each pie section. The colors array contains colors from the BaseColor enum, specifying the color for each corresponding data point in the dataPoints array.
+In this example, we use the `.color(colors)` method with the `pie()` method to set different colors for each pie section. The colors array contains colors from the LibColor enum, specifying the color for each corresponding data point in the dataPoints array.
-
+
You can also use the java.awt.Color class to specify custom colors using RGB values, like `.color(new Color[]{Color.BLUE, Color.GREEN, Color.ORANGE, Color.RED})`.
+### Pie Chart with Label:
+
+```java
+import io.github.manishdait.jplotlib.Jplotlib;
+
+public class App {
+ public static void main(String[] args) {
+ Jplotlib jplotlib = new Jplotlib();
+ double[] dataPoints = {35, 25, 25, 15};
+ String[] labels = {"Apple", "Oranges", "Banana", "Mango"};
+ jplotlib.pie(dataPoints, labels);
+ jplotlib.show();
+ }
+}
+```
+In this example, we use the `pie()` method to create a pie chart using the `dataPoints` as wwll as `labels` array.
+
+
\ No newline at end of file
diff --git a/docs/PLOT.md b/docs/PLOT.md
index 6a1d614..f26540f 100644
--- a/docs/PLOT.md
+++ b/docs/PLOT.md
@@ -24,33 +24,32 @@ The `plot()` method in the `Jplotlib.plot()` allows you to create 2D line plots
## Line Color
-To customize the color of the line in the plot, you can use the `.color()` method available in the Jplotlib library. This method allows you to specify the color using either the `BaseColor` enum from Jplotlib or the `java.awt.Color` class.
+To customize the color of the line in the plot, you can use the `.color()` method available in the Jplotlib library. This method allows you to specify the color using either the `LibColor` enum from Jplotlib or the `java.awt.Color` class.
-### Using `BaseColor` from Jplotlib:
+### Using `LibColor` from Jplotlib:
-The `BaseColor` enum provides a set of predefined colors that you can use to style the line in your plot. Here's an example of how to use it:
+The `LibColor` enum provides a set of predefined colors that you can use to style the line in your plot. Here's an example of how to use it:
```java
import io.github.manishdait.jplotlib.Jplotlib;
-import io.github.manishdait.jplotlib.style.color.BaseColor;
+import io.github.manishdait.jplotlib.defaults.color.LibColor;
public class App {
public static void main(String[] args) {
Jplotlib jplotlib = new Jplotlib();
double[] y1 = {6, 2, 7, 11};
jplotlib.plot(y1)
- .color(BaseColor.LIME.getColor())
- .build();
+ .color(LibColor.LIME.getColor());
jplotlib.show();
}
}
```
-In this example, we use the `.color(BaseColor.LIME.getColor())` method to set the color of the line to lime.
+In this example, we use the `.color(LibColor.LIME.getColor())` method to set the color of the line to lime.
-
+
-For more information about the `BaseColor` enum and the available colors, refer to the [BaseColor Enum section](BASE_COLOR.md).
+For more information about the `LibColor` enum and the available colors, refer to the [LibColor Enum section](LIB_COLOR.md).
### Using `java.awt.Color`:
@@ -66,8 +65,7 @@ public class App {
Jplotlib jplotlib = new Jplotlib();
double[] y1 = {6, 2, 7, 11};
jplotlib.plot(y1)
- .color(Color.RED)
- .build();
+ .color(Color.RED);
jplotlib.show();
}
}
@@ -75,7 +73,7 @@ public class App {
In this example, we use the `.color(Color.RED)` method to set the color of the line to red.
-
+
Whichever method you choose, the `.color()` method allows you to customize the appearance of your line plots with different colors according to your preferences.
@@ -94,8 +92,7 @@ public class App {
Jplotlib jplotlib = new Jplotlib();
double[] y1 = {6, 2, 7, 11};
jplotlib.plot(y1)
- .lineWidth(15F)
- .build();
+ .lineWidth(15F);
jplotlib.show();
}
}
@@ -103,7 +100,7 @@ public class App {
In this example, we use the `.lineWidth(15F)` method to set the width of the line to 15.
-
+
@@ -114,57 +111,55 @@ The value passed to `.lineWidth()` should be a floating-point number between 1 a
## Line Style
-To change the style of the plotted line in the `Jplotlib.plot()` method, you can use the `.lineStyle()` method. This method allows you to customize the appearance of the line using the `BaseStoke` enum from Jplotlib, which currently contains two possible values: `NONE` and `DASHED`.
+To change the style of the plotted line in the `Jplotlib.plot()` method, you can use the `.lineStyle()` method. This method allows you to customize the appearance of the line using the `Stoke` enum from Jplotlib, which currently contains two possible values: `NONE` and `DASHED`.
### Example Usage:
```java
import io.github.manishdait.jplotlib.Jplotlib;
-import io.github.manishdait.jplotlib.style.line.BaseStroke;
+import io.github.manishdait.jplotlib.defaults.line.Stroke;
public class App {
public static void main(String[] args) {
Jplotlib jplotlib = new Jplotlib();
double[] y1 = {6, 2, 7, 11};
jplotlib.plot(y1)
- .lineStyle(BaseStroke.DASHED)
- .build();
+ .lineStyle(Stroke.DASHED);
jplotlib.show();
}
}
```
-In this example, we use the `.lineStyle(BaseStroke.DASHED)` method to set the style of the line to dashed.
+In this example, we use the `.lineStyle(Stroke.DASHED)` method to set the style of the line to dashed.
-
+
-For more information about the `BaseStroke` enum and the available styles, refer to the [BaseStroke Enum section](BASE_STROKE.md).
+For more information about the `Stroke` enum and the available styles, refer to the [Stroke Enum section](STROKE.md).
## Line Marker
-To add markers to line points in `Jplotlib.plot()`, you can use the `.marker()` method. This method allows you to customize the appearance of the markers using the `BaseMarker` enum from Jplotlib, which currently supports two marker types: `NONE`, `CIRCLE`, and `SQUARE`.
+To add markers to line points in `Jplotlib.plot()`, you can use the `.marker()` method. This method allows you to customize the appearance of the markers using the `Marker` enum from Jplotlib, which currently supports two marker types: `NONE`, `CIRCLE`, and `SQUARE`.
### Example Usage:
```java
import io.github.manishdait.jplotlib.Jplotlib;
-import io.github.manishdait.jplotlib.style.marker.BaseMarker;
+import io.github.manishdait.jplotlib.style.marker.Marker;
public class App {
public static void main(String[] args) {
Jplotlib jplotlib = new Jplotlib();
double[] y1 = {6, 2, 7, 11};
jplotlib.plot(y1)
- .marker(BaseMarker.CIRCLE)
- .build();
+ .marker(Marker.CIRCLE);
jplotlib.show();
}
}
```
-In this example, we use the `.marker(BaseMarker.CIRCLE)` method to add circular markers to the line points.
+In this example, we use the `.marker(Marker.CIRCLE)` method to add circular markers to the line points.
-
+
For more information about the `Marker` and how to use, refer to the [Marker section](MARKER.md).
@@ -182,10 +177,8 @@ public class App {
Jplotlib jplotlib = new Jplotlib();
double[] y1 = {6, 2, 7, 11};
double[] y2 = {3, 8, 1, 10};
- jplotlib.plot(y1)
- .build();
- jplotlib.plot(y2)
- .build();
+ jplotlib.plot(y1);
+ jplotlib.plot(y2);
jplotlib.show();
}
}
@@ -193,7 +186,7 @@ public class App {
In this example, we create two sets of y-coordinates (`y1` and `y2`) and plot them using two separate `Jplotlib.plot()` method calls. We customize the appearance of each line using different line styles and markers.
-
+
You can extend this approach to plot any number of lines by adding more `Jplotlib.plot()` method calls with their respective datasets and customizations.
@@ -215,10 +208,8 @@ public class App {
double[] x2 = {2, 3, 4, 5};
double[] y1 = {6, 2, 7, 11};
double[] y2 = {3, 8, 1, 10};
- jplotlib.plot(x1, y1)
- .build();
- jplotlib.plot(x2, y2)
- .build();
+ jplotlib.plot(x1, y1);
+ jplotlib.plot(x2, y2);
jplotlib.show();
}
}
@@ -226,5 +217,5 @@ public class App {
In this example, we create two sets of y-coordinates (`y1` and `y2`) and two sets of x-coordinates (`x1` and `x2`) and plot them using two separate `Jplotlib.plot()` method calls.
-
+
diff --git a/docs/SCATTER.md b/docs/SCATTER.md
index fd8ce11..047b232 100644
--- a/docs/SCATTER.md
+++ b/docs/SCATTER.md
@@ -30,8 +30,7 @@ public class App {
double[] y = {99,86,87,88,111,86,103,87,94,78,77,85,86};
Jplotlib jplotlib = new Jplotlib();
- jplotlib.scatter(x, y)
- .build();
+ jplotlib.scatter(x, y);
jplotlib.show();
}
}
@@ -39,7 +38,7 @@ public class App {
In this example, we use the `scatter()` method to create a scatter plot using `x` as the x-coordinates and `y` as the y-coordinates. Each point in the plot represents a pair of x and y values from the given arrays.
-
+
## Compare Plots
@@ -59,27 +58,25 @@ public class App {
double[] y2 = {100,105,84,105,90,99,90,95,94,100,79,112,91,80,85};
Jplotlib jplotlib = new Jplotlib();
- jplotlib.scatter(x1, y1)
- .build();
- jplotlib.scatter(x2, y2)
- .build();
+ jplotlib.scatter(x1, y1);
+ jplotlib.scatter(x2, y2);
jplotlib.show();
}
}
```
In this example, we use two `scatter()` methods to create two separate scatter plots. The first scatter() method creates a scatter plot using `x1` as the x-coordinates and `y1` as the y-coordinates, and the second scatter() method creates another scatter plot using `x2` and `y2`.
-
+
## Colors
-In Jplotlib, you have the flexibility to set your own color for each scatter plot using the `.color()` method. This feature allows you to customize the appearance of individual scatter plots, making it easier to distinguish different datasets or conditions in your visualizations. Similar to `plot().`[.color()](PLOT.md) you can use `BaseColor` enum of `java.awt.Color`.
+In Jplotlib, you have the flexibility to set your own color for each scatter plot using the `.color()` method. This feature allows you to customize the appearance of individual scatter plots, making it easier to distinguish different datasets or conditions in your visualizations. Similar to `plot().`[.color()](PLOT.md) you can use `LibColor` enum of `java.awt.Color`.
### Example Usage:
```java
import io.github.manishdait.jplotlib.Jplotlib;
-import io.github.manishdait.jplotlib.style.color.BaseColor;
+import io.github.manishdait.jplotlib.defaults.color.LibColor;
public class App {
public static void main(String[] args) {
@@ -90,25 +87,21 @@ public class App {
Jplotlib jplotlib = new Jplotlib();
jplotlib.scatter(x1, y1)
- .color(BaseColor.SKY.getColor())
- .build();
+ .color(LibColor.SKY.getColor());
jplotlib.scatter(x2, y2)
- .color(BaseColor.PINK.getColor())
- .build();
+ .color(LibColor.PINK.getColor());
jplotlib.show();
}
}
```
-In this example, we use the `.color(BaseColor.SKY.getColor())` argument with the first scatter() method to set the color of the first scatter plot to light_blue. Similarly, we use `.color(BaseColor.PINK.getColor())` with the second scatter() method to set the color of the second scatter plot to pink.
+In this example, we use the `.color(LibColor.SKY.getColor())` argument with the first scatter() method to set the color of the first scatter plot to light_blue. Similarly, we use `.color(LibColor.PINK.getColor())` with the second scatter() method to set the color of the second scatter plot to pink.
-
+
-For a complete list of available colors from the `BaseColor` enum, you can refer to the [BaseColor Enum](BASE_COLOR.md).
+For a complete list of available colors from the `BaseColor` enum, you can refer to the [LibColor Enum](LIB_COLOR.md).
-## Size
-
## Size
In Jplotlib, you can change the size of the dots in each scatter plot using the `.size()` argument. This feature allows you to adjust the size of individual data points, making them more visually distinguishable and highlighting specific data values in your scatter plots. It takes value between 1 to 10.
@@ -126,8 +119,7 @@ public class App {
Jplotlib jplotlib = new Jplotlib();
jplotlib.scatter(x, y)
- .size(size)
- .build();
+ .size(size);
jplotlib.show();
}
}
@@ -135,7 +127,7 @@ public class App {
In this example, we use the `.size()` argument with both scatter() methods to set the size of the dots for each data point. By customizing the size of each dot, you can emphasize specific data points or highlight patterns in the data, enhancing the overall visual representation of your scatter plots.
-
+
## Alpha
@@ -156,8 +148,7 @@ public class App {
Jplotlib jplotlib = new Jplotlib();
jplotlib.scatter(x, y)
.size(size)
- .alpha(0.5F)
- .build();
+ .alpha(0.5F);
jplotlib.show();
}
}
@@ -167,7 +158,7 @@ In this example, we use the `.alpha()` argument with the scatter() method to set
By adjusting the transparency of the dots, you can reveal underlying patterns in the data, especially when data points overlap or cluster closely together. It helps in visualizing the density of data points and identifying areas with higher concentration.
-
+
## Marker
@@ -178,7 +169,7 @@ In Jplotlib, you can change the style of markers for scatter points using the `.
```java
import io.github.manishdait.jplotlib.Jplotlib;
-import io.github.manishdait.jplotlib.style.marker.BaseMarker;
+import io.github.manishdait.jplotlib.defaults.marker.Marker;
public class App {
public static void main(String[] args) {
@@ -189,20 +180,18 @@ public class App {
Jplotlib jplotlib = new Jplotlib();
jplotlib.scatter(x1, y1)
- .marker(BaseMarker.SQUARE)
- .build();
- jplotlib.scatter(x2, y2)
- .build();
+ .marker(Marker.SQUARE);
+ jplotlib.scatter(x2, y2);
jplotlib.show();
}
}
```
-In this example, we use the `.marker(BaseMarker.SQUARE)` method with the `.scatter()` method to set the style of the marker for the scatter points. The `BaseMarker.SQUARE` value specifies that square markers will be used for each data point in the scatter plot.
+In this example, we use the `.marker(Marker.SQUARE)` method with the `.scatter()` method to set the style of the marker for the scatter points. The `Marker.SQUARE` value specifies that square markers will be used for each data point in the scatter plot.
-
+
-You can use various marker styles, such as `BaseMarker.NONE`, `BaseMarker.CIRCLE`, or `BaseMarker.SQUARE`, to change the appearance of the data points in the scatter plot.
+You can use various marker styles, such as `Marker.NONE`, `Marker.CIRCLE`, or `Marker.SQUARE`, to change the appearance of the data points in the scatter plot.
-For a complete list of available marker types and more details, you can refer to the [Marker Section](MARKER.md). Here the difference is that the `BaseMarker.NONE` will work same as `BaseMarker.CIRCLE`.
+For a complete list of available marker types and more details, you can refer to the [Marker Section](MARKER.md). Here the difference is that the `Marker.NONE` will work same as `Marker.CIRCLE`.
diff --git a/docs/STROKE.md b/docs/STROKE.md
new file mode 100644
index 0000000..f5cf1e4
--- /dev/null
+++ b/docs/STROKE.md
@@ -0,0 +1,34 @@
+# Stroke Enum
+
+The `Stroke` enum in Jplotlib provides options to customize the style of lines in plots.
+
+### Available Styles:
+
+Currently, the `Stoke` enum in Jplotlib provides two values for line style:
+
+- `Stroke.NONE`: This value sets the line style to a solid line with no special decoration (default style).
+
+- `Stroke.DASHED`: This value sets the line style to a dashed line.
+
+### Example Usage:
+
+```java
+import io.github.manishdait.jplotlib.Jplotlib;
+import io.github.manishdait.jplotlib.defaults.line.Stroke;
+
+public class App {
+ public static void main(String[] args) {
+ Jplotlib jplotlib = new Jplotlib();
+ double[] y1 = {6, 2, 7, 11};
+ jplotlib.plot(y1)
+ .lineStyle(Stroke.DASHED);
+ jplotlib.show();
+ }
+}
+```
+
+In this example, we use the `.lineStyle(Stroke.DASHED)` method to set the line style to dashed, overriding the default style which is `Stroke.NONE`.
+
+
+
+You can use the `Stroke` enum to change the appearance of lines in your plots according to your preferences. If no specific style is set, it will use the default `Stroke.NONE`, which is a solid line.
\ No newline at end of file
diff --git a/docs/assets/bar/bar_EG1.png b/docs/assets/bar/bar_EG1.png
new file mode 100644
index 0000000..3ad294d
Binary files /dev/null and b/docs/assets/bar/bar_EG1.png differ
diff --git a/docs/assets/bar/bar_EG2.png b/docs/assets/bar/bar_EG2.png
new file mode 100644
index 0000000..0a85d34
Binary files /dev/null and b/docs/assets/bar/bar_EG2.png differ
diff --git a/docs/assets/bar/bar_EG3.png b/docs/assets/bar/bar_EG3.png
new file mode 100644
index 0000000..486ac67
Binary files /dev/null and b/docs/assets/bar/bar_EG3.png differ
diff --git a/docs/assets/bar/bar_eg1.png b/docs/assets/bar/bar_eg1.png
deleted file mode 100644
index c70c6aa..0000000
Binary files a/docs/assets/bar/bar_eg1.png and /dev/null differ
diff --git a/docs/assets/bar/bar_eg2.png b/docs/assets/bar/bar_eg2.png
deleted file mode 100644
index a8ed9c8..0000000
Binary files a/docs/assets/bar/bar_eg2.png and /dev/null differ
diff --git a/docs/assets/base_color_eg1.png b/docs/assets/base_color_eg1.png
deleted file mode 100644
index c229c83..0000000
Binary files a/docs/assets/base_color_eg1.png and /dev/null differ
diff --git a/docs/assets/base_eg1.png b/docs/assets/base_eg1.png
deleted file mode 100644
index 5196a9d..0000000
Binary files a/docs/assets/base_eg1.png and /dev/null differ
diff --git a/docs/assets/base_eg2.png b/docs/assets/base_eg2.png
deleted file mode 100644
index 37011d8..0000000
Binary files a/docs/assets/base_eg2.png and /dev/null differ
diff --git a/docs/assets/base_stroke_eg1.png b/docs/assets/base_stroke_eg1.png
deleted file mode 100644
index 3566a18..0000000
Binary files a/docs/assets/base_stroke_eg1.png and /dev/null differ
diff --git a/docs/assets/marker/marker_EG1.png b/docs/assets/marker/marker_EG1.png
new file mode 100644
index 0000000..05b8203
Binary files /dev/null and b/docs/assets/marker/marker_EG1.png differ
diff --git a/docs/assets/marker/marker_EG2.png b/docs/assets/marker/marker_EG2.png
new file mode 100644
index 0000000..9d9ac2f
Binary files /dev/null and b/docs/assets/marker/marker_EG2.png differ
diff --git a/docs/assets/marker/marker_EG3.png b/docs/assets/marker/marker_EG3.png
new file mode 100644
index 0000000..730d508
Binary files /dev/null and b/docs/assets/marker/marker_EG3.png differ
diff --git a/docs/assets/marker/marker_eg1.png b/docs/assets/marker/marker_eg1.png
deleted file mode 100644
index 37b2f8b..0000000
Binary files a/docs/assets/marker/marker_eg1.png and /dev/null differ
diff --git a/docs/assets/marker/marker_eg2.png b/docs/assets/marker/marker_eg2.png
deleted file mode 100644
index da6b631..0000000
Binary files a/docs/assets/marker/marker_eg2.png and /dev/null differ
diff --git a/docs/assets/marker/marker_eg3.png b/docs/assets/marker/marker_eg3.png
deleted file mode 100644
index 59f5af7..0000000
Binary files a/docs/assets/marker/marker_eg3.png and /dev/null differ
diff --git a/docs/assets/pie/pie.EG3.png b/docs/assets/pie/pie.EG3.png
new file mode 100644
index 0000000..71b9a67
Binary files /dev/null and b/docs/assets/pie/pie.EG3.png differ
diff --git a/docs/assets/pie/pie_EG1.png b/docs/assets/pie/pie_EG1.png
new file mode 100644
index 0000000..7df3fb5
Binary files /dev/null and b/docs/assets/pie/pie_EG1.png differ
diff --git a/docs/assets/pie/pie_EG2.png b/docs/assets/pie/pie_EG2.png
new file mode 100644
index 0000000..99181f7
Binary files /dev/null and b/docs/assets/pie/pie_EG2.png differ
diff --git a/docs/assets/pie/pie_eg1.png b/docs/assets/pie/pie_eg1.png
deleted file mode 100644
index 99aa5d9..0000000
Binary files a/docs/assets/pie/pie_eg1.png and /dev/null differ
diff --git a/docs/assets/pie/pie_eg2.png b/docs/assets/pie/pie_eg2.png
deleted file mode 100644
index 58e934a..0000000
Binary files a/docs/assets/pie/pie_eg2.png and /dev/null differ
diff --git a/docs/assets/plot/plot_EG1.png b/docs/assets/plot/plot_EG1.png
new file mode 100644
index 0000000..3b52b22
Binary files /dev/null and b/docs/assets/plot/plot_EG1.png differ
diff --git a/docs/assets/plot/plot_EG2.png b/docs/assets/plot/plot_EG2.png
new file mode 100644
index 0000000..b550f2f
Binary files /dev/null and b/docs/assets/plot/plot_EG2.png differ
diff --git a/docs/assets/plot/plot_EG3.png b/docs/assets/plot/plot_EG3.png
new file mode 100644
index 0000000..4ee9708
Binary files /dev/null and b/docs/assets/plot/plot_EG3.png differ
diff --git a/docs/assets/plot/plot_EG4.png b/docs/assets/plot/plot_EG4.png
new file mode 100644
index 0000000..96039db
Binary files /dev/null and b/docs/assets/plot/plot_EG4.png differ
diff --git a/docs/assets/plot/plot_EG5.png b/docs/assets/plot/plot_EG5.png
new file mode 100644
index 0000000..cc5de0a
Binary files /dev/null and b/docs/assets/plot/plot_EG5.png differ
diff --git a/docs/assets/plot/plot_EG6.png b/docs/assets/plot/plot_EG6.png
new file mode 100644
index 0000000..b05c56c
Binary files /dev/null and b/docs/assets/plot/plot_EG6.png differ
diff --git a/docs/assets/plot/plot_EG7.png b/docs/assets/plot/plot_EG7.png
new file mode 100644
index 0000000..cdb8e91
Binary files /dev/null and b/docs/assets/plot/plot_EG7.png differ
diff --git a/docs/assets/plot/plot_eg1.png b/docs/assets/plot/plot_eg1.png
deleted file mode 100644
index e87724f..0000000
Binary files a/docs/assets/plot/plot_eg1.png and /dev/null differ
diff --git a/docs/assets/plot/plot_eg2.png b/docs/assets/plot/plot_eg2.png
deleted file mode 100644
index 7a17cfb..0000000
Binary files a/docs/assets/plot/plot_eg2.png and /dev/null differ
diff --git a/docs/assets/plot/plot_eg3.png b/docs/assets/plot/plot_eg3.png
deleted file mode 100644
index b60e5da..0000000
Binary files a/docs/assets/plot/plot_eg3.png and /dev/null differ
diff --git a/docs/assets/plot/plot_eg4.png b/docs/assets/plot/plot_eg4.png
deleted file mode 100644
index e80ab11..0000000
Binary files a/docs/assets/plot/plot_eg4.png and /dev/null differ
diff --git a/docs/assets/plot/plot_eg5.png b/docs/assets/plot/plot_eg5.png
deleted file mode 100644
index 3370eb1..0000000
Binary files a/docs/assets/plot/plot_eg5.png and /dev/null differ
diff --git a/docs/assets/plot/plot_eg6.png b/docs/assets/plot/plot_eg6.png
deleted file mode 100644
index 0270ded..0000000
Binary files a/docs/assets/plot/plot_eg6.png and /dev/null differ
diff --git a/docs/assets/plot/plot_eg7.png b/docs/assets/plot/plot_eg7.png
deleted file mode 100644
index 05f3b38..0000000
Binary files a/docs/assets/plot/plot_eg7.png and /dev/null differ
diff --git a/docs/assets/readme_EG1.png b/docs/assets/readme_EG1.png
new file mode 100644
index 0000000..d322deb
Binary files /dev/null and b/docs/assets/readme_EG1.png differ
diff --git a/docs/assets/readme_EG2.png b/docs/assets/readme_EG2.png
new file mode 100644
index 0000000..1cd9ea9
Binary files /dev/null and b/docs/assets/readme_EG2.png differ
diff --git a/docs/assets/scatter/scatter_EG1.png b/docs/assets/scatter/scatter_EG1.png
new file mode 100644
index 0000000..42bba6e
Binary files /dev/null and b/docs/assets/scatter/scatter_EG1.png differ
diff --git a/docs/assets/scatter/scatter_EG2.png b/docs/assets/scatter/scatter_EG2.png
new file mode 100644
index 0000000..25ee42d
Binary files /dev/null and b/docs/assets/scatter/scatter_EG2.png differ
diff --git a/docs/assets/scatter/scatter_EG3.png b/docs/assets/scatter/scatter_EG3.png
new file mode 100644
index 0000000..21c62a2
Binary files /dev/null and b/docs/assets/scatter/scatter_EG3.png differ
diff --git a/docs/assets/scatter/scatter_EG4.png b/docs/assets/scatter/scatter_EG4.png
new file mode 100644
index 0000000..e8bb6a8
Binary files /dev/null and b/docs/assets/scatter/scatter_EG4.png differ
diff --git a/docs/assets/scatter/scatter_EG5.png b/docs/assets/scatter/scatter_EG5.png
new file mode 100644
index 0000000..5fdc0a3
Binary files /dev/null and b/docs/assets/scatter/scatter_EG5.png differ
diff --git a/docs/assets/scatter/scatter_EG6.png b/docs/assets/scatter/scatter_EG6.png
new file mode 100644
index 0000000..593edc4
Binary files /dev/null and b/docs/assets/scatter/scatter_EG6.png differ
diff --git a/docs/assets/scatter/scatter_eg1.png b/docs/assets/scatter/scatter_eg1.png
deleted file mode 100644
index dfff693..0000000
Binary files a/docs/assets/scatter/scatter_eg1.png and /dev/null differ
diff --git a/docs/assets/scatter/scatter_eg2.png b/docs/assets/scatter/scatter_eg2.png
deleted file mode 100644
index dcfa250..0000000
Binary files a/docs/assets/scatter/scatter_eg2.png and /dev/null differ
diff --git a/docs/assets/scatter/scatter_eg3.png b/docs/assets/scatter/scatter_eg3.png
deleted file mode 100644
index 8bbfd28..0000000
Binary files a/docs/assets/scatter/scatter_eg3.png and /dev/null differ
diff --git a/docs/assets/scatter/scatter_eg4.png b/docs/assets/scatter/scatter_eg4.png
deleted file mode 100644
index 739a6cb..0000000
Binary files a/docs/assets/scatter/scatter_eg4.png and /dev/null differ
diff --git a/docs/assets/scatter/scatter_eg5.png b/docs/assets/scatter/scatter_eg5.png
deleted file mode 100644
index 9ad90dd..0000000
Binary files a/docs/assets/scatter/scatter_eg5.png and /dev/null differ
diff --git a/docs/assets/scatter/scatter_eg6.png b/docs/assets/scatter/scatter_eg6.png
deleted file mode 100644
index 747d6eb..0000000
Binary files a/docs/assets/scatter/scatter_eg6.png and /dev/null differ
diff --git a/eclipse-formatter.xml b/eclipse-formatter.xml
new file mode 100644
index 0000000..7f8c57d
--- /dev/null
+++ b/eclipse-formatter.xml
@@ -0,0 +1,315 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/pom.xml b/pom.xml
index a08ff29..c7b72db 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
io.github.manishdait
jplotlib
- 1.0.0
+ 1.1.0
jplotlib
https://github.com/ManishDait/jplotlib
@@ -24,6 +24,22 @@
4.11
test
+
+
+ org.apache.logging.log4j
+ log4j-api
+ 2.7
+
+
+ org.apache.logging.log4j
+ log4j-core
+ 2.7
+
+
+ org.apache.logging.log4j
+ log4j-slf4j-impl
+ 2.7
+
diff --git a/src/main/java/io/github/manishdait/jplotlib/Jplotlib.java b/src/main/java/io/github/manishdait/jplotlib/Jplotlib.java
old mode 100644
new mode 100755
index 88653f2..fb503b3
--- a/src/main/java/io/github/manishdait/jplotlib/Jplotlib.java
+++ b/src/main/java/io/github/manishdait/jplotlib/Jplotlib.java
@@ -27,20 +27,22 @@
import java.util.ArrayList;
import java.util.List;
-import io.github.manishdait.jplotlib.chart.BarGraph;
-import io.github.manishdait.jplotlib.chart.LineGraph;
-import io.github.manishdait.jplotlib.chart.PieChart;
-import io.github.manishdait.jplotlib.chart.ScatterGraph;
-import io.github.manishdait.jplotlib.chart.helper.BarGraphOptions;
-import io.github.manishdait.jplotlib.chart.helper.LineGraphOptions;
-import io.github.manishdait.jplotlib.chart.helper.PieChartOptions;
-import io.github.manishdait.jplotlib.chart.helper.ScatterGraphOptions;
-import io.github.manishdait.jplotlib.data.Coordinates;
-import io.github.manishdait.jplotlib.data.SeriesData;
-import io.github.manishdait.jplotlib.data.StyleData;
-import io.github.manishdait.jplotlib.error.ArrayLengthMissMatchException;
-import io.github.manishdait.jplotlib.internal.util.AxisType;
-import io.github.manishdait.jplotlib.ui.BaseFrame;
+import io.github.manishdait.jplotlib.charts.bar.BarGraph;
+import io.github.manishdait.jplotlib.charts.bar.BarGraphOptions;
+import io.github.manishdait.jplotlib.charts.helper.Graph;
+import io.github.manishdait.jplotlib.charts.line.LineChart;
+import io.github.manishdait.jplotlib.charts.line.LineChartOptions;
+import io.github.manishdait.jplotlib.charts.pie.PieChart;
+import io.github.manishdait.jplotlib.charts.pie.PieChartOptions;
+import io.github.manishdait.jplotlib.charts.scatter.ScatterChart;
+import io.github.manishdait.jplotlib.charts.scatter.ScatterChartOptions;
+import io.github.manishdait.jplotlib.data.GraphData;
+import io.github.manishdait.jplotlib.error.JplotlibError;
+import io.github.manishdait.jplotlib.error.util.ErrorConstants;
+import io.github.manishdait.jplotlib.data.CartesianData;
+import io.github.manishdait.jplotlib.internals.components.axis.Config;
+import io.github.manishdait.jplotlib.internals.util.AxisType;
+import io.github.manishdait.jplotlib.ui.Window;
/**
* Jplotlib is a Java library for creating and displaying different types of
@@ -61,89 +63,68 @@
* jplot.pie(new double[]{10, 20, 30, 40});
* jplot.show();
*
- * Note: The show() method will display the chart only if it has data points
+ * Note: The show() method will display the chart only if it has data points
* (coordinates or pieData).
*
* @author Manish Dait
- * @version 1.0.0
+ * @version 1.1.0
*/
-public class Jplotlib implements
- LineGraphOptions,
- ScatterGraphOptions,
- BarGraphOptions,
- PieChartOptions
-{
+public final class Jplotlib implements
+ LineChartOptions,
+ ScatterChartOptions,
+ BarGraphOptions,
+ PieChartOptions {
- private BaseFrame baseFrame;
- private SeriesData seriesData;
+ protected Window window;
+ protected Config axisConfiguration;
+ protected List graphs;
- private List styleData;
+ private boolean isPlotable;
public Jplotlib() {
- this.seriesData = new SeriesData();
- this.styleData = new ArrayList();
+ this.axisConfiguration = new Config();
+ this.graphs = new ArrayList<>();
}
public final void show() {
- if(seriesData.getCoordinates() == null && seriesData.getPieData() == null) {
+ if (!isPlotable) {
return;
}
- this.baseFrame = new BaseFrame(this.seriesData, this.styleData);
- this.baseFrame.setVisible(true);
+ this.window = new Window(this.axisConfiguration, this.graphs);
+ this.window.setVisible(true);
}
public final void title(final String str) {
- this.seriesData.setTitle(str);
+ this.axisConfiguration.setTitle(str);
}
public final void xLabel(final String str) {
- this.seriesData.setxLabel(str);
+ this.axisConfiguration.setxLabel(str);
}
public final void yLabel(final String str) {
- this.seriesData.setyLabel(str);
+ this.axisConfiguration.setyLabel(str);
}
public final void grid() {
- this.seriesData.setxGrid(true);
- this.seriesData.setyGrid(true);
+ this.axisConfiguration.setxGrid(true);
+ this.axisConfiguration.setyGrid(true);
}
public final void grid(final boolean xGrid, final boolean yGrid) {
- this.seriesData.setxGrid(xGrid);
- this.seriesData.setyGrid(yGrid);
+ this.axisConfiguration.setxGrid(xGrid);
+ this.axisConfiguration.setyGrid(yGrid);
}
- private List setCoordinates(
- final double[] xPoints,
- final double[] yPoints,
- AxisType axisType
- ) {
- List currCoordinates = new ArrayList<>();
- if (this.seriesData.getCoordinates() != null) {
- currCoordinates = this.seriesData.getCoordinates();
+ private void setAxisType(AxisType axisType) {
+ if (axisConfiguration.getAxisType() == null
+ || axisConfiguration.getAxisType().getPriority() < axisType.getPriority()) {
+ axisConfiguration.setAxisType(axisType);
}
-
- Coordinates coordinates = new Coordinates();
- coordinates.setxPoints(xPoints);
- coordinates.setyPoints(yPoints);
- currCoordinates.add(coordinates);
- if (
- seriesData.getAxisType() == null ||
- seriesData.getAxisType().getPriority() < axisType.getPriority()
- ) {
- seriesData.setAxisType(axisType);
- }
-
- return currCoordinates;
}
- private void setLabel(String[] label) {
- seriesData.setLabel(label);
- }
-
- private double[] tempArr(final double[] yPoints) {
+ private double[] createTempArr(final double[] yPoints) {
double[] arr = new double[yPoints.length];
for (int i = 0; i < yPoints.length; i++) {
arr[i] = i;
@@ -151,96 +132,167 @@ private double[] tempArr(final double[] yPoints) {
return arr;
}
- // LINE GRAPH
+ private void setAxisParameters(double[] xPoints, double[] yPoints) {
+ setXData(xPoints);
+ setYData(yPoints);
+ }
+
+ private void setAxisParameters(String[] labels, double[] data, boolean isX) {
+ if (isX) {
+ setXData(data);
+ } else {
+ setYData(data);
+ }
+
+ for (String label : labels) {
+ if (!GraphData.getMap().containsKey(label)) {
+ GraphData.getMap().put(label, GraphData.getIndx());
+ GraphData.setIndx(GraphData.getIndx() + 1);
+ }
+ }
+
+ GraphData.setX(isX);
+ axisConfiguration.setBarLabelLen(GraphData.getMap().size());
+ }
+
+ private void setYData(double[] data) {
+ double max = axisConfiguration.getyUpperBound();
+ double min = axisConfiguration.getyLowerBound();
+ for (double i : data) {
+ max = max > i ? max : i;
+ min = min < i ? min : i;
+ }
+ axisConfiguration.setyUpperBound((int) max);
+ axisConfiguration.setyLowerBound((int) min);
+ axisConfiguration.setMaxYLength(
+ axisConfiguration.getMaxYLength() > data.length ? axisConfiguration.getMaxYLength() : data.length);
+ axisConfiguration.setTotalYLength(axisConfiguration.getTotalYLength() + data.length);
+ }
+
+ private void setXData(double[] data) {
+ double max = axisConfiguration.getxUpperBound();
+ double min = axisConfiguration.getxLowerBound();
+ for (double i : data) {
+ max = max > i ? max : i;
+ min = min < i ? min : i;
+ }
+ axisConfiguration.setxUpperBound((int) max);
+ axisConfiguration.setxLowerBound((int) min);
+ axisConfiguration.setMaxXLength(
+ axisConfiguration.getMaxXLength() > data.length ? axisConfiguration.getMaxXLength() : data.length);
+ axisConfiguration.setTotalXLength(axisConfiguration.getTotalXLength() + data.length);
+ }
+
+ // Line Chart
@Override
- public final LineGraph plot(
- final double[] yPoints
- ) {
- double[] temp = tempArr(yPoints);
- List coordinates = setCoordinates(
- temp,
- yPoints,
- AxisType.PLOT
- );
- this.seriesData.setCoordinates(coordinates);
- LineGraph lineGraph = new LineGraph(this.styleData);
- return lineGraph;
+ public LineChart plot(double[] yPoints) {
+ if (yPoints == null) {
+ throw new JplotlibError(ErrorConstants.NULL_DATA_ERROR);
+ }
+ double[] xPoints = createTempArr(yPoints);
+ setAxisType(AxisType.PLOT);
+ setAxisParameters(xPoints, yPoints);
+ LineChart lineChart = new LineChart(new CartesianData(xPoints, yPoints));
+ graphs.add(lineChart);
+ isPlotable = true;
+ return lineChart;
}
@Override
- public final LineGraph plot(
- final double[] xPoints,
- final double[] yPoints
- ) {
+ public LineChart plot(double[] xPoints, double[] yPoints) {
+ if (xPoints == null || yPoints == null) {
+ throw new JplotlibError(ErrorConstants.NULL_DATA_ERROR);
+ }
if (xPoints.length != yPoints.length) {
- throw new ArrayLengthMissMatchException(
- "xPoints and yPoints must be of same size."
- );
+ throw new JplotlibError(ErrorConstants.UNMATCH_DIMENSION_LENGTH_ERROR);
}
-
- List coordinates = setCoordinates(
- xPoints,
- yPoints,
- AxisType.PLOT
- );
- this.seriesData.setCoordinates(coordinates);
- LineGraph lineGraph = new LineGraph(this.styleData);
- return lineGraph;
+ setAxisType(AxisType.PLOT);
+ setAxisParameters(xPoints, yPoints);
+ LineChart lineChart = new LineChart(new CartesianData(xPoints, yPoints));
+ graphs.add(lineChart);
+ isPlotable = true;
+ return lineChart;
}
- // SCATTER GRAPH
+ // Scatter Chart
@Override
- public final ScatterGraph scatter(
- final double[] xPoints,
- final double[] yPoints
- ) {
+ public ScatterChart scatter(double[] xPoints, double[] yPoints) {
+ if (xPoints == null || yPoints == null) {
+ throw new JplotlibError(ErrorConstants.NULL_DATA_ERROR);
+ }
if (xPoints.length != yPoints.length) {
- throw new ArrayLengthMissMatchException(
- "xPoints and yPoints must be of same size."
- );
+ throw new JplotlibError(ErrorConstants.UNMATCH_DIMENSION_LENGTH_ERROR);
}
-
- List coordinates = setCoordinates(
- xPoints,
- yPoints,
- AxisType.PLOT
- );
- this.seriesData.setCoordinates(coordinates);
- ScatterGraph scatterGraph = new ScatterGraph(this.styleData);
- return scatterGraph;
+ setAxisType(AxisType.PLOT);
+ setAxisParameters(xPoints, yPoints);
+ ScatterChart scatterChart = new ScatterChart(new CartesianData(xPoints, yPoints));
+ graphs.add(scatterChart);
+ isPlotable = true;
+ return scatterChart;
}
- // BAR GRAPH
+ // Bar Graph
+
+ @Override
+ public BarGraph bar(String[] labels, double[] points) {
+ if (labels == null || points == null) {
+ throw new JplotlibError(ErrorConstants.NULL_DATA_ERROR);
+ }
+ if (labels.length != points.length) {
+ throw new JplotlibError(ErrorConstants.MISSMATCH_LABELDATA_LENGTH_ERROR);
+ }
+ setAxisType(AxisType.BAR);
+ setAxisParameters(labels, points, false);
+ BarGraph barGraph = new BarGraph(new GraphData(labels, points));
+ graphs.add(barGraph);
+ isPlotable = true;
+ return barGraph;
+ }
@Override
- public final BarGraph bar(String[] xLabels, double[] yPoints) {
- if (xLabels.length != yPoints.length) {
- throw new ArrayLengthMissMatchException(
- "yPoints and label must be of same size."
- );
- }
-
- List coordinates = setCoordinates(
- tempArr(yPoints),
- yPoints,
- AxisType.BAR
- );
- setLabel(xLabels);
- this.seriesData.setCoordinates(coordinates);
- BarGraph barGraph = new BarGraph(styleData);
+ public BarGraph barh(String[] labels, double[] points) {
+ if (labels == null || points == null) {
+ throw new JplotlibError(ErrorConstants.NULL_DATA_ERROR);
+ }
+ if (labels.length != points.length) {
+ throw new JplotlibError(ErrorConstants.MISSMATCH_LABELDATA_LENGTH_ERROR);
+ }
+ setAxisType(AxisType.BAR);
+ setAxisParameters(labels, points, true);
+ BarGraph barGraph = new BarGraph(new GraphData(labels, points));
+ graphs.add(barGraph);
+ isPlotable = true;
return barGraph;
}
- // PIE CHART
+ // Pie Chart
@Override
- public final PieChart pie(double[] dataPoints) {
- this.seriesData.setAxisType(AxisType.PIE);
- this.seriesData.setPieData(dataPoints);
- PieChart pieChart = new PieChart(styleData);
+ public PieChart pie(double[] dataPoints) {
+ if (dataPoints == null) {
+ throw new JplotlibError(ErrorConstants.NULL_DATA_ERROR);
+ }
+ setAxisType(AxisType.PIE);
+ PieChart pieChart = new PieChart(new GraphData(null, dataPoints));
+ graphs.add(pieChart);
+ isPlotable = true;
return pieChart;
}
+ @Override
+ public PieChart pie(double[] dataPoints, String[] labels) {
+ if (dataPoints == null || labels == null) {
+ throw new JplotlibError(ErrorConstants.NULL_DATA_ERROR);
+ }
+ if (labels.length != dataPoints.length) {
+ throw new JplotlibError(ErrorConstants.MISSMATCH_LABELDATA_LENGTH_ERROR);
+ }
+ setAxisType(AxisType.PIE);
+ PieChart pieChart = new PieChart(new GraphData(labels, dataPoints));
+ graphs.add(pieChart);
+ isPlotable = true;
+ return pieChart;
+ }
}
diff --git a/src/main/java/io/github/manishdait/jplotlib/chart/BarGraph.java b/src/main/java/io/github/manishdait/jplotlib/chart/BarGraph.java
deleted file mode 100644
index ddaef9f..0000000
--- a/src/main/java/io/github/manishdait/jplotlib/chart/BarGraph.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * MIT License
- *
- * Copyright (c) 2023 Manish Dait
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-package io.github.manishdait.jplotlib.chart;
-
-import java.awt.Color;
-import java.util.List;
-
-import io.github.manishdait.jplotlib.data.StyleData;
-import io.github.manishdait.jplotlib.internal.util.ChartType;
-
-
-public class BarGraph {
-
- private BarSeries barSeries;
- private List styleDatas;
-
- public BarGraph(List styleDatas) {
- this.barSeries = new BarSeries();
- this.styleDatas = styleDatas;
- }
-
- public BarGraph color(Color color) {
- barSeries.setColor(color);
- return this;
- }
-
- private BarSeries getMeta() {
- return this.barSeries;
- }
-
- public void build() {
- StyleData styleData = new StyleData();
- styleData.setChartType(ChartType.BAR);
- styleData.setBarSeries(this.getMeta());
- this.styleDatas.add(styleData);
- }
-
-}
diff --git a/src/main/java/io/github/manishdait/jplotlib/chart/BarGraphBuilder.java b/src/main/java/io/github/manishdait/jplotlib/chart/BarGraphBuilder.java
deleted file mode 100644
index 609909a..0000000
--- a/src/main/java/io/github/manishdait/jplotlib/chart/BarGraphBuilder.java
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- * MIT License
- *
- * Copyright (c) 2023 Manish Dait
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-package io.github.manishdait.jplotlib.chart;
-
-import java.awt.Color;
-import java.awt.Graphics;
-import java.awt.Graphics2D;
-import java.awt.RenderingHints;
-
-import javax.swing.JPanel;
-
-import io.github.manishdait.jplotlib.data.SeriesData;
-import io.github.manishdait.jplotlib.plotter.Plotter;
-import io.github.manishdait.jplotlib.style.color.BaseSeriesColor;
-
-
-public class BarGraphBuilder implements Plotter {
-
- private Graphics2D g;
- private JPanel context;
- private SeriesData seriesData;
- private BarSeries barSeries;
- private int indx;
-
- public BarGraphBuilder(
- Graphics g,
- JPanel context,
- SeriesData seriesData,
- BarSeries barSeries,
- int indx
- ) {
- this.g = (Graphics2D) g;
- this.context = context;
- this.seriesData = seriesData;
- this.barSeries = barSeries;
- this.indx = indx;
- }
-
- @Override
- public void draw() {
- double[] yPoints = this.seriesData.getCoordinates().get(indx).getyPoints();
-
- this.g.setRenderingHint(
- RenderingHints.KEY_ANTIALIASING,
- RenderingHints.VALUE_ANTIALIAS_ON
- );
-
- Color color = barSeries.getColor();
- if(color == null) {
- color = BaseSeriesColor.getColor(indx);
- }
-
- this.g.setColor(color);
-
- int yLowerBound = seriesData.getyLowerBound();
-
- int xIncrement = seriesData.getxIncrement();
- int xValDiff = context.getWidth() / (yPoints.length * 2);
-
- int yIncrement = seriesData.getyIncrement();
- int yValDiff = seriesData.getyValDiff();
-
- int extraSpace = (int) (Math.max(xIncrement, yIncrement) * 0.25);
-
- for(int i = 0; i < yPoints.length; i++){
- int x = (xIncrement * (i * 2 + 1)) - xValDiff / 2;
- int y = context.getHeight() - ((int) (yIncrement * (yPoints[i] - yLowerBound)) / yValDiff);
- int h = (int) (yIncrement * (yPoints[i] - yLowerBound)) / yValDiff;
-
- this.g.fillRect(
- x ,
- y - extraSpace,
- xValDiff,
- h + extraSpace
- );
- }
- }
-
-}
diff --git a/src/main/java/io/github/manishdait/jplotlib/chart/LineGraph.java b/src/main/java/io/github/manishdait/jplotlib/chart/LineGraph.java
deleted file mode 100644
index cde5bca..0000000
--- a/src/main/java/io/github/manishdait/jplotlib/chart/LineGraph.java
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
- * MIT License
- *
- * Copyright (c) 2023 Manish Dait
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-package io.github.manishdait.jplotlib.chart;
-
-import java.awt.Color;
-import java.util.List;
-
-import io.github.manishdait.jplotlib.data.StyleData;
-import io.github.manishdait.jplotlib.internal.util.ChartType;
-import io.github.manishdait.jplotlib.style.line.BaseStroke;
-import io.github.manishdait.jplotlib.style.marker.BaseMarker;
-
-
-public class LineGraph {
-
- private LineSeries lineSeries;
- private List styleDatas;
-
- public LineGraph(List styleDatas) {
- this.lineSeries = new LineSeries();
- this.styleDatas = styleDatas;
- }
-
- public LineGraph marker(BaseMarker marker) {
- marker = marker == null ? BaseMarker.NONE : marker;
- lineSeries.setMarker(marker);
- return this;
- }
-
- public LineGraph color(Color color) {
- this.lineSeries.setColor(color);
- return this;
- }
-
- public LineGraph markerColor(Color color) {
- this.lineSeries.setMarkerColor(color);
- return this;
- }
-
- public LineGraph lineStyle(BaseStroke style) {
- style = style == null ? BaseStroke.NONE : style;
- this.lineSeries.setLineStyle(style);
- return this;
- }
-
- public LineGraph lineWidth(float width) {
- width = width < 1 ? 1 : width;
- width = width > 15 ? 15 : width;
- this.lineSeries.setLineWidth(width);
- return this;
- }
-
- public LineGraph markerSize(int size) {
- lineSeries.setMarkerSize(size);
- return this;
- }
-
- private LineSeries getMeta() {
- return this.lineSeries;
- }
-
- public void build() {
- StyleData styleData = new StyleData();
- styleData.setChartType(ChartType.LINE);
- styleData.setLineSeries(this.getMeta());
- this.styleDatas.add(styleData);
- }
-
-}
diff --git a/src/main/java/io/github/manishdait/jplotlib/chart/LineGraphBuilder.java b/src/main/java/io/github/manishdait/jplotlib/chart/LineGraphBuilder.java
deleted file mode 100644
index bc7f975..0000000
--- a/src/main/java/io/github/manishdait/jplotlib/chart/LineGraphBuilder.java
+++ /dev/null
@@ -1,179 +0,0 @@
-/*
- * MIT License
- *
- * Copyright (c) 2023 Manish Dait
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-package io.github.manishdait.jplotlib.chart;
-
-import java.awt.BasicStroke;
-import java.awt.Color;
-import java.awt.Graphics;
-import java.awt.Graphics2D;
-import java.awt.RenderingHints;
-import java.awt.Shape;
-import java.awt.geom.Line2D;
-
-import javax.swing.JPanel;
-
-import io.github.manishdait.jplotlib.data.SeriesData;
-import io.github.manishdait.jplotlib.internal.util.Constants;
-import io.github.manishdait.jplotlib.plotter.Plotter;
-import io.github.manishdait.jplotlib.style.color.BaseSeriesColor;
-import io.github.manishdait.jplotlib.style.marker.BaseMarker;
-
-
-public class LineGraphBuilder implements Plotter {
-
- private Graphics2D g;
- private JPanel context;
- private SeriesData seriesData;
- private LineSeries lineSeries;
- private int indx;
-
- public LineGraphBuilder(
- Graphics g2,
- JPanel context,
- SeriesData seriesData,
- LineSeries lineSeries,
- int indx
- ) {
- this.g = (Graphics2D) g2;
- this.context = context;
- this.seriesData = seriesData;
- this.lineSeries = lineSeries;
- this.indx = indx;
- }
-
- @Override
- public void draw() {
- double[] xPoints = this.seriesData.getCoordinates().get(indx).getxPoints();
- double[] yPoints = this.seriesData.getCoordinates().get(indx).getyPoints();
-
- this.g.setRenderingHint(
- RenderingHints.KEY_ANTIALIASING,
- RenderingHints.VALUE_ANTIALIAS_ON
- );
-
- int yValDiff = seriesData.getyValDiff();
- int xValDiff = seriesData.getxValDiff();
-
- int xIncrement = seriesData.getxIncrement();
- int yIncrement = seriesData.getyIncrement();
-
- int xLowerBound = seriesData.getxLowerBound();
- int yLowerBound = seriesData.getyLowerBound();
-
- int extraSpace = (int) (Math.max(xIncrement, yIncrement) * 0.25);
-
- for(int i = 0 ; i < yPoints.length - 1; i++) {
- float lineWidth = this.lineSeries.getLineWidth();
-
- Color color = this.lineSeries.getColor();
-
- if(color == null) {
- color = BaseSeriesColor.getColor(indx);
- }
-
- if(lineSeries.getMarkerColor() == null) {
- lineSeries.setMarkerColor(color);
- }
-
- this.g.setColor(color);
-
- switch (this.lineSeries.getLineStyle()) {
- case NONE:
- this.g.setStroke(new BasicStroke(lineWidth));
- break;
-
- case DASHED:
- float[] dashPattern = {6F * (int) lineWidth, 6F * (int) lineWidth};
- BasicStroke dashedStroke = new BasicStroke(
- lineWidth, BasicStroke.CAP_BUTT,
- BasicStroke.JOIN_ROUND,
- 0F,
- dashPattern,
- 0F
- );
- g.setStroke(dashedStroke);
- break;
-
- default:
- this.g.setStroke(new BasicStroke(lineWidth));
- }
-
-
- double x1 = (xIncrement * (xPoints[i] - xLowerBound)) / xValDiff;
- double x2 = (xIncrement * (xPoints[i+1] - xLowerBound)) / xValDiff;
-
- double y1 = context.getHeight() - (yIncrement * (yPoints[i] - yLowerBound)) / yValDiff;
- double y2 = context.getHeight() - (yIncrement * (yPoints[i+1] - yLowerBound)) / yValDiff;
-
- Shape l = new Line2D.Double(
- x1 + extraSpace,
- y1 - extraSpace,
- x2 + extraSpace,
- y2 - extraSpace
- );
-
- g.draw(l);
- }
-
- if(this.lineSeries.getMarker() != BaseMarker.NONE){
- int scale = lineSeries.getMarkerSize() * Constants.MIN_MARKER_SCALE;
-
- if(scale < Constants.MIN_MARKER_SCALE || scale > Constants.MAX_MARKER_SCALE) {
- scale = Constants.DEFAULT_MARKER_SCALE;
- }
-
- for(int j = 0; j < yPoints.length; j++) {
- g.setColor(lineSeries.getMarkerColor());
- int x = (int) (xIncrement * (xPoints[j] - xLowerBound)) / xValDiff - (scale/2);
- int y = context.getHeight() - (int) (yIncrement * (yPoints[j] - yLowerBound)) / yValDiff - (scale/2);
- switch (this.lineSeries.getMarker()) {
- case CIRCLE:
- this.g.fillOval(
- x + extraSpace,
- y - extraSpace,
- scale,
- scale
- );
- break;
-
- case SQUARE:
- this.g.fillRect(
- x + extraSpace,
- y - extraSpace,
- scale,
- scale
- );
- break;
-
- default:
- throw new IllegalArgumentException(
- "Unknown marker type: " + lineSeries.getMarker()
- );
- }
- }
- }
- }
-
-}
diff --git a/src/main/java/io/github/manishdait/jplotlib/chart/PieChart.java b/src/main/java/io/github/manishdait/jplotlib/chart/PieChart.java
deleted file mode 100644
index 0300029..0000000
--- a/src/main/java/io/github/manishdait/jplotlib/chart/PieChart.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * MIT License
- *
- * Copyright (c) 2023 Manish Dait
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-package io.github.manishdait.jplotlib.chart;
-
-import java.awt.Color;
-import java.util.List;
-
-import io.github.manishdait.jplotlib.data.StyleData;
-import io.github.manishdait.jplotlib.internal.util.ChartType;
-
-
-public class PieChart {
-
- private List styleDatas;
- private PieSeries pieSeries;
-
- public PieChart(List styleDatas) {
- this.styleDatas = styleDatas;
- this.pieSeries = new PieSeries();
- }
-
- public PieChart color(Color[] color) {
- this.pieSeries.setColor(color);
- return this;
- }
-
- public void build() {
- StyleData styleData = new StyleData();
- styleData.setChartType(ChartType.PIE);
- styleData.setPieSeries(this.pieSeries);
- styleDatas.clear();
- styleDatas.add(styleData);
- }
-
-}
diff --git a/src/main/java/io/github/manishdait/jplotlib/chart/PieChartBuilder.java b/src/main/java/io/github/manishdait/jplotlib/chart/PieChartBuilder.java
deleted file mode 100644
index 1c395b6..0000000
--- a/src/main/java/io/github/manishdait/jplotlib/chart/PieChartBuilder.java
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
- * MIT License
- *
- * Copyright (c) 2023 Manish Dait
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-package io.github.manishdait.jplotlib.chart;
-
-import java.awt.Color;
-import java.awt.Graphics;
-import java.awt.Graphics2D;
-import java.awt.RenderingHints;
-
-import javax.swing.JPanel;
-
-import io.github.manishdait.jplotlib.data.SeriesData;
-import io.github.manishdait.jplotlib.plotter.Plotter;
-import io.github.manishdait.jplotlib.style.color.BaseSeriesColor;
-
-
-public class PieChartBuilder implements Plotter {
-
- private Graphics2D g;
- private JPanel context;
- private SeriesData seriesData;
- private PieSeries pieSeries;
-
- public PieChartBuilder(
- Graphics g,
- JPanel context,
- SeriesData seriesData,
- PieSeries pieSeries
- ) {
- this.g = (Graphics2D) g;
- this.context = context;
- this.seriesData = seriesData;
- this.pieSeries = pieSeries;
- }
-
- @Override
- public void draw() {
- double[] data = seriesData.getPieData();
-
- this.g.setRenderingHint(
- RenderingHints.KEY_ANTIALIASING,
- RenderingHints.VALUE_ANTIALIAS_ON
- );
-
- int width = context.getWidth() / 2;
- int height = context.getHeight() / 2;
-
- double sum = 0;
- for(double i : data) {
- sum += i;
- }
-
- double diff = 360 / sum;
- int radius = Math.min(context.getHeight(), context.getWidth()) / 2 - 10;
-
- int prevAng = 0;
-
- Color[] color = pieSeries.getColor();
-
- for(int i = 0; i < data.length; i++){
- if(color == null) {
- this.g.setColor(BaseSeriesColor.getColor(i));
- } else {
- this.g.setColor(color[i]);
- }
-
- this.g.fillArc(
- width - radius,
- height - radius,
- radius * 2,
- radius * 2,
- prevAng,
- (int) (data[i] * diff)
- );
-
- prevAng += (int) (data[i] * diff);
-
- if(i == data.length - 1 && prevAng != 360){
- this.g.fillArc(
- width - radius,
- height - radius,
- radius * 2,
- radius * 2,
- prevAng,
- 360 - prevAng
- );
- }
- }
- }
-
-}
diff --git a/src/main/java/io/github/manishdait/jplotlib/chart/ScatterGraph.java b/src/main/java/io/github/manishdait/jplotlib/chart/ScatterGraph.java
deleted file mode 100644
index df72dad..0000000
--- a/src/main/java/io/github/manishdait/jplotlib/chart/ScatterGraph.java
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * MIT License
- *
- * Copyright (c) 2023 Manish Dait
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-package io.github.manishdait.jplotlib.chart;
-
-import java.awt.Color;
-import java.util.List;
-
-import io.github.manishdait.jplotlib.data.StyleData;
-import io.github.manishdait.jplotlib.internal.util.ChartType;
-import io.github.manishdait.jplotlib.style.marker.BaseMarker;
-
-public class ScatterGraph {
-
- private ScatterSeries scatterSeries;
- private List styleDatas;
-
- public ScatterGraph(List styleDatas) {
- this.scatterSeries = new ScatterSeries();
- this.styleDatas = styleDatas;
- }
-
- public ScatterGraph marker(BaseMarker marker) {
- marker = marker == null ? BaseMarker.NONE : marker;
- scatterSeries.setMarker(marker);
- return this;
- }
-
- public ScatterGraph size(int[] size) {
- scatterSeries.setScale(size);
- return this;
- }
-
- public ScatterGraph color(Color color) {
- scatterSeries.setColor(color);
- return this;
- }
-
- public ScatterGraph alpha(float alpha) {
- scatterSeries.setAlpha(alpha);
- return this;
- }
-
- public ScatterSeries getMeta() {
- return this.scatterSeries;
- }
-
- public void build() {
- StyleData styleData = new StyleData();
- styleData.setChartType(ChartType.SCATTER);
- styleData.setScatterSeries(scatterSeries);;
- this.styleDatas.add(styleData);
- }
-
-}
diff --git a/src/main/java/io/github/manishdait/jplotlib/chart/ScatterGraphBuilder.java b/src/main/java/io/github/manishdait/jplotlib/chart/ScatterGraphBuilder.java
deleted file mode 100644
index 2e1ab43..0000000
--- a/src/main/java/io/github/manishdait/jplotlib/chart/ScatterGraphBuilder.java
+++ /dev/null
@@ -1,145 +0,0 @@
-/*
- * MIT License
- *
- * Copyright (c) 2023 Manish Dait
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-package io.github.manishdait.jplotlib.chart;
-
-import java.awt.Color;
-import java.awt.Graphics;
-import java.awt.Graphics2D;
-import java.awt.RenderingHints;
-
-import javax.swing.JPanel;
-
-import io.github.manishdait.jplotlib.data.SeriesData;
-import io.github.manishdait.jplotlib.plotter.Plotter;
-import io.github.manishdait.jplotlib.style.color.BaseSeriesColor;
-
-
-public class ScatterGraphBuilder implements Plotter {
-
- private Graphics2D g;
- private JPanel context;
- private SeriesData seriesData;
- private ScatterSeries scatterSeries;
- private int indx;
-
- public ScatterGraphBuilder(
- Graphics g,
- JPanel context,
- SeriesData seriesData,
- ScatterSeries scatterSeries,
- int indx
- ) {
- this.g = (Graphics2D) g;
- this.context = context;
- this.seriesData = seriesData;
- this.scatterSeries = scatterSeries;
- this.indx = indx;
- }
-
- @Override
- public void draw() {
- double[] xPoints = this.seriesData.getCoordinates().get(indx).getxPoints();
- double[] yPoints = this.seriesData.getCoordinates().get(indx).getyPoints();
-
- this.g.setRenderingHint(
- RenderingHints.KEY_ANTIALIASING,
- RenderingHints.VALUE_ANTIALIAS_ON
- );
-
- int yValDiff = seriesData.getyValDiff();
- int xValDiff = seriesData.getxValDiff();
-
- int xIncrement = seriesData.getxIncrement();
- int yIncrement = seriesData.getyIncrement();
-
- int xLowerBound = seriesData.getxLowerBound();
- int yLowerBound = seriesData.getyLowerBound();
-
- int extraSpace = (int) (Math.max(xIncrement, yIncrement) * 0.25);
-
- Color color = this.scatterSeries.getColor();
-
- if(color == null) {
- color = BaseSeriesColor.getColor(indx);
- }
-
- color = setAlpa(color);
-
- this.g.setColor(color);
-
-
- for(int i = 0; i < yPoints.length; i++) {
- int scale = scatterSeries.getScale() == null
- ? 10 : scatterSeries.getScale()[i] * 5;
-
- if(scale < 5 || scale > 50) {
- scale = 10;
- }
-
- int x = (int) (xIncrement * (xPoints[i] - xLowerBound)) / xValDiff - scale/2;
- int y = context.getHeight() - (int) (yIncrement * (yPoints[i] - yLowerBound)) / yValDiff - scale/2;
- switch (scatterSeries.getMarker()) {
- case NONE:
- case CIRCLE:
- this.g.fillOval(
- x + extraSpace,
- y - extraSpace,
- scale,
- scale
- );
- break;
-
- case SQUARE:
- this.g.fillRect(
- x + extraSpace,
- y - extraSpace,
- scale,
- scale
- );
- break;
-
- default:
- System.out.println("Error");
- }
-
- }
- }
-
- private Color setAlpa(Color color) {
- Color currColor = color;
- float alpha = scatterSeries.getAlpha();
- if(alpha < 0 || alpha > 1) {
- alpha = 1;
- }
- Color changeColor = new Color(
- currColor.getRed(),
- currColor.getGreen(),
- currColor.getBlue(),
- (int) (alpha * 255)
- );
- return changeColor;
- }
-
-}
diff --git a/src/main/java/io/github/manishdait/jplotlib/chart/helper/LineGraphOptions.java b/src/main/java/io/github/manishdait/jplotlib/chart/helper/LineGraphOptions.java
deleted file mode 100644
index 70b5df5..0000000
--- a/src/main/java/io/github/manishdait/jplotlib/chart/helper/LineGraphOptions.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * MIT License
- *
- * Copyright (c) 2023 Manish Dait
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-package io.github.manishdait.jplotlib.chart.helper;
-
-import io.github.manishdait.jplotlib.chart.LineGraph;
-
-public interface LineGraphOptions {
-
- public LineGraph plot(double[] xPoints, double[] yPoints);
- public LineGraph plot(double[] yPoints);
-
-}
diff --git a/src/main/java/io/github/manishdait/jplotlib/chart/helper/PieChartOptions.java b/src/main/java/io/github/manishdait/jplotlib/chart/helper/PieChartOptions.java
deleted file mode 100644
index 99f41b0..0000000
--- a/src/main/java/io/github/manishdait/jplotlib/chart/helper/PieChartOptions.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * MIT License
- *
- * Copyright (c) 2023 Manish Dait
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-package io.github.manishdait.jplotlib.chart.helper;
-
-import io.github.manishdait.jplotlib.chart.PieChart;
-
-public interface PieChartOptions {
-
- public PieChart pie(double[] dataPoints);
-
-}
diff --git a/src/main/java/io/github/manishdait/jplotlib/chart/helper/ScatterGraphOptions.java b/src/main/java/io/github/manishdait/jplotlib/chart/helper/ScatterGraphOptions.java
deleted file mode 100644
index b1403aa..0000000
--- a/src/main/java/io/github/manishdait/jplotlib/chart/helper/ScatterGraphOptions.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * MIT License
- *
- * Copyright (c) 2023 Manish Dait
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-package io.github.manishdait.jplotlib.chart.helper;
-
-import io.github.manishdait.jplotlib.chart.ScatterGraph;
-
-public interface ScatterGraphOptions {
-
- public ScatterGraph scatter(double[] xPoints, double[] yPoints);
-
-}
diff --git a/src/main/java/io/github/manishdait/jplotlib/charts/bar/BarGraph.java b/src/main/java/io/github/manishdait/jplotlib/charts/bar/BarGraph.java
new file mode 100755
index 0000000..42f0651
--- /dev/null
+++ b/src/main/java/io/github/manishdait/jplotlib/charts/bar/BarGraph.java
@@ -0,0 +1,84 @@
+/*
+ * MIT License
+ *
+ * Copyright (c) 2023 Manish Dait
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+package io.github.manishdait.jplotlib.charts.bar;
+
+import java.awt.Color;
+
+import io.github.manishdait.jplotlib.charts.helper.Graph;
+import io.github.manishdait.jplotlib.data.util.Data;
+import io.github.manishdait.jplotlib.internals.util.ChartType;
+
+/**
+ * The BarGraph class represents a bar graph configuration containing data
+ * values and style settings
+ * for rendering a bar chart within the JPlotLib library.
+ * It implements the Graph interface and provides methods to access and modify
+ * bar graph properties.
+ *
+ */
+public class BarGraph implements Graph {
+
+ private Data values;
+ private BarGraphStyle style;
+ private static final ChartType CHART_TYPE = ChartType.BAR;
+
+ /**
+ * Constructs a BarGraph object with the provided data values and default style
+ * settings.
+ *
+ * @param values
+ * The Data object containing values for the bar graph.
+ */
+ public BarGraph(Data values) {
+ this.values = values;
+ this.style = new BarGraphStyle();
+ }
+
+ public Data getValues() {
+ return values;
+ }
+
+ public void setValues(Data values) {
+ this.values = values;
+ }
+
+ public BarGraphStyle getStyle() {
+ return style;
+ }
+
+ public void setStyle(BarGraphStyle style) {
+ this.style = style;
+ }
+
+ public ChartType getChartType() {
+ return CHART_TYPE;
+ }
+
+ public BarGraph color(Color color) {
+ style.setColor(color);
+ return this;
+ }
+
+}
diff --git a/src/main/java/io/github/manishdait/jplotlib/charts/bar/BarGraphOptions.java b/src/main/java/io/github/manishdait/jplotlib/charts/bar/BarGraphOptions.java
new file mode 100755
index 0000000..18274cf
--- /dev/null
+++ b/src/main/java/io/github/manishdait/jplotlib/charts/bar/BarGraphOptions.java
@@ -0,0 +1,56 @@
+/*
+ * MIT License
+ *
+ * Copyright (c) 2023 Manish Dait
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+package io.github.manishdait.jplotlib.charts.bar;
+
+/**
+ * The BarGraphOptions interface provides methods for creating vertical (bar)
+ * and horizontal (barh) bar graphs
+ * within the JPlotLib library.
+ *
+ */
+public interface BarGraphOptions {
+ /**
+ * Create a vertical bar graph.
+ *
+ * @param labels
+ * Array of labels or categories for the bars.
+ * @param points
+ * Array of numerical data points corresponding to the labels.
+ * @return BarGraph representing the vertical bar graph.
+ */
+ BarGraph bar(String[] labels, double[] points);
+
+ /**
+ * Create a horizontal bar graph.
+ *
+ * @param labels
+ * Array of labels or categories for the bars.
+ * @param points
+ * Array of numerical data points corresponding to the labels.
+ * @return BarGraph representing the horizontal bar graph.
+ */
+ BarGraph barh(String[] labels, double[] points);
+
+}
diff --git a/src/main/java/io/github/manishdait/jplotlib/charts/bar/BarGraphPlotter.java b/src/main/java/io/github/manishdait/jplotlib/charts/bar/BarGraphPlotter.java
new file mode 100755
index 0000000..a3b14b7
--- /dev/null
+++ b/src/main/java/io/github/manishdait/jplotlib/charts/bar/BarGraphPlotter.java
@@ -0,0 +1,149 @@
+/*
+ * MIT License
+ *
+ * Copyright (c) 2023 Manish Dait
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+package io.github.manishdait.jplotlib.charts.bar;
+
+import java.awt.Color;
+import java.awt.Graphics;
+import java.awt.Graphics2D;
+import java.awt.RenderingHints;
+
+import javax.swing.JPanel;
+
+import io.github.manishdait.jplotlib.charts.helper.Plotter;
+import io.github.manishdait.jplotlib.data.GraphData;
+import io.github.manishdait.jplotlib.defaults.color.PlotColor;
+import io.github.manishdait.jplotlib.internals.components.axis.Config;
+
+/**
+ * The BarGraphPlotter class implements the Plotter interface and is responsible
+ * for rendering
+ * BarGraph objects by drawing bars on a JPanel based on the provided axis
+ * configuration and data.
+ * It handles the visualization of vertical and horizontal bar graphs within the
+ * JPlotLib library.
+ *
+ */
+public class BarGraphPlotter implements Plotter {
+
+ private Graphics2D g;
+ private JPanel context;
+ private Config axisConfiguration;
+ private BarGraph barGraph;
+ private int indx;
+
+ /**
+ * Constructs a BarGraphPlotter with necessary rendering context, axis
+ * configuration,
+ * BarGraph data, and an index for styling.
+ *
+ * @param g
+ * The Graphics object used for rendering.
+ * @param context
+ * The JPanel where the bars will be drawn.
+ * @param axisConfiguration
+ * The configuration for rendering the axis.
+ * @param barGraph
+ * The BarGraph object containing data and style settings.
+ * @param indx
+ * The index used for styling multiple bars.
+ */
+ public BarGraphPlotter(
+ Graphics g,
+ JPanel context,
+ Config axisConfiguration,
+ BarGraph barGraph,
+ int indx) {
+ this.g = (Graphics2D) g;
+ this.context = context;
+ this.axisConfiguration = axisConfiguration;
+ this.barGraph = barGraph;
+ this.indx = indx;
+ }
+
+ @Override
+ public void draw() {
+ double[] datas = ((GraphData) this.barGraph.getValues()).getData();
+ String[] labels = ((GraphData) this.barGraph.getValues()).getLabels();
+
+ this.g.setRenderingHint(
+ RenderingHints.KEY_ANTIALIASING,
+ RenderingHints.VALUE_ANTIALIAS_ON);
+
+ Color color = barGraph.getStyle().getColor();
+ if (color == null) {
+ color = PlotColor.getColor(indx);
+ }
+
+ this.g.setColor(color);
+
+ if (!GraphData.isX()) {
+ int yLowerBound = axisConfiguration.getyLowerBound();
+
+ int xIncrement = axisConfiguration.getxIncrement();
+ int xValDiff = context.getWidth() / (axisConfiguration.getBarLabelLen() * 2);
+
+ int yIncrement = axisConfiguration.getyIncrement();
+ int yValDiff = axisConfiguration.getyValDiff();
+
+ int extraSpace = (int) (Math.min(xIncrement, yIncrement) * 0.5);
+
+ for (int i = 0; i < datas.length; i++) {
+ int x = ((xIncrement * (GraphData.getMap().get(labels[i]) * 2 + 1)) - (xValDiff / 2));
+ int y = context.getHeight() - ((int) (yIncrement * (datas[i] - yLowerBound)) / yValDiff);
+ int h = (int) (yIncrement * (datas[i] - yLowerBound)) / yValDiff;
+
+ this.g.fillRect(
+ x,
+ y - extraSpace,
+ xValDiff,
+ h + extraSpace);
+ }
+ } else {
+ int xLowerBound = axisConfiguration.getxLowerBound();
+
+ int yIncrement = axisConfiguration.getyIncrement();
+ int yValDiff = context.getHeight() / (axisConfiguration.getBarLabelLen() * 2);
+
+ int xIncrement = axisConfiguration.getxIncrement();
+ int xValDiff = axisConfiguration.getxValDiff();
+
+ int extraSpace = (int) (Math.min(xIncrement, yIncrement) * 0.5);
+
+ for (int i = 0; i < datas.length; i++) {
+ int y = context.getHeight() - (yIncrement * (GraphData.getMap().get(labels[i]) * 2 + 1))
+ - (yValDiff / 2);
+ int x = 1;
+ int w = (int) (xIncrement * (datas[i] - xLowerBound)) / xValDiff;
+ this.g.fillRect(
+ x,
+ y,
+ w + extraSpace,
+ yValDiff);
+ }
+ }
+
+ }
+
+}
diff --git a/src/main/java/io/github/manishdait/jplotlib/charts/bar/BarGraphStyle.java b/src/main/java/io/github/manishdait/jplotlib/charts/bar/BarGraphStyle.java
new file mode 100755
index 0000000..5cf6443
--- /dev/null
+++ b/src/main/java/io/github/manishdait/jplotlib/charts/bar/BarGraphStyle.java
@@ -0,0 +1,55 @@
+/*
+ * MIT License
+ *
+ * Copyright (c) 2023 Manish Dait
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+package io.github.manishdait.jplotlib.charts.bar;
+
+import java.awt.Color;
+
+/**
+ * The BarGraphStyle class encapsulates style properties specific to a bar
+ * graph,
+ * allowing customization of visual attributes for rendering bars within the
+ * JPlotLib library.
+ *
+ */
+class BarGraphStyle {
+
+ private Color color;
+
+ /**
+ * Constructs a BarGraphStyle with default style settings.
+ */
+ public BarGraphStyle() {
+ this.color = null;
+ }
+
+ public Color getColor() {
+ return color;
+ }
+
+ public void setColor(Color color) {
+ this.color = color;
+ }
+
+}
diff --git a/src/main/java/io/github/manishdait/jplotlib/chart/BarSeries.java b/src/main/java/io/github/manishdait/jplotlib/charts/helper/Graph.java
old mode 100644
new mode 100755
similarity index 75%
rename from src/main/java/io/github/manishdait/jplotlib/chart/BarSeries.java
rename to src/main/java/io/github/manishdait/jplotlib/charts/helper/Graph.java
index 72d61a7..acfda91
--- a/src/main/java/io/github/manishdait/jplotlib/chart/BarSeries.java
+++ b/src/main/java/io/github/manishdait/jplotlib/charts/helper/Graph.java
@@ -22,22 +22,14 @@
* SOFTWARE.
*/
-package io.github.manishdait.jplotlib.chart;
-
-import java.awt.Color;
-
-public class BarSeries {
-
- private Color color;
-
- public BarSeries() {}
-
- public Color getColor() {
- return color;
- }
-
- public void setColor(Color color) {
- this.color = color;
- }
+package io.github.manishdait.jplotlib.charts.helper;
+/**
+ * The Graph interface defines the contract for different types of graphs in
+ * JPlotLib charts. Implementing classes are expected to represent various types
+ * of graphs like bar graphs, line graphs, etc.
+ * This interface serves as a base for different graph implementations.
+ *
+ */
+public interface Graph {
}
diff --git a/src/main/java/io/github/manishdait/jplotlib/charts/helper/GraphPlotter.java b/src/main/java/io/github/manishdait/jplotlib/charts/helper/GraphPlotter.java
new file mode 100755
index 0000000..a0f6e80
--- /dev/null
+++ b/src/main/java/io/github/manishdait/jplotlib/charts/helper/GraphPlotter.java
@@ -0,0 +1,88 @@
+/*
+ * MIT License
+ *
+ * Copyright (c) 2023 Manish Dait
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+package io.github.manishdait.jplotlib.charts.helper;
+
+import java.awt.Graphics;
+import java.util.List;
+
+import javax.swing.JPanel;
+
+import io.github.manishdait.jplotlib.charts.bar.BarGraph;
+import io.github.manishdait.jplotlib.charts.bar.BarGraphPlotter;
+import io.github.manishdait.jplotlib.charts.line.LineChart;
+import io.github.manishdait.jplotlib.charts.line.LineChartPlotter;
+import io.github.manishdait.jplotlib.charts.pie.PieChart;
+import io.github.manishdait.jplotlib.charts.pie.PieChartPlotter;
+import io.github.manishdait.jplotlib.charts.scatter.ScatterChart;
+import io.github.manishdait.jplotlib.charts.scatter.ScatterChartPlotter;
+import io.github.manishdait.jplotlib.internals.components.axis.Config;
+import io.github.manishdait.jplotlib.internals.util.AxisType;
+
+/**
+ * The GraphPlotter class is responsible for drawing plots based on the
+ * provided AxisConfiguration and List of Graphs.
+ *
+ */
+public class GraphPlotter extends JPanel {
+
+ private transient Config axisConfiguration;
+ private transient List graphs;
+
+ /**
+ * Creates a new GraphPlotter with the given AxisConfiguration and List of
+ * Graphs.
+ *
+ * @param axisConfiguration
+ * the Configuration for rendering axis.
+ * @param graphs
+ * The style data of the graphs.
+ */
+ public GraphPlotter(Config axisConfiguration, List graphs) {
+ this.axisConfiguration = axisConfiguration;
+ this.graphs = graphs;
+ }
+
+ @Override
+ public void paintComponent(Graphics g) {
+ for (int i = 0; i < graphs.size(); i++) {
+ if (axisConfiguration.getAxisType() == AxisType.PIE && graphs.get(i) instanceof PieChart) {
+ new PieChartPlotter(g, this, (PieChart) graphs.get(i)).draw();
+ } else if (axisConfiguration.getAxisType() != AxisType.PIE) {
+ if (graphs.get(i) instanceof LineChart) {
+ new LineChartPlotter(g, this, axisConfiguration, (LineChart) graphs.get(i), i).draw();
+ }
+
+ else if (graphs.get(i) instanceof ScatterChart) {
+ new ScatterChartPlotter(g, this, axisConfiguration, (ScatterChart) graphs.get(i), i).draw();
+ }
+
+ else if (graphs.get(i) instanceof BarGraph) {
+ new BarGraphPlotter(g, this, axisConfiguration, (BarGraph) graphs.get(i), i).draw();
+ }
+ }
+ }
+ }
+
+}
diff --git a/src/main/java/io/github/manishdait/jplotlib/charts/helper/PlotLogger.java b/src/main/java/io/github/manishdait/jplotlib/charts/helper/PlotLogger.java
new file mode 100644
index 0000000..06fecdf
--- /dev/null
+++ b/src/main/java/io/github/manishdait/jplotlib/charts/helper/PlotLogger.java
@@ -0,0 +1,50 @@
+/*
+ * MIT License
+ *
+ * Copyright (c) 2023 Manish Dait
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+package io.github.manishdait.jplotlib.charts.helper;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * The PlotLogger class provides a centralized logger instance for use across
+ * plotting-related functionalities within the JPlotLib library.
+ *
+ */
+public class PlotLogger {
+
+ private PlotLogger() {
+ }
+
+ private static Logger logger = LoggerFactory.getLogger(PlotLogger.class);
+
+ public static Logger getLogger() {
+ return logger;
+ }
+
+ public static void setLogger(Logger logger) {
+ PlotLogger.logger = logger;
+ }
+
+}
diff --git a/src/main/java/io/github/manishdait/jplotlib/plotter/Plotter.java b/src/main/java/io/github/manishdait/jplotlib/charts/helper/Plotter.java
old mode 100644
new mode 100755
similarity index 89%
rename from src/main/java/io/github/manishdait/jplotlib/plotter/Plotter.java
rename to src/main/java/io/github/manishdait/jplotlib/charts/helper/Plotter.java
index d2d1a24..6a9c91f
--- a/src/main/java/io/github/manishdait/jplotlib/plotter/Plotter.java
+++ b/src/main/java/io/github/manishdait/jplotlib/charts/helper/Plotter.java
@@ -22,7 +22,7 @@
* SOFTWARE.
*/
-package io.github.manishdait.jplotlib.plotter;
+package io.github.manishdait.jplotlib.charts.helper;
/**
* The Plotter interface provides a contract for classes that are responsible
@@ -30,15 +30,12 @@
*
* Classes that implement the Plotter interface must provide the 'draw()' method
* to draw the plot on the specified context (e.g., JPanel or Graphics).
- *
*
*/
-
public interface Plotter {
-
- /**
- * Draws the plot on the specified context (e.g., JPanel or Graphics).
- */
- void draw();
+ /**
+ * Draws the plot on the specified context (e.g., JPanel or Graphics).
+ */
+ void draw();
-}
+}
\ No newline at end of file
diff --git a/src/main/java/io/github/manishdait/jplotlib/charts/line/LineChart.java b/src/main/java/io/github/manishdait/jplotlib/charts/line/LineChart.java
new file mode 100755
index 0000000..0e74d06
--- /dev/null
+++ b/src/main/java/io/github/manishdait/jplotlib/charts/line/LineChart.java
@@ -0,0 +1,115 @@
+/*
+ * MIT License
+ *
+ * Copyright (c) 2023 Manish Dait
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+package io.github.manishdait.jplotlib.charts.line;
+
+import java.awt.Color;
+
+import io.github.manishdait.jplotlib.charts.helper.Graph;
+import io.github.manishdait.jplotlib.data.util.Data;
+import io.github.manishdait.jplotlib.defaults.line.Stroke;
+import io.github.manishdait.jplotlib.defaults.marker.Marker;
+import io.github.manishdait.jplotlib.internals.util.ChartType;
+
+/**
+ * The LineChart class implements the Graph interface and represents a line
+ * chart.
+ * It allows plotting data using lines with customizable styles such as markers,
+ * colors, line styles, etc.
+ *
+ */
+public class LineChart implements Graph {
+
+ private Data coordinates;
+ private LineChartStyle style;
+ private static final ChartType CHART_TYPE = ChartType.LINE;
+
+ protected LineChart() {
+ }
+
+ /**
+ * Constructs a LineChart with the provided data coordinates and initializes
+ * default style settings.
+ *
+ * @param coordinates
+ * The data coordinates to be plotted on the line chart.
+ */
+ public LineChart(Data coordinates) {
+ this.coordinates = coordinates;
+ style = new LineChartStyle();
+ }
+
+ public Data getCoordinates() {
+ return coordinates;
+ }
+
+ public void setCoordinates(Data coordinates) {
+ this.coordinates = coordinates;
+ }
+
+ public LineChartStyle getStyle() {
+ return style;
+ }
+
+ public void setStyle(LineChartStyle style) {
+ this.style = style;
+ }
+
+ public ChartType getChartType() {
+ return CHART_TYPE;
+ }
+
+ public LineChart marker(Marker marker) {
+ style.setMarker(marker);
+ return this;
+ }
+
+ public LineChart color(Color color) {
+ style.setColor(color);
+ return this;
+ }
+
+ public LineChart markerColor(Color color) {
+ style.setMarkerColor(color);
+ return this;
+ }
+
+ public LineChart lineStyle(Stroke stroke) {
+ style.setLineStyle(stroke == null ? Stroke.NONE : stroke);
+ return this;
+ }
+
+ public LineChart lineWidth(float width) {
+ width = width < 1 ? 1 : width;
+ width = width > 15 ? 15 : width;
+ style.setLineWidth(width);
+ return this;
+ }
+
+ public LineChart markerSize(int size) {
+ style.setMarkerSize(size);
+ return this;
+ }
+
+}
diff --git a/src/main/java/io/github/manishdait/jplotlib/chart/ScatterSeries.java b/src/main/java/io/github/manishdait/jplotlib/charts/line/LineChartOptions.java
old mode 100644
new mode 100755
similarity index 56%
rename from src/main/java/io/github/manishdait/jplotlib/chart/ScatterSeries.java
rename to src/main/java/io/github/manishdait/jplotlib/charts/line/LineChartOptions.java
index 8bec8c7..b96fb44
--- a/src/main/java/io/github/manishdait/jplotlib/chart/ScatterSeries.java
+++ b/src/main/java/io/github/manishdait/jplotlib/charts/line/LineChartOptions.java
@@ -22,54 +22,34 @@
* SOFTWARE.
*/
-package io.github.manishdait.jplotlib.chart;
-
-import java.awt.Color;
-
-import io.github.manishdait.jplotlib.style.marker.BaseMarker;
-
+package io.github.manishdait.jplotlib.charts.line;
/**
- * The ScatterSeries class represents the style and properties of a scatter plot
- * series in a chart.
+ * The LineChartOptions interface defines methods for configuring and plotting
+ * line charts.
+ * Implementing classes can provide various options for plotting line charts
+ * based on data points.
*
*/
+public interface LineChartOptions {
+ /**
+ * Plots a line chart using provided x and y data points.
+ *
+ * @param xPoints
+ * The array of x-axis data points.
+ * @param yPoints
+ * The array of y-axis data points.
+ * @return The LineChart object representing the plotted line chart.
+ */
+ LineChart plot(double[] xPoints, double[] yPoints);
+
+ /**
+ * Plots a line chart using only y-axis data points.
+ *
+ * @param yPoints
+ * The array of y-axis data points.
+ * @return The LineChart object representing the plotted line chart.
+ */
+ LineChart plot(double[] yPoints);
-public class ScatterSeries {
-
- private Color color;
- private int[] scale;
- private BaseMarker marker = BaseMarker.NONE;
- private float alpha = 1F;
-
- public ScatterSeries() {}
-
- public Color getColor() {
- return color;
- }
- public void setColor(Color color) {
- this.color = color;
- }
-
- public float getAlpha() {
- return alpha;
- }
- public void setAlpha(float alpha) {
- this.alpha = alpha;
- }
-
- public BaseMarker getMarker() {
- return marker;
- }
- public void setMarker(BaseMarker marker) {
- this.marker = marker;
- }
-
- public int[] getScale() {
- return scale;
- }
- public void setScale(int[] scale) {
- this.scale = scale;
- }
-
}
diff --git a/src/main/java/io/github/manishdait/jplotlib/charts/line/LineChartPlotter.java b/src/main/java/io/github/manishdait/jplotlib/charts/line/LineChartPlotter.java
new file mode 100755
index 0000000..d9527b3
--- /dev/null
+++ b/src/main/java/io/github/manishdait/jplotlib/charts/line/LineChartPlotter.java
@@ -0,0 +1,206 @@
+/*
+ * MIT License
+ *
+ * Copyright (c) 2023 Manish Dait
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+package io.github.manishdait.jplotlib.charts.line;
+
+import java.awt.BasicStroke;
+import java.awt.Color;
+import java.awt.Graphics;
+import java.awt.Graphics2D;
+import java.awt.RenderingHints;
+import java.awt.Shape;
+import java.awt.geom.Line2D;
+
+import javax.swing.JPanel;
+
+import io.github.manishdait.jplotlib.charts.helper.Plotter;
+import io.github.manishdait.jplotlib.data.CartesianData;
+import io.github.manishdait.jplotlib.defaults.color.PlotColor;
+import io.github.manishdait.jplotlib.defaults.marker.Marker;
+import io.github.manishdait.jplotlib.internals.components.axis.Config;
+import io.github.manishdait.jplotlib.internals.util.Constants;
+
+/**
+ * The LineChartPlotter class implements the Plotter interface and is
+ * responsible for drawing a line chart.
+ * It uses provided data coordinates and style settings to render a line chart
+ * on the specified context.
+ *
+ */
+public class LineChartPlotter implements Plotter {
+ private Graphics2D g;
+ private LineChart lineChart;
+ private int indx;
+
+ private int yValDiff;
+ private int xValDiff;
+
+ private int xIncrement;
+ private int yIncrement;
+
+ private int xLowerBound;
+ private int yLowerBound;
+ private double[] xPoints;
+ private double[] yPoints;
+
+ private int heigth;
+
+ /**
+ * Constructs a LineChartPlotter with the necessary information to draw a line
+ * chart.
+ *
+ * @param g2
+ * The Graphics object to draw on.
+ * @param context
+ * The JPanel context where the chart is drawn.
+ * @param axisConfiguration
+ * The axis configuration for the chart.
+ * @param lineChart
+ * The LineChart object containing data and style
+ * settings.
+ * @param indx
+ * The index used for styling or identifying the chart.
+ */
+ public LineChartPlotter(
+ Graphics g2,
+ JPanel context,
+ Config axisConfiguration,
+ LineChart lineChart,
+ int indx) {
+ this.g = (Graphics2D) g2;
+ this.lineChart = lineChart;
+ this.indx = indx;
+
+ this.heigth = context.getHeight();
+
+ this.yValDiff = axisConfiguration.getyValDiff();
+ this.xValDiff = axisConfiguration.getxValDiff();
+
+ this.xIncrement = axisConfiguration.getxIncrement();
+ this.yIncrement = axisConfiguration.getyIncrement();
+
+ this.xLowerBound = axisConfiguration.getxLowerBound();
+ this.yLowerBound = axisConfiguration.getyLowerBound();
+ }
+
+ @Override
+ public void draw() {
+ xPoints = ((CartesianData) this.lineChart.getCoordinates()).getxPoints();
+ yPoints = ((CartesianData) this.lineChart.getCoordinates()).getyPoints();
+
+ this.g.setRenderingHint(
+ RenderingHints.KEY_ANTIALIASING,
+ RenderingHints.VALUE_ANTIALIAS_ON);
+
+ int extraSpace = (int) (Math.min(xIncrement, yIncrement) * 0.5);
+
+ for (int i = 0; i < yPoints.length - 1; i++) {
+ float lineWidth = this.lineChart.getStyle().getLineWidth();
+
+ Color color = this.lineChart.getStyle().getColor();
+
+ if (color == null) {
+ color = PlotColor.getColor(indx);
+ }
+
+ if (this.lineChart.getStyle().getMarkerColor() == null) {
+ this.lineChart.getStyle().setMarkerColor(color);
+ }
+
+ this.g.setColor(color);
+
+ switch (this.lineChart.getStyle().getLineStyle()) {
+ case NONE:
+ this.g.setStroke(new BasicStroke(lineWidth));
+ break;
+
+ case DASHED:
+ float[] dashPattern = { 6F * (int) lineWidth, 6F * (int) lineWidth };
+ BasicStroke dashedStroke = new BasicStroke(
+ lineWidth, BasicStroke.CAP_BUTT,
+ BasicStroke.JOIN_ROUND,
+ 0F,
+ dashPattern,
+ 0F);
+ g.setStroke(dashedStroke);
+ break;
+
+ default:
+ this.g.setStroke(new BasicStroke(lineWidth));
+ }
+
+ double x1 = (xIncrement * (xPoints[i] - xLowerBound)) / xValDiff;
+ double x2 = (xIncrement * (xPoints[i + 1] - xLowerBound)) / xValDiff;
+
+ double y1 = heigth - (yIncrement * (yPoints[i] - yLowerBound)) / yValDiff;
+ double y2 = heigth - (yIncrement * (yPoints[i + 1] - yLowerBound)) / yValDiff;
+
+ Shape l = new Line2D.Double(
+ x1 + extraSpace,
+ y1 - extraSpace,
+ x2 + extraSpace,
+ y2 - extraSpace);
+
+ g.draw(l);
+ }
+
+ if (this.lineChart.getStyle().getMarker() != Marker.NONE) {
+ drawMarker(extraSpace);
+ }
+ }
+
+ private void drawMarker(int extraSpace) {
+ int scale = this.lineChart.getStyle().getMarkerSize() * Constants.MIN_MARKER_SCALE;
+
+ if (scale < Constants.MIN_MARKER_SCALE || scale > Constants.MAX_MARKER_SCALE) {
+ scale = Constants.DEFAULT_MARKER_SCALE;
+ }
+
+ for (int j = 0; j < yPoints.length; j++) {
+ g.setColor(this.lineChart.getStyle().getMarkerColor());
+ int x = (int) (xIncrement * (xPoints[j] - xLowerBound)) / xValDiff - (scale / 2);
+ int y = heigth - (int) (yIncrement * (yPoints[j] - yLowerBound)) / yValDiff - (scale / 2);
+ switch (this.lineChart.getStyle().getMarker()) {
+ case CIRCLE:
+ this.g.fillOval(
+ x + extraSpace,
+ y - extraSpace,
+ scale,
+ scale);
+ break;
+
+ case SQUARE:
+ this.g.fillRect(
+ x + extraSpace,
+ y - extraSpace,
+ scale,
+ scale);
+ break;
+
+ default:
+ throw new IllegalArgumentException("Unknown marker type: " + this.lineChart.getStyle().getMarker());
+ }
+ }
+ }
+}
diff --git a/src/main/java/io/github/manishdait/jplotlib/chart/LineSeries.java b/src/main/java/io/github/manishdait/jplotlib/charts/line/LineChartStyle.java
old mode 100644
new mode 100755
similarity index 56%
rename from src/main/java/io/github/manishdait/jplotlib/chart/LineSeries.java
rename to src/main/java/io/github/manishdait/jplotlib/charts/line/LineChartStyle.java
index 20aedc3..6cb246e
--- a/src/main/java/io/github/manishdait/jplotlib/chart/LineSeries.java
+++ b/src/main/java/io/github/manishdait/jplotlib/charts/line/LineChartStyle.java
@@ -21,66 +21,87 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
-
-package io.github.manishdait.jplotlib.chart;
-import java.awt.Color;
+package io.github.manishdait.jplotlib.charts.line;
-import io.github.manishdait.jplotlib.style.line.BaseStroke;
-import io.github.manishdait.jplotlib.style.marker.BaseMarker;
+import java.awt.Color;
+import io.github.manishdait.jplotlib.defaults.line.Stroke;
+import io.github.manishdait.jplotlib.defaults.marker.Marker;
-public class LineSeries {
+/**
+ * The LineChartStyle class holds style properties for configuring the
+ * appearance of a line chart.
+ * It includes settings for markers, colors, line styles, and widths.
+ *
+ */
+class LineChartStyle {
- private BaseMarker marker = BaseMarker.NONE;
+ private Marker marker;
private Color color;
private Color markerColor;
private int markerSize;
- private BaseStroke lineStyle = BaseStroke.NONE;
- private float lineWidth = 2F;
-
- public LineSeries() {}
-
- public BaseMarker getMarker() {
- return marker;
+ private Stroke lineStyle;
+ private float lineWidth;
+
+ /**
+ * Constructs a LineChartStyle with default style settings.
+ */
+ public LineChartStyle() {
+ this.marker = Marker.NONE;
+ color = null;
+ markerColor = null;
+ lineStyle = Stroke.NONE;
+ lineWidth = 2F;
+ this.markerSize = 0;
+ }
+
+ public Marker getMarker() {
+ return marker;
}
- public void setMarker(BaseMarker marker) {
- this.marker = marker;
+
+ public void setMarker(Marker marker) {
+ this.marker = marker;
}
-
+
public Color getColor() {
- return color;
+ return color;
}
+
public void setColor(Color color) {
- this.color = color;
- }
-
- public BaseStroke getLineStyle() {
- return lineStyle;
+ this.color = color;
}
- public void setLineStyle(BaseStroke lineStyle) {
- this.lineStyle = lineStyle;
- }
-
+
public Color getMarkerColor() {
- return markerColor;
+ return markerColor;
}
+
public void setMarkerColor(Color markerColor) {
- this.markerColor = markerColor;
+ this.markerColor = markerColor;
}
- public float getLineWidth() {
- return lineWidth;
+ public int getMarkerSize() {
+ return markerSize;
}
- public void setLineWidth(float lineWidth) {
- this.lineWidth = lineWidth;
+
+ public void setMarkerSize(int markerSize) {
+ this.markerSize = markerSize;
}
- public int getMarkerSize() {
- return markerSize;
+ public Stroke getLineStyle() {
+ return lineStyle;
}
- public void setMarkerSize(int markerSize) {
- this.markerSize = markerSize;
+
+ public void setLineStyle(Stroke lineStyle) {
+ this.lineStyle = lineStyle;
+ }
+
+ public float getLineWidth() {
+ return lineWidth;
}
+ public void setLineWidth(float lineWidth) {
+ this.lineWidth = lineWidth;
+ }
+
}
diff --git a/src/main/java/io/github/manishdait/jplotlib/charts/pie/PieChart.java b/src/main/java/io/github/manishdait/jplotlib/charts/pie/PieChart.java
new file mode 100755
index 0000000..e8e96af
--- /dev/null
+++ b/src/main/java/io/github/manishdait/jplotlib/charts/pie/PieChart.java
@@ -0,0 +1,84 @@
+/*
+ * MIT License
+ *
+ * Copyright (c) 2023 Manish Dait
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+package io.github.manishdait.jplotlib.charts.pie;
+
+import java.awt.Color;
+
+import io.github.manishdait.jplotlib.charts.helper.Graph;
+import io.github.manishdait.jplotlib.data.util.Data;
+import io.github.manishdait.jplotlib.internals.util.ChartType;
+
+/**
+ * The PieChart class represents a pie chart configuration containing data
+ * values and style settings
+ * for rendering a pie chart within the JPlotLib library.
+ * It implements the Graph interface and provides methods to access and modify
+ * pie chart properties.
+ *
+ */
+public class PieChart implements Graph {
+
+ private Data values;
+ private PieChartStyle style;
+ private static final ChartType CHART_TYPE = ChartType.PIE;
+
+ /**
+ * Constructs a PieChart object with the provided data values and default style
+ * settings.
+ *
+ * @param values
+ * The Data object containing values for the pie chart.
+ */
+ public PieChart(Data values) {
+ this.values = values;
+ this.style = new PieChartStyle();
+ }
+
+ public Data getValues() {
+ return values;
+ }
+
+ public void setValues(Data values) {
+ this.values = values;
+ }
+
+ public ChartType getChartType() {
+ return CHART_TYPE;
+ }
+
+ public PieChartStyle getStyle() {
+ return style;
+ }
+
+ public void setStyle(PieChartStyle style) {
+ this.style = style;
+ }
+
+ public PieChart color(Color[] colors) {
+ style.setColor(colors);
+ return this;
+ }
+
+}
diff --git a/src/main/java/io/github/manishdait/jplotlib/charts/pie/PieChartOptions.java b/src/main/java/io/github/manishdait/jplotlib/charts/pie/PieChartOptions.java
new file mode 100755
index 0000000..bb1b6c1
--- /dev/null
+++ b/src/main/java/io/github/manishdait/jplotlib/charts/pie/PieChartOptions.java
@@ -0,0 +1,64 @@
+/*
+ * MIT License
+ *
+ * Copyright (c) 2023 Manish Dait
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+package io.github.manishdait.jplotlib.charts.pie;
+
+/**
+ * The PieChartOptions interface provides a method to create a pie chart with
+ * data points.
+ * Implementations of this interface are expected to generate a PieChart object
+ * based on the provided data points.
+ *
+ */
+public interface PieChartOptions {
+ /**
+ * Creates a pie chart with the given data points.
+ *
+ * @param dataPoints
+ * An array of doubles representing the data points for the
+ * pie chart
+ * slices.
+ * @return PieChart A PieChart object representing a pie chart with the provided
+ * data points.
+ */
+ PieChart pie(double[] dataPoints);
+
+ /**
+ * Creates a pie chart with labeled segments using the given data points and
+ * labels.
+ *
+ * @param dataPoints
+ * An array of doubles representing the data points for the
+ * pie chart slices.
+ * @param labels
+ * An array of Strings providing labels for the corresponding
+ * data points.
+ * Each data point in the chart will be labeled accordingly.
+ * @return PieChart
+ * A PieChart object representing a labeled pie chart with the provided
+ * data points and labels.
+ */
+ PieChart pie(double[] dataPoints, String[] labels);
+
+}
diff --git a/src/main/java/io/github/manishdait/jplotlib/charts/pie/PieChartPlotter.java b/src/main/java/io/github/manishdait/jplotlib/charts/pie/PieChartPlotter.java
new file mode 100755
index 0000000..0713b1d
--- /dev/null
+++ b/src/main/java/io/github/manishdait/jplotlib/charts/pie/PieChartPlotter.java
@@ -0,0 +1,162 @@
+/*
+ * MIT License
+ *
+ * Copyright (c) 2023 Manish Dait
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+package io.github.manishdait.jplotlib.charts.pie;
+
+import java.awt.Color;
+import java.awt.Graphics;
+import java.awt.Graphics2D;
+import java.awt.RenderingHints;
+
+import javax.swing.JPanel;
+
+import io.github.manishdait.jplotlib.charts.helper.Plotter;
+import io.github.manishdait.jplotlib.data.GraphData;
+import io.github.manishdait.jplotlib.defaults.color.PlotColor;
+
+/**
+ * The PieChartPlotter class implements the Plotter interface and is responsible
+ * for rendering PieChart objects by drawing slices on a JPanel based on the
+ * provided data and context.
+ * It handles the visualization of pie charts within the JPlotLib library.
+ *
+ */
+public class PieChartPlotter implements Plotter {
+
+ private Graphics2D g;
+ private JPanel context;
+ private PieChart pieChart;
+
+ /**
+ * Constructs a PieChartPlotter with the necessary rendering context and
+ * PieChart object.
+ *
+ * @param g
+ * The Graphics object used for rendering.
+ * @param context
+ * The JPanel where the pie chart slices will be drawn.
+ * @param pieChart
+ * The PieChart object containing data and style settings.
+ */
+ public PieChartPlotter(
+ Graphics g,
+ JPanel context,
+ PieChart pieChart) {
+ this.g = (Graphics2D) g;
+ this.context = context;
+ this.pieChart = pieChart;
+ }
+
+ @Override
+ public void draw() {
+ double[] data = ((GraphData) pieChart.getValues()).getData();
+ String[] labels = ((GraphData) pieChart.getValues()).getLabels();
+
+ this.g.setRenderingHint(
+ RenderingHints.KEY_ANTIALIASING,
+ RenderingHints.VALUE_ANTIALIAS_ON);
+
+ this.g.setRenderingHint(
+ RenderingHints.KEY_TEXT_ANTIALIASING,
+ RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
+ this.g.setRenderingHint(
+ RenderingHints.KEY_RENDERING,
+ RenderingHints.VALUE_RENDER_QUALITY);
+
+ int width = (context.getWidth()) / 2;
+ int height = (context.getHeight()) / 2;
+
+ double sum = 0;
+ for (double i : data) {
+ sum += i;
+ }
+
+ sum = sum == 0 ? 1 : sum;
+ double diff = 360 / sum;
+ int radius = Math.min(context.getHeight(), context.getWidth()) / 2 - 50;
+
+ int prevAng = 0;
+ Color[] color = pieChart.getStyle().getColor();
+
+ for (int i = 0; i < data.length; i++) {
+ if (color == null) {
+ this.g.setColor(PlotColor.getColor(i));
+ } else {
+ this.g.setColor(color[i]);
+ }
+
+ int angle = (int) (data[i] * diff);
+
+ this.g.fillArc(
+ width - radius,
+ height - radius,
+ radius * 2,
+ radius * 2,
+ prevAng,
+ angle);
+
+ int midAngle = prevAng + angle / 2;
+
+ int[] labelDistance = findLabelDistance(angle, midAngle, width, height, radius);
+
+ prevAng += angle;
+
+ if (i == data.length - 1 && prevAng != 360) {
+ this.g.fillArc(
+ width - radius,
+ height - radius,
+ radius * 2,
+ radius * 2,
+ prevAng,
+ 360 - prevAng);
+ }
+
+ if (labels != null) {
+ String label = labels[i];
+ if (labelDistance[0] < width) {
+ labelDistance[0] = labelDistance[0] - label.length() * 8;
+ }
+ g.setColor(Color.black);
+ this.g.drawString(label, labelDistance[0], labelDistance[1]);
+
+ }
+ }
+ }
+
+ private int[] findLabelDistance(int angle, int midAngle, int width, int height, int radius) {
+ int labelX = 0;
+ int labelY = 0;
+
+ // Calculate label position
+ if (angle < 180) {
+ labelX = (int) (width + (radius * 1.1 * Math.cos(Math.toRadians(midAngle))));
+ labelY = (int) (height - (radius * 1.1 * Math.sin(Math.toRadians(midAngle))));
+ } else {
+ labelX = (int) (width + (radius * 1.1 * Math.cos(Math.toRadians(midAngle))));
+ labelY = (int) (height + (radius * 1.1 * Math.sin(Math.toRadians(midAngle))));
+ }
+ return new int[] { labelX, labelY };
+ }
+
+}
diff --git a/src/main/java/io/github/manishdait/jplotlib/charts/pie/PieChartStyle.java b/src/main/java/io/github/manishdait/jplotlib/charts/pie/PieChartStyle.java
new file mode 100755
index 0000000..ca831d5
--- /dev/null
+++ b/src/main/java/io/github/manishdait/jplotlib/charts/pie/PieChartStyle.java
@@ -0,0 +1,54 @@
+/*
+ * MIT License
+ *
+ * Copyright (c) 2023 Manish Dait
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+package io.github.manishdait.jplotlib.charts.pie;
+
+import java.awt.Color;
+
+/**
+ * The PieChartStyle class encapsulates style properties specific to a pie
+ * chart, allowing customization of visual attributes for rendering slices
+ * within the JPlotLib library.
+ *
+ */
+class PieChartStyle {
+
+ private Color[] color;
+
+ /**
+ * Constructs a ScatterChartStyle with default style settings.
+ */
+ public PieChartStyle() {
+ this.color = null;
+ }
+
+ public Color[] getColor() {
+ return this.color;
+ }
+
+ public void setColor(Color[] color) {
+ this.color = color;
+ }
+
+}
diff --git a/src/main/java/io/github/manishdait/jplotlib/charts/scatter/ScatterChart.java b/src/main/java/io/github/manishdait/jplotlib/charts/scatter/ScatterChart.java
new file mode 100755
index 0000000..c11b9ed
--- /dev/null
+++ b/src/main/java/io/github/manishdait/jplotlib/charts/scatter/ScatterChart.java
@@ -0,0 +1,102 @@
+/*
+ * MIT License
+ *
+ * Copyright (c) 2023 Manish Dait
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+package io.github.manishdait.jplotlib.charts.scatter;
+
+import java.awt.Color;
+
+import io.github.manishdait.jplotlib.charts.helper.Graph;
+import io.github.manishdait.jplotlib.data.util.Data;
+import io.github.manishdait.jplotlib.defaults.marker.Marker;
+import io.github.manishdait.jplotlib.internals.util.ChartType;
+
+/**
+ * The ScatterChart class implements the Graph interface and represents a
+ * scatter chart.
+ * It enables plotting data points using markers with customizable styles such
+ * as markers, sizes, colors, etc.
+ *
+ */
+public class ScatterChart implements Graph {
+
+ private Data coordinates;
+ private ScatterChartStyle style;
+ private static final ChartType CHART_TYPE = ChartType.SCATTER;
+
+ public ScatterChart() {
+ }
+
+ /**
+ * Constructs a ScatterChart with the provided data coordinates and initializes
+ * default style settings.
+ *
+ * @param coordinates
+ * The data coordinates to be plotted on the scatter chart.
+ */
+ public ScatterChart(Data coordinates) {
+ this.coordinates = coordinates;
+ style = new ScatterChartStyle();
+ }
+
+ public Data getCoordinates() {
+ return coordinates;
+ }
+
+ public void setCoordinates(Data coordinates) {
+ this.coordinates = coordinates;
+ }
+
+ public ScatterChartStyle getStyle() {
+ return style;
+ }
+
+ public void setStyle(ScatterChartStyle style) {
+ this.style = style;
+ }
+
+ public ChartType getChartType() {
+ return CHART_TYPE;
+ }
+
+ public ScatterChart marker(Marker marker) {
+ marker = marker == null ? Marker.NONE : marker;
+ style.setMarker(marker);
+ return this;
+ }
+
+ public ScatterChart size(int[] size) {
+ style.setScale(size);
+ return this;
+ }
+
+ public ScatterChart color(Color color) {
+ style.setColor(color);
+ return this;
+ }
+
+ public ScatterChart alpha(float alpha) {
+ style.setAlpha(alpha);
+ return this;
+ }
+
+}
diff --git a/src/main/java/io/github/manishdait/jplotlib/error/ArrayLengthMissMatchException.java b/src/main/java/io/github/manishdait/jplotlib/charts/scatter/ScatterChartOptions.java
old mode 100644
new mode 100755
similarity index 57%
rename from src/main/java/io/github/manishdait/jplotlib/error/ArrayLengthMissMatchException.java
rename to src/main/java/io/github/manishdait/jplotlib/charts/scatter/ScatterChartOptions.java
index 038990d..efd99ea
--- a/src/main/java/io/github/manishdait/jplotlib/error/ArrayLengthMissMatchException.java
+++ b/src/main/java/io/github/manishdait/jplotlib/charts/scatter/ScatterChartOptions.java
@@ -10,7 +10,7 @@
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
- * The above copyright notice and this permission notice shall be included in
+ * The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
@@ -22,30 +22,28 @@
* SOFTWARE.
*/
-package io.github.manishdait.jplotlib.error;
+package io.github.manishdait.jplotlib.charts.scatter;
/**
- * The ArrayLengthMissMatchException is a custom runtime exception that is
- * thrown when there is a mismatch in the lengths of arrays during data plotting
- * in Jplotlib.
- *
- * This exception indicates that the input arrays used for plotting do not have
- * the same length, which is a requirement for plotting data points correctly.
- *
+ * The ScatterChartOptions interface defines methods related to creating scatter
+ * charts.
+ * Implementations of this interface are expected to provide functionality for
+ * generating
+ * ScatterChart objects based on given x and y data points.
*
*/
+public interface ScatterChartOptions {
-public class ArrayLengthMissMatchException extends RuntimeException {
-
- /**
- * Constructs a new ArrayLengthMissMatchException with the specified detail
- * message.
- *
- * @param message the detail message.
- */
-
- public ArrayLengthMissMatchException(String message) {
- super(message);
- }
+ /**
+ * Creates a ScatterChart with the provided x and y data points.
+ *
+ * @param xPoints
+ * An array of double values representing the x-axis data points.
+ * @param yPoints
+ * An array of double values representing the y-axis data points.
+ * @return ScatterChart An object representing a scatter chart constructed using
+ * the given data.
+ */
+ ScatterChart scatter(double[] xPoints, double[] yPoints);
}
diff --git a/src/main/java/io/github/manishdait/jplotlib/charts/scatter/ScatterChartPlotter.java b/src/main/java/io/github/manishdait/jplotlib/charts/scatter/ScatterChartPlotter.java
new file mode 100755
index 0000000..3f707be
--- /dev/null
+++ b/src/main/java/io/github/manishdait/jplotlib/charts/scatter/ScatterChartPlotter.java
@@ -0,0 +1,167 @@
+/*
+ * MIT License
+ *
+ * Copyright (c) 2023 Manish Dait
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+package io.github.manishdait.jplotlib.charts.scatter;
+
+import java.awt.Color;
+import java.awt.Graphics;
+import java.awt.Graphics2D;
+import java.awt.RenderingHints;
+
+import javax.swing.JPanel;
+
+import io.github.manishdait.jplotlib.charts.helper.PlotLogger;
+import io.github.manishdait.jplotlib.charts.helper.Plotter;
+import io.github.manishdait.jplotlib.data.CartesianData;
+import io.github.manishdait.jplotlib.defaults.color.PlotColor;
+import io.github.manishdait.jplotlib.internals.components.axis.Config;
+
+/**
+ * The ScatterChartPlotter class is responsible for rendering ScatterChart
+ * objects on a JPanel by drawing
+ * individual data points based on the provided axis configuration and style
+ * information.
+ *
+ */
+public class ScatterChartPlotter implements Plotter {
+
+ private Graphics2D g;
+ private Config axisConfiguration;
+ private ScatterChart scatterChart;
+ private int indx;
+ private int heigth;
+
+ /**
+ * Constructs a ScatterChartPlotter with the necessary rendering context and
+ * chart data.
+ *
+ * @param g
+ * The Graphics object used for rendering.
+ * @param context
+ * The JPanel where the scatter chart will be drawn.
+ * @param axisConfiguration
+ * The configuration for rendering the axis.
+ * @param scatterChart
+ * The ScatterChart object containing data to be plotted.
+ * @param indx
+ * The index used for styling multiple charts.
+ */
+ public ScatterChartPlotter(
+ Graphics g,
+ JPanel context,
+ Config axisConfiguration,
+ ScatterChart scatterChart,
+ int indx) {
+ this.g = (Graphics2D) g;
+ this.axisConfiguration = axisConfiguration;
+ this.scatterChart = scatterChart;
+ this.indx = indx;
+ this.heigth = context.getHeight();
+ }
+
+ @Override
+ public void draw() {
+ double[] xPoints = ((CartesianData) this.scatterChart.getCoordinates()).getxPoints();
+ double[] yPoints = ((CartesianData) this.scatterChart.getCoordinates()).getyPoints();
+
+ this.g.setRenderingHint(
+ RenderingHints.KEY_ANTIALIASING,
+ RenderingHints.VALUE_ANTIALIAS_ON);
+
+ int yValDiff = axisConfiguration.getyValDiff();
+ int xValDiff = axisConfiguration.getxValDiff();
+
+ int xIncrement = axisConfiguration.getxIncrement();
+ int yIncrement = axisConfiguration.getyIncrement();
+
+ int xLowerBound = axisConfiguration.getxLowerBound();
+ int yLowerBound = axisConfiguration.getyLowerBound();
+
+ int extraSpace = (int) (Math.min(xIncrement, yIncrement) * 0.5);
+
+ Color color = scatterChart.getStyle().getColor();
+
+ if (color == null) {
+ color = PlotColor.getColor(indx);
+ }
+
+ color = setAlpa(color);
+
+ this.g.setColor(color);
+
+ for (int i = 0; i < yPoints.length; i++) {
+ int scale = scatterChart.getStyle().getScale() == null
+ ? 8
+ : scatterChart.getStyle().getScale()[i] * 5;
+
+ if (scale < 5 || scale > 50) {
+ scale = 8;
+ }
+
+ int x = (int) (xIncrement * (xPoints[i] - xLowerBound)) / xValDiff - scale / 2;
+ int y = heigth- (int) (yIncrement * (yPoints[i] - yLowerBound)) / yValDiff - scale / 2;
+ switch (scatterChart.getStyle().getMarker()) {
+ case NONE:
+ case CIRCLE:
+ this.g.fillOval(
+ x + extraSpace,
+ y - extraSpace,
+ scale,
+ scale);
+ break;
+
+ case SQUARE:
+ this.g.fillRect(
+ x + extraSpace,
+ y - extraSpace,
+ scale,
+ scale);
+ break;
+
+ default:
+ PlotLogger.getLogger().error("Error Unknown Marker type {}", scatterChart.getStyle().getMarker());
+ }
+
+ }
+ }
+
+ /**
+ * Adjusts the alpha (transparency) level of the provided color based on style
+ * information
+ * to ensure proper rendering of the scatter chart.
+ *
+ * @param color
+ * The input color for which alpha will be adjusted.
+ * @return Color The adjusted color with alpha transparency applied.
+ */
+ private Color setAlpa(Color color) {
+ Color currColor = color;
+ float alpha = scatterChart.getStyle().getAlpha();
+ if (alpha < 0 || alpha > 1) {
+ alpha = 1;
+ }
+ return new Color(currColor.getRed(), currColor.getGreen(), currColor.getBlue(), (int) (alpha * 255));
+ }
+
+}
diff --git a/src/main/java/io/github/manishdait/jplotlib/charts/scatter/ScatterChartStyle.java b/src/main/java/io/github/manishdait/jplotlib/charts/scatter/ScatterChartStyle.java
new file mode 100755
index 0000000..b950b8d
--- /dev/null
+++ b/src/main/java/io/github/manishdait/jplotlib/charts/scatter/ScatterChartStyle.java
@@ -0,0 +1,83 @@
+/*
+ * MIT License
+ *
+ * Copyright (c) 2023 Manish Dait
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+package io.github.manishdait.jplotlib.charts.scatter;
+
+import java.awt.Color;
+
+import io.github.manishdait.jplotlib.defaults.marker.Marker;
+
+/**
+ * The ScatterChartStyle class defines the visual style properties for rendering
+ * a scatter chart.
+ *
+ */
+class ScatterChartStyle {
+ private Color color;
+ private int[] scale;
+ private Marker marker;
+ private float alpha;
+
+ /**
+ * Constructs a ScatterChartStyle with default style settings.
+ */
+ public ScatterChartStyle() {
+ this.color = null;
+ this.scale = null;
+ this.marker = Marker.NONE;
+ this.alpha = 1F;
+ }
+
+ public Color getColor() {
+ return color;
+ }
+
+ public void setColor(Color color) {
+ this.color = color;
+ }
+
+ public float getAlpha() {
+ return alpha;
+ }
+
+ public void setAlpha(float alpha) {
+ this.alpha = alpha;
+ }
+
+ public Marker getMarker() {
+ return marker;
+ }
+
+ public void setMarker(Marker marker) {
+ this.marker = marker;
+ }
+
+ public int[] getScale() {
+ return scale;
+ }
+
+ public void setScale(int[] scale) {
+ this.scale = scale;
+ }
+}
diff --git a/src/main/java/io/github/manishdait/jplotlib/data/Coordinates.java b/src/main/java/io/github/manishdait/jplotlib/data/CartesianData.java
old mode 100644
new mode 100755
similarity index 53%
rename from src/main/java/io/github/manishdait/jplotlib/data/Coordinates.java
rename to src/main/java/io/github/manishdait/jplotlib/data/CartesianData.java
index 790b90c..1951ac1
--- a/src/main/java/io/github/manishdait/jplotlib/data/Coordinates.java
+++ b/src/main/java/io/github/manishdait/jplotlib/data/CartesianData.java
@@ -24,55 +24,44 @@
package io.github.manishdait.jplotlib.data;
+import io.github.manishdait.jplotlib.data.util.Data;
+
/**
- * The Coordinates class represents a set of x and y points for a series plot.
- *
+ * The CartesianData class implements the Data interface and represents a set of
+ * Cartesian data points. It contains x and y coordinate arrays for plotting
+ * Cartesian coordinates.
+ *
*/
+public class CartesianData implements Data {
+ private double[] xPoints;
+ private double[] yPoints;
-public class Coordinates {
-
- private double[] xPoints;
- private double[] yPoints;
-
- /**
- * Default constructor for Coordinates.
- */
- public Coordinates() {}
-
- /**
- * Get the x points array.
- *
- * @return The x points array.
- */
- public double[] getxPoints() {
- return this.xPoints;
- }
+ /**
+ * Constructs a CartesianData object with the given x and y coordinate arrays.
+ *
+ * @param xPoints
+ * The array containing the x-coordinates.
+ * @param yPoints
+ * The array containing the y-coordinates.
+ */
+ public CartesianData(double[] xPoints, double[] yPoints) {
+ this.xPoints = xPoints;
+ this.yPoints = yPoints;
+ }
- /**
- * Set the x points array.
- *
- * @param xPoints The x points array.
- */
- public void setxPoints(double[] xPoints) {
- this.xPoints = xPoints;
- }
+ public double[] getxPoints() {
+ return xPoints;
+ }
- /**
- * Get the y points array.
- *
- * @return The y points array.
- */
- public double[] getyPoints() {
- return this.yPoints;
- }
+ public void setxPoints(double[] xPoints) {
+ this.xPoints = xPoints;
+ }
- /**
- * Set the y points array.
- *
- * @param yPoints The y points array.
- */
- public void setyPoints(double[] yPoints) {
- this.yPoints = yPoints;
- }
+ public double[] getyPoints() {
+ return yPoints;
+ }
+ public void setyPoints(double[] yPoints) {
+ this.yPoints = yPoints;
+ }
}
diff --git a/src/main/java/io/github/manishdait/jplotlib/data/GraphData.java b/src/main/java/io/github/manishdait/jplotlib/data/GraphData.java
new file mode 100755
index 0000000..fc9440d
--- /dev/null
+++ b/src/main/java/io/github/manishdait/jplotlib/data/GraphData.java
@@ -0,0 +1,105 @@
+/*
+ * MIT License
+ *
+ * Copyright (c) 2023 Manish Dait
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+package io.github.manishdait.jplotlib.data;
+
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+import io.github.manishdait.jplotlib.data.util.Data;
+
+/**
+ * The GraphData class implements the Data interface and represents data for a
+ * graph. It contains labels and data points for plotting graphs.
+ *
+ */
+public class GraphData implements Data {
+ private String[] labels;
+ private double[] data;
+ private static boolean isX;
+ private static LinkedHashMap map;
+ private static int indx;
+
+ /**
+ * Static block to initialize the LinkedHashMap and index.
+ */
+ static {
+ map = new LinkedHashMap<>();
+ indx = 0;
+ }
+
+ /**
+ * Constructs a GraphData object with the given labels and data points.
+ *
+ * @param labels
+ * The array containing labels for the data points.
+ * @param data
+ * The array containing the data points.
+ */
+ public GraphData(String[] labels, double[] data) {
+ this.labels = labels;
+ this.data = data;
+ }
+
+ public String[] getLabels() {
+ return labels;
+ }
+
+ public void setLabels(String[] labels) {
+ this.labels = labels;
+ }
+
+ public static boolean isX() {
+ return isX;
+ }
+
+ public static void setX(boolean isX) {
+ GraphData.isX = isX;
+ }
+
+ public static Map getMap() {
+ return map;
+ }
+
+ public static void setMap(Map map) {
+ GraphData.map = (LinkedHashMap) map;
+ }
+
+ public static int getIndx() {
+ return indx;
+ }
+
+ public static void setIndx(int indx) {
+ GraphData.indx = indx;
+ }
+
+ public double[] getData() {
+ return data;
+ }
+
+ public void setData(double[] data) {
+ this.data = data;
+ }
+
+}
diff --git a/src/main/java/io/github/manishdait/jplotlib/data/SeriesData.java b/src/main/java/io/github/manishdait/jplotlib/data/SeriesData.java
deleted file mode 100644
index 8398add..0000000
--- a/src/main/java/io/github/manishdait/jplotlib/data/SeriesData.java
+++ /dev/null
@@ -1,379 +0,0 @@
-/*
- * MIT License
- *
- * Copyright (c) 2023 Manish Dait
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-package io.github.manishdait.jplotlib.data;
-
-import java.util.List;
-
-import io.github.manishdait.jplotlib.internal.util.AxisType;
-
-
-/**
- * The SeriesData class represents the data for a series plot in Jplotlib.
- *
- */
-
-public class SeriesData {
-
- public AxisType axisType;
- private String title = "";
- private String xLabel = "";
- private String yLabel = "";
-
- private int xIncrement;
- private int yIncrement;
-
- private int xUpperBound;
- private int yUpperBound;
-
- private int xLowerBound;
- private int yLowerBound;
-
- private int xValDiff;
- private int yValDiff;
-
- private boolean xGrid;
- private boolean yGrid;
-
- private String[] label;
-
- private List coordinates;
-
- private double[] pieData;
-
- /**
- * Default constructor for Coordinates.
- */
- public SeriesData() {}
-
-
- /**
- * Get the axis type of the series data.
- *
- * @return The axis type.
- */
- public AxisType getAxisType() {
- return axisType;
- }
-
- /**
- * Set the axis type of the series data.
- *
- * @param axisType The axis type.
- */
- public void setAxisType(AxisType axisType) {
- this.axisType = axisType;
- }
-
- /**
- * Get the title of the series data.
- *
- * @return The title.
- */
- public String getTitle() {
- return title;
- }
-
- /**
- * Set the title of the series data.
- *
- * @param title The axis title.
- */
- public void setTitle(String title) {
- this.title = title;
- }
-
- /**
- * Get the xLabel of the series data.
- *
- * @return The xLabel.
- */
- public String getxLabel() {
- return xLabel;
- }
-
- /**
- * Set the xLabel of the series data.
- *
- * @param xLabel The axis xLabel.
- */
- public void setxLabel(String xLabel) {
- this.xLabel = xLabel;
- }
-
- /**
- * Get the yLabel of the series data.
- *
- * @return The yLabel.
- */
- public String getyLabel() {
- return yLabel;
- }
-
- /**
- * Set the yLabel of the series data.
- *
- * @param yLabel The axis yLabel.
- */
- public void setyLabel(String yLabel) {
- this.yLabel = yLabel;
- }
-
- /**
- * Get the xIncrement value of the series data.
- *
- * @return The xIncrement.
- */
- public int getxIncrement() {
- return xIncrement;
- }
-
- /**
- * Set the xIncrement value of the series data.
- *
- * @param xIncrement The axis xIncrement.
- */
- public void setxIncrement(int xIncrement) {
- this.xIncrement = xIncrement;
- }
-
- /**
- * Get the yIncrement value of the series data.
- *
- * @return The yIncrement.
- */
- public int getyIncrement() {
- return yIncrement;
- }
-
- /**
- * Set the yIncrement value of the series data.
- *
- * @param yIncrement The axis yIncrement.
- */
- public void setyIncrement(int yIncrement) {
- this.yIncrement = yIncrement;
- }
-
- /**
- * Get the UpperBound value of xAxis.
- *
- * @return The xUpperBound.
- */
- public int getxUpperBound() {
- return xUpperBound;
- }
-
- /**
- * Set the UpperBound value of the xAxis.
- *
- * @param xUpperBound The xAxis UpperBound.
- */
- public void setxUpperBound(int xUpperBound) {
- this.xUpperBound = xUpperBound;
- }
-
- /**
- * Get the UpperBound value of yAxis.
- *
- * @return The yUpperBound.
- */
- public int getyUpperBound() {
- return yUpperBound;
- }
-
- /**
- * Set the UpperBound value of the yAxis.
- *
- * @param yUpperBound The yAxis UpperBound.
- */
- public void setyUpperBound(int yUpperBound) {
- this.yUpperBound = yUpperBound;
- }
-
- /**
- * Get the LowerBound value of xAxis.
- *
- * @return The xLowerBound.
- */
- public int getxLowerBound() {
- return xLowerBound;
- }
-
- /**
- * Set the LowerBound value of the xAxis.
- *
- * @param xLowerBound The xAxis LowerBound.
- */
- public void setxLowerBound(int xLowerBound) {
- this.xLowerBound = xLowerBound;
- }
-
- /**
- * Get the LowerBound value of yAxis.
- *
- * @return The yLowerBound.
- */
- public int getyLowerBound() {
- return yLowerBound;
- }
-
- /**
- * Set the LowerBound value of the yAxis.
- *
- * @param yLowerBound The yAxis LowerBound.
- */
- public void setyLowerBound(int yLowerBound) {
- this.yLowerBound = yLowerBound;
- }
-
-
- /**
- * Get the ValDiff value of xAxis.
- *
- * @return The xValDiff.
- */
- public int getxValDiff() {
- return xValDiff;
- }
-
- /**
- * Set the xValDiff of the series data.
- *
- * @param xValDiff The xAxis ValDiff.
- */
- public void setxValDiff(int xValDiff) {
- this.xValDiff = xValDiff;
- }
-
- /**
- * Get the ValDiff value of yAxis.
- *
- * @return The yValDiff.
- */
- public int getyValDiff() {
- return yValDiff;
- }
-
- /**
- * Set the yValDiff of the series data.
- *
- * @param yValDiff The yAxis ValDiff.
- */
- public void setyValDiff(int yValDiff) {
- this.yValDiff = yValDiff;
- }
-
- /**
- * Get the isGrid value of xAxis.
- *
- * @return The xGrid.
- */
- public boolean isxGrid() {
- return xGrid;
- }
-
- /**
- * Set the xGrid of the series data.
- *
- * @param xGrid The axis Grid.
- */
- public void setxGrid(boolean xGrid) {
- this.xGrid = xGrid;
- }
-
- /**
- * Get the isGrid value of yAxis.
- *
- * @return The yGrid.
- */
- public boolean isyGrid() {
- return yGrid;
- }
-
- /**
- * Set the yGrid of the series data.
- *
- * @param yGrid The axis Grid.
- */
- public void setyGrid(boolean yGrid) {
- this.yGrid = yGrid;
- }
-
-
- /**
- * Get the list of coordinates for the series plot.
- *
- * @return The list of coordinates.
- */
- public List getCoordinates() {
- return this.coordinates;
- }
-
- /**
- * Set the list of coordinates for the series plot.
- *
- * @param coordinates The list of coordinates.
- */
- public void setCoordinates(List coordinates) {
- this.coordinates = coordinates;
- }
-
- /**
- * Get the array of labels for the series plot.
- *
- * @return The array of labels.
- */
- public String[] getLabel() {
- return label;
- }
-
- /**
- * Set the array of labels for the series plot (Bar Graph).
- *
- * @param label The array of labels.
- */
- public void setLabel(String[] label) {
- this.label = label;
- }
-
- /**
- * Get the data for the pie chart.
- *
- * @return The data for the pie chart.
- */
- public double[] getPieData() {
- return pieData;
- }
-
- /**
- * Set the data for the pie chart.
- *
- * @param pieData The data for the pie chart.
- */
- public void setPieData(double[] pieData) {
- this.pieData = pieData;
- }
-
-}
diff --git a/src/main/java/io/github/manishdait/jplotlib/data/StyleData.java b/src/main/java/io/github/manishdait/jplotlib/data/StyleData.java
deleted file mode 100644
index af59c99..0000000
--- a/src/main/java/io/github/manishdait/jplotlib/data/StyleData.java
+++ /dev/null
@@ -1,141 +0,0 @@
-/*
- * MIT License
- *
- * Copyright (c) 2023 Manish Dait
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-package io.github.manishdait.jplotlib.data;
-
-import io.github.manishdait.jplotlib.chart.BarSeries;
-import io.github.manishdait.jplotlib.chart.LineSeries;
-import io.github.manishdait.jplotlib.chart.PieSeries;
-import io.github.manishdait.jplotlib.chart.ScatterSeries;
-import io.github.manishdait.jplotlib.internal.util.ChartType;
-
-
-/**
- * The StyleData class represents the style and type of a chart series.
- *
- */
-
-public class StyleData extends Coordinates {
-
- private ChartType chartType;
-
- private LineSeries lineSeries;
- private ScatterSeries scatterSeries;
- private BarSeries barSeries;
- private PieSeries pieSeries;
-
- public StyleData() {}
-
- /**
- * Get the chart type of the style data.
- *
- * @return The chart type.
- */
- public ChartType getChartType() {
- return chartType;
- }
-
- /**
- * Set the chart type of the style data.
- *
- * @param chartType The chart type to set.
- */
- public void setChartType(ChartType chartType) {
- this.chartType = chartType;
- }
-
- /**
- * Get the line series associated with the style data.
- *
- * @return The line series.
- */
- public LineSeries getLineSeries() {
- return lineSeries;
- }
-
- /**
- * Set the line series associated with the style data.
- *
- * @param lineSeries The line series to set.
- */
- public void setLineSeries(LineSeries lineSeries) {
- this.lineSeries = lineSeries;
- }
-
- /**
- * Get the scatter series associated with the style data.
- *
- * @return The scatter series.
- */
- public ScatterSeries getScatterSeries() {
- return scatterSeries;
- }
-
- /**
- * Set the scatter series associated with the style data.
- *
- * @param scatterSeries The scatter series to set.
- */
- public void setScatterSeries(ScatterSeries scatterSeries) {
- this.scatterSeries = scatterSeries;
- }
-
- /**
- * Get the bar series associated with the style data.
- *
- * @return The bar series.
- */
- public BarSeries getBarSeries() {
- return barSeries;
- }
-
- /**
- * Set the bar series associated with the style data.
- *
- * @param barSeries The bar series to set.
- */
- public void setBarSeries(BarSeries barSeries) {
- this.barSeries = barSeries;
- }
-
- /**
- * Get the pie series associated with the style data.
- *
- * @return The pie series.
- */
- public PieSeries getPieSeries() {
- return pieSeries;
- }
-
- /**
- * Set the pie series associated with the style data.
- *
- * @param pieSeries The pie series to set.
- */
- public void setPieSeries(PieSeries pieSeries) {
- this.pieSeries = pieSeries;
- }
-
-}
-
diff --git a/src/main/java/io/github/manishdait/jplotlib/chart/helper/BarGraphOptions.java b/src/main/java/io/github/manishdait/jplotlib/data/util/Data.java
old mode 100644
new mode 100755
similarity index 76%
rename from src/main/java/io/github/manishdait/jplotlib/chart/helper/BarGraphOptions.java
rename to src/main/java/io/github/manishdait/jplotlib/data/util/Data.java
index 30fb248..1cc408a
--- a/src/main/java/io/github/manishdait/jplotlib/chart/helper/BarGraphOptions.java
+++ b/src/main/java/io/github/manishdait/jplotlib/data/util/Data.java
@@ -22,12 +22,13 @@
* SOFTWARE.
*/
-package io.github.manishdait.jplotlib.chart.helper;
-
-import io.github.manishdait.jplotlib.chart.BarGraph;
-
-public interface BarGraphOptions {
-
- public BarGraph bar(String[] xLabels, double[] yPoints);
+package io.github.manishdait.jplotlib.data.util;
+/**
+ * The Data interface defines a contract for data-related classes within the
+ * JplotLib library. Classes implementing this interface are expected to handle
+ * data management or representation.
+ * This interface serves as a base for various data-related functionalities.
+ */
+public interface Data {
}
diff --git a/src/main/java/io/github/manishdait/jplotlib/data/util/DataDiff.java b/src/main/java/io/github/manishdait/jplotlib/data/util/DataDiffer.java
old mode 100644
new mode 100755
similarity index 64%
rename from src/main/java/io/github/manishdait/jplotlib/data/util/DataDiff.java
rename to src/main/java/io/github/manishdait/jplotlib/data/util/DataDiffer.java
index 6423fc5..e5938be
--- a/src/main/java/io/github/manishdait/jplotlib/data/util/DataDiff.java
+++ b/src/main/java/io/github/manishdait/jplotlib/data/util/DataDiffer.java
@@ -28,31 +28,34 @@
* The DataDiff class provides utility methods to calculate data differences.
*
*/
+public class DataDiffer {
-public class DataDiff {
-
- /**
- * Calculate the value difference based on the given points and length.
- *
- * @param points The array of points.
- * @param length The length of the data.
- * @return The value difference.
- */
- public static int getValDiff(double[] points, int length) {
- double max = 1;
- for(double j: points) {
- if(j > max) {
- max = j;
+ private DataDiffer() {
+ }
+
+ static final int MAX_TICKS = 24;
+
+ /**
+ * Calculate the value difference based on the given range and totalLength of
+ * data.
+ *
+ * @param range
+ * the difference between Upper and Lower bound.
+ * @param totalLength
+ * The total length of the data.
+ * @return The value difference.
+ */
+ public static int getValDiff(double range, int totalLength) {
+ int valDiff = (int) range / totalLength;
+
+ if (totalLength > 24) {
+ valDiff = (int) range / MAX_TICKS;
}
- }
-
-
- int valDiff = (int) max / length;
- if(max % points.length != 0) {
- return ++valDiff;
+ if (range % totalLength != 0) {
+ valDiff = valDiff + 1;
+ }
+ return valDiff;
}
- return valDiff;
- }
-
+
}
diff --git a/src/main/java/io/github/manishdait/jplotlib/data/util/PreProcessor.java b/src/main/java/io/github/manishdait/jplotlib/data/util/PreProcessor.java
deleted file mode 100644
index 73388fd..0000000
--- a/src/main/java/io/github/manishdait/jplotlib/data/util/PreProcessor.java
+++ /dev/null
@@ -1,165 +0,0 @@
-/*
- * MIT License
- *
- * Copyright (c) 2023 Manish Dait
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-package io.github.manishdait.jplotlib.data.util;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import io.github.manishdait.jplotlib.data.Coordinates;
-
-/**
- * The PreProcessor class provides utility methods for preprocessing data before
- * plotting.
- *
- */
-
-public class PreProcessor {
-
- /**
- * Default Constuctor for PreProcessor.
- */
- public PreProcessor () {}
-
- /**
- * Process the x-coordinates from the given list of coordinates.
- *
- * @param coordinates The list of coordinates.
- * @return The processed x-coordinates as an array of double.
- */
- public double[] processX(List coordinates) {
- List xPoints = new ArrayList();
-
- for(int i = 0; i < coordinates.size(); i++) {
- for(int j = 0; j < coordinates.get(i).getxPoints().length; j++) {
- xPoints.add(coordinates.get(i).getxPoints()[j]);
- }
- }
-
- return transform(xPoints);
- }
-
- /**
- * Process the y-coordinates from the given list of coordinates.
- *
- * @param coordinates The list of coordinates.
- * @return The processed y-coordinates as an array of double.
- */
- public double[] processY(List coordinates) {
- List yPoints = new ArrayList();
-
- for(int i = 0; i < coordinates.size(); i++) {
- for(int j = 0; j < coordinates.get(i).getyPoints().length; j++) {
- yPoints.add(coordinates.get(i).getyPoints()[j]);
- }
- }
-
- return transform(yPoints);
- }
-
- /**
- * Convert List<> to double[] array.
- * @param points List of points.
- * @return array
- */
- private double[] transform(List points) {
- double[] data = new double[points.size()];
-
- for(int i = 0; i < points.size(); i++) {
- data[i] = points.get(i);
- }
-
- return data;
- }
-
- /**
- * Get the maximum length of x-coordinates from the given list of coordinates.
- *
- * @param coordinates The list of coordinates.
- * @return The maximum length of x-coordinates.
- */
- public int getMaxLengthX(List coordinates) {
- int len = 0;
-
- for(int i = 0; i < coordinates.size(); i++) {
- if(len < coordinates.get(i).getxPoints().length) {
- len = coordinates.get(i).getxPoints().length;
- }
- }
-
- return len;
- }
-
- /**
- * Get the maximum length of y-coordinates from the given list of coordinates.
- *
- * @param coordinates The list of coordinates.
- * @return The maximum length of y-coordinates.
- */
- public int getMaxLengthY(List coordinates) {
- int len = 0;
-
- for(int i = 0; i < coordinates.size(); i++) {
- if(len < coordinates.get(i).getyPoints().length) {
- len = coordinates.get(i).getyPoints().length;
- }
- }
-
- return len;
- }
-
- /**
- * Get the upper bound of values from the given array of points.
- *
- * @param points The array of points.
- * @return The upper bound value.
- */
- public int getUpperBound(double[] points) {
- int max = 1;
- for(int i = 0; i < points.length; i++) {
- if(points[i] > max) {
- max = (int) points[i];
- }
- }
-
- return max;
- }
-
- /**
- * Get the lower bound of values from the given array of points.
- *
- * @param points The array of points.
- * @return The lower bound value.
- */
- public int getLowerBound(double[] points) {
- int min = Integer.MAX_VALUE;
- for(int i = 0; i < points.length; i++) {
- if(min > points[i]) {
- min = (int) points[i];
- }
- }
- return min;
- }
-
-}
diff --git a/src/main/java/io/github/manishdait/jplotlib/style/color/BaseColor.java b/src/main/java/io/github/manishdait/jplotlib/defaults/color/LibColor.java
old mode 100644
new mode 100755
similarity index 60%
rename from src/main/java/io/github/manishdait/jplotlib/style/color/BaseColor.java
rename to src/main/java/io/github/manishdait/jplotlib/defaults/color/LibColor.java
index 7659513..fc5f2de
--- a/src/main/java/io/github/manishdait/jplotlib/style/color/BaseColor.java
+++ b/src/main/java/io/github/manishdait/jplotlib/defaults/color/LibColor.java
@@ -22,40 +22,34 @@
* SOFTWARE.
*/
-package io.github.manishdait.jplotlib.style.color;
+package io.github.manishdait.jplotlib.defaults.color;
import java.awt.Color;
/**
- * The BaseColor enum represents a set of predefined colors.
+ * The LibColor enum represents a set of predefined colors.
*
*/
-public enum BaseColor {
-
- BLUE(new Color(31, 119, 181)),
- ORANGE(new Color(251, 127, 15)),
- GREEN(new Color(46, 161, 47)),
- RED(new Color(215, 42, 44)),
- PURPLE(new Color(148, 104, 189)),
- BROWN(new Color(141, 86, 75)),
- PINK(new Color(227, 119, 194)),
- GREY(new Color(127, 127, 127)),
- LIME(new Color(188, 189, 35)),
- SKY(new Color(44, 193, 209));
-
- private Color color;
-
- BaseColor(Color color) {
- this.color = color;
- }
-
- /**
- * Get the color associated with the BaseColor.
- *
- * @return The color.
- */
- public Color getColor() {
- return this.color;
- }
+public enum LibColor {
+
+ BLUE(new Color(31, 119, 181)), ORANGE(new Color(251, 127, 15)), GREEN(new Color(46, 161, 47)), RED(
+ new Color(215, 42, 44)), PURPLE(new Color(148, 104, 189)), BROWN(new Color(141, 86, 75)), PINK(
+ new Color(227, 119, 194)), GREY(
+ new Color(127, 127, 127)), LIME(new Color(188, 189, 35)), SKY(new Color(44, 193, 209));
+
+ private Color color;
+
+ LibColor(Color color) {
+ this.color = color;
+ }
+
+ /**
+ * Get the color associated with the LibColor.
+ *
+ * @return The color.
+ */
+ public Color getColor() {
+ return this.color;
+ }
}
diff --git a/src/main/java/io/github/manishdait/jplotlib/style/color/BaseSeriesColor.java b/src/main/java/io/github/manishdait/jplotlib/defaults/color/PlotColor.java
old mode 100644
new mode 100755
similarity index 57%
rename from src/main/java/io/github/manishdait/jplotlib/style/color/BaseSeriesColor.java
rename to src/main/java/io/github/manishdait/jplotlib/defaults/color/PlotColor.java
index 2f1b52f..1f3577d
--- a/src/main/java/io/github/manishdait/jplotlib/style/color/BaseSeriesColor.java
+++ b/src/main/java/io/github/manishdait/jplotlib/defaults/color/PlotColor.java
@@ -22,38 +22,42 @@
* SOFTWARE.
*/
-package io.github.manishdait.jplotlib.style.color;
+package io.github.manishdait.jplotlib.defaults.color;
import java.awt.Color;
/**
- * The BaseSeriesColor class provides a set of predefined colors for series in a
+ * The PLotColor class provides a set of predefined colors for series in a
* chart.
*
*/
-public class BaseSeriesColor {
+public class PlotColor {
- private static final Color[] colors = {
- new Color(31, 119, 181),
- new Color(251, 127, 15),
- new Color(46, 161, 47),
- new Color(215, 42, 44),
- new Color(148, 104, 189),
- new Color(141, 86, 75),
- new Color(227, 119, 194),
- new Color(127, 127, 127),
- new Color(188, 189, 35),
- new Color(44, 193, 209)
- };
+ private PlotColor() {
+ }
- /**
- * Get the color associated with the given index.
- *
- * @param index The index of the color to retrieve.
- * @return The color associated with the index.
- */
- public static Color getColor(int indx) {
- return colors[indx];
- }
+ private static final Color[] colors = {
+ new Color(31, 119, 181),
+ new Color(251, 127, 15),
+ new Color(46, 161, 47),
+ new Color(215, 42, 44),
+ new Color(148, 104, 189),
+ new Color(141, 86, 75),
+ new Color(227, 119, 194),
+ new Color(127, 127, 127),
+ new Color(188, 189, 35),
+ new Color(44, 193, 209)
+ };
+
+ /**
+ * Get the color associated with the given index.
+ *
+ * @param index
+ * The index of the color to retrieve.
+ * @return The color associated with the index.
+ */
+ public static Color getColor(int indx) {
+ return colors[indx];
+ }
}
diff --git a/src/main/java/io/github/manishdait/jplotlib/style/line/BaseStroke.java b/src/main/java/io/github/manishdait/jplotlib/defaults/line/Stroke.java
old mode 100644
new mode 100755
similarity index 82%
rename from src/main/java/io/github/manishdait/jplotlib/style/line/BaseStroke.java
rename to src/main/java/io/github/manishdait/jplotlib/defaults/line/Stroke.java
index 78ff2db..8a7d98b
--- a/src/main/java/io/github/manishdait/jplotlib/style/line/BaseStroke.java
+++ b/src/main/java/io/github/manishdait/jplotlib/defaults/line/Stroke.java
@@ -22,22 +22,22 @@
* SOFTWARE.
*/
-package io.github.manishdait.jplotlib.style.line;
+package io.github.manishdait.jplotlib.defaults.line;
/**
- * The BaseStroke enum represents different types of line strokes.
+ * The Stroke enum represents different types of line strokes.
*
*/
-public enum BaseStroke {
+public enum Stroke {
- /**
- * No line stroke.
- */
- NONE,
+ /**
+ * No line stroke.
+ */
+ NONE,
- /**
- * Dashed line stroke.
- */
- DASHED;
+ /**
+ * Dashed line stroke.
+ */
+ DASHED;
}
diff --git a/src/main/java/io/github/manishdait/jplotlib/style/marker/BaseMarker.java b/src/main/java/io/github/manishdait/jplotlib/defaults/marker/Marker.java
old mode 100644
new mode 100755
similarity index 79%
rename from src/main/java/io/github/manishdait/jplotlib/style/marker/BaseMarker.java
rename to src/main/java/io/github/manishdait/jplotlib/defaults/marker/Marker.java
index fd3f1f1..3ef6980
--- a/src/main/java/io/github/manishdait/jplotlib/style/marker/BaseMarker.java
+++ b/src/main/java/io/github/manishdait/jplotlib/defaults/marker/Marker.java
@@ -22,28 +22,28 @@
* SOFTWARE.
*/
-package io.github.manishdait.jplotlib.style.marker;
+package io.github.manishdait.jplotlib.defaults.marker;
/**
- * The BaseMarker enum represents different types of markers for data points in
+ * The Marker enum represents different types of markers for data points in
* a chart.
*
*/
-public enum BaseMarker {
-
- /**
- * No marker.
- */
- NONE,
+public enum Marker {
- /**
- * Circular marker.
- */
- CIRCLE,
+ /**
+ * No marker.
+ */
+ NONE,
- /**
- * Square marker.
- */
- SQUARE;
+ /**
+ * Circular marker.
+ */
+ CIRCLE,
+
+ /**
+ * Square marker.
+ */
+ SQUARE;
}
diff --git a/src/main/java/io/github/manishdait/jplotlib/chart/PieSeries.java b/src/main/java/io/github/manishdait/jplotlib/error/JplotlibError.java
similarity index 72%
rename from src/main/java/io/github/manishdait/jplotlib/chart/PieSeries.java
rename to src/main/java/io/github/manishdait/jplotlib/error/JplotlibError.java
index 81e9575..3e645ce 100644
--- a/src/main/java/io/github/manishdait/jplotlib/chart/PieSeries.java
+++ b/src/main/java/io/github/manishdait/jplotlib/error/JplotlibError.java
@@ -22,21 +22,25 @@
* SOFTWARE.
*/
-package io.github.manishdait.jplotlib.chart;
+package io.github.manishdait.jplotlib.error;
-import java.awt.Color;
+/**
+ * The JplotlibError is a custom runtime exception that is thrown when there is
+ * any issue for data plotting in Jplotlib.
+ *
+ */
-public class PieSeries {
-
- private Color[] color;
+public class JplotlibError extends RuntimeException {
- public PieSeries() {}
+ /**
+ * Constructs a new JplotlibError with the specified detail
+ * message.
+ *
+ * @param message the detail message.
+ */
- public Color[] getColor() {
- return this.color;
- }
- public void setColor(Color[] color) {
- this.color = color;
+ public JplotlibError(String message) {
+ super(message);
}
}
diff --git a/src/main/java/io/github/manishdait/jplotlib/error/util/ErrorConstants.java b/src/main/java/io/github/manishdait/jplotlib/error/util/ErrorConstants.java
new file mode 100644
index 0000000..67bb6c0
--- /dev/null
+++ b/src/main/java/io/github/manishdait/jplotlib/error/util/ErrorConstants.java
@@ -0,0 +1,12 @@
+package io.github.manishdait.jplotlib.error.util;
+
+public class ErrorConstants {
+
+ private ErrorConstants() {
+ }
+
+ public static final String UNMATCH_DIMENSION_LENGTH_ERROR = "The number of xPoints does not match the number of yPoints.";
+ public static final String MISSMATCH_LABELDATA_LENGTH_ERROR = "The number of labels does not match the number of data points.";
+ public static final String NULL_DATA_ERROR = "The provided data point is null.";
+
+}
diff --git a/src/main/java/io/github/manishdait/jplotlib/internal/component/axis/Axis.java b/src/main/java/io/github/manishdait/jplotlib/internal/component/axis/Axis.java
deleted file mode 100644
index 60d2860..0000000
--- a/src/main/java/io/github/manishdait/jplotlib/internal/component/axis/Axis.java
+++ /dev/null
@@ -1,114 +0,0 @@
-/*
- * MIT License
- *
- * Copyright (c) 2023 Manish Dait
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-package io.github.manishdait.jplotlib.internal.component.axis;
-
-import java.awt.BasicStroke;
-import java.awt.Color;
-import java.awt.Graphics;
-import java.awt.Graphics2D;
-
-import javax.swing.JPanel;
-
-import io.github.manishdait.jplotlib.data.SeriesData;
-import io.github.manishdait.jplotlib.internal.util.Constants;
-
-
-/**
- * The Axis class represents a base class for building and drawing axes in
- * Jplotlib charts.
- *
- * This class is used to create and draw the axes (X-axis and Y-axis) for
- * Jplotlib charts. It provides
- * functionality to build and render the axes with borders, ticks, and labels,
- * based on the provided Graphics object, SeriesData, and JPanel context.
- *
- * The Axis class is not intended for direct instantiation, as it serves as a
- * base class for specific axis implementations. Instead, specific axis classes
- * such as HorizontalAxis and VerticalAxis extend this class to create and draw
- * the respective axes.
- *
- *
- */
-
-
-class Axis {
-
- protected Graphics2D g;
- protected SeriesData seriesData;
- protected JPanel context;
-
- /**
- * Constructs a new Axis object with the specified Graphics, JPanel context,
- * and SeriesData.
- *
- * @param g the Graphics object used for drawing the axis.
- * @param context the JPanel context within which the axis will be drawn.
- * @param seriesData the SeriesData containing data points for the chart.
- */
-
- public Axis(Graphics g, JPanel context, SeriesData seriesData) {
- this.g = (Graphics2D) g;
- this.seriesData = seriesData;
- this.context = context;
- }
-
- /**
- * Builds and draws the borders for the X-axis and Y-axis of the chart.
- */
- public void buildBorder() {
- this.g.setStroke(new BasicStroke(1.2F));
- this.g.setColor(Color.BLACK);
-
- int height = this.context.getHeight();
- int width = this.context.getWidth();
-
- this.g.drawLine(
- Constants.MARGIN,
- height - Constants.MARGIN,
- width - Constants.MARGIN,
- height - Constants.MARGIN
- );
- this.g.drawLine(
- Constants.MARGIN,
- Constants.MARGIN,
- width - Constants.MARGIN,
- Constants.MARGIN
- );
-
- this.g.drawLine(
- Constants.MARGIN,
- Constants.MARGIN,
- Constants.MARGIN,
- height - Constants.MARGIN
- );
- this.g.drawLine(
- width - Constants.MARGIN,
- Constants.MARGIN,
- width - Constants.MARGIN,
- height - Constants.MARGIN
- );
- }
-
-}
diff --git a/src/main/java/io/github/manishdait/jplotlib/internal/component/axis/AxisBuilder.java b/src/main/java/io/github/manishdait/jplotlib/internal/component/axis/AxisBuilder.java
deleted file mode 100644
index b498869..0000000
--- a/src/main/java/io/github/manishdait/jplotlib/internal/component/axis/AxisBuilder.java
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * MIT License
- *
- * Copyright (c) 2023 Manish Dait
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-package io.github.manishdait.jplotlib.internal.component.axis;
-
-import java.awt.Graphics;
-
-import javax.swing.JPanel;
-
-import io.github.manishdait.jplotlib.data.SeriesData;
-import io.github.manishdait.jplotlib.internal.util.AxisType;
-
-/**
- * The AxisBuilder class is responsible for building and rendering the axis
- * components for Jplotlib charts.
- *
- * This class extends the Coordinate class, which provides the functionality for
- * drawing and labeling the X-axis and Y-axis. The AxisBuilder further enhances
- * this functionality by adding a border and grid for non-pie charts.
- *
- * The AxisBuilder is not intended for direct instantiation, as it is used
- * internally by Jplotlib to render the axis components.
- *
- *
- */
-
-public class AxisBuilder extends Coordinate {
-
- /**
- * Constructs a new AxisBuilder object with the specified Graphics, JPanel
- * context, and SeriesData.
- *
- * @param g the Graphics object used for drawing the axis components.
- * @param context the JPanel context within which the axis components will be
- * drawn.
- * @param seriesData the SeriesData containing data points for the chart.
- */
- public AxisBuilder(Graphics g, JPanel context, SeriesData seriesData) {
- super(g, context, seriesData);
- }
-
- /**
- * Builds and renders the axis components, including the border and grid
- * (if applicable) for non-pie charts.
- */
- public void buildAxis() {
- if(seriesData.getAxisType() != AxisType.PIE) {
- buildBorder();
- drawCoordinates();
-
- new Grid(g, context, seriesData).buildGrid();
- }
- }
-
-}
diff --git a/src/main/java/io/github/manishdait/jplotlib/internal/component/axis/Coordinate.java b/src/main/java/io/github/manishdait/jplotlib/internal/component/axis/Coordinate.java
deleted file mode 100644
index 34cb92d..0000000
--- a/src/main/java/io/github/manishdait/jplotlib/internal/component/axis/Coordinate.java
+++ /dev/null
@@ -1,199 +0,0 @@
-/*
- * MIT License
- *
- * Copyright (c) 2023 Manish Dait
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-package io.github.manishdait.jplotlib.internal.component.axis;
-
-import java.awt.Graphics;
-import java.awt.RenderingHints;
-
-import javax.swing.JPanel;
-
-import io.github.manishdait.jplotlib.data.SeriesData;
-import io.github.manishdait.jplotlib.data.util.DataDiff;
-import io.github.manishdait.jplotlib.data.util.PreProcessor;
-import io.github.manishdait.jplotlib.internal.util.AxisType;
-import io.github.manishdait.jplotlib.internal.util.Constants;
-
-
-
-/**
- * The Coordinate class represents an axis layout and labeling component for
- * Jplotlib charts.
- *
- * This class is responsible for drawing and labeling the X-axis and Y-axis of
- * Jplotlib charts. It calculates the axis bounds, increments, and labels based
- * on the provided Graphics, JPanel context, and SeriesData. The layout and
- * labels are rendered dynamically based on the data points and chart type.
- *
- * The Coordinate class is not intended for direct instantiation, as it is used
- * internally by other Jplotlib components. It extends the Axis class, which is
- * a base class for building and drawing axes in Jplotlib charts.
- *
- *
- */
-
-class Coordinate extends Axis {
- private int yUpperBound;
- private int xUpperBound;
-
- private int yLowerBound;
- private int xLowerBound;
-
- private double[] xPoints;
- private double[] yPoints;
-
- private PreProcessor preProcessor;
-
- /**
- * Constructs a new Coordinate object with the specified Graphics, JPanel
- * context, and SeriesData.
- *
- * @param g the Graphics object used for drawing the axes.
- * @param context the JPanel context within which the axes will be drawn.
- * @param seriesData the SeriesData containing data points for the chart.
- */
- public Coordinate(Graphics g, JPanel context, SeriesData seriesData) {
- super(g, context, seriesData);
- this.preProcessor = new PreProcessor();
- }
-
- /**
- * Draws the X-axis and Y-axis coordinates, labels, and ticks based on the
- * SeriesData.
- */
- public void drawCoordinates() {
- this.xPoints = preProcessor.processX(seriesData.getCoordinates());
- this.yPoints = preProcessor.processY(seriesData.getCoordinates());
-
- this.xUpperBound = preProcessor.getUpperBound(xPoints);
- this.yUpperBound = preProcessor.getUpperBound(yPoints);
-
- this.xLowerBound = preProcessor.getLowerBound(xPoints);
- this.yLowerBound = preProcessor.getLowerBound(yPoints);
-
- seriesData.setxUpperBound(this.xUpperBound);
- seriesData.setyUpperBound(this.yUpperBound);
-
- seriesData.setyLowerBound(this.yLowerBound);
- seriesData.setxLowerBound(this.xLowerBound);
-
- this.g.setRenderingHint(
- RenderingHints.KEY_TEXT_ANTIALIASING,
- RenderingHints.VALUE_TEXT_ANTIALIAS_ON
- );
- this.g.setRenderingHint(
- RenderingHints.KEY_RENDERING,
- RenderingHints.VALUE_RENDER_QUALITY
- );
-
- if(seriesData.getAxisType() != AxisType.BAR) {
- baseLayout();
- } else {
- barLayout();
- }
- }
-
- private void baseLayout() {
- int xBound = xUpperBound - xLowerBound;
- int xValDiff = DataDiff.getValDiff(
- xPoints,
- preProcessor.getMaxLengthX(seriesData.getCoordinates())
- );
- int totalX = xBound / xValDiff;
- totalX = (xBound % xValDiff) == 0 ? totalX : totalX + 1;
- int xIncrement = getIncrement(this.context.getWidth(), totalX);
-
- seriesData.setxValDiff(xValDiff);
- seriesData.setxIncrement(xIncrement);
-
- int yBound = yUpperBound - yLowerBound;
- int yValDiff = DataDiff.getValDiff(
- yPoints,
- preProcessor.getMaxLengthY(seriesData.getCoordinates())
- );
- int totalY = yBound / yValDiff;
- totalY = (yBound % yValDiff) == 0 ? totalY : totalY + 1;
- int yIncrement = getIncrement(this.context.getHeight(), totalY);
-
- seriesData.setyValDiff(yValDiff);
- seriesData.setyIncrement(yIncrement);
-
- int extraSpace = (int) (Math.max(xIncrement, yIncrement) * 0.25);
-
- for(int i = 0; i <= totalX; i ++) {
- int x = Constants.MARGIN + xIncrement * i;
- int y = this.context.getHeight() - Constants.MARGIN + 20;
- int val = xValDiff * i + xLowerBound;
- this.g.drawString(Integer.toString(val), x + extraSpace, y);
- }
-
- for(int i = 0; i <= (totalY); i ++) {
- int x = Constants.MARGIN - 30;
- int y = this.context.getHeight() - Constants.MARGIN - yIncrement * i;
- int val = yValDiff * i + yLowerBound;
- this.g.drawString(Integer.toString(val), x, y - extraSpace );
- }
- }
-
- private void barLayout() {
- int totalX = seriesData.getLabel().length;
- int xIncrement = getIncrement(this.context.getWidth(), totalX * 2);
-
- for(int i = 0; i < totalX; i++) {
- int x = Constants.MARGIN + (xIncrement * (i * 2 + 1));
- int y = this.context.getHeight() - Constants.MARGIN + 20;
- this.g.drawString(seriesData.getLabel()[i], x, y);
- }
-
- seriesData.setxIncrement(xIncrement);
-
- int yBound = yUpperBound - yLowerBound;
- int yValDiff = DataDiff.getValDiff(
- yPoints,
- preProcessor.getMaxLengthY(seriesData.getCoordinates())
- );
- int totalY = yBound / yValDiff;
- totalY = (yBound % yValDiff) == 0 ? totalY : totalY + 1;
- int yIncrement = getIncrement(this.context.getHeight(), totalY);
-
- seriesData.setyValDiff(yValDiff);
- seriesData.setxValDiff(yValDiff);
- seriesData.setyIncrement(yIncrement);
-
- int extraSpace = (int) (Math.max(xIncrement, yIncrement) * 0.25);
-
- for(int i = 0; i <= totalY; i ++) {
- int x = Constants.MARGIN - 30;
- int y = this.context.getHeight() - Constants.MARGIN - yIncrement * i;
- int val = yValDiff * i + yLowerBound;
- this.g.drawString(Integer.toString(val), x, y - extraSpace );
- }
- }
-
-
- private int getIncrement(int width, int total) {
- return (width - Constants.MARGIN * 2) / (total + 1);
- }
-
-}
diff --git a/src/main/java/io/github/manishdait/jplotlib/internal/component/axis/Grid.java b/src/main/java/io/github/manishdait/jplotlib/internal/component/axis/Grid.java
deleted file mode 100644
index 7051cec..0000000
--- a/src/main/java/io/github/manishdait/jplotlib/internal/component/axis/Grid.java
+++ /dev/null
@@ -1,177 +0,0 @@
-/*
- * MIT License
- *
- * Copyright (c) 2023 Manish Dait
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-package io.github.manishdait.jplotlib.internal.component.axis;
-
-import java.awt.Color;
-import java.awt.Graphics;
-import java.awt.Graphics2D;
-
-import javax.swing.JPanel;
-
-import io.github.manishdait.jplotlib.data.SeriesData;
-import io.github.manishdait.jplotlib.internal.util.AxisType;
-import io.github.manishdait.jplotlib.internal.util.Constants;
-
-
-/**
- * The Grid class is responsible for drawing the grid lines on the chart.
- *
- * This class provides methods to build the grid lines for different chart types,
- * including regular plot charts and bar charts. The grid lines are drawn based
- * on the data points and axis bounds provided in the SeriesData object.
- *
- * The Grid class is used internally by the Jplotlib library and is not intended
- * to be used directly by users
- *
- *
- */
-
-class Grid {
-
- private Graphics2D g;
- private SeriesData seriesData;
- private JPanel context;
-
- int xTotalPoints;
- int yTotalPoints;
-
- int xBounds;
- int yBounds;
-
- int xValDiff;
- int yValDiff;
-
- /**
- * Constructs a Grid object with the specified graphics context, chart context,
- * and series data.
- *
- * @param g the graphics context for drawing the grid lines.
- * @param context the chart context (JPanel) where the grid lines will be
- * drawn.
- * @param seriesData the series data containing the data points and axis
- * bounds.
- */
- public Grid(Graphics g, JPanel context, SeriesData seriesData) {
- this.g = (Graphics2D) g;
- this.seriesData = seriesData;
- this.context = context;
- }
-
- /**
- * Builds the grid lines for the chart based on the chart type (plot or bar).
- */
- public void buildGrid() {
-
- this.g.setColor(new Color(176, 176, 176, 255));
-
- xBounds = seriesData.getxUpperBound() - seriesData.getxLowerBound();
- yBounds = seriesData.getyUpperBound() - seriesData.getyLowerBound();
-
- xValDiff = seriesData.getxValDiff();
- yValDiff = seriesData.getyValDiff();
-
- xTotalPoints = xBounds / xValDiff;
- yTotalPoints = yBounds / yValDiff;
-
- xTotalPoints = (xBounds % xValDiff) == 0 ? xTotalPoints : xTotalPoints + 1;
- yTotalPoints = (yBounds % yValDiff) == 0 ? yTotalPoints : yTotalPoints + 1;
-
- if(seriesData.getAxisType() != AxisType.BAR) {
- baseGrid();
- } else {
- barGrid();
- }
-
- }
-
- /**
- * Draws the grid lines for regular plot charts.
- */
- private void baseGrid() {
- int xIncrement = this.seriesData.getxIncrement();
- int yIncrement = this.seriesData.getyIncrement();
-
- int extraSpace = (int) (Math.max(xIncrement, yIncrement) * 0.25);
-
- if (this.seriesData.isxGrid()) {
- for(int i = 0; i <= xTotalPoints; i ++) {
- int x = Constants.MARGIN + (xIncrement * i) + extraSpace;
- this.g.drawLine(
- x,
- Constants.MARGIN,
- x,
- this.context.getHeight() - Constants.MARGIN
- );
- }
- }
-
- if (this.seriesData.isyGrid()) {
- for(int i = 0; i <= yTotalPoints; i ++) {
- int y = this.context.getHeight() - Constants.MARGIN - (yIncrement * i);
- this.g.drawLine(
- Constants.MARGIN,
- y - extraSpace,
- this.context.getWidth() - Constants.MARGIN,
- y - extraSpace
- );
- }
- }
- }
-
- /**
- * Draws the grid lines for bar charts.
- */
- private void barGrid() {
- int xIncrement = this.seriesData.getxIncrement();
- int yIncrement = this.seriesData.getyIncrement();
-
- int extraSpace = (int) (Math.max(xIncrement, yIncrement) * 0.25);
-
- if (this.seriesData.isxGrid()) {
- for(int i = 0; i < seriesData.getLabel().length; i ++) {
- int x = Constants.MARGIN + (xIncrement * (i*2+1));
- this.g.drawLine(
- x,
- Constants.MARGIN,
- x,
- this.context.getHeight() - Constants.MARGIN
- );
- }
- }
-
- if (this.seriesData.isyGrid()) {
- for(int i = 0; i <= yTotalPoints; i ++) {
- int y = this.context.getHeight() - Constants.MARGIN - (yIncrement * i);
- this.g.drawLine(
- Constants.MARGIN,
- y - extraSpace,
- this.context.getWidth() - Constants.MARGIN,
- y - extraSpace
- );
- }
- }
- }
-
-}
diff --git a/src/main/java/io/github/manishdait/jplotlib/internals/components/axis/Axis.java b/src/main/java/io/github/manishdait/jplotlib/internals/components/axis/Axis.java
new file mode 100755
index 0000000..1688d76
--- /dev/null
+++ b/src/main/java/io/github/manishdait/jplotlib/internals/components/axis/Axis.java
@@ -0,0 +1,89 @@
+/*
+ * MIT License
+ *
+ * Copyright (c) 2023 Manish Dait
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+package io.github.manishdait.jplotlib.internals.components.axis;
+
+import java.awt.Graphics;
+import java.awt.Graphics2D;
+
+import javax.swing.JPanel;
+
+import io.github.manishdait.jplotlib.internals.util.AxisType;
+
+/**
+ * The Axis class is responsible for building and rendering the axis components
+ * for Jplotlib charts.
+ *
+ * This class calls the functions of Border and Coordinate class, which provides
+ * the functionality for drawing and labeling the X-axis and Y-axis. The Axis
+ * further enhances
+ * this functionality by adding a grid for non-pie charts.
+ *
+ * The Axis is not intended for direct instantiation, as it is used internally
+ * by Jplotlib to render the axis components.
+ *
+ *
+ */
+public class Axis {
+
+ private Graphics2D g;
+ private JPanel context;
+ private Config axisConfiguration;
+
+ /**
+ * Constructs a new Axis object with the specified Graphics, JPanel
+ * context, and AxisConfiguration.
+ *
+ * @param g
+ * the Graphics object used for drawing the axis
+ * components.
+ * @param context
+ * the JPanel context within which the axis components
+ * will be
+ * drawn.
+ * @param axisConfiguration
+ * the Configuration for rendering axis.
+ */
+ public Axis(Graphics g, JPanel context, Config axisConfiguration) {
+ this.g = (Graphics2D) g;
+ this.context = context;
+ this.axisConfiguration = axisConfiguration;
+ }
+
+ /**
+ * Builds and renders the axis components, including the border, coordinate and
+ * grid (if applicable) for non-pie charts.
+ */
+ public void drawAxis() {
+ if (axisConfiguration.getAxisType() != AxisType.PIE) {
+ new Border(g, context).drawBorder();
+ new Coordinate(g, context, axisConfiguration).drawCoordinates();
+ new Grid(g, context, axisConfiguration).buildGrid();
+ } else {
+ axisConfiguration.setyLabel("");
+ axisConfiguration.setxLabel("");
+ }
+ }
+
+}
diff --git a/src/main/java/io/github/manishdait/jplotlib/internals/components/axis/Border.java b/src/main/java/io/github/manishdait/jplotlib/internals/components/axis/Border.java
new file mode 100755
index 0000000..80f652c
--- /dev/null
+++ b/src/main/java/io/github/manishdait/jplotlib/internals/components/axis/Border.java
@@ -0,0 +1,89 @@
+/*
+ * MIT License
+ *
+ * Copyright (c) 2023 Manish Dait
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+package io.github.manishdait.jplotlib.internals.components.axis;
+
+import java.awt.BasicStroke;
+import java.awt.Color;
+import java.awt.Graphics;
+import java.awt.Graphics2D;
+
+import javax.swing.JPanel;
+
+import io.github.manishdait.jplotlib.internals.util.Constants;
+
+/**
+ * The Border class represents a class for building and drawing axis border in
+ * Jplotlib charts.
+ *
+ * This class is used to create and draw the axis (X-axis and Y-axis) for
+ * Jplotlib charts. It provides functionality to build and render the axis with
+ * borders based on the provided Graphics object, AxisConfiguration, and JPanel
+ * context.
+ *
+ * The Border class is not intended for direct instantiation, as it serves as a
+ * class for specific axis implementations.
+ *
+ */
+class Border {
+ protected Graphics2D g;
+ protected JPanel context;
+
+ /**
+ * Constructs a new Border object with the specified Graphics, JPanel context.
+ *
+ * @param g
+ * the Graphics object used for drawing the axis.
+ * @param context
+ * the JPanel context within which the axis will be
+ * drawn.
+ */
+ public Border(Graphics g, JPanel context) {
+ this.g = (Graphics2D) g;
+ this.context = context;
+ }
+
+ /**
+ * Draws the borders for the X-axis and Y-axis of the chart.
+ */
+ public void drawBorder() {
+ this.g.setStroke(new BasicStroke(1.4F));
+ this.g.setColor(Color.BLACK);
+
+ int height = this.context.getHeight();
+ int width = this.context.getWidth();
+
+ this.g.drawLine(
+ Constants.MARGIN,
+ height - Constants.MARGIN,
+ width - Constants.MARGIN,
+ height - Constants.MARGIN);
+
+ this.g.drawLine(
+ Constants.MARGIN,
+ Constants.MARGIN,
+ Constants.MARGIN,
+ height - Constants.MARGIN);
+ }
+}
diff --git a/src/main/java/io/github/manishdait/jplotlib/internals/components/axis/Config.java b/src/main/java/io/github/manishdait/jplotlib/internals/components/axis/Config.java
new file mode 100755
index 0000000..e88b0f6
--- /dev/null
+++ b/src/main/java/io/github/manishdait/jplotlib/internals/components/axis/Config.java
@@ -0,0 +1,215 @@
+/*
+ * MIT License
+ *
+ * Copyright (c) 2023 Manish Dait
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+package io.github.manishdait.jplotlib.internals.components.axis;
+
+import io.github.manishdait.jplotlib.internals.util.AxisType;
+
+/**
+ * Configuration class for defining axis properties in a chart.
+ */
+public class Config {
+
+ private AxisType axisType;
+ private String title = "";
+ private String xLabel = "";
+ private String yLabel = "";
+
+ private int xIncrement;
+ private int yIncrement;
+
+ private int xUpperBound = 0;
+ private int yUpperBound = 0;
+
+ private int xLowerBound = Integer.MAX_VALUE;
+ private int yLowerBound = Integer.MAX_VALUE;
+
+ private int xValDiff;
+ private int yValDiff;
+
+ private int maxXLength = 0;
+ private int maxYLength = 0;
+
+ private int totalXLength = 0;
+ private int totalYLength = 0;
+
+ private int barLabelLen = 0;
+
+ private boolean xGrid;
+ private boolean yGrid;
+
+ public AxisType getAxisType() {
+ return axisType;
+ }
+
+ public void setAxisType(AxisType axisType) {
+ this.axisType = axisType;
+ }
+
+ public String getTitle() {
+ return title;
+ }
+
+ public void setTitle(String title) {
+ this.title = title;
+ }
+
+ public String getxLabel() {
+ return xLabel;
+ }
+
+ public void setxLabel(String xLabel) {
+ this.xLabel = xLabel;
+ }
+
+ public String getyLabel() {
+ return yLabel;
+ }
+
+ public void setyLabel(String yLabel) {
+ this.yLabel = yLabel;
+ }
+
+ public int getxIncrement() {
+ return xIncrement;
+ }
+
+ public void setxIncrement(int xIncrement) {
+ this.xIncrement = xIncrement;
+ }
+
+ public int getyIncrement() {
+ return yIncrement;
+ }
+
+ public void setyIncrement(int yIncrement) {
+ this.yIncrement = yIncrement;
+ }
+
+ public int getxUpperBound() {
+ return xUpperBound;
+
+ }
+
+ public void setxUpperBound(int xUpperBound) {
+ this.xUpperBound = xUpperBound;
+ }
+
+ public int getyUpperBound() {
+ return yUpperBound;
+ }
+
+ public void setyUpperBound(int yUpperBound) {
+ this.yUpperBound = yUpperBound;
+ }
+
+ public int getxLowerBound() {
+ return xLowerBound;
+ }
+
+ public void setxLowerBound(int xLowerBound) {
+ this.xLowerBound = xLowerBound;
+ }
+
+ public int getyLowerBound() {
+ return yLowerBound;
+ }
+
+ public void setyLowerBound(int yLowerBound) {
+ this.yLowerBound = yLowerBound;
+ }
+
+ public int getMaxXLength() {
+ return maxXLength;
+ }
+
+ public void setMaxXLength(int maxXLength) {
+ this.maxXLength = maxXLength;
+ }
+
+ public int getMaxYLength() {
+ return maxYLength;
+ }
+
+ public void setMaxYLength(int maxYLength) {
+ this.maxYLength = maxYLength;
+ }
+
+ public int getTotalXLength() {
+ return totalXLength;
+ }
+
+ public void setTotalXLength(int totalXLength) {
+ this.totalXLength = totalXLength;
+ }
+
+ public int getTotalYLength() {
+ return totalYLength;
+ }
+
+ public void setTotalYLength(int totalYLength) {
+ this.totalYLength = totalYLength;
+ }
+
+ public int getxValDiff() {
+ return xValDiff;
+ }
+
+ public void setxValDiff(int xValDiff) {
+ this.xValDiff = xValDiff;
+ }
+
+ public int getyValDiff() {
+ return yValDiff;
+ }
+
+ public void setyValDiff(int yValDiff) {
+ this.yValDiff = yValDiff;
+ }
+
+ public int getBarLabelLen() {
+ return barLabelLen;
+ }
+
+ public void setBarLabelLen(int barLabelsLen) {
+ this.barLabelLen = barLabelsLen;
+ }
+
+ public boolean isxGrid() {
+ return xGrid;
+ }
+
+ public void setxGrid(boolean xGrid) {
+ this.xGrid = xGrid;
+ }
+
+ public boolean isyGrid() {
+ return yGrid;
+ }
+
+ public void setyGrid(boolean yGrid) {
+ this.yGrid = yGrid;
+ }
+
+}
diff --git a/src/main/java/io/github/manishdait/jplotlib/internals/components/axis/Coordinate.java b/src/main/java/io/github/manishdait/jplotlib/internals/components/axis/Coordinate.java
new file mode 100755
index 0000000..5df71a8
--- /dev/null
+++ b/src/main/java/io/github/manishdait/jplotlib/internals/components/axis/Coordinate.java
@@ -0,0 +1,218 @@
+/*
+ * MIT License
+ *
+ * Copyright (c) 2023 Manish Dait
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+package io.github.manishdait.jplotlib.internals.components.axis;
+
+import java.awt.Font;
+import java.awt.Graphics;
+import java.awt.Graphics2D;
+import java.awt.RenderingHints;
+import java.util.Map;
+
+import javax.swing.JPanel;
+
+import io.github.manishdait.jplotlib.data.GraphData;
+import io.github.manishdait.jplotlib.data.util.DataDiffer;
+import io.github.manishdait.jplotlib.internals.util.AxisType;
+import io.github.manishdait.jplotlib.internals.util.Constants;
+
+/**
+ * The Coordinate class represents an axis layout and labeling component for
+ * Jplotlib charts.
+ *
+ * This class is responsible for labeling coordinates of the X-axis and Y-axis
+ * of Jplotlib charts. It calculates the axis tange, increments, and ticks based
+ * on the provided Graphics, JPanel context, and AxisConfiguration data.
+ * The coordinates are rendered dynamically based on the data points and chart
+ * type.
+ *
+ * The Coordinate class is not intended for direct instantiation, as it is
+ * internally used by Jplotlib.
+ *
+ */
+class Coordinate {
+
+ private Graphics2D g;
+ private Config axisConfiguration;
+ private int heigth;
+ private int width;
+
+ protected Coordinate() {
+ }
+
+ /**
+ * Constructs a new Coordinate object with the specified Graphics, JPanel
+ * context, and AxisConfiguration.
+ *
+ * @param g
+ * the Graphics object used for drawing the axes.
+ * @param context
+ * the JPanel context within which the axes will be
+ * drawn.
+ * @param axisConfiguration
+ * the Configuration for rendering axis.
+ */
+ public Coordinate(Graphics g, JPanel context, Config axisConfiguration) {
+ this.g = (Graphics2D) g;
+ this.axisConfiguration = axisConfiguration;
+ this.g.setRenderingHint(
+ RenderingHints.KEY_TEXT_ANTIALIASING,
+ RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
+ this.g.setRenderingHint(
+ RenderingHints.KEY_RENDERING,
+ RenderingHints.VALUE_RENDER_QUALITY);
+ this.heigth = context.getHeight();
+ this.width = context.getWidth();
+ }
+
+ /**
+ * Draws the X-axis and Y-axis coordinates,and ticks based on the
+ * AxisConfiguration.
+ */
+ public void drawCoordinates() {
+ if (axisConfiguration.getAxisType() != AxisType.BAR) {
+ baseLayout();
+ } else {
+ barLayout();
+ }
+ }
+
+ private void baseLayout() {
+ int xRange = axisConfiguration.getxUpperBound() - axisConfiguration.getxLowerBound();
+ int xValDiff = DataDiffer.getValDiff(xRange, axisConfiguration.getTotalXLength());
+
+ int totalX = getTotalTicks(xRange, xValDiff);
+ int xIncrement = getIncrement(width, totalX);
+
+ axisConfiguration.setxValDiff(xValDiff);
+ axisConfiguration.setxIncrement(xIncrement);
+
+ int yRange = axisConfiguration.getyUpperBound() - axisConfiguration.getyLowerBound();
+ int yValDiff = DataDiffer.getValDiff(yRange, axisConfiguration.getTotalYLength());
+
+ int totalY = getTotalTicks(yRange, yValDiff);
+ int yIncrement = getIncrement(heigth, totalY);
+
+ axisConfiguration.setyValDiff(yValDiff);
+ axisConfiguration.setyIncrement(yIncrement);
+
+ int extraSpace = (int) (Math.min(xIncrement, yIncrement) * 0.5) - 2;
+ g.setFont(new Font("Arial", Font.PLAIN, 11));
+
+ for (int i = 0; i <= totalX; i++) {
+ int x = Constants.MARGIN + xIncrement * i;
+ int y = heigth - Constants.MARGIN + 14;
+ int val = xValDiff * i + axisConfiguration.getxLowerBound();
+ this.g.drawString(Integer.toString(val), x + extraSpace, y);
+ }
+
+ for (int i = 0; i <= (totalY); i++) {
+ int y = heigth - Constants.MARGIN - yIncrement * i;
+ int val = yValDiff * i + axisConfiguration.getyLowerBound();
+ int x = Constants.MARGIN - (String.valueOf(val).length() * 8);
+ this.g.drawString(Integer.toString(val), x, y - extraSpace);
+ }
+ }
+
+ private void barLayout() {
+ g.setFont(new Font("Arial", Font.PLAIN, 11));
+ if (!GraphData.isX()) {
+ int totalX = axisConfiguration.getBarLabelLen();
+ int xIncrement = getIncrement(width, totalX * 2);
+
+ int indx = 0;
+ for (Map.Entry set : GraphData.getMap().entrySet()) {
+ int x = Constants.MARGIN + (xIncrement * (indx * 2 + 1));
+ int y = heigth - Constants.MARGIN + 20;
+ this.g.drawString(set.getKey(), x, y);
+ indx += 1;
+ }
+
+ axisConfiguration.setxIncrement(xIncrement);
+
+ int yRange = axisConfiguration.getyUpperBound() - axisConfiguration.getyLowerBound();
+ int yValDiff = DataDiffer.getValDiff(
+ yRange,
+ axisConfiguration.getTotalYLength());
+ int totalY = getTotalTicks(yRange, yValDiff);
+ int yIncrement = getIncrement(this.heigth, totalY);
+
+ axisConfiguration.setyValDiff(yValDiff);
+ axisConfiguration.setxValDiff(yValDiff);
+ axisConfiguration.setyIncrement(yIncrement);
+
+ int extraSpace = (int) (Math.min(xIncrement, yIncrement) * 0.5);
+
+ for (int i = 0; i <= totalY; i++) {
+ int y = heigth - Constants.MARGIN - yIncrement * i;
+ int val = yValDiff * i + axisConfiguration.getyLowerBound();
+ int x = Constants.MARGIN - (String.valueOf(val).length() * 9);
+ this.g.drawString(Integer.toString(val), x, y - extraSpace);
+ }
+ } else {
+ int totalY = axisConfiguration.getBarLabelLen();
+ int yIncrement = getIncrement(heigth, totalY * 2);
+
+ int indx = 0;
+ for (Map.Entry set : GraphData.getMap().entrySet()) {
+ String val = set.getKey();
+ int x = Constants.MARGIN - (String.valueOf(val).length() * 9);
+ int y = this.heigth - Constants.MARGIN - yIncrement * (indx * 2 + 1);
+ this.g.drawString(val, x, y);
+ indx += 1;
+ }
+
+ axisConfiguration.setyIncrement(yIncrement);
+
+ int xRange = axisConfiguration.getxUpperBound() - axisConfiguration.getxLowerBound();
+ int xValDiff = DataDiffer.getValDiff(
+ xRange,
+ axisConfiguration.getTotalXLength());
+ int totalX = getTotalTicks(xRange, xValDiff);
+ int xIncrement = getIncrement(this.width, totalX);
+
+ axisConfiguration.setyValDiff(xValDiff);
+ axisConfiguration.setxValDiff(xValDiff);
+ axisConfiguration.setxIncrement(xIncrement);
+
+ int extraSpace = (int) (Math.min(xIncrement, yIncrement) * 0.5);
+
+ for (int i = 0; i <= totalX; i++) {
+ int x = Constants.MARGIN + xIncrement * i;
+ int y = heigth - Constants.MARGIN + 14;
+ int val = xValDiff * i + axisConfiguration.getxLowerBound();
+ this.g.drawString(Integer.toString(val), x + extraSpace, y);
+ }
+ }
+ }
+
+ protected int getIncrement(int width, int total) {
+ return (width - Constants.MARGIN * 2) / (total + 1);
+ }
+
+ protected int getTotalTicks(int range, int valDiff) {
+ return (range % valDiff) == 0 ? (range / valDiff) : (range / valDiff) + 1;
+ }
+
+}
diff --git a/src/main/java/io/github/manishdait/jplotlib/internals/components/axis/Grid.java b/src/main/java/io/github/manishdait/jplotlib/internals/components/axis/Grid.java
new file mode 100755
index 0000000..73c46a6
--- /dev/null
+++ b/src/main/java/io/github/manishdait/jplotlib/internals/components/axis/Grid.java
@@ -0,0 +1,209 @@
+/*
+ * MIT License
+ *
+ * Copyright (c) 2023 Manish Dait
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+package io.github.manishdait.jplotlib.internals.components.axis;
+
+import java.awt.BasicStroke;
+import java.awt.Color;
+import java.awt.Graphics;
+import java.awt.Graphics2D;
+
+import javax.swing.JPanel;
+
+import io.github.manishdait.jplotlib.data.GraphData;
+import io.github.manishdait.jplotlib.internals.util.AxisType;
+import io.github.manishdait.jplotlib.internals.util.Constants;
+
+/**
+ * The Grid class is responsible for drawing the grid lines on the chart.
+ *
+ * This class provides methods to build the grid lines for different chart
+ * types, including regular plot charts and bar charts. The grid lines are drawn
+ * based on the data points and axis bounds provided in the AixsConfiguration
+ * object.
+ *
+ * The Grid class is used internally by the Jplotlib library and is not intended
+ * to be used directly by users.
+ *
+ */
+class Grid {
+
+ private Graphics2D g;
+ private Config axisConfiguration;
+ private JPanel context;
+
+ int xTotalPoints;
+ int yTotalPoints;
+
+ int xBounds;
+ int yBounds;
+
+ int xValDiff;
+ int yValDiff;
+
+ /**
+ * Constructs a Grid object with the specified graphics, JPanel context,
+ * and axisConfiguration.
+ *
+ * @param g
+ * the graphics context for drawing the grid lines.
+ * @param context
+ * the chart context (JPanel) where the grid lines will
+ * be
+ * drawn.
+ * @param axisConfiguration
+ * the Configuration for rendering axis.
+ */
+ public Grid(Graphics g, JPanel context, Config axisConfiguration) {
+ this.g = (Graphics2D) g;
+ this.axisConfiguration = axisConfiguration;
+ this.context = context;
+ }
+
+ /**
+ * Builds the grid lines for the chart based on the chart type (plot or bar).
+ */
+ public void buildGrid() {
+
+ this.g.setColor(new Color(231, 231, 231));
+ this.g.setStroke(new BasicStroke(1.4F));
+
+ xBounds = axisConfiguration.getxUpperBound() - axisConfiguration.getxLowerBound();
+ yBounds = axisConfiguration.getyUpperBound() - axisConfiguration.getyLowerBound();
+
+ xValDiff = axisConfiguration.getxValDiff();
+ yValDiff = axisConfiguration.getyValDiff();
+
+ xTotalPoints = xBounds / xValDiff;
+ yTotalPoints = yBounds / yValDiff;
+
+ xTotalPoints = (xBounds % xValDiff) == 0 ? xTotalPoints : xTotalPoints + 1;
+ yTotalPoints = (yBounds % yValDiff) == 0 ? yTotalPoints : yTotalPoints + 1;
+
+ if (axisConfiguration.getAxisType() != AxisType.BAR) {
+ baseGrid();
+ } else {
+ barGrid();
+ }
+
+ }
+
+ /**
+ * Draws the grid lines for regular plot charts.
+ */
+ private void baseGrid() {
+ int xIncrement = this.axisConfiguration.getxIncrement();
+ int yIncrement = this.axisConfiguration.getyIncrement();
+
+ int extraSpace = (int) (Math.min(xIncrement, yIncrement) * 0.5);
+
+ if (this.axisConfiguration.isxGrid()) {
+ for (int i = 0; i <= xTotalPoints; i++) {
+ int x = Constants.MARGIN + (xIncrement * i) + extraSpace;
+ this.g.drawLine(
+ x,
+ Constants.MARGIN + 1,
+ x,
+ this.context.getHeight() - Constants.MARGIN - 1);
+ }
+ }
+
+ if (this.axisConfiguration.isyGrid()) {
+ for (int i = 0; i <= yTotalPoints; i++) {
+ int y = this.context.getHeight() - Constants.MARGIN - (yIncrement * i);
+ this.g.drawLine(
+ Constants.MARGIN + 1,
+ y - extraSpace,
+ this.context.getWidth() - Constants.MARGIN - 1,
+ y - extraSpace);
+ }
+ }
+ }
+
+ /**
+ * Draws the grid lines for bar charts.
+ */
+ private void barGrid() {
+ if (!GraphData.isX()) {
+ plotBarGridForX();
+ } else {
+ int xIncrement = this.axisConfiguration.getxIncrement();
+ int yIncrement = this.axisConfiguration.getyIncrement();
+
+ int extraSpace = (int) (Math.min(xIncrement, yIncrement) * 0.5);
+
+ if (this.axisConfiguration.isxGrid()) {
+ for (int i = 0; i <= xTotalPoints; i++) {
+ int x = Constants.MARGIN + xIncrement * i;
+ this.g.drawLine(
+ x + extraSpace,
+ Constants.MARGIN,
+ x + extraSpace,
+ this.context.getHeight() - Constants.MARGIN);
+ }
+ }
+
+ if (this.axisConfiguration.isyGrid()) {
+ for (int i = 0; i < axisConfiguration.getBarLabelLen(); i++) {
+ int y = this.context.getHeight() - Constants.MARGIN - yIncrement * (i * 2 + 1);
+ this.g.drawLine(
+ Constants.MARGIN,
+ y,
+ this.context.getWidth() - Constants.MARGIN,
+ y);
+ }
+ }
+ }
+ }
+
+ private void plotBarGridForX() {
+ int xIncrement = this.axisConfiguration.getxIncrement();
+ int yIncrement = this.axisConfiguration.getyIncrement();
+
+ int extraSpace = (int) (Math.min(xIncrement, yIncrement) * 0.5);
+
+ if (this.axisConfiguration.isxGrid()) {
+ for (int i = 0; i < axisConfiguration.getBarLabelLen(); i++) {
+ int x = Constants.MARGIN + (xIncrement * (i * 2 + 1));
+ this.g.drawLine(
+ x,
+ Constants.MARGIN,
+ x,
+ this.context.getHeight() - Constants.MARGIN);
+ }
+ }
+
+ if (this.axisConfiguration.isyGrid()) {
+ for (int i = 0; i <= yTotalPoints; i++) {
+ int y = this.context.getHeight() - Constants.MARGIN - (yIncrement * i);
+ this.g.drawLine(
+ Constants.MARGIN,
+ y - extraSpace,
+ this.context.getWidth() - Constants.MARGIN,
+ y - extraSpace);
+ }
+ }
+ }
+
+}
diff --git a/src/main/java/io/github/manishdait/jplotlib/internal/component/label/AxisLabel.java b/src/main/java/io/github/manishdait/jplotlib/internals/components/label/AxisLabel.java
old mode 100644
new mode 100755
similarity index 84%
rename from src/main/java/io/github/manishdait/jplotlib/internal/component/label/AxisLabel.java
rename to src/main/java/io/github/manishdait/jplotlib/internals/components/label/AxisLabel.java
index e6e1672..cacc4ae
--- a/src/main/java/io/github/manishdait/jplotlib/internal/component/label/AxisLabel.java
+++ b/src/main/java/io/github/manishdait/jplotlib/internals/components/label/AxisLabel.java
@@ -22,7 +22,7 @@
* SOFTWARE.
*/
-package io.github.manishdait.jplotlib.internal.component.label;
+package io.github.manishdait.jplotlib.internals.components.label;
import java.awt.Font;
@@ -38,19 +38,17 @@
*
* The AxisLabel is not intended for direct instantiation, as it is used
* internally by Jplotlib to create axis labels.
- *
*
*/
-
public class AxisLabel extends JLabel {
-
- /**
- * Constructs a new AxisLabel with default settings.
- */
- public AxisLabel() {
- super();
- super.setHorizontalAlignment(CENTER);
- super.setFont(new Font("Arial", Font.BOLD, 12));
- }
+
+ /**
+ * Constructs a new AxisLabel with default settings.
+ */
+ public AxisLabel() {
+ super();
+ super.setHorizontalAlignment(CENTER);
+ super.setFont(new Font("Arial", Font.BOLD, 12));
+ }
}
diff --git a/src/main/java/io/github/manishdait/jplotlib/internal/component/label/TitleLabel.java b/src/main/java/io/github/manishdait/jplotlib/internals/components/label/TitleLabel.java
old mode 100644
new mode 100755
similarity index 82%
rename from src/main/java/io/github/manishdait/jplotlib/internal/component/label/TitleLabel.java
rename to src/main/java/io/github/manishdait/jplotlib/internals/components/label/TitleLabel.java
index 3ee8eb9..8495149
--- a/src/main/java/io/github/manishdait/jplotlib/internal/component/label/TitleLabel.java
+++ b/src/main/java/io/github/manishdait/jplotlib/internals/components/label/TitleLabel.java
@@ -22,35 +22,33 @@
* SOFTWARE.
*/
-package io.github.manishdait.jplotlib.internal.component.label;
+package io.github.manishdait.jplotlib.internals.components.label;
import java.awt.Font;
import javax.swing.JLabel;
/**
- * The TitleLabel class represents a label used for chart titles in Jplotlib
+ * The TitleLabel class represents a label used for chart titles in Jplotlib
* charts.
*
- * This class extends the JLabel class and provides additional functionality
- * specific to chart titles, such as centering the text and setting a default
+ * This class extends the JLabel class and provides additional functionality
+ * specific to chart titles, such as centering the text and setting a default
* font.
*
- * The TitleLabel is not intended for direct instantiation, as it is used
+ * The TitleLabel is not intended for direct instantiation, as it is used
* internally by Jplotlib to create chart titles.
*
- *
*/
-
public class TitleLabel extends JLabel {
-
- /**
- * Constructs a new TitleLabel with default settings.
- */
- public TitleLabel() {
- super();
- super.setHorizontalAlignment(CENTER);
- super.setFont(new Font("Arial", Font.BOLD, 16));
- }
+
+ /**
+ * Constructs a new TitleLabel with default settings.
+ */
+ public TitleLabel() {
+ super();
+ super.setHorizontalAlignment(CENTER);
+ super.setFont(new Font("Arial", Font.BOLD, 16));
+ }
}
diff --git a/src/main/java/io/github/manishdait/jplotlib/internal/component/label/VerticalAxisLabel.java b/src/main/java/io/github/manishdait/jplotlib/internals/components/label/VerticalAxisLabel.java
old mode 100644
new mode 100755
similarity index 66%
rename from src/main/java/io/github/manishdait/jplotlib/internal/component/label/VerticalAxisLabel.java
rename to src/main/java/io/github/manishdait/jplotlib/internals/components/label/VerticalAxisLabel.java
index 67565dc..36de6c8
--- a/src/main/java/io/github/manishdait/jplotlib/internal/component/label/VerticalAxisLabel.java
+++ b/src/main/java/io/github/manishdait/jplotlib/internals/components/label/VerticalAxisLabel.java
@@ -22,14 +22,14 @@
* SOFTWARE.
*/
-package io.github.manishdait.jplotlib.internal.component.label;
+package io.github.manishdait.jplotlib.internals.components.label;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Graphics2D;
/**
- * The VerticalAxisLabel class represents a label used for vertical axis titles
+ * The VerticalAxisLabel class represents a label used for vertical axis titles
* in Jplotlib charts.
*
* This class extends the AxisLabel class and provides additional functionality
@@ -39,39 +39,36 @@
* The VerticalAxisLabel is not intended for direct instantiation, as it is used
* internally by Jplotlib to create vertical axis labels.
*
- *
*/
-
public class VerticalAxisLabel extends AxisLabel {
- /**
- * Constructs a new VerticalAxisLabel with default settings.
- */
- public VerticalAxisLabel() {
- super();
- super.setHorizontalAlignment(CENTER);
- super.setVerticalAlignment(TOP);
- }
-
- @Override
- public void paintComponent(Graphics g) {
- Graphics2D g2d = (Graphics2D) g.create();
- int labelWidth = getWidth();
- int labelHeight = getHeight();
- int centerX = labelWidth / 2;
- int centerY = labelHeight / 2;
+ /**
+ * Constructs a new VerticalAxisLabel with default settings.
+ */
+ public VerticalAxisLabel() {
+ super();
+ super.setHorizontalAlignment(CENTER);
+ super.setVerticalAlignment(TOP);
+ }
- g2d.translate(centerX, centerY);
+ @Override
+ public void paintComponent(Graphics g) {
+ Graphics2D g2d = (Graphics2D) g.create();
+ int labelWidth = getWidth();
+ int labelHeight = getHeight();
+ int centerX = labelWidth / 2;
+ int centerY = labelHeight / 2;
- g2d.rotate(Math.toRadians(-90));
+ g2d.translate(centerX, centerY);
- FontMetrics fm = g2d.getFontMetrics();
- int textWidth = fm.stringWidth(getText());
- int textHeight = fm.getHeight();
- g2d.drawString(getText(), -textWidth / 2, textHeight / 4);
+ g2d.rotate(Math.toRadians(-90));
- g2d.dispose();
+ FontMetrics fm = g2d.getFontMetrics();
+ int textWidth = fm.stringWidth(getText());
+ int textHeight = fm.getHeight();
+ g2d.drawString(getText(), -textWidth / 2, textHeight / 4);
- }
+ g2d.dispose();
+ }
}
diff --git a/src/main/java/io/github/manishdait/jplotlib/internal/util/AxisType.java b/src/main/java/io/github/manishdait/jplotlib/internals/util/AxisType.java
old mode 100644
new mode 100755
similarity index 64%
rename from src/main/java/io/github/manishdait/jplotlib/internal/util/AxisType.java
rename to src/main/java/io/github/manishdait/jplotlib/internals/util/AxisType.java
index 3b6f0c3..41264d4
--- a/src/main/java/io/github/manishdait/jplotlib/internal/util/AxisType.java
+++ b/src/main/java/io/github/manishdait/jplotlib/internals/util/AxisType.java
@@ -22,58 +22,55 @@
* SOFTWARE.
*/
-package io.github.manishdait.jplotlib.internal.util;
+package io.github.manishdait.jplotlib.internals.util;
/**
* The AxisType enum represents the types of axes used in Jplotlib charts.
*
- * This enum provides three values for different chart types: PLOT, BAR, and
+ * This enum provides three values for different chart types: PLOT, BAR, and
* PIE. Each value has a corresponding priority, which determines the order in
* which the axes are rendered.
*
* The AxisType enum is used to indicate the type of axis to be used in a
* particular chart.
*
- *
*/
-
public enum AxisType {
-
- /**
- * The PLOT axis type represents a regular plot chart with X and Y axes.
- */
- PLOT(1),
- /**
- * The BAR axis type represents a bar chart with X and Y axes.
- */
- BAR(2),
+ /**
+ * The PLOT axis type represents a regular plot chart with X and Y axes.
+ */
+ PLOT(1),
- /**
- * The PIE axis type represents a pie chart with no traditional X and Y axes.
- */
- PIE(3);
-
- private int priority;
+ /**
+ * The BAR axis type represents a bar chart with X and Y axes.
+ */
+ BAR(2),
+ /**
+ * The PIE axis type represents a pie chart with no traditional X and Y axes.
+ */
+ PIE(3);
+ private int priority;
- /**
- * Constructs an AxisType enum with the specified priority.
- *
- * @param priority the priority of the axis type, used for rendering order.
- */
- AxisType(int priority) {
- this.priority = priority;
- }
+ /**
+ * Constructs an AxisType enum with the specified priority.
+ *
+ * @param priority
+ * the priority of the axis type, used for rendering order.
+ */
+ AxisType(int priority) {
+ this.priority = priority;
+ }
- /**
- * Gets the priority value of the axis type.
- *
- * @return the priority value.
- */
- public int getPriority() {
- return this.priority;
- }
+ /**
+ * Gets the priority value of the axis type.
+ *
+ * @return the priority value.
+ */
+ public int getPriority() {
+ return this.priority;
+ }
}
diff --git a/src/main/java/io/github/manishdait/jplotlib/internal/util/ChartType.java b/src/main/java/io/github/manishdait/jplotlib/internals/util/ChartType.java
old mode 100644
new mode 100755
similarity index 78%
rename from src/main/java/io/github/manishdait/jplotlib/internal/util/ChartType.java
rename to src/main/java/io/github/manishdait/jplotlib/internals/util/ChartType.java
index 99b9079..d5f5ce4
--- a/src/main/java/io/github/manishdait/jplotlib/internal/util/ChartType.java
+++ b/src/main/java/io/github/manishdait/jplotlib/internals/util/ChartType.java
@@ -22,42 +22,40 @@
* SOFTWARE.
*/
-package io.github.manishdait.jplotlib.internal.util;
+package io.github.manishdait.jplotlib.internals.util;
/**
- * The ChartType enum represents the types of charts that can be created using
+ * The ChartType enum represents the types of charts that can be created using
* Jplotlib.
*
* This enum provides four values for different chart types: LINE, SCATTER, BAR,
- * and PIE. Each value corresponds to a specific type of chart that can be
+ * and PIE. Each value corresponds to a specific type of chart that can be
* generated using Jplotlib.
*
- * The ChartType enum is used to specify the type of chart to be created in
+ * The ChartType enum is used to specify the type of chart to be created in
* Jplotlib.
*
- *
*/
-
public enum ChartType {
- /**
- * The LINE chart type represents a line plot.
- */
- LINE,
-
- /**
- * The SCATTER chart type represents a scatter plot.
- */
- SCATTER,
-
- /**
- * The BAR chart type represents a bar chart.
- */
- BAR,
-
- /**
- * The PIE chart type represents a pie chart.
- */
- PIE;
+ /**
+ * The LINE chart type represents a line plot.
+ */
+ LINE,
+
+ /**
+ * The SCATTER chart type represents a scatter plot.
+ */
+ SCATTER,
+
+ /**
+ * The BAR chart type represents a bar chart.
+ */
+ BAR,
+
+ /**
+ * The PIE chart type represents a pie chart.
+ */
+ PIE;
}
diff --git a/src/main/java/io/github/manishdait/jplotlib/internal/util/Constants.java b/src/main/java/io/github/manishdait/jplotlib/internals/util/Constants.java
old mode 100644
new mode 100755
similarity index 61%
rename from src/main/java/io/github/manishdait/jplotlib/internal/util/Constants.java
rename to src/main/java/io/github/manishdait/jplotlib/internals/util/Constants.java
index 2ccce5c..f424957
--- a/src/main/java/io/github/manishdait/jplotlib/internal/util/Constants.java
+++ b/src/main/java/io/github/manishdait/jplotlib/internals/util/Constants.java
@@ -22,7 +22,7 @@
* SOFTWARE.
*/
-package io.github.manishdait.jplotlib.internal.util;
+package io.github.manishdait.jplotlib.internals.util;
/**
* The Constants class contains various constant values used in the Jplotlib
@@ -36,42 +36,44 @@
*
*
*/
-
public class Constants {
-
- /**
- * The name of the chart provider (Jplotlib).
- */
- public static final String PROVIDER = "io.github.manishdait.jplotlib.Jplotlib";
+ private Constants() {
+ throw new IllegalStateException("Constant class can not be instantiated");
+ }
+
+ /**
+ * The name of the chart provider (Jplotlib).
+ */
+ public static final String PROVIDER = "io.github.manishdait.jplotlib.Jplotlib";
- /**
- * The default width of the chart.
- */
- public static final int WIDTH = 750;
+ /**
+ * The default width of the chart.
+ */
+ public static final int WIDTH = 750;
- /**
- * The default height of the chart.
- */
- public static final int HEIGTH = 600;
+ /**
+ * The default height of the chart.
+ */
+ public static final int HEIGTH = 600;
- /**
- * The margin size for the chart.
- */
- public static final int MARGIN = 90;
+ /**
+ * The margin size for the chart.
+ */
+ public static final int MARGIN = 90;
- /**
- * The minimum scale value for markers.
- */
- public static final int MIN_MARKER_SCALE = 5;
+ /**
+ * The minimum scale value for markers.
+ */
+ public static final int MIN_MARKER_SCALE = 5;
- /**
- * The maximum scale value for markers.
- */
- public static final int MAX_MARKER_SCALE = 50;
+ /**
+ * The maximum scale value for markers.
+ */
+ public static final int MAX_MARKER_SCALE = 50;
- /**
- * The default scale value for markers.
- */
- public static final int DEFAULT_MARKER_SCALE = 10;
+ /**
+ * The default scale value for markers.
+ */
+ public static final int DEFAULT_MARKER_SCALE = 10;
}
diff --git a/src/main/java/io/github/manishdait/jplotlib/plotter/SeriesPlotter.java b/src/main/java/io/github/manishdait/jplotlib/plotter/SeriesPlotter.java
deleted file mode 100644
index 4f1794b..0000000
--- a/src/main/java/io/github/manishdait/jplotlib/plotter/SeriesPlotter.java
+++ /dev/null
@@ -1,118 +0,0 @@
-/*
- * MIT License
- *
- * Copyright (c) 2023 Manish Dait
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-package io.github.manishdait.jplotlib.plotter;
-
-import java.awt.Graphics;
-import java.util.List;
-
-import javax.swing.JPanel;
-
-import io.github.manishdait.jplotlib.chart.BarGraphBuilder;
-import io.github.manishdait.jplotlib.chart.LineGraphBuilder;
-import io.github.manishdait.jplotlib.chart.PieChartBuilder;
-import io.github.manishdait.jplotlib.chart.ScatterGraphBuilder;
-import io.github.manishdait.jplotlib.data.SeriesData;
-import io.github.manishdait.jplotlib.data.StyleData;
-import io.github.manishdait.jplotlib.internal.util.AxisType;
-
-
-/**
- * The SeriesPlotter class is responsible for drawing series plots based on the
- * provided SeriesData and StyleData.
- *
- *
- */
-
-public class SeriesPlotter extends JPanel {
-
- private SeriesData seriesData;
- private List styleData;
-
- /**
- * Creates a new SeriesPlotter with the given SeriesData and StyleData.
- *
- * @param seriesData The data for the series plot.
- * @param styleData The style data for the series plot.
- */
- public SeriesPlotter(SeriesData seriesData, List styleData) {
- this.seriesData = seriesData;
- this.styleData = styleData;
- }
-
- @Override
- public void paintComponent(Graphics g) {
- if(seriesData.axisType != AxisType.PIE) {
- for(int i = 0; i < styleData.size(); i++) {
- switch (styleData.get(i).getChartType()) {
- case LINE:
- new LineGraphBuilder(
- g,
- this,
- seriesData,
- styleData.get(i).getLineSeries(),
- i
- ).draw();
- break;
-
- case SCATTER:
- new ScatterGraphBuilder(
- g,
- this,
- seriesData,
- styleData.get(i).getScatterSeries(),
- i
- ).draw();
- break;
-
- case BAR:
- new BarGraphBuilder(
- g,
- this,
- seriesData,
- styleData.get(i).getBarSeries(),
- i
- ).draw();
- break;
-
- default:
- throw new UnsupportedOperationException(
- "Unimplemented method 'draw'"
- );
- }
- }
- }
-
- else {
- new PieChartBuilder(
- g,
- this,
- seriesData,
- styleData.get(0).getPieSeries()
- ).draw();
- }
-
- }
-
-}
diff --git a/src/main/java/io/github/manishdait/jplotlib/ui/BaseFrame.java b/src/main/java/io/github/manishdait/jplotlib/ui/BaseFrame.java
deleted file mode 100644
index cc13547..0000000
--- a/src/main/java/io/github/manishdait/jplotlib/ui/BaseFrame.java
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * MIT License
- *
- * Copyright (c) 2023 Manish Dait
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-package io.github.manishdait.jplotlib.ui;
-
-import java.util.List;
-
-import javax.swing.JFrame;
-
-import io.github.manishdait.jplotlib.data.SeriesData;
-import io.github.manishdait.jplotlib.data.StyleData;
-import io.github.manishdait.jplotlib.internal.util.Constants;
-
-
-/**
- * The BaseFrame class represents a custom JFrame that serves as the base window
- * for displaying Jplotlib charts.
- *
- * This class extends the standard JFrame class and is used to create a window
- * that contains a ChartPanel for rendering the Jplotlib charts. It provides a
- * customizable interface for displaying various types of plots and data
- * visualizations.
- *
- * The BaseFrame is created with a specific SeriesData and a List of StyleData,
- * which define the data and styles for the charts to be displayed in the frame.
- *
- *
- */
-
-public class BaseFrame extends JFrame {
-
- private ChartPanel chartPanel;
-
- /**
- * Constructs a new BaseFrame with the specified SeriesData and List of
- * StyleData.
- *
- * @param seriesData the SeriesData containing the data points for the charts.
- * @param styleData the List of StyleData containing style information for the
- * charts.
- */
-
- public BaseFrame(SeriesData seriesData, List styleData) {
- this.setTitle(Constants.PROVIDER);
- this.setSize(Constants.WIDTH, Constants.HEIGTH);
- this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
-
- this.chartPanel = new ChartPanel(seriesData, styleData);
- this.chartPanel.setBounds(0, 0, this.getWidth(), this.getHeight());
- this.add(this.chartPanel);
- }
-
-}
diff --git a/src/main/java/io/github/manishdait/jplotlib/ui/ChartPanel.java b/src/main/java/io/github/manishdait/jplotlib/ui/ChartPanel.java
old mode 100644
new mode 100755
index a19776e..d18abb4
--- a/src/main/java/io/github/manishdait/jplotlib/ui/ChartPanel.java
+++ b/src/main/java/io/github/manishdait/jplotlib/ui/ChartPanel.java
@@ -24,122 +24,111 @@
package io.github.manishdait.jplotlib.ui;
+import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Graphics;
import java.util.List;
+import javax.swing.BorderFactory;
import javax.swing.JPanel;
-import io.github.manishdait.jplotlib.data.SeriesData;
-import io.github.manishdait.jplotlib.data.StyleData;
-import io.github.manishdait.jplotlib.internal.component.axis.AxisBuilder;
-import io.github.manishdait.jplotlib.internal.component.label.AxisLabel;
-import io.github.manishdait.jplotlib.internal.component.label.TitleLabel;
-import io.github.manishdait.jplotlib.internal.component.label.VerticalAxisLabel;
-import io.github.manishdait.jplotlib.internal.util.Constants;
-import io.github.manishdait.jplotlib.plotter.SeriesPlotter;
-
+import io.github.manishdait.jplotlib.charts.helper.Graph;
+import io.github.manishdait.jplotlib.charts.helper.GraphPlotter;
+import io.github.manishdait.jplotlib.internals.components.axis.Axis;
+import io.github.manishdait.jplotlib.internals.components.axis.Config;
+import io.github.manishdait.jplotlib.internals.components.label.AxisLabel;
+import io.github.manishdait.jplotlib.internals.components.label.TitleLabel;
+import io.github.manishdait.jplotlib.internals.components.label.VerticalAxisLabel;
+import io.github.manishdait.jplotlib.internals.util.Constants;
/**
- * The ChartPanel class represents a custom JPanel used for rendering Jplotlib
+ * The ChartPanel class represents a custom JPanel used for rendering Jplotlib
* charts and data visualizations.
*
- * This class extends the standard JPanel and provides functionality to display
- * a Jplotlib chart within a JPanel container. It dynamically renders the chart
- * based on the provided SeriesData and StyleData, ensuring that the chart is
- * properly displayed with the appropriate title, axis labels, and data points.
+ * This class extends the standard JPanel and provides functionality to display
+ * a Jplotlib chart within a JPanel container. It dynamically renders the chart
+ * based on the provided AxisConfiguration and Graphs, ensuring that the chart
+ * is properly displayed with the appropriate title, axis labels, and data points.
*
- * The ChartPanel handles the rendering of the chart by using the provided
- * Graphics object. It sets the title, x-axis label, and y-axis label, and then
- * plots the data points using the SeriesPlotter class.
+ * The ChartPanel handles the rendering of the chart by using the provided
+ * Graphics object. It sets the title, x-axis label, and y-axis label, and then
+ * plots the data points using the GraphPlotter class.
*
*
*/
-
public class ChartPanel extends JPanel {
- private SeriesData seriesData;
-
- private List styleData;
-
- private TitleLabel title = new TitleLabel();
- private AxisLabel xLabel = new AxisLabel();
- private VerticalAxisLabel yLabel = new VerticalAxisLabel();
-
- private JPanel graph = new JPanel();
-
- /**
- * Constructs a new ChartPanel with the specified SeriesData and List of
- * StyleData.
- *
- * @param seriesData the SeriesData containing the data points for the chart.
- * @param styleData the List of StyleData containing style information for the
- * chart.
- */
-
- public ChartPanel(SeriesData seriesData, List styleData) {
- super.setBackground(new Color(255, 255, 255, 255));
- this.seriesData = seriesData;
- this.styleData = styleData;
- }
-
- @Override
- public void paintComponent(Graphics g) {
- super.paintComponent(g);
-
- // Set title label
- this.title.setBounds(
- 0,
- 60,
- this.getWidth(),
- 20
- );
- this.title.setText(this.seriesData.getTitle());
- this.add(title);
-
- // Set xLabel label
- this.xLabel.setBounds(
- 0,
- this.getHeight() - 60,
- this.getWidth(),
- 20
- );
- this.xLabel.setText(this.seriesData.getxLabel());
- this.add(xLabel);
-
- // Set yLabel label
- this.yLabel.setBounds(
- 0,
- 0,
- 40,
- this.getHeight()
- );
- this.yLabel.setText(this.seriesData.getyLabel());
- this.add(yLabel);
-
- // Build and draw axes
- new AxisBuilder(g, this, seriesData).buildAxis();
-
- // Plot and draw graph
- setGraph(this.graph);
- plotGraph();
- }
-
- private void setGraph(JPanel graph) {
- this.remove(this.graph);
- this.graph = graph;
- this.graph.setBounds(
- Constants.MARGIN,
- Constants.MARGIN,
- this.getWidth() - (Constants.MARGIN * 2),
- this.getHeight() - (Constants.MARGIN * 2)
- );
- this.add(graph);
- }
-
- private void plotGraph() {
- JPanel graph = new SeriesPlotter(seriesData, styleData);
- setGraph(graph);
- }
+ private transient Config axisConfiguration;
+ private transient List graphs;
+
+ private TitleLabel title = new TitleLabel();
+ private AxisLabel xLabel = new AxisLabel();
+ private VerticalAxisLabel yLabel = new VerticalAxisLabel();
+
+ private JPanel graph = new JPanel();
+ private BorderLayout borderlayout = new BorderLayout();
+
+ /**
+ * Constructs a new ChartPanel with the specified AxisConfiguration and List of
+ * Graphs.
+ *
+ * @param axisConfiguration
+ * the AxisConfiguration defining rendering properties for the axis.
+ * @param graphs
+ * the List of Graphs containing style and data
+ * information
+ * for the charts.
+ *
+ */
+ public ChartPanel(Config axisConfiguration, List graphs) {
+ super.setBackground(new Color(255, 255, 255, 255));
+ this.axisConfiguration = axisConfiguration;
+ this.graphs = graphs;
+ this.setLayout(borderlayout);
+ this.setBorder(BorderFactory.createEmptyBorder(40, 10, 40, 10));
+
+ }
+
+ @Override
+ public void paintComponent(Graphics g) {
+ super.paintComponent(g);
+
+ // Set title label
+ this.title.setText(this.axisConfiguration.getTitle());
+ this.add(title, BorderLayout.NORTH);
+
+ // Set xLabel label
+ this.xLabel.setText(this.axisConfiguration.getxLabel());
+ this.add(xLabel, BorderLayout.SOUTH);
+
+ // Set yLabel label
+ this.yLabel.setText(this.axisConfiguration.getyLabel());
+ this.add(yLabel, BorderLayout.LINE_START);
+
+ // Build and draw axis
+ new Axis(g, this, axisConfiguration).drawAxis();
+ setGraph(this.graph);
+
+ // Plot and draw graph
+ plotGraph();
+
+ }
+
+ private void setGraph(JPanel graph) {
+ this.remove(this.graph);
+ this.graph = graph;
+ this.graph.setBounds(
+ Constants.MARGIN,
+ Constants.MARGIN,
+ this.getWidth() - (Constants.MARGIN * 2),
+ this.getHeight() - (Constants.MARGIN * 2));
+ this.add(graph, BorderLayout.CENTER);
+ }
+
+ private void plotGraph() {
+ JPanel plot = new GraphPlotter(axisConfiguration, graphs);
+ setGraph(plot);
+ this.repaint();
+ }
}
diff --git a/src/main/java/io/github/manishdait/jplotlib/ui/Window.java b/src/main/java/io/github/manishdait/jplotlib/ui/Window.java
new file mode 100755
index 0000000..4d4e0fc
--- /dev/null
+++ b/src/main/java/io/github/manishdait/jplotlib/ui/Window.java
@@ -0,0 +1,76 @@
+/*
+ * MIT License
+ *
+ * Copyright (c) 2023 Manish Dait
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+package io.github.manishdait.jplotlib.ui;
+
+import java.awt.BorderLayout;
+import java.util.List;
+
+import javax.swing.JFrame;
+
+import io.github.manishdait.jplotlib.charts.helper.Graph;
+import io.github.manishdait.jplotlib.internals.components.axis.Config;
+import io.github.manishdait.jplotlib.internals.util.Constants;
+
+/**
+ * The Window class represents a custom JFrame that serves as the base window
+ * for displaying Jplotlib charts.
+ *
+ * This class extends the standard JFrame class and is used to create a window
+ * that contains a ChartPanel for rendering the Jplotlib charts. It provides an
+ * interface for displaying various types of plots and data visualizations.
+ *
+ * The Window is created with a specific AxisConfiguration and a List of Graphs,
+ * which define the data and styles for the charts/graph to be displayed in the
+ * frame.
+ *
+ */
+public class Window extends JFrame {
+
+ private ChartPanel chartPanel;
+ private BorderLayout borderLayout = new BorderLayout();
+
+ /**
+ * Constructs a new Window with the specified AxisConfiguration and List of
+ * Graphs.
+ *
+ * @param axisConfiguration
+ * the AxisConfiguration defining rendering properties
+ * for the axis.
+ * @param graphs
+ * the List of Graph containing style and data
+ * information for the charts.
+ *
+ */
+ public Window(Config axisConfiguration, List graphs) {
+ this.setTitle(Constants.PROVIDER);
+ this.setSize(Constants.WIDTH, Constants.HEIGTH);
+ this.setLayout(borderLayout);
+ this.setDefaultCloseOperation(EXIT_ON_CLOSE);
+
+ this.chartPanel = new ChartPanel(axisConfiguration, graphs);
+ this.add(this.chartPanel, BorderLayout.CENTER);
+ }
+
+}
diff --git a/src/test/java/io/github/manishdait/jplotlib/JplotlibTest.java b/src/test/java/io/github/manishdait/jplotlib/JplotlibTest.java
old mode 100644
new mode 100755
index 37d4faa..b9dc13d
--- a/src/test/java/io/github/manishdait/jplotlib/JplotlibTest.java
+++ b/src/test/java/io/github/manishdait/jplotlib/JplotlibTest.java
@@ -1,15 +1,88 @@
package io.github.manishdait.jplotlib;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
-/**
- * Unit test for Jplotlib.
- */
+import io.github.manishdait.jplotlib.charts.bar.BarGraph;
+import io.github.manishdait.jplotlib.charts.line.LineChart;
+import io.github.manishdait.jplotlib.charts.pie.PieChart;
+import io.github.manishdait.jplotlib.charts.scatter.ScatterChart;
+
public class JplotlibTest {
+
+ @Test
+ public void testTitle() {
+ Jplotlib jplot = new Jplotlib();
+ jplot.title("Test Title");
+ assertEquals("Test Title", jplot.axisConfiguration.getTitle());
+ }
+
+ @Test
+ public void testXLabel() {
+ Jplotlib jplot = new Jplotlib();
+ jplot.xLabel("X Label Test");
+ assertEquals("X Label Test", jplot.axisConfiguration.getxLabel());
+ }
+
+ @Test
+ public void testYLabel() {
+ Jplotlib jplot = new Jplotlib();
+ jplot.yLabel("Y Label Test");
+ assertEquals("Y Label Test", jplot.axisConfiguration.getyLabel());
+ }
+
+ @Test
+ public void testGrid() {
+ Jplotlib jplot = new Jplotlib();
+ jplot.grid();
+ assertTrue(jplot.axisConfiguration.isxGrid());
+ assertTrue(jplot.axisConfiguration.isyGrid());
+ }
+
+ @Test
+ public void testGridX() {
+ Jplotlib jplot = new Jplotlib();
+ jplot.grid(true, false);
+ assertTrue(jplot.axisConfiguration.isxGrid());
+ assertTrue(!jplot.axisConfiguration.isyGrid());
+ }
+
+ @Test
+ public void testGridY() {
+ Jplotlib jplot = new Jplotlib();
+ jplot.grid(false, true);
+ assertTrue(!jplot.axisConfiguration.isxGrid());
+ assertTrue(jplot.axisConfiguration.isyGrid());
+ }
+
+ @Test
+ public void testPlot() {
+ Jplotlib jplot = new Jplotlib();
+ LineChart lineChart = jplot.plot(new double[]{1, 2, 3}, new double[]{4, 5, 6});
+ assertNotNull(lineChart);
+ }
+
+ @Test
+ public void testScatter() {
+ Jplotlib jplot = new Jplotlib();
+ ScatterChart scatterChart = jplot.scatter(new double[]{1, 2, 3}, new double[]{4, 5, 6});
+ assertNotNull(scatterChart);
+ }
+
+ @Test
+ public void testBar() {
+ Jplotlib jplot = new Jplotlib();
+ BarGraph barGraph = jplot.bar(new String[]{"A", "B", "C"}, new double[]{10, 20, 30});
+ assertNotNull(barGraph);
+ }
+
@Test
- public void shouldAnswerWithTrue() {
- assertTrue( true );
+ public void testPie() {
+ Jplotlib jplot = new Jplotlib();
+ PieChart pieChart = jplot.pie(new double[]{10, 20, 30});
+ assertNotNull(pieChart);
}
}
diff --git a/src/test/java/io/github/manishdait/jplotlib/data/CoordinatesTest.java b/src/test/java/io/github/manishdait/jplotlib/data/CoordinatesTest.java
deleted file mode 100644
index 4824799..0000000
--- a/src/test/java/io/github/manishdait/jplotlib/data/CoordinatesTest.java
+++ /dev/null
@@ -1,28 +0,0 @@
-package io.github.manishdait.jplotlib.data;
-
-import static org.junit.Assert.assertArrayEquals;
-
-import org.junit.Test;
-
-public class CoordinatesTest {
-
- private double[] testX = {1, 2, 3, 4, 5};
- private double[] testY = {20, 40, 60, 80, 100};
-
- @Test
- public void testGetXPoints() {
- Coordinates coordinates = new Coordinates();
- coordinates.setxPoints(testX);
-
- assertArrayEquals(testX, coordinates.getxPoints(), 0);
- }
-
- @Test
- public void testGetYPoints() {
- Coordinates coordinates = new Coordinates();
- coordinates.setyPoints(testY);
-
- assertArrayEquals(testY, coordinates.getyPoints(), 0);
- }
-
-}
diff --git a/src/test/java/io/github/manishdait/jplotlib/data/DiffCalTest.java b/src/test/java/io/github/manishdait/jplotlib/data/DiffCalTest.java
new file mode 100755
index 0000000..6058ac9
--- /dev/null
+++ b/src/test/java/io/github/manishdait/jplotlib/data/DiffCalTest.java
@@ -0,0 +1,30 @@
+package io.github.manishdait.jplotlib.data;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+import io.github.manishdait.jplotlib.data.util.DataDiffer;
+
+public class DiffCalTest {
+ @Test
+ public void shouldReturnOne() {
+ int range = 10;
+ int totalLength = 10;
+ assertEquals(1, DataDiffer.getValDiff(range, totalLength));
+ }
+
+ @Test
+ public void shouldReturnTen() {
+ int range = 100;
+ int totalLength = 10;
+ assertEquals(10, DataDiffer.getValDiff(range, totalLength));
+ }
+
+ @Test
+ public void shouldReturnFive() {
+ int range = 100;
+ int totalLength = 24;
+ assertEquals(5, DataDiffer.getValDiff(range, totalLength));
+ }
+}
diff --git a/src/test/java/io/github/manishdait/jplotlib/data/util/DataDiffTest.java b/src/test/java/io/github/manishdait/jplotlib/data/util/DataDiffTest.java
deleted file mode 100644
index 06f393f..0000000
--- a/src/test/java/io/github/manishdait/jplotlib/data/util/DataDiffTest.java
+++ /dev/null
@@ -1,30 +0,0 @@
-package io.github.manishdait.jplotlib.data.util;
-
-import static org.junit.Assert.assertEquals;
-
-import org.junit.Test;
-
-public class DataDiffTest {
-
- @Test
- public void testGetValDiff1() {
- double arr[] = {1, 2, 3, 4, 5};
- int expected = 1;
- assertEquals(expected, DataDiff.getValDiff(arr, arr.length));
- }
-
- @Test
- public void testGetValDiff2() {
- double arr[] = {1, 2, 3, 4, 20};
- int expected = 4;
- assertEquals(expected, DataDiff.getValDiff(arr, arr.length));
- }
-
- @Test
- public void testGetValDiff3() {
- double arr[] = {0, 0, 0, 0, 0, 0};
- int expected = 1;
- assertEquals(expected, DataDiff.getValDiff(arr, arr.length));
- }
-
-}
diff --git a/src/test/java/io/github/manishdait/jplotlib/data/util/PreProcessorTest.java b/src/test/java/io/github/manishdait/jplotlib/data/util/PreProcessorTest.java
deleted file mode 100644
index 50ff2e1..0000000
--- a/src/test/java/io/github/manishdait/jplotlib/data/util/PreProcessorTest.java
+++ /dev/null
@@ -1,95 +0,0 @@
-package io.github.manishdait.jplotlib.data.util;
-
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.junit.Test;
-
-import io.github.manishdait.jplotlib.data.Coordinates;
-
-public class PreProcessorTest {
-
- private double[] arr1 = {1, 2, 3, 4};
- private double[] arr2 = {10, 20, 30, 40, 50};
- List list = new ArrayList();
-
- @Test
- public void textProcessX() {
- Coordinates coordinates1 = new Coordinates();
- coordinates1.setxPoints(arr1);
-
- Coordinates coordinates2 = new Coordinates();
- coordinates2.setxPoints(arr2);
-
- list.add(coordinates1);
- list.add(coordinates2);
-
- double[] expected = {1, 2, 3, 4, 10, 20, 30, 40, 50};
-
- assertArrayEquals(expected, new PreProcessor().processX(list), 0);
- }
-
- @Test
- public void textProcessY() {
- Coordinates coordinates1 = new Coordinates();
- coordinates1.setyPoints(arr2);
-
- Coordinates coordinates2 = new Coordinates();
- coordinates2.setyPoints(arr1);
-
- list.add(coordinates1);
- list.add(coordinates2);
-
- double[] expected = {10, 20, 30, 40, 50, 1, 2, 3, 4};
-
- assertArrayEquals(expected, new PreProcessor().processY(list), 0);
- }
-
- @Test
- public void testGetMaxLengthX() {
- Coordinates coordinates1 = new Coordinates();
- coordinates1.setxPoints(arr1);
-
- Coordinates coordinates2 = new Coordinates();
- coordinates2.setxPoints(arr2);
-
- list.add(coordinates1);
- list.add(coordinates2);
-
- int expected = 5;
-
- assertEquals(expected, new PreProcessor().getMaxLengthX(list));
- }
-
- @Test
- public void testGetMaxLengthY() {
- Coordinates coordinates1 = new Coordinates();
- coordinates1.setyPoints(arr2);
-
- Coordinates coordinates2 = new Coordinates();
- coordinates2.setyPoints(arr1);
-
- list.add(coordinates1);
- list.add(coordinates2);
-
- int expected = 5;
-
- assertEquals(expected, new PreProcessor().getMaxLengthY(list));
- }
-
- @Test
- public void testGetUpperBound() {
- int expected = 50;
- assertEquals(expected, new PreProcessor().getUpperBound(arr2));
- }
-
- @Test
- public void testGetLowerBound() {
- int expected = 10;
- assertEquals(expected, new PreProcessor().getLowerBound(arr2));
- }
-
-}
diff --git a/src/test/java/io/github/manishdait/jplotlib/internals/components/axis/CoordinateTest.java b/src/test/java/io/github/manishdait/jplotlib/internals/components/axis/CoordinateTest.java
new file mode 100755
index 0000000..f5435f7
--- /dev/null
+++ b/src/test/java/io/github/manishdait/jplotlib/internals/components/axis/CoordinateTest.java
@@ -0,0 +1,32 @@
+package io.github.manishdait.jplotlib.internals.components.axis;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+import io.github.manishdait.jplotlib.data.util.DataDiffer;
+
+public class CoordinateTest {
+ @Test
+ public void shouldReturnTwentyOne() {
+ int range = 10;
+ int totalLenght = 10;
+ int diff = DataDiffer.getValDiff(range, totalLenght);
+ assertEquals(10, new Coordinate().getTotalTicks(range, diff));
+ }
+
+ @Test
+ public void shouldReturnTwentyFive() {
+ int range = 100;
+ int totalLenght = 100;
+ int diff = DataDiffer.getValDiff(range, totalLenght);
+ assertEquals(25, new Coordinate().getTotalTicks(range, diff));
+ }
+
+ @Test
+ public void shouldReturnEleven() {
+ int width = 358;
+ int total = 25;
+ assertEquals(6, new Coordinate().getIncrement(width, total));
+ }
+}
diff --git a/src/test/java/io/github/manishdait/jplotlib/internals/util/AxisTypeTest.java b/src/test/java/io/github/manishdait/jplotlib/internals/util/AxisTypeTest.java
new file mode 100755
index 0000000..802261a
--- /dev/null
+++ b/src/test/java/io/github/manishdait/jplotlib/internals/util/AxisTypeTest.java
@@ -0,0 +1,16 @@
+package io.github.manishdait.jplotlib.internals.util;
+
+import static org.junit.Assert.assertArrayEquals;
+
+import org.junit.Test;
+
+public class AxisTypeTest {
+
+ @Test
+ public void shouldReturnProperPriorites() {
+ int[] expeccted = {1, 2, 3};
+ int[] priorites = {AxisType.PLOT.getPriority(), AxisType.BAR.getPriority(), AxisType.PIE.getPriority()};
+ assertArrayEquals(expeccted, priorites);
+ }
+
+}