Skip to content

Commit

Permalink
fix: null safety fixing, refactor some code
Browse files Browse the repository at this point in the history
  • Loading branch information
mdat31 committed Jun 4, 2021
1 parent 1414aec commit aed5587
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions lib/renderer/base_chart_painter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -134,19 +134,18 @@ abstract class BaseChartPainter extends CustomPainter {
void drawCrossLineText(Canvas canvas, Size size);

void initRect(Size size) {
double volHeight = volHidden != true ? mDisplayHeight! * 0.2 : 0;
double volHeight = volHidden != true ? mDisplayHeight * 0.2 : 0;
double secondaryHeight =
secondaryState != SecondaryState.NONE ? mDisplayHeight! * 0.2 : 0;
secondaryState != SecondaryState.NONE ? mDisplayHeight * 0.2 : 0;

double mainHeight = mDisplayHeight!;
double mainHeight = mDisplayHeight;
mainHeight -= volHeight;
mainHeight -= secondaryHeight;

mMainRect =
Rect.fromLTRB(0, mTopPadding, mWidth!, mTopPadding + mainHeight);
mMainRect = Rect.fromLTRB(0, mTopPadding, mWidth, mTopPadding + mainHeight);

if (volHidden != true) {
mVolRect = Rect.fromLTRB(0, mMainRect!.bottom + mChildPadding, mWidth!,
mVolRect = Rect.fromLTRB(0, mMainRect!.bottom + mChildPadding, mWidth,
mMainRect!.bottom + volHeight);
}

Expand All @@ -155,7 +154,7 @@ abstract class BaseChartPainter extends CustomPainter {
mSecondaryRect = Rect.fromLTRB(
0,
mMainRect!.bottom + volHeight + mChildPadding,
mWidth!,
mWidth,
mMainRect!.bottom + volHeight + secondaryHeight);
}
}
Expand All @@ -166,7 +165,7 @@ abstract class BaseChartPainter extends CustomPainter {
maxScrollX = getMinTranslateX().abs();
setTranslateXFromScrollX(scrollX);
mStartIndex = indexOfTranslateX(xToTranslateX(0));
mStopIndex = indexOfTranslateX(xToTranslateX(mWidth!));
mStopIndex = indexOfTranslateX(xToTranslateX(mWidth));
for (int i = mStartIndex; i <= mStopIndex; i++) {
var item = datas![i];
getMainMaxMinValue(item, i);
Expand Down Expand Up @@ -310,7 +309,7 @@ abstract class BaseChartPainter extends CustomPainter {

///获取平移的最小值
double getMinTranslateX() {
var x = -mDataLen + mWidth! / scaleX - mPointWidth / 2;
var x = -mDataLen + mWidth / scaleX - mPointWidth / 2;
return x >= 0 ? 0.0 : x;
}

Expand Down

0 comments on commit aed5587

Please sign in to comment.