# HG changeset patch # User hertzhaft # Date 1476372829 -7200 # Node ID c883ee76e1a79c4f536b98806cd53e4b91fc86fb # Parent f129468a9ab8a1c04d39dc696310c449beb14145 measure plugin: first step towards info window diff -r f129468a9ab8 -r c883ee76e1a7 webapp/src/main/webapp/jquery/jquery.digilib.measure.css --- a/webapp/src/main/webapp/jquery/jquery.digilib.measure.css Mon Oct 10 13:31:27 2016 +0200 +++ b/webapp/src/main/webapp/jquery/jquery.digilib.measure.css Thu Oct 13 17:33:49 2016 +0200 @@ -15,6 +15,25 @@ z-index: 20; } +div#dl-measure-info { + font-size: 90%; + display: none; + border: 1px solid grey; + border-radius: 5px; + background-color:rgba(255, 255, 255, 0.3); + padding: 5px; + position: absolute; + z-index: 20; +} + +div#dl-measure-info div.head { + font-weight: bold; +} + +div#dl-measure-info em { + font-weight: bold; +} + input#dl-measure-value1 { font-size: 100%; width: 8em; @@ -117,16 +136,19 @@ fill: none; } -span#dl-measure-shapecolor, -span#dl-measure-constrcolor, -span#dl-measure-guidecolor, -span#dl-measure-selectedcolor { +.dl-measure-handle { + stroke: blue; + fill: none; +} + + +span.dl-measure-color { display: inline-block; - width: 8px; - height: 16px; + width: 12px; + height: 12px; vertical-align: middle; - margin: 0px 0px 2px 2px; - border: 1px solid darkgray; + margin: 1px; + border: 1px solid black; background-color: darkgray; } diff -r f129468a9ab8 -r c883ee76e1a7 webapp/src/main/webapp/jquery/jquery.digilib.measure.js --- a/webapp/src/main/webapp/jquery/jquery.digilib.measure.js Mon Oct 10 13:31:27 2016 +0200 +++ b/webapp/src/main/webapp/jquery/jquery.digilib.measure.js Thu Oct 13 17:33:49 2016 +0200 @@ -28,8 +28,8 @@ */ /* TODO: - - infowindow for shapes - - display fractions + - infowindow for shapes (partially done) + - display fractions (1/3 etc.) - display angles - display Vitruvian intercolumnium types - display shapes overlay? (angles, distances?) @@ -717,36 +717,36 @@ // styles for shapes styles : { shape : { - stroke : 'red', - strokewidth : 1, + stroke : 'lightgreen', + 'stroke-width' : 2, fill : 'none' }, constr : { stroke : 'cornsilk', - strokewidth : 1, + 'stroke-width' : 1, fill : 'none' }, guide : { stroke : 'blue', - strokewidth : 1, + 'stroke-width' : 1, fill : 'none' }, selected : { stroke : 'cyan', - strokewidth : 1, + 'stroke-width' : 1, fill : 'none' }, handle : { stroke : 'blue', - strokewidth : 1, + 'stroke-width' : 1, fill : 'none', hover : { - fill : 'red', + fill : 'yellow', } } }, // implemented styles - implementedStyles : ['shape', 'constr', 'guide', 'selected'], + implementedStyles : ['shape', 'constr', 'guide', 'selected', 'handle'], // implemented measuring shape types, for select widget implementedShapes : ['Line', 'LineString', 'Proportion', 'Rect', 'Rectangle', 'Polygon', 'Circle', 'Ellipse', 'Oval', 'Grid'], // all measuring shape types @@ -754,7 +754,7 @@ Line : { name : 'line', display : 'length', }, LineString : { name : 'linestring', display : 'length' }, Proportion : { name : 'proportion', display : 'length' }, - Rectangle : { name : 'box', display : 'area' }, + Rectangle : { name : 'box', display : 'diagonal' }, Rect : { name : 'rectangle', display : 'area' }, Square : { name : 'square', display : 'length' }, Polygon : { name : 'polygon', display : 'area' }, @@ -804,7 +804,9 @@ // keep original object when moving/scaling/rotating keepOriginal : false, // number of copies when drawing grids - gridCopies : 10 + gridCopies : 10, + // info window + infoDiv : null }; // debug routine @@ -830,7 +832,8 @@ var shape = newShape(data); var layer = data.measureLayer; $(data).trigger('createShape', shape); - digilib.actions.addShape(data, shape, shapeCompleted, layer); + digilib.actions.addShape(data, shape, shapeCompleted, layer); + console.debug('drawshape', shape); _debug_shape('action drawshape', shape); } }; @@ -879,6 +882,22 @@ // event handler for changeShape var onChangeShape = function(event, shape) { var data = this; + // event handler for updating shape info + var select = function(event) { + selectShape(data, shape); + updateInfo(data, shape); + _debug_shape('onClick', shape); + }; + var info = function(event) { + showInfoDiv(event, data, shape); + _debug_shape('onMouseover', shape); + }; + var $elem = shape.geometry.type === 'Oval' + ? shape.$elem.children('path') + : shape.$elem; + console.debug('measure: onChangeShape', $elem); + $elem.on('mouseover.measure', info); + $elem.on('click.measure', select); updateInfo(data, shape); currentShape = null; _debug_shape('onChangeShape', shape); @@ -886,15 +905,6 @@ // event handler for renderShape var onRenderShape = function(event, shape) { - // event handler for updating shape info - var info = function(event) { - selectShape(data, shape); - updateInfo(data, shape); - _debug_shape('onClick', shape); - }; - var data = this; - var $elem = shape.$elem; - $elem.on('click.measure', info); _debug_shape('onRenderShape', shape); }; @@ -962,47 +972,75 @@ var val = parseFloat(widgets.value1.val()); var fac = val / data.lastMeasuredValue; data.measureFactor = fac; - convertUnits(data); + updateUnits(data); }; // convert measured value to second unit and display var updateMeasures = function(data, val, type) { - var info = data.settings.shapeInfo[type] var widgets = data.measureWidgets; - var display = info.display; - var u1 = parseFloat(widgets.unit1.val()); - var u2 = parseFloat(widgets.unit2.val()); - var ratio = u1 / u2; - var result = (display === 'area') // TODO: display unit² - ? val * ratio * ratio - : val * ratio; + var unit1 = parseFloat(widgets.unit1.val()); + var unit2 = parseFloat(widgets.unit2.val()); + var ratio = unit1 / unit2; + var result = scaleValue(data, type, val, ratio); widgets.shape.val(type); widgets.value1.val(fn.cropFloatStr(mRound(val))); widgets.value2.text(fn.cropFloatStr(mRound(result))); }; - // convert measured pixel values to new units - var convertUnits = function(data) { - var type = getActiveShapeType(data); + // scale + var scaleValue = function(data, type, val, factor) { + var scaleArea = data.settings.shapeInfo[type].display === 'area'; + var result = scaleArea + ? val * factor * factor + : val * factor; + return result; + }; + + // convert pixel values to other units + var pixelToUnit = function(data, type, px) { + var ratio = data.measureFactor; + var result = scaleValue(data, type, px, ratio); + return result; + }; + + // rectify pixel values according to digilib aspect ratio + var rectifiedPixel = function(data, shape) { + var type = shape.geometry.type; var display = data.settings.shapeInfo[type].display; - var val = data.lastMeasuredValue; - var fac = data.measureFactor; - var result = (display === 'area') - ? val * fac * fac - : val * fac; + var px = (display === 'area') + ? rectifiedArea(data, shape) + : rectifiedDist(data, shape); + return px; + }; + + // update last measured pixel values, display as converted to new units + var updateUnits = function(data) { + var type = getActiveShapeType(data); + var px = data.lastMeasuredValue; + var result = pixelToUnit(data, type, px); updateMeasures(data, result, type); }; // display info for shape var updateInfo = function(data, shape) { + data.lastMeasuredValue = rectifiedPixel(data, shape); + setActiveShapeType(data, shape); + updateUnits(data); + }; + + // info data for shape + var getInfo = function(data, shape) { + var s = data.settings; var type = shape.geometry.type; - var display = data.settings.shapeInfo[type].display; - var val = (display === 'area') + var display = s.shapeInfo[type].display; + var name = s.shapeInfo[type].name; + var px = (display === 'area') ? rectifiedArea(data, shape) : rectifiedDist(data, shape); - data.lastMeasuredValue = val; - setActiveShapeType(data, type); - convertUnits(data); + var len = fn.cropFloat(pixelToUnit(data, type, px), 2); + var unit = data.measureWidgets.unit1.find('option:selected').text(); + var html = '