Skip to content

Commit b4bd6a5

Browse files
committed
Add min-max options for number types
1 parent a36c0f2 commit b4bd6a5

File tree

2 files changed

+26
-8
lines changed

2 files changed

+26
-8
lines changed

js/scripts/prop-types.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,25 +199,43 @@ _.extend(Bool.prototype, BaseType.prototype, {
199199
function Int(defaultValue, options) {
200200
options = options || {};
201201
this.nullable = options.nullable === true;
202+
this.minValue = options.minValue;
203+
this.maxValue = options.maxValue;
202204
this.defaultValue = (defaultValue === null || defaultValue === undefined) && !this.nullable ? 0 : defaultValue ;
203205
}
204206
_.extend(Int.prototype, BaseType.prototype, {
205207
getTraitlet: function() {
206208
var nullableStr = this.nullable ? 'True' : 'False';
207-
return `CInt(${this.getPythonDefaultValue()}, allow_none=${nullableStr}).tag(sync=True)`;
209+
var limits = '';
210+
if (this.minValue !== undefined) {
211+
limits += `, min=${this.minValue}`
212+
}
213+
if (this.maxValue !== undefined) {
214+
limits += `, max=${this.maxValue}`
215+
}
216+
return `CInt(${this.getPythonDefaultValue()}, allow_none=${nullableStr}${limits}).tag(sync=True)`;
208217
},
209218

210219
});
211220

212221
function Float(defaultValue, options) {
213222
options = options || {};
214223
this.nullable = options.nullable === true;
224+
this.minValue = options.minValue;
225+
this.maxValue = options.maxValue;
215226
this.defaultValue = (defaultValue === null || defaultValue === undefined) && !this.nullable ? 0.0 : defaultValue;
216227
}
217228
_.extend(Float.prototype, BaseType.prototype, {
218229
getTraitlet: function() {
219230
var nullableStr = this.nullable ? 'True' : 'False';
220-
return `CFloat(${this.getPythonDefaultValue()}, allow_none=${nullableStr}).tag(sync=True)`;
231+
var limits = '';
232+
if (this.minValue !== undefined) {
233+
limits += `, min=${this.minValue}`
234+
}
235+
if (this.maxValue !== undefined) {
236+
limits += `, max=${this.maxValue}`
237+
}
238+
return `CFloat(${this.getPythonDefaultValue()}, allow_none=${nullableStr}${limits}).tag(sync=True)`;
221239
},
222240
getPropertyConverterFn: function() {
223241
return 'convertFloat';

js/scripts/three-class-config.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1400,7 +1400,7 @@ module.exports = {
14001400
constructorArgs: [ 'radius', 'segments', 'thetaStart', 'thetaLength' ],
14011401
properties: {
14021402
radius: new Types.Float(50.0),
1403-
segments: new Types.Int(8), // TODO: min:3
1403+
segments: new Types.Int(8, {minValue: 3}),
14041404
thetaStart: new Types.Float(0.0),
14051405
thetaLength: new Types.Float(Math.PI * 2.0),
14061406
},
@@ -1411,7 +1411,7 @@ module.exports = {
14111411
constructorArgs: [ 'radius', 'segments', 'thetaStart', 'thetaLength' ],
14121412
properties: {
14131413
radius: new Types.Float(50.0),
1414-
segments: new Types.Int(8), // TODO: min:3
1414+
segments: new Types.Int(8, {minValue: 3}),
14151415
thetaStart: new Types.Float(0.0),
14161416
thetaLength: new Types.Float(Math.PI * 2.0),
14171417
},
@@ -1570,8 +1570,8 @@ module.exports = {
15701570
properties: {
15711571
innerRadius: new Types.Float(0.0), // Docs: "Default is 0, but it doesn't work right when innerRadius is set to 0.
15721572
outerRadius: new Types.Float(50.0),
1573-
thetaSegments: new Types.Int(8), // TODO: min: 3
1574-
phiSegments: new Types.Int(8), // TODO: min 1
1573+
thetaSegments: new Types.Int(8, {minValue: 3}),
1574+
phiSegments: new Types.Int(8, {minValue: 1}),
15751575
thetaStart: new Types.Float(0),
15761576
thetaLength: new Types.Float(Math.PI * 2),
15771577
},
@@ -1583,8 +1583,8 @@ module.exports = {
15831583
properties: {
15841584
innerRadius: new Types.Float(0.0), // Docs: "Default is 0, but it doesn't work right when innerRadius is set to 0.
15851585
outerRadius: new Types.Float(50.0),
1586-
thetaSegments: new Types.Int(8), // TODO: min: 3
1587-
phiSegments: new Types.Int(8), // TODO: min 1
1586+
thetaSegments: new Types.Int(8, {minValue: 3}),
1587+
phiSegments: new Types.Int(8, {minValue: 1}),
15881588
thetaStart: new Types.Float(0),
15891589
thetaLength: new Types.Float(Math.PI * 2),
15901590
},

0 commit comments

Comments
 (0)