I would like to create a stamp that allows for toggling the visibility of links in a map.
How would I do that?
I would like to create a stamp that allows for toggling the visibility of links in a map.
How would I do that?
Do you need to have lots of different link types? If not, you could make a new linkType, hidden, that is invisible. After that, youāll need a function that changes all the untitled links on a given note to have type have type hidden, and another to make all the hidden links *untitled
. We might call those hideLinks(path:string){}
and showLinks(path:string)
.
Finally, we want functions that take a list of paths and call show and hide in turn for each path.
$Path(children(parent)).each(x){showLink(x);}
OK: when I started this reply I was ready to say, āyou canāt.ā Half-way through, I was ready to say, āthis is awfully complicated.ā But itās not, not really! The basic idea is simply an outline of what you want:
theNode
in this containerā¦theLink
starting or ending on theNodeā¦hidden
or *untitled
If I were doing this, Iād do it in very small steps ā steps so small that nothing could possibly go wrong ā and check at each step that nothing is, in fact, going wrong. Iād do everything in functions, and try to limit each function to a handful of lines.
If you DO need lots of link types, then save the old link type in a dictionary attribute and restore it when unhiding. But thatās making things really painful, at least if you have multiple links from the same note with distinct paths. At that point, my recommendation might be: ask Mark to add a new action.
OK, Iāve implemented part of this in a single function. All three arguments are needed, but if supplied as an empty string value, a default is used. For the new/old link types it is *untitled
and for the IDString is is this
. Some of the tests also need a link type called hidden
. Add a new link type to your document, call it āhiddenā and un-tick the āvisibleā label (you can leave the label option as invisible links donāt draw their label). The function is:
function fSwitchLink(iOldType:string, iNewType:string, iIDStr:string){
var:string vNote;
if(iIDStr==""){
vNote="this";
}else{
vNote=iIDStr;
};
var:string vOldType;
if(iOldType==""){
vOldType="*untitled";
}else{
vOldType=iOldType;
};
var:string vNewType;
if(iNewType==""){
vNewType="*untitled";
}else{
vNewType=iNewType;
};
eachLink(aLink,vNote){
if(aLink["type"]==vOldType){
aLink["type"]=vNewType;
}
};
To change the selected noteās untitled links to āhiddenā (using the optional empty defaults):
fSwitchLink("","hidden","");
To change the selected noteās āagreeā links to ādisagreeā (using the optional empty defaults):
fSwitchLink("agree","disagree",$IDString);
By giving the $IDString of a different note, either as a literal string value or using an offset reference, e.g. $IDString(āSome noteā), links for a different note can be altered.
Note that you can only toggle the link type of a pair of types, rather than all types. If you be easy to write a function to loop trough all used link types (we can get those from the link-types
key of document(). Harder is storing original per-link differing link types, especially if the same two notes are linked by links of multiple types. IOW, I suggest the latter scenerio is not noew to plan for.
Anyway, here is the test doc for the above: linktype-swap.tbx (268.6 KB)
The TBX has 6 stamps (3 matched reversing pairs) for you to try out by switching to the Map view tab, selecting note āaaā and applying a stamp.
Note that this method works by changing a given links link type and not the links properties. Individual links links cannot be altered using action code (though appleScript is a possibility, though iāve not tested this).
However, Iām not sure the above is what @andreas was asking for. Instead I think he wanted a map-scoped single toggle for all link types (links and stubs). That basically alters the visible
property of links as opposed to altering the link type of links. On a busy map there may be a lot of links and rather than fiddle with each, if there were a boolean switch that was checked at the point where the map starts to draw links I suspect thatāwhilst requiring a new feature (a system boolean?)āit might when done result in less work for the app to ājustā suppress links on a given map. FWIW, this sort of approach was what was in mind when i mentioned it when describing a circular map layout pattern the other day (see this thread).
OK. Iām working on better control for link visibility. Should be backstage in a day or two.
thank you @mwra
I am afraid, though, I donāt get it
that would be of great help. thanks
Well, itās a demo code that does what you ask, within the limits of the current app. You can āhideā all links. You can change any/all links to a different type that is configured to not be visible (here in the Links Inspector):
The code posted does that, so that you donāt have to do the task manually in the Browse Links dialog. Swapping one link type, e.g. ā*untitledā to a āhiddenā type is easy, as demonstrated. Cyling through easy link type in use and changing it to hidden ā¦ (oops pressed wrong button, continued in next post).
ā¦ is pretty easy do do, building off my demo above. Storing each linkās existing link is much harder. Of the per-link properties revealed via eachLink
only source
, destination
, and type
are read-write the rest being read-only, so we canāt save the normal, visible, link type.
So thatās what you can do now. For Backstage members a more nuanced control is already under test.
Great1 @mwra
Now I start to get it @mwra ā¦ and eventually could benefit from your kind ātemplateā.
The only way I see right now to toggle more than one āuntitledā Link to āhiddenā is by selecting all nots on the map and then apply the respective stamp. Is that correct?
You could select one note in the map.
Then, loop through all the children of that noteās parents.
The probelm with the above and multiple link ytypes is knowing to which link type to toggle back to. Links do have a comment field but it is read-only in action code. so changing all links to a āhiddenā type is easy, changing back is difficult.
For now itās probably easier to open the Links Inspector and simply alter visibility fo currently used link types. Even so youāll need to record or remember which those are for when you wish them to be visible again.
Itās hard to give a simple answer because there are several different reasons/contexts for wanting invisible links:
The nuance between the latter and the solution being trialled. is that the latter uses action code to toggle the visibility of some/all links (depending how code is used). The latter idea is one where the user tells Tinderbox "Stop drawing all links, regardless of their visibility state). Extensive testing in recent days suggests to me there is no one-size-fits-all answer as all the above scenarios are both entirely likely but different.
In fact, you already see the effect of #1 in a doc using prototypes. Yes, because prototype assignments are reflected by a link of type āprototypeā form the prototype to the note using it but the link is default set to not be visible. Aside, and in case anyone wonders, a lot of action code link-related operators auto-exclude prototype links as generally the user is not expecting such a relationship to be a link.
Ack. I had the backstage solution in mind
ā¦ which of course only raises the appetite to see the backstage discussed solution go live eventually. Really looking forward to this.
Thank you ever so much, @mwra, for always supporting and pushing our understanding!
@mwra @eastgate are there any updates on control for link visibility as you seem to have been discussing this backstage a while back.
thank you
Ugh: I need a pointer or a precis.
you mean: like this
I may still be behind the curve on this issue! But hereās what I think I did.
As you know, eachLink(theLink) {...}
cycles through each link to or from this
note. The temporary variable theLink
is bound, in turn, to a dictionary of facets of link. These include visible, broad, dashed, dotted, linear, bold, class, title, target, comment, url, source, sourceID, sourceIDString, dest, destID, and destIDString.
If you change a dictionary entry theLink[visible]=false;
, that change is performed on the corresponding link.
This should work in Tinderbox 10.
Digging back the above changes were made to eachLink()
in v9.6.0 (1 Aug 2023), although the operator itself was first introduced in v9.1.0 (10 Dec 2021).
Current eachLink() documentation.