mirror of
https://github.com/seigler/neat-charts
synced 2025-07-27 09:26:10 +00:00
label placement adjustments
This commit is contained in:
parent
481dd6747b
commit
57f007f71f
2 changed files with 10 additions and 7 deletions
|
@ -193,8 +193,8 @@ class SVGChartBuilder {
|
||||||
|
|
||||||
// Top and bottom grid labels
|
// Top and bottom grid labels
|
||||||
$gridText =
|
$gridText =
|
||||||
'<text x="'.(0.4 * $this->options['fontSize']).'" y="'.($this->options['fontSize'] / 2).'">'.($this->labelFormat($this->yMax, $labelPrecision + 1)).'</text>' .
|
'<text x="'.(0.4 * $this->options['fontSize']).'" y="'.($this->options['fontSize'] * 0.4).'">'.($this->labelFormat($this->yMax, $labelPrecision + 1)).'</text>' .
|
||||||
'<text x="'.(0.4 * $this->options['fontSize']).'" y="'.($this->options['fontSize'] / 2 + $this->height).'">'.($this->labelFormat($this->yMin, $labelPrecision + 1)).'</text>';
|
'<text x="'.(0.4 * $this->options['fontSize']).'" y="'.($this->options['fontSize'] * 0.4 + $this->height).'">'.($this->labelFormat($this->yMin, $labelPrecision + 1)).'</text>';
|
||||||
|
|
||||||
// Main labels and grid lines
|
// Main labels and grid lines
|
||||||
for (
|
for (
|
||||||
|
@ -204,14 +204,14 @@ class SVGChartBuilder {
|
||||||
) {
|
) {
|
||||||
$labelHeight = $this->transformY($labelY);
|
$labelHeight = $this->transformY($labelY);
|
||||||
if ( // label is not too close to the min or max
|
if ( // label is not too close to the min or max
|
||||||
$labelHeight < $this->height - 2.5 * $this->options['fontSize'] &&
|
$labelHeight < $this->height - 1.5 * $this->options['fontSize'] &&
|
||||||
$labelHeight > $this->options['fontSize'] * 2.5
|
$labelHeight > $this->options['fontSize'] * 1.5
|
||||||
) {
|
) {
|
||||||
$gridText .= '<text x="-'.(0.25 * $this->options['fontSize']).'" y="'.($labelHeight + $this->options['fontSize'] / 2).'">'.$this->labelFormat($labelY, $labelPrecision).'</text>';
|
$gridText .= '<text x="-'.(0.25 * $this->options['fontSize']).'" y="'.($labelHeight + $this->options['fontSize'] * 0.4).'">'.$this->labelFormat($labelY, $labelPrecision).'</text>';
|
||||||
$gridLines .= ' M0,'.$labelHeight.' '.$this->width.','.$labelHeight;
|
$gridLines .= ' M0,'.$labelHeight.' '.$this->width.','.$labelHeight;
|
||||||
} else if ( // label is too close
|
} else if ( // label is too close
|
||||||
$labelHeight < $this->height - $this->options['fontSize'] / 2 &&
|
$labelHeight < $this->height - $this->options['fontSize'] * 0.75 &&
|
||||||
$labelHeight > $this->options['fontSize'] / 2
|
$labelHeight > $this->options['fontSize'] * 0.75
|
||||||
) {
|
) {
|
||||||
$gridLines .= ' M'.( // move grid line over when it's very close to the min or max label
|
$gridLines .= ' M'.( // move grid line over when it's very close to the min or max label
|
||||||
$labelHeight < $this->height - $this->options['fontSize'] / 2 && $labelHeight > $this->options['fontSize'] / 2 ? 0 : $this->options['fontSize'] / 2
|
$labelHeight < $this->height - $this->options['fontSize'] / 2 && $labelHeight > $this->options['fontSize'] / 2 ? 0 : $this->options['fontSize'] / 2
|
||||||
|
|
3
demo.php
3
demo.php
|
@ -21,6 +21,9 @@
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
|
<header>
|
||||||
|
<h1>PHP SVG Chart Builder: chart demos</h1>
|
||||||
|
</header>
|
||||||
<main>
|
<main>
|
||||||
<section>
|
<section>
|
||||||
<h2>Poloniex Dash/BTC Price</h2>
|
<h2>Poloniex Dash/BTC Price</h2>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue