From 226221ca5d3d5da8b278d37d279646449ef352b1 Mon Sep 17 00:00:00 2001 From: liuxuan30 Date: Tue, 30 Jun 2015 11:41:24 +0800 Subject: [PATCH] fix drawing out of bound negative value axis labels issue --- Charts/Classes/Renderers/ChartYAxisRenderer.swift | 5 +++++ .../Renderers/ChartYAxisRendererHorizontalBarChart.swift | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/Charts/Classes/Renderers/ChartYAxisRenderer.swift b/Charts/Classes/Renderers/ChartYAxisRenderer.swift index 981d4efa9b..8dfe45a8c7 100644 --- a/Charts/Classes/Renderers/ChartYAxisRenderer.swift +++ b/Charts/Classes/Renderers/ChartYAxisRenderer.swift @@ -230,6 +230,11 @@ public class ChartYAxisRenderer: ChartAxisRendererBase pt.x = fixedPosition pt.y += offset + if (pt.y > viewPortHandler.contentRect.height) + { + continue + } + ChartUtils.drawText(context: context, text: text, point: pt, align: textAlign, attributes: [NSFontAttributeName: labelFont, NSForegroundColorAttributeName: labelTextColor]) } } diff --git a/Charts/Classes/Renderers/ChartYAxisRendererHorizontalBarChart.swift b/Charts/Classes/Renderers/ChartYAxisRendererHorizontalBarChart.swift index 25abe7b80c..59c6cace74 100644 --- a/Charts/Classes/Renderers/ChartYAxisRendererHorizontalBarChart.swift +++ b/Charts/Classes/Renderers/ChartYAxisRendererHorizontalBarChart.swift @@ -159,6 +159,11 @@ public class ChartYAxisRendererHorizontalBarChart: ChartYAxisRenderer return } + if (positions[i].x < viewPortHandler.contentRect.origin.x) + { + continue + } + ChartUtils.drawText(context: context, text: text, point: CGPoint(x: positions[i].x, y: fixedPosition - offset), align: .Center, attributes: [NSFontAttributeName: labelFont, NSForegroundColorAttributeName: labelTextColor]) } }