graph shaded region added from horizontal spaces

lab-result-changes
tahaalam 5 months ago
parent ac15ab26f5
commit 95243c250f

@ -79,6 +79,7 @@ class LabViewModel extends ChangeNotifier {
List<String> indexedCharacterForUniqueTest = []; List<String> indexedCharacterForUniqueTest = [];
double maxY = 0.0; double maxY = 0.0;
double minY = double.infinity;
double maxX = double.infinity; double maxX = double.infinity;
LabViewModel( LabViewModel(
@ -317,7 +318,8 @@ class LabViewModel extends ChangeNotifier {
mainLabResults.clear(); mainLabResults.clear();
filteredGraphValues.clear(); filteredGraphValues.clear();
maxY = double.negativeInfinity; maxY = double.negativeInfinity;
minY = double.infinity;
maxX = double.infinity;
final result = await labRepo.getPatientLabResults( final result = await labRepo.getPatientLabResults(
laborder, laborder,
Utils.isVidaPlusProject(int.parse(laborder.projectID ?? "0")), Utils.isVidaPlusProject(int.parse(laborder.projectID ?? "0")),
@ -352,6 +354,9 @@ class LabViewModel extends ChangeNotifier {
maxY = resultValue; maxY = resultValue;
maxX = maxY; maxX = maxY;
} }
if (resultValue < minY) {
minY = resultValue;
}
if (highRefrenceValue < double.parse(element.referenceHigh ?? "0.0")) { if (highRefrenceValue < double.parse(element.referenceHigh ?? "0.0")) {
highRefrenceValue = double.parse(element.referenceHigh ?? "0.0"); highRefrenceValue = double.parse(element.referenceHigh ?? "0.0");
flagForHighReferenceRange = element.calculatedResultFlag; flagForHighReferenceRange = element.calculatedResultFlag;
@ -373,17 +378,23 @@ class LabViewModel extends ChangeNotifier {
)); ));
} catch (e) {} } catch (e) {}
}); });
maxY += transformValueInRange(50, "H"); if (flagForLowReferenceRange == null && flagForHighReferenceRange == null) {
//todo handle the value if flags are null highRefrenceValue = maxY;
if(flagForLowReferenceRange != null && flagForHighReferenceRange!= null){ lowRefenceValue = minY;
}
this.flagForHighReferenceRange = flagForHighReferenceRange; this.flagForHighReferenceRange = flagForHighReferenceRange;
this.flagForLowReferenceRange = flagForLowReferenceRange; this.flagForLowReferenceRange = flagForLowReferenceRange;
highTransformedReferenceValue = transformValueInRange(highRefrenceValue, flagForHighReferenceRange??""); highTransformedReferenceValue = double.parse(transformValueInRange(highRefrenceValue, flagForHighReferenceRange ?? "").toStringAsFixed(1));
lowTransformedReferenceValue = transformValueInRange(lowRefenceValue, flagForLowReferenceRange??""); lowTransformedReferenceValue = double.parse(transformValueInRange(lowRefenceValue, flagForLowReferenceRange ?? "").toStringAsFixed(1));
this.highRefrenceValue = highRefrenceValue; this.highRefrenceValue = double.parse(highRefrenceValue.toStringAsFixed(1));
this.lowRefenceValue = lowRefenceValue; this.lowRefenceValue = double.parse(lowRefenceValue.toStringAsFixed(1));
}
if(maxY< highRefrenceValue) {
maxY = highRefrenceValue;
}
maxY += 25;
minY -= 25;
LabResult recentResult = recentThree.first; LabResult recentResult = recentThree.first;
checkIfGraphShouldBeDisplayed(recentResult); checkIfGraphShouldBeDisplayed(recentResult);
recentResult.verifiedOn = resultDate(DateUtil.convertStringToDate(recentResult.verifiedOnDateTime!)); recentResult.verifiedOn = resultDate(DateUtil.convertStringToDate(recentResult.verifiedOnDateTime!));

