Home Information - Your home, your data, organized.
Python
Better styling for entity areas and CSS/color cleanup.
Anthony Cassandra60f0911a7bfa
diff --git a/src/hi/apps/common/svg_models.py b/src/hi/apps/common/svg_models.pyindex 19b8694c..608fd3b9 100644--- a/src/hi/apps/common/svg_models.py+++ b/src/hi/apps/common/svg_models.py@@ -1,6 +1,7 @@from dataclasses import dataclassfrom decimal import Decimal, ROUND_HALF_UP-+from typing import List+from django.core.exceptions import ValidationErrorfrom django.db import models@@ -138,18 +139,23 @@ class SvgPathItem:path item is a sequence of drawing commands defined in 'svg_path'."""- html_id : str- css_class : str- svg_path : str- stroke_color : str- stroke_width : float- fill_color : str- fill_opacity : float+ html_id : str+ css_class : str+ svg_path : str+ stroke_color : str+ stroke_width : float+ stroke_dasharray : List[ int ]+ fill_color : str+ fill_opacity : float@propertydef is_closed(self):return bool( self.svg_path and ( self.svg_path[-1].lower() == 'z' ))+ @property+ def stroke_dasharray_value(self):+ return ",".join([ str(x) for x in self.stroke_dasharray ])+class SvgDecimalField( models.DecimalField ):"""@@ -186,18 +192,21 @@ class SvgDecimalField( models.DecimalField ):@dataclassclass SvgStatusStyle:- status_value : str- stroke_color : str- stroke_width : float- fill_color : str- fill_opacity : float+ status_value : str+ stroke_color : str+ stroke_width : float+ stroke_dasharray : List[ int ]+ fill_color : str+ fill_opacity : floatdef to_dict(self):- return {+ result = {'status': self.status_value,'stroke': self.stroke_color,'stroke-width': self.stroke_width,'fill': self.fill_color,'fill-opacity': self.fill_opacity,}-+ if self.stroke_dasharray:+ result['stroke-dasharray'] = ','.join([ str(x) for x in self.stroke_dasharray ])+ return resultdiff --git a/src/hi/apps/location/svg_item_factory.py b/src/hi/apps/location/svg_item_factory.pyindex 36632032..2ff856e8 100644--- a/src/hi/apps/location/svg_item_factory.py+++ b/src/hi/apps/location/svg_item_factory.py@@ -55,6 +55,7 @@ class SvgItemFactory( Singleton ):svg_path = path.svg_path,stroke_color = svg_status_style.stroke_color,stroke_width = svg_status_style.stroke_width,+ stroke_dasharray = svg_status_style.stroke_dasharray,fill_color = svg_status_style.fill_color,fill_opacity = svg_status_style.fill_opacity,)diff --git a/src/hi/apps/location/templates/location/panes/svg_path_item.html b/src/hi/apps/location/templates/location/panes/svg_path_item.htmlindex 8bbc404c..7fef9b8e 100644--- a/src/hi/apps/location/templates/location/panes/svg_path_item.html+++ b/src/hi/apps/location/templates/location/panes/svg_path_item.html@@ -4,9 +4,10 @@fill-opacity="{{ svg_path_item.fill_opacity }}"stroke="{{ svg_path_item.stroke_color }}"stroke-width="{{ svg_path_item.stroke_width }}"+ stroke-dasharray="{{ svg_path_item.stroke_dasharray_value }}"vector-effect="non-scaling-stroke"{% if not svg_path_item.is_closed %}style="pointer-events: stroke;"{% endif %}- onmouseover="this.style.strokeWidth='10';"+ onmouseover="this.style.strokeWidth='3';"onmouseout="this.style.strokeWidth='{{ svg_path_item.stroke_width }}';"d="{{ svg_path_item.svg_path }}"></path></g>diff --git a/src/hi/apps/monitor/status_display_data.py b/src/hi/apps/monitor/status_display_data.pyindex 88f85492..3669411f 100644--- a/src/hi/apps/monitor/status_display_data.py+++ b/src/hi/apps/monitor/status_display_data.py@@ -9,116 +9,140 @@ from .transient_models import EntityStateStatusDataclass StatusStyle:DEFAULT_STATUS_VALUE = ''- DEFAULT_STROKE_COLOR = '#40f040'- DEFAULT_STROKE_WIDTH = 5.0+ DEFAULT_STROKE_COLOR = '#a0a0a0'+ DEFAULT_STROKE_WIDTH = 1.0+ DEFAULT_STROKE_DASHARRAY = [ 3, 6 ]DEFAULT_FILL_COLOR = 'white'DEFAULT_FILL_OPACITY = 0.0++ # These should match those in main.css+ STATUS_ACTIVE_COLOR = 'red'+ STATUS_RECENT_COLOR = 'orange'+ STATUS_PAST_COLOR = 'yellow'+ STATUS_OK_COLOR = 'green'+ STATUS_BAD_COLOR = 'red'+ STATUS_IDLE_COLOR = '#888888'MovementActive = SvgStatusStyle(status_value = 'active',- stroke_color = 'red',+ stroke_color = STATUS_ACTIVE_COLOR,stroke_width = DEFAULT_STROKE_WIDTH,- fill_color = 'red',+ stroke_dasharray = DEFAULT_STROKE_DASHARRAY,+ fill_color = STATUS_ACTIVE_COLOR,fill_opacity = 0.5,)MovementRecent = SvgStatusStyle(status_value = 'recent',- stroke_color = 'orange',+ stroke_color = STATUS_RECENT_COLOR,stroke_width = DEFAULT_STROKE_WIDTH,- fill_color = 'orange',+ stroke_dasharray = DEFAULT_STROKE_DASHARRAY,+ fill_color = STATUS_RECENT_COLOR,fill_opacity = 0.5,)MovementPast = SvgStatusStyle(status_value = 'past',- stroke_color = 'yellow',+ stroke_color = STATUS_PAST_COLOR,stroke_width = DEFAULT_STROKE_WIDTH,- fill_color = 'yellow',+ stroke_dasharray = DEFAULT_STROKE_DASHARRAY,+ fill_color = STATUS_PAST_COLOR,fill_opacity = 0.5,)MovementIdle = SvgStatusStyle(status_value = 'idle',- stroke_color = '#888888',+ stroke_color = STATUS_OK_COLOR,stroke_width = DEFAULT_STROKE_WIDTH,- fill_color = 'white',- fill_opacity = 0.0,+ stroke_dasharray = DEFAULT_STROKE_DASHARRAY,+ fill_color = STATUS_OK_COLOR,+ fill_opacity = 0.15,)On = SvgStatusStyle(status_value = 'on',stroke_color = 'green',stroke_width = DEFAULT_STROKE_WIDTH,+ stroke_dasharray = DEFAULT_STROKE_DASHARRAY,fill_color = 'green',fill_opacity = 0.5,)Off = SvgStatusStyle(status_value = 'off',- stroke_color = '#888888',+ stroke_color = STATUS_IDLE_COLOR,stroke_width = DEFAULT_STROKE_WIDTH,- fill_color = '#888888',+ stroke_dasharray = DEFAULT_STROKE_DASHARRAY,+ fill_color = STATUS_IDLE_COLOR,fill_opacity = 0.5,)Open = SvgStatusStyle(status_value = 'open',- stroke_color = 'red',+ stroke_color = STATUS_ACTIVE_COLOR,stroke_width = DEFAULT_STROKE_WIDTH,- fill_color = 'red',+ stroke_dasharray = DEFAULT_STROKE_DASHARRAY,+ fill_color = STATUS_ACTIVE_COLOR,fill_opacity = 0.5,)OpenRecent = SvgStatusStyle(status_value = 'recent',- stroke_color = 'orange',+ stroke_color = STATUS_RECENT_COLOR,stroke_width = DEFAULT_STROKE_WIDTH,- fill_color = 'orange',+ stroke_dasharray = DEFAULT_STROKE_DASHARRAY,+ fill_color = STATUS_RECENT_COLOR,fill_opacity = 0.5,)OpenPast = SvgStatusStyle(status_value = 'past',- stroke_color = 'yellow',+ stroke_color = STATUS_PAST_COLOR,stroke_width = DEFAULT_STROKE_WIDTH,- fill_color = 'yellow',+ stroke_dasharray = DEFAULT_STROKE_DASHARRAY,+ fill_color = STATUS_PAST_COLOR,fill_opacity = 0.5,)Closed = SvgStatusStyle(status_value = 'closed',- stroke_color = '#888888',+ stroke_color = STATUS_IDLE_COLOR,stroke_width = DEFAULT_STROKE_WIDTH,- fill_color = '#888888',+ stroke_dasharray = DEFAULT_STROKE_DASHARRAY,+ fill_color = STATUS_IDLE_COLOR,fill_opacity = 0.5,)Connected = SvgStatusStyle(status_value = 'connected',- stroke_color = 'green',+ stroke_color = STATUS_OK_COLOR,stroke_width = DEFAULT_STROKE_WIDTH,- fill_color = 'green',+ stroke_dasharray = DEFAULT_STROKE_DASHARRAY,+ fill_color = STATUS_OK_COLOR,fill_opacity = 0.5,)Disconnected = SvgStatusStyle(status_value = 'disconnected',- stroke_color = 'red',+ stroke_color = STATUS_BAD_COLOR,stroke_width = DEFAULT_STROKE_WIDTH,- fill_color = 'red',+ stroke_dasharray = DEFAULT_STROKE_DASHARRAY,+ fill_color = STATUS_BAD_COLOR,fill_opacity = 0.5,)High = SvgStatusStyle(status_value = 'high',- stroke_color = 'green',+ stroke_color = STATUS_OK_COLOR,stroke_width = DEFAULT_STROKE_WIDTH,- fill_color = 'green',+ stroke_dasharray = DEFAULT_STROKE_DASHARRAY,+ fill_color = STATUS_OK_COLOR,fill_opacity = 0.5,)Low = SvgStatusStyle(status_value = 'low',- stroke_color = 'red',+ stroke_color = STATUS_BAD_COLOR,stroke_width = DEFAULT_STROKE_WIDTH,- fill_color = 'red',+ stroke_dasharray = DEFAULT_STROKE_DASHARRAY,+ fill_color = STATUS_BAD_COLOR,fill_opacity = 0.5,)@classmethod- def default(cls):+ def default( cls, status_value : str = DEFAULT_STATUS_VALUE ):return SvgStatusStyle(- status_value = cls.DEFAULT_STATUS_VALUE,+ status_value = status_value,stroke_color = cls.DEFAULT_STROKE_COLOR,stroke_width = cls.DEFAULT_STROKE_WIDTH,+ stroke_dasharray = cls.DEFAULT_STROKE_DASHARRAY,fill_color = cls.DEFAULT_FILL_COLOR,fill_opacity = cls.DEFAULT_FILL_OPACITY,)@@ -224,14 +248,8 @@ class StatusDisplayData:status_value = self.latest_sensor_valueif not status_value:status_value = StatusStyle.DEFAULT_STATUS_VALUE-- return SvgStatusStyle(- status_value = status_value,- stroke_color = StatusStyle.DEFAULT_STROKE_COLOR,- stroke_width = StatusStyle.DEFAULT_STROKE_WIDTH,- fill_color = StatusStyle.DEFAULT_FILL_COLOR,- fill_opacity = StatusStyle.DEFAULT_FILL_OPACITY,- )++ return StatusStyle.default( status_value = status_value )def _get_movement_status_style( self ):diff --git a/src/hi/static/css/main.css b/src/hi/static/css/main.cssindex 66ff50ea..e73be234 100644--- a/src/hi/static/css/main.css+++ b/src/hi/static/css/main.css@@ -27,6 +27,25 @@--top-buttons-height: 2.5rem;--bottom-buttons-height: 2.5rem;++ --status-highlighted-color: red;+ --status-hover-color: blue;++ /* These should match those in hi.apps.monitor.StatusStyle */+ --status-active-color: red;+ --status-recent-color: orange;+ --status-past-color: yellow;+ --status-ok-color: green;+ --status-bad-color: red;+ --status-idle-color: #888888;++ --on-status-active-color: white;+ --on-status-recent-color: black;+ --on-status-past-color: black;+ --on-status-ok-color: white;+ --on-status-bad-color: white;+ --on-status-idle-color: black;+}html, body {@@ -222,96 +241,100 @@ svg[action-state="scale"] {}svg .highlighted {- filter: drop-shadow(0 0 10px red);+ filter: drop-shadow(0 0 10px var(--status-highlighted-color));}g[hover] {- outline: 2px solid blue;- filter: drop-shadow(0 0 5px blue);+ outline: 2px solid var(--status-hover-color);+ filter: drop-shadow(0 0 5px var(--status-hover-color));}g[status="active"] {- outline: 2px solid red;- filter: drop-shadow(0 0 5px red);+ outline: 2px solid var(--status-active-color);+ filter: drop-shadow(0 0 5px var(--status-active-color));}g[status="recent"] {- outline: 2px solid orange;- filter: drop-shadow(0 0 5px orange);+ outline: 2px solid var(--status-recent-color);+ filter: drop-shadow(0 0 5px var(--status-recent-color));}g[status="past"] {- outline: 2px solid yellow;- filter: drop-shadow(0 0 5px yellow);+ outline: 2px solid var(--status-past-color);+ filter: drop-shadow(0 0 5px var(--status-past-color));}g[status="on"] {- outline: 5px solid green;- filter: drop-shadow(0 0 5px green);+ outline: 5px solid var(--status-ok-color);+ filter: drop-shadow(0 0 5px var(--status-ok-color));+}+g[status="off"] {+ outline: 5px solid var(--status-idle-color);+ filter: drop-shadow(0 0 5px var(--status-idle-color));}g[status="open"] {- outline: 5px solid red;- filter: drop-shadow(0 0 5px red);+ outline: 5px solid var(--status-active-color);+ filter: drop-shadow(0 0 5px var(--status-active-color));}g[status="connected"] {- outline: 5px solid green;- filter: drop-shadow(0 0 5px green);+ outline: 5px solid var(--status-ok-color);+ filter: drop-shadow(0 0 5px var(--status-ok-color));}g[status="disconnected"] {- outline: 5px solid red;- filter: drop-shadow(0 0 5px red);+ outline: 5px solid var(--status-active-color);+ filter: drop-shadow(0 0 5px var(--status-active-color));}g[status="high"] {- outline: 5px solid green;- filter: drop-shadow(0 0 5px green);+ outline: 5px solid var(--status-ok-color);+ filter: drop-shadow(0 0 5px var(--status-ok-color));}g[status="low"] {- outline: 5px solid red;- filter: drop-shadow(0 0 5px red);+ outline: 5px solid var(--status-active-color);+ filter: drop-shadow(0 0 5px var(--status-active-color));}div[status="active"] {- color: white;- background-color: red;+ color: var(--on-status-active-color);+ background-color: var(--status-active-color);}div[status="idle"] {- color: var(--on-success-color);- background-color: var(--success-color);+ color: var(--on-status-ok-color);+ background-color: var(--status-ok-color);}div[status="recent"] {- color: black;- background-color: orange;+ color: var(--on-status-recent-color);+ background-color: var(--status-recent-color);}div[status="past"] {- color: black;- background-color: yellow;+ color: var(--on-status-past-color);+ background-color: var(--status-past-color);}div[status="on"] {- color: var(--on-success-color);- background-color: var(--success-color);+ color: var(--on-status-ok-color);+ background-color: var(--status-ok-color);}div[status="off"] {- color: var(--on-error-color);- background-color: var(--error-color);+ color: var(--on-status-idle-color);+ background-color: var(--status-idle-color);}div[status="open"] {- color: var(--on-error-color);- background-color: var(--error-color);+ color: var(--on-status-bad-color);+ background-color: var(--status-bad-color);}div[status="closed"] {- color: var(--on-success-color);- background-color: var(--success-color);+ color: var(--on-status-idle-color);+ background-color: var(--status-idle-color);}div[status="connected"] {- color: var(--on-success-color);- background-color: var(--success-color);+ color: var(--on-status-ok-color);+ background-color: var(--status-ok-color);}div[status="disconnected"] {- color: var(--on-error-color);- background-color: var(--error-color);+ color: var(--on-status-bad-color);+ background-color: var(--status-bad-color);}div[status="high"] {- color: var(--on-success-color);- background-color: var(--success-color);+ color: var(--on-status-ok-color);+ background-color: var(--status-ok-color);}div[status="low"] {- color: var(--on-error-color);- background-color: var(--error-color);+ color: var(--on-status-bad-color);+ background-color: var(--status-bad-color);}.switch {