diff --git a/src/NeatCharts/LineChart.php b/src/NeatCharts/LineChart.php index df2279c..d5f13d9 100644 --- a/src/NeatCharts/LineChart.php +++ b/src/NeatCharts/LineChart.php @@ -85,6 +85,23 @@ namespace NeatCharts { $this->options['height'] = $this->height + $this->padding['top'] + $this->padding['bottom']; } + $numLabels = 2 + ceil($this->height / $this->options['fontSize'] / 6); + $labelInterval = $this->yRange / $numLabels; + $labelModulation = 10 ** (1 + floor(-log($this->yRange / $numLabels, 10))); + // 0.1 here is a fudge factor so we get multiples of 2.5 a little more often + if (fmod($labelInterval * $labelModulation, 2.5) < fmod($labelInterval * $labelModulation, 2) + 0.1) { + $labelModulation /= 2.5; + } else { + $labelModulation /= 2; + } + $labelInterval = ceil($labelInterval * $labelModulation) / $labelModulation; + $labelPrecision = $this->getPrecision($labelInterval); + + $this->padding['left'] = $this->options['fontSize'] * 0.6 * ( + 1 + max(1, ceil(log($this->yMax, 10))) + $this->getPrecision($labelInterval) + ) + 10; + $this->width = $this->options['width'] - $this->padding['left'] - $this->padding['right']; + $chartPoints = 'M'; $chartSplines = 'M'. $this->transformX($this->xMin).','. @@ -109,19 +126,6 @@ namespace NeatCharts { } } - $numLabels = 2 + ceil($this->height / $this->options['fontSize'] / 6); - $labelInterval = $this->yRange / $numLabels; - $labelModulation = 10 ** (1 + floor(-log($this->yRange / $numLabels, 10))); - - // 0.1 here is a fudge factor so we get multiples of 2.5 a little more often - if (fmod($labelInterval * $labelModulation, 2.5) < fmod($labelInterval * $labelModulation, 2) + 0.1) { - $labelModulation /= 2.5; - } else { - $labelModulation /= 2; - } - $labelInterval = ceil($labelInterval * $labelModulation) / $labelModulation; - $labelPrecision = $this->getPrecision($labelInterval); - // Top and bottom grid lines $gridLines = 'M10,0 '.$this->width.',0 '. @@ -156,8 +160,7 @@ namespace NeatCharts { } $chartID = rand(); - $this->output = ' - + $this->output = ' @@ -181,7 +184,7 @@ namespace NeatCharts { '.( $gridText ).' diff --git a/src/NeatCharts/NeatChart.php b/src/NeatCharts/NeatChart.php index 52b9d74..a008ca3 100644 --- a/src/NeatCharts/NeatChart.php +++ b/src/NeatCharts/NeatChart.php @@ -66,8 +66,8 @@ namespace NeatCharts { } public abstract function setData($chartData); - public function render() { - return $this->output; + public function render($inline = false) { + return ($inline ? '' : '') . $this->output; } } }