Skip to content

Commit

Permalink
Merge pull request #2 from ManishDait/beta-1.2.0
Browse files Browse the repository at this point in the history
Mege Beta 1.2.0 to master
  • Loading branch information
manishdait authored Apr 20, 2024
2 parents 096b509 + fa8ffcd commit 1c03d1d
Show file tree
Hide file tree
Showing 15 changed files with 559 additions and 3 deletions.
155 changes: 155 additions & 0 deletions docs/AREA_PLOT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
# Jplotlib.areaPlot()

The `areaPlot()` method in the `Jplotlib.areaPlot()` allows you to create 2D area plots with ease. This method is designed to visualize datasets using y-coordinates and x-coordinates:

## Method Signatures
`areaPlot(double[] xPoints, double[] yPoints)`:
- Description: Plots a 2D area chart using the given x-coordinates and y-coordinates.
- Example usage:
```java
double[] xCoords = {1.0, 2.0, 3.0, 4.0};
double[] yCoords = {2.5, 5.1, 3.9, 6.2};
new Jplotlib.areaPlot(xCoords, yCoords);
```


## Area Color

To customize the color of the area in the chart, 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 `LibColor` from Jplotlib:

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.defaults.color.LibColor;

public class App {
public static void main(String[] args) {
Jplotlib jplotlib = new Jplotlib();
double[] y = {6, 2, 7, 11};
double[] x = {1, 2, 3, 4};
jplotlib.areaPlot(x, y)
.color(LibColor.LIME.getColor());
jplotlib.show();
}
}
```

In this example, we use the `.color(LibColor.LIME.getColor())` method to set the color of the line to lime.

<img src="assets/area/area_EG1.png" alt="area_eg1.png" width="620px">

For more information about the `LibColor` enum and the available colors, refer to the [LibColor Enum section](LIB_COLOR.md).


### Using `java.awt.Color`:

If you prefer to use the `java.awt.Color` class, you can do so as follows:

```java
import java.awt.Color;
import io.github.manishdait.jplotlib.Jplotlib;

public class App {
public static void main(String[] args) {
Jplotlib jplotlib = new Jplotlib();
double[] y = {6, 2, 7, 11};
double[] x = {1, 2, 3, 4};
jplotlib.areaPlot(x, y)
.color(Color.RED);
jplotlib.show();
}
}
```

In this example, we use the `.color(Color.RED)` method to set the color of the line to red.

<img src="assets/area/area_EG2.png" alt="area_eg2.png" width="620px">

Whichever method you choose, the `.color()` method allows you to customize the appearance of your line plots with different colors according to your preferences.


## Alpha

In Jplotlib, you can adjust the transparency of the area in area plots using the `.alpha()` method. This feature allows you to control the opacity of area, making the area plot visually more informative and expressive.

### Example Usage:

```java
import io.github.manishdait.jplotlib.Jplotlib;

public class App {
public static void main(String[] args) {
double[] x = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13};
double[] y = {99,86,87,88,111,86,103,87,94,78,77,85,86};

Jplotlib jplotlib = new Jplotlib();
jplotlib.areaPlot(x, y)
.alpha(0.5F);
jplotlib.show();
}
}
```

In this example, we use the `.alpha()` argument with the areaPlot() method to set the transparency (opacity) of the aarea in the area plot. The `alphaValue` is a float value between 0 and 1, where 0 means completely transparent (invisible) area, and 1 means completely opaque (fully visible) area.

By adjusting the transparency of the area, you can reveal underlying patterns in the data, especially when data points overlap closely together. It helps in visualizing the density of data points and identifying areas with overlaping concentration.

<img src="assets/area/area_EG3.png" alt="area_eg3.png" width="620px">




## Multiples Lines

You can plot as many area chart as you like by simply adding more `Jplotlib.areaPlot()` method calls:

### Example Usage:

```java
import io.github.manishdait.jplotlib.Jplotlib;

public class App {
public static void main(String[] args) {
Jplotlib jplotlib = new Jplotlib();
double[] x1 = {0, 1, 2, 3};
double[] x2 = {2, 3, 4, 5};
double[] y1 = {6, 2, 7, 11};
double[] y2 = {3, 8, 1, 10};
jplotlib.areaPlot(x1, y1);
jplotlib.areaPlot(x2, y2);
jplotlib.show();
}
}
```

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.areaPlot()` method calls.

<img src="assets/area/area_EG4.png" alt="area_eg4.png" width="620px">

### Example Usage:

```java
import io.github.manishdait.jplotlib.Jplotlib;

public class App {
public static void main(String[] args) {
Jplotlib jplotlib = new Jplotlib();
double[] x1 = {0, 1, 2, 3};
double[] x2 = {2, 3, 4, 5};
double[] y1 = {6, 2, 7, 11};
double[] y2 = {3, 8, 1, 10};
jplotlib.areaPlot(x1, y1);
jplotlib.areaPlot(x2, y2).alpha(0.3f);
jplotlib.show();
}
}
```

