/** * __set * * @param mixed $propertyName * @param mixed $propertyValue * @throws ezcBaseValueException * If a submitted parameter was out of range or type. * @throws ezcBasePropertyNotFoundException * If a the value for the property options is not an instance of * @return void * @ignore */ public function __set($propertyName, $propertyValue) { switch ($propertyName) { case 'startPoint': if (!$propertyValue instanceof ezcGraphCoordinate) { throw new ezcBaseValueException($propertyName, $propertyValue, 'ezcGraphCoordinate'); } else { $this->properties['startPoint'] = $propertyValue; } break; case 'endPoint': if (!$propertyValue instanceof ezcGraphCoordinate) { throw new ezcBaseValueException($propertyName, $propertyValue, 'ezcGraphCoordinate'); } else { $this->properties['endPoint'] = $propertyValue; } break; case 'startColor': $this->properties['startColor'] = ezcGraphColor::create($propertyValue); break; case 'endColor': $this->properties['endColor'] = ezcGraphColor::create($propertyValue); break; } }
public function testRenderHorizontalAxisReverse() { $chart = new ezcGraphLineChart(); $this->driver->expects($this->at(0))->method('drawLine')->with($this->equalTo(new ezcGraphCoordinate(450.0, 120.0), 1.0), $this->equalTo(new ezcGraphCoordinate(150.0, 120.0), 1.0), $this->equalTo(ezcGraphColor::fromHex('#2E3436')), $this->equalTo(1)); $this->driver->expects($this->at(1))->method('drawPolygon')->with($this->equalTo(array(new ezcGraphCoordinate(150.0, 120.0), new ezcGraphCoordinate(157.0, 116.5), new ezcGraphCoordinate(157.0, 123.5)), 1.0), $this->equalTo(ezcGraphColor::fromHex('#2E3436')), $this->equalTo(true)); $this->renderer->drawAxis(new ezcGraphBoundings(100, 20, 500, 220), new ezcGraphCoordinate(350, 100), new ezcGraphCoordinate(50, 100), $chart->yAxis); }
/** * Set an option value * * @param string $propertyName * @param mixed $propertyValue * @throws ezcBasePropertyNotFoundException * If a property is not defined in this class * @return void * @ignore */ public function __set($propertyName, $propertyValue) { switch ($propertyName) { case 'borderWidth': case 'markerWidth': if (!is_numeric($propertyValue) || $propertyValue < 1) { throw new ezcBaseValueException($propertyName, $propertyValue, 'int >= 1'); } $this->properties[$propertyName] = (int) $propertyValue; break; case 'borderColor': case 'startColor': case 'endColor': $this->properties[$propertyName] = ezcGraphColor::create($propertyValue); break; case 'odometerHeight': if (!is_numeric($propertyValue) || $propertyValue < 0 || $propertyValue > 1) { throw new ezcBaseValueException($propertyName, $propertyValue, '0 <= float <= 1'); } $this->properties[$propertyName] = (double) $propertyValue; break; default: return parent::__set($propertyName, $propertyValue); } }
/** * Constructor * * @param array $options Default option array * @return void * @ignore */ public function __construct(array $options = array()) { $this->properties['width'] = null; $this->properties['height'] = null; $this->properties['lineSpacing'] = 0.1; $this->properties['shadeCircularArc'] = 0.5; $this->properties['font'] = new ezcGraphFontOptions(); $this->properties['font']->color = ezcGraphColor::fromHex('#000000'); $this->properties['autoShortenString'] = true; $this->properties['autoShortenStringPostFix'] = '..'; parent::__construct($options); }
/** * Set an option value * * @param string $propertyName * @param mixed $propertyValue * @throws ezcBasePropertyNotFoundException * If a property is not defined in this class * @return void */ public function __set($propertyName, $propertyValue) { switch ($propertyName) { case 'minFontSize': if (!is_numeric($propertyValue) || $propertyValue < 1) { throw new ezcBaseValueException($propertyName, $propertyValue, 'float > 1'); } // Ensure min font size is smaller or equal max font size. if ($propertyValue > $this->properties['maxFontSize']) { throw new ezcBaseValueException($propertyName, $propertyValue, 'float <= ' . $this->properties['maxFontSize']); } $this->properties[$propertyName] = (double) $propertyValue; break; case 'maxFontSize': if (!is_numeric($propertyValue) || $propertyValue < 1) { throw new ezcBaseValueException($propertyName, $propertyValue, 'float > 1'); } // Ensure max font size is greater or equal min font size. if ($propertyValue < $this->properties['minFontSize']) { throw new ezcBaseValueException($propertyName, $propertyValue, 'float >= ' . $this->properties['minFontSize']); } $this->properties[$propertyName] = (double) $propertyValue; break; case 'minimalUsedFont': $propertyValue = (double) $propertyValue; if ($propertyValue < $this->minimalUsedFont) { $this->properties['minimalUsedFont'] = $propertyValue; } break; case 'color': case 'background': case 'border': case 'textShadowColor': $this->properties[$propertyName] = ezcGraphColor::create($propertyValue); break; case 'borderWidth': case 'padding': case 'textShadowOffset': if (!is_numeric($propertyValue) || $propertyValue < 0) { throw new ezcBaseValueException($propertyName, $propertyValue, 'int >= 0'); } $this->properties[$propertyName] = (int) $propertyValue; break; case 'minimizeBorder': case 'textShadow': if (!is_bool($propertyValue)) { throw new ezcBaseValueException($propertyName, $propertyValue, 'bool'); } $this->properties[$propertyName] = (bool) $propertyValue; break; case 'name': if (is_string($propertyValue)) { $this->properties['name'] = $propertyValue; } else { throw new ezcBaseValueException($propertyName, $propertyValue, 'string'); } break; case 'path': if (is_file($propertyValue) && is_readable($propertyValue)) { $this->properties['path'] = $propertyValue; $parts = pathinfo($this->properties['path']); switch (strtolower($parts['extension'])) { case 'fdb': $this->properties['type'] = ezcGraph::PALM_FONT; break; case 'pfb': $this->properties['type'] = ezcGraph::PS_FONT; break; case 'ttf': $this->properties['type'] = ezcGraph::TTF_FONT; break; case 'svg': $this->properties['type'] = ezcGraph::SVG_FONT; $this->properties['name'] = ezcGraphSvgFont::getFontName($propertyValue); break; default: throw new ezcGraphUnknownFontTypeException($propertyValue, $parts['extension']); } $this->pathChecked = true; } else { throw new ezcBaseFileNotFoundException($propertyValue, 'font'); } break; case 'type': if (is_int($propertyValue)) { $this->properties['type'] = $propertyValue; } else { throw new ezcBaseValueException($propertyName, $propertyValue, 'int'); } break; default: throw new ezcBasePropertyNotFoundException($propertyName); break; } }
/** * __set * * @param mixed $propertyName * @param mixed $propertyValue * @throws ezcBaseValueException * If a submitted parameter was out of range or type. * @throws ezcBasePropertyNotFoundException * If a the value for the property options is not an instance of * @return void */ public function __set($propertyName, $propertyValue) { switch ($propertyName) { case 'nullPosition': $this->properties['nullPosition'] = (double) $propertyValue; break; case 'axisSpace': if (!is_numeric($propertyValue) || $propertyValue < 0 || $propertyValue >= 1) { throw new ezcBaseValueException($propertyName, $propertyValue, '0 <= float < 1'); } $this->properties['axisSpace'] = (double) $propertyValue; break; case 'outerAxisSpace': if (!is_null($propertyValue) && (!is_numeric($propertyValue) || $propertyValue < 0 || $propertyValue >= 1)) { throw new ezcBaseValueException($propertyName, $propertyValue, 'null, or 0 <= float < 1'); } $this->properties['outerAxisSpace'] = $propertyValue; break; case 'majorGrid': $this->properties['majorGrid'] = ezcGraphColor::create($propertyValue); break; case 'minorGrid': $this->properties['minorGrid'] = ezcGraphColor::create($propertyValue); break; case 'majorStep': if (!is_numeric($propertyValue) || $propertyValue <= 0) { throw new ezcBaseValueException($propertyName, $propertyValue, 'float > 0'); } $this->properties['majorStep'] = (double) $propertyValue; break; case 'minorStep': if (!is_numeric($propertyValue) || $propertyValue <= 0) { throw new ezcBaseValueException($propertyName, $propertyValue, 'float > 0'); } $this->properties['minorStep'] = (double) $propertyValue; break; case 'formatString': $this->properties['formatString'] = (string) $propertyValue; break; case 'label': $this->properties['label'] = (string) $propertyValue; break; case 'labelSize': if (!is_numeric($propertyValue) || $propertyValue <= 6) { throw new ezcBaseValueException($propertyName, $propertyValue, 'int >= 6'); } $this->properties['labelSize'] = (int) $propertyValue; break; case 'labelMargin': if (!is_numeric($propertyValue) || $propertyValue <= 0) { throw new ezcBaseValueException($propertyName, $propertyValue, 'int >= 0'); } $this->properties['labelMargin'] = (int) $propertyValue; break; case 'maxArrowHeadSize': if (!is_numeric($propertyValue) || $propertyValue <= 0) { throw new ezcBaseValueException($propertyName, $propertyValue, 'int >= 0'); } $this->properties['maxArrowHeadSize'] = (int) $propertyValue; break; case 'minArrowHeadSize': if (!is_numeric($propertyValue) || $propertyValue <= 0) { throw new ezcBaseValueException($propertyName, $propertyValue, 'int >= 0'); } $this->properties['minArrowHeadSize'] = (int) $propertyValue; break; case 'axisLabelRenderer': if ($propertyValue instanceof ezcGraphAxisLabelRenderer) { $this->axisLabelRenderer = $propertyValue; } else { throw new ezcBaseValueException($propertyName, $propertyValue, 'ezcGraphAxisLabelRenderer'); } break; case 'labelCallback': if (is_callable($propertyValue)) { $this->properties['labelCallback'] = $propertyValue; } else { throw new ezcBaseValueException($propertyName, $propertyValue, 'callback function'); } break; case 'chartPosition': if (!is_numeric($propertyValue) || $propertyValue < 0 || $propertyValue > 1) { throw new ezcBaseValueException($propertyName, $propertyValue, '0 <= float <= 1'); } $this->properties['chartPosition'] = (double) $propertyValue; break; case 'labelRotation': if (!is_numeric($propertyValue)) { throw new ezcBaseValueException($propertyName, $propertyValue, 'float'); } $this->properties['labelRotation'] = fmod((double) $propertyValue, 360.0); break; default: parent::__set($propertyName, $propertyValue); break; } }
public function testRenderAxisNoInnerSteps() { $chart = new ezcGraphRadarChart(); $chart->palette = new ezcGraphPaletteBlack(); $chart->axis->axisLabelRenderer->innerStep = false; $chart->axis->axisLabelRenderer->outerStep = true; $chart->data['sampleData'] = new ezcGraphArrayDataSet(array('sample 1' => 234, 'sample 2' => 21, 'sample 3' => 324, 'sample 4' => 120, 'sample 5' => 1)); $mockedRenderer = $this->getMock('ezcGraphRenderer2d', array('drawStepRadar')); $mockedRenderer->expects($this->at(0))->method('drawStepRadar')->with($this->equalTo(new ezcGraphCoordinate(204.0, 180.0), 1.0), $this->equalTo(new ezcGraphCoordinate(204.0, 183.0), 1.0), $this->equalTo(ezcGraphColor::fromHex('#EEEEEC'))); $mockedRenderer->expects($this->at(4))->method('drawStepRadar')->with($this->equalTo(new ezcGraphCoordinate(460.0, 180.0), 1.0), $this->equalTo(new ezcGraphCoordinate(460.0, 183.0), 1.0), $this->equalTo(ezcGraphColor::fromHex('#EEEEEC'))); $chart->renderer = $mockedRenderer; $chart->render(500, 200); }
/** * Draws a circular arc * * @param ezcGraphCoordinate $center Center of ellipse * @param integer $width Width of ellipse * @param integer $height Height of ellipse * @param integer $size Height of border * @param float $startAngle Starting angle of circle sector * @param float $endAngle Ending angle of circle sector * @param ezcGraphColor $color Color of Border * @param bool $filled * @return void */ public function drawCircularArc(ezcGraphCoordinate $center, $width, $height, $size, $startAngle, $endAngle, ezcGraphColor $color, $filled = true) { $this->initiliazeSurface(); // Normalize angles if ($startAngle > $endAngle) { $tmp = $startAngle; $startAngle = $endAngle; $endAngle = $tmp; } $this->simulateCircularArc($center, $width, $height, $size, $startAngle, $endAngle, $color, $filled); if ($this->options->shadeCircularArc !== false && $filled) { $gradient = new ezcGraphLinearGradient(new ezcGraphCoordinate($center->x - $width, $center->y), new ezcGraphCoordinate($center->x + $width, $center->y), ezcGraphColor::fromHex('#FFFFFF')->transparent($this->options->shadeCircularArc * 1.5), ezcGraphColor::fromHex('#000000')->transparent($this->options->shadeCircularArc * 1.5)); $this->simulateCircularArc($center, $width, $height, $size, $startAngle, $endAngle, $gradient, $filled); } // Create polygon array to return $polygonArray = array(); for ($angle = $startAngle; $angle < $endAngle; $angle += $this->options->imageMapResolution) { $polygonArray[] = new ezcGraphCoordinate($center->x + cos(deg2rad($angle)) * $width / 2, $center->y + sin(deg2rad($angle)) * $height / 2); } $polygonArray[] = new ezcGraphCoordinate($center->x + cos(deg2rad($endAngle)) * $width / 2, $center->y + sin(deg2rad($endAngle)) * $height / 2); for ($angle = $endAngle; $angle > $startAngle; $angle -= $this->options->imageMapResolution) { $polygonArray[] = new ezcGraphCoordinate($center->x + cos(deg2rad($angle)) * $width / 2 + $size, $center->y + sin(deg2rad($angle)) * $height / 2); } $polygonArray[] = new ezcGraphCoordinate($center->x + cos(deg2rad($startAngle)) * $width / 2 + $size, $center->y + sin(deg2rad($startAngle)) * $height / 2); return $polygonArray; }
/** * Converts value to an {@link ezcGraphColor} object * * @param & $value * @return void */ protected function checkValue(&$value) { $value = ezcGraphColor::create($value); return true; }
public function testDrawTextWithMinimizedBorderAndBackgroundBottomRight() { $filename = $this->tempDir . __FUNCTION__ . '.png'; $this->driver->options->font->border = ezcGraphColor::fromHex('#555555'); $this->driver->options->font->background = ezcGraphColor::fromHex('#DDDDDD'); $this->driver->options->font->minimizeBorder = true; $this->driver->options->font->padding = 2; $this->driver->drawTextBox('Some test string', new ezcGraphCoordinate(10, 10), 150, 70, ezcGraph::RIGHT | ezcGraph::BOTTOM); $this->driver->render($filename); $this->assertTrue(file_exists($filename), 'No image was generated.'); $this->assertImageSimilar($filename, $this->basePath . 'compare/' . 'ezcGraphCairoDriverTest' . '_' . __FUNCTION__ . '.png', 'Image does not look as expected.', 2000); }
public function testRenderAxisGridFromBottom() { $chart = new ezcGraphLineChart(); $chart->palette = new ezcGraphPaletteBlack(); $chart->xAxis->axisLabelRenderer = new ezcGraphAxisNoLabelRenderer(); $chart->yAxis->axisLabelRenderer = new ezcGraphAxisBoxedLabelRenderer(); $chart->yAxis->position = ezcGraph::BOTTOM; $chart->data['sampleData'] = new ezcGraphArrayDataSet(array('sample 1' => 234, 'sample 2' => 21, 'sample 3' => 324, 'sample 4' => 120, 'sample 5' => 1)); $mockedRenderer = $this->getMock('ezcGraphRenderer2d', array('drawGridLine')); $mockedRenderer->expects($this->at(0))->method('drawGridLine')->with($this->equalTo(new ezcGraphCoordinate(140.0, 148.0), 1.0), $this->equalTo(new ezcGraphCoordinate(460.0, 148.0), 1.0), $this->equalTo(ezcGraphColor::fromHex('#888A85'))); $chart->renderer = $mockedRenderer; $chart->render(500, 200); }
public function testDrawJpeg() { $filename = $this->tempDir . __FUNCTION__ . '.jpg'; $this->driver->options->imageFormat = IMG_JPEG; $this->driver->drawPolygon(array(new ezcGraphCoordinate(45, 12), new ezcGraphCoordinate(122, 34), new ezcGraphCoordinate(12, 71)), ezcGraphColor::fromHex('#3465A4'), true); $this->driver->render($filename); $this->assertTrue(file_exists($filename), 'No image was generated.'); $this->assertImageSimilar($filename, $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.jpg', 'Image does not look as expected.', 2000); }
/** * Tries to detect type of color color definition and returns an * ezcGraphColor object * * @param mixed $color Some kind of color definition * @return ezcGraphColor */ public static function create($color) { if ($color instanceof ezcGraphColor) { return $color; } elseif (is_string($color)) { return ezcGraphColor::fromHex($color); } elseif (is_array($color)) { $testElement = reset($color); if (is_int($testElement)) { return ezcGraphColor::fromIntegerArray($color); } else { return ezcGraphColor::fromFloatArray($color); } } else { throw new ezcGraphUnknownColorDefinitionException($color); } }
public function testSetOptionsBorderLineChart() { $lineChart = new ezcGraphLineChart(); $lineChart->background = '#FF0000'; $this->assertEquals(ezcGraphColor::fromHex('FF0000'), $lineChart->background->color); }
public function testRenderChartSymbols() { $chart = new ezcGraphLineChart(); $chart->palette = new ezcGraphPaletteBlack(); $chart->data['sampleData'] = new ezcGraphArrayDataSet(array('sample 1' => 234, 'sample 2' => 21, 'sample 3' => 324, 'sample 4' => 120, 'sample 5' => 1)); $chart->data['sampleData']->symbol = ezcGraph::DIAMOND; $chart->data['sampleData']->symbol['sample 3'] = ezcGraph::CIRCLE; $mockedRenderer = $this->getMock('ezcGraphRenderer2d', array('drawDataLine')); $mockedRenderer->expects($this->at(0))->method('drawDataLine')->with($this->equalTo(new ezcGraphBoundings(140.0, 20.0, 460.0, 180.0), 1.0), $this->equalTo(new ezcGraphContext('sampleData', 'sample 1')), $this->equalTo(ezcGraphColor::fromHex('#729FCF')), $this->equalTo(new ezcGraphCoordinate(0.0, 0.415), 0.05), $this->equalTo(new ezcGraphCoordinate(0.0, 0.415), 0.05), $this->equalTo(0), $this->equalTo(1), $this->equalTo(ezcGraph::DIAMOND), $this->equalTo(ezcGraphColor::fromHex('#729FCF')), $this->equalTo(null)); $mockedRenderer->expects($this->at(2))->method('drawDataLine')->with($this->equalTo(new ezcGraphBoundings(140.0, 20.0, 460.0, 180.0), 1.0), $this->equalTo(new ezcGraphContext('sampleData', 'sample 3')), $this->equalTo(ezcGraphColor::fromHex('#729FCF')), $this->equalTo(new ezcGraphCoordinate(0.25, 0.9475), 0.05), $this->equalTo(new ezcGraphCoordinate(0.5, 0.19), 0.05), $this->equalTo(0), $this->equalTo(1), $this->equalTo(ezcGraph::CIRCLE), $this->equalTo(ezcGraphColor::fromHex('#729FCF')), $this->equalTo(null)); $mockedRenderer->expects($this->at(4))->method('drawDataLine')->with($this->equalTo(new ezcGraphBoundings(140.0, 20.0, 460.0, 180.0), 1.0), $this->equalTo(new ezcGraphContext('sampleData', 'sample 5')), $this->equalTo(ezcGraphColor::fromHex('#729FCF')), $this->equalTo(new ezcGraphCoordinate(0.75, 0.7), 0.05), $this->equalTo(new ezcGraphCoordinate(1.0, 0.9975000000000001), 0.05), $this->equalTo(0), $this->equalTo(1), $this->equalTo(ezcGraph::DIAMOND), $this->equalTo(ezcGraphColor::fromHex('#729FCF')), $this->equalTo(null)); $chart->renderer = $mockedRenderer; $chart->render(500, 200); }
/** * Draws a circular arc * * @param ezcGraphCoordinate $center Center of ellipse * @param integer $width Width of ellipse * @param integer $height Height of ellipse * @param integer $size Height of border * @param float $startAngle Starting angle of circle sector * @param float $endAngle Ending angle of circle sector * @param ezcGraphColor $color Color of Border * @param bool $filled * @return void */ public function drawCircularArc(ezcGraphCoordinate $center, $width, $height, $size, $startAngle, $endAngle, ezcGraphColor $color, $filled = true) { if ($startAngle > $endAngle) { $tmp = $startAngle; $startAngle = $endAngle; $endAngle = $tmp; } $id = $this->simulateCircularArc($center, $width, $height, $size, $startAngle, $endAngle, $color, $filled); if ($this->options->shadeCircularArc !== false && $filled) { $gradient = new ezcGraphLinearGradient(new ezcGraphCoordinate($center->x - $width, $center->y), new ezcGraphCoordinate($center->x + $width, $center->y), ezcGraphColor::fromHex('#FFFFFF')->transparent($this->options->shadeCircularArc * 1.5), ezcGraphColor::fromHex('#000000')->transparent($this->options->shadeCircularArc * 1.5)); $this->simulateCircularArc($center, $width, $height, $size, $startAngle, $endAngle, $gradient, $filled); } return $id; }
public function testInvertRandomColor() { $color = ezcGraphColor::create('#123456')->invert(); $this->assertEquals($color, ezcGraphColor::create('#EDCBA9')); }
public function testModifyPaletteDatasetColorArray() { $palette = new ezcGraphPaletteTango(); $palette->dataSetColor = array('#ABCDEF', array(255, 255, 255)); $this->assertEquals($palette->dataSetColor, ezcGraphColor::fromHex('#ABCDEF')); try { $palette->dataSetColor = '#FFFFFF'; } catch (ezcBaseValueException $e) { return true; } $this->fail('expected ezcBaseValueException.'); }
/** * Draws a single element of a circular arc * * ext/gd itself does not support something like circular arcs, so that * this functions draws rectangular polygons as a part of circular arcs * to interpolate them. This way it is possible to apply a linear gradient * to the circular arc, because we draw single steps anyway. * * @param ezcGraphCoordinate $center Center of ellipse * @param integer $width Width of ellipse * @param integer $height Height of ellipse * @param integer $size Height of border * @param float $startAngle Starting angle of circle sector * @param float $endAngle Ending angle of circle sector * @param ezcGraphColor $color Color of Border * @return void */ protected function drawCircularArcStep(ezcGraphCoordinate $center, $width, $height, $size, $startAngle, $endAngle, ezcGraphColor $color) { $this->drawPolygon(array(new ezcGraphCoordinate($center->x + cos(deg2rad($startAngle)) * $width / 2, $center->y + sin(deg2rad($startAngle)) * $height / 2), new ezcGraphCoordinate($center->x + cos(deg2rad($startAngle)) * $width / 2, $center->y + sin(deg2rad($startAngle)) * $height / 2 + $size), new ezcGraphCoordinate($center->x + cos(deg2rad($endAngle)) * $width / 2, $center->y + sin(deg2rad($endAngle)) * $height / 2 + $size), new ezcGraphCoordinate($center->x + cos(deg2rad($endAngle)) * $width / 2, $center->y + sin(deg2rad($endAngle)) * $height / 2)), $color->darken($this->options->shadeCircularArc * (1 + cos(deg2rad($startAngle))) / 2), true); }
/** * Set an option value * * @param string $propertyName * @param mixed $propertyValue * @throws ezcBasePropertyNotFoundException * If a property is not defined in this class * @return void * @ignore */ public function __set($propertyName, $propertyValue) { switch ($propertyName) { case 'pieChartShadowSize': if (!is_numeric($propertyValue) || $propertyValue < 0) { throw new ezcBaseValueException($propertyName, $propertyValue, 'float >= 0'); } $this->properties['pieChartShadowSize'] = (int) $propertyValue; break; case 'pieChartShadowTransparency': if (!is_numeric($propertyValue) || $propertyValue < 0 || $propertyValue > 1) { throw new ezcBaseValueException($propertyName, $propertyValue, '0 <= float <= 1'); } $this->properties['pieChartShadowTransparency'] = (double) $propertyValue; break; case 'pieChartShadowColor': $this->properties['pieChartShadowColor'] = ezcGraphColor::create($propertyValue); break; default: return parent::__set($propertyName, $propertyValue); } }
/** * __set * * @param mixed $propertyName Property name * @param mixed $propertyValue Property value * @access public * @ignore */ public function __set($propertyName, $propertyValue) { switch ($propertyName) { case 'axisColor': case 'majorGridColor': case 'minorGridColor': case 'fontColor': case 'chartBackground': case 'chartBorderColor': case 'elementBackground': case 'elementBorderColor': $this->{$propertyName} = ezcGraphColor::create($propertyValue); break; case 'dataSetColor': if (!is_array($propertyValue)) { throw new ezcBaseValueException($propertyName, $propertyValue, 'array( ezcGraphColor )'); } $this->dataSetColor = array(); foreach ($propertyValue as $value) { $this->dataSetColor[] = ezcGraphColor::create($value); } $this->colorIndex = -1; break; case 'dataSetSymbol': if (!is_array($propertyValue)) { throw new ezcBaseValueException($propertyName, $propertyValue, 'array( (int) ezcGraph::SYMBOL_TYPE )'); } $this->dataSetSymbol = array(); foreach ($propertyValue as $value) { $this->dataSetSymbol[] = (int) $value; } $this->symbolIndex = -1; break; case 'fontName': $this->{$propertyName} = (string) $propertyValue; break; case 'chartBorderWidth': case 'elementBorderWidth': case 'padding': case 'margin': if (!is_numeric($propertyValue) || $propertyValue < 0) { throw new ezcBaseValueException($propertyName, $propertyValue, 'int >= 0'); } $this->{$propertyName} = (int) $propertyValue; break; default: throw new ezcBasePropertyNotFoundException($propertyName); } }
public function testDrawGridLines() { $filename = $this->tempDir . __FUNCTION__ . '.svg'; $chart = new ezcGraphRadarChart(); $chart->palette = new ezcGraphPaletteBlack(); $chart->data['sample'] = new ezcGraphArrayDataSet($this->getRandomData(6)); $mockedRenderer = $this->getMock('ezcGraphRenderer2d', array('drawGridLine')); $mockedRenderer->expects($this->at(0))->method('drawGridLine')->with($this->equalTo(new ezcGraphCoordinate(338.0, 93.8), 0.1), $this->equalTo(new ezcGraphCoordinate(300.0, 80.0), 0.1), $this->equalTo(ezcGraphColor::fromHex('#888A85'))); $mockedRenderer->expects($this->at(1))->method('drawGridLine')->with($this->equalTo(new ezcGraphCoordinate(343.75, 92.90000000000001), 0.1), $this->equalTo(new ezcGraphCoordinate(300.0, 77.0), 0.1), $this->equalTo(ezcGraphColor::fromHex('#888A8588'))); // Next axis $mockedRenderer->expects($this->at(21))->method('drawGridLine')->with($this->equalTo(new ezcGraphCoordinate(323.5, 116.2), 0.1), $this->equalTo(new ezcGraphCoordinate(338.0, 93.8), 0.1), $this->equalTo(ezcGraphColor::fromHex('#888A85'))); $chart->renderer = $mockedRenderer; $chart->render(500, 200); }
/** * Draw step line * * Draw a step (marker for label position) on a axis. * * @param ezcGraphCoordinate $start Start point * @param ezcGraphCoordinate $end End point * @param ezcGraphColor $color Color of the grid line * @return void */ public function drawStepLine(ezcGraphCoordinate $start, ezcGraphCoordinate $end, ezcGraphColor $color) { $stepPolygonCoordinates = array($this->get3dCoordinate($start, true), $this->get3dCoordinate($end, true), $this->get3dCoordinate($end, false), $this->get3dCoordinate($start, false)); // Draw step polygon if ($this->options->fillAxis > 0 && $this->options->fillAxis < 1) { $this->driver->drawPolygon($stepPolygonCoordinates, $color->transparent($this->options->fillAxis), true); $this->driver->drawPolygon($stepPolygonCoordinates, $color, false); } else { $this->driver->drawPolygon($stepPolygonCoordinates, $color, !(bool) $this->options->fillAxis); } }
/** * __set * * @param mixed $propertyName * @param mixed $propertyValue * @throws ezcBaseValueException * If a submitted parameter was out of range or type. * @throws ezcBasePropertyNotFoundException * If a the value for the property options is not an instance of * @return void * @ignore */ public function __set($propertyName, $propertyValue) { switch ($propertyName) { case 'title': $this->properties['title'] = (string) $propertyValue; break; case 'background': $this->properties['background'] = ezcGraphColor::create($propertyValue); break; case 'border': $this->properties['border'] = ezcGraphColor::create($propertyValue); break; case 'padding': if (!is_numeric($propertyValue) || $propertyValue < 0) { throw new ezcBaseValueException($propertyName, $propertyValue, 'int >= 0'); } $this->properties['padding'] = (int) $propertyValue; break; case 'margin': if (!is_numeric($propertyValue) || $propertyValue < 0) { throw new ezcBaseValueException($propertyName, $propertyValue, 'int >= 0'); } $this->properties['margin'] = (int) $propertyValue; break; case 'borderWidth': if (!is_numeric($propertyValue) || $propertyValue < 0) { throw new ezcBaseValueException($propertyName, $propertyValue, 'int >= 0'); } $this->properties['borderWidth'] = (int) $propertyValue; break; case 'font': if ($propertyValue instanceof ezcGraphFontOptions) { $this->properties['font'] = $propertyValue; } elseif (is_string($propertyValue)) { if (!$this->fontCloned) { $this->properties['font'] = clone $this->font; $this->properties['fontCloned'] = true; } $this->properties['font']->path = $propertyValue; } else { throw new ezcBaseValueException($propertyName, $propertyValue, 'ezcGraphFontOptions'); } break; case 'position': $positions = array(ezcGraph::TOP, ezcGraph::BOTTOM, ezcGraph::LEFT, ezcGraph::RIGHT); if (in_array($propertyValue, $positions, true)) { $this->properties['position'] = $propertyValue; } else { throw new ezcBaseValueException('position', $propertyValue, 'integer'); } break; case 'maxTitleHeight': if (!is_numeric($propertyValue) || $propertyValue < 0) { throw new ezcBaseValueException($propertyName, $propertyValue, 'int >= 0'); } $this->properties['maxTitleHeight'] = (int) $propertyValue; break; case 'portraitTitleSize': if (!is_numeric($propertyValue) || $propertyValue < 0 || $propertyValue > 1) { throw new ezcBaseValueException($propertyName, $propertyValue, '0 <= float <= 1'); } $this->properties['portraitTitleSize'] = (double) $propertyValue; break; case 'landscapeTitleSize': if (!is_numeric($propertyValue) || $propertyValue < 0 || $propertyValue > 1) { throw new ezcBaseValueException($propertyName, $propertyValue, '0 <= float <= 1'); } $this->properties['landscapeTitleSize'] = (double) $propertyValue; break; default: throw new ezcBasePropertyNotFoundException($propertyName); break; } }
/** * __set * * @param mixed $propertyName * @param mixed $propertyValue * @throws ezcBaseValueException * If a submitted parameter was out of range or type. * @throws ezcBasePropertyNotFoundException * If a the value for the property options is not an instance of * @return void * @ignore */ public function __set($propertyName, $propertyValue) { switch ($propertyName) { case 'center': if (!$propertyValue instanceof ezcGraphCoordinate) { throw new ezcBaseValueException($propertyName, $propertyValue, 'ezcGraphCoordinate'); } else { $this->properties['center'] = $propertyValue; } break; case 'width': if (!is_numeric($propertyValue) || $propertyValue <= 0) { throw new ezcBaseValueException($propertyName, $propertyValue, 'float > 0'); } $this->properties['width'] = (double) $propertyValue; break; case 'height': if (!is_numeric($propertyValue) || $propertyValue <= 0) { throw new ezcBaseValueException($propertyName, $propertyValue, 'float > 0'); } $this->properties['height'] = (double) $propertyValue; break; case 'offset': if (!is_numeric($propertyValue) || $propertyValue < 0 || $propertyValue > 1) { throw new ezcBaseValueException($propertyName, $propertyValue, '0 <= float <= 1'); } $this->properties['offset'] = $propertyValue; break; case 'startColor': $this->properties['startColor'] = ezcGraphColor::create($propertyValue); break; case 'endColor': $this->properties['endColor'] = ezcGraphColor::create($propertyValue); break; } }
public function testISO_8859_15SpecialCharsFlash() { if (!ezcBaseFeatures::hasExtensionSupport("ming")) { $this->markTestSkipped("ext/ming not found"); } $filename = $this->tempDir . __FUNCTION__ . '.swf'; $driver = new ezcGraphFlashDriver(); $driver->options->font->path = $this->basePath . 'fdb_font.fdb'; $driver->options->width = 200; $driver->options->height = 100; $driver->drawPolygon(array(new ezcGraphCoordinate(10, 10), new ezcGraphCoordinate(160, 10), new ezcGraphCoordinate(160, 80), new ezcGraphCoordinate(10, 80)), ezcGraphColor::fromHex('#eeeeec'), true); $driver->drawTextBox(iconv('UTF-8', 'ISO-8859-15', 'öäüÖÄÜß'), new ezcGraphCoordinate(10, 10), 150, 70, ezcGraph::LEFT); $driver->render($filename); $this->swfCompare($filename, $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.swf'); }
public function testRenderer2dOptionsPropertyPieChartShadowColor() { $options = new ezcGraphRenderer2dOptions(); $this->assertEquals(ezcGraphColor::fromHex('#000000'), $options->pieChartShadowColor, 'Wrong default value for property pieChartShadowColor in class ezcGraphRenderer2dOptions'); $options->pieChartShadowColor = $color = ezcGraphColor::fromHex('#FFFFFF'); $this->assertSame($color, $options->pieChartShadowColor, 'Setting property value did not work for property pieChartShadowColor in class ezcGraphRenderer2dOptions'); try { $options->pieChartShadowColor = false; } catch (ezcGraphUnknownColorDefinitionException $e) { return true; } $this->fail('Expected ezcGraphUnknownColorDefinitionException.'); }
public function testPieRenderPieSegmentsWithLabelCallback() { $chart = new ezcGraphPieChart(); $chart->data['sample'] = new ezcGraphArrayDataSet(array('Mozilla' => 4375, 'IE' => 345, 'Opera' => 1204, 'wget' => 231, 'Safari' => 987)); $chart->data['sample']->highlight['wget'] = true; $chart->options->labelCallback = create_function('$label, $value, $percent', "return 'Callback: ' . \$label;"); $mockedRenderer = $this->getMock('ezcGraphRenderer2d', array('drawPieSegment')); $mockedRenderer->expects($this->at(0))->method('drawPieSegment')->with($this->equalTo(new ezcGraphBoundings(80, 0, 400, 200)), $this->equalTo(new ezcGraphContext('sample', 'Mozilla')), $this->equalTo(ezcGraphColor::fromHex('#3465A4')), $this->equalTo(0.0, 1.0), $this->equalTo(220.5, 0.1), $this->equalTo('Callback: Mozilla'), $this->equalTo(false)); $mockedRenderer->expects($this->at(1))->method('drawPieSegment')->with($this->equalTo(new ezcGraphBoundings(80, 0, 400, 200)), $this->equalTo(new ezcGraphContext('sample', 'IE')), $this->equalTo(ezcGraphColor::fromHex('#4E9A06')), $this->equalTo(220.5, 0.1), $this->equalTo(238.0, 1.0), $this->equalTo('Callback: IE'), $this->equalTo(false)); $mockedRenderer->expects($this->at(2))->method('drawPieSegment')->with($this->equalTo(new ezcGraphBoundings(80, 0, 400, 200)), $this->equalTo(new ezcGraphContext('sample', 'Opera')), $this->equalTo(ezcGraphColor::fromHex('#CC0000')), $this->equalTo(238.0, 1.0), $this->equalTo(298.6, 1.0), $this->equalTo('Callback: Opera'), $this->equalTo(false)); $mockedRenderer->expects($this->at(3))->method('drawPieSegment')->with($this->equalTo(new ezcGraphBoundings(80, 0, 400, 200)), $this->equalTo(new ezcGraphContext('sample', 'wget')), $this->equalTo(ezcGraphColor::fromHex('#EDD400')), $this->equalTo(298.6, 1.0), $this->equalTo(310.0, 1.0), $this->equalTo('Callback: wget'), $this->equalTo(true)); $mockedRenderer->expects($this->at(4))->method('drawPieSegment')->with($this->equalTo(new ezcGraphBoundings(80, 0, 400, 200)), $this->equalTo(new ezcGraphContext('sample', 'Safari')), $this->equalTo(ezcGraphColor::fromHex('#75505B')), $this->equalTo(310.0, 1.0), $this->equalTo(360.0, 1.0), $this->equalTo('Callback: Safari'), $this->equalTo(false)); $chart->renderer = $mockedRenderer; $chart->render(400, 200); }
/** * Draws a circular arc * * @param ezcGraphCoordinate $center Center of ellipse * @param integer $width Width of ellipse * @param integer $height Height of ellipse * @param integer $size Height of border * @param float $startAngle Starting angle of circle sector * @param float $endAngle Ending angle of circle sector * @param ezcGraphColor $color Color of Border * @param bool $filled * @return void */ public function drawCircularArc(ezcGraphCoordinate $center, $width, $height, $size, $startAngle, $endAngle, ezcGraphColor $color, $filled = true) { $this->createDocument(); // Normalize angles if ($startAngle > $endAngle) { $tmp = $startAngle; $startAngle = $endAngle; $endAngle = $tmp; } if ($endAngle - $startAngle > 180 || $startAngle % 180 != 0 && $endAngle % 180 != 0 && ($startAngle % 360 > 180 xor $endAngle % 360 > 180)) { // Border crosses he 180 degrees border $intersection = floor($endAngle / 180) * 180; while ($intersection >= $endAngle) { $intersection -= 180; } $this->drawCircularArc($center, $width, $height, $size, $startAngle, $intersection, $color, $filled); $this->drawCircularArc($center, $width, $height, $size, $intersection, $endAngle, $color, $filled); return; } // We need the radius $width /= 2; $height /= 2; $Xstart = $center->x + $this->options->graphOffset->x + $width * cos(-deg2rad($startAngle)); $Ystart = $center->y + $this->options->graphOffset->y + $height * sin(deg2rad($startAngle)); $Xend = $center->x + $this->options->graphOffset->x + $width * cos(-deg2rad($endAngle)); $Yend = $center->y + $this->options->graphOffset->y + $height * sin(deg2rad($endAngle)); if ($filled === true) { $arc = $this->dom->createElement('path'); $arc->setAttribute('d', sprintf('M %.2F,%.2F A %.2F,%.2F 0 %d,0 %.2F,%.2F L %.2F,%.2F A %.2F,%2F 0 %d,1 %.2F,%.2F z', $Xend, $Yend + $size, $width, $height, $endAngle - $startAngle > 180, $Xstart, $Ystart + $size, $Xstart, $Ystart, $width, $height, $endAngle - $startAngle > 180, $Xend, $Yend)); } else { $arc = $this->dom->createElement('path'); $arc->setAttribute('d', sprintf('M %.2F,%.2F A %.2F,%.2F 0 %d,1 %.2F,%.2F', $Xstart, $Ystart, $width, $height, $endAngle - $startAngle > 180, $Xend, $Yend)); } $arc->setAttribute('style', $this->getStyle($color, $filled)); $arc->setAttribute('id', $id = $this->options->idPrefix . 'CircularArc_' . ++$this->elementID); $this->elements->appendChild($arc); if ($this->options->shadeCircularArc !== false && $filled) { $gradient = new ezcGraphLinearGradient(new ezcGraphCoordinate($center->x - $width, $center->y), new ezcGraphCoordinate($center->x + $width, $center->y), ezcGraphColor::fromHex('#FFFFFF')->transparent($this->options->shadeCircularArc * 1.5), ezcGraphColor::fromHex('#000000')->transparent($this->options->shadeCircularArc)); $arc = $this->dom->createElement('path'); $arc->setAttribute('d', sprintf('M %.2F,%.2F A %.2F,%.2F 0 %d,0 %.2F,%.2F L %.2F,%.2F A %.2F,%2F 0 %d,1 %.2F,%.2F z', $Xend, $Yend + $size, $width, $height, $endAngle - $startAngle > 180, $Xstart, $Ystart + $size, $Xstart, $Ystart, $width, $height, $endAngle - $startAngle > 180, $Xend, $Yend)); $arc->setAttribute('style', $this->getStyle($gradient, $filled)); $arc->setAttribute('id', $id = $this->options->idPrefix . 'CircularArc_' . ++$this->elementID); $this->elements->appendChild($arc); } return $id; }
/** * Set an option value * * @param string $propertyName * @param mixed $propertyValue * @throws ezcBasePropertyNotFoundException * If a property is not defined in this class * @return void * @ignore */ public function __set($propertyName, $propertyValue) { switch ($propertyName) { case 'dataBorder': case 'pieChartGleam': case 'legendSymbolGleam': if ($propertyValue !== false && !is_numeric($propertyValue) || $propertyValue < 0 || $propertyValue > 1) { throw new ezcBaseValueException($propertyName, $propertyValue, 'false OR 0 <= float <= 1'); } $this->properties[$propertyName] = $propertyValue === false ? false : (double) $propertyValue; break; case 'maxLabelHeight': case 'moveOut': case 'barMargin': case 'barPadding': case 'legendSymbolGleamSize': case 'pieVerticalSize': case 'pieHorizontalSize': if (!is_numeric($propertyValue) || $propertyValue < 0 || $propertyValue > 1) { throw new ezcBaseValueException($propertyName, $propertyValue, '0 <= float <= 1'); } $this->properties[$propertyName] = (double) $propertyValue; break; case 'symbolSize': case 'titlePosition': case 'titleAlignement': case 'pieChartGleamBorder': if (!is_numeric($propertyValue) || $propertyValue < 0) { throw new ezcBaseValueException($propertyName, $propertyValue, 'int >= 0'); } $this->properties[$propertyName] = (int) $propertyValue; break; case 'showSymbol': case 'syncAxisFonts': if (!is_bool($propertyValue)) { throw new ezcBaseValueException($propertyName, $propertyValue, 'bool'); } $this->properties[$propertyName] = (bool) $propertyValue; break; case 'pieChartOffset': if (!is_numeric($propertyValue) || $propertyValue < 0 || $propertyValue > 360) { throw new ezcBaseValueException($propertyName, $propertyValue, '0 <= float <= 360'); } $this->properties[$propertyName] = (double) $propertyValue; break; case 'pieChartSymbolColor': case 'pieChartGleamColor': case 'legendSymbolGleamColor': $this->properties[$propertyName] = ezcGraphColor::create($propertyValue); break; default: return parent::__set($propertyName, $propertyValue); } }