diff --git a/inventory/static/js/components/draw.js b/inventory/static/js/components/draw.js index 4c67f2f..f149cdc 100644 --- a/inventory/static/js/components/draw.js +++ b/inventory/static/js/components/draw.js @@ -290,11 +290,18 @@ function initGridWidget(root, opts = {}) { function encodeStates(shapes) { return shapes.map(shape => { if (shape.type !== 'stateChange') return shape; + const re = /^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/; let newShape = {}; Object.keys(shape).forEach(key => { if (key === 'strokeOpacity' || key === 'strokeWidth' || key === 'fillOpacity') { - newShape[key] = Math.round(shape[key] * 100); + const v = Number(shape[key]); + if (Number.isFinite(v)) + newShape[key] = Math.round(v * 100); + } else if (key === 'color') { + newShape[key] = re.test(shape[key]) ? shape[key] : '#000000'; + } else if (key === 'fill') { + newShape[key] = !!shape[key]; } }); return { ...shape, ...newShape };