From 2cb45088d949e6321793d9247dcdeb8878fc89d1 Mon Sep 17 00:00:00 2001 From: Michael Silveira Date: Tue, 11 Jun 2013 21:26:41 -0700 Subject: [PATCH 1/2] add scale to TKAdjustableNumber --- TangleKit/TangleKit.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/TangleKit/TangleKit.js b/TangleKit/TangleKit.js index ca5dd12..7785867 100644 --- a/TangleKit/TangleKit.js +++ b/TangleKit/TangleKit.js @@ -131,6 +131,7 @@ Tangle.classes.TKNumberField = { // Attributes: data-min (optional): minimum value // data-max (optional): maximum value // data-step (optional): granularity of adjustment (can be fractional) +// data-scale (optional): rate of drag movements var isAnyAdjustableNumberDragging = false; // hack for dragging one value over another one @@ -144,6 +145,7 @@ Tangle.classes.TKAdjustableNumber = { this.min = (options.min !== undefined) ? parseFloat(options.min) : 0; this.max = (options.max !== undefined) ? parseFloat(options.max) : 1e100; this.step = (options.step !== undefined) ? parseFloat(options.step) : 1; + this.scale = (options.scale !== undefined) ? parseFloat(options.scale) : 1/5; this.initializeHover(); this.initializeHelp(); @@ -217,7 +219,7 @@ Tangle.classes.TKAdjustableNumber = { }, touchDidMove: function (touches) { - var value = this.valueAtMouseDown + touches.translation.x / 5 * this.step; + var value = this.valueAtMouseDown + touches.translation.x * this.scale * this.step; value = ((value / this.step).round() * this.step).limit(this.min, this.max); this.tangle.setValue(this.variable, value); this.updateHelp(); From 40f56ce75612dc8e89b0c28039db817e053566c0 Mon Sep 17 00:00:00 2001 From: Michael Silveira Date: Sun, 23 Jun 2013 22:34:32 -0700 Subject: [PATCH 2/2] Add toFixed to get rid of js rounding errors on decimal step-size --- TangleKit/TangleKit.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/TangleKit/TangleKit.js b/TangleKit/TangleKit.js index 7785867..276e74c 100644 --- a/TangleKit/TangleKit.js +++ b/TangleKit/TangleKit.js @@ -146,6 +146,7 @@ Tangle.classes.TKAdjustableNumber = { this.max = (options.max !== undefined) ? parseFloat(options.max) : 1e100; this.step = (options.step !== undefined) ? parseFloat(options.step) : 1; this.scale = (options.scale !== undefined) ? parseFloat(options.scale) : 1/5; + this.digits = (""+this.step).split('.')[1].length; this.initializeHover(); this.initializeHelp(); @@ -220,8 +221,8 @@ Tangle.classes.TKAdjustableNumber = { touchDidMove: function (touches) { var value = this.valueAtMouseDown + touches.translation.x * this.scale * this.step; - value = ((value / this.step).round() * this.step).limit(this.min, this.max); - this.tangle.setValue(this.variable, value); + value = ((value / this.step).round() * this.step).limit(this.min, this.max).toFixed(this.digits); + this.tangle.setValue(this.variable, parseFloat(value, 10)); this.updateHelp(); },