1<!-- Copyright (C) 2017 The Android Open Source Project 2 3 Licensed under the Apache License, Version 2.0 (the "License"); 4 you may not use this file except in compliance with the License. 5 You may obtain a copy of the License at 6 7 http://www.apache.org/licenses/LICENSE-2.0 8 9 Unless required by applicable law or agreed to in writing, software 10 distributed under the License is distributed on an "AS IS" BASIS, 11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 See the License for the specific language governing permissions and 13 limitations under the License. 14--> 15<template> 16 <div class="bounds" :style="boundsStyle"> 17 <div 18 class="rect" v-for="r in filteredRects" 19 :style="rectToStyle(r)" 20 @click="onClick(r)" 21 v-bind:key="`${r.left}-${r.right}-${r.top}-${r.bottom}-${r.ref.name}`" 22 > 23 <span class="label">{{r.label}}</span> 24 </div> 25 <div class="highlight" v-if="highlight" :style="rectToStyle(highlight)" /> 26 </div> 27</template> 28 29<script> 30 31// eslint-disable-next-line camelcase 32import {multiply_rect} from './matrix_utils.js'; 33 34export default { 35 name: 'rects', 36 props: ['bounds', 'rects', 'highlight'], 37 data() { 38 return { 39 desiredHeight: 800, 40 desiredWidth: 400, 41 }; 42 }, 43 computed: { 44 boundsC() { 45 if (this.bounds) { 46 return this.bounds; 47 } 48 const width = Math.max( 49 ...this.rects.map((r) => multiply_rect(r.transform, r).right)); 50 const height = Math.max( 51 ...this.rects.map((r) => multiply_rect(r.transform, r).bottom)); 52 return {width, height}; 53 }, 54 boundsStyle() { 55 return this.rectToStyle({top: 0, left: 0, right: this.boundsC.width, 56 bottom: this.boundsC.height}); 57 }, 58 filteredRects() { 59 return this.rects.filter((rect) => { 60 const isVisible = rect.ref.visible ?? rect.ref.isVisible; 61 console.warn(`Name: ${rect.ref.name} Kind: ${rect.ref.kind} isVisible=${isVisible}`); 62 return isVisible; 63 }); 64 }, 65 }, 66 methods: { 67 s(sourceCoordinate) { // translate source into target coordinates 68 let scale; 69 if (this.boundsC.width < this.boundsC.height) { 70 scale = this.desiredHeight / this.boundsC.height; 71 } else { 72 scale = this.desiredWidth / this.boundsC.width; 73 } 74 return sourceCoordinate * scale; 75 }, 76 rectToStyle(r) { 77 const x = this.s(r.left); 78 const y = this.s(r.top); 79 const w = this.s(r.right) - this.s(r.left); 80 const h = this.s(r.bottom) - this.s(r.top); 81 const t = r.transform; 82 const tr = t ? `matrix(${t.dsdx}, ${t.dtdx}, ${t.dsdy}, ${t.dtdy}, ` + 83 `${this.s(t.tx)}, ${this.s(t.ty)})` : ''; 84 return `top: ${y}px; left: ${x}px; height: ${h}px; width: ${w}px;` + 85 `transform: ${tr}; transform-origin: 0 0;`; 86 }, 87 onClick(r) { 88 this.$emit('rect-click', r.ref); 89 }, 90 }, 91}; 92</script> 93 94<style scoped> 95.bounds { 96 position: relative; 97 overflow: hidden; 98} 99.highlight, .rect { 100 position: absolute; 101 box-sizing: border-box; 102 display: flex; 103 justify-content: flex-end; 104} 105.rect { 106 border: 1px solid black; 107 background-color: rgba(110, 114, 116, 0.8); 108} 109.highlight { 110 border: 2px solid rgb(235, 52, 52); 111 pointer-events: none; 112} 113.label { 114 align-self: center; 115} 116</style> 117