Fix graph

This commit is contained in:
2023-03-28 16:52:53 +02:00
parent 522214898b
commit c0b8260996
9 changed files with 322 additions and 165 deletions

View File

@@ -1,30 +1,30 @@
var filiInfo = {
css: null,
exports: null,
template: (template, expressionTypes, bindingTypes, getComponent) => template('<div class="box p-1 m-2"><h1 class="title is-4 m-2"><a>BUT</a> / <a>BUT - Production</a> / <a>Informatique</a></h1><div class="box mt-2" style="background-color: #EAEAEA; margin: auto; width: 60%;"><p>Moyenne des admis<span class="is-pulled-right">19.3</span></p><p>Nombre de formations<span class="is-pulled-right">5</span></p><p>Capacité<span class="is-pulled-right">90</span></p><p>Sélectivité</p></div><div class="m-4"><line-graph expr249="expr249" style="height: 6rem;"></line-graph></div><div class="m-4"><line-graph expr250="expr250" style="height: 6rem;"></line-graph></div><div class="m-4"><line-graph expr251="expr251" style="height: 6rem;"></line-graph></div></div>', [{
template: (template, expressionTypes, bindingTypes, getComponent) => template('<div class="box p-1 m-2"><h1 class="title is-4 m-2"><a>BUT</a> / <a>BUT - Production</a> / <a>Informatique</a></h1><div class="box mt-2" style="background-color: #EAEAEA; margin: auto; width: 60%;"><p>Moyenne des admis<span class="is-pulled-right">19.3</span></p><p>Nombre de formations<span class="is-pulled-right">5</span></p><p>Capacité<span class="is-pulled-right">90</span></p><p>Sélectivité</p></div><div class="m-4"><line-graph expr0="expr0" style="height: 6rem;"></line-graph></div><div class="m-4"><line-graph expr1="expr1" style="height: 6rem;"></line-graph></div><div class="m-4"><line-graph expr2="expr2" style="height: 6rem;"></line-graph></div></div>', [{
type: bindingTypes.TAG,
getComponent: getComponent,
evaluate: _scope => 'line-graph',
slots: [],
attributes: [],
redundantAttribute: 'expr249',
selector: '[expr249]'
redundantAttribute: 'expr0',
selector: '[expr0]'
}, {
type: bindingTypes.TAG,
getComponent: getComponent,
evaluate: _scope => 'line-graph',
slots: [],
attributes: [],
redundantAttribute: 'expr250',
selector: '[expr250]'
redundantAttribute: 'expr1',
selector: '[expr1]'
}, {
type: bindingTypes.TAG,
getComponent: getComponent,
evaluate: _scope => 'line-graph',
slots: [],
attributes: [],
redundantAttribute: 'expr251',
selector: '[expr251]'
redundantAttribute: 'expr2',
selector: '[expr2]'
}]),
name: 'fili-info'
};

View File

@@ -3,17 +3,18 @@ var lineGraph = {
exports: {
updateCanvas() {
let canvas = this.$("canvas");
canvas.width = canvas.clientWidth;
canvas.height = canvas.clientHeight;
let cx = canvas.getContext("2d");
//Default context properties
cx.textBaseline = "middle";
cx.textAlign = "center";
let width = canvas.width;
let height = canvas.height;
let spacing = 1; //Controls the spacing between each horizontal elements
let spacing = 1;
let data = this.state.data;
let colors = ["#003F5C", "#2F4B7C", "#665191", "#A05195", "#D45087"];
cx.clearRect(0, 0, width, height);
cx.resetTransform();
if (!data) return;
cx.fillStyle = "#707070";
cx.font = "15px Arial";
@@ -28,7 +29,7 @@ var lineGraph = {
let start = curr + spacing;
let barWidth = field.value / total * width - spacing * 2;
let text = `${Math.round(field.value / total * 1000) / 10}% (${field.name})`;
cx.fillStyle = this.colors[counter];
cx.fillStyle = colors[counter];
cx.fillRect(start, 0, barWidth, height / 3);
cx.fillStyle = "#FFFFFF";
if (cx.measureText(text).width < barWidth) {
@@ -46,7 +47,7 @@ var lineGraph = {
cx.translate(width / 2 - legendWidth / 2, height / 4 + 20);
counter = 0;
for (let field of data) {
cx.fillStyle = this.colors[counter];
cx.fillStyle = colors[counter];
cx.fillRect(0, 0, 25, 25);
cx.fillStyle = "#707070";
cx.fillText(field.name, 30, 12.5);
@@ -54,32 +55,16 @@ var lineGraph = {
counter++;
}
},
state: {
data: [],
title: "Example"
},
onMounted() {
this.colors = ["#003F5C", "#2F4B7C", "#665191", "#A05195", "#D45087"];
this.state.data = [{
name: "P",
value: 52
}, {
name: "AB",
value: 43
}, {
name: "B",
value: 2
}, {
name: "TB",
value: 1
}, {
name: "TBF",
value: 0
}];
let canvas = this.$("canvas");
canvas.width = canvas.clientWidth;
canvas.height = canvas.clientHeight;
this.updateCanvas();
new ResizeObserver(this.updateCanvas).observe(canvas);
},
onUpdated(props, state) {
console.log("boop");
this.updateCanvas();
}
},

View File

@@ -1,38 +1,38 @@
var mainController = {
css: null,
exports: {},
template: (template, expressionTypes, bindingTypes, getComponent) => template('<div class="columns"><div class="column is-one-third"><div class="box p-2 m-2"><img src="../resources/logo-parcoursup.svg"/></div><search expr41="expr41"></search></div><div class="column"><fili-info expr42="expr42"></fili-info><school expr43="expr43"></school></div></div><school-info expr44="expr44"></school-info>', [{
template: (template, expressionTypes, bindingTypes, getComponent) => template('<div class="columns"><div class="column is-one-third"><div class="box p-3 m-2"><img class="mt-1 ml-5 mr-auto" style="margin: auto;" src="../resources/logo-parcoursup.svg"/></div><search expr12="expr12"></search></div><div class="column"><fili-info expr13="expr13"></fili-info><school expr14="expr14"></school></div></div><school-info expr15="expr15"></school-info>', [{
type: bindingTypes.TAG,
getComponent: getComponent,
evaluate: _scope => 'search',
slots: [],
attributes: [],
redundantAttribute: 'expr41',
selector: '[expr41]'
redundantAttribute: 'expr12',
selector: '[expr12]'
}, {
type: bindingTypes.TAG,
getComponent: getComponent,
evaluate: _scope => 'fili-info',
slots: [],
attributes: [],
redundantAttribute: 'expr42',
selector: '[expr42]'
redundantAttribute: 'expr13',
selector: '[expr13]'
}, {
type: bindingTypes.TAG,
getComponent: getComponent,
evaluate: _scope => 'school',
slots: [],
attributes: [],
redundantAttribute: 'expr43',
selector: '[expr43]'
redundantAttribute: 'expr14',
selector: '[expr14]'
}, {
type: bindingTypes.TAG,
getComponent: getComponent,
evaluate: _scope => 'school-info',
slots: [],
attributes: [],
redundantAttribute: 'expr44',
selector: '[expr44]'
redundantAttribute: 'expr15',
selector: '[expr15]'
}]),
name: 'main-controller'
};

View File

@@ -10,14 +10,14 @@ var schoolInfo = {
this.update();
}
},
template: (template, expressionTypes, bindingTypes, getComponent) => template('<div expr26="expr26" style="position: absolute; top: 0px; left: 0px; width: 100%; height: 100%; background: #000000DD;"></div>', [{
template: (template, expressionTypes, bindingTypes, getComponent) => template('<div expr3="expr3" style="position: absolute; top: 0px; left: 0px; width: 100%; height: 100%; background: #000000DD;"></div>', [{
type: bindingTypes.IF,
evaluate: _scope => _scope.state.enabled,
redundantAttribute: 'expr26',
selector: '[expr26]',
template: template('<div style="position: absolute; top: 10%; left: 10%; width: 80%; height: 80%; background: #FFFFFF"><button expr27="expr27" class="delete is-medium">X</button><p><h2></h2></p><line-graph expr28="expr28" style="height: 90px; margin: 10px;"></line-graph></div>', [{
redundantAttribute: 'expr27',
selector: '[expr27]',
redundantAttribute: 'expr3',
selector: '[expr3]',
template: template('<div style="position: absolute; top: 10%; left: 10%; width: 80%; height: 80%; background: #FFFFFF"><button expr4="expr4" class="delete is-medium">X</button><p><h2></h2></p><line-graph expr5="expr5" style="height: 90px; margin: 10px;"></line-graph></div>', [{
redundantAttribute: 'expr4',
selector: '[expr4]',
expressions: [{
type: expressionTypes.EVENT,
name: 'onclick',
@@ -29,8 +29,8 @@ var schoolInfo = {
evaluate: _scope => 'line-graph',
slots: [],
attributes: [],
redundantAttribute: 'expr28',
selector: '[expr28]'
redundantAttribute: 'expr5',
selector: '[expr5]'
}])
}]),
name: 'school-info'

View File

@@ -114,9 +114,9 @@ var search = {
}
};
},
template: (template, expressionTypes, bindingTypes, getComponent) => template('<div class="box p-1 m-2"><div class="columns m-1"><input expr3="expr3" class="input" type="input"/><button expr4="expr4" class="button ml-1">&lt;</button></div><div id="list-formations"><ul><li expr5="expr5" class="m-1"></li></ul></div></div>', [{
redundantAttribute: 'expr3',
selector: '[expr3]',
template: (template, expressionTypes, bindingTypes, getComponent) => template('<div class="box p-1 m-2"><div class="columns m-1"><input expr6="expr6" class="input" type="input"/><button expr7="expr7" class="button ml-1">&lt;</button></div><div id="list-formations"><ul><li expr8="expr8" class="m-1"></li></ul></div></div>', [{
redundantAttribute: 'expr6',
selector: '[expr6]',
expressions: [{
type: expressionTypes.EVENT,
name: 'onkeydown',
@@ -127,8 +127,8 @@ var search = {
evaluate: _scope => _scope.state.placeholder
}]
}, {
redundantAttribute: 'expr4',
selector: '[expr4]',
redundantAttribute: 'expr7',
selector: '[expr7]',
expressions: [{
type: expressionTypes.EVENT,
name: 'onclick',
@@ -138,33 +138,33 @@ var search = {
type: bindingTypes.EACH,
getKey: null,
condition: null,
template: template('<button expr6="expr6" class="button is-fullwidth"><span style="font-size: .75em;"><strong expr7="expr7"> </strong></span><div style="margin-left: auto;"></div><span expr8="expr8" class="tag is-primary"> </span></button>', [{
redundantAttribute: 'expr6',
selector: '[expr6]',
template: template('<button expr9="expr9" class="button is-fullwidth"><span style="font-size: .75em;"><strong expr10="expr10"> </strong></span><div style="margin-left: auto;"></div><span expr11="expr11" class="tag is-primary"> </span></button>', [{
redundantAttribute: 'expr9',
selector: '[expr9]',
expressions: [{
type: expressionTypes.EVENT,
name: 'onclick',
evaluate: _scope => () => _scope.filter(_scope.item.name)
}]
}, {
redundantAttribute: 'expr7',
selector: '[expr7]',
redundantAttribute: 'expr10',
selector: '[expr10]',
expressions: [{
type: expressionTypes.TEXT,
childNodeIndex: 0,
evaluate: _scope => _scope.item.name
}]
}, {
redundantAttribute: 'expr8',
selector: '[expr8]',
redundantAttribute: 'expr11',
selector: '[expr11]',
expressions: [{
type: expressionTypes.TEXT,
childNodeIndex: 0,
evaluate: _scope => _scope.item.count
}]
}]),
redundantAttribute: 'expr5',
selector: '[expr5]',
redundantAttribute: 'expr8',
selector: '[expr8]',
itemName: 'item',
indexName: null,
evaluate: _scope => _scope.state.items