Giter VIP home page Giter VIP logo

Comments (9)

timdream avatar timdream commented on July 26, 2024 1

The code block in https://timdream.org/wordcloud2.js/#love provides the exact example.

from wordcloud2.js.

khaivngo avatar khaivngo commented on July 26, 2024

Proposed a solution here: #61

from wordcloud2.js.

timdream avatar timdream commented on July 26, 2024

Sorry about the late reply. I agree this feature, but I don't think each of the item should be represented as arrays anymore. How about let's do a little refactor first like this?

[ { word: 'foo', score: 6, color: '#00b2ee' }, ... ]

Please maintain compatibility with the old syntax by checking the object type, with, e.g.,

if (Array.isArray(foo)) {
  foo = { word: foo[0], score: foo[1] };
}

Thank you!

from wordcloud2.js.

khaivngo avatar khaivngo commented on July 26, 2024

Of course, you know the code best. Do you have any estimation on when you are able to implement it?

from wordcloud2.js.

timdream avatar timdream commented on July 26, 2024

Don't think I will be able to work on this anytime soon. I think you are capable of working on this and you should. Thanks for helping out!

from wordcloud2.js.

Pyot avatar Pyot commented on July 26, 2024

Hi,
I try differently loop through the array but I can setup individual colour for a single word. I have seen in API documentation callback function but I don't understand how to apply to code. I get continuously syntax error.
Is it any chance to get an example of code how to do that?

from wordcloud2.js.

Pyot avatar Pyot commented on July 26, 2024

Thank you,
It's working. :)

from wordcloud2.js.

GitFr33 avatar GitFr33 commented on July 26, 2024

When trying to utilizes this feature I have run into some challenges.

It seems that when item is passed in to the color callback function it only contains the word and not any other of the array elements. In contrast the item works as expected when passed into the click callback.

This can be seen by editing the example configuration at https://timdream.org/wordcloud2.js/#love with the following:

color: function(item){
   console.log(item);
 },
click: function(item){
   console.log(item);
 }

The first callback logs just the word, the second one logs the array of word and number.

from wordcloud2.js.

raefa avatar raefa commented on July 26, 2024

I had the same issue. In case it helps anyone, here is my workaround. Seems to do the job.

    var list = [
      ['foo', 40, '#FD0100'], 
      ['bar', 60, '#019240']
    ];
    var listColorCounter = 0;
    
    WordCloud(document.getElementById(divId), { 
      list: list,
      fontFamily: 'Open Sans, Arial, sans-serif',
      color: function () {
        return list[listColorCounter++][2];
      },
      click: function(item){
        console.log(item);
      },
      rotateRatio: 0.5,
      rotationSteps: 2,
      backgroundColor: '#FAF6EB'
    });

from wordcloud2.js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.