In this example, we create two sets of y-coordinates (`y1` and `y2`) similar to above example but with alpha.

<img src="assets/area/area_EG5.png" alt="area_eg5.png" width="620px">


14 changes: 14 additions & 0 deletions docs/GETTING_STARTED.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Jplotlib is a Java library that allows you to create 2D line plots, scatter plot
- [Creating a Scatter Plot](#creating-a-scatter-plot)
- [Creating a Bar Graph](#creating-a-bar-graph)
- [Creating a Pie Chart](#creating-a-pie-chart)
- [CReating a Area PLot](#creating-a-area-plot)

## Installation

Expand Down Expand Up @@ -88,6 +89,19 @@ jplotlib.pie(dataPoints);

More information about pie charts can be found in the [PIE.md](PIE.md) document.

## Creating a Area Plot

To create a 2D area plot using Jplotlib, follow the same steps as above, by using the `areaPlot()` method.

```java
double[] x = {1.0, 2.0, 3.0, 4.0};
double[] y = {2.5, 5.1, 3.9, 6.2};
jplotlib.areaPlot(x, y);
```

You can find more information about scatter plots in the [AREA_PLOT.md](AREA_PLOT.md) document.


That's it! You now have the basic knowledge to create various types of visualizations using Jplotlib. Experiment with different data and customization options to create meaningful plots and charts.


Binary file added docs/assets/area/area_EG1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/assets/area/area_EG2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/assets/area/area_EG3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/assets/area/area_EG4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/assets/area/area_EG5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>io.github.manishdait</groupId>
<artifactId>jplotlib</artifactId>
<version>1.1.0</version>
<version>1.2.0</version>

<name>jplotlib</name>
<url>https://github.com/ManishDait/jplotlib</url>
Expand Down
17 changes: 16 additions & 1 deletion src/main/java/io/github/manishdait/jplotlib/Jplotlib.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import java.util.ArrayList;
import java.util.List;

import io.github.manishdait.jplotlib.charts.area.AreaChart;
import io.github.manishdait.jplotlib.charts.area.AreaChartOption;
import io.github.manishdait.jplotlib.charts.bar.BarGraph;
import io.github.manishdait.jplotlib.charts.bar.BarGraphOptions;
import io.github.manishdait.jplotlib.charts.helper.Graph;
Expand Down Expand Up @@ -74,7 +76,8 @@ public final class Jplotlib implements
LineChartOptions,
ScatterChartOptions,
BarGraphOptions,
PieChartOptions {
PieChartOptions,
AreaChartOption {

protected Window window;
protected Config axisConfiguration;
Expand Down Expand Up @@ -295,4 +298,16 @@ public PieChart pie(double[] dataPoints, String[] labels) {
isPlotable = true;
return pieChart;
}

// Area Chart

@Override
public AreaChart areaPlot(double[] xPoints, double[] yPoints) {
setAxisType(AxisType.PLOT);
setAxisParameters(xPoints, yPoints);
AreaChart areaChart = new AreaChart(new CartesianData(xPoints, yPoints));
graphs.add(areaChart);
isPlotable = true;
return areaChart;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/*
* 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.area;

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 AreaChart class implements the Graph interface and represents a area
* chart.
* It allows plotting area chart using polygon with customizable styles.
*
*/
public class AreaChart implements Graph {

private Data data;
private AreaChartStyle style;
private static final ChartType CHART_TYPE = ChartType.AREA;

/**
* Constructs a AreaChart with the provided data coordinates and initializes
* default style settings.
*
* @param data
* The data coordinates to be plotted on the area chart.
*/
public AreaChart(Data data) {
this.data = data;
this.style = new AreaChartStyle();
}

public Data getData() {
return data;
}

public void setData(Data data) {
this.data = data;
}

public AreaChartStyle getStyle() {
return style;
}

public void setStyle(AreaChartStyle style) {
this.style = style;
}

public static ChartType getChartType() {
return CHART_TYPE;
}

public AreaChart color(Color color) {
style.setColor(color);
return this;
}

public AreaChart alpha(float alpha) {
if (alpha > 1 || alpha < 0) {
alpha = 1;
}
style.setAlpha(alpha);
return this;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* 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.area;

/**
* The AreaChartOptions interface defines methods related to creating area
* charts.
* Implementations of this interface are expected to provide functionality for
* generating
* AreaChart objects based on given x and y data points.
*
*/
public interface AreaChartOption {

/**
* Creates a AreaChart 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 AreaChart An object representing a area chart constructed using
* the given data.
*/
AreaChart areaPlot(double[] xPoints, double[] yPoints);

}
Loading

0 comments on commit 1c03d1d

Please sign in to comment.