Highlighting duplicates in lists

403 views
Skip to first unread message

paulgilbert2000

unread,
Jul 29, 2021, 7:03:33 PM7/29/21
to TiddlyWiki
Hi ,

is it possible to highlight duplicates in a list , or make them stand out in a different format/color , you know similar to excel

so in the below example ,i have a list that returns tiddlers matching a certain criteria , and then displays their title field value , and also the value in a custom field i named "field_example"

tiddler1 and tiddler4 have the same value in the custom field and the value is "X"

can i highlight tiddler 1 and tiddler 4 maybe in red ?

duplicates.PNG

TW Tones

unread,
Jul 29, 2021, 7:37:33 PM7/29/21
to TiddlyWiki
Mohamad,

One way is to sort in the parameter order before you can detect that the last is the same as the current ie a duplicate.

The other way is for each tiddler, search for the same parameter elsewhere, if more than one found then it is duplicate before displaying the parameter. 
  • If you do this you may need to add to the filter the one that selected the list of tiddlers as well, so you don't find the parameter elsewhere. ie you are only searching in the current list of tiddlers.
Regards
RTones

paulgilbert2000

unread,
Jul 29, 2021, 8:20:59 PM7/29/21
to TiddlyWiki
thanks tones

for the second method , would that display the duplicates  , because i want that

TW Tones

unread,
Jul 29, 2021, 9:29:30 PM7/29/21
to TiddlyWiki
Mohamad

See the following
<$list filter="[all[]prefix[New]has[field]]">
   <$link/> {{!!field}} {{{ [all[]prefix[New]!title<currentTiddler>get[field]match{!!field}then[*]] }}}<br>
</$list>

  • First we list All tiddlers satisfying [all[]prefix[New]has[field]]
  • Then we display a link to each tiddler and the value in field
  • Then inside the filtered transclusion (could be in a list) we now search all tiddlers (again) excluding the current tiddler, if another tiddler has the same value for {{!!field}} we display an Asterix.
It gets a little more complex if you want to select one as a the duplicate and the other as the original but if so you need to decide the condition to determine the first. Eg oldest in the primary, youngest is the duplicate.

Regards
Tones

PMario

unread,
Jul 30, 2021, 4:44:55 AM7/30/21
to TiddlyWiki
Hi,
Your construction should look like this, if you want to have a UL list

<ul>
<$list ...>
<li> ... your code </li>
</$list>
</ul>

Otherwise you will create invalid HTML code.


On Friday, July 30, 2021 at 1:03:33 AM UTC+2 Mohamed...@hotmail.com wrote:

can i highlight tiddler 1 and tiddler 4 maybe in red ?

You can't do this with 1 list widget.

TW loops evaluate each element in turn. So when tiddler 1 is evaluated, how should the loop know, that there will be a second element in the future, that will have the same name. ... Except you know, how to time-travel you will need 2 lists.

The first list will need to evaluate the list of duplicates and the second run will need to add an eg: .duplicate-element class to every element that is there multiple times.

I could think of a construction in wikitext, but it would be complex and time consuming. I personally would create a javascript macro, that returns a list of duplicates, or even better a data-tiddler with the duplicates as index and the color as a value.

So it would be simple to assign a class to the elements. ...

just some thoughts. I also think it's a valid request, and we should think about it in more detail.

So if you raise an issue with a link to this thread at github, we won't forget it. ..

-mario

Mat

unread,
Jul 30, 2021, 7:28:43 AM7/30/21
to TiddlyWiki
I would say it is possible with this general idea:

<div class="mywrap">
<$list filter="[tag[tests]]">
<div class={{!!title}}>{{!!title}}</div>
<style> .mywrap.{{!!title}}:not(:first-of-type) {background:yellow}</style>
</$list>
</div>

The above will likely not work right away but it shows the idea. For example, for the title to work as a class name it must follow css naming conventions (and you can use some modifying filters in a $vars or $set to make it be so). And you might have to split out the content of the listwidget into a separate macro.

<:-)


On Friday, July 30, 2021 at 1:03:33 AM UTC+2 Mohamed...@hotmail.com wrote:

TW Tones

unread,
Jul 30, 2021, 8:23:40 AM7/30/21
to TiddlyWiki
I can see by other replies that my example that showed the logic was not enough for the OT

Here I turn it into an unordered list with duplicates in red.

<ul>
<$list filter="[all[]prefix[New]has[field]]">
   <li><span style={{{ [all[]prefix[New]!title<currentTiddler>get[field]match{!!field}then[color: red;]] }}}> <<currentTiddler>> {{!!field}}</span></li>
</$list>
</ul>

Have I fully addressed the Original Post?
Tones

paulgilbert2000

