1 | /** |
---|
2 | * @file Text Helper |
---|
3 | * @author Patryk Gliszczynski |
---|
4 | * @version 1.0 |
---|
5 | */ |
---|
6 | |
---|
7 | var Text = { |
---|
8 | styleRegex: /<style>.*<\/style>/, |
---|
9 | numberRegex : /-?\d+(\.\d+)?/g, |
---|
10 | roundMatch: function(match) { |
---|
11 | return roundNumber(match,2).toString(); |
---|
12 | }, |
---|
13 | |
---|
14 | getGenotypeMesh: function(genotype,genotypeType) { |
---|
15 | const genman = new Module.GenMan(); |
---|
16 | genotype = genotype.replace(this.numberRegex, this.roundMatch); |
---|
17 | genotype = genotype.replaceAll("\n","⤶"); |
---|
18 | if (genotype.length > 20) { |
---|
19 | genotype = genotype.slice(0,30) + "..." |
---|
20 | } |
---|
21 | var element = document.createElement("div"); |
---|
22 | element.innerHTML = genman.HTMLize(genotype).c_str(); |
---|
23 | element.innerHTML = element.innerHTML.replace(this.styleRegex,"").replace(genotypeType,""); |
---|
24 | Module.destroy(genman); |
---|
25 | return new CSS3DObject(element); |
---|
26 | }, |
---|
27 | |
---|
28 | getFitnessMesh: function(fitness) { |
---|
29 | var element = document.createElement("div"); |
---|
30 | element.className = "fitness"; |
---|
31 | element.textContent = fitness; |
---|
32 | return new CSS3DObject(element); |
---|
33 | }, |
---|
34 | |
---|
35 | getInfoMesh: function(info) { |
---|
36 | var element = document.createElement("div"); |
---|
37 | element.className = "info"; |
---|
38 | element.textContent = info; |
---|
39 | return new CSS3DObject(element); |
---|
40 | } |
---|
41 | } |
---|