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

Add shadow for Pie Chart #1497

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

samir7osny
Copy link

@samir7osny samir7osny commented Nov 21, 2023

This adds the drop shadow to the Pie Chart with some cool customizations

  1. You can add simply a drop shadow like this (check the pie chart sample 4 here)
    image

  2. Also you can simulate the third dimension like this (check the pie chart sample 5 here)
    image

solves #1482

Copy link

codecov bot commented Nov 24, 2023

Codecov Report

Attention: Patch coverage is 9.25926% with 49 lines in your changes missing coverage. Please review.

Please upload report for BASE (main@0ae88cf). Learn more about missing BASE report.

Files with missing lines Patch % Lines
lib/src/chart/pie_chart/pie_chart_painter.dart 9.25% 49 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1497   +/-   ##
=======================================
  Coverage        ?   85.34%           
=======================================
  Files           ?       45           
  Lines           ?     3078           
  Branches        ?        0           
=======================================
  Hits            ?     2627           
  Misses          ?      451           
  Partials        ?        0           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@imaNNeo
Copy link
Owner

imaNNeo commented Nov 24, 2023

It seems there is an issue, it freezes the app (tested on iPhone and macOS)

@samir7osny
Copy link
Author

It seems there is an issue, it freezes the app (tested on iPhone and macOS)

Can you test again? I changed the number of layers to be drawn, it should fix this issue.

@3DExtended
Copy link

Tested on iPhone 15 Pro and simulator on MacBook Pro (2023). Seems to work now!

Simulator Screenshot - iPhone 15 Pro - 2023-11-25 at 19 59 39

@imaNNeo
Copy link
Owner

imaNNeo commented Dec 1, 2023

Okay, I found the freeze issue, if you change the offset to Offset(0, 0), it freezes the app process (it seems a low-level exception happens)

offset = offset ?? const Offset(3, 3),
color = color ?? Colors.black.withOpacity(0.5),
numberOfLayers = numberOfLayers ?? 1,
minDarkenValue = minDarkenValue ?? 0,
Copy link
Owner

Choose a reason for hiding this comment

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

Please define a better value for minDarkenValue and maxDarkenValue to simplify the usage. (for example 40 and 70 as you used in examples)

final bool show;
final Offset offset;
final Color color;
final MaskFilter? maskFilter;
Copy link
Owner

Choose a reason for hiding this comment

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

Do we need it for a simple shadow? If yes, please make it non-nullable and define a default value to make it simple for user/developer to implement a shadow

@@ -78,6 +78,79 @@ class FlBorderData with EquatableMixin {
];
}

/// Holds data to drawing shdow for the chart.
Copy link
Owner

Choose a reason for hiding this comment

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

Typo for shdow

@@ -78,6 +78,79 @@ class FlBorderData with EquatableMixin {
];
}

/// Holds data to drawing shdow for the chart.
class FlShadowData with EquatableMixin {
/// [show] Determines showing or hiding border around the chart.
Copy link
Owner

Choose a reason for hiding this comment

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

hiding border is wrong. It should be hiding shadow I think

maxDarkenValue == null ||
maxDarkenValue >= minDarkenValue,
);
final bool show;
Copy link
Owner

Choose a reason for hiding this comment

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

Please write the code doc for the properties.


bool isVisible() => show;

/// Copies current [FlBorderData] to a new [FlBorderData],
Copy link
Owner

Choose a reason for hiding this comment

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

FlBorderData is wrong here

@@ -213,6 +214,8 @@ class PieChartSectionData {
/// 1.0 means near the outside of the [PieChart].
final double badgePositionPercentageOffset;

final FlShadowData? shadow;
Copy link
Owner

Choose a reason for hiding this comment

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

Write the code doc please

@@ -268,6 +273,7 @@ class PieChartSectionData {
b.badgePositionPercentageOffset,
t,
),
shadow: b.shadow,
Copy link
Owner

Choose a reason for hiding this comment

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

Can we have a FlShadowData.lerp() here? It makes it good when animating between states.

@imaNNeo
Copy link
Owner

imaNNeo commented Dec 1, 2023

Please update the pie_chart.md and base_chart.md docs.
Also please write some unit-tests. Read more about the contributing guideline here

break;
}

final sectionPath = generateSectionPath(
Copy link
Owner

Choose a reason for hiding this comment

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

Please store this variable in the outer scope to make it possible to re-use it on line 168 when we want to draw actual paths to improve the performance.

offset: offset ?? this.offset,
color: color ?? this.color,
maskFilter: maskFilter ?? this.maskFilter,
numberOfLayers: numberOfLayers ?? 1,
Copy link
Owner

Choose a reason for hiding this comment

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

You need to use this.numberOfLayers instead of hard-coded 1

color: color ?? this.color,
maskFilter: maskFilter ?? this.maskFilter,
numberOfLayers: numberOfLayers ?? 1,
minDarkenValue: minDarkenValue ?? 0,
Copy link
Owner

@imaNNeo imaNNeo Dec 1, 2023

Choose a reason for hiding this comment

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

You need to use this.minDarkenValue instead of hard-coded 0

maskFilter: maskFilter ?? this.maskFilter,
numberOfLayers: numberOfLayers ?? 1,
minDarkenValue: minDarkenValue ?? 0,
maxDarkenValue: maxDarkenValue ?? 0,
Copy link
Owner

@imaNNeo imaNNeo Dec 1, 2023

Choose a reason for hiding this comment

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

You need to use this.maxDarkenValue instead of hard-coded 0

@imaNNeo
Copy link
Owner

imaNNeo commented Dec 1, 2023

Also, please use different style/color/value for the new charts. You just copy-pasted the sample1 and they look exactly the same except the shadow. It doesn't feel good to see some duplicate charts.
You can combine the sample 4 and 5 together and add some options to change the shadow style (it helps users/developers to understand how it works).
For example you can add a slider to allow user/developer to increase the shadow layers, offset, ...
Or when you hover/touch it, instead of adding stroke radius, you can increase/decrease the shadow.

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants