Skip to content

Commit

Permalink
Added datetime_key_format option
Browse files Browse the repository at this point in the history
  • Loading branch information
goat1000 committed Jul 26, 2016
1 parent 2661a96 commit 788ffc3
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
23 changes: 20 additions & 3 deletions SVGGraph.php
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ abstract class Graph {
private static $precision = 5;
private static $decimal = '.';
private static $thousands = ',';
public static $key_format = NULL;
protected $legend_reverse = false;
protected $force_assoc = false;
protected $repeated_keys = 'error';
Expand Down Expand Up @@ -317,6 +318,10 @@ public function Values($values)
$this->structure = array('key' => 0, 'value' => 1, 'datasets' => true);
}

if($this->datetime_keys && $this->datetime_key_format) {
Graph::$key_format = $this->datetime_key_format;
}

if($this->structured_data || is_array($this->structure)) {
$this->structured_data = true;
require_once 'SVGGraphStructuredData.php';
Expand Down Expand Up @@ -1077,6 +1082,9 @@ protected function SetStroke(&$attr, &$item, $set = 0, $line_join = null)
$attr['stroke-dasharray'] = $dash;
else
unset($attr['stroke-dasharray']);
} else {
unset($attr['stroke'], $attr['stroke-width'], $attr['stroke-linejoin'],
$attr['stroke-dasharray']);
}
}

Expand Down Expand Up @@ -1758,11 +1766,20 @@ public static function min(&$a)


/**
* Converts a string key to a unix timestamp, or NULL if invalid
*/
* Converts a string key to a unix timestamp, or NULL if invalid
*/
function SVGGraphDateConvert($k)
{
$dt = date_create($k);
// if the format is set, try it
if(!is_null(Graph::$key_format)) {
$dt = date_create_from_format(Graph::$key_format, $k);

// if the specified format fails, try default format
if($dt === FALSE)
$dt = date_create($k);
} else {
$dt = date_create($k);
}
if($dt === FALSE)
return NULL;
// this works in 64-bit on 32-bit systems, getTimestamp() doesn't
Expand Down
8 changes: 5 additions & 3 deletions SVGGraphStructuredData.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,12 @@ public function __construct(&$data, $force_assoc, $datetime_keys,

// check for more datasets
foreach($data as $item) {
foreach(array_keys($item) as $key)
if($key != $this->key_field &&
array_search($key, $this->dataset_fields) === FALSE)
foreach(array_keys($item) as $key) {
if($key !== $this->key_field &&
array_search($key, $this->dataset_fields) === FALSE) {
$this->dataset_fields[] = $key;
}
}
}

// default structure
Expand Down
3 changes: 2 additions & 1 deletion svggraph.ini
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ svg_class = null
encoding = "UTF-8"
id_prefix = ""
precision = 5
pad_top = 10
exception_throw = false
exception_details = false
pad_top = 10
pad_bottom = 10
pad_left = 10
pad_right = 10
Expand Down Expand Up @@ -84,6 +84,7 @@ legend_draggable = true
legend_autohide = false
force_assoc = false
datetime_keys = false
datetime_key_format = null
structured_data = false
structure = null
decimal = "."
Expand Down

0 comments on commit 788ffc3

Please sign in to comment.