Skip to content

Home Information - Your home, your data, organized.

Python

Mostly running in Docker now. A few minor issues ot work out. WIP

Anthony Cassandra45a0e90b6dc9
diff --git a/src/hi/apps/location/templates/location/panes/location_view.html b/src/hi/apps/location/templates/location/panes/location_view.html
index 93490ca4..6ef04f94 100644
--- a/src/hi/apps/location/templates/location/panes/location_view.html
+++ b/src/hi/apps/location/templates/location/panes/location_view.html
@@ -3,7 +3,7 @@
<link rel="stylesheet" href="{% static location_view.svg_style_name.css_static_file_name %}">
<div id="hi-location-view-main" class="hi-location-view">
<svg id="{{ location_view.html_id }}"
- class="hi-location-view"
+ class="hi-location-view-svg"
location-view-id="{{ location_view.id }}"
xmlns="http://www.w3.org/2000/svg"
viewBox="{{ location_view.svg_view_box }}"
diff --git a/src/hi/requirements/base.txt b/src/hi/requirements/base.txt
index 0d34eb75..0c6cbaf0 100644
--- a/src/hi/requirements/base.txt
+++ b/src/hi/requirements/base.txt
@@ -12,13 +12,12 @@ Django==4.2.15
django-constance==3.1.0
django-csp==3.8
django-picklefield==3.2
+django-pipeline==4.0.0
django-pipeline-csscompressor==0.1
-django-pipeline==3.1.0
frozenlist==1.4.1
gunicorn==23.0.0
idna==3.7
imutils==0.5.4
-jsmin==3.0.1
multidict==6.0.5
mysql-connector-python==9.0.0
numpy==2.1.0
diff --git a/src/hi/settings/base.py b/src/hi/settings/base.py
index 501b1b50..be794195 100644
--- a/src/hi/settings/base.py
+++ b/src/hi/settings/base.py
@@ -268,7 +268,7 @@ PIPELINE = {
'DISABLE_WRAPPER': True, # Important since some scripts assume global scope
'CSS_COMPRESSOR': 'django_pipeline_csscompressor.CssCompressor',
- 'JS_COMPRESSOR': 'pipeline.compressors.jsmin.JSMinCompressor',
+ 'JS_COMPRESSOR': None,
'STYLESHEETS': {
'css_head': {
diff --git a/src/hi/simulator/apps.py b/src/hi/simulator/apps.py
index 886df656..896505aa 100644
--- a/src/hi/simulator/apps.py
+++ b/src/hi/simulator/apps.py
@@ -30,6 +30,6 @@ class SimulatorConfig(AppConfig):
or ( "gunicorn" in sys.argv[0] )):
return
- time.sleep(1)
+ time.sleep(1) # Hack - Despite this method's name, Django is not actually "ready".
start_background_event_loop( task_function = SimulatorManager().initialize )
return
diff --git a/src/hi/static/css/main.css b/src/hi/static/css/main.css
index e617b513..360e1500 100644
--- a/src/hi/static/css/main.css
+++ b/src/hi/static/css/main.css
@@ -271,7 +271,7 @@ input[type="number"] {
align-items: center;
height: calc(100vh - var(--top-buttons-height) - var(--bottom-buttons-height) );
}
-.hi-location-view svg {
+.hi-location-view-svg {
max-height: calc(100vh - var(--top-buttons-height) - var(--bottom-buttons-height) );
width: auto;
height: auto;
diff --git a/src/hi/static/css/svg-location-color.css b/src/hi/static/css/svg-location-color.css
index 5a3ffa3f..02ad3c72 100644
--- a/src/hi/static/css/svg-location-color.css
+++ b/src/hi/static/css/svg-location-color.css
@@ -1,192 +1,192 @@
-svg.hi-location-view path.ground {
+svg.hi-location-view-svg path.ground {
fill: url(#ground-pattern);
stroke: black;
stroke-width: 0;
}
-svg.hi-location-view path.grass {
+svg.hi-location-view-svg path.grass {
fill: url(#grass-pattern);
stroke: black;
stroke-width: 0;
}
-svg.hi-location-view path.rock-beds {
+svg.hi-location-view-svg path.rock-beds {
fill: url(#rock-pattern);
stroke: black;
stroke-width: 1;
}
-svg.hi-location-view path.stone-walls {
+svg.hi-location-view-svg path.stone-walls {
fill: url(#stone-pattern);
stroke: black;
stroke-width: 1;
}
-svg.hi-location-view path.landscape-transitions {
+svg.hi-location-view-svg path.landscape-transitions {
fill: none;
stroke: #606060;
stroke-width: 4;
}
-svg.hi-location-view path.brick {
+svg.hi-location-view-svg path.brick {
fill: url(#brick-pattern);
stroke: #606060;
stroke-width: 4;
}
-svg.hi-location-view path.mulch {
+svg.hi-location-view-svg path.mulch {
fill: url(#mulch-pattern);
stroke: #606060;
stroke-width: 4;
}
-svg.hi-location-view path.gravel {
+svg.hi-location-view-svg path.gravel {
fill: url(#gravel-pattern);
stroke: #606060;
stroke-width: 4;
}
-svg.hi-location-view path.asphalt {
+svg.hi-location-view-svg path.asphalt {
fill: url(#asphalt-pattern);
stroke: #606060;
stroke-width: 4;
}
-svg.hi-location-view path.tiles {
+svg.hi-location-view-svg path.tiles {
fill: url(#tiles-pattern);
stroke: #606060;
stroke-width: 1;
}
-svg.hi-location-view path.wood-decks {
+svg.hi-location-view-svg path.wood-decks {
fill: url(#wood-pattern);
stroke: black;
stroke-width: 1;
}
-svg.hi-location-view path.pavement {
+svg.hi-location-view-svg path.pavement {
fill: url(#pavement-pattern);
stroke: black;
stroke-width: 1;
}
-svg.hi-location-view path.dead-space {
+svg.hi-location-view-svg path.dead-space {
fill: url(#dead-space-pattern);
stroke: black;
stroke-width: 1;
}
-svg.hi-location-view path.pavers {
+svg.hi-location-view-svg path.pavers {
fill: url(#pavers-pattern);
stroke: black;
stroke-width: 1;
}
-svg.hi-location-view path.pool-coping {
+svg.hi-location-view-svg path.pool-coping {
fill: #a0a0a0;
stroke: black;
stroke-width: 1;
}
-svg.hi-location-view path.property-lines {
+svg.hi-location-view-svg path.property-lines {
fill: none;
stroke: black;
stroke-width: 5;
stroke-dasharray: 50,10,50,10,10,10;
}
-svg.hi-location-view path.fencing {
+svg.hi-location-view-svg path.fencing {
fill: none;
stroke: #432b0f;
stroke-width: 8;
}
-svg.hi-location-view path.water {
+svg.hi-location-view-svg path.water {
fill: url(#water-pattern);
stroke: none;
stroke-width: 1;
}
-svg.hi-location-view path.sheds {
+svg.hi-location-view-svg path.sheds {
fill: #f2d0a7;
stroke: black;
stroke-width: 1;
}
-svg.hi-location-view path.foliage {
+svg.hi-location-view-svg path.foliage {
fill: url(#foliage-pattern);
stroke: black;
stroke-width: 1;
}
-svg.hi-location-view path.utilities {
+svg.hi-location-view-svg path.utilities {
fill: none;
stroke: black;
stroke-width: 1;
}
-svg.hi-location-view path.interior-floors {
+svg.hi-location-view-svg path.interior-floors {
fill: #f8f8f8;
stroke: none;
stroke-width: 1;
}
-svg.hi-location-view path.floor-transitions {
+svg.hi-location-view-svg path.floor-transitions {
fill: none;
stroke: #404040;
stroke-width: 1;
stroke-dasharray: 10, 10;
}
-svg.hi-location-view path.stairs {
+svg.hi-location-view-svg path.stairs {
fill: none;
stroke: black;
stroke-width: 1;
}
-svg.hi-location-view path.ceiling-transitions {
+svg.hi-location-view-svg path.ceiling-transitions {
fill: none;
stroke: #404040;
stroke-width: 1;
stroke-dasharray: 5, 5;
}
-svg.hi-location-view path.interior-walls {
+svg.hi-location-view-svg path.interior-walls {
fill: black;
stroke: black;
stroke-width: 1;
}
-svg.hi-location-view path.secondary-walls {
+svg.hi-location-view-svg path.secondary-walls {
fill: #a0a0a0;
stroke: #a0a0a0;
stroke-width: 1;
}
-svg.hi-location-view path.windows {
+svg.hi-location-view-svg path.windows {
fill: #78e3df;
stroke: black;
stroke-width: 1;
}
-svg.hi-location-view path.exterior-walls {
+svg.hi-location-view-svg path.exterior-walls {
fill: black;
stroke: black;
stroke-width: 1;
}
-svg.hi-location-view path.door-arcs {
+svg.hi-location-view-svg path.door-arcs {
fill: none;
stroke: black;
stroke-width: 1;
}
-svg.hi-location-view path.doors {
+svg.hi-location-view-svg path.doors {
fill: none;
stroke: black;
stroke-width: 3;
}
-svg.hi-location-view path.countertops {
+svg.hi-location-view-svg path.countertops {
fill: #e0e0e0;
stroke: black;
stroke-width: 1;
}
-svg.hi-location-view path.fireplaces {
+svg.hi-location-view-svg path.fireplaces {
fill: #fff0f0;
stroke: black;
stroke-width: 1;
}
-svg.hi-location-view path.furniture {
+svg.hi-location-view-svg path.furniture {
fill: #f2d0a7;
stroke: black;
stroke-width: 1;
}
-svg.hi-location-view path.toilets {
+svg.hi-location-view-svg path.toilets {
fill: #e0e0e0;
stroke: black;
stroke-width: 1;
}
-svg.hi-location-view path.shelves {
+svg.hi-location-view-svg path.shelves {
fill: #fffff0;
stroke: black;
stroke-width: 1;
}
-svg.hi-location-view path.bathtubs {
+svg.hi-location-view-svg path.bathtubs {
fill: #f8f8f8;
stroke: black;
stroke-width: 1;
}
-svg.hi-location-view path.sinks {
+svg.hi-location-view-svg path.sinks {
fill: #f8f8f8;
stroke: black;
stroke-width: 1;
diff --git a/src/hi/static/css/svg-location-greyscale.css b/src/hi/static/css/svg-location-greyscale.css
index 5223f5b0..49ebc295 100644
--- a/src/hi/static/css/svg-location-greyscale.css
+++ b/src/hi/static/css/svg-location-greyscale.css
@@ -1,192 +1,192 @@
-svg.hi-location-view path.ground {
+svg.hi-location-view-svg path.ground {
fill: url(#ground-pattern);
stroke: black;
stroke-width: 0;
}
-svg.hi-location-view path.grass {
+svg.hi-location-view-svg path.grass {
fill: url(#grass-pattern);
stroke: black;
stroke-width: 0;
}
-svg.hi-location-view path.rock-beds {
+svg.hi-location-view-svg path.rock-beds {
fill: url(#rock-pattern);
stroke: black;
stroke-width: 1;
}
-svg.hi-location-view path.stone-walls {
+svg.hi-location-view-svg path.stone-walls {
fill: url(#stone-pattern);
stroke: black;
stroke-width: 1;
}
-svg.hi-location-view path.landscape-transitions {
+svg.hi-location-view-svg path.landscape-transitions {
fill: none;
stroke: #606060;
stroke-width: 4;
}
-svg.hi-location-view path.brick {
+svg.hi-location-view-svg path.brick {
fill: url(#brick-pattern);
stroke: #606060;
stroke-width: 4;
}
-svg.hi-location-view path.mulch {
+svg.hi-location-view-svg path.mulch {
fill: url(#mulch-pattern);
stroke: #606060;
stroke-width: 4;
}
-svg.hi-location-view path.gravel {
+svg.hi-location-view-svg path.gravel {
fill: url(#gravel-pattern);
stroke: #606060;
stroke-width: 4;
}
-svg.hi-location-view path.asphalt {
+svg.hi-location-view-svg path.asphalt {
fill: url(#asphalt-pattern);
stroke: #606060;
stroke-width: 4;
}
-svg.hi-location-view path.tiles {
+svg.hi-location-view-svg path.tiles {
fill: url(#tiles-pattern);
stroke: #606060;
stroke-width: 1;
}
-svg.hi-location-view path.wood-decks {
+svg.hi-location-view-svg path.wood-decks {
fill: url(#wood-pattern);
stroke: black;
stroke-width: 1;
}
-svg.hi-location-view path.pavement {
+svg.hi-location-view-svg path.pavement {
fill: url(#pavement-pattern);
stroke: black;
stroke-width: 1;
}
-svg.hi-location-view path.dead-space {
+svg.hi-location-view-svg path.dead-space {
fill: url(#dead-space-pattern);
stroke: black;
stroke-width: 1;
}
-svg.hi-location-view path.pavers {
+svg.hi-location-view-svg path.pavers {
fill: url(#pavers-pattern);
stroke: black;
stroke-width: 1;
}
-svg.hi-location-view path.pool-coping {
+svg.hi-location-view-svg path.pool-coping {
fill: #a0a0a0;
stroke: black;
stroke-width: 1;
}
-svg.hi-location-view path.property-lines {
+svg.hi-location-view-svg path.property-lines {
fill: none;
stroke: black;
stroke-width: 5;
stroke-dasharray: 50,10,50,10,10,10;
}
-svg.hi-location-view path.fencing {
+svg.hi-location-view-svg path.fencing {
fill: none;
stroke: #404040;
stroke-width: 8;
}
-svg.hi-location-view path.water {
+svg.hi-location-view-svg path.water {
fill: url(#water-pattern);
stroke: none;
stroke-width: 1;
}
-svg.hi-location-view path.sheds {
+svg.hi-location-view-svg path.sheds {
fill: #b0b0b0;
stroke: black;
stroke-width: 1;
}
-svg.hi-location-view path.foliage {
+svg.hi-location-view-svg path.foliage {
fill: url(#foliage-pattern);
stroke: black;
stroke-width: 1;
}
-svg.hi-location-view path.utilities {
+svg.hi-location-view-svg path.utilities {
fill: none;
stroke: black;
stroke-width: 1;
}
-svg.hi-location-view path.interior-floors {
+svg.hi-location-view-svg path.interior-floors {
fill: #f8f8f8;
stroke: none;
stroke-width: 1;
}
-svg.hi-location-view path.floor-transitions {
+svg.hi-location-view-svg path.floor-transitions {
fill: none;
stroke: #404040;
stroke-width: 1;
stroke-dasharray: 10, 10;
}
-svg.hi-location-view path.stairs {
+svg.hi-location-view-svg path.stairs {
fill: none;
stroke: black;
stroke-width: 1;
}
-svg.hi-location-view path.ceiling-transitions {
+svg.hi-location-view-svg path.ceiling-transitions {
fill: none;
stroke: #404040;
stroke-width: 1;
stroke-dasharray: 5, 5;
}
-svg.hi-location-view path.interior-walls {
+svg.hi-location-view-svg path.interior-walls {
fill: black;
stroke: black;
stroke-width: 1;
}
-svg.hi-location-view path.secondary-walls {
+svg.hi-location-view-svg path.secondary-walls {
fill: #a0a0a0;
stroke: #a0a0a0;
stroke-width: 1;
}
-svg.hi-location-view path.windows {
+svg.hi-location-view-svg path.windows {
fill: #e0e0e0;
stroke: black;
stroke-width: 1;
}
-svg.hi-location-view path.exterior-walls {
+svg.hi-location-view-svg path.exterior-walls {
fill: black;
stroke: black;
stroke-width: 1;
}
-svg.hi-location-view path.door-arcs {
+svg.hi-location-view-svg path.door-arcs {
fill: none;
stroke: black;
stroke-width: 1;
}
-svg.hi-location-view path.doors {
+svg.hi-location-view-svg path.doors {
fill: none;
stroke: black;
stroke-width: 3;
}
-svg.hi-location-view path.countertops {
+svg.hi-location-view-svg path.countertops {
fill: #e0e0e0;
stroke: black;
stroke-width: 1;
}
-svg.hi-location-view path.fireplaces {
+svg.hi-location-view-svg path.fireplaces {
fill: #fff0f0;
stroke: black;
stroke-width: 1;
}
-svg.hi-location-view path.furniture {
+svg.hi-location-view-svg path.furniture {
fill: #e0e0e0;
stroke: black;
stroke-width: 1;
}
-svg.hi-location-view path.toilets {
+svg.hi-location-view-svg path.toilets {
fill: #e0e0e0;
stroke: black;
stroke-width: 1;
}
-svg.hi-location-view path.shelves {
+svg.hi-location-view-svg path.shelves {
fill: #fffff0;
stroke: black;
stroke-width: 1;
}
-svg.hi-location-view path.bathtubs {
+svg.hi-location-view-svg path.bathtubs {
fill: #f8f8f8;
stroke: black;
stroke-width: 1;
}
-svg.hi-location-view path.sinks {
+svg.hi-location-view-svg path.sinks {
fill: #f8f8f8;
stroke: black;
stroke-width: 1;
diff --git a/src/hi/static/js/main.js b/src/hi/static/js/main.js
index cb75ff71..ccf8c16c 100644
--- a/src/hi/static/js/main.js
+++ b/src/hi/static/js/main.js
@@ -5,8 +5,8 @@
DEBUG: true,
isEditMode: ( gHiViewMode == 'edit' ), // Set by server to keep front-end in sync with back-end
LOCATION_VIEW_AREA_SELECTOR: '#hi-location-view-main',
- LOCATION_VIEW_SVG_CLASS: 'hi-location-view',
- LOCATION_VIEW_SVG_SELECTOR: '.hi-location-view',
+ LOCATION_VIEW_SVG_CLASS: 'hi-location-view-svg',
+ LOCATION_VIEW_SVG_SELECTOR: '.hi-location-view-svg',
LOCATION_VIEW_BASE_SELECTOR: '.hi-location-view-base',
BASE_SVG_SELECTOR: '#hi-location-view-main > svg',
HIGHLIGHTED_CLASS: 'highlighted',
@@ -52,6 +52,9 @@
getSvgViewBox: function( svgElement ) {
return _getSvgViewBox( svgElement );
},
+ setSvgViewBox: function( svgElement, newX, newY, newWidth, newHeight ) {
+ return _setSvgViewBox( svgElement, newX, newY, newWidth, newHeight );
+ },
getExtentsSvgViewBox: function( svgElement ) {
return _getExtentsSvgViewBox( svgElement );
},
@@ -209,24 +212,63 @@
let y = null;
let width = null;
let height = null;
-
+
if (svgElement.length < 1 ) {
- return { x, y, width, height };
+ return { x: x, y: y, width: width, height: height };
}
- let viewBoxValue = $(svgElement).attr( attrName );
- if ( ! viewBoxValue) {
- return { x, y, width, height };
+ let viewBoxValueJquery = $(svgElement).attr( attrName );
+ let viewBoxValue = $(svgElement)[0].getAttribute( attrName );
+
+ if ( viewBoxValue != viewBoxValueJquery ) {
+ console.warning( `Inconsistent SVG viewBox: jQuery=${viewBoxValueJquery}, DOM=${viewBoxValue}` );
+ }
+
+ if ( viewBoxValue === null || viewBoxValue === undefined ) {
+ console.error( "No viewBox value found.", svgElement );
+ return { x: x, y: y, width: width, height: height };
}
let viewBoxArray = viewBoxValue.split(' ').map(Number);
+
+ if (viewBoxArray.length !== 4 || viewBoxArray.some(isNaN)) {
+ console.error( `Invalid viewBox attribute: ${viewBoxValue}`, svgElement );
+ return { x: x, y: y, width: width, height: height };
+ }
+
x = viewBoxArray[0];
y = viewBoxArray[1];
width = viewBoxArray[2];
height = viewBoxArray[3];
- return { x, y, width, height };
+ return { x: x, y: y, width: width, height: height };
}
+ function _setSvgViewBox( svgElement, newX, newY, newWidth, newHeight ) {
+ if ( $(svgElement).length < 1 ) {
+ console.error("SVG element is null or undefined.");
+ return;
+ }
+ if ( typeof newX !== 'number' || isNaN(newX)) {
+ console.error("newX is not a valid number:", newX);
+ return;
+ }
+ if ( typeof newY !== 'number' || isNaN(newY)) {
+ console.error("newY is not a valid number:", newY);
+ return;
+ }
+ if ( typeof newWidth !== 'number' || isNaN(newWidth) || newWidth <= 0) {
+ console.error("newWidth is not a valid positive number:", newWidth);
+ return;
+ }
+ if ( typeof newHeight !== 'number' || isNaN(newHeight) || newHeight <= 0) {
+ console.error("newHeight is not a valid positive number:", newHeight);
+ return;
+ }
+
+ const svgViewBoxStr = `${newX} ${newY} ${newWidth} ${newHeight}`;
+ $(svgElement).attr('viewBox', svgViewBoxStr );
+ }
+
function _getExtentsSvgViewBox( svgElement ) {
// Hi-specific attribute used for pan, zoom and edit operations.
return _getSvgViewBox( svgElement, 'extents' );
@@ -348,9 +390,9 @@
let svgStr = 'Not an SVG';
if ( elementTag == 'svg' ) {
- let { x, y, width, height } = _getSvgViewBox( element );
+ let viewBox = _getSvgViewBox( element );
if ( x != null ) {
- svgStr = `Viewbox: ( ${x}, ${y}, ${width}, ${height} )`;
+ svgStr = `Viewbox: ( ${viewBox.x}, ${viewBox.y}, ${viewBox.width}, ${viewBox.height} )`;
} else {
svgStr = 'No viewbox attribute';
}
diff --git a/src/hi/static/js/svg-location.js b/src/hi/static/js/svg-location.js
index 98a57998..ec4f9f92 100644
--- a/src/hi/static/js/svg-location.js
+++ b/src/hi/static/js/svg-location.js
@@ -476,10 +476,9 @@
newY = extentsSvgViewBox.y + extentsSvgViewBox.height - newHeight;
}
- let svgViewBoxStr = `${newX} ${newY} ${newWidth} ${newHeight}`;
- $(gSelectedLocationViewSvg).attr('viewBox', svgViewBoxStr );
+ Hi.setSvgViewBox( gSelectedLocationViewSvg, newX, newY, newWidth, newHeight );
}
-
+
function calculateRotatedRectangle( initialRect, rotationAngle ) {
let corners = [
diff --git a/src/hi/static/js/svg-utils.js b/src/hi/static/js/svg-utils.js
index 654c67e7..756fde0f 100644
--- a/src/hi/static/js/svg-utils.js
+++ b/src/hi/static/js/svg-utils.js
@@ -16,17 +16,14 @@
const $baseSvg = $('#' + htmlId + ' svg' );
const bbox = $baseSvg[0].getBoundingClientRect();
+ const viewBox = Hi.getSvgViewBox( $baseSvg );
- const viewBox = $baseSvg.attr('viewBox').split(' ').map(Number);
- const viewBoxWidth = viewBox[2];
- const viewBoxHeight = viewBox[3];
-
- const scaleX = bbox.width / viewBoxWidth;
- const scaleY = bbox.height / viewBoxHeight;
+ const scaleX = bbox.width / viewBox.width;
+ const scaleY = bbox.height / viewBox.height;
return {
htmlBoundingBox : bbox,
- svgViewBox : { x: viewBox[0], y: viewBox[1], width: viewBox[2], height: viewBox[3] },
+ svgViewBox : viewBox,
scaleX : scaleX,
scaleY : scaleY
};