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:Vert support for ValueBar #91

Merged
merged 3 commits into from
Mar 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import 'package:example/gauge_vertical.dart';
import 'package:example/range_vertical.dart';
import 'package:example/vert_pointer_example.dart';
import 'package:flutter/material.dart';
import 'package:geekyants_flutter_gauges/gauges.dart';
import 'package:geekyants_flutter_gauges/linear_gauge/value_bar/value_bar.dart';

import 'multiple_pointer_example.dart';

void main() {
runApp(
Expand All @@ -23,6 +24,8 @@ class MyGaugeExample extends StatefulWidget {
class _MyGaugeExampleState extends State<MyGaugeExample> {
@override
Widget build(BuildContext context) {
return MyVerticalRange();

return VerticalValueBarExample();

}
}
1 change: 1 addition & 0 deletions example/lib/ruler_offset_feature_example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class MyRulerOffset extends StatelessWidget {
// value: 50,

valueBarPosition: ValueBarPosition.bottom,
rulers: RulerStyle(rulerPosition: RulerPosition.bottom),
),
),
],
Expand Down
53 changes: 53 additions & 0 deletions example/lib/valuebar_position.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import 'package:flutter/material.dart';
import 'package:geekyants_flutter_gauges/gauges.dart';
import 'package:geekyants_flutter_gauges/linear_gauge/value_bar/value_bar.dart';

class MyValueBarPosition extends StatefulWidget {
const MyValueBarPosition({super.key});

@override
State<MyValueBarPosition> createState() => _MyValueBarPositionState();
}

class _MyValueBarPositionState extends State<MyValueBarPosition> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: LinearGauge(
valueBar: [
ValueBar(
value: 90,
position: ValueBarPosition.center,
color: Colors.indigo,
),
ValueBar(
value: 50,
position: ValueBarPosition.bottom,
color: Colors.purple,
),
ValueBar(
value: 50,
offset: 8,
position: ValueBarPosition.top,
color: Colors.red,
),
ValueBar(
value: 30,
offset: 4,
position: ValueBarPosition.top,
color: Colors.orange,
),
ValueBar(
value: 29,
offset: 0,
position: ValueBarPosition.top,
color: Colors.green,
),
],
rulers: RulerStyle(rulerPosition: RulerPosition.left),
),
),
);
}
}
43 changes: 43 additions & 0 deletions example/lib/vert_pointer_example.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import 'package:flutter/material.dart';
import 'package:geekyants_flutter_gauges/gauges.dart';

class VerticalValueBarExample extends StatelessWidget {
const VerticalValueBarExample({super.key});

@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: LinearGauge(
start: 0,
end: 200,
valueBar: [
ValueBar(
value: 150,
offset: 10,
position: ValueBarPosition.left,
color: Colors.red,
),
ValueBar(
value: 150,
offset: 0,
position: ValueBarPosition.center,
color: Colors.red,
),
ValueBar(
value: 50,
offset: 10,
position: ValueBarPosition.right,
color: Colors.red,
),
],
gaugeOrientation: GaugeOrientation.vertical,
rulers: const RulerStyle(
inverseRulers: false,
rulerPosition: RulerPosition.left,
),
),
),
);
}
}
1 change: 1 addition & 0 deletions lib/gauges.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ export 'linear_gauge/styles/linear_gauge_ruler_style.dart';
export './linear_gauge/pointers/linear_gauge_pointer.dart';
export './linear_gauge/range_linear_gauge/range_linear_gauge.dart';
export 'linear_gauge/custom_label/custom_ruler_label.dart';
export 'package:geekyants_flutter_gauges/linear_gauge/value_bar/value_bar.dart';
31 changes: 28 additions & 3 deletions lib/linear_gauge/value_bar/value_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -112,24 +112,45 @@ class ValueBar {

// Start and End values of the Linear Gauge
double endValue = linearGauge.getEnd;

double startValue = linearGauge.getStart;
GaugeOrientation gaugeOrientation = linearGauge.getGaugeOrientation;

// width of the value bar in pixels based on the value
double valueBarWidth =
((value - startValue) / (endValue - startValue)) * totalWidth;

double valueBarHeight =
((value - endValue) / (startValue - endValue)) * totalWidth;

final ValueBarPosition valueBarPosition = position;
final getLinearGaugeBoxDecoration = linearGauge.getLinearGaugeBoxDecoration;
final Paint linearGaugeContainerPaint = Paint();
linearGaugeContainerPaint.color = color;

//For get Offset Height
double height = linearGauge.getLinearGaugeBoxDecoration.height;
double width = getLinearGaugeBoxDecoration.width;
double totalValOffset = _getOffsetHeight(valueBarPosition, height, offset);

bool getInversedRulers = linearGauge.getInversedRulers;
// Drawing Value Bar
final gaugeContainer = Rect.fromLTWH(start, totalValOffset, valueBarWidth,
getLinearGaugeBoxDecoration.height);
final gaugeContainer;
if (gaugeOrientation == GaugeOrientation.horizontal) {
double startValue = (!getInversedRulers) ? start : start + valueBarWidth;
gaugeContainer = Rect.fromLTWH(startValue, totalValOffset, valueBarWidth,
getLinearGaugeBoxDecoration.height);
} else {
double barTop = (!getInversedRulers) ? start + valueBarHeight : start;
double barLeft = _getOffsetHeight(
position, height, offset); // adjust left position as needed
gaugeContainer = Rect.fromLTWH(
barLeft,
barTop,
width, // set width to half of the gauge width
valueBarWidth,
);
}

canvas.drawRect(gaugeContainer, linearGaugeContainerPaint);
}

Expand All @@ -143,6 +164,10 @@ class ValueBar {
return -(height + valueBarOffset);
case ValueBarPosition.bottom:
return height + valueBarOffset;
case ValueBarPosition.left:
return -(height + valueBarOffset);
case ValueBarPosition.right:
return height + valueBarOffset;
default:
return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/enums.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ enum RulerPosition { top, center, bottom, right, left }

enum QuarterTurns { zero, one, two, three }

enum ValueBarPosition { top, center, bottom }
enum ValueBarPosition { top, center, bottom, right, left }
4 changes: 3 additions & 1 deletion test/gauges_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import 'package:flutter_test/flutter_test.dart';
import 'package:geekyants_flutter_gauges/gauges.dart';

void main() {
LinearGauge linearGauge = LinearGauge();
LinearGauge linearGauge = LinearGauge(
rulers: RulerStyle(rulerPosition: RulerPosition.bottom),
);
setUp(() {
linearGauge = LinearGauge(
start: 0,
Expand Down