Hong-Phuc Bui
2025-01-16 2889de7f0c2d587a17fbd322af57c29e84238620
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/**
 * this module provides common functions to work with a JSXGraph-Board.
 * If a function in this module should manipulate a JSX-Board, the board should be the
 * first parameter in funtion's argument list.
 * */
 
import {download} from './dfhi-dom.js';
 
export function exportBoard(board, filename) {
    console.log("exportBoard called");
    if( !filename) {
        filename = guestFilename();
    }
    let svgCode = new XMLSerializer().serializeToString(board.renderer.svgRoot);
    console.log("svgCode ready");
    download(filename, svgCode, "image/svg+xml");
}
 
function guestFilename() {
    try {
        let title = document.title || "export-jsxgraph";
        if (title) {
            title = title.replace(/\s+/g, '-');
        }
        return `${title}.svg`;
    } catch (e)    {
        return "export-jsxgraph.svg";
    }
}
 
export function toggleAxis(board) {
    try {
        const currentAxis =  board.attr['axis'];
        console.log(board);
        board.attr['axis'] = ! currentAxis;
    }catch(e) {
        console.error(e);
    }
}