summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKore Nordmann <github@kore-nordmann.de>2009-05-29 07:21:05 +0000
committerKore Nordmann <github@kore-nordmann.de>2009-05-29 07:21:05 +0000
commitbf95cbf5f3c4eefb04a79ad9888e75d9fc2c57cf (patch)
tree73b7c29d86e20bd7fc52ac7ddb1da211c536f70a
parenteb36eb0b72d1e0b01b46f4570c2f6e77ba723e63 (diff)
downloadzetacomponents-graph-bf95cbf5f3c4eefb04a79ad9888e75d9fc2c57cf.zip
zetacomponents-graph-bf95cbf5f3c4eefb04a79ad9888e75d9fc2c57cf.tar.gz
- Fixed #14538: Performance degration for very high numbers of data points
# Test cases with 1000 data points show improvements of about 65% and with 2000 # data points around 85%. # Reduced the number of calls to array functions by better indexing or caching.
-rw-r--r--ChangeLog1
-rw-r--r--src/axis/labeled.php16
-rw-r--r--src/datasets/base.php23
3 files changed, 27 insertions, 13 deletions
diff --git a/ChangeLog b/ChangeLog
index 233ff78..a64e554 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,7 @@
1.4.3 - [RELEASEDATE]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+- Fixed #14538: Performance degration for very high numbers of data points.
- Fixed #14857: Highlight text misplaced in charts with multiple bar data
sets.
diff --git a/src/axis/labeled.php b/src/axis/labeled.php
index a9550c7..ff413ca 100644
--- a/src/axis/labeled.php
+++ b/src/axis/labeled.php
@@ -69,7 +69,6 @@
*/
class ezcGraphChartElementLabeledAxis extends ezcGraphChartElementAxis
{
-
/**
* Array with labeles for data
*
@@ -78,6 +77,13 @@ class ezcGraphChartElementLabeledAxis extends ezcGraphChartElementAxis
protected $labels = array();
/**
+ * Labels indexed by thei name as key for faster lookups
+ *
+ * @var array
+ */
+ protected $labelsIndexed = array();
+
+ /**
* Reduced amount of labels which will be displayed in the chart
*
* @var array
@@ -219,6 +225,7 @@ class ezcGraphChartElementLabeledAxis extends ezcGraphChartElementAxis
}
}
ksort( $this->labels );
+ $this->labelsIndexed = array_flip( $this->labels );
$this->properties['initialized'] = true;
}
@@ -415,9 +422,9 @@ class ezcGraphChartElementLabeledAxis extends ezcGraphChartElementAxis
*/
public function getCoordinate( $value )
{
- if ( $value === false ||
- $value === null ||
- ( $key = array_search( $value, $this->labels ) ) === false )
+ if ( ( $value === false ) ||
+ ( $value === null ) ||
+ ( !isset( $this->labelsIndexed[$value] ) ) )
{
switch ( $this->position )
{
@@ -431,6 +438,7 @@ class ezcGraphChartElementLabeledAxis extends ezcGraphChartElementAxis
}
else
{
+ $key = $this->labelsIndexed[$value];
switch ( $this->position )
{
case ezcGraph::LEFT:
diff --git a/src/datasets/base.php b/src/datasets/base.php
index 2ed1a5e..88096d6 100644
--- a/src/datasets/base.php
+++ b/src/datasets/base.php
@@ -67,6 +67,13 @@ abstract class ezcGraphDataSet implements ArrayAccess, Iterator, Countable
protected $pallet;
/**
+ * Array keys
+ *
+ * @var array
+ */
+ protected $keys;
+
+ /**
* Constructor
*
* @return void
@@ -219,13 +226,13 @@ abstract class ezcGraphDataSet implements ArrayAccess, Iterator, Countable
*/
public function current()
{
- $keys = array_keys( $this->data );
if ( !isset( $this->current ) )
{
+ $this->keys = array_keys( $this->data );
$this->current = 0;
}
- return $this->data[$keys[$this->current]];
+ return $this->data[$this->keys[$this->current]];
}
/**
@@ -239,14 +246,13 @@ abstract class ezcGraphDataSet implements ArrayAccess, Iterator, Countable
*/
public function next()
{
- $keys = array_keys( $this->data );
- if ( ++$this->current >= count( $keys ) )
+ if ( ++$this->current >= count( $this->keys ) )
{
return false;
}
else
{
- return $this->data[$keys[$this->current]];
+ return $this->data[$this->keys[$this->current]];
}
}
@@ -261,8 +267,7 @@ abstract class ezcGraphDataSet implements ArrayAccess, Iterator, Countable
*/
public function key()
{
- $keys = array_keys( $this->data );
- return $keys[$this->current];
+ return $this->keys[$this->current];
}
/**
@@ -276,8 +281,7 @@ abstract class ezcGraphDataSet implements ArrayAccess, Iterator, Countable
*/
public function valid()
{
- $keys = array_keys( $this->data );
- return isset( $keys[$this->current] );
+ return isset( $this->keys[$this->current] );
}
/**
@@ -290,6 +294,7 @@ abstract class ezcGraphDataSet implements ArrayAccess, Iterator, Countable
*/
public function rewind()
{
+ $this->keys = array_keys( $this->data );
$this->current = 0;
}
}
OpenPOWER on IntegriCloud