unread,
Jul 31, 2021, 10:00:00 PM7/31/21
to TiddlyWiki
Hi Tones,

yes, this perfectly fits my needs, thank you very much

@ Mario , thank you for your help , i have just raised a feature request on GitHub

PMario

unread,
Aug 1, 2021, 12:17:44 PM8/1/21
to TiddlyWiki
Hi, 

Since Tony did present a workable solution, the issue was moved to the discussions section at github. https://github.com/Jermolene/TiddlyWiki5/discussions/5925

I still think, that a <<duplicates>> macro may reduce the complexity of the solution.

-mario

paulgilbert2000

unread,
Aug 1, 2021, 7:23:23 PM8/1/21
to TiddlyWiki
Hi,

is it possible to use the same code for multiple criteria, so highlight in red all occurrences of duplicates in field A and also field B within the same list of tiddlers?

i guess my question is can a Get / then  be used within the same filter multiple times for multiple fields/criteria

thanks

TW Tones

unread,
Aug 1, 2021, 8:33:26 PM8/1/21
to TiddlyWiki
Mohamad,

My solution above can be used to do this for multiple fields/criteria because it re-examines the whole list every time. This makes it logically very flexible but revisiting the whole list for every special field for each tiddler is not very high performance. There are other "algorithms you can deploy" if you describe the full problem, especially if you can share test data.

The thing is, what you want to achieve could be addressed more efficiently with better knowledge of the input data(set), and ensuring that data is arranged appropriately. Over in the aforementioned  github item https://github.com/Jermolene/TiddlyWiki5/discussions/5925 I think a solution may be a report widget designed for most reporting requirements ie beyond the list widget features. However even in this case you will need to give further thought on your input data and its structure.

Mohamad - you could generate a list of tiddlers with duplicate A fields and another with a list of duplicate B fields then in the list test if each title exists in these lists.

Regards
Tones

paulgilbert2000

unread,
Aug 7, 2021, 12:05:57 PM8/7/21
to TiddlyWiki
Hi Tones,

sorry for the late reply , i wasn't clear at all in my last question actually

So for example ,if  every tiddler has three fields  , field_example , field_example2 and  field_example3

Capture.PNG

and they are populated with values as such

       tiddler 1    has in field_example "3" And in field_example2 "2"    And in field_example3 "6"   
and
       tiddler 2    has in field_example "4" And in field_example2 "9"    And in field_example3 "8"   
and
       tiddler 3    has in field_example "2" And in field_example2 "7"    And in field_example3 "5"   
and
       tiddler 4    has in field_example "1" And in field_example2 "2"    And in field_example3 "4"  


 as you can see, the number is reoccurring in different fields in different tiddlers , so when doing a list, can all these tiddlers  which has a 2 be highlighted

Capture2.PNG

even better can the transcluded values only be highlighted and not the whole line
Capture3.PNG

i have attached a sample file with with the test data i am working with
 

Thanks again for your help
example.html

TW Tones

unread,
Aug 8, 2021, 1:31:10 AM8/8/21
to TiddlyWiki
Mohamad,

I am happy to look at solving the problem presented but my suspicion remains that there may be a different way to put the question in the first place. 

Sometimes a question can be rephrased such that the answer is simpler to find.
  • In this we have multiple tiddlers, with multiple fields, with values that may be duplicated across these tiddlers/fields.
  • in effect you want to list all tiddlers using the select fields, list these for each tiddler then for each found value
    •  detect when that value occurs in any other tiddler (not self?) or select fields, if it does highlight it.
  • I am not sure why you want to do this and can think of many ways to list/interpret the data! 
  • What about triplicates?
  • What about duplicates in the same tiddler?
I think using your test data this is what you wanted?

<ul>
<$list filter="[all[]has[field_example]]"><!-- each tiddler meeting condition -->
   <$set name=other-values filter="[all[]!<currentTiddler>get[field_example]] [all[]!title<currentTiddler>get[field_example2]] [all[]!title<currentTiddler>get[field_example3]] +[sort[]]"><!-- for this tiddler build a list of all values in the three fields except this tiddlers -->
   <li><<currentTiddler>>: |  
   <$list filter="[all[current]get[field_example]] [all[current]get[field_example2]] [all[current]get[field_example3]]" variable=field-value><!-- for each example field get the value on the current tiddler-->
        <span style={{{ [enlist<other-values>match<field-value>then[color: red;]] }}}><<field-value>></span><!-- change the style to color red if any other-values match the current value -->
    </$list></li>
   </$set>
</$list>
</ul>

It will also highlight triplicates...

A slightly more efficient method is available that could actually could the number of repeats and color red if > 1

