Giter VIP home page Giter VIP logo

Comments (4)

timdream avatar timdream commented on July 26, 2024 3

BTW you could listen to wordclouddrawn event and access it's drawn property to tell the word have been drawn or not.

from wordcloud2.js.

timdream avatar timdream commented on July 26, 2024 2

Hi!

In my case, the weight of each words is a number of occurrences. I use the weightFactor function in order to normalize it. The problem is depending on the rotation random some big weighted words are shown or not.
I can change de size of my canvas but by doing so I have sometimes big empty places.

Having some normalize functions choices would be a good enhancement (linear, exp, ..., custom).
Being able to have the size (height or width) of the canvas calculated automatically would be good as well.. Maybe having a function for rotation would be a solution since you can choose if you want to rotate depending on the weight...

Indeed. While there is a custom function to specify the color or weight of a specific word, there isn't a function for rotateRatio. It's possible to patch the code and have it doing so.

I spent quite some time on your wordcloud code looking for a way to have the hover word highlighted. I found your fixed issue but no explanation on how to do so. At the end I found that you use a absolute div (no pointer-event) that you place using dimensions provided by the hover callback. You should say it in your doc :)

The demo page is part of the documentation. This can be made obvious on the doc. Doc sometimes leave important detail because of my inability as non-native English speaker to write great doc, compare to code -- patch to fix either or both is very welcome :)

from wordcloud2.js.

PeterOeClausen avatar PeterOeClausen commented on July 26, 2024 2

@timdream thank you so much for making this man!

Feedback: I thought "woudclouddrawn" was triggered when the whole cloud was finished drawing, however after reading this thread, it is indeed every time a word is drawn.

Using typescript, one can subscribe to the event like this:

document.getElementById('wordcloud-canvas-container').addEventListener('wordclouddrawn', (data : any) => this.onWordCloudDrawn(data));

wordcloud-canvas-container being a div around a canvas:

<div id="wordcloud-canvas-container">
    <canvas id="wordcloud-canvas" width="{{getCanvasWidth()}}" height="{{getCanvasHeight()}}"></canvas>
</div>

Then do something with it in onWordCloudDrawn(), eg print it in the console:

onWordCloudDrawn(eventData : any){
    console.log("Word cloud drawn", eventData);
}

The data has a "detail" property with important information, so my onWordCloudDrawn is actually:

onWordCloudDrawn(eventData : eventData){
    //console.log("Word cloud drawn", eventData);
    console.log(eventData.detail.item[0], eventData.detail.item[1], eventData.detail.drawn);
}

And then eventData is an interface, where I'm able to get the information I'm interested in:

export interface eventData {
    detail : { 
        drawn: boolean, 
        item: string | number [] 
    }
}

For my own project, I'm going to check if all words has been drawn, and then re-scale using the weightFactor property, or let users adjust it and re-draw.

This comment is only to provide a bit of feedback to you, as well as tell others what I was looking for reading this thread 😄

from wordcloud2.js.

bwl21 avatar bwl21 commented on July 26, 2024

I went into a similar issue today. I found out, that the ordering of the entries is pretty relevant. It seems the the cloud is built inside out. So it might make sense to place the longest words first.

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.