Skip to content

Home Information - Your home, your data, organized.

Python

Working on location view pan, zoom, rotate. WIP

Anthony Cassandra56c9b713a558
diff --git a/src/hi/apps/collection/templates/collection/collection_buttons.html b/src/hi/apps/collection/templates/collection/collection_buttons.html
index c046a094..c6089998 100644
--- a/src/hi/apps/collection/templates/collection/collection_buttons.html
+++ b/src/hi/apps/collection/templates/collection/collection_buttons.html
@@ -1,6 +1,6 @@
<div class="d-flex justify-content-start draggable-container">
{% for collection in collection_list %}
- <div class="col-1 {% if request.is_editing %}draggable{% endif %}"
+ <div class="{% if request.is_editing %}draggable{% endif %}"
{% if request.is_editing %}draggable="true"{% endif %}
data-id="{{ collection.html_id }}">
<a href="{% url 'collection_view' id=collection.id %}"
@@ -12,7 +12,7 @@
</div>
{% endfor %}
{% if request.is_editing %}
- <div class="col-1">
+ <div class="">
<a href="{% url 'collection_edit_collection_add' %}"
class="btn btn-success btn-control" role="button"
data-async="modal" >
diff --git a/src/hi/apps/collection/views.py b/src/hi/apps/collection/views.py
index 76748f43..bd18c41b 100644
--- a/src/hi/apps/collection/views.py
+++ b/src/hi/apps/collection/views.py
@@ -54,6 +54,7 @@ class CollectionView( HiGridView ):
return bad_request_response( request, message = message )
# Remember last collection chosen
+ view_type_changed = bool( request.view_parameters.view_type != ViewType.COLLECTION )
request.view_parameters.view_type = ViewType.COLLECTION
request.view_parameters.collection_id = collection.id
request.view_parameters.to_session( request )
@@ -63,7 +64,7 @@ class CollectionView( HiGridView ):
# views are invalidated. Else, the editing state and edit side
# panel will be invalid for the new view.
#
- if is_ajax( request ) and request.view_parameters.view_mode.should_reload_on_view_change:
+ if view_type_changed and is_ajax( request ):
sync_url = reverse( 'collection_view', kwargs = kwargs )
return antinode.redirect_response( url = sync_url )
diff --git a/src/hi/apps/config/views.py b/src/hi/apps/config/views.py
index 00aa3414..63614cbf 100644
--- a/src/hi/apps/config/views.py
+++ b/src/hi/apps/config/views.py
@@ -1,3 +1,8 @@
+from django.urls import reverse
+
+import hi.apps.common.antinode as antinode
+from hi.apps.common.utils import is_ajax
+from hi.enums import ViewMode, ViewType
from hi.hi_grid_view import HiGridView
from hi.integrations.core.views import IntegrationViewMixin
@@ -6,6 +11,15 @@ class ConfigHomePaneView( HiGridView, IntegrationViewMixin ):
def get(self, request, *args, **kwargs):
+ view_type_changed = bool( request.view_parameters.view_type != ViewType.CONFIGURATION )
+ request.view_parameters.view_type = ViewType.CONFIGURATION
+ request.view_parameters.view_mode = ViewMode.MONITOR
+ request.view_parameters.to_session( request )
+
+ if view_type_changed and is_ajax( request ):
+ sync_url = reverse('config_home_pane')
+ return antinode.redirect_response( url = sync_url )
+
context = {
}
context.update( self.get_integration_config_tab_context() )
diff --git a/src/hi/apps/edit/templates/edit/panes/side.html b/src/hi/apps/edit/templates/edit/panes/side.html
index 04263842..f3486722 100644
--- a/src/hi/apps/edit/templates/edit/panes/side.html
+++ b/src/hi/apps/edit/templates/edit/panes/side.html
@@ -1,12 +1,6 @@
<div id="hi-edit-side-content" class="">
<div class="">EDIT PANEL</div>
- <div class="">
- <a href="{% url 'edit_end' %}"
- class="btn btn-tertiary btn-control" role="button" >
- EXIT EDITING
- </a>
- </div>
<div class="">
<a href="{% url 'edit_add_remove' %}"
diff --git a/src/hi/apps/edit/views.py b/src/hi/apps/edit/views.py
index ae9f06f9..2ec2a344 100644
--- a/src/hi/apps/edit/views.py
+++ b/src/hi/apps/edit/views.py
@@ -58,9 +58,6 @@ class EditStartView( View ):
# Javascript handling is consistent with the current operating
# state mode.
- if request.view_parameters.view_mode.is_editing:
- return bad_request_response( request, message = 'Edit mode already started.' )
-
request.view_parameters.view_mode = ViewMode.EDIT
request.view_parameters.to_session( request )
diff --git a/src/hi/apps/location/templates/location/location_view_buttons.html b/src/hi/apps/location/templates/location/location_view_buttons.html
index 6af74a66..ef2a3959 100644
--- a/src/hi/apps/location/templates/location/location_view_buttons.html
+++ b/src/hi/apps/location/templates/location/location_view_buttons.html
@@ -1,6 +1,6 @@
<div class="d-flex justify-content-start draggable-container">
{% for location_view in location_view_list %}
- <div class="col-1 {% if request.is_editing %}draggable{% endif %}"
+ <div class="{% if request.is_editing %}draggable{% endif %}"
{% if request.is_editing %}draggable="true"{% endif %}
data-id="{{ location_view.html_id }}" >
<a href="{% url 'location_view' id=location_view.id %}"
@@ -12,7 +12,7 @@
</div>
{% endfor %}
{% if request.is_editing %}
- <div class="col-1">
+ <div class="">
<a href="{% url 'location_edit_location_view_add' %}"
class="btn btn-success btn-control" role="button"
data-async="modal" >
diff --git a/src/hi/apps/location/views.py b/src/hi/apps/location/views.py
index 46a636bb..ffd35cf9 100644
--- a/src/hi/apps/location/views.py
+++ b/src/hi/apps/location/views.py
@@ -8,7 +8,7 @@ import hi.apps.common.antinode as antinode
from hi.apps.common.utils import is_ajax
from hi.enums import ViewType
from hi.hi_grid_view import HiGridView
-from hi.views import bad_request_response
+from hi.views import bad_request_response, page_not_found_response
from .location_view_manager import LocationViewManager
from .models import Location, LocationView
@@ -54,11 +54,10 @@ class LocationViewView( HiGridView ):
location_view = LocationView.objects.select_related(
'location' ).get( id = location_view_id )
except LocationView.DoesNotExist:
- message = f'Location view "{location_view_id}" does not exist.'
- logger.warning( message )
- return bad_request_response( request, message = message )
+ return page_not_found_response( request )
# Remember last location view chosen
+ view_type_changed = bool( request.view_parameters.view_type != ViewType.LOCATION_VIEW )
request.view_parameters.view_type = ViewType.LOCATION_VIEW
request.view_parameters.location_view_id = location_view.id
request.view_parameters.to_session( request )
@@ -68,7 +67,7 @@ class LocationViewView( HiGridView ):
# views are invalidated. Else, the editing state and edit side
# panel will be invalid for the new view.
#
- if is_ajax( request ) and request.view_parameters.view_mode.should_reload_on_view_change:
+ if view_type_changed and is_ajax( request ):
sync_url = reverse( 'location_view', kwargs = kwargs )
return antinode.redirect_response( url = sync_url )
@@ -86,3 +85,69 @@ class LocationViewView( HiGridView ):
push_url_name = 'location_view',
push_url_kwargs = kwargs,
)
+
+
+class LocationViewPanZoomRotateView( HiGridView ):
+
+ def get(self, request, *args, **kwargs):
+
+ location_view_id = kwargs.get('id')
+ try:
+ location_view = LocationView.objects.select_related(
+ 'location' ).get( id = location_view_id )
+ except LocationView.DoesNotExist:
+ return page_not_found_response( request )
+
+ action = zzz
+ if not action:
+ return bad_request_response( request, message = 'Missing action param.' )
+
+ svg_view_box = zzz
+ svg_rotate = zzz
+
+ if not svg_view_box:
+ svg_view_box = location_view.svg_view_box
+ svg_rotate = location_view.svg_rotate
+
+ pan_factor = 0.1
+ zoom_factor = 0.1
+ rotate_angle = 9
+
+ if action == 'pan-left':
+ new_x = svg_view_box.x - ( pan_factor * svg_view_box.width )
+ elif action == 'pan-right':
+ new_x = svg_view_box.x + ( pan_factor * svg_view_box.width )
+ elif action == 'pan-up':
+ new_y = svg_view_box.y - ( pan_factor * svg_view_box.height )
+ elif action == 'pan-down':
+ new_y = svg_view_box.y + ( pan_factor * svg_view_box.height )
+ elif action == 'zoom-in':
+ new_width = zoom_factor * svg_view_box.width
+ new_height = zoom_factor * svg_view_box.height
+ elif action == 'zoom-out':
+ new_width = ( 1.0 + zoom_factor ) * svg_view_box.width
+ new_height = ( 1.0 * zoom_factor ) * svg_view_box.height
+ elif action == 'rotate-clockwise':
+ new_rotate = float(svg_rotate) - rotate_angle
+ elif action == 'rotate-counterclockwise':
+ new_rotate = float(svg_rotate) + rotate_angle
+
+
+
+ # zzz norm angle to 0-360
+ # zzz limit on zoom
+ # zzz limit on pan
+
+ context = {
+ 'svg_view_box_override': svg_view_box,
+ 'svg_rotate_override': svg_rotate,
+ }
+
+ return self.hi_grid_response(
+ request = request,
+ context = context,
+ main_template_name = 'location/location_view.html',
+ push_url_name = 'location_view',
+ push_url_kwargs = kwargs,
+ )
+
diff --git a/src/hi/enums.py b/src/hi/enums.py
index 99fcfc9e..f0258d75 100644
--- a/src/hi/enums.py
+++ b/src/hi/enums.py
@@ -5,6 +5,7 @@ class ViewType(LabeledEnum):
LOCATION_VIEW = ('Location View', '' )
COLLECTION = ('Collection', '' )
+ CONFIGURATION = ('Configuration', '' )
@property
def is_location_view(self):
@@ -14,6 +15,15 @@ class ViewType(LabeledEnum):
def is_collection(self):
return bool( self == ViewType.COLLECTION )
+ @property
+ def is_configuration(self):
+ return bool( self == ViewType.CONFIGURATION )
+
+ @property
+ def allows_edit_mode(self):
+ return bool( self in [ ViewType.LOCATION_VIEW,
+ ViewType.COLLECTION ] )
+
class ViewMode(LabeledEnum):
@@ -23,8 +33,3 @@ class ViewMode(LabeledEnum):
@property
def is_editing(self):
return bool( self == ViewMode.EDIT )
-
- @property
- def should_reload_on_view_change(self):
- return bool( self == ViewMode.EDIT )
-
diff --git a/src/hi/settings/base.py b/src/hi/settings/base.py
index 816885d5..c4139932 100644
--- a/src/hi/settings/base.py
+++ b/src/hi/settings/base.py
@@ -286,6 +286,7 @@ PIPELINE = {
'js/edit-dragdrop.js',
'js/edit-svg-icon.js',
'js/edit-svg-path.js',
+ 'js/svg-location.js', # Should come last: edit event handlers should be registered first.
),
'output_filename': 'js/js_after_content_custom.js',
}
diff --git a/src/hi/static/js/edit-svg-icon.js b/src/hi/static/js/edit-svg-icon.js
index aaf2a1e7..0bfa8242 100644
--- a/src/hi/static/js/edit-svg-icon.js
+++ b/src/hi/static/js/edit-svg-icon.js
@@ -31,13 +31,10 @@
const SELECTABLE_CLASS = 'selectable';
const SELECTABLE_SELECTOR = '.' + SELECTABLE_CLASS;
- const ICON_ACTION_STATE_ATTR_NAME = 'action-state';
const ICON_ACTION_SCALE_KEY = 's';
const ICON_ACTION_ROTATE_KEY = 'r';
- const CLICK_HOLD_THRESHOLD_MS = 50; // For ignoreing very short, transient clicks
- const DOUBLE_CLICK_DELAY_MS = 250;
- const CURSOR_MOVEMENT_THRESHOLD_PIXELS = 3;
+ const CURSOR_MOVEMENT_THRESHOLD_PIXELS = 3; // Differentiate between move events and sloppy clicks
const API_EDIT_SVG_POSITION_URL = '/edit/svg/position';
@@ -53,37 +50,35 @@
let gSvgIconEditData = null;
let gClickStart = null;
- let gClickTimeout = null;
let gLastMousePosition = { x: 0, y: 0 };
- let gIgnoreCLick = false; // Set by mouseup handling when non-click actions are needed
-
-
+ let gIgnoreCLick = false; // Set by mouseup handling when no click handling should be done
+
$(document).ready(function() {
$(document).on('mousedown', Hi.LOCATION_VIEW_AREA_SELECTOR, function(event) {
- if ( gHiViewMode != 'edit' ) { return; }
+ if ( ! Hi.isEditMode ) { return; }
handleMouseDown( event );
});
$(document).on('mousemove', Hi.LOCATION_VIEW_AREA_SELECTOR, function(event) {
- if ( gHiViewMode != 'edit' ) { return; }
+ if ( ! Hi.isEditMode ) { return; }
handleMouseMove( event );
});
$(document).on('mouseup', Hi.LOCATION_VIEW_AREA_SELECTOR, function(event) {
- if ( gHiViewMode != 'edit' ) { return; }
+ if ( ! Hi.isEditMode ) { return; }
handleMouseUp( event );
});
$(document).on('click', function(event) {
- if ( gHiViewMode != 'edit' ) { return; }
+ if ( ! Hi.isEditMode ) { return; }
handleClick( event );
});
$(document).on('keydown', function(event) {
- if ( gHiViewMode != 'edit' ) { return; }
+ if ( ! Hi.isEditMode ) { return; }
handleKeyDown( event );
});
});
function handleMouseDown( event ) {
- if ( Hi.DEBUG ) { Hi.displayEventInfo( `Mouse down event [${MODULE_NAME}]`, event ); }
+ if ( Hi.DEBUG ) { console.log( `Mouse down event [${MODULE_NAME}]`, event ); }
// Need to track start time to differentiate drag/scale/rotate actions from regular clicks.
gClickStart = {
@@ -99,6 +94,7 @@
gSvgIconEditData.isRotating = true;
}
event.preventDefault();
+ event.stopImmediatePropagation();
return;
} else {
if ( Hi.DEBUG ) { Hi.displayElementInfo( 'Event target: ', $(event.target) ); }
@@ -108,6 +104,7 @@
if ( svgDataType == Hi.DATA_TYPE_ICON_VALUE ) {
createIconDragData( event, enclosingSvgGroup );
event.preventDefault();
+ event.stopImmediatePropagation();
return;
}
}
@@ -116,16 +113,17 @@
}
function handleMouseUp( event ) {
- if ( Hi.DEBUG ) { Hi.displayEventInfo( `Mouse up event [${MODULE_NAME}]`, event ); }
+ if ( Hi.DEBUG ) { console.log( `Mouse up event [${MODULE_NAME}]`, event ); }
if ( gSvgIconDragData ) {
if ( gSvgIconDragData.isDragging ) {
endDrag( event );
- $(Hi.BASE_SVG_SELECTOR).attr( ICON_ACTION_STATE_ATTR_NAME, '');
+ $(Hi.BASE_SVG_SELECTOR).attr( Hi.SVG_ACTION_STATE_ATTR_NAME, '');
}
- $(Hi.BASE_SVG_SELECTOR).attr( ICON_ACTION_STATE_ATTR_NAME, '' );
+ $(Hi.BASE_SVG_SELECTOR).attr( Hi.SVG_ACTION_STATE_ATTR_NAME, '' );
gSvgIconDragData = null;
event.preventDefault();
+ event.stopImmediatePropagation();
return;
}
@@ -138,10 +136,11 @@
iconActionRotateApply();
}
gSvgIconActionState = SvgActionStateType.MOVE;
- $(Hi.BASE_SVG_SELECTOR).attr( ICON_ACTION_STATE_ATTR_NAME, '');
+ $(Hi.BASE_SVG_SELECTOR).attr( Hi.SVG_ACTION_STATE_ATTR_NAME, '');
gSvgIconEditData = null;
gIgnoreCLick = true;
event.preventDefault();
+ event.stopImmediatePropagation();
return;
}
if ( Hi.DEBUG ) { console.log( `Mouse up skipped [${MODULE_NAME}]` ); }
@@ -162,19 +161,20 @@
|| ( distanceX > CURSOR_MOVEMENT_THRESHOLD_PIXELS )
|| ( distanceY > CURSOR_MOVEMENT_THRESHOLD_PIXELS )) {
gSvgIconDragData.isDragging = true;
- $(Hi.BASE_SVG_SELECTOR).attr( ICON_ACTION_STATE_ATTR_NAME, SvgActionStateType.MOVE);
+ $(Hi.BASE_SVG_SELECTOR).attr( Hi.SVG_ACTION_STATE_ATTR_NAME, SvgActionStateType.MOVE);
updateDrag(event);
event.preventDefault();
+ event.stopImmediatePropagation();
}
}
else if ( gSvgIconEditData ) {
if ( gSvgIconEditData.isScaling ) {
iconActionScaleUpdate( currentMousePosition );
- event.preventDefault();
} else if ( gSvgIconEditData.isRotating ) {
iconActionRotateUpdate( currentMousePosition );
- event.preventDefault();
}
+ event.preventDefault();
+ event.stopImmediatePropagation();
}
gLastMousePosition = currentMousePosition;
@@ -184,7 +184,8 @@
if ( gIgnoreCLick ) {
if ( Hi.DEBUG ) { console.log( `Ignoring click [${MODULE_NAME}]`, event ); }
gIgnoreCLick = false;
- event.preventDefault();
+ event.preventDefault();
+ event.stopImmediatePropagation();
return;
}
gIgnoreCLick = false;
@@ -203,6 +204,7 @@
if ( isSvgIcon && svgItemId ) {
handleSvgIconClick( event, enclosingSvgGroup );
event.preventDefault();
+ event.stopImmediatePropagation();
return;
}
}
@@ -214,8 +216,10 @@
return;
}
if ( gSelectedIconSvgGroup ) {
+ if ( Hi.DEBUG ) { console.log( `Key Down [${MODULE_NAME}]`, event ); }
handleSvgIconSelectedKeyDown( event );
event.preventDefault();
+ event.stopImmediatePropagation();
return;
}
if ( Hi.DEBUG ) { console.log( `Key down skipped [${MODULE_NAME}]` ); }
@@ -227,10 +231,10 @@
const targetWidth = targetArea.outerWidth();
const targetHeight = targetArea.outerHeight();
- if (gLastMousePosition.x >= targetOffset.left &&
- gLastMousePosition.x <= targetOffset.left + targetWidth &&
- gLastMousePosition.y >= targetOffset.top &&
- gLastMousePosition.y <= targetOffset.top + targetHeight) {
+ if (( gLastMousePosition.x >= targetOffset.left )
+ && ( gLastMousePosition.x <= ( targetOffset.left + targetWidth ))
+ && ( gLastMousePosition.y >= targetOffset.top )
+ && ( gLastMousePosition.y <= ( targetOffset.top + targetHeight ))) {
if ( Hi.DEBUG ) { Hi.displayEventInfo( 'Key Down', event ); }
@@ -246,14 +250,14 @@
iconActionScaleAbort();
iconActionRotateAbort();
gSvgIconActionState = SvgActionStateType.MOVE;
- $(Hi.BASE_SVG_SELECTOR).attr( ICON_ACTION_STATE_ATTR_NAME, '');
+ $(Hi.BASE_SVG_SELECTOR).attr( Hi.SVG_ACTION_STATE_ATTR_NAME, '');
} else {
return;
}
- event.stopPropagation();
event.preventDefault();
+ event.stopImmediatePropagation();
}
}
@@ -283,7 +287,7 @@
Hi.displayElementInfo( 'Base SVG', baseSvgElement );
let transform = dragElement.attr('transform') || '';
- let { scale, translate, rotate } = getSvgTransformValues( transform );
+ let { scale, translate, rotate } = Hi.getSvgTransformValues( transform );
let cursorSvgPoint = Hi.toSvgPoint( baseSvgElement, event.clientX, event.clientY );
const cursorSvgOffset = {
@@ -295,7 +299,7 @@
element: dragElement,
baseSvgElement: baseSvgElement,
cursorSvgOffset: cursorSvgOffset,
- elementSvgCenterPoint: getSvgCenterPoint( dragElement, baseSvgElement ),
+ elementSvgCenterPoint: Hi.getSvgCenterPoint( dragElement, baseSvgElement ),
originalSvgScale: scale,
originalSvgRotate: rotate,
isDragging: false
@@ -331,7 +335,8 @@
gSvgIconDragData.element.attr('transform', newTransform);
- gSvgIconDragData.elementSvgCenterPoint = getSvgCenterPoint( gSvgIconDragData.element, gSvgIconDragData.baseSvgElement );
+ gSvgIconDragData.elementSvgCenterPoint = Hi.getSvgCenterPoint( gSvgIconDragData.element,
+ gSvgIconDragData.baseSvgElement );
if ( Hi.DEBUG ) {
console.log( `Drag Update:
@@ -365,10 +370,10 @@
function saveIconSvgPosition( element ) {
let transform = element.attr('transform');
- let { scale, translate, rotate } = getSvgTransformValues( transform );
+ let { scale, translate, rotate } = Hi.getSvgTransformValues( transform );
const baseSvgElement = $(Hi.BASE_SVG_SELECTOR);
- const center = getSvgCenterPoint( element, baseSvgElement );
+ const center = Hi.getSvgCenterPoint( element, baseSvgElement );
let svgItemId = element.attr('id');
let data = {
@@ -383,7 +388,7 @@
function createIconEditActionData( actionState ) {
if ( gSelectedIconSvgGroup ) {
let transform = gSelectedIconSvgGroup.attr('transform');
- let { scale, translate, rotate } = getSvgTransformValues( transform );
+ let { scale, translate, rotate } = Hi.getSvgTransformValues( transform );
gSvgIconEditData = {
element: gSelectedIconSvgGroup,
@@ -395,7 +400,7 @@
};
gSvgIconActionState = actionState;
- $(Hi.BASE_SVG_SELECTOR).attr( ICON_ACTION_STATE_ATTR_NAME, actionState );
+ $(Hi.BASE_SVG_SELECTOR).attr( Hi.SVG_ACTION_STATE_ATTR_NAME, actionState );
}
}
@@ -414,14 +419,15 @@
}
function iconActionScaleUpdate( currentMousePosition ) {
+ if ( Hi.DEBUG ) { console.log( `updateScale [${MODULE_NAME}]` ); }
- let center = getScreenCenterPoint( gSvgIconEditData.element );
+ let center = Hi.getScreenCenterPoint( gSvgIconEditData.element );
let scaleFactor = getScaleFactor( center.x, center.y,
gLastMousePosition.x, gLastMousePosition.y,
currentMousePosition.x, currentMousePosition.y );
let transform = gSvgIconEditData.element.attr('transform');
- let { scale, translate, rotate } = getSvgTransformValues( transform );
+ let { scale, translate, rotate } = Hi.getSvgTransformValues( transform );
const newScale = {
x: scale.x * scaleFactor,
@@ -458,46 +464,20 @@
}
function iconActionRotateUpdate( currentMousePosition ) {
- if ( Hi.DEBUG ) { console.log( 'Rotate Update' ); }
+ if ( Hi.DEBUG ) { console.log( `updateRotation [${MODULE_NAME}]` ); }
- let center = getScreenCenterPoint( gSvgIconEditData.element );
+ let center = Hi.getScreenCenterPoint( gSvgIconEditData.element );
- let deltaAngle = getIconRotationAngle( center.x, center.y,
- gLastMousePosition.x, gLastMousePosition.y,
- currentMousePosition.x, currentMousePosition.y );
+ let deltaAngle = Hi.getRotationAngle( center.x, center.y,
+ gLastMousePosition.x, gLastMousePosition.y,
+ currentMousePosition.x, currentMousePosition.y );
let transform = gSvgIconEditData.element.attr('transform');
- let { scale, translate, rotate } = getSvgTransformValues( transform );
+ let { scale, translate, rotate } = Hi.getSvgTransformValues( transform );
rotate.angle += deltaAngle;
- rotate.angle = normalizeAngle( rotate.angle );
+ rotate.angle = Hi.normalizeAngle( rotate.angle );
setSvgTransformAttr( gSvgIconEditData.element, scale, translate, rotate );
}
-
- function getIconRotationAngle( centerX, centerY, startX, startY, endX, endY ) {
-
- const startVectorX = startX - centerX;
- const startVectorY = startY - centerY;
-
- const endVectorX = endX - centerX;
- const endVectorY = endY - centerY;
-
- const startAngle = Math.atan2(startVectorY, startVectorX);
- const endAngle = Math.atan2(endVectorY, endVectorX);
-
- let angleDifference = endAngle - startAngle;
-
- // Normalize the angle to be between -π and π
- if (angleDifference > Math.PI) {
- angleDifference -= 2 * Math.PI;
- } else if (angleDifference < -Math.PI) {
- angleDifference += 2 * Math.PI;
- }
-
- const angleDifferenceDegrees = angleDifference * (180 / Math.PI);
-
- return angleDifferenceDegrees;
- }
-
function iconActionRotateApply() {
saveIconSvgPosition( gSvgIconEditData.element );
@@ -510,83 +490,6 @@
revertIconAction();
}
- function getScreenCenterPoint( element ) {
- try {
- let rect = element[0].getBoundingClientRect();
- if ( rect ) {
- const screenCenterX = rect.left + ( rect.width / 2.0 );
- const screenCenterY = rect.top + ( rect.height / 2.0 );
- return {
- x: rect.left + ( rect.width / 2.0 ),
- y: rect.top + ( rect.height / 2.0 )
- };
- }
- } catch (e) {
- console.debug( `Problem getting bounding box: ${e}` );
- }
- return null;
- }
-
- function getSvgCenterPoint( element, svgElement ) {
-
- try {
- let rect = element[0].getBoundingClientRect();
- if ( rect ) {
- const screenCenterX = rect.left + ( rect.width / 2.0 );
- const screenCenterY = rect.top + ( rect.height / 2.0 );
- return Hi.toSvgPoint( svgElement, screenCenterX, screenCenterY );
- }
- } catch (e) {
- console.debug( `Problem getting bounding box: ${e}` );
- }
- return { x: 0, y: 0 };
- }
-
- function getSvgTransformValues(transform) {
- let scale = { x: 1, y: 1 }, rotate = { angle: 0, cx: 0, cy: 0 }, translate = { x: 0, y: 0 };
-
- let scaleMatch = transform.match(/scale\(([^)]+)\)/);
- if (scaleMatch) {
- let scaleValues = scaleMatch[1].trim().split(/[ ,]+/).map(parseFloat);
- scale.x = scaleValues[0];
- if ( scaleValues.length == 1 ) {
- scale.y = scale.x;
- } else {
- scale.y = scaleValues[1];
- }
- }
-
- let translateMatch = transform.match(/translate\(([^)]+)\)/);
- if (translateMatch) {
- let [x, y] = translateMatch[1].trim().split(/[ ,]+/).map(parseFloat);
- translate.x = x;
- translate.y = y;
- }
-
- let rotateMatch = transform.match(/rotate\(([^)]+)\)/);
- if (rotateMatch) {
- let rotateValues = rotateMatch[1].trim().split(/[ ,]+/).map(parseFloat);
- rotate.angle = rotateValues[0];
-
- // Check if cx and cy are provided
- if (rotateValues.length === 3) {
- rotate.cx = rotateValues[1];
- rotate.cy = rotateValues[2];
- } else {
- rotate.cx = 0;
- rotate.cy = 0;
- }
- }
-
- if ( Hi.DEBUG ) {
- console.log( `TRANSFORM:
- Raw: ${transform},
- Parsed: scale=${JSON.stringify(scale)} translate=${JSON.stringify(translate)} rotate=${JSON.stringify(rotate)}` );
- }
-
- return { scale, translate, rotate };
- }
-
function setSvgTransformAttr( element, scale, translate, rotate ) {
let newTransform = `scale(${scale.x} ${scale.y}) translate(${translate.x}, ${translate.y}) rotate(${rotate.angle}, ${rotate.cx}, ${rotate.cy})`;
element.attr('transform', newTransform);
@@ -606,10 +509,4 @@
return scaleFactor;
}
- function normalizeAngle(angle) {
- return (angle % 360 + 360) % 360;
- }
-
-
-
})();
diff --git a/src/hi/static/js/edit-svg-path.js b/src/hi/static/js/edit-svg-path.js
index e57386c1..2760f6d9 100644
--- a/src/hi/static/js/edit-svg-path.js
+++ b/src/hi/static/js/edit-svg-path.js
@@ -73,12 +73,12 @@
27 // Escape
];
+ const CURSOR_MOVEMENT_THRESHOLD_PIXELS = 3; // Differentiate between move events and sloppy clicks
const PATH_EDIT_PROXY_POINT_RADIUS_PIXELS = 12;
const PATH_EDIT_PROXY_LINE_WIDTH_PIXELS = 5;
const PATH_EDIT_NEW_PATH_RADIUS_PERCENT = 5; // Preferrable if this matches server new path sizing.
const PATH_EDIT_PROXY_LINE_COLOR = 'red';
const PATH_EDIT_PROXY_POINT_COLOR = 'red';
- const CURSOR_MOVEMENT_THRESHOLD_PIXELS = 3;
const API_EDIT_SVG_PATH_URL = '/edit/svg/path';
@@ -89,16 +89,16 @@
let gSelectedPathSvgGroup = null;
let gSvgPathEditData = null;
- let gIgnoreCLick = false; // Set by mouseup handling when non-click actions are needed
+ let gIgnoreCLick = false; // Set by mouseup handling when no click handling should be done
$(document).ready(function() {
$(document).on('click', function(event) {
- if ( gHiViewMode != 'edit' ) { return; }
+ if ( ! Hi.isEditMode ) { return; }
handleClick( event );
});
$(document).on('keydown', function(event) {
- if ( gHiViewMode != 'edit' ) { return; }
+ if ( ! Hi.isEditMode ) { return; }
handleKeyDown( event );
});
});
@@ -108,6 +108,7 @@
if ( Hi.DEBUG ) { console.log( `Ignoring click [${MODULE_NAME}]`, event ); }
gIgnoreCLick = false;
event.preventDefault();
+ event.stopImmediatePropagation();
return;
}
gIgnoreCLick = false;
@@ -126,6 +127,7 @@
if ( isSvgIcon && svgItemId ) {
handleSvgPathClick( event, enclosingSvgGroup );
event.preventDefault();
+ event.stopImmediatePropagation();
return;
}
}
@@ -135,6 +137,7 @@
if ( $(enclosingSvg).hasClass( Hi.LOCATION_VIEW_SVG_CLASS ) ) {
handleProxyPathClick( event );
event.preventDefault();
+ event.stopImmediatePropagation();
return;
}
}
@@ -146,9 +149,10 @@
return;
}
if ( ! gSvgPathEditData ) {
+ if ( Hi.DEBUG ) { console.log( `Key down skipped [${MODULE_NAME}]` ); }
return;
}
- if ( Hi.DEBUG ) { console.log( 'Key Down', event ); }
+ if ( Hi.DEBUG ) { console.log( `Key Down [${MODULE_NAME}]`, event ); }
if ( PATH_ACTION_ADD_KEY_CODES.includes( event.keyCode ) ) {
addProxyPath();
@@ -158,6 +162,7 @@
} else {
if ( ! gSvgPathEditData.selectedProxyElement ) {
+ if ( Hi.DEBUG ) { console.log( `Key down skipped [${MODULE_NAME}]` ); }
return;
}
@@ -169,6 +174,7 @@
deleteProxyLine( gSvgPathEditData.selectedProxyElement );
} else {
+ if ( Hi.DEBUG ) { console.log( `Key down skipped [${MODULE_NAME}]` ); }
return;
}
@@ -189,15 +195,17 @@
}
}
} else {
+ if ( Hi.DEBUG ) { console.log( `Key down skipped [${MODULE_NAME}]` ); }
return;
}
} else {
+ if ( Hi.DEBUG ) { console.log( `Key down skipped [${MODULE_NAME}]` ); }
return;
}
}
- event.stopPropagation();
event.preventDefault();
+ event.stopImmediatePropagation();
}
function handleSvgPathClick( event, enclosingSvgGroup ) {
@@ -761,6 +769,7 @@
// Drag logic for the proxy point
$(proxyPoint).on('mousedown', function( event ) {
event.preventDefault();
+ event.stopImmediatePropagation();
let startMousePosition = {
x: event.clientX,
@@ -786,6 +795,7 @@
|| ( distanceY > CURSOR_MOVEMENT_THRESHOLD_PIXELS )) {
isDragging = true;
event.preventDefault();
+ event.stopImmediatePropagation();
gSvgPathEditData.dragProxyPoint = event.target;
const newCx = event.clientX - offsetX;
const newCy = event.clientY - offsetY;
@@ -806,6 +816,7 @@
// Function to handle mouse up (end of drag)
function onMouseUp( event ) {
event.preventDefault();
+ event.stopImmediatePropagation();
saveSvgPath();
gSvgPathEditData.dragProxyPoint = null;
diff --git a/src/hi/static/js/main.js b/src/hi/static/js/main.js
index f001b970..676ae6c4 100644
--- a/src/hi/static/js/main.js
+++ b/src/hi/static/js/main.js
@@ -3,10 +3,13 @@
const Hi = {
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',
BASE_SVG_SELECTOR: '#hi-location-view-main > svg',
HIGHLIGHTED_CLASS: 'highlighted',
+ SVG_ACTION_STATE_ATTR_NAME: 'action-state',
+
DATA_TYPE_ATTR: 'data-type',
DATA_TYPE_ICON_VALUE: 'svg-icon',
DATA_TYPE_PATH_VALUE: 'svg-path',
@@ -15,15 +18,30 @@
generateUniqueId: function() {
return _generateUniqueId();
},
+ getScreenCenterPoint: function( element ) {
+ return _getScreenCenterPoint( element );
+ },
+ getRotationAngle: function( centerX, centerY, startX, startY, endX, endY ) {
+ return _getRotationAngle( centerX, centerY, startX, startY, endX, endY );
+ },
+ normalizeAngle: function(angle) {
+ return _normalizeAngle(angle);
+ },
getSvgViewBox: function( svgElement ) {
return _getSvgViewBox( svgElement );
},
+ getSvgCenterPoint: function( element, svgElement ) {
+ return _getSvgCenterPoint( element, svgElement );
+ },
getPixelsPerSvgUnit: function( svgElement ) {
return _getPixelsPerSvgUnit( svgElement );
},
toSvgPoint: function( svgElement, clientX, clientY) {
return _toSvgPoint( svgElement, clientX, clientY);
},
+ getSvgTransformValues: function( transformAttrStr ) {
+ return _getSvgTransformValues( transformAttrStr );
+ },
displayEventInfo: function ( label, event ) {
return _displayEventInfo( label, event );
},
@@ -39,6 +57,52 @@
return 'id-' + Date.now() + '-' + Math.floor(Math.random() * 1000);
}
+ function _getScreenCenterPoint( element ) {
+ try {
+ let rect = $(element)[0].getBoundingClientRect();
+ if ( rect ) {
+ const screenCenterX = rect.left + ( rect.width / 2.0 );
+ const screenCenterY = rect.top + ( rect.height / 2.0 );
+ return {
+ x: rect.left + ( rect.width / 2.0 ),
+ y: rect.top + ( rect.height / 2.0 )
+ };
+ }
+ } catch (e) {
+ console.debug( `Problem getting bounding box: ${e}` );
+ }
+ return null;
+ }
+
+ function _getRotationAngle( centerX, centerY, startX, startY, endX, endY ) {
+
+ const startVectorX = startX - centerX;
+ const startVectorY = startY - centerY;
+
+ const endVectorX = endX - centerX;
+ const endVectorY = endY - centerY;
+
+ const startAngle = Math.atan2(startVectorY, startVectorX);
+ const endAngle = Math.atan2(endVectorY, endVectorX);
+
+ let angleDifference = endAngle - startAngle;
+
+ // Normalize the angle to be between -π and π
+ if (angleDifference > Math.PI) {
+ angleDifference -= 2 * Math.PI;
+ } else if (angleDifference < -Math.PI) {
+ angleDifference += 2 * Math.PI;
+ }
+
+ const angleDifferenceDegrees = angleDifference * (180 / Math.PI);
+
+ return angleDifferenceDegrees;
+ }
+
+ function _normalizeAngle(angle) {
+ return (angle % 360 + 360) % 360;
+ }
+
function _getSvgViewBox( svgElement ) {
let x = null;
let y = null;
@@ -48,7 +112,7 @@
if (svgElement.length < 1 ) {
return { x, y, width, height };
}
- let viewBoxValue = svgElement.attr('viewBox');
+ let viewBoxValue = $(svgElement).attr('viewBox');
if ( ! viewBoxValue) {
return { x, y, width, height };
}
@@ -62,8 +126,23 @@
return { x, y, width, height };
}
+ function _getSvgCenterPoint( element, svgElement ) {
+
+ try {
+ let rect = element[0].getBoundingClientRect();
+ if ( rect ) {
+ const screenCenterX = rect.left + ( rect.width / 2.0 );
+ const screenCenterY = rect.top + ( rect.height / 2.0 );
+ return Hi.toSvgPoint( svgElement, screenCenterX, screenCenterY );
+ }
+ } catch (e) {
+ console.debug( `Problem getting bounding box: ${e}` );
+ }
+ return { x: 0, y: 0 };
+ }
+
function _getPixelsPerSvgUnit( svgElement ) {
- let ctm = svgElement[0].getScreenCTM();
+ let ctm = $(svgElement)[0].getScreenCTM();
return {
scaleX: ctm.a,
scaleY: ctm.d
@@ -71,12 +150,57 @@
}
function _toSvgPoint( svgElement, clientX, clientY) {
- let point = svgElement[0].createSVGPoint();
+ let point = $(svgElement)[0].createSVGPoint();
point.x = clientX;
point.y = clientY;
- return point.matrixTransform( svgElement[0].getScreenCTM().inverse() );
+ return point.matrixTransform( $(svgElement)[0].getScreenCTM().inverse() );
}
+ function _getSvgTransformValues( transformAttrStr ) {
+ let scale = { x: 1, y: 1 }, rotate = { angle: 0, cx: 0, cy: 0 }, translate = { x: 0, y: 0 };
+
+ let scaleMatch = transformAttrStr.match(/scale\(([^)]+)\)/);
+ if (scaleMatch) {
+ let scaleValues = scaleMatch[1].trim().split(/[ ,]+/).map(parseFloat);
+ scale.x = scaleValues[0];
+ if ( scaleValues.length == 1 ) {
+ scale.y = scale.x;
+ } else {
+ scale.y = scaleValues[1];
+ }
+ }
+
+ let translateMatch = transformAttrStr.match(/translate\(([^)]+)\)/);
+ if (translateMatch) {
+ let [x, y] = translateMatch[1].trim().split(/[ ,]+/).map(parseFloat);
+ translate.x = x;
+ translate.y = y;
+ }
+
+ let rotateMatch = transformAttrStr.match(/rotate\(([^)]+)\)/);
+ if (rotateMatch) {
+ let rotateValues = rotateMatch[1].trim().split(/[ ,]+/).map(parseFloat);
+ rotate.angle = rotateValues[0];
+
+ // Check if cx and cy are provided
+ if (rotateValues.length === 3) {
+ rotate.cx = rotateValues[1];
+ rotate.cy = rotateValues[2];
+ } else {
+ rotate.cx = 0;
+ rotate.cy = 0;
+ }
+ }
+
+ if ( Hi.DEBUG ) {
+ console.log( `TRANSFORM:
+ Raw: ${transformAttrStr},
+ Parsed: scale=${JSON.stringify(scale)} translate=${JSON.stringify(translate)} rotate=${JSON.stringify(rotate)}` );
+ }
+
+ return { scale, translate, rotate };
+ }
+
function _displayEventInfo ( label, event ) {
if ( ! Hi.DEBUG ) { return; }
if ( ! event ) {
@@ -96,13 +220,13 @@
console.log( 'No element to display info for.' );
return;
}
- const elementTag = element.prop('tagName');
- const elementId = element.attr('id') || 'No ID';
- const elementClasses = element.attr('class') || 'No Classes';
+ const elementTag = $(element).prop('tagName');
+ const elementId = $(element).attr('id') || 'No ID';
+ const elementClasses = $(element).attr('class') || 'No Classes';
let rectStr = 'No Bounding Rect';
try {
- let rect = element[0].getBoundingClientRect();
+ let rect = $(element)[0].getBoundingClientRect();
if ( rect ) {
rectStr = `Dim: ${rect.width}px x ${rect.height}px,
Pos: left=${rect.left}px, top=${rect.top}px`;
@@ -111,7 +235,7 @@
}
let offsetStr = 'No Offset';
- const offset = element.offset();
+ const offset = $(element).offset();
if ( offset ) {
offsetStr = `Offset: ( ${offset.left}px, ${offset.top}px )`;
}
diff --git a/src/hi/static/js/svg-location.js b/src/hi/static/js/svg-location.js
new file mode 100644
index 00000000..58846938
--- /dev/null
+++ b/src/hi/static/js/svg-location.js
@@ -0,0 +1,378 @@
+(function() {
+
+ window.Hi = window.Hi || {};
+ window.Hi.edit = window.Hi.edit || {};
+
+ const MODULE_NAME = 'svg-location';
+
+ const HiSvgLocation = {
+ init: function() {
+ Hi.edit.eventBus.subscribe( Hi.edit.SELECTION_MADE_EVENT_NAME,
+ this.clearSelection.bind(this) );
+ },
+ clearSelection: function( data ) {
+ if ( data != MODULE_NAME ) {
+ clearSelectedLocationViewSvg();
+ }
+ }
+ };
+
+ window.Hi.location = HiSvgLocation;
+ HiSvgLocation.init();
+
+ /*
+ SVG LOCATION
+
+ - For panning, zooming and rotating of the underlying background SVG of a location view.
+ */
+
+ const CURSOR_MOVEMENT_THRESHOLD_PIXELS = 3; // Differentiate between move events and sloppy clicks
+ const SVG_TRANSFORM_ACTION_SCALE_KEY = 's';
+ const SVG_TRANSFORM_ACTION_ROTATE_KEY = 'r';
+ const PIXEL_MOVE_DISTANCE_SCALE_FACTOR = 500.0;
+
+ const SvgTransformType = {
+ MOVE: 'move',
+ SCALE: 'scale',
+ ROTATE: 'rotate'
+ };
+ let gSvgTransformType = SvgTransformType.MOVE;
+
+ let gSelectedLocationViewSvg = null;
+ let gSvgTransformData = null;
+ let gLastMousePosition = { x: 0, y: 0 };
+ let gIgnoreCLick = false; // Set by mouseup handling when no click handling should be done
+
+ $(document).ready(function() {
+
+ $(document).on('mousedown', Hi.LOCATION_VIEW_AREA_SELECTOR, function(event) {
+ handleMouseDown( event );
+ });
+ $(document).on('mousemove', Hi.LOCATION_VIEW_AREA_SELECTOR, function(event) {
+ handleMouseMove( event );
+ });
+ $(document).on('mouseup', Hi.LOCATION_VIEW_AREA_SELECTOR, function(event) {
+ handleMouseUp( event );
+ });
+ $(document).on('click', function(event) {
+ handleClick( event );
+ });
+ $(document).on('keydown', function(event) {
+ handleKeyDown( event );
+ });
+ });
+
+ function handleMouseDown( event ) {
+ if ( Hi.DEBUG ) { console.log( `Mouse down event [${MODULE_NAME}]`, event ); }
+
+ if ( gSelectedLocationViewSvg ) {
+ createTransformData( event, gSelectedLocationViewSvg );
+ event.preventDefault();
+ event.stopImmediatePropagation();
+ return;
+ }
+ if ( Hi.DEBUG ) { console.log( `Mouse down skipped [${MODULE_NAME}]` ); }
+ }
+
+ function handleMouseUp( event ) {
+ if ( Hi.DEBUG ) { console.log( `Mouse up event [${MODULE_NAME}]`, event ); }
+
+ if ( gSvgTransformData && gSvgTransformData.isDragging ) {
+ if ( gSvgTransformType == SvgTransformType.SCALE ) {
+ applyScale( event );
+ } else if( gSvgTransformType == SvgTransformType.ROTATE ) {
+ applyRotation( event );
+ } else {
+ endDrag( event );
+ }
+ gSvgTransformData = null;
+ gSvgTransformType = SvgTransformType.MOVE;
+ gIgnoreCLick = true;
+
+ event.preventDefault();
+ event.stopImmediatePropagation();
+ return;
+ }
+
+ if ( Hi.DEBUG ) { console.log( `Mouse up skipped [${MODULE_NAME}]` ); }
+ }
+
+ function handleMouseMove( event ) {
+ const currentMousePosition = {
+ x: event.clientX,
+ y: event.clientY
+ };
+ if ( gSvgTransformData ) {
+
+ const distanceX = Math.abs( currentMousePosition.x - gSvgTransformData.clickStart.x );
+ const distanceY = Math.abs( currentMousePosition.y - gSvgTransformData.clickStart.y );
+
+ if ( gSvgTransformData.isDragging
+ || ( distanceX > CURSOR_MOVEMENT_THRESHOLD_PIXELS )
+ || ( distanceY > CURSOR_MOVEMENT_THRESHOLD_PIXELS )) {
+ gSvgTransformData.isDragging = true;
+ if ( gSvgTransformType == SvgTransformType.SCALE ) {
+ updateScale( event );
+ } else if( gSvgTransformType == SvgTransformType.ROTATE ) {
+ updateRotation( event );
+ } else {
+ updateDrag(event);
+ }
+ gSvgTransformData.lastMousePosition = currentMousePosition;
+ event.preventDefault();
+ event.stopImmediatePropagation();
+ }
+ }
+ gLastMousePosition = currentMousePosition;
+ }
+
+ function handleClick( event ) {
+ if ( gIgnoreCLick ) {
+ if ( Hi.DEBUG ) { console.log( `Ignoring click [${MODULE_NAME}]`, event ); }
+ gIgnoreCLick = false;
+ event.preventDefault();
+ event.stopImmediatePropagation();
+ return;
+ }
+ gIgnoreCLick = false;
+
+ if ( Hi.DEBUG ) { console.log( `Click [${MODULE_NAME}]`, event ); }
+
+ if ( $(event.target).hasClass( Hi.LOCATION_VIEW_SVG_CLASS ) ) {
+ if ( Hi.DEBUG ) { console.log( 'SVG Target', event.target ); }
+ handleLocationViewSvgClick( event, event.target );
+ event.preventDefault();
+ event.stopImmediatePropagation();
+ return;
+ }
+ if ( Hi.DEBUG ) { console.log( `Click skipped [${MODULE_NAME}]` ); }
+ }
+
+ function handleKeyDown( event ) {
+ if ( $(event.target).is('input[type="text"], textarea') ) {
+ return;
+ }
+ if ( gSelectedLocationViewSvg ) {
+
+ const targetArea = $(Hi.LOCATION_VIEW_AREA_SELECTOR);
+ const targetOffset = targetArea.offset();
+ const targetWidth = targetArea.outerWidth();
+ const targetHeight = targetArea.outerHeight();
+
+ if (( gLastMousePosition.x >= targetOffset.left )
+ && ( gLastMousePosition.x <= ( targetOffset.left + targetWidth ))
+ && ( gLastMousePosition.y >= targetOffset.top )
+ && ( gLastMousePosition.y <= ( targetOffset.top + targetHeight ))) {
+
+ if ( Hi.DEBUG ) { console.log( `Key Down [${MODULE_NAME}]`, event ); }
+
+ if ( event.key == SVG_TRANSFORM_ACTION_SCALE_KEY ) {
+ abortRotation();
+ startScale();
+
+ } else if ( event.key == SVG_TRANSFORM_ACTION_ROTATE_KEY ) {
+ abortScale();
+ startRotation();
+
+ } else if ( event.key == 'Escape' ) {
+ abortScale();
+ abortRotation();
+ }
+ event.preventDefault();
+ event.stopImmediatePropagation();
+ return;
+ }
+ }
+ if ( Hi.DEBUG ) { console.log( `Key down skipped [${MODULE_NAME}]` ); }
+ }
+
+ function createTransformData( event, locationViewSvg ) {
+
+ let svgViewBox = Hi.getSvgViewBox( locationViewSvg );
+ let transform = $(locationViewSvg).attr('transform') || '';
+ let { scale, translate, rotate } = Hi.getSvgTransformValues( transform );
+
+ gSvgTransformData = {
+ isDragging: false,
+ clickStart: {
+ x: event.clientX,
+ y: event.clientY,
+ time: Date.now()
+ },
+ lastMousePosition: {
+ x: event.clientX,
+ y: event.clientY,
+ },
+ originalSvgRotate: rotate,
+ originalSvgViewBox: svgViewBox
+ };
+ }
+
+ function clearSelectedLocationViewSvg() {
+ if ( gSelectedLocationViewSvg ) {
+ if ( Hi.DEBUG ) { console.log('Clearing location view svg transform data'); }
+ gSelectedLocationViewSvg = null;
+ gSvgTransformData = null;
+ }
+ }
+
+ function handleLocationViewSvgClick( event, locationViewSvg ) {
+ gSelectedLocationViewSvg = locationViewSvg;
+ Hi.edit.eventBus.emit( Hi.edit.SELECTION_MADE_EVENT_NAME, MODULE_NAME );
+ AN.get( `${Hi.API_SHOW_DETAILS_URL}` );
+ }
+
+ function startDrag( event ) {
+ }
+
+ function updateDrag( event ) {
+ if ( Hi.DEBUG ) { console.log( `updateDrag [${MODULE_NAME}]` ); }
+ if ( gSvgTransformData == null ) {
+ return;
+ }
+
+ let pixelsPerSvgUnit = Hi.getPixelsPerSvgUnit( gSelectedLocationViewSvg );
+ let deltaSvgUnits = {
+ x: ( event.clientX - gSvgTransformData.clickStart.x ) / pixelsPerSvgUnit.scaleX,
+ y: ( event.clientY - gSvgTransformData.clickStart.y ) / pixelsPerSvgUnit.scaleX
+ };
+
+ let svgViewBox = {
+ x: gSvgTransformData.originalSvgViewBox.x - deltaSvgUnits.x,
+ y: gSvgTransformData.originalSvgViewBox.y - deltaSvgUnits.y,
+ width: gSvgTransformData.originalSvgViewBox.width,
+ height: gSvgTransformData.originalSvgViewBox.height
+ };
+
+ let svgViewBoxStr = `${svgViewBox.x} ${svgViewBox.y} ${svgViewBox.width} ${svgViewBox.height}`;
+ $(gSelectedLocationViewSvg).attr('viewBox', svgViewBoxStr );
+ }
+
+ function endDrag( event ) {
+ if ( Hi.DEBUG ) { console.log( `endDrag [${MODULE_NAME}]` ); }
+
+ if ( Hi.isEditMode ) {
+ let data = {
+ view_box: $(gSelectedLocationViewSvg).attr('viewBox'),
+ };
+
+ // ZZZ TODO: AN.post( `${API_EDIT_LOCATION_VIEW_VIEWBOX_URL}/${locationViewId}`, data );
+ }
+ }
+
+ function startScale( event ) {
+ if ( Hi.DEBUG ) { console.log( `startScale [${MODULE_NAME}]` ); }
+
+ gSvgTransformType = SvgTransformType.SCALE;
+ $(Hi.BASE_SVG_SELECTOR).attr( Hi.SVG_ACTION_STATE_ATTR_NAME, gSvgTransformType );
+ }
+
+ function updateScale( event ) {
+ if ( Hi.DEBUG ) { console.log( `updateScale [${MODULE_NAME}]` ); }
+
+ if ( gSvgTransformData == null ) {
+ return;
+ }
+
+ let screenCenter = Hi.getScreenCenterPoint( gSelectedLocationViewSvg );
+ const startVector = {
+ x: gSvgTransformData.clickStart.x- screenCenter.x,
+ y: gSvgTransformData.clickStart.y - screenCenter.y
+ };
+ const endVector = {
+ x: event.clientX - screenCenter.x,
+ y: event.clientY - screenCenter.y
+ };
+ const startVectorLength = Math.sqrt( ( startVector.x * startVector.x )
+ + ( startVector.y * startVector.y ));
+ const endVectorLength = Math.sqrt( ( endVector.x * endVector.x )
+ + ( endVector.y * endVector.y ));
+ const vectorLengthDelta = endVectorLength - startVectorLength;
+
+ let scale = ( 1.0 - ( vectorLengthDelta / PIXEL_MOVE_DISTANCE_SCALE_FACTOR ));
+
+ let svgViewBox = {
+ x: gSvgTransformData.originalSvgViewBox.x,
+ y: gSvgTransformData.originalSvgViewBox.y,
+ width: scale * gSvgTransformData.originalSvgViewBox.width,
+ height: scale * gSvgTransformData.originalSvgViewBox.height
+ };
+
+ let svgOffset = {
+ x: ( gSvgTransformData.originalSvgViewBox.width - svgViewBox.width ) / 2.0,
+ y: ( gSvgTransformData.originalSvgViewBox.height - svgViewBox.height ) / 2.0
+ };
+ svgViewBox.x += svgOffset.x;
+ svgViewBox.y += svgOffset.y;
+
+
+
+
+ let svgViewBoxStr = `${svgViewBox.x} ${svgViewBox.y} ${svgViewBox.width} ${svgViewBox.height}`;
+ $(gSelectedLocationViewSvg).attr('viewBox', svgViewBoxStr );
+ }
+
+ function applyScale( event ) {
+ if ( Hi.DEBUG ) { console.log( `applyScale [${MODULE_NAME}]` ); }
+
+ // ZZZ
+
+
+
+ gSvgTransformType = SvgTransformType.MOVE;
+ $(Hi.BASE_SVG_SELECTOR).attr( Hi.SVG_ACTION_STATE_ATTR_NAME, '' );
+ }
+
+ function abortScale( event ) {
+ if ( Hi.DEBUG ) { console.log( `abortScale [${MODULE_NAME}]` ); }
+ gSvgTransformType = SvgTransformType.MOVE;
+ $(Hi.BASE_SVG_SELECTOR).attr( Hi.SVG_ACTION_STATE_ATTR_NAME, '' );
+ }
+
+ function startRotation( event ) {
+ if ( Hi.DEBUG ) { console.log( `startRotation [${MODULE_NAME}]` ); }
+ gSvgTransformType = SvgTransformType.ROTATE;
+ $(Hi.BASE_SVG_SELECTOR).attr( Hi.SVG_ACTION_STATE_ATTR_NAME, gSvgTransformType );
+ }
+
+ function updateRotation( event ) {
+ if ( Hi.DEBUG ) { console.log( `updateRotation [${MODULE_NAME}]` ); }
+
+ let screenCenter = Hi.getScreenCenterPoint( gSelectedLocationViewSvg );
+
+ let deltaAngle = Hi.getRotationAngle( screenCenter.x, screenCenter.y,
+ gLastMousePosition.x, gLastMousePosition.y,
+ event.clientX, event.clientY );
+
+ let transform = $(gSelectedLocationViewSvg).attr('transform');
+ let { scale, translate, rotate } = Hi.getSvgTransformValues( transform );
+ rotate.angle += deltaAngle;
+ rotate.angle = Hi.normalizeAngle( rotate.angle );
+
+ let newTransform = `rotate(${rotate.angle}, ${rotate.cx}, ${rotate.cy})`;
+ $(gSelectedLocationViewSvg).attr( 'transform', newTransform );
+
+ }
+
+ function applyRotation( event ) {
+ if ( Hi.DEBUG ) { console.log( `applyRotation [${MODULE_NAME}]` ); }
+
+
+
+ // ZZZ
+
+
+ gSvgTransformType = SvgTransformType.MOVE;
+ $(Hi.BASE_SVG_SELECTOR).attr( Hi.SVG_ACTION_STATE_ATTR_NAME, '' );
+
+ }
+
+ function abortRotation( event ) {
+ if ( Hi.DEBUG ) { console.log( `abortRotation [${MODULE_NAME}]` ); }
+ gSvgTransformType = SvgTransformType.MOVE;
+ $(Hi.BASE_SVG_SELECTOR).attr( Hi.SVG_ACTION_STATE_ATTR_NAME, '' );
+ }
+
+
+
+})();
diff --git a/src/hi/templates/panes/bottom_buttons.html b/src/hi/templates/panes/bottom_buttons.html
index 1b3a6345..0c0e1772 100644
--- a/src/hi/templates/panes/bottom_buttons.html
+++ b/src/hi/templates/panes/bottom_buttons.html
@@ -1,3 +1,12 @@
<div class="bg-white p-1">
- {% include "collection/collection_buttons.html" %}
+ <div class="d-flex justify-content-between">
+ {% include "collection/collection_buttons.html" %}
+ <div>
+ <a href="{% url 'config_home_pane' %}"
+ class="btn btn-tertiary btn-control" role="button"
+ data-async="true" >
+ ADMIN
+ </a>
+ </div>
+ </div>
</div>
diff --git a/src/hi/templates/panes/side_default.html b/src/hi/templates/panes/side_default.html
new file mode 100644
index 00000000..b3a9ebe0
--- /dev/null
+++ b/src/hi/templates/panes/side_default.html
@@ -0,0 +1 @@
+SIDE DEFAULT
diff --git a/src/hi/templates/panes/side_panel.html b/src/hi/templates/panes/side_panel.html
index c5b314a7..031ecd96 100644
--- a/src/hi/templates/panes/side_panel.html
+++ b/src/hi/templates/panes/side_panel.html
@@ -1,22 +1,20 @@
+{% if request.view_parameters.view_type.is_location_view %}
+
{% if request.is_editing %}
{% include "edit/panes/side.html" %}
{% else %}
-<div class="border-left" >
- SIDE PANEL
+{% include "panes/side_default.html" %}
+{% endif %}
+
+{% elif request.view_parameters.view_type.is_collection %}
- <div class="">
- <a href="{% url 'config_home_pane' %}"
- class="btn btn-tertiary btn-control" role="button"
- data-async="true" >
- ADMIN
- </a>
- </div>
- <div class="">
- <a href="{% url 'edit_start' %}"
- class="btn btn-tertiary btn-control" role="button" >
- EDIT
- </a>
- </div>
+{% if request.is_editing %}
+{% include "edit/panes/side.html" %}
+{% else %}
+{% include "panes/side_default.html" %}
+{% endif %}
+
+{% else %}
+{% include "panes/side_default.html" %}
-</div>
{% endif %}
diff --git a/src/hi/templates/panes/top_buttons.html b/src/hi/templates/panes/top_buttons.html
index 8d30919c..31bae1fe 100644
--- a/src/hi/templates/panes/top_buttons.html
+++ b/src/hi/templates/panes/top_buttons.html
@@ -1,3 +1,22 @@
<div class="bg-white p-1">
- {% include "location/location_view_buttons.html" %}
+ <div class="d-flex justify-content-between">
+ {% include "location/location_view_buttons.html" %}
+ {% if request.is_editing %}
+ <div class="">
+ <a href="{% url 'edit_end' %}"
+ class="btn btn-tertiary btn-control" role="button" >
+ EXIT EDITING
+ </a>
+ </div>
+ {% else %}
+ {% if request.view_parameters.view_type.allows_edit_mode %}
+ <div>
+ <a href="{% url 'edit_start' %}"
+ class="btn btn-tertiary btn-control" role="button" >
+ EDIT
+ </a>
+ </div>
+ {% endif %}
+ {% endif %}
+ </div>
</div>