MPAndroidChart icon indicating copy to clipboard operation
MPAndroidChart copied to clipboard

Marker not visible when outside of chartview area event if cliptochildren = false & cliptopadding = false

Open anneso-duchene opened this issue 5 years ago • 2 comments

When set setClipToChildren and setClipToPadding to false on the chart, the marker view displayed outside of the chart is not visible. I want to put the marker view above the chartview.

To do this in the onDraw I override the yPosition

 @Override
    public void draw(Canvas canvas, float posX, float posY) {
        // take offsets into consideration
        int lineChartWidth = parentView.getWidth();
        float offsetX = getOffset().getX();

        posY = -getHeight(); <-- to put the marker above

        float width = getWidth();

        if (posX + offsetX < 0) {
            offsetX = -posX;
        } else if (posX + width + offsetX > lineChartWidth) {
            offsetX = lineChartWidth - posX - width;
        }

        posX += offsetX;

        // translate to the correct position and draw
        canvas.translate(posX, posY);
        draw(canvas);
        canvas.translate(-posX, -posY);
    }

All the parent of the chart have cliptoChidren = false & clipToPadding = false With the iOS library the result is correct

image

Device (please complete the following information):

  • Device: Samsung TabS2
  • Android Version7.0
  • Library Version v3.1.0

Thanks in advance : )

anneso-duchene avatar Mar 25 '20 14:03 anneso-duchene

If you replace posY = - getHeight() by posY = - (getHeight - 1) it's working ...

anneso-duchene avatar Mar 25 '20 14:03 anneso-duchene

override fun getOffsetForDrawingAtPoint(posX: Float, posY: Float): MPPointF {
        if (posX > chartView.width - width) {
            offset.x = (-width).toFloat()
        } else {
            offset.x = (-(width / 2)).toFloat()
        }

        offset.y = -(height / 2).toFloat()

        return offset
    }

You need to set chart view to MarkerView.chartView before calculation.

mostafaimran avatar Dec 23 '22 07:12 mostafaimran