Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ranjith smitch17 patch 1 #5444

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
44 changes: 44 additions & 0 deletions .github/workflows/gradle-publish.yml
@@ -0,0 +1,44 @@
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
# This workflow will build a package using Gradle and then publish it to GitHub packages when a release is created

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Performance Issue: The workflow comment suggests that actions not certified by GitHub are being used. This could introduce security vulnerabilities or maintenance issues if these third-party actions are not properly managed or become deprecated.
Fix: Consider using GitHub-certified actions where possible. If third-party actions must be used, ensure they are from reputable sources and actively maintained. Regularly review and update these actions to their latest versions to mitigate potential security vulnerabilities.
Code Suggestion:

- uses: gradle/actions/setup-gradle@417ae3ccd767c252f5661f1ace9f835f9654f2b5 # Consider changing to a GitHub-certified action or ensure it's from a reputable source and actively maintained

# For more information see: https://github.com/actions/setup-java/blob/main/docs/advanced-usage.md#Publishing-using-gradle

name: Gradle Package

on:
release:
types: [created]

jobs:
build:

runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
server-id: github # Value of the distributionManagement/repository/id field of the pom.xml
settings-path: ${{ github.workspace }} # location for the settings.xml file

- name: Setup Gradle
uses: gradle/actions/setup-gradle@417ae3ccd767c252f5661f1ace9f835f9654f2b5 # v3.1.0

- name: Build with Gradle
run: ./gradlew build

# The USERNAME and TOKEN need to correspond to the credentials environment variables used in
# the publishing section of your build.gradle
- name: Publish to GitHub Packages
run: ./gradlew publish
env:
USERNAME: ${{ github.actor }}
TOKEN: ${{ secrets.GITHUB_TOKEN }}
Comment on lines +1 to +44

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: Ensure that the new GitHub Actions workflow for publishing the Gradle package is tested in a separate branch before merging into the main branch to avoid disruptions in the CI/CD process.
Code Suggestion:

# It is recommended to test this new workflow thoroughly in a separate branch before integrating.

Comment on lines +1 to +44

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Structure Issue: The GitHub Actions workflow for publishing the Gradle package is well-defined and follows standard practices for building and publishing Java packages. However, it's important to ensure that the secrets and environment variables used (like GITHUB_TOKEN) are securely managed and have the minimal scopes necessary for their usage to maintain the security of the CI/CD pipeline.
Fix: Review the scopes assigned to the GITHUB_TOKEN and any other secrets or credentials used in the workflow. Ensure they are limited to the minimum required for their tasks. Additionally, consider implementing auditing or monitoring to detect any unauthorized access or usage of these secrets.
Code Suggestion:

- permissions:
      contents: read
      packages: write
      # Review the scopes assigned to the GITHUB_TOKEN and any other secrets or credentials used in the workflow.

Comment on lines +1 to +44

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optimization Issue: The workflow for publishing the package to GitHub packages upon release creation could benefit from optimization in terms of security and efficiency. Using third-party actions poses a potential risk if not properly managed and versioned. Additionally, the build and publish steps could be optimized to only trigger when necessary, reducing unnecessary runs and potential errors.
Fix: - Pin the third-party actions to a specific commit SHA to mitigate the risk of malicious code injection from compromised or updated actions. For example, change 'uses: actions/checkout@v4' to 'uses: actions/checkout@'.

  • Add conditional steps or jobs to ensure that the build and publish steps only run when there are meaningful changes to the package, thus optimizing CI/CD resources. This can be achieved by using 'paths' or 'paths-ignore' options in the workflow trigger section or by adding conditional checks within the job.
    Code Suggestion:
- uses: actions/checkout@<commit-sha>
  if: github.event_name == 'release' && github.event.action == 'created'
- uses: actions/setup-java@<commit-sha>
  with:
    java-version: '17'
    distribution: 'temurin'
    server-id: github
    settings-path: ${{ github.workspace }}
  if: github.event_name == 'release' && github.event.action == 'created'

