jsxgraph: use data-lang to specify graph size

This commit is contained in:
joyqat 2020-08-07 12:22:34 +08:00
parent dd57510365
commit 795307569a
2 changed files with 25 additions and 2 deletions

View File

@ -16,6 +16,8 @@ libraries:
image: images/feature1/graph.png image: images/feature1/graph.png
--- ---
Use `Shift` and `Mouse Left` to drag, `Shift` and `Mouse Scroll` to zoom. Use `Shift` and `Mouse Left` to drag, `Shift` and `Mouse Scroll` to zoom.
### Example 1
```jessiecode ```jessiecode
point(5, 5) <<id:'pt', name: 'point'>>; point(5, 5) <<id:'pt', name: 'point'>>;
grid(); grid();
@ -29,6 +31,7 @@ g = functiongraph(f);
$board.setView([-10, 10, 10, -10]); $board.setView([-10, 10, 10, -10]);
``` ```
### Example 2
Point A will stay inside the circle. Point A will stay inside the circle.
```jessiecode ```jessiecode
@ -51,9 +54,10 @@ p.on('drag',function(){
}); });
``` ```
### Example3
This graph shows the properties of triangle. Drag the edges of triangle to observe changes. This graph shows the properties of triangle. Drag the edges of triangle to observe changes.
```jessiecode ```jessiecode:400x400
// code adapted from https://github.com/jsxgraph/JessieCode/blob/master/examples/euler.html // code adapted from https://github.com/jsxgraph/JessieCode/blob/master/examples/euler.html
cerise = << cerise = <<
strokeColor: '#901B77', strokeColor: '#901B77',
@ -111,3 +115,12 @@ euler = line(H, S) << strokeWidth: 2, strokeColor:'#901B77' >>;
$board.setView([-1.5, 2, 1.5, -1]); $board.setView([-1.5, 2, 1.5, -1]);
``` ```
### Note
You can specify height and weight in the language specifier. e.g.
````markdown
```jessiecode:400x300
// codes...
```
````
will change the graph size to width 400px and height 300px.

View File

@ -633,8 +633,18 @@
board.jc = new JXG.JessieCode(); board.jc = new JXG.JessieCode();
board.jc.use(board); board.jc.use(board);
board.jc.parse(x.innerText); board.jc.parse(x.innerText);
board.resizeContainer(300,300); board.resizeContainer(300,300);
index += 1; var size = x.getAttribute('data-lang').split('x');
if (size && size.length == 2) {
var w = parseInt(size[0], 10);
var h = parseInt(size[0], 10);
if (!(isNaN(w) || isNaN(h))) {
board.resizeContainer(w, h);
}
}
index += 1;
}); });
} }
{{ end }} {{ end }}