Skip to content

Commit e392496

Browse files
committed
Remove Base.toFloat() and replace with direct parseFloat() calls.
1 parent d3435ec commit e392496

3 files changed

Lines changed: 13 additions & 13 deletions

File tree

src/core/Base.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -469,11 +469,7 @@ this.Base = Base.inject(/** @lends Base# */{
469469
*/
470470
formatFloat: function(num, precision) {
471471
precision = precision ? Math.pow(10, precision) : 100000;
472-
return (Math.round(num * precision) / precision);
473-
},
474-
475-
toFloat: function(str) {
476-
return parseFloat(str, 10);
472+
return Math.round(num * precision) / precision;
477473
}
478474
}
479475
});

src/svg/SvgImport.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ new function() {
3030
// Base.pick(base.value, base)
3131
return base
3232
? index !== undefined
33+
// Item list? Look up by index:
3334
? index < base.numberOfItems
3435
? Base.pick((base = base.getItem(index)).value, base)
3536
: null
@@ -56,7 +57,7 @@ new function() {
5657
return value === 'none'
5758
? null
5859
: type === 'number'
59-
? Base.toFloat(value)
60+
? parseFloat(value)
6061
: type === 'array'
6162
? value ? value.split(/[\s,]+/g).map(parseFloat) : []
6263
: type === 'color' && getDefinition(value)
@@ -358,6 +359,9 @@ new function() {
358359
function applyAttributes(item, node) {
359360
// SVG attributes can be set both as styles and direct node attributes,
360361
// so we need to parse both
362+
// TODO: Instead of looping through the styles, we need to loop through
363+
// a list of styles relevant to SVG, and calculate the computed style,
364+
// to support style classes too.
361365
for (var i = 0, l = node.style.length; i < l; i++) {
362366
var name = node.style[i];
363367
item = applyAttribute(item, node, name, node.style[Base.camelize(name)]);
@@ -411,7 +415,7 @@ new function() {
411415
case 'stop-opacity':
412416
// http://www.w3.org/TR/SVG/masking.html#OpacityProperty
413417
case 'opacity':
414-
var opacity = Base.toFloat(value);
418+
var opacity = parseFloat(value);
415419
if (name === 'stop-opacity') {
416420
item.color.setAlpha(opacity);
417421
} else {
@@ -425,7 +429,7 @@ new function() {
425429
var color = item[name == 'fill-opacity' ? 'getFillColor'
426430
: 'getStrokeColor']();
427431
if (color)
428-
color.setAlpha(Base.toFloat(value));
432+
color.setAlpha(parseFloat(value));
429433
break;
430434
case 'visibility':
431435
item.setVisible(value === 'visible');
@@ -485,7 +489,7 @@ new function() {
485489
item.setFont(value.split(',')[0].replace(/^\s+|\s+$/g, ''));
486490
break;
487491
case 'font-size':
488-
item.setFontSize(Base.toFloat(value));
492+
item.setFontSize(parseFloat(value));
489493
break;
490494
case 'text-anchor':
491495
item.setJustification({

src/ui/Component.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,12 @@ var Component = this.Component = Base.extend(Callback, /** @lends Component# */{
129129
DomElement.set(this._inputItem, key, value);
130130
// Read back and convert from input again, to make sure we're in sync
131131
value = DomElement.get(this._inputItem, key);
132-
this._value = this._info.number ? Base.toFloat(value) : value;
132+
this._value = this._info.number ? parseFloat(value, 10) : value;
133133
},
134134

135135
getRange: function() {
136-
return [Base.toFloat(DomElement.get(this._inputItem, 'min')),
137-
Base.toFloat(DomElement.get(this._inputItem, 'max'))];
136+
return [parseFloat(DomElement.get(this._inputItem, 'min')),
137+
parseFloat(DomElement.get(this._inputItem, 'max'))];
138138
},
139139

140140
setRange: function(min, max) {
@@ -159,7 +159,7 @@ var Component = this.Component = Base.extend(Callback, /** @lends Component# */{
159159
},
160160

161161
getStep: function() {
162-
return Base.toFloat(DomElement.get(this._inputItem, 'step'));
162+
return parseFloat(DomElement.get(this._inputItem, 'step'));
163163
},
164164

165165
setStep: function(step) {

0 commit comments

Comments
 (0)