Aligning text: Difference between revisions
From JSXGraph Wiki
A WASSERMANN (talk | contribs) No edit summary |
Andrewbaker (talk | contribs) m (Changed code style from italics to monospace font) |
||
(36 intermediate revisions by one other user not shown) | |||
Line 1: | Line 1: | ||
<html> | |||
<style type="text/css"> | |||
.mytext { | |||
border: 1px solid black; | |||
padding:2px; | |||
} | |||
</style> | |||
</html> | |||
Texts can be aligned with the attributes <code>anchorX</code> and <code>anchorY</code>. Possible values for <code>anchorX</code> are <code>'left'</code>, <code>'middle'</code>, and <code>'right'</code>. Possible values for <code>anchorY</code> are <code>'bottom'</code>, <code>'middle'</code>, and <code>'top'</code>. | |||
Text can be rotated if it is declared as <code>display: 'internal'</code>. For SVG this means, instead of an HTML div the SVG text is taken as text node. | |||
<jsxgraph width="600" height="600"> | <jsxgraph width="600" height="600"> | ||
var brd = JXG.JSXGraph.initBoard('jxgbox',{boundingbox: [-1,10, | var brd = JXG.JSXGraph.initBoard('jxgbox',{boundingbox: [-1,10,7,-1], axis:true, keepaspectratio:false}); | ||
// Vertical line at x=3 | |||
brd.create('line', [-3, 1, 0], {strokeWidth:1, dash:2}); | |||
brd.create('text', [3, 8, "Default"], {cssClass:'mytext'}); | |||
brd.create('text', [3, 7, "anchorX left"], {anchorX:'left', cssClass:'mytext'}); | |||
brd.create('text', [3, 6, "anchorX middle"], {anchorX:'middle', cssClass:'mytext'}); | |||
brd.create('text', [3, 5, "anchorX right"], {anchorX:'right', cssClass:'mytext'}); | |||
// Horizontal line at y=3 | |||
brd.create('line', [-3, 0, 1], {strokeWidth:1, dash:2}); | |||
brd.create('text', [1, 3, "Multiline text<br>default"], {cssClass:'mytext'}); | |||
brd.create('text', [2.2, 3, "Multiline text<br>anchorY bottom"], {anchorY:'bottom', cssClass:'mytext'}); | |||
brd.create('text', [3.4, 3, "Multiline text<br>anchorY middle"], {anchorY:'middle', cssClass:'mytext'}); | |||
brd.create('text', [4.6, 3, "Multiline text<br>anchorY top"], {anchorY:'top', cssClass:'mytext'}); | |||
// Horizontal line at y=2 | |||
brd.create('line', [-2, 0, 1], {strokeWidth:1, dash:2}); | |||
brd.create('text', [3, 2, "Multiline text<br>anchorX right<br>anchorY top"], {anchorX:'right', anchorY:'top', cssClass:'mytext'}); | |||
brd.create('text', [0.0,0.0,'Rotate'], {display:'internal', rotate:30}); | |||
</jsxgraph> | </jsxgraph> | ||
===The underlying JavaScript code=== | ===The underlying JavaScript code=== | ||
<source lang="javascript"> | <source lang="javascript"> | ||
var brd = JXG.JSXGraph.initBoard('jxgbox',{boundingbox: [-1,10,7,-1], axis:true, keepaspectratio:false}); | |||
// Vertical line at x=3 | |||
brd.create('line', [-3, 1, 0], {strokeWidth:1, dash:2}); | |||
brd.create('text', [3, 8, "Default"], {cssClass:'mytext'}); | |||
brd.create('text', [3, 7, "anchorX left"], {anchorX:'left', cssClass:'mytext'}); | |||
brd.create('text', [3, 6, "anchorX middle"], {anchorX:'middle', cssClass:'mytext'}); | |||
brd.create('text', [3, 5, "anchorX right"], {anchorX:'right', cssClass:'mytext'}); | |||
// Horizontal line at y=2 | |||
brd.create('line', [-2, 0, 1], {strokeWidth:1, dash:2}); | |||
brd.create('text', [1, 2, "Multiline text<br>default"], {cssClass:'mytext'}); | |||
brd.create('text', [2.2, 2, "Multiline text<br>anchorY bottom"], {anchorY:'bottom', cssClass:'mytext'}); | |||
brd.create('text', [3.4, 2, "Multiline text<br>anchorY middle"], {anchorY:'middle', cssClass:'mytext'}); | |||
brd.create('text', [4.6, 2, "Multiline text<br>anchorY top"], {anchorY:'top', cssClass:'mytext'}); | |||
// Horizontal line at y=2 | |||
brd.create('line', [-2, 0, 1], {strokeWidth:1, dash:2}); | |||
brd.create('text', [3, 2, "Multiline text<br>anchorX right<br>anchorY top"], {anchorX:'right', anchorY:'top', cssClass:'mytext'}); | |||
brd.create('text', [0.0,0.0,'Rotate'], {display:'internal', rotate:30}); | |||
</source> | </source> | ||
[[Category:Examples]] | [[Category:Examples]] | ||
[[Category:Text]] |
Latest revision as of 18:20, 16 November 2020
Texts can be aligned with the attributes anchorX
and anchorY
. Possible values for anchorX
are 'left'
, 'middle'
, and 'right'
. Possible values for anchorY
are 'bottom'
, 'middle'
, and 'top'
.
Text can be rotated if it is declared as display: 'internal'
. For SVG this means, instead of an HTML div the SVG text is taken as text node.
The underlying JavaScript code
var brd = JXG.JSXGraph.initBoard('jxgbox',{boundingbox: [-1,10,7,-1], axis:true, keepaspectratio:false});
// Vertical line at x=3
brd.create('line', [-3, 1, 0], {strokeWidth:1, dash:2});
brd.create('text', [3, 8, "Default"], {cssClass:'mytext'});
brd.create('text', [3, 7, "anchorX left"], {anchorX:'left', cssClass:'mytext'});
brd.create('text', [3, 6, "anchorX middle"], {anchorX:'middle', cssClass:'mytext'});
brd.create('text', [3, 5, "anchorX right"], {anchorX:'right', cssClass:'mytext'});
// Horizontal line at y=2
brd.create('line', [-2, 0, 1], {strokeWidth:1, dash:2});
brd.create('text', [1, 2, "Multiline text<br>default"], {cssClass:'mytext'});
brd.create('text', [2.2, 2, "Multiline text<br>anchorY bottom"], {anchorY:'bottom', cssClass:'mytext'});
brd.create('text', [3.4, 2, "Multiline text<br>anchorY middle"], {anchorY:'middle', cssClass:'mytext'});
brd.create('text', [4.6, 2, "Multiline text<br>anchorY top"], {anchorY:'top', cssClass:'mytext'});
// Horizontal line at y=2
brd.create('line', [-2, 0, 1], {strokeWidth:1, dash:2});
brd.create('text', [3, 2, "Multiline text<br>anchorX right<br>anchorY top"], {anchorX:'right', anchorY:'top', cssClass:'mytext'});
brd.create('text', [0.0,0.0,'Rotate'], {display:'internal', rotate:30});