diff --git a/cryptide_project/src/Components/GraphContainer.tsx b/cryptide_project/src/Components/GraphContainer.tsx index 00375c1..f965aec 100644 --- a/cryptide_project/src/Components/GraphContainer.tsx +++ b/cryptide_project/src/Components/GraphContainer.tsx @@ -1,7 +1,7 @@ import React, { useEffect } from "react"; import { DataSet, Network} from "vis-network/standalone/esm/vis-network"; import EdgesCreator from "../source/EdgesCreator"; -import GraphCreator from "../source/GraphCreator"; +import GraphCreator from "../source/Graph/GraphCreator"; import IndiceChooser from "../source/IndiceChooser"; import NetworkGenerator from "../source/NetworkGenerator"; import Stub from "../source/Stub"; @@ -41,13 +41,6 @@ const MyGraphComponent = () => { // Configuration des options du Graphe const initialOptions = { - nodes: { - shape: 'circle', - size: 30, - font: { - size: 20 - }, - }, layout: { improvedLayout: true, hierarchical: { @@ -70,8 +63,6 @@ const MyGraphComponent = () => { const network = new Network(container, networkData, initialOptions); // Gérer le changement entre la physique et le déplacement manuel - let physicsEnabled = true; - network.on("dragging", (params) => { if (params.nodes.length > 0) { // Un nœud a été cliqué diff --git a/cryptide_project/src/Pages/Home.tsx b/cryptide_project/src/Pages/Home.tsx index 6fb664b..5cc819b 100644 --- a/cryptide_project/src/Pages/Home.tsx +++ b/cryptide_project/src/Pages/Home.tsx @@ -17,7 +17,7 @@ import Indice from '../source/Indices/Indice'; import SportIndice from '../source/Indices/SportIndice'; import Stub from '../source/Stub'; import NetworkGenerator from '../source/NetworkGenerator'; -import GraphCreator from '../source/GraphCreator'; +import GraphCreator from '../source/Graph/GraphCreator'; import { FormattedMessage } from 'react-intl'; diff --git a/cryptide_project/src/source/Color.ts b/cryptide_project/src/source/Color.ts index c2d7bf0..49c3e0f 100644 --- a/cryptide_project/src/source/Color.ts +++ b/cryptide_project/src/source/Color.ts @@ -3,9 +3,7 @@ enum Color { NOIR, BLOND, ROUX, - CHATAIN, + BRUN, } -export default Color - - \ No newline at end of file +export default Color \ No newline at end of file diff --git a/cryptide_project/src/source/EdgesCreator.ts b/cryptide_project/src/source/EdgesCreator.ts index 2eaf0cc..fee63e6 100644 --- a/cryptide_project/src/source/EdgesCreator.ts +++ b/cryptide_project/src/source/EdgesCreator.ts @@ -50,19 +50,23 @@ class EdgesCreator{ return } if (p != personToCreateEdge && p != choosenPerson && !personToCreateEdge.getFriends().includes(p)){ - let testEdgeWork = 0 + let testEdgeWork1 = 0 + let testEdgeWork2 = 0 const p1 = cloneDeep(p); const personEdge = cloneDeep(personToCreateEdge); p1.addFriend(personEdge) personEdge.addFriend(p1) indices.forEach((indice) => { const tester = IndiceTesterFactory.Create(indice) - if (tester.Works(p1) || tester.Works(personEdge) || map.get(p.getId()) === p.getFriends().length){ - testEdgeWork ++ + if (tester.Works(p1) || map.get(p.getId()) === p.getFriends().length){ + testEdgeWork1 ++ } + if (tester.Works(personEdge) || map.get(p.getId()) === p.getFriends().length){ + testEdgeWork2 ++ + } }); - if (testEdgeWork < indices.length){ + if (testEdgeWork1 < indices.length && testEdgeWork2 < indices.length){ p.addFriend(personToCreateEdge) personToCreateEdge.addFriend(p) } @@ -72,6 +76,13 @@ class EdgesCreator{ CreateAllEdges(personNetwork: PersonNetwork, choosenPerson: Person, indices: Indice[]){ const test = new Map() + const tabEdgesSize: number[] = [] + for (let i = 0; i { if (indice instanceof EdgesIndice){ this.CreateWorkingEdge(personNetwork, choosenPerson, indice, indices) @@ -79,7 +90,8 @@ class EdgesCreator{ }); personNetwork.getPersons().forEach((p) => { if (p != choosenPerson){ - test.set(p.getId(), Math.floor(Math.random() * 5) + p.getFriends().length + 1) + const rand = Math.floor(Math.random() * 4) + test.set(p.getId(), tabEdgesSize[rand] + p.getFriends().length) } }); personNetwork.getPersons().forEach((p) => { diff --git a/cryptide_project/src/source/EnumExtender.ts b/cryptide_project/src/source/EnumExtender.ts new file mode 100644 index 0000000..51e94c6 --- /dev/null +++ b/cryptide_project/src/source/EnumExtender.ts @@ -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} diff --git a/cryptide_project/src/source/Edge.ts b/cryptide_project/src/source/Graph/Edge.ts similarity index 100% rename from cryptide_project/src/source/Edge.ts rename to cryptide_project/src/source/Graph/Edge.ts diff --git a/cryptide_project/src/source/Graph/Font.ts b/cryptide_project/src/source/Graph/Font.ts new file mode 100644 index 0000000..355739e --- /dev/null +++ b/cryptide_project/src/source/Graph/Font.ts @@ -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 \ No newline at end of file diff --git a/cryptide_project/src/source/Graph/GraphCreator.ts b/cryptide_project/src/source/Graph/GraphCreator.ts new file mode 100644 index 0000000..1464e75 --- /dev/null +++ b/cryptide_project/src/source/Graph/GraphCreator.ts @@ -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{ + 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 \ No newline at end of file diff --git a/cryptide_project/src/source/GraphPerson.ts b/cryptide_project/src/source/Graph/GraphPerson.ts similarity index 100% rename from cryptide_project/src/source/GraphPerson.ts rename to cryptide_project/src/source/Graph/GraphPerson.ts diff --git a/cryptide_project/src/source/Graph/NodePerson.ts b/cryptide_project/src/source/Graph/NodePerson.ts new file mode 100644 index 0000000..5415756 --- /dev/null +++ b/cryptide_project/src/source/Graph/NodePerson.ts @@ -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 \ No newline at end of file diff --git a/cryptide_project/src/source/GraphCreator.ts b/cryptide_project/src/source/GraphCreator.ts deleted file mode 100644 index 69b1704..0000000 --- a/cryptide_project/src/source/GraphCreator.ts +++ /dev/null @@ -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 \ No newline at end of file diff --git a/cryptide_project/src/source/Indices/AgeIndice.ts b/cryptide_project/src/source/Indices/AgeIndice.ts index 6f15a6d..5221b70 100644 --- a/cryptide_project/src/source/Indices/AgeIndice.ts +++ b/cryptide_project/src/source/Indices/AgeIndice.ts @@ -11,7 +11,7 @@ class AgeIndice extends Indice { } // Implémentation de la méthode abstraite - ToString(): string { + ToString(lang: string): string { return "La personne a entre " + this.minimum + " et " + this.maximum + " ans" } diff --git a/cryptide_project/src/source/Indices/ColorEdgesIndice.ts b/cryptide_project/src/source/Indices/ColorEdgesIndice.ts index 61c0432..7b37e4e 100644 --- a/cryptide_project/src/source/Indices/ColorEdgesIndice.ts +++ b/cryptide_project/src/source/Indices/ColorEdgesIndice.ts @@ -1,7 +1,9 @@ import Color from "../Color"; +import { ColorToString } from "../EnumExtender"; import EdgesIndice from "./EdgesIndice"; class ColorEdgesIndice extends EdgesIndice { + private neighborsColors: Color[]; constructor(id: number, neighborsColors: Color[]) { @@ -14,8 +16,17 @@ class ColorEdgesIndice extends EdgesIndice { } // Implémentation de la méthode abstraite - ToString(): string { - return "La personne a au moins " + this.neighborsColors + " amis"; + ToString(lang: string): string { + let string = "La personne a au moins un ami avec les cheveux"; + for (let i = 0; i