|
1 | 1 | <link rel="import" href="../polymer/polymer.html"> |
2 | 2 |
|
3 | 3 | <!-- |
4 | | -The `flightpanel-speed` element renders an analog Speed indicator. |
| 4 | +The `flightpanel-speed` element renders an analog Speed indicator. |
5 | 5 |
|
6 | 6 | @element flightpanel-speed |
7 | 7 | @status alpha |
8 | 8 | @homepage https://github.com/hb9cwp/flightpanel-speed |
9 | 9 | --> |
10 | 10 |
|
11 | | -<polymer-element name="flightpanel-speed" attributes="width height speed"> |
| 11 | +<dom-module id="flightpanel-speed"> |
12 | 12 |
|
13 | 13 | <template> |
14 | 14 | <link rel="stylesheet" href="flightpanel-speed.css"> |
|
28 | 28 | <script> |
29 | 29 | 'use strict'; |
30 | 30 | Polymer({ |
31 | | - /** |
32 | | - * Changes `width` of the indicator from its default (in px). |
33 | | - * |
34 | | - * @attribute width |
35 | | - * @type number |
36 | | - * @default 300 |
37 | | - */ |
38 | | - width: 300, |
39 | | - |
40 | | - /** |
41 | | - * Changes `height` of the indicator from its default (in px). |
42 | | - * |
43 | | - * @attribute height |
44 | | - * @type number |
45 | | - * @default 300 |
46 | | - */ |
47 | | - height: 300, |
48 | | - |
49 | | - /** |
50 | | - * The hand tracks the `speed` (in kts). |
51 | | - * |
52 | | - * @attribute speed |
53 | | - * @type number |
54 | | - * @default 0 |
55 | | - */ |
56 | | - speed: 0, |
| 31 | + is: "flightpanel-speed", |
| 32 | + properties: { |
| 33 | + /** |
| 34 | + * Changes `width` of the indicator from its default (in px). |
| 35 | + * |
| 36 | + * @attribute width |
| 37 | + * @type number |
| 38 | + * @default 300 |
| 39 | + */ |
| 40 | + width: 300, |
| 41 | + |
| 42 | + /** |
| 43 | + * Changes `height` of the indicator from its default (in px). |
| 44 | + * |
| 45 | + * @attribute height |
| 46 | + * @type number |
| 47 | + * @default 300 |
| 48 | + */ |
| 49 | + height: 300, |
| 50 | + |
| 51 | + /** |
| 52 | + * The hand tracks the `speed` (in kts). |
| 53 | + * |
| 54 | + * @attribute speed |
| 55 | + * @type number |
| 56 | + * @default 0 |
| 57 | + */ |
| 58 | + speed: 0, |
| 59 | + }, |
57 | 60 |
|
58 | 61 | min: 0, |
59 | 62 | max: 0, |
60 | 63 | angles: [], |
61 | 64 |
|
62 | 65 | created: function() { |
63 | | - // interpolation etc. |
| 66 | + // interpolation etc. |
64 | 67 | setup(this); |
65 | 68 | }, |
66 | | - |
| 69 | + |
67 | 70 | ctx1: null, |
68 | 71 | hand: null, |
69 | | - |
| 72 | + |
70 | 73 | // on ready, not on created, unlike shown in some examples! |
71 | 74 | ready: function () { |
72 | 75 | var that= this |
73 | | - |
| 76 | + |
74 | 77 | // using label ID |
75 | 78 | var canvas0 = this.$.canvas0; |
76 | 79 | var canvas1 = this.$.canvas1; |
77 | 80 | // or using class |
78 | 81 | //var canvas= this.shadowRoot.querySelector('.canvasClass') |
79 | 82 | var ctx0 = canvas0.getContext('2d') |
80 | 83 | that.ctx1 = canvas1.getContext('2d') |
81 | | - |
| 84 | + |
82 | 85 | var dial= new Image() |
83 | 86 | that.hand= new Image() |
84 | | - |
| 87 | + |
85 | 88 | dial.onload = function(){ |
86 | 89 | ctx0.drawImage(dial,0,0,that.width,that.height); // scale to canvas size |
87 | 90 | } |
88 | 91 | //dial.src= "../flightpanel-speed/speedDial.png" |
89 | | - dial.src= "./bower_components/flightpanel-speed/speedDial.png" |
90 | | - |
| 92 | + dial.src= "./speedDial.png" |
| 93 | + |
91 | 94 | that.hand.onload = function() { |
92 | 95 | /* Variant A: save/restore */ |
93 | 96 | // 0. save context, e.g. offset etc. |
|
113 | 116 | */ |
114 | 117 | } |
115 | 118 | //that.hand.src= "../flightpanel-speed/speedHand.png" |
116 | | - that.hand.src= "./bower_components/flightpanel-speed/speedHand.png" |
| 119 | + that.hand.src= "./speedHand.png" |
117 | 120 | }, |
118 | | - |
| 121 | + |
119 | 122 | speedChanged: function () { |
120 | 123 | var speed = Math.round(this.speed) |
121 | 124 | if (speed < this.min) { |
|
139 | 142 | this.ctx1.drawImage(this.hand,0,0,this.width,this.height) // scale to canvas size |
140 | 143 | */ |
141 | 144 | } |
142 | | - |
143 | | - |
| 145 | + |
| 146 | + |
144 | 147 | }); |
145 | | - |
| 148 | + |
146 | 149 | function setup(that) { |
147 | 150 | // from (scale modified for Si2) |
148 | 151 | // https://github.com/dmolin/flightSimPanels/blob/master/src/services/measures/speed/client/speed.js |
|
170 | 173 | }, |
171 | 174 | zeroAngle = 0, |
172 | 175 | angles = []; |
173 | | - |
| 176 | + |
174 | 177 | var keys = Object.keys(interp).sort(function(a, b) { |
175 | 178 | return parseInt(a, 10) - parseInt(b, 10); |
176 | 179 | }); |
177 | | - |
| 180 | + |
178 | 181 | var min = parseInt(keys[0], 10), |
179 | 182 | max = parseInt(keys[keys.length - 1], 10); |
180 | 183 |
|
|
200 | 203 | that.angles = angles; |
201 | 204 | console.log("setup() done!") |
202 | 205 | } |
203 | | - |
204 | 206 | </script> |
205 | | - |
206 | | -</polymer-element> |
| 207 | +</dom-module> |
0 commit comments