##// END OF EJS Templates
Backport PR #2384: Adapt inline backend to changes in matplotlib...
Backport PR #2384: Adapt inline backend to changes in matplotlib Matplotlib recently merged https://github.com/matplotlib/matplotlib/pull/1125 that makes it simpler to use objective oriented figure creation by automatically creating the right canvas for the backend. To solve that all backends must provide a backend_xxx.FigureCanvas. This is obviosly missing from the inline backend. The change is needed to make the inline backend work with mpl's 1.2.x branch which is due to released soon. Simply setting the default canvas equal to a Agg canvas appears to work for both svg and png figures but I'm not sure weather that is the right approach. Should the canvas depend on the figure format and provide a svg canvas for a svg figure? (Note that before this change to matplotlib the canvas from a plt.figure call seams to be a agg type in all cases) Edit: I made the pull request against 0.13.1 since it would be good to have this in the stable branch for when mpl is released. Just let me know and I can rebase it against master

File last commit:

r7196:b0be2d03
r8562:7d16877a
Show More
contexthint.js
94 lines | 2.9 KiB | application/javascript | JavascriptLexer
// highly adapted for codemiror jshint
(function () {
"use strict";
function forEach(arr, f) {
for (var i = 0, e = arr.length; i < e; ++i) f(arr[i]);
}
function arrayContains(arr, item) {
if (!Array.prototype.indexOf) {
var i = arr.length;
while (i--) {
if (arr[i] === item) {
return true;
}
}
return false;
}
return arr.indexOf(item) != -1;
}
CodeMirror.contextHint = function (editor) {
// Find the token at the cursor
var cur = editor.getCursor(),
token = editor.getTokenAt(cur),
tprop = token;
// If it's not a 'word-style' token, ignore the token.
// If it is a property, find out what it is a property of.
var list = new Array();
var clist = getCompletions(token, editor);
for (var i = 0; i < clist.length; i++) {
list.push({
str: clist[i],
type: "context",
from: {
line: cur.line,
ch: token.start
},
to: {
line: cur.line,
ch: token.end
}
})
}
return list;
}
// find all 'words' of current cell
var getAllTokens = function (editor) {
var found = [];
// add to found if not already in it
function maybeAdd(str) {
if (!arrayContains(found, str)) found.push(str);
}
// loop through all token on all lines
var lineCount = editor.lineCount();
// loop on line
for (var l = 0; l < lineCount; l++) {
var line = editor.getLine(l);
//loop on char
for (var c = 1; c < line.length; c++) {
var tk = editor.getTokenAt({
line: l,
ch: c
});
// if token has a class, it has geat chances of beeing
// of interest. Add it to the list of possible completions.
// we could skip token of ClassName 'comment'
// or 'number' and 'operator'
if (tk.className != null) {
maybeAdd(tk.string);
}
// jump to char after end of current token
c = tk.end;
}
}
return found;
}
function getCompletions(token, editor) {
var candidates = getAllTokens(editor);
// filter all token that have a common start (but nox exactly) the lenght of the current token
var lambda = function (x) {
return (x.indexOf(token.string) == 0 && x != token.string)
};
var filterd = candidates.filter(lambda);
return filterd;
}
})();