Reusable Sharepoint content word cloud
Yet another installment of the making patterns series: Reusable Sharepoint content word cloud. This time it’s less of a pattern and more of a reusable object. This one came about because I needed a visual way to analyze some content in a Sharepoint list. I know I have seen word clouds on Sharepoint blogs so I thought it would be simple to find one that would work on any arbitrary set of lists and columns. My searching came up empty, whole bunch of people using the tag cloud web part. That’s not what I needed so I wrote one.
The code is up on my git page YNV Max Powers
Technical Overview:
Like most of the stuff that I write this is an encapsulated javascript object, spCTNWordCloud. All it needs is for you to point it at the list(s) /column(s) then to tell it where to write the word cloud...
The object has two dependencies one jquery, that is for convenience sake and could easily be done away with. The second is on a secondary javascript array that contains common words that I did not want to include in the word cloud. I put this in a separate file for editing’s sake.
The two functions that do the core of the word cloud work are buildFrequencyHash and makeDiv. Both are pretty self-explanatory and have some comments. The build Frequency hash does just that and counts the frequency of words and stores that in a hash where word is the key. Make div uses the frequency of the word to determine the size. It randomly assigns a color and location within the document.
The loadRequests function uses Sharepoints restfull api to query the list(s) so you don’t have to run this in the context of Sharepoint but the URL you give to loadRequests functions should be something from the ListData.svc. I have locally used this library to create word clouds from arbitrary text files on my desktop also. A sample call to create the word cloud is:
spCTNWordCloud.loadRequests('%/_vti_bin/ListData.svc/%listname', function(){writeFrequencyMap(“whereToPut”);});