web/data/cubicweb.flot.js
author Julien Cristau <julien.cristau@logilab.fr>
Mon, 29 Jun 2015 16:58:43 +0200
changeset 10463 9add9b7f9df7
parent 7567 d6366de1d0dc
permissions -rw-r--r--
[server/test] fix random error in unittest_security When entering a new Connection, we cache the user and its 'login' attribute (with no permissions checking). This test makes 'CWUser.login' unreadable by guests, and then proceeds to make sure the 'anon' user can actually not read any 'login' attribute. However, due to the above cnx initialization, anon's login is actually cached, hence readable. This happens to make the test fail sometimes depending on the order in which CWUser entities are returned, because one of them has .complete() called, which as a side effect sets the attribute cache to None for unreadable attributes. Call .complete() on both entities to reset the login cache. While this is still highly debatable, at least it's consistent.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1888
f36d43f00f32 [views] plot with flot and get rid of matplotlib
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     1
function showTooltip(x, y, contents) {
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2564
diff changeset
     2
    $('<div id="tooltip">' + contents + '</div>').css({
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2564
diff changeset
     3
        position: 'absolute',
2564
5f38f5eaff86 [F plot] make jquery plots accept a fourth column that specifies a date format for tooltips
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1888
diff changeset
     4
        display: 'none',
5f38f5eaff86 [F plot] make jquery plots accept a fourth column that specifies a date format for tooltips
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1888
diff changeset
     5
        top: y + 5,
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2564
diff changeset
     6
        left: x + 5,
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2564
diff changeset
     7
        border: '1px solid #fdd',
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2564
diff changeset
     8
        padding: '2px',
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2564
diff changeset
     9
        'background-color': '#fee',
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2564
diff changeset
    10
        opacity: 0.80
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2564
diff changeset
    11
    }).appendTo("body").fadeIn(200);
1888
f36d43f00f32 [views] plot with flot and get rid of matplotlib
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    12
}
f36d43f00f32 [views] plot with flot and get rid of matplotlib
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    13
f36d43f00f32 [views] plot with flot and get rid of matplotlib
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    14
var previousPoint = null;
f36d43f00f32 [views] plot with flot and get rid of matplotlib
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    15
function onPlotHover(event, pos, item) {
7567
d6366de1d0dc Display proper date in plot/flot (closes #1725589)
Arthur Lutz <arthur.lutz@logilab.fr>
parents: 5658
diff changeset
    16
    var $fig = $(event.target);
1888
f36d43f00f32 [views] plot with flot and get rid of matplotlib
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    17
    if (item) {
f36d43f00f32 [views] plot with flot and get rid of matplotlib
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    18
        if (previousPoint != item.datapoint) {
2564
5f38f5eaff86 [F plot] make jquery plots accept a fourth column that specifies a date format for tooltips
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1888
diff changeset
    19
            previousPoint = item.datapoint;
5f38f5eaff86 [F plot] make jquery plots accept a fourth column that specifies a date format for tooltips
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1888
diff changeset
    20
            $("#tooltip").remove();
5f38f5eaff86 [F plot] make jquery plots accept a fourth column that specifies a date format for tooltips
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1888
diff changeset
    21
            var x = item.datapoint[0].toFixed(2),
7567
d6366de1d0dc Display proper date in plot/flot (closes #1725589)
Arthur Lutz <arthur.lutz@logilab.fr>
parents: 5658
diff changeset
    22
                y = item.datapoint[1].toFixed(2);
d6366de1d0dc Display proper date in plot/flot (closes #1725589)
Arthur Lutz <arthur.lutz@logilab.fr>
parents: 5658
diff changeset
    23
            if ($fig.data('mode') == 'time') {
d6366de1d0dc Display proper date in plot/flot (closes #1725589)
Arthur Lutz <arthur.lutz@logilab.fr>
parents: 5658
diff changeset
    24
                x = new Date(item.datapoint[0]);
d6366de1d0dc Display proper date in plot/flot (closes #1725589)
Arthur Lutz <arthur.lutz@logilab.fr>
parents: 5658
diff changeset
    25
                var dateformat = $fig.data('dateformat');
d6366de1d0dc Display proper date in plot/flot (closes #1725589)
Arthur Lutz <arthur.lutz@logilab.fr>
parents: 5658
diff changeset
    26
                if (dateformat) {
d6366de1d0dc Display proper date in plot/flot (closes #1725589)
Arthur Lutz <arthur.lutz@logilab.fr>
parents: 5658
diff changeset
    27
                    x = x.strftime(dateformat);
d6366de1d0dc Display proper date in plot/flot (closes #1725589)
Arthur Lutz <arthur.lutz@logilab.fr>
parents: 5658
diff changeset
    28
                } else {
d6366de1d0dc Display proper date in plot/flot (closes #1725589)
Arthur Lutz <arthur.lutz@logilab.fr>
parents: 5658
diff changeset
    29
                    x = x.toLocaleDateString() + ' ' + x.toLocaleTimeString();
d6366de1d0dc Display proper date in plot/flot (closes #1725589)
Arthur Lutz <arthur.lutz@logilab.fr>
parents: 5658
diff changeset
    30
                }
2564
5f38f5eaff86 [F plot] make jquery plots accept a fourth column that specifies a date format for tooltips
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1888
diff changeset
    31
            } else if (item.datapoint.length == 4) {
7567
d6366de1d0dc Display proper date in plot/flot (closes #1725589)
Arthur Lutz <arthur.lutz@logilab.fr>
parents: 5658
diff changeset
    32
                // NOTE: this has no chance to work with jquery flot >= 0.6 because
d6366de1d0dc Display proper date in plot/flot (closes #1725589)
Arthur Lutz <arthur.lutz@logilab.fr>
parents: 5658
diff changeset
    33
                // jquery flot normalizes datapoints and only keeps 2 columns. Either
d6366de1d0dc Display proper date in plot/flot (closes #1725589)
Arthur Lutz <arthur.lutz@logilab.fr>
parents: 5658
diff changeset
    34
                // use processRawData hook or use the 'dateformat' option.
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2564
diff changeset
    35
                x = new Date(item.datapoint[2]);
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2564
diff changeset
    36
                x = x.strftime(item.datapoint[3]);
1888
f36d43f00f32 [views] plot with flot and get rid of matplotlib
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    37
            }
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2564
diff changeset
    38
            showTooltip(item.pageX, item.pageY, item.series.label + ': (' + x + ' ; ' + y + ')');
2564
5f38f5eaff86 [F plot] make jquery plots accept a fourth column that specifies a date format for tooltips
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1888
diff changeset
    39
        }
1888
f36d43f00f32 [views] plot with flot and get rid of matplotlib
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    40
    } else {
f36d43f00f32 [views] plot with flot and get rid of matplotlib
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    41
        $("#tooltip").remove();
f36d43f00f32 [views] plot with flot and get rid of matplotlib
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    42
        previousPoint = null;
f36d43f00f32 [views] plot with flot and get rid of matplotlib
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    43
    }
f36d43f00f32 [views] plot with flot and get rid of matplotlib
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    44
}
5658
7b9553a9db65 [ajax] refactor/cleanup low-level ajax functions
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2564
diff changeset
    45