Draft: add FlDotImagePainter for custom image dot markers#2049
Draft: add FlDotImagePainter for custom image dot markers#2049InsoooooooooJANG wants to merge 1 commit intoimaNNeo:mainfrom
Conversation
- Add FlDotImagePainter class that extends FlDotPainter - Support rendering custom images as dot markers on charts - Include static loadImageFromAsset() helper method - Add LineChartSample14 to demonstrate usage - Images must be pre-loaded asynchronously before use This allows users to display custom images (PNG, JPG, etc.) as dot markers instead of the default circle, square, or cross shapes.
| /// final image = await FlDotImagePainter.loadImageFromAsset('assets/dot.png'); | ||
| /// final painter = FlDotImagePainter(image: image, size: 20.0); | ||
| /// ``` | ||
| static Future<Image> loadImageFromAsset(String assetPath) async { |
There was a problem hiding this comment.
loadImageFromAsset doesn't belong in the painter.
A static method on a painter that does rootBundle.load() and instantiateImageCodec() mixes asset loading with rendering. This should be the user's responsibility.
They load the image however they want (asset, network, generated) and pass the Image object in. The static helper could live in an example or utility, but not in the library's core data class.
There was a problem hiding this comment.
btw, it seems instantiateImageCodec() is deprecated in Flutter 3.x.
I get this warning as well:
Warning: In index.html:92: "FlutterLoader.loadEntrypoint" is deprecated. Use "FlutterLoader.load" instead. See https://docs.flutter.dev/platform-integration/web/initialization for more details.
So please make sure you're using the new approach to load the image
| // Center the image at the offset | ||
| final drawOffset = offsetInCanvas - Offset(size / 2, size / 2); | ||
| final rect = Rect.fromLTWH(drawOffset.dx, drawOffset.dy, size, size); | ||
| paintImage( |
There was a problem hiding this comment.
Please use canvasWrapper.drawImage() instead of paintImage. This way, we keep the consistency and testability. Just like here:
fl_chart/lib/src/chart/base/axis_chart/axis_chart_painter.dart
Lines 296 to 305 in c83aa90
| maxX: 6, | ||
| minY: 0, | ||
| maxY: 6, | ||
| // Configure axis titles |
There was a problem hiding this comment.
I think we don't need these kinds of comments. Please remove the unnecessary comments.
|
You also need to write some unit-tests in the end. |
🚧 Draft: Add FlDotImagePainter for custom image dot markers
Status: Work in Progress - Seeking early feedback
Description
This PR adds
FlDotImagePainter, a new implementation ofFlDotPainterthat allows users to display custom images as dot markers on line charts, instead of the default circle, square, or cross shapes.Motivation
Currently, fl_chart only supports basic geometric shapes for dot markers. Many users want to display custom icons or images (e.g., profile pictures, product icons) as data point markers.
Screenshots
Implementation Details
Core Changes
FlDotImagePainterclass (lib/src/chart/base/axis_chart/axis_chart_data.dart)FlDotPainterto support image renderingloadImageFromAsset()helper for loading imagesdraw()methodExample
LineChartSample14demonstrates the usageUsage Example
Related Issue
[Feature Request] Add FlDotImagePainter to support custom image dot markers