From 68249690717964b0ebf7f24f8d0162906dbf4667 Mon Sep 17 00:00:00 2001 From: Joshua Seigler Date: Tue, 7 Mar 2017 02:43:36 -0500 Subject: [PATCH] fix: avoid overlapping x-axis labels --- src/NeatCharts/NeatChart.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/NeatCharts/NeatChart.php b/src/NeatCharts/NeatChart.php index dec61fa..08aaa0a 100644 --- a/src/NeatCharts/NeatChart.php +++ b/src/NeatCharts/NeatChart.php @@ -141,7 +141,7 @@ namespace NeatCharts { 'days' => [24 * 60 * 60, 'M j'], 'years' => [365 * 24 * 60 * 60, 'Y'] ]; - $numXLabels = 1 + round($this->width / $this->options['fontSize'] / 10); + $numXLabels = round($this->width / $this->options['fontSize'] / 12); $scale = 'years'; $xLabelFormat = $timeIntervals[$scale][1]; foreach ($timeIntervals as $period => $duration) { @@ -161,7 +161,15 @@ namespace NeatCharts { $labelXCoord = $this->transformX($labelX); $gridLines .= 'M'.$labelXCoord.' 0 '.$labelXCoord.' '.$this->height.' '; $xLabelAlignment = ($this->width - $labelXCoord > $this->options['fontSize'] * 2 ? ($labelXCoord > $this->options['fontSize'] * 2 ? 'middle' : 'start') : 'end'); - $gridText .= ''.date($xLabelFormat, $labelX).''; + if ($this->width - $labelXCoord > $this->options['fontSize'] * 2) { + if ($labelXCoord > $this->options['fontSize'] * 2) { + $gridText .= ''.date($xLabelFormat, $labelX).''; + } else { + $gridText .= ''.date($xLabelFormat, $labelX).''; + }; + } else { + $gridText .= ''.date($xLabelFormat, $labelX).''; + } } }