Comment on lines +1 to +44

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Security Issue: The workflow uses actions that are not certified by GitHub. It's recommended to use actions that are verified by GitHub for security and reliability.
Fix: Consider using verified actions for the workflow or thoroughly review third-party actions before use.
Code Suggestion:

- uses: actions/checkout@v4 # Consider changing to a verified action or review third-party actions before use
- uses: actions/setup-java@v4 # Consider changing to a verified action or review third-party actions before use

Expand Up @@ -65,12 +65,11 @@ protected void onCreate(Bundle savedInstanceState) {

tvX = findViewById(R.id.tvXMax);
tvY = findViewById(R.id.tvYMax);

seekBarX = findViewById(R.id.seekBar1);
seekBarX.setOnSeekBarChangeListener(this);

seekBarY = findViewById(R.id.seekBar2);
seekBarY.setMax(180);
seekBarY.setMax(40);
seekBarY.setOnSeekBarChangeListener(this);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Performance Issue: The 'seekBarY.setMax(40);' adjustment significantly reduces the maximum value for the Y-axis compared to the original 'setMax(180)', which might not accommodate the data range effectively.
Fix: Ensure the 'setMax' value for 'seekBarY' is appropriately set to accommodate the expected range of data. If the data range exceeds 40, consider adjusting this value to a higher limit that suits the data distribution.
Code Suggestion:

-        seekBarY.setMax(180);
+        seekBarY.setMax(40);



Expand Down Expand Up @@ -126,12 +125,11 @@ protected void onCreate(Bundle savedInstanceState) {
yAxis.enableGridDashedLine(10f, 10f, 0f);

// axis range
yAxis.setAxisMaximum(200f);
yAxis.setAxisMinimum(-50f);
yAxis.setAxisMaximum(40f);
yAxis.setAxisMinimum(0f);
Comment on lines +128 to +129

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Performance Issue: Changing the axis maximum from '200f' to '40f' and minimum from '-50f' to '0f' might not accurately represent negative values or larger data ranges.
Fix: Re-evaluate the data range that needs to be represented in the chart. If negative values or values above 40 are expected, adjust the axis minimum and maximum accordingly.
Code Suggestion:

-            yAxis.setAxisMaximum(200f);
-            yAxis.setAxisMinimum(-50f);
+            yAxis.setAxisMaximum(40f);
+            yAxis.setAxisMinimum(0f);

}
Comment on lines 126 to 130

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Scalability Issue: Modification of the Y-axis maximum and minimum values from a wider range (-50 to 200) to a narrower range (0 to 40) can significantly impact the scalability of the chart. This change restricts the chart's ability to display data points that fall outside the new limited range, potentially omitting critical data from the visualization.
Fix: Consider implementing dynamic Y-axis bounds based on the dataset's actual value range. This approach allows the chart to adapt to various datasets, improving scalability and ensuring that all relevant data points are included in the visualization.
Code Suggestion:

-            yAxis.setAxisMaximum(200f);
-            yAxis.setAxisMinimum(-50f);
+            yAxis.setAxisMaximum(40f);
+            yAxis.setAxisMinimum(0f);



{ // // Create Limit Lines // //
/* { // // Create Limit Lines // //
LimitLine llXAxis = new LimitLine(9f, "Index 10");
llXAxis.setLineWidth(4f);
llXAxis.enableDashedLine(10f, 10f, 0f);
Expand Down Expand Up @@ -162,11 +160,11 @@ protected void onCreate(Bundle savedInstanceState) {
yAxis.addLimitLine(ll2);
//xAxis.addLimitLine(llXAxis);
}

*/
// add data
seekBarX.setProgress(45);
seekBarY.setProgress(180);
setData(45, 180);
seekBarY.setProgress(30);
setData(25, 30);

// draw points over time
chart.animateX(1500);
Expand All @@ -184,12 +182,13 @@ private void setData(int count, float range) {

for (int i = 0; i < count; i++) {

float val = (float) (Math.random() * range) - 30;
float val = (float) (Math.random() * range);
values.add(new Entry(i, val, getResources().getDrawable(R.drawable.star)));
}

LineDataSet set1;


if (chart.getData() != null &&
chart.getData().getDataSetCount() > 0) {
set1 = (LineDataSet) chart.getData().getDataSetByIndex(0);
Expand All @@ -202,24 +201,26 @@ private void setData(int count, float range) {
set1 = new LineDataSet(values, "DataSet 1");

set1.setDrawIcons(false);

set1.setMode(LineDataSet.Mode.GRADIENT_CUBIC_BEZIER);
set1.setGradientColor(getResources().getColor(android.R.color.holo_green_dark),
getResources().getColor(android.R.color.holo_blue_dark));
// draw dashed line
Comment on lines +205 to 207

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Performance Issue: Disabling the dashed line with 'set1.enableDashedLine(10f, 5f, 0f);' and modifying the line width from '1f' to '5f' could impact the chart's readability and visual appeal.
Fix: Consider the visual implications of these changes on the chart's readability. If the dashed line is essential for distinguishing data sets or if a thinner line width is preferred for aesthetics, revert these changes.
Code Suggestion:

-            set1.enableDashedLine(10f, 5f, 0f);
+            /* set1.enableDashedLine(10f, 5f, 0f);*/
-            set1.setLineWidth(1f);
+            set1.setLineWidth(5f);

set1.enableDashedLine(10f, 5f, 0f);
/* set1.enableDashedLine(10f, 5f, 0f);*/

// black lines and points
set1.setColor(Color.BLACK);
set1.setCircleColor(Color.BLACK);

// line thickness and point size
set1.setLineWidth(1f);
set1.setLineWidth(5f);
set1.setCircleRadius(3f);

// draw points as solid circles
set1.setDrawCircleHole(false);
set1.setDrawCircles(false);

// customize legend entry
set1.setFormLineWidth(1f);
set1.setFormLineDashEffect(new DashPathEffect(new float[]{10f, 5f}, 0f));
//set1.setFormLineDashEffect(new DashPathEffect(new float[]{10f, 5f}, 0f));
set1.setFormSize(15.f);
Comment on lines 202 to 224

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Structure Issue: The introduction of gradient cubic bezier mode and gradient color for the line dataset, along with disabling the dashed line, represents a significant visual change. While this can enhance the visual appeal, it's important to consider its impact on readability and the overall user experience.
Fix: Evaluate the visual changes in various scenarios, including devices with different screen sizes and resolutions. Ensure that the gradient colors and cubic bezier mode improve data visualization without compromising readability. Consider providing options for users to switch between visual modes based on their preferences.
Code Suggestion:

+            set1.setMode(LineDataSet.Mode.GRADIENT_CUBIC_BEZIER);
+            set1.setGradientColor(getResources().getColor(android.R.color.holo_green_dark),
+                    getResources().getColor(android.R.color.holo_blue_dark));
-            /* set1.enableDashedLine(10f, 5f, 0f);*/


// text size of values
Comment on lines 202 to 226

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Scalability Issue: The introduction of 'LineDataSet.Mode.GRADIENT_CUBIC_BEZIER' and gradient colors for the line chart can impact performance, especially for large datasets. While gradient colors can enhance visual appeal, rendering gradients is more computationally intensive than rendering solid colors. This change could lead to scalability issues, such as slower rendering times and decreased responsiveness, particularly when visualizing large or complex datasets.
Fix: Perform performance testing to assess the impact of using gradient colors on rendering times and responsiveness. If scalability issues are observed, consider providing options to toggle between solid and gradient colors based on the dataset's size or complexity. Implementing level-of-detail (LOD) techniques can also help mitigate performance issues by adjusting the chart's visual complexity based on the current zoom level or data density.
Code Suggestion:

+            set1.setMode(LineDataSet.Mode.GRADIENT_CUBIC_BEZIER);
+            set1.setGradientColor(getResources().getColor(android.R.color.holo_green_dark),
+                    getResources().getColor(android.R.color.holo_blue_dark));

Expand All @@ -229,34 +230,35 @@ private void setData(int count, float range) {
set1.enableDashedHighlightLine(10f, 5f, 0f);

// set the filled area
set1.setDrawFilled(true);
set1.setFillFormatter(new IFillFormatter() {
@Override
public float getFillLinePosition(ILineDataSet dataSet, LineDataProvider dataProvider) {
return chart.getAxisLeft().getAxisMinimum();
}
});

// set color of filled area
/* // set color of filled area
if (Utils.getSDKInt() >= 18) {
// drawables only supported on api level 18 and above
Drawable drawable = ContextCompat.getDrawable(this, R.drawable.fade_red);
set1.setFillDrawable(drawable);
} else {
set1.setFillColor(Color.BLACK);
}
}*/

ArrayList<ILineDataSet> dataSets = new ArrayList<>();
/* dataSets.add(ds1);*/
dataSets.add(set1); // add the data sets

// create a data object with the data sets
LineData data = new LineData(dataSets);

// set data
chart.setData(data);
}

}


@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.line, menu);
Expand Down Expand Up @@ -300,7 +302,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
break;
}
case R.id.actionToggleHighlight: {
if(chart.getData() != null) {
if (chart.getData() != null) {
chart.getData().setHighlightEnabled(!chart.getData().isHighlightEnabled());
chart.invalidate();
}
Expand Down Expand Up @@ -346,7 +348,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
LineDataSet set = (LineDataSet) iSet;
set.setMode(set.getMode() == LineDataSet.Mode.CUBIC_BEZIER
? LineDataSet.Mode.LINEAR
: LineDataSet.Mode.CUBIC_BEZIER);
: LineDataSet.Mode.CUBIC_BEZIER);
}
chart.invalidate();
break;
Expand All @@ -360,7 +362,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
LineDataSet set = (LineDataSet) iSet;
set.setMode(set.getMode() == LineDataSet.Mode.STEPPED
? LineDataSet.Mode.LINEAR
: LineDataSet.Mode.STEPPED);
: LineDataSet.Mode.STEPPED);
}
chart.invalidate();
break;
Expand All @@ -374,7 +376,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
LineDataSet set = (LineDataSet) iSet;
set.setMode(set.getMode() == LineDataSet.Mode.HORIZONTAL_BEZIER
? LineDataSet.Mode.LINEAR
: LineDataSet.Mode.HORIZONTAL_BEZIER);
: LineDataSet.Mode.HORIZONTAL_BEZIER);
}
chart.invalidate();
break;
Expand Down Expand Up @@ -435,10 +437,12 @@ protected void saveToGallery() {
}

