Conversation
| const data = JSON.parse(`{{topology_data_list| escapejs }}`); | ||
| Promise.all([addBusses(data['busses']), addAssets(data['assets'])]) | ||
| .then(async () => addLinks(data['links'])) | ||
| .then(() => zoomToFit()) |
There was a problem hiding this comment.
@josihoppe - You can comment the line next to this in order to see the traceback into the console:
downloadable font: Glyph bbox was incorrect (glyph ids 10 12 17 18 19) (font-family: "icomoon" style:normal weight:400 stretch:100 src index:1) source: http://127.0.0.1:8000/static/fonts/icomoon.ttf?xke5es
Uncaught (in promise) TypeError: canvas.getBoundingClientRect is not a function
zoomToFit http://127.0.0.1:8000/static/js/grid_model_topology.js:438
<anonymous> http://127.0.0.1:8000/en/project/41/scenario/67/edit/step/2:754
promise callback* http://127.0.0.1:8000/en/project/41/scenario/67/edit/step/2:754
jQuery 8
<anonymous> https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js:6
<anonymous> https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js:6
grid_model_topology.js:438:32
Bachibouzouk
left a comment
There was a problem hiding this comment.
I tried it with a larger energy system and it seems that it is not well centered.
On another topic: I noticed this "transform" function applying to the style seem to be at the origin of the draggable zone of the canevas issue (#317) .
Maybe we could solve both issues at once?
Somehow when I zoom in and out again, I cannot reach the same zoom depth as if I just refresh the page. The Editor.Width seem to always be the same value. We should have a way to change it dynamically as well.
|
Maybe the html structure is not correct, could you check it and try with this one? |
What do you mean by trying this structure? The structure should be created by editor.start() if I see that correctly and I didn't see if if is being changed at some point in the code? |
I meant comparing it with the structure rendered within our DOM, it seemed to me that it was different, and thus could be a reason why we are facing problems with panning (not be able to drag the canevas anywhere on the page, like one can do in a miro board) |
A I see! I think the strutuce in the DOM looks correct, I compared it to the code of Drawflow and it seems to be rendered fine. From my research, I think that others also had a problem with panning. Like here: jerosoler/Drawflow#141 or here: jerosoler/Drawflow#199 |
|
@Bachibouzouk I think I fixed the panning problem with this solution: jerosoler/Drawflow#199 . But I am struggling to get the big energy systems centered. And I tried to recreate this
But for me when Zooming with strg+mouse wheel it always zooms in +1/-1 increments. So it can indeed go back to the original Zoom level. (When I tested I did not move the canvas/did not change the translation) |
Great, I will find time to review tonight or tomorrow
Maybe now this will also be fixed for me, no need to worry more, I will try it and let you know |
Bachibouzouk
left a comment
There was a problem hiding this comment.
This works already better than before, I suggest we implement this and improve it further in subsequent PRs.
A conflict will happen with #337 as there the grid_model_topology.js get indented and suffled around. I suggest we merge this one first and struggle with conflicts in #337, I will highlight the lines which are not just js linting in this PR
Bachibouzouk
left a comment
There was a problem hiding this comment.
I marked the lines with the important code (other changes are just linting) to ease conflict resolution in #337
| pos_x = pos_x * (editor.precanvas.clientWidth / (editor.precanvas.clientWidth * editor.zoom)) - (editor.precanvas.getBoundingClientRect().x * (editor.precanvas.clientWidth / (editor.precanvas.clientWidth * editor.zoom))); | ||
| pos_y = pos_y * (editor.precanvas.clientHeight / (editor.precanvas.clientHeight * editor.zoom)) - (editor.precanvas.getBoundingClientRect().y * (editor.precanvas.clientHeight / (editor.precanvas.clientHeight * editor.zoom))); | ||
| return createNodeObject(name, nodeInputs, nodeOutputs, nodeData, pos_x, pos_y); | ||
| return createNodeObject(name, pos_x, pos_y, nodeInputs, nodeOutputs, nodeData); |
|
|
||
| /* Create node on the gui */ | ||
| async function createNodeObject(nodeName, connectionInputs = 1, connectionOutputs = 1, nodeData = {}, pos_x, pos_y) { | ||
| async function createNodeObject(nodeName, pos_x, pos_y, connectionInputs = 1, connectionOutputs = 1, nodeData = {}) { |
| const result = await createNodeObject(nodeData.name, nodeData.pos_x, nodeData.pos_y, nodeData.input_ports, nodeData.output_ports, nodeData.data); | ||
| nodesToDB.set(`node-${result.editorNodeId}`, {uid:nodeData.data.databaseId, assetTypeName: "bus" }); | ||
| })); | ||
|
|
||
| const addAssets = async (data) => | ||
| await Promise.all(data.map(async nodeData => { | ||
| const result = await createNodeObject(nodeData.name, 1, 1, nodeData.data, nodeData.pos_x, nodeData.pos_y); | ||
| const result = await createNodeObject(nodeData.name, nodeData.pos_x, nodeData.pos_y, 1, 1, nodeData.data); |
|
|
||
|
|
||
| function zoomToFit() { | ||
| const nodeWidth = 152; | ||
| const nodeHeight = 128; | ||
|
|
||
| const nodes = Object.values(editor.drawflow.drawflow.Home.data); // Array with all nodes | ||
|
|
||
| let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity; | ||
|
|
||
| // get outer most node bounding box edges | ||
| nodes.forEach(node => { | ||
| minX = Math.min(minX, node.pos_x); | ||
| minY = Math.min(minY, node.pos_y); | ||
| maxX = Math.max(maxX, node.pos_x + nodeWidth); | ||
| maxY = Math.max(maxY, node.pos_y + nodeHeight); | ||
| }); | ||
| const nodesWidth = maxX - minX; | ||
| const nodesHeight = maxY - minY; | ||
|
|
||
| // get space of editor | ||
| const editorElem = document.querySelector('.drawflow'); | ||
| const editorWidth = editorElem.clientWidth; | ||
| const editorHeight = editorElem.clientHeight; | ||
|
|
||
| // calculate zoom | ||
| const zoomX = editorWidth / (nodesWidth + 2); | ||
| const zoomY = editorHeight / (nodesHeight + 2); | ||
| const zoom = Math.min(zoomX, zoomY, 1); // Maximal 1 (kein Hineinzoomen) | ||
| editor.zoom = zoom; | ||
|
|
||
| // center editor | ||
| const offsetX = (editorWidth - nodesWidth * zoom) / 2 - minX * zoom; | ||
| const offsetY = (editorHeight - nodesHeight * zoom) / 2 - minY * zoom; | ||
| editor.precanvas.style.transform = `translate(${offsetX}px, ${offsetY}px) scale(${zoom})`; | ||
|
|
| const data = JSON.parse(`{{topology_data_list| escapejs }}`); | ||
| Promise.all([addBusses(data['busses']), addAssets(data['assets'])]) | ||
| .then(async () => addLinks(data['links'])) | ||
| .then(() => zoomToFit()) |
added function zoomToFit in grid_model_topology and trying to call it in scenario_step2.html