-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
141 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} | ||
} |