@@ -25,10 +25,10 @@ discard block |
||
25 | 25 | $overlapped3 = new IntervalGraph([$base, $date3]); |
26 | 26 | $overlapped = new IntervalGraph([$base, $date1, $date2, $date3]); |
27 | 27 | |
28 | -$withNull1 = new IntervalGraph([$base, [new DateTime('today'), new DateTime('today + 3 days'), 4 / 10],]); |
|
29 | -$withNull2 = new IntervalGraph([$base, [new DateTime('today + 1 day'), new DateTime('today + 2 days')],]); |
|
30 | -$withNull3 = new IntervalGraph([$base, [new DateTime('today + 2 day'), new DateTime('today + 3 days'), 4 / 10],]); |
|
31 | -$withNull4 = new IntervalGraph([$base, [new DateTime('today + 4 day'), new DateTime('today + 5 days'), 5 / 10],]); |
|
28 | +$withNull1 = new IntervalGraph([$base, [new DateTime('today'), new DateTime('today + 3 days'), 4 / 10], ]); |
|
29 | +$withNull2 = new IntervalGraph([$base, [new DateTime('today + 1 day'), new DateTime('today + 2 days')], ]); |
|
30 | +$withNull3 = new IntervalGraph([$base, [new DateTime('today + 2 day'), new DateTime('today + 3 days'), 4 / 10], ]); |
|
31 | +$withNull4 = new IntervalGraph([$base, [new DateTime('today + 4 day'), new DateTime('today + 5 days'), 5 / 10], ]); |
|
32 | 32 | $withNullIntervals = new IntervalGraph([ |
33 | 33 | [$today, new DateTime('today + 3 days'), 4 / 10], |
34 | 34 | [new DateTime('today + 1 day'), new DateTime('today + 2 days')], |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | [new DateTime('today + 6 day'), new DateTime('today + 9 days'), 2 / 10], |
47 | 47 | ]; |
48 | 48 | |
49 | -$longDateFormat = function (\DateTime $bound){ |
|
49 | +$longDateFormat = function(\DateTime $bound) { |
|
50 | 50 | return $bound->format('Y-m-d H:i:s'); |
51 | 51 | }; |
52 | 52 | |
@@ -57,16 +57,16 @@ discard block |
||
57 | 57 | */ |
58 | 58 | |
59 | 59 | // An aggregate function for arrays representing fractions with the same denominator. |
60 | -$agg = function ($a, $b) { |
|
60 | +$agg = function($a, $b) { |
|
61 | 61 | if ($a === null && $b === null) return null; |
62 | 62 | return [$a[0] + $b[0], $b[1]]; |
63 | 63 | }; |
64 | 64 | |
65 | 65 | // A toNumeric function… |
66 | -$toNumeric = function ($a) {return $a === null ? null : (int)($a[0] / $a[1] * 100);}; |
|
66 | +$toNumeric = function($a) {return $a === null ? null : (int)($a[0] / $a[1] * 100); }; |
|
67 | 67 | |
68 | 68 | // A toString function… |
69 | -$toString = function ($a) {return $a === null ? null : ($a[0] . '/' . $a[1]);}; |
|
69 | +$toString = function($a) {return $a === null ? null : ($a[0] . '/' . $a[1]); }; |
|
70 | 70 | |
71 | 71 | $fractions = [ |
72 | 72 | [$today, new DateTime('today + 3 days'), [2, 10]], |
@@ -58,7 +58,9 @@ |
||
58 | 58 | |
59 | 59 | // An aggregate function for arrays representing fractions with the same denominator. |
60 | 60 | $agg = function ($a, $b) { |
61 | - if ($a === null && $b === null) return null; |
|
61 | + if ($a === null && $b === null) { |
|
62 | + return null; |
|
63 | + } |
|
62 | 64 | return [$a[0] + $b[0], $b[1]]; |
63 | 65 | }; |
64 | 66 |
@@ -1,6 +1,6 @@ |
||
1 | 1 | <div class='intvg'> |
2 | 2 | <?php foreach ($vs as $k => $v) : ?> |
3 | - <?php if (count($v) === 2 ): // Isolated date.?> |
|
3 | + <?php if (count($v) === 2): // Isolated date.?> |
|
4 | 4 | <div class='bar bar-date bar<?= $k; ?>' style='left:<?= $v[0] ?>%;' data-title='<?= $v[1] ?>'></div> |
5 | 5 | <?php else: ?> |
6 | 6 | <div class='bar bar-intv bar<?= $k; ?>' |
@@ -2,8 +2,11 @@ |
||
2 | 2 | <?php foreach ($vs as $k => $v) : ?> |
3 | 3 | <?php if (count($v) === 2 ): // Isolated date.?> |
4 | 4 | <div class='bar bar-date bar<?= $k; ?>' style='left:<?= $v[0] ?>%;' data-title='<?= $v[1] ?>'></div> |
5 | - <?php else: ?> |
|
6 | - <div class='bar bar-intv bar<?= $k; ?>' |
|
5 | + <?php else { |
|
6 | + : ?> |
|
7 | + <div class='bar bar-intv bar<?= $k; |
|
8 | +} |
|
9 | +?>' |
|
7 | 10 | style='left:<?= $v[0] ?>%;right:<?= $v[1] ?>%;background-color:<?= $v[2] ?>' |
8 | 11 | data-title="<?= $v[3] . ' ➔ ' . $v[4] . (isset($v[5]) ? ' : ' . $v[5] : '') ?>"> |
9 | 12 | </div> |
@@ -49,7 +49,7 @@ |
||
49 | 49 | */ |
50 | 50 | public function setColors(array $palette) |
51 | 51 | { |
52 | - usort($palette, function ($p1, $p2) { |
|
52 | + usort($palette, function($p1, $p2) { |
|
53 | 53 | return $p2[0] - $p1[0]; |
54 | 54 | }); |
55 | 55 | $this->palette = $palette; |
@@ -46,23 +46,23 @@ discard block |
||
46 | 46 | $this->setIntervals($intervals); |
47 | 47 | } |
48 | 48 | |
49 | - $this->boundToNumeric = function (\DateTime $bound) { |
|
49 | + $this->boundToNumeric = function(\DateTime $bound) { |
|
50 | 50 | return $bound->getTimestamp(); |
51 | 51 | }; |
52 | 52 | |
53 | - $this->boundToString = function (\DateTime $bound) { |
|
53 | + $this->boundToString = function(\DateTime $bound) { |
|
54 | 54 | return $bound->format("Y-m-d"); |
55 | 55 | }; |
56 | 56 | |
57 | - $this->valueToNumeric = function ($v) { |
|
57 | + $this->valueToNumeric = function($v) { |
|
58 | 58 | return $v === null ? null : (int)($v * 100); |
59 | 59 | }; |
60 | 60 | |
61 | - $this->valueToString = function ($v) { |
|
61 | + $this->valueToString = function($v) { |
|
62 | 62 | return $v === null ? null : ($v * 100 . '%'); |
63 | 63 | }; |
64 | 64 | |
65 | - $this->aggregateFunction = function ($a, $b) { |
|
65 | + $this->aggregateFunction = function($a, $b) { |
|
66 | 66 | if ($a === null && $b === null) { |
67 | 67 | return null; |
68 | 68 | } |
@@ -160,7 +160,7 @@ discard block |
||
160 | 160 | public static function truncate(array $intervals, $lowerLimit = null, $upperLimit = null, $padding = false) |
161 | 161 | { |
162 | 162 | if (isset($lowerLimit)) { |
163 | - $intervals = array_map(function ($i) use ($lowerLimit) { |
|
163 | + $intervals = array_map(function($i) use ($lowerLimit) { |
|
164 | 164 | if ($i[0] < $lowerLimit) { // If the low bound is before the lower bound... |
165 | 165 | if ($i[1] < $lowerLimit) { |
166 | 166 | // ... and the high bound is also before the lower bound, set the interval to false. |
@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | |
189 | 189 | // TODO DRY |
190 | 190 | if (isset($upperLimit)) { |
191 | - $intervals = array_map(function ($i) use ($upperLimit) { |
|
191 | + $intervals = array_map(function($i) use ($upperLimit) { |
|
192 | 192 | if ($i[1] > $upperLimit) { |
193 | 193 | if ($i[0] > $upperLimit) { |
194 | 194 | // If both bounds are after the given upper limit, set the interval to false. |
@@ -290,7 +290,7 @@ discard block |
||
290 | 290 | $t = array_column($flatIntervals, 2); |
291 | 291 | |
292 | 292 | // Change bounds to numeric values. |
293 | - $numVals = array_map(function (array $i) { |
|
293 | + $numVals = array_map(function(array $i) { |
|
294 | 294 | return [ |
295 | 295 | ($this->boundToNumeric)($i[0]), |
296 | 296 | ($this->boundToNumeric)($i[1]), |
@@ -298,7 +298,7 @@ discard block |
||
298 | 298 | }, $flatIntervals); |
299 | 299 | |
300 | 300 | // Order by low bound. |
301 | - uasort($numVals, function (array $i1, array $i2) { |
|
301 | + uasort($numVals, function(array $i1, array $i2) { |
|
302 | 302 | return ($i1[0] < $i2[0]) ? -1 : 1; |
303 | 303 | }); |
304 | 304 | |
@@ -306,7 +306,7 @@ discard block |
||
306 | 306 | $min = reset($numVals)[0]; |
307 | 307 | |
308 | 308 | // Substract min from all timestamps. |
309 | - $numVals = array_map(function ($i) use ($min) { |
|
309 | + $numVals = array_map(function($i) use ($min) { |
|
310 | 310 | return [ |
311 | 311 | $i[0] - $min, |
312 | 312 | $i[1] - $min |
@@ -314,7 +314,7 @@ discard block |
||
314 | 314 | }, $numVals); |
315 | 315 | |
316 | 316 | // Order by high bound. |
317 | - uasort($numVals, function (array $i1, array $i2) { |
|
317 | + uasort($numVals, function(array $i1, array $i2) { |
|
318 | 318 | return ($i1[1] < $i2[1]) ? -1 : 1; |
319 | 319 | }); |
320 | 320 | |
@@ -322,15 +322,15 @@ discard block |
||
322 | 322 | $max = end($numVals)[1]; |
323 | 323 | |
324 | 324 | // Calculate percentages. |
325 | - $numVals = array_map(function (array $i) use ($max) { |
|
326 | - return array_map(function ($int) use ($max) { |
|
325 | + $numVals = array_map(function(array $i) use ($max) { |
|
326 | + return array_map(function($int) use ($max) { |
|
327 | 327 | return round($int * 100 / $max); |
328 | 328 | }, $i); |
329 | 329 | }, $numVals); |
330 | 330 | |
331 | 331 | // Put values back in, along with the formatted bound. |
332 | 332 | // Since we're using associative sorting functions, we know the keys haven't changed. |
333 | - $numVals = array_map(function ($k, array $i) use ($t, $flatIntervals) { |
|
333 | + $numVals = array_map(function($k, array $i) use ($t, $flatIntervals) { |
|
334 | 334 | if ($flatIntervals[$k][0] === $flatIntervals[$k][1]) { |
335 | 335 | return [ |
336 | 336 | $i[0], // Single value position percentage |
@@ -347,7 +347,7 @@ discard block |
||
347 | 347 | !empty($t) ? $this->palette->getColor($colorval) : 50, // Interval color |
348 | 348 | ($this->boundToString)($flatIntervals[$k][0]), // Interval start string value |
349 | 349 | ($this->boundToString)($flatIntervals[$k][1]), // Interval end string value |
350 | - !empty($t) ? ($stingval) : null,// Interval string value |
|
350 | + !empty($t) ? ($stingval) : null, // Interval string value |
|
351 | 351 | ]; |
352 | 352 | } |
353 | 353 | }, array_keys($numVals), $numVals); |
@@ -355,7 +355,7 @@ discard block |
||
355 | 355 | // Put discrete values at the end and reset indices. |
356 | 356 | // Reseting indices ensures the processed values are |
357 | 357 | // serialized as correctly ordered JSON arrays. |
358 | - usort($numVals, function ($i) { |
|
358 | + usort($numVals, function($i) { |
|
359 | 359 | return count($i) === 2 ? 1 : -1; |
360 | 360 | }); |
361 | 361 | |
@@ -377,7 +377,7 @@ discard block |
||
377 | 377 | $adjacentIntervals = $this->calcAdjacentIntervals($signedBounds); |
378 | 378 | |
379 | 379 | // Remove empty interval generated when two or more intervals share a common bound. |
380 | - $adjacentIntervals = array_values(array_filter($adjacentIntervals, function ($i) { |
|
380 | + $adjacentIntervals = array_values(array_filter($adjacentIntervals, function($i) { |
|
381 | 381 | // Use weak comparison in case of object typed bounds. |
382 | 382 | return $i[0] != $i[1]; |
383 | 383 | })); |
@@ -402,7 +402,7 @@ discard block |
||
402 | 402 | */ |
403 | 403 | public static function extractDiscreteValues(array &$intervals) |
404 | 404 | { |
405 | - $discreteValues = array_filter($intervals, function ($interval) { |
|
405 | + $discreteValues = array_filter($intervals, function($interval) { |
|
406 | 406 | return $interval[0] === $interval[1]; |
407 | 407 | }); |
408 | 408 | |
@@ -429,7 +429,7 @@ discard block |
||
429 | 429 | $bounds[] = [$interval[1], isset($interval[2]) ? $interval[2] : null, '-', $key]; |
430 | 430 | } |
431 | 431 | // Order the bounds. |
432 | - usort($bounds, function (array $d1, array $d2) { |
|
432 | + usort($bounds, function(array $d1, array $d2) { |
|
433 | 433 | return ($d1[0] < $d2[0]) ? -1 : 1; |
434 | 434 | }); |
435 | 435 | return $bounds; |
@@ -444,7 +444,7 @@ discard block |
||
444 | 444 | public function calcAdjacentIntervals($bounds) |
445 | 445 | { |
446 | 446 | // Get the values of the original intervals, including nulls. |
447 | - $origIntVals = array_map(function ($interval) { |
|
447 | + $origIntVals = array_map(function($interval) { |
|
448 | 448 | return isset($interval[2]) ? $interval[2] : null; |
449 | 449 | }, $this->intervals); |
450 | 450 |