<$set name=all-values filter="=[all[]get[field_example]] =[all[]get[field_example2]] =[all[]get[field_example3]]"><!-- get all values in all three fields using = so duplicates are not removed -->
"<<all-values>>" {{{ [<all-values>split[ ]count[]] }}}
<ul>
<$list filter="[all[]has[field_example]]"><!-- each tiddler meeting given condition -->
   <li><<currentTiddler>>: |  
   <$list filter="[all[current]get[field_example]] [all[current]get[field_example2]] [all[current]get[field_example3]]" variable=field-value><!-- for each example field get the value on the current tiddler-->
        <$set name=value-count filter="[<all-values>split[ ]match<field-value>count[]]">
        <span style={{{ [<value-count>compare:number:gt[1]then[color: Red;]] }}} ><<field-value>> (<<value-count>>)</span><!-- change the style to color red if any other-values match the current value -->
         </$set>
    </$list></li>
</$list>
</ul>
</$set>

Of course in the above you can choose not to show the count of the same value delete  "(<<value-count>>)"

Regards
Tones

paulgilbert2000

unread,
Aug 8, 2021, 7:10:18 PM8/8/21
to TiddlyWiki
Thank you tones

Will take me a while to understand all that . but it works like a charm , and its even more than what i have asked for

thanks again:)

paulgilbert2000

unread,
Aug 14, 2021, 8:26:32 PM8/14/21
to TiddlyWiki
Sorry one more questions

if the values are dates, how can they be displayed in normal format ,and not the tiddly wiki format

TW Tones

unread,
Aug 15, 2021, 4:12:57 AM8/15/21
to TiddlyWiki
Look for and use the viewWidget and use the format date with a template, or the format relativedate

Get into the habit also of searching in tiddlywiki.com to learn how to do things.
Snag_c8a06a9.png

eg;

<$view field=created format=date template="YYYY"/>

<$view field=created format=relativedate/>


Regards
Tones

paulgilbert2000

unread,
Aug 15, 2021, 11:46:55 AM8/15/21
to TiddlyWiki
HI tones,

sorry i guess i asked the wrong question, what i wanted to know is where to place the widget  in the code , if i do it that way , it no longer highlights duplicates

 <li><<currentTiddler>>: |  
   <$list filter="[all[current]get[field_example]] [all[current]get[field_example2]] [all[current]get[field_example3]]" variable=field-value><!-- for each example field get the value on the current tiddler-->
<$view field="field_example "format=date template="YYYY"/>
<$view field="field_example1"format=date template="YYYY"/>
<$view field="field_example2"format=date template="YYYY"/>

 <span style={{{ [enlist<other-values>match<field-value>then[color: red;]] }}}><<field-value>></span><!-- change the style to color red if any other-values match the current value -->

    </$list></li>

i also tried  adding format:date[DDD]] , which didn't yield any results

   <$list filter="[all[current]get[field_example]] [all[current]get[field_example2]] [all[current]get[field_example3]]" format:date[DDD]] variable=field-value>

TW Tones

unread,
Aug 15, 2021, 8:34:07 PM8/15/21
to TiddlyWiki
Mohammad,

I am confused, until now the fields  field_example,  field_example1,  field_example2 did not contain dates. 
  • Are you trying to convert these to dates?
  • the view widget format=date only works on tiddlywiki full serial number dates!
Perhaps step back and describe what you want to do in the real world, not with tiddlywiki code that may or may not be correct. 

Regards
Tones

paulgilbert2000

unread,
Aug 15, 2021, 10:14:51 PM8/15/21
to TiddlyWiki
Thank you tones

The real life example is to evaluate duplicate dates, so the actual real values populating the fields are not  1 ,2 , etc.. they are actual dates , IE . 20210625062959999,   20210811055859000,etc.
and so what i was trying is to  do is have the highlighted duplicate values converted from the tiddly wiki format they are stored in in their respective fields , to a normal readable format when displayed in the filter

the

TW Tones

unread,
Aug 16, 2021, 12:29:52 AM8/16/21
to TiddlyWiki
Hio,

Back in my code
<ul>
<$list filter="[all[]prefix[New]has[field]]">
   <li><span style={{{ [all[]prefix[New]!title<currentTiddler>get[field]match{!!field}then[color: red;]] }}}> <<currentTiddler>> {{!!field}}</span></li>
</$list>
</ul>


<<currentTiddler>> {{!!field}} is the display
replace this with 
{{{ [all[current]get[field]format:date[]] }}}
Not tested by me on this occasion

where field is the chosen fieldname.

Regards
Tones

paulgilbert2000

unread,
Aug 20, 2021, 11:14:38 PM8/20/21
to TiddlyWiki
Hi Tones,

