Support SSR(server side render) so that you can export static HTML tiddler or using headless render method such as $tw.wiki.renderText for tiddlers contains <$echarts>!
I think it’s because I was using the multicolumn layout!
I was hoping I could have the brain view in one column and it change depending on whatever I was viewing else where, but I guess multicolumn does strange things with current-tiddler?
off topic…
I usually like the side bar closed so I was exploring other options. A layout/ ensemble/ toggle button to change fixed and fluid sidebar or just thin to fat sidebar would do the job. Or one of those two sidebar themes! Have to go and find! Had a try with @saqimtiaz float experiment (float+test.json (15.7 KB)) but that doesn’t seem to work on my wiki. Some plugin clash or other I guess!
you can use the Brain with the multi-column layout… there are only some lines of additional wikitext needed because the multi-column layout uses multiple history lists
Add @saqimtiaz’s Streams compatibility to TheBrain in 4 steps (note: there are probably better ways to accomplish this, using the get-stream-root[] and get-stream-nodes[] filters, but TheBrain is in javascript and I am not great at leveraging WikiText filters from javascript).
step 1 in $:/core/modules/wiki.js add the following two functions:
/*
Return an array of tiddler titles that are directly linked from the specified tiddler or
from any of the Streams nodes tied to the specified tiddler
*/
exports.getStreamLinks = function(title) {
var self = this;
var results = [];
// Parse the tiddler first, then worry about the subordinate Stream nodes
var parser = self.parseTiddler(title);
if(parser) {
//deduplicate as we push returned array element into the results array
for (var element of self.extractLinks(parser.tree)) {
if (results.indexOf(element) == -1) { //not already present
results.push(element);
}
}
}
//examine the "stream-*" fields
var tiddler = self.getTiddler(title); //work from the tiddler title, to access fields
if(tiddler && tiddler.fields["stream-list"] && tiddler.fields["stream-type"]) {
//turn the stream-list into array of tiddler titles
var streamList = $tw.utils.parseStringArray(tiddler.fields["stream-list"]);
for (var node of streamList) { //for each tiddler title in stream list, recurse
//deduplicate as we push returned array item into the results array
for (var item of self.getStreamLinks(node)) {
if (results.indexOf(item) == -1) { //not already present
results.push(item);
}
}
}
}
return results;
};
/*
Return an array of tiddler titles that link to the specified tiddler
*/
exports.getStreamBacklinks = function(targetTitle) {
var self = this,
backlinksIndexer = this.getIndexer("BacklinksIndexer"),
backlinks = backlinksIndexer && backlinksIndexer.lookup(targetTitle),
ancestorList = [];
if(!backlinks) {
backlinks = [];
this.forEachTiddler(function(title,tiddler) {
var links = self.getTiddlerLinks(title);
if(links.indexOf(targetTitle) !== -1) {
backlinks.push(title);
}
});
}
backlinks.forEach(function (title, index) {
var ancestors = [];
var tiddler = self.getTiddler(title);
if(tiddler && tiddler.fields["parent"] && tiddler.fields["stream-type"]) {
var parentTiddler = tiddler;
while(parentTiddler) {
ancestors.unshift(parentTiddler.fields.title);
if(parentTiddler.fields.parent) {
parentTiddler = self.getTiddler(parentTiddler.fields.parent);
} else {
break;
}
}
} else {
ancestors.unshift(title);
}
ancestorList.push(ancestors[0]);
});
return ancestorList;
};
step 2 in $:/plugins/Gk0Wk/echarts/addons/TheBrain.js, replace getTiddlerLinks with the new function getStreamLinks
step 3 in $:/plugins/Gk0Wk/echarts/addons/TheBrain.js, replace getTiddlerBacklinks with the new function getStreamBacklinks
step 4 replace the content of $:/plugins/Gk0Wk/echarts/addons/TheBrainPopup with <h3><$text text=<<currentTiddler>> /></h3><$transclude tiddler="$:/plugins/sq/streams/templates/stream-root-template" mode="inline" />
I think you can create a new file $:/plugins/Gk0Wk/echarts/addons/TheBrain4Stream.js or something, and add getStreamLinks and getStreamBacklinks in that file instead?
So you don’t need to change the wiki.js in the echarts plugin.
Could this heatmap be developed into a more modular plugin? For example, opening an interface allows me to easily input other types of data and display it.