2017-08-20 14:32:01 +08:00
|
|
|
const colourToHex = (value) => {
|
|
|
|
let hex;
|
|
|
|
hex = parseInt(value, 10).toString(16);
|
|
|
|
while (hex.length < 6) {
|
|
|
|
hex = `0${hex}`;
|
|
|
|
}
|
2016-06-04 06:39:28 +08:00
|
|
|
|
2017-08-20 14:32:01 +08:00
|
|
|
return `#${hex}`;
|
2016-06-04 06:39:28 +08:00
|
|
|
};
|
|
|
|
|
2017-09-06 09:36:15 +08:00
|
|
|
const getFormattedColor = (color) => {
|
2017-09-07 03:36:52 +08:00
|
|
|
let _color = color || '0';
|
2016-06-04 06:39:28 +08:00
|
|
|
|
2017-08-20 14:32:01 +08:00
|
|
|
if (!_color.toString().match(/#.*/)) {
|
|
|
|
_color = colourToHex(_color);
|
2016-06-04 06:39:28 +08:00
|
|
|
}
|
|
|
|
|
2017-08-20 14:32:01 +08:00
|
|
|
return _color;
|
2016-06-04 06:39:28 +08:00
|
|
|
};
|
|
|
|
|
2017-08-20 14:32:01 +08:00
|
|
|
const getStrokeWidth = (thickness, slideWidth) => (thickness * slideWidth) / 100;
|
2016-06-04 06:39:28 +08:00
|
|
|
|
2020-04-07 04:34:08 +08:00
|
|
|
const denormalizeCoord = (normCoord, sideLength) => ((normCoord / 100) * sideLength).toFixed(2);
|
|
|
|
|
|
|
|
export {
|
2017-09-06 09:36:15 +08:00
|
|
|
getFormattedColor,
|
2016-06-04 06:39:28 +08:00
|
|
|
getStrokeWidth,
|
2020-04-07 04:34:08 +08:00
|
|
|
denormalizeCoord,
|
2016-06-04 06:39:28 +08:00
|
|
|
};
|