summaryrefslogtreecommitdiffstats
path: root/web/gui/src/dashboard.js/charting/_morris.js
blob: 30789e4e228e3212ec6506631f76ce0713b98525 (plain)
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// DEPRECATED: will be removed!

// morris

NETDATA.morrisInitialize = function(callback) {
    if (typeof netdataNoMorris === 'undefined' || !netdataNoMorris) {

        // morris requires raphael
        if (!NETDATA.chartLibraries.raphael.initialized) {
            if (NETDATA.chartLibraries.raphael.enabled) {
                NETDATA.raphaelInitialize(function() {
                    NETDATA.morrisInitialize(callback);
                });
            } else {
                NETDATA.chartLibraries.morris.enabled = false;
                if (typeof callback === "function")
                    return callback();
            }
        } else {
            NETDATA._loadCSS(NETDATA.morris_css);

            $.ajax({
                url: NETDATA.morris_js,
                cache: true,
                dataType: "script",
                xhrFields: { withCredentials: true } // required for the cookie
            })
            .done(function() {
                NETDATA.registerChartLibrary('morris', NETDATA.morris_js);
            })
            .fail(function() {
                NETDATA.chartLibraries.morris.enabled = false;
                NETDATA.error(100, NETDATA.morris_js);
            })
            .always(function() {
                if (typeof callback === "function")
                    return callback();
            });
        }
    } else {
        NETDATA.chartLibraries.morris.enabled = false;
        if (typeof callback === "function")
            return callback();
    }
};

NETDATA.morrisChartUpdate = function(state, data) {
    state.morris_instance.setData(data.result.data);
    return true;
};

NETDATA.morrisChartCreate = function(state, data) {

    state.morris_options = {
            element: state.element_chart.id,
            data: data.result.data,
            xkey: 'time',
            ykeys: data.dimension_names,
            labels: data.dimension_names,
            lineWidth: 2,
            pointSize: 3,
            smooth: true,
            hideHover: 'auto',
            parseTime: true,
            continuousLine: false,
            behaveLikeLine: false
    };

    if (state.chart.chart_type === 'line')
        state.morris_instance = new Morris.Line(state.morris_options);

    else if (state.chart.chart_type === 'area') {
        state.morris_options.behaveLikeLine = true;
        state.morris_instance = new Morris.Area(state.morris_options);
    }
    else // stacked
        state.morris_instance = new Morris.Area(state.morris_options);

    return true;
};