Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Radar bound fill #21

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/charts/line.php
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,12 @@ protected function renderData( ezcGraphRenderer $renderer, ezcGraphBoundings $bo
$yAxis = ( $data->yAxis->default ? $data->yAxis->default: $this->elements['yAxis'] );

// Determine fill color for dataset
if ( $this->options->fillLines !== false )
if ( $data->fillLine !== false )
{
$fillColor = clone $data->color->default;
$fillColor->alpha = (int) round( ( 255 - $fillColor->alpha ) * ( $data->fillLine / 255 ) );
}
else if ( $this->options->fillLines !== false )
{
$fillColor = clone $data->color->default;
$fillColor->alpha = (int) round( ( 255 - $fillColor->alpha ) * ( $this->options->fillLines / 255 ) );
Expand Down
26 changes: 25 additions & 1 deletion src/charts/radar.php
Original file line number Diff line number Diff line change
Expand Up @@ -296,11 +296,17 @@ protected function renderData( ezcGraphRenderer $renderer, ezcGraphBoundings $bo

// Display data
$this->elements['axis']->position = ezcGraph::TOP;
$prevDataSetPoints = array();
foreach ( $this->data as $datasetName => $data )
{
--$nr;
// Determine fill color for dataset
if ( $this->options->fillLines !== false )
if ( $data->fillLine !== false )
{
$fillColor = clone $data->color->default;
$fillColor->alpha = (int) round( ( 255 - $fillColor->alpha ) * ( $data->fillLine / 255 ) );
}
else if ( $this->options->fillLines !== false )
{
$fillColor = clone $data->color->default;
$fillColor->alpha = (int) round( ( 255 - $fillColor->alpha ) * ( $this->options->fillLines / 255 ) );
Expand All @@ -310,8 +316,11 @@ protected function renderData( ezcGraphRenderer $renderer, ezcGraphBoundings $bo
$fillColor = null;
}

$prevDataSetBounded = $data->boundFillToPreviousDataSet;

// Draw lines for dataset
$lastPoint = false;
$lastInnerPoint = false;
foreach ( $data as $key => $value )
{
$point = new ezcGraphCoordinate(
Expand All @@ -331,13 +340,25 @@ protected function renderData( ezcGraphRenderer $renderer, ezcGraphBoundings $bo
);
// */

if ($prevDataSetBounded && array_key_exists($key, $prevDataSetPoints)) {
$innerPoint = $prevDataSetPoints[$key];
}
else {
$innerPoint = new ezcGraphCoordinate(
0,
0
);
}

$renderer->drawRadarDataLine(
$boundings,
new ezcGraphContext( $datasetName, $key, $data->url[$key] ),
$data->color->default,
clone $center,
( $lastPoint === false ? $point : $lastPoint ),
$point,
$innerPoint,
( $lastInnerPoint === false ? $innerPoint : $lastInnerPoint ),
$nr,
$count,
$data->symbol[$key],
Expand All @@ -346,7 +367,10 @@ protected function renderData( ezcGraphRenderer $renderer, ezcGraphBoundings $bo
$this->options->lineThickness
);

$prevDataSetPoints[$key] = $point;

$lastPoint = $point;
$lastInnerPoint = $innerPoint;
}
}
}
Expand Down
28 changes: 28 additions & 0 deletions src/datasets/base.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@
* Displayed string if a data point is highlighted
* @property bool $highlight
* Status if datapoint element is hilighted
* @property mixed $fillLine
* Interpretation depends on underlying chart type
* @see chart type fillLines option for details
* @property bool $boundFillToPreviousDataSet
* Only fill the region between the current data set
* and the previous data set. Only works for radar
* plots at this time. @see $fillLine property.
* @property int $displayType
* Display type of chart data
* @property string $url
Expand Down Expand Up @@ -110,6 +117,8 @@ public function __construct()
$this->properties['yAxis'] = new ezcGraphDataSetAxisProperty( $this );

$this->properties['highlight']->default = false;
$this->properties['fillLine'] = false;
$this->properties['boundFillToPreviousDataSet'] = false;
}

/**
Expand Down Expand Up @@ -149,6 +158,25 @@ public function __set( $propertyName, $propertyValue )
$this->symbol->default = $this->palette->dataSetSymbol;
break;

case 'fillLine':
if ( ( $propertyValue !== false ) &&
!is_numeric( $propertyValue ) ||
( $propertyValue < 0 ) ||
( $propertyValue > 255 ) )
{
throw new ezcBaseValueException( $propertyName, $propertyValue, 'false OR 0 <= int <= 255' );
}

$this->properties[$propertyName] = (
$propertyValue === false
? false
: (int) $propertyValue );
break;

case 'boundFillToPreviousDataSet':
$this->properties[$propertyName] = $propertyValue;
break;

default:
throw new ezcBasePropertyNotFoundException( $propertyName );
break;
Expand Down
2 changes: 2 additions & 0 deletions src/interfaces/radar_renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ public function drawRadarDataLine(
ezcGraphCoordinate $center,
ezcGraphCoordinate $start,
ezcGraphCoordinate $end,
ezcGraphCoordinate $fillStart,
ezcGraphCoordinate $fillEnd,
$dataNumber = 1,
$dataCount = 1,
$symbol = ezcGraph::NO_SYMBOL,
Expand Down
20 changes: 16 additions & 4 deletions src/renderer/2d.php
Original file line number Diff line number Diff line change
Expand Up @@ -884,6 +884,8 @@ public function drawRadarDataLine(
ezcGraphCoordinate $center,
ezcGraphCoordinate $start,
ezcGraphCoordinate $end,
ezcGraphCoordinate $fillStart,
ezcGraphCoordinate $fillEnd,
$dataNumber = 1,
$dataCount = 1,
$symbol = ezcGraph::NO_SYMBOL,
Expand All @@ -905,6 +907,18 @@ public function drawRadarDataLine(
$end->x * 2 * M_PI,
$end->y
);
$fillStart = $this->getCoordinateFromAngleAndRadius(
$boundings,
$center,
$fillStart->x * 2 * M_PI,
$fillStart->y
);
$fillEnd = $this->getCoordinateFromAngleAndRadius(
$boundings,
$center,
$fillEnd->x * 2 * M_PI,
$fillEnd->y
);

// Fill line
if ( $fillColor !== null )
Expand All @@ -913,10 +927,8 @@ public function drawRadarDataLine(
array(
$start,
$end,
new ezcGraphCoordinate(
$boundings->x0 + $center->x,
$boundings->y0 + $center->y
),
$fillStart,
$fillEnd
),
$fillColor,
true
Expand Down