-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Add Pattern Painters Support for BarChart (Stripes, Dots, Squares) #1958
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
Open
Caffo17
wants to merge
8
commits into
imaNNeo:main
Choose a base branch
from
Caffo17:feature/pattern-bar-chart
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
73fa3c9
feat: created pr to add pattern painter to bar chart painter
Caffo17 ab9f2b3
feat: refactor pattern painters using FragmentShader
Caffo17 29cf44e
feat: Refactor shader usage and update pattern fragment shaders
Caffo17 43ea454
test: Add testable shader injection and improve pattern painter tests
Caffo17 d75d2fb
Refactor shader management and pattern painters
Caffo17 eb44b32
fix: Refactor pattern painters
Caffo17 3046096
fix: shaders alpha
Caffo17 0cc20c7
feat: added surface painter to BarChartRodStackItem
Caffo17 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| import 'package:fl_chart/fl_chart.dart'; | ||
| import 'package:flutter/material.dart'; | ||
|
|
||
| /// {@template circle_pois_pattern_painter} | ||
| /// A [CustomPainter] that fills the area with a polka dot pattern. | ||
| /// | ||
| /// The pattern consists of evenly spaced circles (dots) arranged in rows and columns. | ||
| /// You can configure the dot color, number of dots per row, horizontal and vertical gaps, and margin. | ||
| /// | ||
| /// The pattern is rendered using a custom [CirclePoisShader], which allows for efficient and flexible drawing. | ||
| /// | ||
| /// ### Constructor parameters: | ||
| /// - [poisShader]: The shader responsible for rendering the polka dot pattern. | ||
| /// - [color]: The color of the dots (default: black). | ||
| /// - [dotsPerRow]: Number of dots per row (default: 2). | ||
| /// - [gap]: Horizontal gap between dots (default: 2.0). | ||
| /// - [verticalGap]: Vertical gap between dots (default: 2.0). | ||
| /// - [margin]: Margin around the pattern (default: 2.0). | ||
| /// | ||
| /// ### Example usage: | ||
| /// ```dart | ||
| /// CustomPaint( | ||
| /// painter: CirclePoisPatternPainter( | ||
| /// poisShader: myShader, | ||
| /// color: Colors.red, | ||
| /// dotsPerRow: 4, | ||
| /// gap: 4.0, | ||
| /// verticalGap: 4.0, | ||
| /// margin: 2.0, | ||
| /// ), | ||
| /// ) | ||
| /// ``` | ||
| /// {@endtemplate} | ||
| class CirclePoisPatternPainter extends FlSurfacePainter { | ||
| CirclePoisPatternPainter({ | ||
| required this.poisShader, | ||
| this.color = Colors.black, | ||
| this.dotsPerRow = 2, | ||
| this.gap = 2.0, | ||
| this.verticalGap = 2.0, | ||
| this.margin = 2.0, | ||
| }) : super(flShader: poisShader); | ||
|
|
||
| /// The color of the dots. | ||
| final Color color; | ||
|
|
||
| /// Number of dots per row. | ||
| final int dotsPerRow; | ||
|
|
||
| /// The gap between dots on X axis. | ||
| final double gap; | ||
|
|
||
| /// The gap between dots on Y axis. | ||
| final double verticalGap; | ||
|
|
||
| /// The margin around the pattern from the borders. | ||
| final double margin; | ||
|
|
||
| /// The shader used to render the polka dot pattern. | ||
| final CirclePoisShader poisShader; | ||
|
|
||
| @override | ||
| void paint(Canvas canvas, Size size) { | ||
| poisShader | ||
| ..setFloat(0, size.width) | ||
| ..setFloat(1, size.height) | ||
| ..setFloat(2, color.r) | ||
| ..setFloat(3, color.g) | ||
| ..setFloat(4, color.b) | ||
| ..setFloat(5, dotsPerRow.toDouble()) | ||
| ..setFloat(6, gap) | ||
| ..setFloat(7, verticalGap) | ||
| ..setFloat(8, margin); | ||
|
|
||
| canvas.drawRect( | ||
| Rect.fromLTWH(0, 0, size.width, size.height), | ||
| Paint()..shader = poisShader.shader, | ||
| ); | ||
| } | ||
|
|
||
| @override | ||
| bool shouldRepaint(covariant CustomPainter oldDelegate) => false; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| import 'package:fl_chart/fl_chart.dart'; | ||
| import 'package:flutter/material.dart'; | ||
|
|
||
| /// {@template square_pois_pattern_painter} | ||
| /// A [CustomPainter] that fills the area with a square polka dot pattern. | ||
| /// | ||
| /// The pattern consists of evenly spaced squares arranged in rows and columns. | ||
| /// You can configure the color of the squares, the number of squares per row, the horizontal and vertical gaps between squares, and the margin around the pattern. | ||
| /// | ||
| /// The pattern is rendered using a custom [SquarePoisShader], which allows for efficient and flexible drawing. | ||
| /// | ||
| /// ### Constructor parameters: | ||
| /// - [poisShader]: The shader responsible for rendering the square polka dot pattern. | ||
| /// - [color]: The color of the squares (default: black). | ||
| /// - [squaresPerRow]: Number of squares per row (default: 3). | ||
| /// - [gap]: Horizontal gap between squares (default: 2.0). | ||
| /// - [verticalGap]: Vertical gap between squares (default: 2.0). | ||
| /// - [margin]: Margin around the pattern (default: 2.0). | ||
| /// | ||
| /// ### Example usage: | ||
| /// ```dart | ||
| /// CustomPaint( | ||
| /// painter: SquarePoisPatternPainter( | ||
| /// poisShader: myShader, | ||
| /// color: Colors.green, | ||
| /// squaresPerRow: 4, | ||
| /// gap: 2.0, | ||
| /// verticalGap: 2.0, | ||
| /// margin: 2.0, | ||
| /// ), | ||
| /// ) | ||
| /// ``` | ||
| /// {@endtemplate} | ||
| class SquarePoisPatternPainter extends FlSurfacePainter { | ||
| SquarePoisPatternPainter({ | ||
| required this.poisShader, | ||
| this.color = Colors.black, | ||
| this.squaresPerRow = 3, | ||
| this.gap = 2.0, | ||
| this.verticalGap = 2.0, | ||
| this.margin = 2.0, | ||
| }) : super(flShader: poisShader); | ||
|
|
||
| /// The color of the squares. | ||
| final Color color; | ||
|
|
||
| /// Number of squares per row. | ||
| final int squaresPerRow; | ||
|
|
||
| /// The gap between dots on X axis; | ||
| final double gap; | ||
|
|
||
| /// The gap between dots on Y axis; | ||
| final double verticalGap; | ||
|
|
||
| /// The margin around the pattern from the borders. | ||
| final double margin; | ||
|
|
||
| /// The shader used to render the polka dot pattern. | ||
| final SquarePoisShader poisShader; | ||
|
|
||
| @override | ||
| void paint(Canvas canvas, Size size) { | ||
| poisShader | ||
| ..setFloat(0, size.width) | ||
| ..setFloat(1, size.height) | ||
| ..setFloat(2, color.r) | ||
| ..setFloat(3, color.g) | ||
| ..setFloat(4, color.b) | ||
| ..setFloat(5, squaresPerRow.toDouble()) | ||
| ..setFloat(6, gap) | ||
| ..setFloat(7, verticalGap) | ||
| ..setFloat(8, margin); | ||
|
|
||
| canvas.drawRect( | ||
| Rect.fromLTWH(0, 0, size.width, size.height), | ||
| Paint()..shader = poisShader.shader, | ||
| ); | ||
| } | ||
|
|
||
| @override | ||
| bool shouldRepaint(covariant CustomPainter oldDelegate) => false; | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.