parent
5667dc7ee6
commit
515a5e1407
@ -0,0 +1,118 @@
|
|||||||
|
import Color from "./Color";
|
||||||
|
import Sport from "./Sport";
|
||||||
|
|
||||||
|
function ColorToString(color: Color, lang: string): string{
|
||||||
|
switch(color){
|
||||||
|
case Color.BLANC:
|
||||||
|
switch(lang){
|
||||||
|
case "en":
|
||||||
|
return "White"
|
||||||
|
default:
|
||||||
|
return "Blanc"
|
||||||
|
}
|
||||||
|
case Color.NOIR:
|
||||||
|
switch(lang){
|
||||||
|
case "en":
|
||||||
|
return "Black"
|
||||||
|
default:
|
||||||
|
return "Noir"
|
||||||
|
}
|
||||||
|
case Color.BLOND:
|
||||||
|
switch(lang){
|
||||||
|
case "en":
|
||||||
|
return "Blond"
|
||||||
|
default:
|
||||||
|
return "Blond"
|
||||||
|
}
|
||||||
|
case Color.ROUX:
|
||||||
|
switch(lang){
|
||||||
|
case "en":
|
||||||
|
return "Redhead"
|
||||||
|
default:
|
||||||
|
return "Roux"
|
||||||
|
}
|
||||||
|
case Color.BRUN:
|
||||||
|
switch(lang){
|
||||||
|
case "en":
|
||||||
|
return "Brown"
|
||||||
|
default:
|
||||||
|
return "Brun"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function ColorToHexa(color: Color): string{
|
||||||
|
switch(color){
|
||||||
|
case Color.BLANC:
|
||||||
|
return "#FFFFFF"
|
||||||
|
case Color.NOIR:
|
||||||
|
return "#000000"
|
||||||
|
case Color.BLOND:
|
||||||
|
return "#E2BC74"
|
||||||
|
case Color.ROUX:
|
||||||
|
return "#FF8B00"
|
||||||
|
case Color.BRUN:
|
||||||
|
return "#5B3C11"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function ColorToColorFont(color: Color): string{
|
||||||
|
switch(color){
|
||||||
|
case Color.BLANC:
|
||||||
|
return "#000000"
|
||||||
|
case Color.NOIR:
|
||||||
|
return "#FFFFFF"
|
||||||
|
case Color.BLOND:
|
||||||
|
return "#000000"
|
||||||
|
case Color.ROUX:
|
||||||
|
return "#000000"
|
||||||
|
case Color.BRUN:
|
||||||
|
return "#FFFFFF"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function SportToString(sport: Sport, lang: string): string{
|
||||||
|
switch(sport){
|
||||||
|
case Sport.FOOT:
|
||||||
|
switch(lang){
|
||||||
|
case "en":
|
||||||
|
return "Football"
|
||||||
|
default:
|
||||||
|
return "Football"
|
||||||
|
}
|
||||||
|
case Sport.RUGBY:
|
||||||
|
switch(lang){
|
||||||
|
case "en":
|
||||||
|
return "Rugby"
|
||||||
|
default:
|
||||||
|
return "Rugby"
|
||||||
|
}
|
||||||
|
case Sport.BASKET:
|
||||||
|
switch(lang){
|
||||||
|
case "en":
|
||||||
|
return "Basket"
|
||||||
|
default:
|
||||||
|
return "Basket"
|
||||||
|
}
|
||||||
|
case Sport.TENNIS:
|
||||||
|
switch(lang){
|
||||||
|
case "en":
|
||||||
|
return "Tennis"
|
||||||
|
default:
|
||||||
|
return "Tennis"
|
||||||
|
}
|
||||||
|
case Sport.CURLING:
|
||||||
|
switch(lang){
|
||||||
|
case "en":
|
||||||
|
return "Curling"
|
||||||
|
default:
|
||||||
|
return "Curling"
|
||||||
|
}
|
||||||
|
case Sport.AUCUN:
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export {ColorToString, SportToString, ColorToHexa, ColorToColorFont}
|
@ -0,0 +1,14 @@
|
|||||||
|
class Font{
|
||||||
|
public color: string
|
||||||
|
public size: number
|
||||||
|
public align: string
|
||||||
|
|
||||||
|
constructor(color: string, size: number, align: string){
|
||||||
|
this.color=color
|
||||||
|
this.size=size
|
||||||
|
this.align=align
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export default Font
|
@ -0,0 +1,39 @@
|
|||||||
|
import Edge from "./Edge";
|
||||||
|
import { ColorToColorFont, ColorToHexa, SportToString } from "../EnumExtender";
|
||||||
|
import GraphPerson from "./GraphPerson";
|
||||||
|
import NodePerson from "./NodePerson";
|
||||||
|
import PersonNetwork from "../PersonsNetwork";
|
||||||
|
import Font from "./Font";
|
||||||
|
|
||||||
|
class GraphCreator{
|
||||||
|
|
||||||
|
static CreateGraph(network: PersonNetwork): GraphPerson{
|
||||||
|
const nodesPerson : NodePerson[] = []
|
||||||
|
const edges: Edge[] = []
|
||||||
|
network.getPersons().forEach((p) =>{
|
||||||
|
let label = p.getName() + "\n" + p.getAge() + "\n"
|
||||||
|
for (let i = 0; i<p.getSports().length; i++){
|
||||||
|
if (i==p.getSports().length -1 || p.getSports().length == 1){
|
||||||
|
label += SportToString(p.getSports()[i], "fr")
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
label += SportToString(p.getSports()[i], "fr") + "\n"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const nodePerson = new NodePerson(p.getId(), label, p.getColor(), new Font(ColorToColorFont(p.getColor()), 14, 'center'), 'ellipse')
|
||||||
|
nodesPerson.push(nodePerson)
|
||||||
|
p.getFriends().forEach((f) =>{
|
||||||
|
if(edges.some(edge => (edge.from === f.getId() && edge.to === p.getId()) || (edge.from === p.getId() && edge.to === f.getId()))){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
edges.push(new Edge(p.getId(), f.getId()))
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
return new GraphPerson(edges, nodesPerson)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default GraphCreator
|
@ -0,0 +1,21 @@
|
|||||||
|
import Color from "../Color"
|
||||||
|
import { ColorToColorFont, ColorToHexa } from "../EnumExtender"
|
||||||
|
import Font from "./Font"
|
||||||
|
|
||||||
|
class NodePerson{
|
||||||
|
public id: number
|
||||||
|
public label: string
|
||||||
|
public color: string
|
||||||
|
public font: Font
|
||||||
|
public shape: string
|
||||||
|
|
||||||
|
constructor(id: number, label: string, color: Color, font: Font, shape: string){
|
||||||
|
this.id=id
|
||||||
|
this.label=label
|
||||||
|
this.color=ColorToHexa(color)
|
||||||
|
this.font=font
|
||||||
|
this.shape = shape
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default NodePerson
|
@ -1,26 +0,0 @@
|
|||||||
import Edge from "./Edge";
|
|
||||||
import GraphPerson from "./GraphPerson";
|
|
||||||
import NodePerson from "./NodePerson";
|
|
||||||
import PersonNetwork from "./PersonsNetwork";
|
|
||||||
|
|
||||||
class GraphCreator{
|
|
||||||
|
|
||||||
static CreateGraph(network: PersonNetwork): GraphPerson{
|
|
||||||
const nodesPerson : NodePerson[] = []
|
|
||||||
const edges: Edge[] = []
|
|
||||||
network.getPersons().forEach((p) =>{
|
|
||||||
const nodePerson = new NodePerson(p.getId(), p.getName())
|
|
||||||
nodesPerson.push(nodePerson)
|
|
||||||
p.getFriends().forEach((f) =>{
|
|
||||||
if(edges.some(edge => (edge.from === f.getId() && edge.to === p.getId()) || (edge.from === p.getId() && edge.to === f.getId()))){
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
edges.push(new Edge(p.getId(), f.getId()))
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
return new GraphPerson(edges, nodesPerson)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export default GraphCreator
|
|
@ -1,11 +0,0 @@
|
|||||||
class NodePerson{
|
|
||||||
public id: number
|
|
||||||
public label: string
|
|
||||||
|
|
||||||
constructor(id: number, label: string){
|
|
||||||
this.id=id
|
|
||||||
this.label=label
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export default NodePerson
|
|
Loading…
Reference in new issue