numbas / numbas-extension-jsxgraph

An extension for Numbas providing the JSXGraph library
Other
0 stars 0 forks source link

jsxGraph acts differently on regenerated question #2

Open YannickNeyt opened 3 years ago

YannickNeyt commented 3 years ago

I made a drawing with jsxGraph: image But if I preview the question, the labels are off. Only when I ask for a second try, the labels are corrected (and stay so for other generated questions): image I noticed that the second time, the labels 'jump' in the first second from the incorrect to the correct place, this 'jump' doesn't occur when I first open the question.

The code for the drawing:

var div = Numbas.extensions.jsxgraph.makeBoard('400px','400px',{boundingBox:[-8,8,8,-8],grid:false,axis:false});
var board = div.board;
var p1 = board.create('point',[-ha,hb], {fixed:true,visible: false,withLabel:false});
var p2 = board.create('point',[-ha+xx,hb], {fixed:true,visible: false,withLabel:false});
var p3 = board.create('point',[-ha+xx,-hb+xx], {fixed:true,visible: false,withLabel:false});
var p4 = board.create('point',[ha-xx,-hb+xx], {fixed:true,visible: false,withLabel:false});
var p5 = board.create('point',[ha-xx,hb], {fixed:true,visible: false,withLabel:false});
var p6 = board.create('point',[ha,hb], {fixed:true,visible: false,withLabel:false});
var p7 = board.create('point',[ha,-hb], {fixed:true,visible: false,withLabel:false});
var p8 = board.create('point',[-ha,-hb], {fixed:true,visible: false,withLabel:false});
var poly = board.create('polygon',[p1,p2,p3,p4,p5,p6,p7,p8], { borders:{strokeColor:'black'} });
var h0 = board.create('point', [-ha,hb-xx], {fixed:true,visible: false,withLabel:false});
var h1 = board.create('point', [-ha+xx,hb-xx], {fixed:true,visible: false,withLabel:false});
var h2 = board.create('point', [ha-xx,hb-xx], {fixed:true,visible: false,withLabel:false});
var h3 = board.create('point', [ha,hb-xx], {fixed:true,visible: false,withLabel:false});      
var hseg1 = board.create('segment', [h0,h1], {firstarrow:{type:2,size:4},lastarrow:{type:2,size:4},withLabel:true, name:'$x$',label:{position:'top',offset:[-4,12]}});
var hseg2 = board.create('segment', [h2,h3], {firstarrow:{type:2,size:4},lastarrow:{type:2,size:4},withLabel:true, name:'$x$',label:{position:'top',offset:[-4,12]}});
var v0 = board.create('point', [0,-hb+xx], {fixed:true,visible: false,withLabel:false});
var v1 = board.create('point', [0,-hb], {fixed:true,visible: false,withLabel:false});
var vseg = board.create('segment', [v0,v1], {firstarrow:{type:2,size:4},lastarrow:{type:2,size:4},withLabel:true, name:'$x$',label:{position:'top',offset:[8,0]}});
var b0 = board.create('point', [-ha,-hb-0.5], {fixed:true,visible: false,withLabel:false});
var b1 = board.create('point', [ha,-hb-0.5], {fixed:true,visible: false,withLabel:false});
var base = board.create('segment', [b0,b1], {firstarrow:{type:2,size:4},lastarrow:{type:2,size:4},withLabel:true, name:'$'+a+'$',label:{position:'bot',offset:[-6,-12]}});
var l0 = board.create('point', [ha+0.5,hb], {fixed:true,visible: false,withLabel:false});
var l1 = board.create('point', [ha+0.5,-hb], {fixed:true,visible: false,withLabel:false});
var length = board.create('segment', [l0,l1], {firstarrow:{type:2,size:4},lastarrow:{type:2,size:4},withLabel:true, name:'$'+b+'$',label:{position:'top',offset:[8,0]}});
return div;
christianp commented 3 years ago

Does adding a line board.update() just before the last line make it better? If so, I should make the extension do this for you.

christianp commented 3 years ago

@YannickNeyt did you look at this any more?

YannickNeyt commented 3 years ago

Sorry, I didn't, I just tried it, I don't think it changes anything.

ugoertz commented 3 years ago

I also noticed this (this question). In that question it's a very minor issue, but it is noticeable that the labels are a little closer to the red dots for "try another" questions. For some weird reason the label offsets are ignored when the first question is generated. The board update which I just added does not seem to help there, either.

christianp commented 1 year ago

Is this still a problem?

ugoertz commented 1 year ago

In the question I linked to the problem does not occur anymore. Thanks!