1212
1313import androidx .core .view .GestureDetectorCompat ;
1414
15+ import android .graphics .RectF ;
1516import android .graphics .Typeface ;
1617import android .util .AttributeSet ;
1718import android .view .MotionEvent ;
@@ -310,6 +311,10 @@ private void drawGird(Canvas canvas) {
310311 // Y value divider
311312 float dividerXPosition = mWidth - yAxisMaxLabelLength - 20F ;
312313 canvas .drawLine (dividerXPosition , 0 , dividerXPosition , mMainRect .bottom , mGridPaint );
314+ if (mVolDraw != null )
315+ canvas .drawLine (dividerXPosition , mVolRect .top , dividerXPosition , mVolRect .bottom , mGridPaint );
316+ if (mChildDraw != null )
317+ canvas .drawLine (dividerXPosition , mChildRect .top , dividerXPosition , mChildRect .bottom , mGridPaint );
313318
314319 //Vertical grid
315320 float columnSpace = dividerXPosition / mGridColumns ;
@@ -398,8 +403,13 @@ private void drawText(Canvas canvas) {
398403 Paint .FontMetrics fm = mTextPaint .getFontMetrics ();
399404 float textHeight = fm .descent - fm .ascent ;
400405 float baseLine = (textHeight - fm .bottom - fm .top ) / 2 ;
406+ float maxTextWidth = mWidth - yAxisMaxLabelLength - 20 ;
401407 //--------------Draw the value of the bar graph above-------------
402408 if (mMainDraw != null ) {
409+
410+ // Draw a background for Y-axis labels
411+ canvas .drawRect (maxTextWidth , 0 , mWidth , mMainRect .bottom , mBackgroundPaint );
412+
403413 canvas .drawText (formatValue (mMainMaxValue ), mWidth - calculateWidth (formatValue (mMainMaxValue )), baseLine + mMainRect .top , mTextPaint );
404414 canvas .drawText (formatValue (mMainMinValue ), mWidth - calculateWidth (formatValue (mMainMinValue )), mMainRect .bottom - textHeight + baseLine , mTextPaint );
405415 float rowValue = (mMainMaxValue - mMainMinValue ) / mGridRows ;
@@ -414,16 +424,18 @@ private void drawText(Canvas canvas) {
414424 //--------------Draw the value of the middle subgraph-------------
415425 if (mVolDraw != null ) {
416426 canvas .drawText (mVolDraw .getValueFormatter ().format (mVolMaxValue ),
417- mWidth - calculateWidth (formatValue (mVolMaxValue )), mMainRect .bottom + baseLine , mTextPaint );
418- /*canvas.drawText(mVolDraw.getValueFormatter().format(mVolMinValue),
419- mWidth - calculateWidth(formatValue(mVolMinValue)), mVolRect.bottom, mTextPaint);*/
427+ mWidth - calculateWidth (mVolDraw .getValueFormatter ().format (mVolMaxValue )), mMainRect .bottom + baseLine , mTextPaint );
428+
429+ // Draw a background for Y-axis labels
430+ canvas .drawRect (maxTextWidth , mVolRect .top , mWidth , mVolRect .bottom , mBackgroundPaint );
420431 }
421432 //--------------Draw the value of the subgraph below-------------
422433 if (mChildDraw != null ) {
423434 canvas .drawText (mChildDraw .getValueFormatter ().format (mChildMaxValue ),
424435 mWidth - calculateWidth (formatValue (mChildMaxValue )), mVolRect .bottom + baseLine , mTextPaint );
425- /*canvas.drawText(mChildDraw.getValueFormatter().format(mChildMinValue),
426- mWidth - calculateWidth(formatValue(mChildMinValue)), mChildRect.bottom, mTextPaint);*/
436+
437+ // Draw a background for Y-axis labels
438+ canvas .drawRect (maxTextWidth , mChildRect .top , mWidth , mChildRect .bottom , mBackgroundPaint );
427439 }
428440 //--------------Draw time---------------------
429441 float columnSpace = mWidth / mGridColumns ;
0 commit comments