Skip to content

Commit

Permalink
Merge branch 'master' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
quincylvania committed Sep 28, 2020
2 parents 502098b + ae05e1f commit d4aed84
Show file tree
Hide file tree
Showing 12 changed files with 644 additions and 372 deletions.
41 changes: 41 additions & 0 deletions data/icons.json
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,12 @@
"information"
]
},
"cloth": {
"groups": [
"clothes",
"home"
]
},
"clothes_hanger": {
"groups": [
"clothes"
Expand Down Expand Up @@ -794,6 +800,11 @@
"home"
]
},
"detergent_bottle": {
"groups": [
"home"
]
},
"diamond": {
"groups": [
"highways",
Expand Down Expand Up @@ -888,6 +899,12 @@
"sports"
]
},
"fighter_jet": {
"groups": [
"aeroways",
"vehicles"
]
},
"fire_hydrant": {
"groups": [
"water"
Expand Down Expand Up @@ -1231,6 +1248,12 @@
"water"
]
},
"latrine": {
"groups": [
"buildings",
"camping"
]
},
"laundry": {
"groups": [
"home",
Expand Down Expand Up @@ -1799,6 +1822,12 @@
"snow"
]
},
"sailboat": {
"groups": [
"vehicles",
"water"
]
},
"sailing": {
"groups": [
"sports",
Expand Down Expand Up @@ -2201,6 +2230,12 @@
"sports"
]
},
"tents": {
"groups": [
"buildings",
"camping"
]
},
"ticket": {
"groups": [
"information"
Expand Down Expand Up @@ -2551,6 +2586,12 @@
"water"
]
},
"water_bottle": {
"groups": [
"food",
"water"
]
},
"water_device": {
"groups": [
"utilities",
Expand Down
24 changes: 24 additions & 0 deletions dist/temaki-symbol.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
742 changes: 383 additions & 359 deletions dist/temaki-view.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
89 changes: 88 additions & 1 deletion docs/index.html

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions icons/cloth.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions icons/detergent_bottle.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions icons/fighter_jet.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions icons/latrine.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions icons/sailboat.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions icons/tents.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions icons/water_bottle.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
82 changes: 70 additions & 12 deletions scripts/check.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,49 @@ function ellipseAttrsToPathD(rx, cx, ry, cy) {
return `M${cx - rx},${cy}a${rx},${ry} 0 1,0 ${rx * 2},0a${rx},${ry} 0 1,0 -${rx * 2},0z`;
}

// https://github.com/elrumordelaluz/element-to-path/blob/master/src/index.js
function rectAttrsToPathD(attrs) {
const w = parseFloat(attrs('width'));
const h = parseFloat(attrs('height'));
const x = attrs('x') ? parseFloat(attrs('x')) : 0;
const y = attrs('y') ? parseFloat(attrs('y')) : 0;
let rx = attrs('rx') || 'auto';
let ry = attrs('ry') || 'auto';
if (rx === 'auto' && ry === 'auto') {
rx = ry = 0;
} else if (rx !== 'auto' && ry === 'auto') {
rx = ry = calcValue(rx, w);
} else if (ry !== 'auto' && rx === 'auto') {
ry = rx = calcValue(ry, h);
} else {
rx = calcValue(rx, w);
ry = calcValue(ry, h);
}
if (rx > w / 2) {
rx = w / 2;
}
if (ry > h / 2) {
ry = h / 2;
}
const hasCurves = rx > 0 && ry > 0;
return [
`M${x + rx} ${y}`,
`H${x + w - rx}`,
(hasCurves ? `A${rx} ${ry} 0 0 1 ${x + w} ${y + ry}` : ''),
`V${y + h - ry}`,
(hasCurves ? `A${rx} ${ry} 0 0 1 ${x + w - rx} ${y + h}` : ''),
`H${x + rx}`,
(hasCurves ? `A${rx} ${ry} 0 0 1 ${x} ${y + h - ry}` : ''),
`V${y + ry}`,
(hasCurves ? `A${rx} ${ry} 0 0 1 ${x + rx} ${y}` : ''),
'z',
].filter(Boolean).join('');

function calcValue(val, base) {
return /%$/.test(val) ? (val.replace('%', '') * 100) / base : parseFloat(val);
}
}

function checkIcons() {
const START = '✅ ' + colors.yellow('Checking icons...');
const END = '👍 ' + colors.green('done');
Expand Down Expand Up @@ -38,6 +81,7 @@ function checkIcons() {
let warnings = [];

let childrenToRemove = new Set();
let pathDataToAdd = new Set();

xml.each((child, index, level) => {
const node = child.node;
Expand Down Expand Up @@ -73,37 +117,40 @@ function checkIcons() {
// convert ellipses to paths
if (node.nodeName === 'ellipse') {
const attr = (name) => parseFloat(node.getAttribute(name));
child.up().ele('path', {
d: ellipseAttrsToPathD(attr('rx'), attr('cx'), attr('ry'), attr('cy'))
});
pathDataToAdd.add(ellipseAttrsToPathD(attr('rx'), attr('cx'), attr('ry'), attr('cy')));
childrenToRemove.add(child);
return;

// convert rects to paths
} else if (node.nodeName === 'rect') {
const attr = (name) => node.getAttribute(name);
pathDataToAdd.add(rectAttrsToPathD(attr));
childrenToRemove.add(child);
return;

// convert polygons to paths
} else if (node.nodeName === 'polygon') {
child.up().ele('path', {
d: 'M ' + node.getAttribute('points') + 'z'
});
pathDataToAdd.add('M ' + node.getAttribute('points') + 'z');
childrenToRemove.add(child);
return;
// remove metadata nodes
} else if (node.nodeName === 'title' || node.nodeName === 'desc') {
childrenToRemove.add(child);
return;
} else if (node.nodeName === 'g') {
// groups will be emptied so remove them
childrenToRemove.add(child);
return;
}

if (level > 2) {
let parent = child.up();
if (parent.node.nodeName === 'g') {
// move the node out of the group
parent.up().ele(child.toString());
pathDataToAdd.add(child.toString());
childrenToRemove.add(child);
}
} else if (level === 2 && node.nodeName === 'g') {
// groups will be emptied so remove them
childrenToRemove.add(child);
return;
}
}

// suspicious elements
if (node.nodeName !== 'path') {
Expand Down Expand Up @@ -133,6 +180,17 @@ function checkIcons() {
child.remove();
});

Array.from(pathDataToAdd).forEach((pathData) => {
if (pathData[0] === '<') {
xml.root().ele(pathData);
} else {
xml.root().ele('path', {
d: pathData
});
}
});


if (warnings.length) {
warnings.forEach(w => console.warn(w));
console.warn(' in ' + file);
Expand Down

0 comments on commit d4aed84

Please sign in to comment.