Skip to content

Commit 8a6592a

Browse files
committed
wip
1 parent 8beaa33 commit 8a6592a

2 files changed

Lines changed: 50 additions & 50 deletions

File tree

src/Control/Chart/ChartControl.php

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -30,61 +30,61 @@ public function __construct(
3030

3131

3232
public function render(): void
33-
{
34-
$this->template->count = $this->collection->count();
35-
foreach ($this->collection as $item) {
33+
{
34+
$this->template->count = $this->collection->count();
35+
foreach ($this->collection as $item) {
3636
$rowValue = 0;
37-
$columnValue = $this->main->getColumnColumn()->name == 'month' ? $item->getMonth() : ($this->main->getColumnColumn()->name == 'day' ? $item->date->format('Y-m-d') : $item->getRawValue($this->main->getColumnColumn()->name));
38-
$this->items[$rowValue][$columnValue] = $item;
39-
$this->items[$rowValue]['total'] = ($items[$rowValue]['total'] ?? 0) + ($this->getValue($item, $this->main->getValueColumn()->columnName) !== null ? $this->getValue($item, $this->main->getValueColumn()->columnName)[0] : 0);
40-
if (!isset($columnHeaderItems[$columnValue])) {
41-
$this->columnHeaderItems[$columnValue] = $item;
42-
}
43-
}
44-
uasort($this->columnHeaderItems, fn($a, $b) =>
45-
strnatcmp(
46-
$this->main->getColumnColumn()->name == 'month' ? (string) $a->getMonth() : ($this->main->getColumnColumn()->name == 'day' ? $a->date->format('Y-m-d') : (string) $this->getValue($a, $this->main->getColumnColumn()->columnName)[0]),
47-
$this->main->getColumnColumn()->name == 'month' ? (string) $b->getMonth() : ($this->main->getColumnColumn()->name == 'day' ? $b->date->format('Y-m-d') : (string) $this->getValue($b, $this->main->getColumnColumn()->columnName)[0])
48-
)
49-
);
50-
uasort($this->items, fn($a, $b) => -($a['total'] <=> $b['total']));
37+
$columnValue = $this->main->getColumnColumn()->name == 'month' ? $item->getMonth() : ($this->main->getColumnColumn()->name == 'day' ? $item->date->format('Y-m-d') : $item->getRawValue($this->main->getColumnColumn()->name));
38+
$this->items[$rowValue][$columnValue] = $item;
39+
$this->items[$rowValue]['total'] = ($items[$rowValue]['total'] ?? 0) + ($this->getValue($item, $this->main->getValueColumn()->columnName) !== null ? $this->getValue($item, $this->main->getValueColumn()->columnName)[0] : 0);
40+
if (!isset($columnHeaderItems[$columnValue])) {
41+
$this->columnHeaderItems[$columnValue] = $item;
42+
}
43+
}
44+
uasort($this->columnHeaderItems, fn($a, $b) =>
45+
strnatcmp(
46+
$this->main->getColumnColumn()->name == 'month' ? (string) $a->getMonth() : ($this->main->getColumnColumn()->name == 'day' ? $a->date->format('Y-m-d') : (string) $this->getValue($a, $this->main->getColumnColumn()->columnName)[0]),
47+
$this->main->getColumnColumn()->name == 'month' ? (string) $b->getMonth() : ($this->main->getColumnColumn()->name == 'day' ? $b->date->format('Y-m-d') : (string) $this->getValue($b, $this->main->getColumnColumn()->columnName)[0])
48+
)
49+
);
50+
uasort($this->items, fn($a, $b) => -($a['total'] <=> $b['total']));
5151
$this->template->table = $this->createTable();
5252
$this->template->options = $this->createOptions();
5353
$this->template->numberFormats = $this->createNumberFormats();
54-
$this->template->columnHeaderItems = $this->columnHeaderItems;
54+
$this->template->columnHeaderItems = $this->columnHeaderItems;
5555
$this->template->valueColumn = $this->main->getValueColumn();
56-
$this->template->items = $this->items;
56+
$this->template->items = $this->items;
5757
$this->template->visualization = $this->visualization;
5858
$this->template->chartType = $this->main->getColumnColumn()->chart?->type ?: $this->main->getValueColumn()->chart->type;
59-
$this->template->render($this->main->getView()->chartTemplate);
60-
}
59+
$this->template->render($this->main->getView()->chartTemplate);
60+
}
6161

6262

63-
public function getValue(IEntity $entity, $columnName): ?array
64-
{
65-
$columnNames = explode('.', $columnName);
66-
$values = [$entity];
67-
foreach ($columnNames as $columnName) {
68-
$newValues = [];
69-
foreach ($values as $value) {
70-
if ($value instanceof HasMany) {
71-
foreach ($value as $v) {
72-
if (!isset($v->{$columnName})) {
73-
return null;
74-
}
75-
$newValues[] = $v->{$columnName};
76-
}
77-
} else {
78-
if (!isset($value->{$columnName})) {
79-
return null;
80-
}
81-
$newValues[] = $value->{$columnName};
82-
}
83-
}
84-
$values = $newValues;
85-
}
86-
return $values;
87-
}
63+
public function getValue(IEntity $entity, $columnName): ?array
64+
{
65+
$columnNames = explode('.', $columnName);
66+
$values = [$entity];
67+
foreach ($columnNames as $columnName) {
68+
$newValues = [];
69+
foreach ($values as $value) {
70+
if ($value instanceof HasMany) {
71+
foreach ($value as $v) {
72+
if (!isset($v->{$columnName})) {
73+
return null;
74+
}
75+
$newValues[] = $v->{$columnName};
76+
}
77+
} else {
78+
if (!isset($value->{$columnName})) {
79+
return null;
80+
}
81+
$newValues[] = $value->{$columnName};
82+
}
83+
}
84+
$values = $newValues;
85+
}
86+
return $values;
87+
}
8888

8989

9090
private function createTable(): array
@@ -227,11 +227,11 @@ private function createOptions(): array
227227
'pagingTextStyle' => ['color' => $this->visualization->primaryColor],
228228
'scrollArrows' => ['activeColor' => $this->visualization->primaryColor],
229229
],
230-
'focusTarget' => 'category',
230+
'focusTarget' => 'category',
231231
'colors' => $valueColumn->chart?->colors ? $valueColumn->chart->colors : [$this->visualization->primaryColor],
232232
'backgroundColor' => $this->visualization->bgColor,
233233
'color' => $this->visualization->textColor,
234-
'isStacked' => $valueColumn->chart?->stacked ? $valueColumn->chart->stacked : null,
234+
'isStacked' => $valueColumn->chart?->stacked ? $valueColumn->chart->stacked : null,
235235
];
236236
if ($valueColumn->chart->series && $valueColumn->chart->separateSeriesAxis) {
237237
$options['series'] = [];

src/Control/Chart/ChartTemplate.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212

1313
class ChartTemplate extends DataTemplate
1414
{
15-
/** @var IEntity[][] */ public array $items;
16-
/** @var IEntity[] */ public array $columnHeaderItems;
15+
/** @var IEntity[][] */ public array $items;
16+
/** @var IEntity[] */ public array $columnHeaderItems;
1717
public int $count;
1818
public array $table;
1919
public array $options;

0 commit comments

Comments
 (0)