Search code examples
inequalityjsxgraphinequalities

Plotting inequalities domain comb-style with JSXGraph


I want to draw axis line with comb-styled selection of inequality domain, like in this picture:

some inequalities

Is it possible with JSXGraph?


Solution

  • It is not built-in to JSXGraph, yet. But this is good suggestion. Here is an implementation (to be built-in, it had to be rewritten as JSXGraph element).

    const board = JXG.JSXGraph.initBoard('jxgbox', {
                                boundingbox: [-5, 5, 5, -5],
                  axis: true
              });
    
    var comb = function(board, [left, right, n, base, height]) {
        var delta,
            c = board.create('curve', [[0], [0]]);
    
        delta = (right - left) / n;
    
        c.updateDataArray = function() {
            var s;
    
            this.dataX = [];
            this.dataY = [];
            for (s = left; s + delta*0.5<= right; s += delta) {
                this.dataX.push(s);
                this.dataY.push(base);
                this.dataX.push(s + delta);
                this.dataY.push(base + height);
                this.dataX.push(NaN);  // Force a jump
                this.dataY.push(NaN);
            }
        };
    
        board.update();
    
        return c;  
    };
    
    
    var c1 = comb(board, [1, 3, 10, 0, 0.2]);
    var c2 = comb(board, [-4, -1, 20, -2, 0.2]);
    

    See it in action here: https://jsfiddle.net/vcL7aepo/217/ .