@teachinglab/omd 0.7.28 → 0.7.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/jsvg/jsvg.js +19 -0
- package/package.json +1 -1
- package/src/omdShapes.js +58 -6
package/jsvg/jsvg.js
CHANGED
|
@@ -400,6 +400,25 @@ export class jsvgEllipse extends jsvgObject
|
|
|
400
400
|
this.height = h;
|
|
401
401
|
this.svgObject.setAttribute("ry", (this.height/2).toString() );
|
|
402
402
|
}
|
|
403
|
+
|
|
404
|
+
setPosition( x, y )
|
|
405
|
+
{
|
|
406
|
+
this.xpos = x;
|
|
407
|
+
this.ypos = y;
|
|
408
|
+
this.svgObject.setAttribute("cx", x.toString() );
|
|
409
|
+
this.svgObject.setAttribute("cy", y.toString() );
|
|
410
|
+
this.svgObject.setAttribute("transform", "" );
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
updateTransform()
|
|
414
|
+
{
|
|
415
|
+
var transformParams = "";
|
|
416
|
+
if ( this.scale != 1.0 )
|
|
417
|
+
transformParams += " scale(" + this.scale.toString() + ")";
|
|
418
|
+
if ( this.rotation != 0.0 )
|
|
419
|
+
transformParams += " rotate(" + this.rotation + ")";
|
|
420
|
+
this.svgObject.setAttribute("transform", transformParams.trim() );
|
|
421
|
+
}
|
|
403
422
|
}
|
|
404
423
|
|
|
405
424
|
|
package/package.json
CHANGED
package/src/omdShapes.js
CHANGED
|
@@ -148,10 +148,15 @@ export class omdIsoscelesTriangle extends jsvgGroup
|
|
|
148
148
|
{
|
|
149
149
|
this.shapePath.clearPoints();
|
|
150
150
|
|
|
151
|
-
|
|
152
|
-
this.
|
|
153
|
-
|
|
154
|
-
|
|
151
|
+
const baseWidth = this.unitScale * this.triangleBase;
|
|
152
|
+
const triangleHeight = this.unitScale * this.triangleHeight;
|
|
153
|
+
const offsetX = 10;
|
|
154
|
+
const offsetY = triangleHeight + 10;
|
|
155
|
+
|
|
156
|
+
this.shapePath.addPoint( offsetX, offsetY );
|
|
157
|
+
this.shapePath.addPoint( offsetX + baseWidth, offsetY );
|
|
158
|
+
this.shapePath.addPoint( offsetX + baseWidth * 0.5, offsetY - triangleHeight );
|
|
159
|
+
this.shapePath.addPoint( offsetX, offsetY );
|
|
155
160
|
|
|
156
161
|
this.shapePath.updatePath();
|
|
157
162
|
|
|
@@ -259,6 +264,7 @@ export class omdEllipse extends jsvgGroup
|
|
|
259
264
|
this.rectWidth = 10;
|
|
260
265
|
this.rectHeight = 5;
|
|
261
266
|
this.unitScale = 10;
|
|
267
|
+
this.showLabels = false;
|
|
262
268
|
|
|
263
269
|
this.shapePath = new jsvgEllipse();
|
|
264
270
|
this.shapePath.setWidthAndHeight( this.rectWidth*this.unitScale, this.rectHeight*this.unitScale );
|
|
@@ -267,6 +273,9 @@ export class omdEllipse extends jsvgGroup
|
|
|
267
273
|
this.shapePath.setFillColor( omdColor.lightGray );
|
|
268
274
|
this.addChild( this.shapePath );
|
|
269
275
|
|
|
276
|
+
this.labelsHolder = new jsvgGroup();
|
|
277
|
+
this.addChild( this.labelsHolder );
|
|
278
|
+
|
|
270
279
|
this.updateLayout();
|
|
271
280
|
}
|
|
272
281
|
|
|
@@ -281,12 +290,32 @@ export class omdEllipse extends jsvgGroup
|
|
|
281
290
|
if ( typeof data.unitScale != "undefined" )
|
|
282
291
|
this.unitScale = data.unitScale;
|
|
283
292
|
|
|
293
|
+
if ( typeof data.showLabels != "undefined" )
|
|
294
|
+
this.showLabels = data.showLabels;
|
|
295
|
+
|
|
284
296
|
this.updateLayout();
|
|
285
297
|
}
|
|
286
298
|
|
|
287
299
|
updateLayout()
|
|
288
300
|
{
|
|
289
|
-
|
|
301
|
+
const ellipseWidth = this.rectWidth * this.unitScale;
|
|
302
|
+
const ellipseHeight = this.rectHeight * this.unitScale;
|
|
303
|
+
|
|
304
|
+
this.shapePath.setWidthAndHeight( ellipseWidth, ellipseHeight );
|
|
305
|
+
this.shapePath.setPosition( ellipseWidth * 0.5 + 10, ellipseHeight * 0.5 + 10 );
|
|
306
|
+
|
|
307
|
+
this.labelsHolder.removeAllChildren();
|
|
308
|
+
if ( this.showLabels )
|
|
309
|
+
{
|
|
310
|
+
const label = new jsvgTextLine();
|
|
311
|
+
label.setAlignment("center");
|
|
312
|
+
label.setFontFamily( "Albert Sans" );
|
|
313
|
+
label.setFontColor( "black" );
|
|
314
|
+
label.setFontSize( 12 );
|
|
315
|
+
label.setPosition( ellipseWidth * 0.5 + 10, ellipseHeight * 0.5 + 14 );
|
|
316
|
+
label.setText( `${this.rectWidth} × ${this.rectHeight}` );
|
|
317
|
+
this.labelsHolder.addChild( label );
|
|
318
|
+
}
|
|
290
319
|
|
|
291
320
|
// Set dimensions and viewBox for API compatibility
|
|
292
321
|
this.width = this.rectWidth * this.unitScale + 20;
|
|
@@ -306,6 +335,7 @@ export class omdCircle extends jsvgGroup
|
|
|
306
335
|
|
|
307
336
|
this.radius = 5;
|
|
308
337
|
this.unitScale = 10;
|
|
338
|
+
this.showLabels = false;
|
|
309
339
|
|
|
310
340
|
this.shapePath = new jsvgEllipse();
|
|
311
341
|
this.shapePath.setWidthAndHeight( this.radius*this.unitScale, this.radius*this.unitScale );
|
|
@@ -314,6 +344,9 @@ export class omdCircle extends jsvgGroup
|
|
|
314
344
|
this.shapePath.setFillColor( omdColor.lightGray );
|
|
315
345
|
this.addChild( this.shapePath );
|
|
316
346
|
|
|
347
|
+
this.labelsHolder = new jsvgGroup();
|
|
348
|
+
this.addChild( this.labelsHolder );
|
|
349
|
+
|
|
317
350
|
this.updateLayout();
|
|
318
351
|
}
|
|
319
352
|
|
|
@@ -325,12 +358,31 @@ export class omdCircle extends jsvgGroup
|
|
|
325
358
|
if ( typeof data.unitScale != "undefined" )
|
|
326
359
|
this.unitScale = data.unitScale;
|
|
327
360
|
|
|
361
|
+
if ( typeof data.showLabels != "undefined" )
|
|
362
|
+
this.showLabels = data.showLabels;
|
|
363
|
+
|
|
328
364
|
this.updateLayout();
|
|
329
365
|
}
|
|
330
366
|
|
|
331
367
|
updateLayout()
|
|
332
368
|
{
|
|
333
|
-
|
|
369
|
+
const diameter = 2.0 * this.radius * this.unitScale;
|
|
370
|
+
|
|
371
|
+
this.shapePath.setWidthAndHeight( diameter, diameter );
|
|
372
|
+
this.shapePath.setPosition( this.radius * this.unitScale + 10, this.radius * this.unitScale + 10 );
|
|
373
|
+
|
|
374
|
+
this.labelsHolder.removeAllChildren();
|
|
375
|
+
if ( this.showLabels )
|
|
376
|
+
{
|
|
377
|
+
const label = new jsvgTextLine();
|
|
378
|
+
label.setAlignment("center");
|
|
379
|
+
label.setFontFamily( "Albert Sans" );
|
|
380
|
+
label.setFontColor( "black" );
|
|
381
|
+
label.setFontSize( 12 );
|
|
382
|
+
label.setPosition( this.radius * this.unitScale + 10, this.radius * this.unitScale + 14 );
|
|
383
|
+
label.setText( `r=${this.radius}` );
|
|
384
|
+
this.labelsHolder.addChild( label );
|
|
385
|
+
}
|
|
334
386
|
|
|
335
387
|
// Set dimensions and viewBox for API compatibility
|
|
336
388
|
this.width = 2.0 * this.radius * this.unitScale + 20;
|