graph values fix and comparision with the pdf

lab-graph
tahaalam 1 day ago
parent 24fa8e18f3
commit fc21746683

@ -377,7 +377,8 @@ class LabViewModel extends ChangeNotifier {
LoaderBottomSheet.hideLoader();
if (apiResponse.messageStatus == 2) {
} else if (apiResponse.messageStatus == 1) {
var recentThree = sort(apiResponse.data!);
var sortedResult = sort(apiResponse.data!);
var recentThree = sortedResult.take(3).toList();
mainLabResults = recentThree;
double highRefrenceValue = double.negativeInfinity;
@ -385,11 +386,12 @@ class LabViewModel extends ChangeNotifier {
double lowRefenceValue = double.infinity;
String? flagForLowReferenceRange;
recentThree.reversed.forEach((element) {
sortedResult.take(3).toList().reversed.forEach((element) {
try {
var dateTime = DateUtil.convertStringToDate(element.verifiedOnDateTime!);
var resultValue = double.parse(element.resultValue!);
var transformedValue = transformValueInRange(double.parse(element.resultValue!), element.calculatedResultFlag ?? "");
// var transformedValue = transformValueInRange(double.parse(element.resultValue!), element.calculatedResultFlag ?? "");
var transformedValue = resultValue;
if (resultValue > maxY) {
maxY = resultValue;
maxX = maxY;
@ -421,9 +423,9 @@ class LabViewModel extends ChangeNotifier {
highRefrenceValue = maxY;
lowRefenceValue = minY;
}
//
if (minY > lowRefenceValue) {
minY = lowRefenceValue - 25;
minY = lowRefenceValue - getInterval();
}
this.flagForHighReferenceRange = flagForHighReferenceRange;
@ -432,12 +434,16 @@ class LabViewModel extends ChangeNotifier {
lowTransformedReferenceValue = double.parse(transformValueInRange(lowRefenceValue, flagForLowReferenceRange ?? "").toStringAsFixed(1));
this.highRefrenceValue = double.parse(highRefrenceValue.toStringAsFixed(1));
this.lowRefenceValue = double.parse(lowRefenceValue.toStringAsFixed(1));
if (maxY < highRefrenceValue) {
if(maxY<highRefrenceValue){
maxY = highRefrenceValue;
maxX = maxY;
}
maxY += 25;
minY -= 25;
// if (maxY < highRefrenceValue) {
// minY = highRefrenceValue - getInterval();
// }
// maxY += 25;
// minY -= 25;
LabResult recentResult = recentThree.first;
recentResult.uOM = unitOfMeasure;
checkIfGraphShouldBeDisplayed(recentResult);
@ -454,6 +460,17 @@ class LabViewModel extends ChangeNotifier {
},
);
}
num getInterval() {
// return .1;
var maxX = maxY;
if(maxX<1) return .2;
if(maxX >=1.0 && maxX < 5.0) return .3;
if(maxX >=5.0 && maxX < 10.0) return 1.5;
if(maxX >=10.0 && maxX < 50.0) return 2.5;
if(maxX >=50.0 && maxX < 100.0) return 5;
if(maxX >=100.0 && maxX < 200.0) return 10;
return 15;
}
void checkIfGraphShouldBeDisplayed(LabResult recentResult) {
shouldShowGraph = recentResult.checkIfGraphShouldBeDisplayed();
@ -576,7 +593,8 @@ class LabViewModel extends ChangeNotifier {
try {
var dateTime = DateUtil.convertStringToDate(element.verifiedOnDateTime!);
var resultValue = double.parse(element.resultValue!);
var transformedValue = transformValueInRange(double.parse(element.resultValue!), element.calculatedResultFlag ?? "");
// var transformedValue = transformValueInRange(double.parse(element.resultValue!), element.calculatedResultFlag ?? "");
var transformedValue = double.parse(element.resultValue!);
if (resultValue > maxY) {
maxY = resultValue;
}

@ -326,20 +326,20 @@ class LabResultDetails extends StatelessWidget {
},
leftLabelFormatter: (value) {
value = double.parse(value.toStringAsFixed(1));
// return leftLabels(value.toStringAsFixed(2));
if (value == labmodel.highRefrenceValue) {
return leftLabels(LocaleKeys.high.tr());
}
if (value == labmodel.lowRefenceValue) {
return leftLabels(LocaleKeys.low.tr());
}
return leftLabels(value.toStringAsFixed(2));
// if (value == labmodel.highRefrenceValue) {
// return leftLabels(LocaleKeys.high.tr());
// }
//
// if (value == labmodel.lowRefenceValue) {
// return leftLabels(LocaleKeys.low.tr());
// }
return SizedBox.shrink();
// }
},
graphColor: AppColors.blackColor,
graphShadowColor: Colors.transparent,
graphColor: AppColors.graphGridColor,
graphShadowColor: AppColors.graphGridColor.withOpacity(.5),
graphGridColor: graphColor.withOpacity(.4),
bottomLabelFormatter: (value, data) {
if (data.isEmpty) return SizedBox.shrink();
@ -371,7 +371,7 @@ class LabResultDetails extends StatelessWidget {
ranges.add(HorizontalRangeAnnotation(
y1: model.minY,
y2: model.lowRefenceValue,
color: AppColors.highAndLow.withOpacity(0.05),
color: Colors.transparent,
));
ranges.add(HorizontalRangeAnnotation(
@ -383,7 +383,7 @@ class LabResultDetails extends StatelessWidget {
ranges.add(HorizontalRangeAnnotation(
y1: model.highRefrenceValue,
y2: model.maxY,
color: AppColors.criticalLowAndHigh.withOpacity(0.05),
color: Colors.transparent,
));
return ranges;
}
@ -412,15 +412,17 @@ class LabResultDetails extends StatelessWidget {
}
double? getInterval(LabViewModel labmodel) {
return .1;
// var maxX = labmodel.maxY;
// if(maxX<1) return .5;
// if(maxX >1 && maxX < 5) return 1;
// if(maxX >5 && maxX < 10) return 5;
// if(maxX >10 && maxX < 50) return 10;
// if(maxX >50 && maxX < 100) return 20;
// if(maxX >100 && maxX < 200) return 30;
// return 50;
// return .1;
var maxX = labmodel.maxY;
if(maxX<1) return .3;
if(maxX >1 && maxX <= 5) return .7;
if(maxX >5 && maxX <= 10) return 2.5;
if(maxX >10 && maxX <= 50) return 5;
if(maxX >50 && maxX <= 100) return 10;
if(maxX >100 && maxX <= 200) return 30;
if(maxX >200 && maxX <= 300) return 50;
if(maxX >300 && maxX <= 400) return 100;
return 200 ;
}
Widget getLabDescription(BuildContext context) {

@ -257,7 +257,7 @@ class CustomGraph extends StatelessWidget {
isCurved: true,
isStrokeCapRound: true,
isStrokeJoinRound: true,
barWidth: 2,
barWidth: 3,
gradient: LinearGradient(
colors: [resolvedGraphColor, resolvedGraphColor],
begin: Alignment.centerLeft,

Loading…
Cancel
Save