Skip to content

Commit

Permalink
Merge branch 'main' into update-version
Browse files Browse the repository at this point in the history
  • Loading branch information
Afroz-Shaikh authored May 6, 2024
2 parents 33839ce + 103ac4d commit 0657286
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 7 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,12 @@ Default **`endAngle`**`: 210°

<p align='center'><img src="https://raw.githubusercontent.com/GeekyAnts/GaugesFlutter/main/example/screens/radial-angles.png" alt="radial-angels" height=440></p>

#### Custom Track Labels

The labels displayed on the RadialGauge track can easily be formated to your need.

<p align='center'><img src="example/screens/radial-custom-track-label.png" alt="radial-gauge-custom-track-label" height=440></p>

#### **Radii Customization**

`radiusFactor` can be used to size the adjust the scaling factor of the radius and change the radius of the gauge accordingly.
Expand Down
32 changes: 32 additions & 0 deletions example/lib/radial_gauge_custom_label.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import 'package:flutter/material.dart';
import 'package:geekyants_flutter_gauges/geekyants_flutter_gauges.dart';

///
/// The following code is a Simple Example of [RadialGauge] Widget with custom track labels.
///
class RadialGaugeCustomLabel extends StatefulWidget {
const RadialGaugeCustomLabel({super.key});

@override
State<RadialGaugeCustomLabel> createState() => _RadialGaugeCustomLabelState();
}

class _RadialGaugeCustomLabelState extends State<RadialGaugeCustomLabel> {
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white,
body: RadialGauge(
track: RadialTrack(
color: Colors.grey,
start: 0,
end: 100,
trackLabelFormater: (double value) => "${value.round()}€",
trackStyle: const TrackStyle(
showFirstLabel: false,
showLastLabel: false,
)),
),
);
}
}
Binary file added example/screens/radial-custom-track-label.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 6 additions & 7 deletions lib/src/radial_gauge/radial_gauge_container_painter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ class RenderRadialGaugeContainer extends RenderBox {
..strokeWidth = getRadialGauge.track.trackStyle.secondaryRulersWidth!
..style = PaintingStyle.stroke;

final trackLabelFormater = getRadialGauge.track.trackLabelFormater ??
(double value) => ((value * 10).round() / 10).toString();

// Loop to draw the Rulers and Labels
for (int i = 0; i <= numParts; i++) {
double rulerOffset = getRadialGauge.track.trackStyle.rulersOffset ?? 0;
Expand Down Expand Up @@ -111,13 +114,10 @@ class RenderRadialGaugeContainer extends RenderBox {
final TextPainter textPainter =
TextPainter(textDirection: TextDirection.ltr);

const String labelFormat = '%d';
final double langle =
startAngle + i * partAngle; // the angle of the current ruler
// the y coordinate of the label
final String label = labelFormat.replaceAll(
'%d', ((langle - startAngle) * 180 / pi).round().toString());
double l = double.parse(label);
double l = (langle - startAngle) * 180 / pi;
double sAngle = _radialGauge.track.startAngle;
double eAngle = _radialGauge.track.endAngle;

Expand All @@ -126,11 +126,10 @@ class RenderRadialGaugeContainer extends RenderBox {
double end = _radialGauge.track.end;
double valueRange = (end - start);

double exactValue =
start + double.parse(((l / range) * valueRange).toStringAsFixed(2));
double exactValue = start + ((l / range) * valueRange);
Color textColor = Colors.black;
textPainter.text = TextSpan(
text: exactValue.toString(),
text: trackLabelFormater(exactValue),
style: getRadialGauge.track.trackStyle.labelStyle ??
TextStyle(color: textColor, fontWeight: FontWeight.bold));
textPainter.layout();
Expand Down
16 changes: 16 additions & 0 deletions lib/src/radial_gauge/radial_track.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class RadialTrack {
secondaryRulerPerInterval: 4.0,
),
this.gradient,
this.trackLabelFormater,
});

///
Expand Down Expand Up @@ -121,6 +122,21 @@ class RadialTrack {
/// The [trackStyle] property is used to customize the track of the Radial Gauge.
///
final TrackStyle trackStyle;

///
/// The [trackLabelFormater] property is used to customize the track labels of the Radial Gauge.
///
/// ``` dart
/// RadialGauge(
/// track: RadialTrack(
/// start: 0,
/// end: 100,
/// trackLabelFormater: (double value) => "${value.round()}€",
/// ),
/// ),
/// ```
///
final String Function(double)? trackLabelFormater;
}

class TrackStyle extends BaseRulerStyle {
Expand Down

0 comments on commit 0657286

Please sign in to comment.