Skip to content

Commit

Permalink
Merge branch 'nightly'
Browse files Browse the repository at this point in the history
  • Loading branch information
daredloco committed Dec 7, 2022
2 parents ff50df1 + 649a6fd commit 0505e83
Show file tree
Hide file tree
Showing 3 changed files with 141 additions and 0 deletions.
40 changes: 40 additions & 0 deletions resources/views/livewire/waterfall-chart.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<div>
@once
@push('styles')
<style>
svg > g > g.google-visualization-tooltip { pointer-events: none }
</style>
@endpush
@push('headerScripts')
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
google.charts.load('current', {'packages':['corechart'], 'language': '{{ config("lagoon.language") }}'});
</script>
@endpush
@endonce

<script type="text/javascript">
google.charts.setOnLoadCallback(drawChart{{ $chartId }});
function drawChart{{ $chartId }}() {
var data = google.visualization.arrayToDataTable(
@json($chartData)
, true);
var options = @json($optionsArray);
var chart = new google.visualization.CandlestickChart(document.getElementById('{{ $chartId.$random }}'));
chart.draw(data, options);
@if($printable)
document.getElementById('lagoon-printable-{{ $chartId.$random }}').outerHTML = '<div style="display: flex; justify-content: center;"><a href="' + chart.getImageURI() + '">Print</a></div>';
@endif
}
</script>

<div id="{{ $chartId.$random }}" style="height: 100%; width: 100%;"></div>
@if($printable)
<div id="lagoon-printable-{{ $chartId.$random }}"></div>
@endif
</div>
38 changes: 38 additions & 0 deletions src/DataTables/WaterfallChartTable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace Helvetiapps\LagoonCharts\DataTables;

use Exception;

class WaterfallChartTable{

private $data = [];
private $colCount = 5;

public function __construct(array $rows = [])
{
$rowCount = 0;

$this->data = [];
foreach($rows as $row){
$rowCount++;
if(count($row) != $this->colCount){
throw new Exception("Row ".$rowCount." has ".count($row)." columns but needs to have ".$this->colCount."!");
}
array_push($this->data, $row);
}
}

public function addRow(string $label, $min, $max){
array_push($this->data, [$label, $min, $min, $max, $max]);
}

public function __toString()
{
return json_encode($this->data);
}

public function toArray():array{
return $this->data;
}
}
63 changes: 63 additions & 0 deletions src/Http/Livewire/WaterfallChart.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php

namespace Helvetiapps\LagoonCharts\Http\Livewire;

use Carbon\Carbon;
use Livewire\Component;

class CandlestickChart extends Component
{
public $title = "NO_TITLE";
public $chartData = [];

public $height;
public $width;

public $options;

public $chartId;
public $random;

public $optionsArray;

public $printable = false;

public function mount(){
$newOptions = [
'title' => $this->title,
'bar' => [
'groupWidth' => "100%"
],
'candlestick' => [
'fallingColor' => [
'strokeWidth' => 0,
'fill' => ''
],
'risingColor' => [
'strokeWidth' => 0,
'fill' => ''
]
]
];

if(!is_null($this->height)){
$newOptions["height"] = $this->height;
}
if(!is_null($this->width)){
$newOptions["width"] = $this->width;
}
if(!is_null($this->options) && is_array($this->options)){
foreach($this->options as $key => $value){
$newOptions[$key] = $value;
}
}

$this->optionsArray = $newOptions;
}

public function render()
{
$this->random = Carbon::now()->timestamp;
return view('lagoon::livewire.waterfall-chart');
}
}

0 comments on commit 0505e83

Please sign in to comment.