clone a jsxGraph objet

198 views
Skip to first unread message

Ciola

unread,
Aug 10, 2013, 12:27:28 AM8/10/13
to jsxg...@googlegroups.com
Hello everybody,
I would like to copy un jsxGraph objet. I tried to do this with any js tolls, but without succes.
I would like to duplicate a text before to rotate it in order to conserve the antecedent.
Thanking you in advance.


JXG.Options.text.display = 'internal';
var brd = JXG.JSXGraph.initBoard('box', {boundingbox: [-2, 2, 2, -2], axis:true, showCopyright:false, showNavigation:false});

var point = function(a, b){
return brd.create('point', [a, b]);
};

var texte = function(message, taille){
return brd.create('text',[-2,-1, message], {fontSize:taille});
};

var rotation = function(centre, angle, text){
      //var image = texte('Salut', 50);
   var image = jQuery.extend(true, {}, text);
var tRot = brd.create('transform',[Math.PI/180.0 * angle,function(){return centre.X();},function(){return centre.Y();}],{type:'rotate'}
);
tRot.bindTo(image);
brd.update();
return image;
};

var A= point(-1, -1);

var monTexte = texte('Salut', 50);
//monTexte.hideElement();
var monTexte1 = rotation(A, 45, monTexte);

michael

unread,
Aug 12, 2013, 5:21:22 AM8/12/13
to jsxg...@googlegroups.com
Hi,

I think the closest to cloning an object would be using the attributes and the parents of that element and create a new one:

original = brd.create('text', [-2,-1, message], {fontSize:taille});
copy = brd.create('text', original.getParents(), original.visProp);

I'm not sure if the text element's getParents() method returns the current or the original coordinates but this could be fixed.


Michael
Reply all
Reply to author
Forward
0 new messages