-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmapper.html
744 lines (625 loc) · 34.6 KB
/
mapper.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
<script src="https://cdnjs.cloudflare.com/ajax/libs/svg.js/3.1.2/svg.min.js" type="text/javascript"></script>
<script type="text/javascript">
const editorPadding = 10;
const keyframeShift = 5;
var global = {}
RED.nodes.registerType('mapper', {
category: 'function',
color: '#59b1c3',
defaults: {
name: { value: "" },
inputFrom: { value: 0, required: true },
inputTo: { value: 100, required: true },
outputFrom: { value: 0, required: true },
outputTo: { value: 100, required: true },
rounding: {value: 0, required: true },
inputOutOfRangeStrategy: {value: 'block', required: true},
keyframesHash: {value: ''},
gridX : {value: 10},
gridY: {value: 10},
property: {value:"payload", required:true},
keyframes: {
value: [
{
x: 0,
y: 0,
},
{
x: 1,
y: 1,
},
]
},
snapToGrid: {value: false},
displayRoundedInput: {value: true}
},
inputs: 1,
outputs: 1,
icon: "mapper.svg",
label: function () {
return this.name || "mapper";
},
labelStyle: function () { return this.name ? "node_label_italic" : ""; },
inputLabels: "any message",
oneditprepare: function () {
const presets = [
{ name: 'linear', keyframes: [{x:0,y:0}, {x:1,y:1}] },
{ name: 'linear inverted', keyframes: [{x:0,y:1}, {x:1,y:0}] },
{ name: 'triangle', keyframes: [{x:0,y:0}, {x:0.5,y:1}, {x:1,y:0}] },
{ name: 'trapeze', keyframes: [{x:0,y:0}, {x:0.3,y:1},{x:0.7,y:1}, {x:1,y:0}] },
{ name: 'gausian like', keyframes: [{x:0,y:0},{x:0.2,y:0.05},{x:0.3,y:0.2},{x:0.4,y:0.8},{x:0.45,y:0.95},{x:0.5,y:1},{x:0.55,y:0.95},{x:0.6,y:0.8},{x:0.7,y:0.2},{x:0.8,y:0.05},{x:1,y:0},] },
{ name: 'impulse', keyframes: [{x:0,y:0}, {x:0.3,y:0},{x:0.3,y:1},{x:0.7,y:1},{x:0.7,y:0}, {x:1,y:0}] },
{ name: 'treshold', keyframes: [{x:0,y:0}, {x:0.5,y:0},{x:0.5,y:1},{x:1,y:1}] },
{ name: 'mapper logo', keyframes: [{x:0,y:0},{x:0.2,y:0.8}, {x:0.4,y:0.8},{x:0.7,y:0.2}, {x:1,y:1}] }
]
const previewHeight = 40
const previewWidth = 80
var presetsOptionsHtml = '';
for(var i = 0; i < presets.length; i++){
let linesHtml = '';
for(var j=0; j<presets[i].keyframes.length-1; j++)
{
const x1 = Math.round(interpolateLinear(0, previewWidth, presets[i].keyframes[j].x));
const y1 = Math.round(interpolateLinear(previewHeight, 0, presets[i].keyframes[j].y));
const x2 = Math.round(interpolateLinear(0, previewWidth, presets[i].keyframes[j+1].x));
const y2 = Math.round(interpolateLinear(previewHeight, 0, presets[i].keyframes[j+1].y));
linesHtml += `<line x1="${x1}" y1="${y1}" x2="${x2}" y2="${y2}" style="stroke:#eee;stroke-width:2" />`
}
presetsOptionsHtml += `<li><a href="#" data-preset-id="${i}">
<svg id="preset-${i}" width="${previewWidth}" height="${previewHeight}" style="border: 5px solid #0a0a0a">
<rect width="100%" height="100%" style="fill: #0a0a0a; "/>
${linesHtml}
</svg>
<div>
${presets[i].name}
<br><span>${presets[i].keyframes.length} points</span>
</div>
</a></li>`
}
$('#presets-list').append(presetsOptionsHtml)
$('#presets-list a').each(function(){
$(this).click(function(){
let presetId = Number($(this).attr('data-preset-id'))
n.keyframes = [...presets[presetId].keyframes]
global.draw()
$('#keyframe-editor').focus()
})
})
var presetsListMenuTracker = function (event) {
var e = $(event.target);
if (($(e).attr('id') !== 'load-preset') && $(e).parents('#load-preset').length < 1) {
$('#presets-list').css("display", 'none')
$(document).off('click', presetsListMenuTracker)
}
}
$('#load-preset').click(function () {
if ($('#presets-list').css("display") === 'none') {
$('#presets-list').css("display", 'block')
$(document).on('click', presetsListMenuTracker)
}
else {
$('#presets-list').css("display", 'none')
$(document).off('click', presetsListMenuTracker)
}
})
if (this.property === undefined) {
$("#node-input-property").val("payload");
}
$("#node-input-property").typedInput({default:'msg',types:['msg']});
function interpolateLinear(a, b, x) {
return ((b * x) + (a * (1 - x)));
};
function normalize(x, min, max) {
if (max == min)
return 0;
return (x - min) / (max - min);
};
var n = this;
$.when( $.getScript('mapper/js/svg.draggable.js/svg.draggable.min.js')).done(
function (data, textStatus, jqxhr)
{
var editor = $("#keyframe-editor");
let editedKeyframe = null
let editedKeyframeIndex = null
var svg = SVG().addTo("#keyframe-editor").size('100%', '100%');
n.svg = svg;
svg.on('mousemove', onMouseMove)
svg.on('mouseleave', onMouseLeave)
svg.on('click', onEditorMouseClick)
var gridGroup = svg.group().addClass('grid-group');;
var linksGroup = svg.group().addClass('links-group');
var keyframesGroup = svg.group().addClass('keyframes-group');
var keyframeId = 0
$('#node-input-gridX').on('change keyup paste',
function()
{
n.gridX = Number($(this).val())
global.draw()
})
$('#node-input-gridY').on('change keyup paste',
function()
{
n.gridY = Number($(this).val())
global.draw()
})
$('#node-input-inputFrom').on('change keyup paste', draw)
$('#node-input-inputTo').on('change keyup paste', draw)
$('#node-input-outputFrom').on('change keyup paste', draw)
$('#node-input-outputTo').on('change keyup paste', draw)
draw()
function onLinkClick(e)
{
let editorHeight = editor.height();
let editorWidth = editor.width();
let link = e.target;
let editorSvg = $("#keyframe-editor svg")[0];
let ownerId = link.instance.data('owner');
let x = e.clientX - editorSvg.getBoundingClientRect().x - keyframeShift;
let y = e.clientY - editorSvg.getBoundingClientRect().y - keyframeShift;
let keyframe =
{
x: normalize(x, editorPadding - keyframeShift, editorWidth - editorPadding * 2 + keyframeShift),
y: normalize(y, editorHeight - editorPadding * 2 + keyframeShift, editorPadding - keyframeShift)
}
n.keyframes.splice(ownerId, 0, keyframe)
draw()
}
function onKeyframeContextMenu(e)
{
e.preventDefault();
var keyframe = e.target
var id = keyframe.instance.data('id');
//don't remove first and last keyframes
if( id === 0 || id === n.keyframes.length-1)
return
n.keyframes.splice(id,1)
draw()
}
function onEditorMouseClick(e)
{
if(editedKeyframe != null)
{
editedKeyframe = null
editedKeyframeIndex = null
$('#editor-position-tooltip #editor-x').off('input', onKeyframeEditorChange)
$('#editor-position-tooltip #editor-y').off('input', onKeyframeEditorChange)
onMouseMove(e)
draw()
}
}
function onKeyframeDoubleClick(e)
{
e.preventDefault();
var target = e.target
var currentKeyframeId = target.instance.data('id');
let keyframe = n.keyframes[currentKeyframeId]
let {x, y} = normalizedToReal(keyframe.x,keyframe.y)
let xBlocked = false
if (currentKeyframeId === 0 || currentKeyframeId === n.keyframes.length-1)
xBlocked = true
let rounding = Number($('#node-input-rounding').val())
if(rounding === -1)
rounding = 8
let displayRoundedInput = $("#node-input-displayRoundedInput").is(':checked')
$('#editor-position-tooltip').css({left: target.x + 64, top: target.y + 128, opacity: .9}).html(`IN <input type="number" id="editor-x" value="${displayRoundedInput ? x.toFixed(rounding): x}" ${xBlocked ? 'readonly' : ''}> OUT <input type="number" id="editor-y" value="${y.toFixed(rounding)}">`)
$('#editor-position-tooltip #editor-x').on('input', onKeyframeEditorChange)
$('#editor-position-tooltip #editor-y').on('input', onKeyframeEditorChange)
editedKeyframe = keyframe
editedKeyframeIndex = currentKeyframeId
draw()
}
function onKeyframeEditorChange(element)
{
let el = $(element.target)
let inputFrom = Number($('#node-input-inputFrom').val())
let inputTo = Number($('#node-input-inputTo').val())
let outputFrom = Number($('#node-input-outputFrom').val())
let outputTo = Number($('#node-input-outputTo').val())
switch(el[0].id)
{
case 'editor-x':
let x = Number(el.val())
//limit middle keyframes to left and right keyframes
let leftKeyframe = normalizedToReal(n.keyframes[editedKeyframeIndex-1].x,0)
let rightKeyframe = normalizedToReal(n.keyframes[editedKeyframeIndex+1].x,0)
if( x < leftKeyframe.x)
{
el.addClass('error')
setTimeout(()=>{$(`#keyframe-editor g.keyframes-group rect[data-id=${editedKeyframeIndex-1}]`).fadeOut(100).fadeIn(100).fadeOut(100).fadeIn(100)}
, 100)
x = Math.min(rightKeyframe.x, Math.max(leftKeyframe.x, x))
}
else if( x > rightKeyframe.x)
{
el.addClass('error')
setTimeout(()=>{$(`#keyframe-editor g.keyframes-group rect[data-id=${editedKeyframeIndex+1}]`).fadeOut(100).fadeIn(100).fadeOut(100).fadeIn(100)}
, 100)
x = Math.min(rightKeyframe.x, Math.max(leftKeyframe.x, x))
}
else
{
el.removeClass('error')
}
x = normalize(x, inputFrom, inputTo)
editedKeyframe.x = x
break;
case 'editor-y':
let y = Number(el.val())
if(y < outputFrom || y > outputTo)
{
el.addClass('error')
if(y < outputFrom)
$('#node-input-outputFrom').fadeOut(100).fadeIn(100).fadeOut(100).fadeIn(100)
else if(y > outputTo)
$('#node-input-outputTo').fadeOut(100).fadeIn(100).fadeOut(100).fadeIn(100)
y = Math.min(outputTo, Math.max(outputFrom, y))
}
else
{
el.removeClass('error')
}
y = normalize(y, outputFrom, outputTo)
editedKeyframe.y = y
break;
}
draw()
}
function onKeyframeDrag(e)
{
e.preventDefault();
let editorHeight = editor.height();
let editorWidth = editor.width();
const { handler, box } = e.detail;
let { x, y } = box;
let currentKeyframeId = handler.el.data('id')
// limit movement to window
if (x < editorPadding - keyframeShift)
x = editorPadding - keyframeShift;
if (y < editorPadding - keyframeShift)
y = editorPadding - keyframeShift;
if (box.x2 > editorWidth - editorPadding + keyframeShift)
x = editorWidth - editorPadding + keyframeShift - box.w;
if (box.y2 > editorHeight - editorPadding + keyframeShift)
y = editorHeight - editorPadding + keyframeShift - box.h;
let leftKeyframe = $(`#keyframe-editor g.keyframes-group rect[data-id=${currentKeyframeId-1}]`)[0]
let rightKeyframe = $(`#keyframe-editor g.keyframes-group rect[data-id=${currentKeyframeId+1}]`)[0]
if($("#node-input-snapToGrid").is(':checked'))
{
if(n.gridX > 0)
{
let gridXPadding = (editorWidth - editorPadding * 2) / n.gridX
if(gridXPadding !== 0 )
x = Math.round(x / gridXPadding) * gridXPadding + keyframeShift;
}
if(n.gridY > 0)
{
let gridYPadding = (editorHeight - editorPadding * 2) / n.gridY
if( gridYPadding !== 0)
y = Math.round(y / gridYPadding) * gridYPadding + keyframeShift;
}
}
// limit first and last keyframe to vertical move only
if (currentKeyframeId === 0)
x = editorPadding - keyframeShift;
else if (currentKeyframeId === n.keyframes.length-1)
x = editorWidth - 2 * editorPadding + keyframeShift;
else
{
//limit middle keyframes to left and right keyframes
x = Math.max(x,leftKeyframe.instance.x())
x = Math.min(x, rightKeyframe.instance.x())
}
//redraw left and right links
let leftLink = $(`#keyframe-editor g.links-group line[data-owner=${currentKeyframeId}]`)[0]
let rightLink = $(`#keyframe-editor g.links-group line[data-owner=${currentKeyframeId+1}]`)[0]
if (leftLink)
leftLink.instance.plot(leftKeyframe.instance.x() + keyframeShift, leftKeyframe.instance.y() + keyframeShift, x + keyframeShift, y + keyframeShift)
if (rightLink)
rightLink.instance.plot(x + keyframeShift, y + keyframeShift, rightKeyframe.instance.x() + keyframeShift, rightKeyframe.instance.y() + keyframeShift);
let keyframe =
{
x: normalize(x, editorPadding - keyframeShift, editorWidth - editorPadding * 2 + keyframeShift),
y: normalize(y, editorHeight - editorPadding * 2 + keyframeShift, editorPadding - keyframeShift)
}
n.keyframes[currentKeyframeId] = keyframe
displayTooltip(x, y, keyframe.x, keyframe.y)
handler.move(x, y)
}
function normalizedToReal(normalizedX, normalizedY)
{
let inputFrom = Number($('#node-input-inputFrom').val())
let inputTo = Number($('#node-input-inputTo').val())
let outputFrom = Number($('#node-input-outputFrom').val())
let outputTo = Number($('#node-input-outputTo').val())
return {
x: interpolateLinear(inputFrom, inputTo, normalizedX),
y: interpolateLinear(outputFrom, outputTo, normalizedY)
}
}
function displayTooltip(posX, posY, normalizedX, normalizedY)
{
let {x, y} = normalizedToReal(normalizedX,normalizedY)
let rounding = Number($('#node-input-rounding').val())
if(rounding === -1)
rounding = 8
let displayRoundedInput = $("#node-input-displayRoundedInput").is(':checked')
$('#editor-position-tooltip').css({left: posX + 48, top: posY + 128, opacity: .9}).html(`${displayRoundedInput ? x.toFixed(rounding) : x}, ${y.toFixed(rounding)}`)
}
function onMouseMove(e)
{
if(editedKeyframe == null)
{
let svgEditor = $("#keyframe-editor svg")[0];
let x = e.clientX - svgEditor.getBoundingClientRect().left - keyframeShift;
let y = e.clientY - svgEditor.getBoundingClientRect().top - keyframeShift;
let keyframe =
{
x: normalize(x, editorPadding - keyframeShift, editor.width() - editorPadding * 2 + keyframeShift),
y: normalize(y, editor.height() - editorPadding * 2 + keyframeShift, editorPadding - keyframeShift)
}
keyframe.x = Math.max(0, Math.min(1, keyframe.x))
keyframe.y = Math.max(0, Math.min(1, keyframe.y))
displayTooltip(x, y, keyframe.x, keyframe.y)
}
}
function onMouseLeave(e)
{
if(editedKeyframe == null)
$('#editor-position-tooltip').css({opacity: .0})
}
function draw()
{
linksGroup.clear()
keyframesGroup.clear()
gridGroup.clear()
keyframeId = 0
let editorHeight = editor.height();
let editorWidth = editor.width();
gridGroup.rect(editorWidth - editorPadding * 2, editorHeight - editorPadding * 2).move(editorPadding, editorPadding).attr({ stroke: '#666', 'stroke-width': 1, 'fill-opacity': 0.8 });
let inputFrom = Number($('#node-input-inputFrom').val())
let inputTo = Number($('#node-input-inputTo').val())
let outputFrom = Number($('#node-input-outputFrom').val())
let outputTo = Number($('#node-input-outputTo').val())
if(n.gridX > 0)
{
let xStep = (inputTo-inputFrom)/n.gridX
let gridXPadding = (editorWidth - editorPadding * 2) / n.gridX
for(let i = 0; i < n.gridX; i++)
{
if(i>0)
gridGroup.line( editorPadding + gridXPadding*i, editorPadding, editorPadding + gridXPadding*i, editorHeight-editorPadding).stroke({color: '#555', width: 1})
let number = (inputFrom+(xStep*i)).toFixed(1)
if(number.substr(-1) == "0")
number = number.substr(0, number.indexOf('.'))
gridGroup.text( number ).move(editorPadding + gridXPadding*i + 4, editorHeight - editorPadding - 18).attr({fill: '#555'})
}
}
if(n.gridY > 0)
{
let yStep = (outputTo-outputFrom)/n.gridY
let gridYPadding = (editorHeight - editorPadding * 2) / n.gridY
for(let i = 1; i < n.gridY; i++)
{
gridGroup.line( editorPadding, editorPadding + gridYPadding*i, editorWidth - editorPadding, editorPadding + gridYPadding*i).stroke({color: '#555', width: 1})
let number = (outputFrom+(yStep*i)).toFixed(1)
if(number.substr(-1) == "0")
number = number.substr(0, number.indexOf('.'))
let text = gridGroup.text( number )
text.move(editorWidth - editorPadding - text.bbox().width - 4, editorHeight - editorPadding - gridYPadding*i - 18 ).attr({fill: '#555'})
}
}
let previousKeyframe = null
for(let i = 0; i < n.keyframes.length; i++)
{
const x = Math.round(interpolateLinear(editorPadding - keyframeShift, editorWidth - editorPadding * 2 + keyframeShift, n.keyframes[i].x));
const y = Math.round(interpolateLinear(editorHeight - editorPadding * 2 + keyframeShift, editorPadding - keyframeShift, n.keyframes[i].y));
let keyframeColor = '#bbb'
if(i === editedKeyframeIndex)
keyframeColor = 'yellow'
let keyframe = keyframesGroup.rect(keyframeShift*2,keyframeShift*2).attr({fill: keyframeColor, x: x, y: y});
keyframe.stroke({color: '#eee', width: 2});
keyframe.draggable();
keyframe.data('id', keyframeId);
keyframe.on('dragmove.namespace', onKeyframeDrag)
keyframe.on('dblclick', onKeyframeDoubleClick)
keyframe.on('contextmenu', onKeyframeContextMenu)
if( i > 0 )
{
let link = linksGroup.line(previousKeyframe.x() + keyframeShift, previousKeyframe.y() + keyframeShift, keyframe.x() + keyframeShift, keyframe.y() + keyframeShift).stroke({ color: '#eee', width: 3 })
link.data('owner', keyframeId);
link.on('click', onLinkClick)
}
previousKeyframe = keyframe
keyframeId++
}
}
global.draw = draw
})
.fail(function (jqxhr, settings, exception) {
console.log("failed");
console.log(exception);
console.log(exception.stack);
});
},
oneditsave: function ()
{
var config = this;
if (config.keyframes.length < 2)
config.keyframes =
[
{
x: 0,
y: 0,
},
{
x: 1,
y: 1,
},
]
function hash(s)
{
var hash = 0, i, chr;
if (s.length === 0) return hash;
for (i = 0; i < s.length; i++) {
chr = s.charCodeAt(i);
hash = ((hash << 5) - hash) + chr;
hash |= 0;
}
return hash;
}
config.keyframesHash = hash(JSON.stringify(config.keyframes))
},
oneditresize: function()
{
if(global.draw !== undefined )
global.draw();
}
});
</script>
<script type="text/x-red" data-template-name="mapper">
<style>
#keyframe-editor, #drawing {
border: 1px solid #111;
background-color: #333;
height: 400px;
width: 100%;
padding: 0;
}
.grid {
display: grid;
grid-template-columns: auto 80px 0px;
grid-template-rows: auto 20px 20px 30px;
grid-gap: 4px;
}
.grid input {
width: 60px !important;
text-align: right;
}
#editor-position-tooltip {
position: absolute;
padding: 4px;
background-color: yellow;
border: 1px solid #888;
color: black;
opacity: 0;
transition: opacity 0.3s;
border-radius: 5px;
z-index: 100;
}
#editor-x, #editor-y {
width: 110px !important;
}
#keyframe-editor .error {
background-color: red;
color: white;
}
.preset-container {
position: relative;
}
#presets-list a {
display: flex;
flex-direction: row;
justify-content: flex-start;
align-items: center;
}
#presets-list a div{
width: 200px;
margin-left: 16px;
font-weight: bold;
}
#presets-list a div span{
opacity: 0.6;
}
</style>
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name">
</div>
<div class="form-row">
<label for="node-input-property"><i class="fa fa-ellipsis-h"></i> Property</label>
<input type="text" id="node-input-property">
</div>
<div class="form-row" style="display: flex;">
<div>
<input style="width: auto; display: inline-block; vertical-align: top;" type="checkbox" id="node-input-snapToGrid">
<label style="width: auto;" for="node-input-snapToGrid"> Snap to grid</label>
</div>
<div style="margin-left: 32px;">
<input style="width: auto; display: inline-block; vertical-align: top;" type="checkbox" id="node-input-displayRoundedInput">
<label style="width: auto;" for="node-input-displayRoundedInput"> Display rounded input</label>
</div>
</div>
<div class="form-row preset-container">
<button id="load-preset"><i class="fa fa-area-chart"></i> Choose preset</button>
<ul id="presets-list" class="red-ui-menu-dropdown" style="width: auto !important;">
</ul>
</div>
<div class="form-row">
<div class="grid">
<div id="keyframe-editor" style="grid-column: 1; grid-row: 1">
<div id="editor-position-tooltip"></div>
</div>
<div style="grid-row: 1; grid-column: 2; display: flex; justify-content:space-between; flex-direction: column; align-items: start;">
<input id="node-input-outputTo">
<div>
<div style="transform: rotate(270deg) translateY(-30px)"><i class="fa fa-long-arrow-left" style="transform: scaleX(3) translate(-10px, 21px);"></i> output range <i class="fa fa-long-arrow-right" style="transform: scaleX(3) translate(35px, -20px);"></i></div>
<input style="background-color: #333; color: #999; text-align: center; width: 45px !important; transform: translate(35px, -30px);" id="node-input-gridY">
</div>
<input id="node-input-outputFrom">
</div>
<div style="grid-row: 2; grid-column: 1; display: flex; justify-content:space-between; flex-direction: row; align-items: baseline;">
<input id="node-input-inputFrom">
<div><i class="fa fa-long-arrow-left" style="transform: scaleX(3) translateX(-4px);"></i> input range <i class="fa fa-long-arrow-right" style="transform: scaleX(3) translateX(4px);"></i></div>
<input id="node-input-inputTo">
</div>
<div style="grid-row: 4; grid-column: 1; display: flex; justify-content: center;">
<input style="background-color: #333; color: #999; text-align: center; width: 45px !important;" id="node-input-gridX">
</div>
</div>
</div>
<div class="form-row">
<p><i class="fa fa-arrows-h"></i> Input out of range strategy</p>
<label for="node-input-name"></label>
<select id="node-input-inputOutOfRangeStrategy">
<option value="leave">leave unchanged</option>
<option value="block">block message</option>
<option value="limitKeyframe">limit to keyframes</option>
<option value="limitRange">limit to output range</option>
</select>
</div>
<div class="form-row">
<label for="node-input-name"><i class="fa fa-dot-circle-o"></i> Rounding</label>
<select id="node-input-rounding">
<option selected="selected" value="0">1</option>
<option value="1">0.1</option>
<option value="2">0.01</option>
<option value="3">0.001</option>
<option value="4">0.0001</option>
<option value="5">0.00001</option>
<option value="-1">disabled</option>
</select>
</div>
</script>
<script type="text/x-red" data-help-name="mapper">
<p>Maps input to output value with multiple editable sections.</p>
<h3>Overview</h3>
<p>Mapper performs multi-segment value mapping from one value to another. You can edit map function by drawing it in the editor.</p>
<p>To <b>add new keyframe</b> click on the line between two other keyframes with You left mouse button.</p>
<p>To <b>remove keyframe</b> click on the keyframe with the right mouse button.</p>
<p>You cannot remove first and last keyframes and their positions stick to minimum and maximum input values.</p>
<p>To <b>edit specific keyframe values</b> double click on a keyframe</p>
<p>Red background indicates that the entered value exceeds one of the constraints values (left or right keyframe on the input axis or min/max value on the output axis)</p>
<p>You can specify available <b>input range</b> by typing min and max value. If the input value is out of this range the <i>Input out of range strategy</i> will be applied.</p>
<ul>
<li><b>leave unchanged</b> - value will not be changed</li>
<li><b>block message</b> - will not produce any output. The whole message will be blocked.</li>
<li><b>limit to keyframes</b> - output value will be limited to corresponding keyframe value.</li>
<li><b>limit to output range</b> - output value will be limited to output range values.</li>
</ul>
<p>The <b>Rounding</b> options apply output truncation to specified decimal digits. For example rounding 3.1415 to 1 produces 3, to 0.1 produces 3.1, 0.01 produces 3.14 and so on.
Selected rounding option has an effect on a tooltip and keyframe editor.
You can also disable rounding.</p>
<p>The editor can be divided to a custom number of grid lines (dark edit controls).</p>
<p><b>Snap to grid</b> option will do a snapping when keyframe is being dragged</p>
<p><b>Display rounded input</b> option will round input value in a tooltip and a keyframe editor window</p>
</script>