/Graph/tests/axis_rotated_boxed_renderer_test.php

https://github.com/F5/zetacomponents · PHP · 304 lines · 192 code · 75 blank · 37 comment · 2 complexity · be4f4166d947c017eb71f736337c17fb MD5 · raw file

  1. <?php
  2. /**
  3. * ezcGraphAxisRotatedRendererTest
  4. *
  5. * Licensed to the Apache Software Foundation (ASF) under one
  6. * or more contributor license agreements. See the NOTICE file
  7. * distributed with this work for additional information
  8. * regarding copyright ownership. The ASF licenses this file
  9. * to you under the Apache License, Version 2.0 (the
  10. * "License"); you may not use this file except in compliance
  11. * with the License. You may obtain a copy of the License at
  12. *
  13. * http://www.apache.org/licenses/LICENSE-2.0
  14. *
  15. * Unless required by applicable law or agreed to in writing,
  16. * software distributed under the License is distributed on an
  17. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  18. * KIND, either express or implied. See the License for the
  19. * specific language governing permissions and limitations
  20. * under the License.
  21. *
  22. * @package Graph
  23. * @version //autogen//
  24. * @subpackage Tests
  25. * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
  26. */
  27. require_once dirname( __FILE__ ) . '/test_case.php';
  28. /**
  29. * Tests for ezcGraph class.
  30. *
  31. * @package Graph
  32. * @subpackage Tests
  33. */
  34. class ezcGraphAxisRotatedBoxedRendererTest extends ezcGraphTestCase
  35. {
  36. protected $basePath;
  37. protected $tempDir;
  38. protected $renderer;
  39. protected $driver;
  40. public static function suite()
  41. {
  42. return new PHPUnit_Framework_TestSuite( __CLASS__ );
  43. }
  44. protected function setUp()
  45. {
  46. static $i = 0;
  47. if ( version_compare( phpversion(), '5.1.3', '<' ) )
  48. {
  49. $this->markTestSkipped( "This test requires PHP 5.1.3 or later." );
  50. }
  51. $this->tempDir = $this->createTempDir( __CLASS__ . sprintf( '_%03d_', ++$i ) ) . '/';
  52. $this->basePath = dirname( __FILE__ ) . '/data/';
  53. }
  54. protected function tearDown()
  55. {
  56. if ( !$this->hasFailed() )
  57. {
  58. $this->removeTempDir();
  59. }
  60. }
  61. public function testRenderCompleteBarChart()
  62. {
  63. $filename = $this->tempDir . __FUNCTION__ . '.svg';
  64. $chart = new ezcGraphBarChart();
  65. $chart->palette = new ezcGraphPaletteBlack();
  66. $chart->xAxis->axisLabelRenderer = new ezcGraphAxisRotatedBoxedLabelRenderer();
  67. $chart->data['Line 1'] = new ezcGraphArrayDataSet( array( 'sample 1' => 100, 'sample 2' => 0, 'sample 3' => 500, 'sample 4' => 250, 'sample 5' => 500) );
  68. $chart->render( 500, 200, $filename );
  69. $this->compare(
  70. $filename,
  71. $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.svg'
  72. );
  73. }
  74. public function testRenderCompleteBarChartReverseRotated()
  75. {
  76. $filename = $this->tempDir . __FUNCTION__ . '.svg';
  77. $chart = new ezcGraphBarChart();
  78. $chart->data['Line 1'] = new ezcGraphArrayDataSet( array( 'sample 1' => 234, 'sample 2' => 21, 'sample 3' => 324, 'sample 4' => 120, 'sample 5' => 1) );
  79. $chart->data['Line 2'] = new ezcGraphArrayDataSet( array( 'sample 1' => 543, 'sample 2' => 234, 'sample 3' => 298, 'sample 4' => 5, 'sample 5' => 613) );
  80. $chart->xAxis->axisLabelRenderer = new ezcGraphAxisRotatedBoxedLabelRenderer();
  81. $chart->xAxis->axisSpace = .25;
  82. $chart->xAxis->axisLabelRenderer->angle = -45;
  83. $chart->yAxis->axisLabelRenderer = new ezcGraphAxisRotatedBoxedLabelRenderer();
  84. $chart->yAxis->axisLabelRenderer->angle = -45;
  85. $chart->render( 500, 200, $filename );
  86. $this->compare(
  87. $filename,
  88. $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.svg'
  89. );
  90. }
  91. public function testRenderRotatedAxisWithLotsOfLabels()
  92. {
  93. $filename = $this->tempDir . __FUNCTION__ . '.svg';
  94. $labelCount = 30;
  95. $data = $this->getRandomData( $labelCount, 500, 2000, 23 );
  96. $chart = new ezcGraphBarChart();
  97. $chart->data['sample'] = new ezcGraphArrayDataSet( $data );
  98. // Set manual label count
  99. $chart->xAxis->labelCount = 31;
  100. $chart->xAxis->axisLabelRenderer = new ezcGraphAxisRotatedBoxedLabelRenderer();
  101. $chart->xAxis->axisLabelRenderer->angle = 45;
  102. $chart->render( 500, 200, $filename );
  103. $this->compare(
  104. $filename,
  105. $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.svg'
  106. );
  107. }
  108. public function testRenderRotatedAxisWithLotsOfLabelsVertical()
  109. {
  110. $filename = $this->tempDir . __FUNCTION__ . '.svg';
  111. $labelCount = 20;
  112. $data = $this->getRandomData( $labelCount, 500, 2000, 23 );
  113. $chart = new ezcGraphBarChart();
  114. $chart->data['sample'] = new ezcGraphArrayDataSet( $data );
  115. // Set manual label count
  116. $chart->xAxis->labelCount = 21;
  117. $chart->xAxis->axisLabelRenderer = new ezcGraphAxisRotatedBoxedLabelRenderer();
  118. $chart->xAxis->axisLabelRenderer->angle = 0;
  119. $chart->render( 500, 200, $filename );
  120. $this->compare(
  121. $filename,
  122. $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.svg'
  123. );
  124. }
  125. public function testRenderRotatedAxisWithLotsOfLabelsLargeAngle()
  126. {
  127. $filename = $this->tempDir . __FUNCTION__ . '.svg';
  128. $labelCount = 10;
  129. $data = $this->getRandomData( $labelCount, 500, 2000, 23 );
  130. $chart = new ezcGraphBarChart();
  131. $chart->data['sample'] = new ezcGraphArrayDataSet( $data );
  132. // Set manual label count
  133. $chart->xAxis->labelCount = 11;
  134. $chart->xAxis->axisLabelRenderer = new ezcGraphAxisRotatedBoxedLabelRenderer();
  135. $chart->xAxis->axisLabelRenderer->angle = 75;
  136. $chart->render( 500, 200, $filename );
  137. $this->compare(
  138. $filename,
  139. $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.svg'
  140. );
  141. }
  142. public function testRender3dRotatedAxisWithLotsOfLabels()
  143. {
  144. $filename = $this->tempDir . __FUNCTION__ . '.svg';
  145. $labelCount = 30;
  146. $data = $this->getRandomData( $labelCount, 500, 2000, 23 );
  147. $chart = new ezcGraphBarChart();
  148. $chart->data['sample'] = new ezcGraphArrayDataSet( $data );
  149. // Set manual label count
  150. $chart->xAxis->labelCount = 31;
  151. $chart->xAxis->axisLabelRenderer = new ezcGraphAxisRotatedBoxedLabelRenderer();
  152. $chart->xAxis->axisLabelRenderer->angle = 45;
  153. $chart->renderer = new ezcGraphRenderer3d();
  154. $chart->render( 500, 200, $filename );
  155. $this->compare(
  156. $filename,
  157. $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.svg'
  158. );
  159. }
  160. public function testOptimalAngleCalculation()
  161. {
  162. $filename = $this->tempDir . __FUNCTION__ . '.svg';
  163. $chart = new ezcGraphBarChart();
  164. $chart->data['Line 1'] = new ezcGraphArrayDataSet( array( 'sample 1' => 234, 'sample 2' => 21, 'sample 3' => 324, 'sample 4' => 120, 'sample 5' => 1) );
  165. $chart->data['Line 2'] = new ezcGraphArrayDataSet( array( 'sample 1' => 543, 'sample 2' => 234, 'sample 3' => 298, 'sample 4' => 5, 'sample 5' => 613) );
  166. $chart->xAxis->axisLabelRenderer = new ezcGraphAxisRotatedBoxedLabelRenderer();
  167. $chart->yAxis->axisLabelRenderer = new ezcGraphAxisRotatedBoxedLabelRenderer();
  168. $chart->render( 500, 200, $filename );
  169. $this->compare(
  170. $filename,
  171. $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.svg'
  172. );
  173. $this->assertEquals(
  174. $chart->xAxis->axisLabelRenderer->angle,
  175. 76.,
  176. 'Angle estimation wrong.',
  177. 1.
  178. );
  179. $this->assertEquals(
  180. $chart->yAxis->axisLabelRenderer->angle,
  181. 53.,
  182. 'Angle estimation wrong.',
  183. 1.
  184. );
  185. }
  186. public function testRenderWithModifiedAxisSpace()
  187. {
  188. $filename = $this->tempDir . __FUNCTION__ . '.svg';
  189. $labelCount = 20;
  190. $data = $this->getRandomData( $labelCount, 500, 2000, 23 );
  191. $chart = new ezcGraphBarChart();
  192. $chart->palette = new ezcGraphPaletteBlack();
  193. $chart->data['sample'] = new ezcGraphArrayDataSet( $data );
  194. // Set manual label count
  195. $chart->xAxis->labelCount = 21;
  196. $chart->xAxis->axisLabelRenderer = new ezcGraphAxisRotatedBoxedLabelRenderer();
  197. $chart->xAxis->axisLabelRenderer->angle = 45;
  198. $chart->xAxis->axisSpace = 0.1;
  199. $chart->yAxis->axisLabelRenderer = new ezcGraphAxisNoLabelRenderer();
  200. $chart->yAxis->axisSpace = 0.05;
  201. $chart->render( 500, 200, $filename );
  202. $this->compare(
  203. $filename,
  204. $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.svg'
  205. );
  206. }
  207. public function testRenderWithZeroAxisSpace()
  208. {
  209. $filename = $this->tempDir . __FUNCTION__ . '.svg';
  210. $labelCount = 20;
  211. $data = $this->getRandomData( $labelCount, 500, 2000, 23 );
  212. $chart = new ezcGraphBarChart();
  213. $chart->palette = new ezcGraphPaletteBlack();
  214. $chart->data['sample'] = new ezcGraphArrayDataSet( $data );
  215. // Set manual label count
  216. $chart->xAxis->labelCount = 21;
  217. $chart->xAxis->axisLabelRenderer = new ezcGraphAxisRotatedBoxedLabelRenderer();
  218. $chart->xAxis->axisLabelRenderer->angle = 45;
  219. $chart->xAxis->axisSpace = 0.1;
  220. $chart->yAxis->axisLabelRenderer = new ezcGraphAxisNoLabelRenderer();
  221. $chart->yAxis->axisSpace = 0;
  222. $chart->render( 500, 200, $filename );
  223. $this->compare(
  224. $filename,
  225. $this->basePath . 'compare/' . __CLASS__ . '_' . __FUNCTION__ . '.svg'
  226. );
  227. }
  228. }
  229. ?>