summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhorus2020-03-24 17:45:43 +0100
committerhorus2020-03-24 17:45:43 +0100
commit9c36acdbde287c4fddec76153536ab5b342cd0a8 (patch)
tree09e5835b02e5eeb2572178c9194e4fa2de4a7d4c
parent74e73666e5f79fe5862bc9cd2c8d244004c381b4 (diff)
downloadsenpai-9c36acdbde287c4fddec76153536ab5b342cd0a8.tar.gz
Fix bug with displayed floats.
-rw-r--r--app/helpers.php42
-rw-r--r--resources/views/anime.blade.php5
2 files changed, 44 insertions, 3 deletions
diff --git a/app/helpers.php b/app/helpers.php
index bac4f0e..1c2896f 100644
--- a/app/helpers.php
+++ b/app/helpers.php
@@ -10,3 +10,45 @@ function replaceSpecialChars($string) {
return $string;
}
+
+function _formatFloat($float, $size = 2) {
+ #return number_format($float, $size, ",", ".");
+ return number_format($float, $size);
+}
+
+function formatFloat($f) {
+ if ( 0 == ($f - floor($f))) {
+ $f = intval($f);
+ } else {
+ $f = _formatFloat($f);
+ }
+
+ return $f;
+}
+
+/**
+ * Shorter alias to formatFloat().
+ */
+function fF($f) {
+ return formatFloat($f);
+}
+
+function printScoreData($score_array) {
+ $return = "[";
+
+ foreach($score_array as $score) {
+ try {
+ $return .= formatFloat($score);
+ } catch( Exception $e ) {
+ error_log("printScoreData: score data seems to be messed up: " . $e->getMessage());
+ $return .= 0;
+ }
+ $return .= ",";
+ }
+
+ rtrim($return, ",");
+
+ $return .= "]";
+
+ return $return;
+}
diff --git a/resources/views/anime.blade.php b/resources/views/anime.blade.php
index f2daedf..10634dd 100644
--- a/resources/views/anime.blade.php
+++ b/resources/views/anime.blade.php
@@ -10,8 +10,7 @@
</div>
<div class="col-sm-8 col-lg-9">
<h2>Synopsis</h2>
- <!--{!! str_replace("%%br%%", "<br>", e($anime->synopsis)) !!}-->
- {!! replaceSpecialChars(e($anime->synopsis)) !!}
+ {!! replaceSpecialChars( e($anime->synopsis) ) !!}
<br>
<br>
<strong>Score: </strong> {{ $anime["basic_data"]->score }}
@@ -58,7 +57,7 @@ new Chart(document.getElementById('score_chart'), {
labels: {!! json_encode($anime["chart_label"]) !!},
datasets: [{
label: 'Average Score on MAL',
- data: {{ json_encode($anime["score"]) }},
+ data: {!! printScoreData($anime["score"]) !!},
file: 'false',
borderColor: 'rgb(75, 192, 192)',
lineTension: 0.01,