diff --git a/imperative/python/megengine/tools/profiler.py b/imperative/python/megengine/tools/profiler.py index 9fee3872..bea9615f 100755 --- a/imperative/python/megengine/tools/profiler.py +++ b/imperative/python/megengine/tools/profiler.py @@ -1,3 +1,11 @@ +#! /usr/bin/env python3 +# MegEngine is Licensed under the Apache License, Version 2.0 (the "License") +# +# Copyright (c) 2014-2021 Megvii Inc. All rights reserved. +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT ARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. import argparse import getopt import os diff --git a/imperative/python/megengine/tools/svg_viewer.html b/imperative/python/megengine/tools/svg_viewer.html index d77c947c..b04f3bf5 100644 --- a/imperative/python/megengine/tools/svg_viewer.html +++ b/imperative/python/megengine/tools/svg_viewer.html @@ -18,6 +18,8 @@ var svg = undefined; var svgWidth = undefined; var svgHeight = undefined; + var resetBtn = document.getElementById('resetBtn'); + var relocBtn = document.getElementById('relocBtn'); var loadDesc = (svgElem) => { var mgeType = svgElem.attributes['tag:type']; @@ -52,7 +54,7 @@ lastColor = undefined; }; - function recLoadSVG(svgElem) { + var recLoadSVG = svgElem => { if (svgElem.children === undefined) { return; } @@ -71,8 +73,37 @@ recLoadSVG(child); } } + var scaleBoard = (x, y) => { + var transform = 'scale(' + x + ',' + y + ')'; + svg.setAttribute('transform', transform); + board.style['width'] = svgWidth * x; + board.style['height'] = svgHeight * y; + } + var autoScaleBoard = () => { + var hRangeValue = Math.sqrt(Number(hRange.value) / 10); + var vRangeValue = Math.sqrt(Number(vRange.value) / 10); + scaleBoard(Number(hRangeValue), Number(vRangeValue)); + } + var zoomBoard = dScale => { + scale *= dScale; + scaleBoard(scale, scale); + }; - function loadSVG() { + var reset = () => { + if (!svgHeight || !svgWidth) { + return; + } + var vScale = window.screen.availHeight / svgHeight; + var hScale = window.screen.availWidth / svgWidth; + var minScale = Math.min(hScale, vScale); + zoomBoard(minScale / scale); + window.scrollTo({ + top: 0, + left: 0, + }); + }; + + var loadSVG = () => { var file = fileInput.files[0]; var reader = new FileReader(); reader.readAsText(file, "UTF-8"); @@ -98,26 +129,10 @@ info.innerHTML = elemList.join(''); } } + setTimeout(reset, 1); }; } - function scaleBoard(x, y) { - var transform = 'scale(' + x + ',' + y + ')'; - svg.setAttribute('transform', transform); - board.style['width'] = svgWidth * x; - board.style['height'] = svgHeight * y; - } - function autoScaleBoard() { - var hRangeValue = Math.sqrt(Number(hRange.value) / 10); - var vRangeValue = Math.sqrt(Number(vRange.value) / 10); - scaleBoard(Number(hRangeValue), Number(vRangeValue)); - } - fileInput.onchange = loadSVG; - var zoomBoard = dScale => { - scale *= dScale; - scaleBoard(scale, scale); - }; window.addEventListener('wheel', e => { - console.log(e); if (e.ctrlKey) { e.preventDefault(); e.stopPropagation(); @@ -136,19 +151,39 @@ top: y, left: x, }); - console.log('scroll', [x, y]); + } else if (e.altKey) { + } }, { 'passive': false }); + fileInput.onchange = loadSVG; + resetBtn.onclick = reset; + relocBtn.onclick = () => { + if (!lastElem) { + return; + } + y = scale * lastElem.attributes['y'].value; + x = scale * lastElem.attributes['x'].value; + window.scrollTo({ + top: y - window.screen.availHeight/2, + left: x - window.screen.availWidth/2, + behavior: 'smooth', + }); + }; };
-desc
-info
+ style="white-space: nowrap; display: flex; justify-content: center; align-content: center; align-items: center; margin: 0; left: 0;">
- +desc
+info