I’m trying to set up some kind of loop to generate an SVG image dynamically, the goal is to generate a spider graph dynamically.
I thought about using a list widget with a counter to serve as a while() loop but the list widget iterate over a list, and I don’t know how to generate a list of n item from a variable.
Then I tried to use recursive transclusion but didn’t succeed: I think I need to trigger a macro to update a field value on each pass but don’t know how (and it’s probably really bad for performances anyway).
Is there a way to iterate a code an n number of times? If not, can you give me some hints on how I can use regular javascript and wikitext to achieve this result?
@telumire another method can be storing a list (even the result of a range operator - but typically a list of titles) then using setWidgets index parameter to address each item inside the variable (0- based index)
With 5.2.0 the list widget now has a counter=variablename parameter that returns a 1 based counter for each list item. With this you can have the opportunity to treat the first or Nth item differently and if previously you used count to establish the number or elements you can also determine what the last element is.
In short the use of the new counter variable, the range operator and or the set widget index opens the world of tiddlywiki looping much further.
@TW_Tones: this new looping index with list is great. I had develop it for my own usage. I’ll be glad to switch to the official version when it’s available. Do you plan to include a possibility of choosing the starting index and the increment?
Of course I could offer more examples using the item as an index into a variable in a set statement. Or driving the counter with the range operator then using the index but there are so many possibilities I will leave it for you to ask or do it yourself.
@Alvaro ol is fine if you just want the items numbered, or to remain up to date if using draggable lists however the number is generated by CSS and not available to your code. There are range of other “algorithm’s” that need the “index” or counter, such as detecting the first or last, making calculations and inserting content generated in wiki text. In many cases a CSS equivalent appears including the nth item, inserting content etc… but this is more the “display layer” and not the “application” layer.
In my case, I needed it to inser some data from a parallel list. It was the only possibility (I tried a lot of other ways!). For this kind of needs, having the default index is just enough, as, as @TW_Tones showed, you can always make simple computations to alter it to your very need. But, true enough, choosing the first digit would be cool (0 or 1 most of the time) and could avoid any calculus.
The following code demonstrates driving a list by a number.
It also demonstrates how to use the set select to access the members of a list via a number.
I believe it could help in the Original post but it also demonstrates my suggestions later in the threads. Study this closely and I think you will find a solution for most related cases.
I dont know how I missed this, up until now I used nth[n] to get the nth output of a filter… this works great ! Thank you all for helping me understand tiddlywiki better!
I have always wondered with these “spider” graphs if the area inside should be compared with the area outside to determine the magnitude when compared with other sets of values.
Perhaps 6x100=600 the, divided by the sum below. Not so much the graph area as projected in 2D but the sum in the 6 Dimensions we are measuring?
Somewhere on my list of things to do is radar graphs for my tasting notes edition. I had been thinking I might find a way to use chart.js without directly including it in the wiki to create the graph and then render and save as an image. A wikitext based solution opens a lot of possibilities!