-
Notifications
You must be signed in to change notification settings - Fork 5
/
cross-hair.html
88 lines (83 loc) · 2.08 KB
/
cross-hair.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<link rel="import" href="bower_components/polymer/polymer.html">
<dom-module id="cross-hair">
<style type="text/css">
:host {
position: absolute;
top: 0px;
left: 0px;
height: 100%;
width: 100%;
overflow: hidden;
}
</style>
<template><svg></svg></template>
<script>
"use strict";
Polymer({
is: 'cross-hair',
properties:{
x: {
type: Number,
value: 0,
notify: true
},
y: {
type: Number,
value: 0,
notify: true
},
w: {
type: Number,
value: 0,
notify: true
},
left:{
type: Number,
value: 0,
notify: true
},
top: {
type: Number,
value: 0,
notify: true
},
r: {
type: Number,
value: 6,
notify: true
},
show_bars: {
type: Number,
value: 1, //1=horizontal, 2=vertical 3=both (only 1 is implemented)
notify: true
},
},
observers: [
'_update_svg(x, y, w, left, top, r, show_bars)'
],
_update_svg: function(x, y , w, left, top, r, show_bars){
this.debounce('update', function(){
let width = show_bars & 1 ? w : x+r+2;
let height = y+r+2;
let x_minus_r = x-r;
let x_plus_r = x+r;
let bars_1 = "";
if(show_bars & 1){
bars_1 = `<line x1='0' y1='${y}' x2='${x_minus_r}' y2='${y}' stroke='black' stroke-width='1'/>
<line x1='${w}' y1='${y}' x2='${x_plus_r}' y2='${y}' stroke='black' stroke-width='1'/>
<line x1='0' y1='${y}' x2='${x_minus_r}' y2='${y}' stroke='white' stroke-dasharray='2,2' stroke-width='1'/>
<line x1='${w}' y1='${y}' x2='${x_plus_r}' y2='${y}' stroke='white' stroke-dasharray='2,2' stroke-width='1'/>`
}
// TODO: add show_bars & 2
let svg = `<svg style='pointer-events:none;position:absolute;left:${left}px;top:${top}px;width:${width};height:${height}px;'
xmlns='http://www.w3.org/2000/svg' version='1.1'>
<circle cx='${x}' cy='${y}' r='${r}' stroke='black' stroke-width='1' fill='none'/>
<circle cx='${x}' cy='${y}' r='${r}' stroke='white' stroke-dasharray='2,2' stroke-width='1' fill='none'/>
${bars_1}</svg>`;
Polymer.dom(this.root).innerHTML = svg;
Polymer.dom.flush();
});
}
});
</script>
</dom-module>