I am not sure which line of code you are referring too , the line that does the coloring is
<$list filter="[all[current]get[field_example]] [all[current]get[field_example2]] [all[current]get[field_example3]]" variable=field-value><!-- for each example field get the value on the current tiddler-->
        <span style={{{ [enlist<other-values>match<field-value>then[color: red;]] }}}><<field-value>></span>

It does not have <<currentTiddler>> {{!!field}}

instead there is  <<field-value>>  ,so is this the bit that should be replaced ?

i tried this  with no luck..

Capture.PNG

paulgilbert2000

unread,
Aug 27, 2021, 12:13:48 PM8/27/21
to TiddlyWiki
Hi tones,

have you had the chance to look at my last post?

TW Tones

unread,
Aug 27, 2021, 7:44:23 PM8/27/21
to TiddlyWiki
The information you are after is in my earlier post
<<currentTiddler>> {{!!field}} is the display replace this with {{{ [all[current]get[field]format:date[]] }}}

It is what is inside the span that gets coloured using style attribute, thus what is inside the span is what is displayed,

<li><span style={{{ [all[]prefix[New]!title<currentTiddler>get[field]match{!!field}then[color: red;]] }}}> this is displayed inside the list</span></li>

So basically we replace the display of  {{!!field}} 
With {{{ [all[current]get[field]format:date[]] }}}
(change "field" to your date field)

So the following will be inside the span because you want the title and its date.
<<currentTiddler>> {{{ [all[current]get[field]format:date[]] }}}

The format operator requires tiddlywiki 5.1.23 or greater

Tones

paulgilbert2000

unread,
Aug 28, 2021, 10:38:56 PM8/28/21
to TiddlyWiki
thanks tones,

back one step , the original code was ..

  <span style={{{ [enlist<other-values>match<field-value>then[color: red;]] }}}><<field-value>></span><!-- change the style to color red if any other-values match the current value -->
    </$list></li>
   </$set>
</$list>
</ul>
the modified code is as follows

<li><span style={{{ [all[]prefix[New]!title<currentTiddler>get[field]match{!!field}then[color: red;]] }}}> this is displayed inside the list</span></li>

the instruction is to replace
 {{!!field}} 
With {{{ [all[current]get[field]format:date[]] }}}
(change "field" to your date field)

making the code

<li><span style={{{ [all[]prefix[New]!title<currentTiddler>get[field]match {{{ [all[current]get[field_example]format:date[]] }}} then[color: red;]] }}}> this is displayed inside the list</span></li>

this does not work, prob because i have misinterpreted your instructions

also there are several things missed out in the modified code , the enlist operator, the <other-values>  variable, is this intentional?

if the date field is "field_example"  , can you please tell me what the full line of code would be ..  <Span  to </span>

thanks again

Charlie Veniot

unread,
Aug 29, 2021, 12:42:29 AM8/29/21
to TiddlyWiki
This whole thread inspired me to get my geek on and play my kind of "BrainAge" game: see Some coding fun: A Word Occurrence Highlighter just in case there's anything of use to you in there, even if just the entertainment value...

TW Tones

unread,
Aug 29, 2021, 8:25:28 PM8/29/21
to TiddlyWiki
Mohamad,

Part of the issue here is you have not yet learned the basic syntax of tiddlywiki yet, we all start somewhere, my instructions should have being self evident if you had just rudimentary tiddlywiki syntax, all of which I learned from TiddlyWiki.com 

I did answer this latest question here and you can put {{{ [all[current]get[date-field]format:date[]] }}} where you read this is displayed inside the list

I am happy still to help, but you force me to revisit the whole thread again. I am not sure that when I gave previous answers, you tried to understand what I shared with you, it seems more like you just tried to "plugin my answers" to your code without trying to work it out. I may be wrong but please try a little harder to work through the carefully considered answers you get.

Tones

paulgilbert2000

unread,
Aug 30, 2021, 5:42:21 PM8/30/21
to TiddlyWiki
Thanks tones

actually my problem is not lack of effort but  rather lack of knowledge  :( , i try many different things before coming back, its just like you said i am guilty of trying to plug in the code rather than fully understanding it

well then ..i guess its time for me to up my game with the filter syntax first  before attempting anything else

i guess for now the thread can be closed, but thanks again for you help :)

TW Tones

unread,
Aug 30, 2021, 11:25:59 PM8/30/21
to TiddlyWiki
Mohamad,

Sorry, I did not mean to imply you were not putting in the effort, more that you needed to direct it elsewhere first.

Although it is great to see you are keen and jumping into it, it can just make it a little hard to support you. Don't be shy to keep asking, but trust in your ability to learn yourself as well.

Tones
Reply all
Reply to author
Forward
0 new messages