rbarbantan / android-word-cloud

Example of a javascript word cloud made with D3 in Android
MIT License
11 stars 2 forks source link

is it possible to customize the d3 cloud through android programmatically? #3

Open yummyummyummy opened 6 years ago

yummyummyummy commented 6 years ago

Hi I am trying to attach d3 word cloud in my android app. To support many kinds of android devices, I wanna optimize the word cloud's size programmatically. Also, fontSize and color of each words. Can you give me any hints? I am not really familiar with js so it is very difficult for me. Thank you.

rbarbantan commented 6 years ago

All the logic in done in d3.js (https://d3js.org/). There really is no way around it. You can compute some of the values (like the size) in java/android and pass them as parameters, just like you pass the "wordCloud" in MainActivity. For example, replace change the StringBuilder to include other params, like: sb.append("], 300)"); and in javascript, replace the hardcoded values with variables:

function wordCloud(data, cloudSize) {
    var fill = d3.scale.category20();
    var layout = d3.layout.cloud().size([cloudSize, cloudSize ])
...
yummyummyummy commented 6 years ago

Thank you so much. It helped me a lot