@Override
public void onStartTrackingTouch(SeekBar seekBar) {}
public void onStartTrackingTouch(SeekBar seekBar) {
}

@Override
public void onStopTrackingTouch(SeekBar seekBar) {}
public void onStopTrackingTouch(SeekBar seekBar) {
}

@Override
public void onValueSelected(Entry e, Highlight h) {
Expand All @@ -451,4 +455,4 @@ public void onValueSelected(Entry e, Highlight h) {
public void onNothingSelected() {
Log.i("Nothing selected", "Nothing selected.");
}
}
}
@@ -1,4 +1,7 @@
package com.xxmassdeveloper.mpchartexample.fragments;
import android.graphics.LinearGradient;
import android.graphics.Paint;
import android.graphics.Shader;
import android.graphics.Typeface;
import android.os.Bundle;
import androidx.annotation.NonNull;
Expand Down Expand Up @@ -52,6 +55,22 @@ public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
XAxis xAxis = chart.getXAxis();
xAxis.setEnabled(false);

chart.post(this::setupGradient);

return v;
}

private void setupGradient() {

Paint paint = chart.getRenderer().getPaintRender();
int height = chart.getHeight();

LinearGradient linGrad = new LinearGradient(0, 0, 0, height,
getResources().getColor(android.R.color.holo_blue_dark),
getResources().getColor(android.R.color.holo_green_dark),
Shader.TileMode.REPEAT);
paint.setShader(linGrad);

chart.invalidate();
}
}
Expand Up @@ -70,6 +70,7 @@ protected void onCreate(Bundle savedInstanceState) {
////
objects.add(0, new ContentItem("Line Charts"));


objects.add(1, new ContentItem("Basic", "Simple line chart."));
objects.add(2, new ContentItem("Multiple", "Show multiple data sets."));
objects.add(3, new ContentItem("Dual Axis", "Line chart with dual y-axes."));
Expand Down
Expand Up @@ -9,6 +9,7 @@
import com.github.mikephil.charting.components.YAxis;
import com.github.mikephil.charting.formatter.IValueFormatter;
import com.github.mikephil.charting.interfaces.datasets.IDataSet;
import com.github.mikephil.charting.model.GradientColor;
import com.github.mikephil.charting.utils.ColorTemplate;
import com.github.mikephil.charting.utils.MPPointF;
import com.github.mikephil.charting.utils.Utils;
Expand All @@ -28,6 +29,8 @@ public abstract class BaseDataSet<T extends Entry> implements IDataSet<T> {
*/
protected List<Integer> mColors = null;

protected GradientColor mGradientColor = null;

/**
* List representing all colors that are used for drawing the actual values for this DataSet
*/
Expand Down Expand Up @@ -141,6 +144,11 @@ public int getColor(int index) {
return mColors.get(index % mColors.size());
}

@Override
public GradientColor getGradientColor() {
return mGradientColor;
}

/**
* ###### ###### COLOR SETTING RELATED METHODS ##### ######
*/
Expand Down Expand Up @@ -226,6 +234,16 @@ public void setColor(int color, int alpha) {
setColor(Color.argb(alpha, Color.red(color), Color.green(color), Color.blue(color)));
}

/**
* Sets the start and end color for gradient color, ONLY color that should be used for this DataSet.
*
* @param startColor
* @param endColor
*/
public void setGradientColor(int startColor, int endColor) {
mGradientColor = new GradientColor(startColor, endColor);
}
Comment on lines +243 to +245

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: The introduction of gradient coloring to datasets is a significant enhancement. Ensure that this feature is compatible with all chart types in the library and does not interfere with existing coloring options.
Code Suggestion:

# Test gradient coloring extensively with various datasets and chart types to ensure broad compatibility and no regression in existing functionality.


/**
* Sets colors with a specific alpha value.
*
Expand Down Expand Up @@ -495,6 +513,7 @@ protected void copy(BaseDataSet baseDataSet) {
baseDataSet.mFormLineDashEffect = mFormLineDashEffect;
baseDataSet.mFormLineWidth = mFormLineWidth;
baseDataSet.mFormSize = mFormSize;
baseDataSet.mGradientColor = mGradientColor;
baseDataSet.mHighlightEnabled = mHighlightEnabled;
baseDataSet.mIconsOffset = mIconsOffset;
baseDataSet.mValueColors = mValueColors;
Expand Down
Expand Up @@ -412,6 +412,7 @@ public enum Mode {
LINEAR,
STEPPED,
CUBIC_BEZIER,
HORIZONTAL_BEZIER
HORIZONTAL_BEZIER,
GRADIENT_CUBIC_BEZIER
}
}
@@ -1,14 +1,14 @@
package com.github.mikephil.charting.interfaces.datasets;

import android.graphics.DashPathEffect;
import android.graphics.PointF;
import android.graphics.Typeface;

import com.github.mikephil.charting.components.Legend;
import com.github.mikephil.charting.components.YAxis;
import com.github.mikephil.charting.data.DataSet;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.formatter.IValueFormatter;
import com.github.mikephil.charting.model.GradientColor;
import com.github.mikephil.charting.utils.MPPointF;

import java.util.List;
Expand Down Expand Up @@ -285,6 +285,13 @@ public interface IDataSet<T extends Entry> {
*/
int getColor();

/**
* Returns the Gradient color model
*
* @return
*/
GradientColor getGradientColor();
Comment on lines 285 to +293

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: Adding the getGradientColor method to the IDataSet interface increases the flexibility of the library. Ensure that all implementations of IDataSet properly support this method, returning meaningful gradient information or a default if not applicable.
Code Suggestion:

# Implement default handling of getGradientColor in datasets that do not support gradients, possibly returning null or a default GradientColor object.


/**
* Returns the color at the given index of the DataSet's color array.
* Performs a IndexOutOfBounds check by modulus.
Expand Down