Jump to content

Recommended Posts

BACKGROUND:  I would like to insert a jQuery UI widget into my code.  In order to make the widget work, however, it appears to require a more recent version of jQuery.  Should I implement the widget, the HTML in which it resides, the controlling Javascript including the new version of jQuery, as well as the CSS would all be called dynamically when the widget is inserted.  My concern is that the new inserted version of jQuery might interfere with the rest of the page not included in the insert.

QUESTION:  Do I have reason to be concerned?  Please explain your answer.

Share this post


Link to post
Share on other sites

Note that whichever version you include last will overwrite any other version, so if you want to use a particular version for something special then you should include it before your other version and save the reference.  If you are dynamically adding a new version at some later point when some event happens, it's probably going to override your main version, so in that case you need to save a reference to your main version and use that reference in your code.

Of course, it would be preferable to use plugins that will work in a recent version, but for older things that's not always possible.

Share this post


Link to post
Share on other sites

No, I have not forgotten.  Simply, I believe that I have found a way to avoid the problem. Use a technique that does not depend on jQuery.

BACKGROUND:  I have discovered a Javascript package called wordcloud2.js.  In order to run this I need to create a list.  in preparation for this moment I have managed to create an array of objects from the Matomo database that contain the information needed to create the list.  Each object in the array takes the following form:

category: "Site Search / [category]"
count: "[number]"
target: "[search string]"

where the information contained in the brackets are the values of the respective properties of each object.

The array takes on the following appearance:  array {object, object, object, ..., object)

THE GOAL:  Create a list of the following format.

[number] [search string]

[number] [search string]

[number] [search string]

...

[number] [search string]

DILEMMA:  Now, there is plenty of information about how to create objects and arrays from lists.  I need to know how to do just the opposite.

Roddy

Edited by iwato

Share this post


Link to post
Share on other sites

Just loop through the array and build the text from whatever information you want to use in each object.

Share this post


Link to post
Share on other sites

Yes, but what is the format of the resulting list? 

1) Is it pairs of elements separated by commas in a single line.

[count] [search string], [count] [search string], [count] [search string], ... [count] [search string] \n

2) Is it pairs of elements separated by line breaks?

[count] [search string] \n
[count] [search string] \n
[count] [search string] \n

...

[count] [search string] \n

Also, how does Javascript recognize a list as a list?  Is everything closed in parantheses?  Is there a special method that constitutes a list from either of the above two formats.

Then too, what happens, if the search string is composed of multiple words?

It is not as simple a problem, as it would first appear.  Well, at least not for me, at any rate.

Roddy

 

 

 

Share this post


Link to post
Share on other sites
Quote

Yes, but what is the format of the resulting list?

There's not a rule on what you have to build, so build what you need.  An obvious way is to put each item you want into another array, and then join the array elements using whatever separator you want.

Quote

Also, how does Javascript recognize a list as a list?

Javascript does not have a data structure called a list, that is not a well-defined term in Javascript.  If it is string data that is structured a certain way, then you're the one who defines how it is structured (or whatever consumes the data defines what it expects).  If it is a string that is composed of other strings separated by some separator, it makes sense to put them in an array then join them.

Quote

Then too, what happens, if the search string is composed of multiple words?

These are questions that need to be answered by whatever is consuming the data.  Maybe you need a CSV format, for example, with each field quoted.

 

Quote

It is not as simple a problem, as it would first appear.

 

It's not as complex as you think.  Step 1 is figuring out in exactly what format the data needs to be.

If you want each item separated by a newline, it's this easy:

var ar = [];
	for (var i = 0; i < items.length; i++) {
	  ar.push(items[i].number + " " + items[i].search_string);
	}
	var list = ar.join("\n");

Share this post


Link to post
Share on other sites

OK.  Then you appear to agree with the following:

Quote

Load wordcloud.js script to the web page, and run:


WordCloud(document.getElementById('my_canvas'), { list: list } );

where list is an array that look like this: [['foo', 12], ['bar', 6]].

But then, how would you interpret the meaning of {list: list} in the above statement?  Is the first list the name of an object property called list, and the second list an array called list of the form [['foo', 12], ['bar', 6]].

Is it just this simple?

Roddy

Share this post


Link to post
Share on other sites

I have managed to get wordcloud2.js to interact effectively with the Matomo database.  Very soon Grammar Captive will have its own word cloud.

Thank you!

Roddy

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×