@ -284,15 +284,14 @@ class LabResultDetails extends StatelessWidget {
leftLabelInterval: getInterval(labmodel), leftLabelInterval: getInterval(labmodel),
// maxY: (labmodel.maxY)+(getInterval(labmodel)??0)/2, // maxY: (labmodel.maxY)+(getInterval(labmodel)??0)/2,
maxY: (labmodel.maxY), maxY: (labmodel.maxY),
minY: labmodel.minY,
maxX: labmodel.filteredGraphValues.length.toDouble()-.75, maxX: labmodel.filteredGraphValues.length.toDouble()-.75,
horizontalInterval: .1, horizontalInterval: .1,
getDrawingHorizontalLine: (value){ getDrawingHorizontalLine: (value){
print("the FLline transformed line is $value"); value = double.parse(value.toStringAsFixed(1));
print("the labmodel.highTransformedReferenceValue is ${labmodel.highTransformedReferenceValue}"); if(value == labmodel.highRefrenceValue ||value== labmodel.lowRefenceValue) {
print("thelabmodel.lowTransformedReferenceValue is ${labmodel.lowTransformedReferenceValue}");
if(value == labmodel.highRefrenceValue ||value== labmodel.highRefrenceValue) {
return FlLine( return FlLine(
color: AppColors.greyTextColor, color: AppColors.bgGreenColor.withOpacity(0.6),
strokeWidth: 1, strokeWidth: 1,
// dashArray: [5, 5], // dashArray: [5, 5],
); );
@ -300,35 +299,22 @@ class LabResultDetails extends StatelessWidget {
return FlLine( return FlLine(
color: Colors.transparent, color: Colors.transparent,
strokeWidth: 1, strokeWidth: 1,
// dashArray: [5, 5],
);; );;
}, },
leftLabelFormatter: (value) { leftLabelFormatter: (value) {
value = double.parse(value.toStringAsFixed(1));
// return leftLabels(value.toStringAsFixed(2)); // return leftLabels(value.toStringAsFixed(2));
if(value == labmodel.highTransformedReferenceValue) if(value == labmodel.highRefrenceValue)
return leftLabels("High".needTranslation); return leftLabels("High".needTranslation);
if(value== labmodel.lowTransformedReferenceValue) if(value== labmodel.lowRefenceValue)
return leftLabels("Low".needTranslation); return leftLabels("Low".needTranslation);
// switch (value.toInt()) {
// case 10:
// return leftLabels("Critical Low".needTranslation);
// case 30:
// return leftLabels("Low".needTranslation);
// case 50:
// return leftLabels("Normal".needTranslation);
// case 70:
// return leftLabels("High".needTranslation);
// case 90:
// return leftLabels(
// "Critical High".needTranslation);
// default:
return SizedBox.shrink(); return SizedBox.shrink();
// } // }
}, },
graphColor:graphColor , graphColor:AppColors.blackColor,
graphShadowColor: graphColor.withOpacity(.1), graphShadowColor: Colors.transparent,
graphGridColor: graphColor.withOpacity(.4), graphGridColor: graphColor.withOpacity(.4),
bottomLabelFormatter: (value, data) { bottomLabelFormatter: (value, data) {
if(data.isEmpty) return SizedBox.shrink(); if(data.isEmpty) return SizedBox.shrink();
@ -343,6 +329,9 @@ class LabResultDetails extends StatelessWidget {
} }
return SizedBox.shrink(); return SizedBox.shrink();
}, },
rangeAnnotations: RangeAnnotations(
horizontalRangeAnnotations: _buildRangeShades(labmodel)
),
minX:(labmodel.filteredGraphValues.length == 1)?null : -.2, minX:(labmodel.filteredGraphValues.length == 1)?null : -.2,
scrollDirection: Axis.horizontal, scrollDirection: Axis.horizontal,
height: 180.h); height: 180.h);
@ -351,6 +340,29 @@ class LabResultDetails extends StatelessWidget {
} }
} }
List<HorizontalRangeAnnotation> _buildRangeShades( LabViewModel model,) {
List<HorizontalRangeAnnotation> ranges = [];
ranges.add(HorizontalRangeAnnotation(
y1:model.minY,
y2: model.lowRefenceValue,
color: AppColors.highAndLow.withOpacity(0.05),
));
ranges.add(HorizontalRangeAnnotation(
y1:model.lowRefenceValue,
y2: model.highRefrenceValue,
color: AppColors.bgGreenColor.withOpacity(0.05),
));
ranges.add(HorizontalRangeAnnotation(
y1:model.highRefrenceValue,
y2: model.maxY,
color: AppColors.criticalLowAndHigh.withOpacity(0.05),
));
return ranges;
}
Widget labHistoryList(LabViewModel labmodel) { Widget labHistoryList(LabViewModel labmodel) {
return SizedBox( return SizedBox(
height: labmodel.filteredGraphValues.length<3?labmodel.filteredGraphValues.length*64:180.h, height: labmodel.filteredGraphValues.length<3?labmodel.filteredGraphValues.length*64:180.h,

@ -59,6 +59,9 @@ class CustomGraph extends StatelessWidget {
final bool? showGridLines; final bool? showGridLines;
final GetDrawingGridLine? getDrawingHorizontalLine; final GetDrawingGridLine? getDrawingHorizontalLine;
final double? horizontalInterval; final double? horizontalInterval;
final double? minY;
final bool showShadow;
final RangeAnnotations? rangeAnnotations;
///creates the left label and provide it to the chart as it will be used by other part of the application so the label will be different for every chart ///creates the left label and provide it to the chart as it will be used by other part of the application so the label will be different for every chart
final Widget Function(double) leftLabelFormatter; final Widget Function(double) leftLabelFormatter;
@ -96,14 +99,13 @@ class CustomGraph extends StatelessWidget {
this.showGridLines = false, this.showGridLines = false,
this.getDrawingHorizontalLine, this.getDrawingHorizontalLine,
this.horizontalInterval, this.horizontalInterval,
this.minY,
this.showShadow = false,
this.rangeAnnotations
}); });
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
// var maxY = 0.0;
double interval = 20;
print("the maxY is $maxY");
return Material( return Material(
color: Colors.white, color: Colors.white,
child: SizedBox( child: SizedBox(
@ -111,10 +113,8 @@ class CustomGraph extends StatelessWidget {
height: height, height: height,
child: LineChart( child: LineChart(
LineChartData( LineChartData(
minY: 0, minY: minY??0,
// maxY: ((maxY?.ceilToDouble() ?? 0.0) + interval).floorToDouble(),
maxY: maxY, maxY: maxY,
// minX: dataPoints.first.labelValue - 1,
maxX: maxX, maxX: maxX,
minX: minX , minX: minX ,
lineTouchData: LineTouchData( lineTouchData: LineTouchData(
@ -210,15 +210,17 @@ class CustomGraph extends StatelessWidget {
); );
}, },
), ),
rangeAnnotations: rangeAnnotations
),
), ),
), ),
)); );
} }
List<LineChartBarData> _buildColoredLineSegments(List<DataPoint> dataPoints) { List<LineChartBarData> _buildColoredLineSegments(List<DataPoint> dataPoints) {
final List<FlSpot> allSpots = dataPoints.asMap().entries.map((entry) { final List<FlSpot> allSpots = dataPoints.asMap().entries.map((entry) {
double value = (makeGraphBasedOnActualValue)?double.tryParse(entry.value.actualValue)??0.0:entry.value.value; double value = (makeGraphBasedOnActualValue)?double.tryParse(entry.value.actualValue)??0.0:entry.value.value;
debugPrint("the value is $value");
return FlSpot(entry.key.toDouble(), value); return FlSpot(entry.key.toDouble(), value);
}).toList(); }).toList();
@ -228,7 +230,7 @@ class CustomGraph extends StatelessWidget {
isCurved: true, isCurved: true,
isStrokeCapRound: true, isStrokeCapRound: true,
isStrokeJoinRound: true, isStrokeJoinRound: true,
barWidth: 4, barWidth: 2,
gradient: LinearGradient( gradient: LinearGradient(
colors: [graphColor, graphColor], colors: [graphColor, graphColor],
begin: Alignment.centerLeft, begin: Alignment.centerLeft,
@ -238,7 +240,7 @@ class CustomGraph extends StatelessWidget {
show: false, show: false,
), ),
belowBarData: BarAreaData( belowBarData: BarAreaData(
show: true, show: showShadow,
gradient: LinearGradient( gradient: LinearGradient(
colors: [ colors: [
graphShadowColor, graphShadowColor,
@ -253,33 +255,4 @@ class CustomGraph extends StatelessWidget {
return data; return data;
} }
// Widget buildLabel(String label) {
// return Padding(
// padding: const EdgeInsets.only(right: 8),
// child: Text(
// label,
// style: TextStyle(
// fontSize: leftLabelSize ?? 8.fSize, color: leftLabelColor),
// textAlign: TextAlign.right,
// ),
// );
// }
} }
// final List<DataPoint> sampleData = [
// DataPoint(
// value: 20,
// label: 'Jan 2024',
// ),
// DataPoint(
// value: 36,
// label: 'Feb 2024',
// ),
// DataPoint(
// value: 80,
// label: 'This result',
// ),
// ];

Loading…
Cancel
Save