Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix compatibility #7

Merged
merged 1 commit into from
Apr 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions demo/demo.php → demo/index.php
Original file line number Diff line number Diff line change
@@ -1,28 +1,35 @@
<?php
require '../vendor/autoload.php';

use atk4\chart\ChartBox;
use atk4\chart\BarChart;
use atk4\chart\PieChart;
use atk4\data\Model;
use atk4\data\Persistence\Array_;
use atk4\ui\App;

$p = ['t'=>[
[ 'name'=>'January', 'sales'=>20000, 'purchases'=>10000, ],
[ 'name'=>'February', 'sales'=>23000, 'purchases'=>12000, ],
[ 'name'=>'March', 'sales'=>16000, 'purchases'=>11000, ],
[ 'name'=>'April', 'sales'=>14000, 'purchases'=>13000, ],
]];
$m = new \atk4\data\Model(new \atk4\data\Persistence_Array($p), 't');
$m = new Model(new Array_($p), 't');
$m->addFields(['name', 'sales', 'purchases', 'profit']);
$m->addHook('afterLoad', function($m) { $m['profit'] = $m['sales'] - $m['purchases']; });
$app = new \atk4\ui\App('Chart Demo');
$app = new App('Chart Demo');
$app->initLayout('Centered');

// Lets put your chart into a box:
$columns = $app->layout->add('Columns');
$cb = $columns->addColumn(10)->add(new \atk4\chart\ChartBox(['label'=>['Demo Chart', 'icon'=>'book']]));
$chart = $cb->add(new \atk4\chart\BarChart());
$cb = $columns->addColumn(10)->add(new ChartBox(['label'=>['Demo Chart', 'icon'=>'book']]));
$chart = $cb->add(new BarChart());
$chart->setModel($m, ['name', 'sales', 'purchases','profit']);
$chart->withCurrency('$');

// Tweak our chart to support currencies better

$cb = $columns->addColumn(6)->add(new \atk4\chart\ChartBox(['label'=>['Demo Chart', 'icon'=>'book']]));
$chart = $cb->add(new \atk4\chart\PieChart());
$cb = $columns->addColumn(6)->add(new ChartBox(['label'=>['Demo Chart', 'icon'=>'book']]));
$chart = $cb->add(new PieChart());
$chart->setModel($m, ['name', 'profit']);
$chart->withCurrency('$');
4 changes: 2 additions & 2 deletions src/Chart.php
Original file line number Diff line number Diff line change
Expand Up @@ -290,10 +290,10 @@ public function summarize($model, $options = []) {

// next we need to group
if ($options['by'] ?? null) {
$qq->field($model->getElement($options['by']), 'by');
$qq->field($model->getField($options['by']), 'by');
$qq->group('by');
} else {
$qq->field($model->getElement($model->title_field), 'by');
$qq->field($model->getField($model->title_field), 'by');
}

$this->setSource($qq->get(), $fields);
Expand Down
2 changes: 1 addition & 1 deletion src/PieChart.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function setModel(\atk4\data\Model $model, $columns = [])


$this->dataSets[$column] = [
//'label'=>$model->getElement($column)->getCaption(),
//'label'=>$model->getField($column)->getCaption(),
'data'=>[],
'backgroundColor'=>[], //$colors[0],
//'borderColor'=>[], //$colors[1],
Expand Down