Skip to content

Commit

Permalink
pridane sortovanie
Browse files Browse the repository at this point in the history
  • Loading branch information
Ondrej Kassovic committed Nov 9, 2018
1 parent 4f63bb5 commit dcb28c4
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 13 deletions.
13 changes: 5 additions & 8 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion chart/src/app/barchart/chart.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ <h3 class="fs-2 m-0 font-weight-normal">Vsetky rezorty</h3>
(chartClick)="chartClicked($event)"></canvas>
</div>
<!-- <button (click)="randomize()">Update</button> -->
<!-- <button (click)="sort()">Sort</button> -->
<button (click)="onSort()">Sortuj podla uspesnosti</button>
</div>
</div>
</section>
Expand Down
35 changes: 31 additions & 4 deletions chart/src/app/barchart/chart.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {Component, OnInit} from '@angular/core';
import { Component, OnInit, ViewChild } from '@angular/core';
import { BaseChartDirective } from 'ng2-charts';

@Component({
selector: 'app-chart',
Expand All @@ -7,12 +8,14 @@ import {Component, OnInit} from '@angular/core';
})
export class ChartComponent {

@ViewChild(BaseChartDirective)
public chart: BaseChartDirective;
public barChartType: String = 'bar';
public barChartLegend: Boolean = true;
public barChartData: any[] = [
{data: [20, 30, 60, 40, 50, 35, 25, 34, 44, 15, 28, 15, 5, 45], label: 'Uspesne', stack: '1'},
{data: [2, 3, 4, 5, 9, 8, 7, 6, 12, 16, 9, 14, 2, 3], label: 'Rozpracovane', stack: '1'},
{data: [20, 23, 21, 26, 22, 1, 17, 26, 27, 29, 14, 15, 22, 27], label: 'Ostatne', stack: '1'}
{ data: [20, 30, 60, 40, 50, 35, 25, 34, 44, 15, 28, 15, 5, 45], label: 'Uspesne', stack: '1' },
{ data: [2, 3, 4, 5, 9, 8, 7, 6, 12, 16, 9, 14, 2, 3], label: 'Rozpracovane', stack: '1' },
{ data: [20, 23, 21, 26, 22, 1, 17, 26, 27, 29, 14, 15, 22, 27], label: 'Ostatne', stack: '1' }
];

public barChartLabels: string[] = ['ked je dlhsi-->pica', 'MF', 'MH', 'MK', 'MO', 'b', 'c', 'MS', 'd', 'MV', 'e', 'MZ', 'MZP'];
Expand Down Expand Up @@ -42,5 +45,29 @@ export class ChartComponent {
// console.log('Adam je super projektak a grafy su este viac supernejsie');
}

public onSort() {
this.sorting(this.barChartData[0].data, this.barChartLabels);

}

private sorting(data, label) {
// 1) combine the arrays:
let list = [];
for (let j = 0; j < data.length; j++) {
list.push({ 'name': data[j], 'age': label[j] });
}

// 2) sort:
list.sort(function (a, b) {
return ((a.name < b.name) ? -1 : ((a.name == b.name) ? 0 : 1));
});

// 3) separate them back out:
for (let k = 0; k < list.length; k++) {
data[k] = list[k].name;
label[k] = list[k].age;
}
this.chart.chart.update();
}

}

0 comments on commit dcb28c4

Please sign in to comment.