-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgeneratesvgs.js
80 lines (67 loc) · 2.08 KB
/
generatesvgs.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
const { data } = require('./public/data/trainNums');
const { types } = require('./public/data/trainTypes');
const fs = require('fs');
const statusColors = {
'ontime': '#63A744',
'early': '#63A744',
'late': '#F6A33D',
'complete': '#212529',
'nodata': '#212529'
}
const backgroundColors = {
'long': '#1A4F7F',
'state': '#474747',
'nec': '#000000',
'acela': '#028599'
};
const sizing = {
1: {
'outer': '128',
'inner': '114'
},
2: {
'outer': '128',
'inner': '114'
},
3: {
'outer': '192',
'inner': '178'
},
4: {
'outer': '256',
'inner': '242'
}
}
const generateSvg = ((params) => {
const state = params.split('.')[0].split('-');
const trainNum = state[0];
const status = state[1]; //late, early, etc
//console.log(trainNum.split('').length)
const trainSizing = sizing[trainNum.split('').length];
//console.log(trainSizing.outer)
//backgroundColors[types[trainNum]]
//statusColors[status]
return `
<svg width="${trainSizing.outer}" height="128" viewBox="0 0 ${trainSizing.outer} 128" fill="none" xmlns="http://www.w3.org/2000/svg">
<rect x="0" width="${trainSizing.outer}" height="128" rx="44" fill="${backgroundColors[types[trainNum]]}"/>
<rect x="7" y="7" width="${trainSizing.inner}" height="114" rx="36" fill="${statusColors[status]}"/>
<text x="${parseInt(trainSizing.outer) / 2}" y="90" fill="#fff" font-family="monospace" font-size="86px" text-anchor="middle">${trainNum}</text>
</svg>
`
})
const trainNums = Object.keys(data);
const states = ['late', 'early', 'ontime', 'nodata', 'complete'];
let trainStates = [];
for (let i = 0; i < trainNums.length; i++) {
for (let j = 0; j < states.length; j++) {
trainStates.push(`${trainNums[i]}-${states[j]}.svg`)
}
}
fs.readdirSync('./').forEach(file => {
console.log(file);
});
for (let i = 0; i < trainStates.length; i++) {
const svgData = generateSvg(trainStates[i]);
console.log('public/images/trainicons/' + trainStates[i])
fs.writeFileSync(__dirname + '/public/images/trainicons/' + trainStates[i], svgData);
}