[TW5] How to make transcluded /generated with macro data tiddlers as JSONTiddlers?

340 views
Skip to first unread message

Martian

unread,
Apr 21, 2016, 1:21:55 PM4/21/16
to TiddlyWiki
Hello!
As I understand, to be able to get {{##datafield}} a tiddler have to be marked as 'application/json' type.

But since I mark a tiddler with this type then neither transclude {{}} nor macros <<>> is not working inside it.
And I am going to generate JSON content with a  macro. 

Is there any way to turn tiddler with macro/transclude content into JSONTiddler ?

PMario

unread,
Apr 22, 2016, 4:07:21 AM4/22/16
to TiddlyWiki
Hi Martian,

JSON is specified here: http://www.json.org/ ... So transclusions will never work with a tiddler type: application/json, since this would be against the spec.

but

it should be possible to create a wikitext template, that lets you create json tiddlers. similar to the existing TW export function.

can you post simple example, how your JSON creator tiddler looks like?

-mario

Martian

unread,
Apr 22, 2016, 6:34:51 AM4/22/16
to tiddl...@googlegroups.com
Hi Mario,
well 
I am playing with D3 plugin examples.

my idea was to create a tiddlers with Title and Text = city names and add field "size". I tagged these tiddlers with tag "Cities"

then I created a tiddler "toJSON" with macro as in $:/core/templates/exporters/JsonFile

\define renderContent()
<$text text=<<jsontiddlers filter:"[tag[Cities]]">>/>
\end
<<renderContent>>

then tried to use these tiddler "toJSON" as source for D3 macros as 
This is a demo of TiddlyWiki5 incorporating a plugin for the [[D3.js]] visualization library.

! Word Cloud

<$d3cloud data="toJSON" spiral={{$:/spiral}}/>

but it doesn't work because [[toJSON]] don't have "application/json". 

But then I manually copied [[toJSON]] content to tiddler [[toJSON2]] typed with "application/json" and put it into data="toJSON2" to $d3cloud - then it works ok and showed me Word Cloud.


пятница, 22 апреля 2016 г., 11:07:21 UTC+3 пользователь PMario написал:

PMario

unread,
Apr 22, 2016, 8:11:58 AM4/22/16
to TiddlyWiki
On Friday, April 22, 2016 at 12:34:51 PM UTC+2, Martian wrote:
I am playing with D3 plugin examples.

ok
 
my idea was to create a tiddlers with Title and Text = city names and add field "size". I tagged these tiddlers with tag "Cities"

then I created a tiddler "toJSON" with macro as in $:/core/templates/exporters/JsonFile

\define renderContent()
<$text text=<<jsontiddlers filter:"[tag[Cities]]">>/>
\end
<<renderContent>>


good idea and imo you are at the right way. But it seems the <$d3cloud> widget has a very exact idea, how the data has to be presented. ... I had a very fast look at the code. So it seems the data parameter can only handle tiddlers with the type application/json. I thought it would be more flexible and also allows a "json formatted text stream". ... It doesn't :/
 
then tried to use these tiddler "toJSON" as source for D3 macros as 
This is a demo of TiddlyWiki5 incorporating a plugin for the [[D3.js]] visualization library.

! Word Cloud

<$d3cloud data="toJSON" spiral={{$:/spiral}}/>

but it doesn't work because [[toJSON]] don't have "application/json". 

But then I manually copied [[toJSON]] content to tiddler [[toJSON2]] typed with "application/json" and put it into data="toJSON2" to $d3cloud - then it works ok and showed me Word Cloud.

Yea. That's the workflow it would need. You need to create a button, that uses the output of <<jsontiddlers filter:"[tag[Cities]]">> and creates a new tiddler type application/json that can be fed into the widget. So no "one click" but a "two click" solution and a bit cumbersome. if you modify the "city" tiddlers or create a new on, you'll also need to create a new "data set" the the $d3cloud widget can understand. That's sub-optimal.

IMO the better way would be to extend the widget, so it can be called like this:

<$d3cloud data=<<jsontiddlers filter:"[tag[Cities]]">> spiral={{$:/spiral}}/>

---------

The problem is, that I don't have a fast solution.

The button to create a data tiddler that works looks like this:


<$button>
<$action-sendmessage $message="tm-new-tiddler" title="citiesCloudData" type="application/json" text=<
<jsontiddlers filter:"[tag[city]]">>/>
createCouldData
</$button>


Some remarks:

I would use city as a tag for a city and not the plural. It just looks stange. (most of the time my tags are lower case. So I can remember how to write them :)

And I would rewrite the d3cloud widget. It seems the examples are the minimum required functionality to show something. .. Imo they are there to show, how the library can be used. The widgets are very simple examples and imo not production ready.

have fun!
Mario


Jeremy Ruston

unread,
Apr 22, 2016, 10:42:22 AM4/22/16
to tiddl...@googlegroups.com
Hi Martian

Just to expand on Mario’s answer: the D3 plugin is little more than a tech demo to show how a third party library can be integrated with TiddlyWiki. In particular, the way that data is passed to it doesn’t easily permit the data to be created dynamically. I agree that the best way forwards for your use case is likely to involve improving the D3 widget itself.

Best wishes

Jeremy

--
You received this message because you are subscribed to the Google Groups "TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywiki+...@googlegroups.com.
To post to this group, send email to tiddl...@googlegroups.com.
Visit this group at https://groups.google.com/group/tiddlywiki.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/2243e137-da57-49ad-9020-6437be89c1b5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages