kopia lustrzana https://github.com/neopoly/tagcloud
				
				
				
			Use a custom word sizer to handle the situation where all words have the same weight
							rodzic
							
								
									d19d604110
								
							
						
					
					
						commit
						4b094ee734
					
				| 
						 | 
				
			
			@ -6,4 +6,5 @@ height=636
 | 
			
		|||
minSize=4
 | 
			
		||||
maxSize=38
 | 
			
		||||
colors=#000000,#3a3a3a,#787878,#b2b2b2
 | 
			
		||||
background=#ffffff
 | 
			
		||||
background=#ffffff
 | 
			
		||||
debug=true
 | 
			
		||||
							
								
								
									
										252
									
								
								input.txt
								
								
								
								
							
							
						
						
									
										252
									
								
								input.txt
								
								
								
								
							| 
						 | 
				
			
			@ -1,156 +1,96 @@
 | 
			
		|||
mythology,50.0
 | 
			
		||||
children,25
 | 
			
		||||
lemonade,25
 | 
			
		||||
compression,25
 | 
			
		||||
usa,25
 | 
			
		||||
Lemon,25
 | 
			
		||||
out,25
 | 
			
		||||
darkness,25
 | 
			
		||||
Brain,25
 | 
			
		||||
puppy,24
 | 
			
		||||
django,24
 | 
			
		||||
customers,24
 | 
			
		||||
Mask,23
 | 
			
		||||
full moon,23
 | 
			
		||||
bus,23
 | 
			
		||||
html,23
 | 
			
		||||
Internet,23
 | 
			
		||||
zombies,22
 | 
			
		||||
bored,22
 | 
			
		||||
yarn,22
 | 
			
		||||
career,22
 | 
			
		||||
pen,22
 | 
			
		||||
computers,22
 | 
			
		||||
Black,22
 | 
			
		||||
potato,21
 | 
			
		||||
Pills,21
 | 
			
		||||
bank,21
 | 
			
		||||
One,21
 | 
			
		||||
investments,21
 | 
			
		||||
Green,21
 | 
			
		||||
web,21
 | 
			
		||||
paper,21
 | 
			
		||||
book,20
 | 
			
		||||
anger,20
 | 
			
		||||
Pencil,20
 | 
			
		||||
read,20
 | 
			
		||||
tricycle,19
 | 
			
		||||
linux,19
 | 
			
		||||
super,19
 | 
			
		||||
ugly,19
 | 
			
		||||
Japan,19
 | 
			
		||||
site,19
 | 
			
		||||
Chocolate,18
 | 
			
		||||
money,18
 | 
			
		||||
danger,18
 | 
			
		||||
White,18
 | 
			
		||||
widget,18
 | 
			
		||||
Penguin,18
 | 
			
		||||
Mint,18
 | 
			
		||||
Low,18
 | 
			
		||||
roof,17
 | 
			
		||||
venture,17
 | 
			
		||||
favorites,17
 | 
			
		||||
nose,17
 | 
			
		||||
sun,17
 | 
			
		||||
clients,17
 | 
			
		||||
dog,17
 | 
			
		||||
ocean,16
 | 
			
		||||
Handle,16
 | 
			
		||||
Pink,16
 | 
			
		||||
find,15
 | 
			
		||||
venture,15
 | 
			
		||||
life,15
 | 
			
		||||
customers,15
 | 
			
		||||
hate microsoft,15
 | 
			
		||||
run,15
 | 
			
		||||
sky,14
 | 
			
		||||
fun,14
 | 
			
		||||
software,14
 | 
			
		||||
wmd,14
 | 
			
		||||
Internet,14
 | 
			
		||||
tomato,14
 | 
			
		||||
SAAS,14
 | 
			
		||||
tag,14
 | 
			
		||||
Orient,14
 | 
			
		||||
 | 
			
		||||
life,14
 | 
			
		||||
bloody,14
 | 
			
		||||
framework,13
 | 
			
		||||
Door,13
 | 
			
		||||
type,13
 | 
			
		||||
firefox,13
 | 
			
		||||
chocolate,13
 | 
			
		||||
Dragon,13
 | 
			
		||||
Cellphone,13
 | 
			
		||||
startup,13
 | 
			
		||||
vodka,13
 | 
			
		||||
china,13
 | 
			
		||||
linux,13
 | 
			
		||||
job,13
 | 
			
		||||
fair,13
 | 
			
		||||
tag,12
 | 
			
		||||
software,12
 | 
			
		||||
Color,12
 | 
			
		||||
pizza,12
 | 
			
		||||
gothic,11
 | 
			
		||||
murder,11
 | 
			
		||||
usa,11
 | 
			
		||||
wordpress,11
 | 
			
		||||
SAAS,11
 | 
			
		||||
High,11
 | 
			
		||||
Knob,11
 | 
			
		||||
farm,11
 | 
			
		||||
Speaker,11
 | 
			
		||||
Knife,11
 | 
			
		||||
Light,10
 | 
			
		||||
startup,10
 | 
			
		||||
Wood,10
 | 
			
		||||
Love,10
 | 
			
		||||
Cat,10
 | 
			
		||||
georgeous,10
 | 
			
		||||
pencil,10
 | 
			
		||||
broken,10
 | 
			
		||||
service,10
 | 
			
		||||
career,10
 | 
			
		||||
cloud,10
 | 
			
		||||
money,10
 | 
			
		||||
html,10
 | 
			
		||||
fun,9
 | 
			
		||||
hippo,9
 | 
			
		||||
service,9
 | 
			
		||||
flag,9
 | 
			
		||||
opera,9
 | 
			
		||||
fallen,9
 | 
			
		||||
vodka,9
 | 
			
		||||
europe,8
 | 
			
		||||
computers,8
 | 
			
		||||
ubuntu,8
 | 
			
		||||
job,8
 | 
			
		||||
web,8
 | 
			
		||||
beer,8
 | 
			
		||||
Dark,8
 | 
			
		||||
development,8
 | 
			
		||||
cruel,8
 | 
			
		||||
google,8
 | 
			
		||||
ubuntu,8
 | 
			
		||||
cloud,7
 | 
			
		||||
Dog,7
 | 
			
		||||
coconut,7
 | 
			
		||||
europe,7
 | 
			
		||||
Brush,7
 | 
			
		||||
early riser,7
 | 
			
		||||
wordpress,7
 | 
			
		||||
development,6
 | 
			
		||||
bank,6
 | 
			
		||||
georgeous,6
 | 
			
		||||
hit,6
 | 
			
		||||
early riser,6
 | 
			
		||||
speaker,6
 | 
			
		||||
investments,6
 | 
			
		||||
opera,6
 | 
			
		||||
firefox,5
 | 
			
		||||
site,5
 | 
			
		||||
china,5
 | 
			
		||||
clients,5
 | 
			
		||||
widget,5
 | 
			
		||||
acceptation, 1
 | 
			
		||||
acceptance, 1
 | 
			
		||||
appreciation, 1
 | 
			
		||||
recognition, 1
 | 
			
		||||
compliment, 1
 | 
			
		||||
acknowledgement, 1
 | 
			
		||||
praise, 1
 | 
			
		||||
respect, 1
 | 
			
		||||
esteem, 1
 | 
			
		||||
dignity, 1
 | 
			
		||||
deference, 1
 | 
			
		||||
appraisement, 1
 | 
			
		||||
appreciation, 1
 | 
			
		||||
valuation, 1
 | 
			
		||||
appreciation, 1
 | 
			
		||||
estimation, 1
 | 
			
		||||
regard, 1
 | 
			
		||||
prestige, 1
 | 
			
		||||
esteem, 1
 | 
			
		||||
importance, 1
 | 
			
		||||
significance, 1
 | 
			
		||||
dignity, 1
 | 
			
		||||
honourableness, 1
 | 
			
		||||
worth, 1
 | 
			
		||||
respect, 1
 | 
			
		||||
relevance, 1
 | 
			
		||||
gratefulness, 1
 | 
			
		||||
acceptance, 1
 | 
			
		||||
salary, 1
 | 
			
		||||
bonus, 1
 | 
			
		||||
pay, 1
 | 
			
		||||
wage, 1
 | 
			
		||||
incentives, 1
 | 
			
		||||
reward, 1
 | 
			
		||||
promotion, 1
 | 
			
		||||
preferment, 1
 | 
			
		||||
goodwill, 1
 | 
			
		||||
favour, 1
 | 
			
		||||
tolerance, 1
 | 
			
		||||
broad-mindedness, 1
 | 
			
		||||
distinction, 1
 | 
			
		||||
award, 1
 | 
			
		||||
honour, 1
 | 
			
		||||
interest, 1
 | 
			
		||||
attention, 1
 | 
			
		||||
friendliness, 1
 | 
			
		||||
training, 1
 | 
			
		||||
education, 1
 | 
			
		||||
scope-of-action, 1
 | 
			
		||||
give-thanks, 1
 | 
			
		||||
thank-you, 1
 | 
			
		||||
family, 1
 | 
			
		||||
friends, 1
 | 
			
		||||
solidarity, 1
 | 
			
		||||
love, 1
 | 
			
		||||
money, 1
 | 
			
		||||
partner, 1
 | 
			
		||||
environment, 1
 | 
			
		||||
wife, 1
 | 
			
		||||
husband, 1
 | 
			
		||||
children, 1
 | 
			
		||||
well-being, 1
 | 
			
		||||
traveling, 1
 | 
			
		||||
career, 1
 | 
			
		||||
creative-ideas, 1
 | 
			
		||||
image, 1
 | 
			
		||||
responsibility, 1
 | 
			
		||||
tolerance, 1
 | 
			
		||||
humanity, 1
 | 
			
		||||
openness, 1
 | 
			
		||||
affection, 1
 | 
			
		||||
moral, 1
 | 
			
		||||
motivation, 1
 | 
			
		||||
leisure-time, 1
 | 
			
		||||
hobbies, 1
 | 
			
		||||
ethics, 1
 | 
			
		||||
health, 1
 | 
			
		||||
sport, 1
 | 
			
		||||
maintaining-contact, 1
 | 
			
		||||
personal-life, 1
 | 
			
		||||
workplace, 1
 | 
			
		||||
loyalty, 1
 | 
			
		||||
honesty, 1
 | 
			
		||||
parents, 1
 | 
			
		||||
foreign-languages, 1
 | 
			
		||||
trust, 1
 | 
			
		||||
solidarity, 1
 | 
			
		||||
growth, 1
 | 
			
		||||
success, 1
 | 
			
		||||
living, 1
 | 
			
		||||
change, 1
 | 
			
		||||
self-esteem, 1
 | 
			
		||||
compassion, 1
 | 
			
		||||
trustworthiness, 1
 | 
			
		||||
laugh, 1
 | 
			
		||||
something, 1
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -21,14 +21,16 @@ public class Tree extends PApplet {
 | 
			
		|||
 | 
			
		||||
        ShapeBasedPlacer placer  = ShapeBasedPlacer.fromFile(config.getShapeFile(), Color.black);
 | 
			
		||||
        InputWords       input   = new InputWords(config.getInputFile());
 | 
			
		||||
        Word[]           words   = input.getWords();
 | 
			
		||||
        TreeColorer      colorer = new TreeColorer(config.getColors());
 | 
			
		||||
        WordSizer        sizer   = new WordSizer(config.getMinSize(), config.getMaxSize(), words);
 | 
			
		||||
 | 
			
		||||
        cram = new WordCram(this)
 | 
			
		||||
            .fromWords(input.getWords())
 | 
			
		||||
            .fromWords(words)
 | 
			
		||||
            .withColorer(colorer)
 | 
			
		||||
            .withPlacer(placer)
 | 
			
		||||
            .withNudger(placer)
 | 
			
		||||
            .sizedByWeight(config.getMinSize(),config.getMaxSize());
 | 
			
		||||
            .withSizer(sizer);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -0,0 +1,33 @@
 | 
			
		|||
import processing.core.PApplet;
 | 
			
		||||
import wordcram.Word;
 | 
			
		||||
 | 
			
		||||
public class WordSizer implements wordcram.WordSizer{
 | 
			
		||||
 | 
			
		||||
    private boolean allEqual = true;
 | 
			
		||||
    private float minSize  = 4;
 | 
			
		||||
    private float maxSize  = 38;
 | 
			
		||||
 | 
			
		||||
    public WordSizer(float minSize, float maxSize, Word[] words){
 | 
			
		||||
        this.minSize = minSize;
 | 
			
		||||
        this.maxSize = maxSize;
 | 
			
		||||
        if(words.length > 0){
 | 
			
		||||
            float initial = words[0].weight;
 | 
			
		||||
            for(Word w : words){
 | 
			
		||||
                if(Math.abs(w.weight - initial) > 0.1){
 | 
			
		||||
                    allEqual = false;
 | 
			
		||||
                    break;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public float sizeFor(Word word, int wordRank, int wordCount) {
 | 
			
		||||
        if(allEqual){
 | 
			
		||||
            return (maxSize - minSize) / 3.0f;
 | 
			
		||||
        }
 | 
			
		||||
        else{
 | 
			
		||||
            return PApplet.lerp(minSize, maxSize, word.weight);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Ładowanie…
	
		Reference in New Issue