Skip to content

Commit

Permalink
add
Browse files Browse the repository at this point in the history
  • Loading branch information
houbb committed Nov 23, 2021
1 parent 217c57c commit b59bf29
Show file tree
Hide file tree
Showing 29 changed files with 676 additions and 133 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,10 @@

| 序号 | 变更类型 | 说明 | 时间 | 备注 |
|:---|:---|:---|:---|:--|
| 1 | A | 新增 InputStream 形式的输入流 | 2021-07-06 19:21:55 | |
| 1 | A | 新增 InputStream 形式的输入流 | 2021-07-06 19:21:55 | |

# release_1.3.0

| 序号 | 变更类型 | 说明 | 时间 | 备注 |
|:---|:---|:---|:---|:--|
| 1 | A | 实现优化,便于拓展 | 2021-11-23 19:21:55 | |
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
<dependency>
<groupId>com.github.houbb</groupId>
<artifactId>word-cloud</artifactId>
<version>1.2.2</version>
<version>1.3.0</version>
</dependency>
```

Expand Down Expand Up @@ -78,6 +78,12 @@ WordCloudHelper.wordCloud(text, "out_bg.png", imagePath);

![out_bg.png](https://github.com/houbb/word-cloud/raw/master/out_bg.png)

## 自定义

结合汉字拆分实现的效果。

![out_chaizi.png](out_chaizi.png)

# Road-Map

- [x] 默认的形状,图片。
Expand All @@ -98,4 +104,4 @@ WordCloudHelper.wordCloud(text, "out_bg.png", imagePath);

如果喜欢,不妨给个 star 鼓励一下作者。

希望和你一起,见证最好用的云图工具的成长。
希望和你一起,见证最好用的云图工具的成长。
Binary file added out_chaizi.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 11 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

<groupId>com.github.houbb</groupId>
<artifactId>word-cloud</artifactId>
<version>1.2.2</version>
<version>1.3.0</version>

<properties>
<!--============================== All Plugins START ==============================-->
Expand Down Expand Up @@ -61,6 +61,15 @@
<artifactId>kumo</artifactId>
<version>${kumo.version}</version>
</dependency>

<dependency>
<groupId>com.github.houbb</groupId>
<artifactId>nlp-chaizi</artifactId>
<version>1.1.0</version>
<optional>true</optional>
<scope>test</scope>
</dependency>

</dependencies>

<build>
Expand Down Expand Up @@ -224,4 +233,4 @@
</profile>
</profiles>

</project>
</project>
4 changes: 2 additions & 2 deletions release.bat
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ ECHO "============================= RELEASE START..."

:: 版本号信息(需要手动指定)
:::: 旧版本名称
SET version=1.2.2
SET version=1.3.0
:::: 新版本名称
SET newVersion=1.3.0
SET newVersion=1.4.0
:::: 组织名称
SET groupName=com.github.houbb
:::: 项目名称
Expand Down
136 changes: 67 additions & 69 deletions src/main/java/com/github/houbb/word/cloud/bs/WordCloudBs.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
package com.github.houbb.word.cloud.bs;

import com.github.houbb.word.cloud.support.freq.DefaultWordFrequency;
import com.github.houbb.word.cloud.support.background.Backgrounds;
import com.github.houbb.word.cloud.support.background.IBackground;
import com.github.houbb.word.cloud.support.color.ColorPalettes;
import com.github.houbb.word.cloud.support.color.IColorPalette;
import com.github.houbb.word.cloud.support.font.IWordKumoFont;
import com.github.houbb.word.cloud.support.font.WordKumoFonts;
import com.github.houbb.word.cloud.support.fontscalar.IWordFontScalar;
import com.github.houbb.word.cloud.support.fontscalar.WordFontScalars;
import com.github.houbb.word.cloud.support.freq.IWordFrequency;
import com.github.houbb.word.cloud.support.freq.WordFrequencies;
import com.github.houbb.word.cloud.support.freq.WordFrequencyContext;
import com.kennycason.kumo.CollisionMode;
import com.kennycason.kumo.WordCloud;
import com.kennycason.kumo.WordFrequency;
import com.kennycason.kumo.bg.Background;
import com.kennycason.kumo.font.FontWeight;
import com.kennycason.kumo.font.KumoFont;
import com.kennycason.kumo.font.scale.FontScalar;
import com.kennycason.kumo.font.scale.LinearFontScalar;
import com.kennycason.kumo.palette.ColorPalette;

import java.awt.*;
import java.util.List;
import java.util.Random;
import java.util.concurrent.ThreadLocalRandom;

/**
* @author binbin.hou
Expand All @@ -36,24 +37,12 @@ public static WordCloudBs newInstance() {
*/
private String outPath = "out.png";

/**
* 词频实现
* @since 1.0.0
*/
private IWordFrequency wordFrequency = new DefaultWordFrequency();

/**
* 文本内容
* @since 1.0.0
*/
private String text = "我爱云图,云图爱我";

/**
* 限制个数
* @since 1.0.0
*/
private int limit = Integer.MAX_VALUE;

/**
* 宽度
* @since 1.0.0
Expand All @@ -67,53 +56,67 @@ public static WordCloudBs newInstance() {
private int height = 600;

/**
* 碰撞模式
* padding 的大小
* @since 1.0.0
*/
private CollisionMode collisionMode = CollisionMode.PIXEL_PERFECT;
private int padding = 0;

/**
* padding 的大小
* 碰撞模式
* @since 1.0.0
*/
private int padding = 0;
private CollisionMode collisionMode = CollisionMode.PIXEL_PERFECT;

/**
* 背景色
*/
private Color backgroundColor = Color.WHITE;

/**
* 词频实现
* @since 1.0.0
*/
private IWordFrequency wordFrequency = WordFrequencies.defaults();

/**
* 背景
*/
private Background background;
private IBackground background = Backgrounds.none();

private FontScalar fontScalar = new LinearFontScalar(10, 40);
/**
* 色彩
* @since 1.3.0
*/
private IColorPalette colorPalette = ColorPalettes.random();

/**
* 字体标量
* @since 1.3.0
*/
private IWordFontScalar fontScalar = WordFontScalars.linear();

private KumoFont kumoFont = new KumoFont("Default", FontWeight.BOLD);
/**
* 字体
* @since 1.3.0
*/
private IWordKumoFont kumoFont = WordKumoFonts.kumo();

private ColorPalette colorPalette = buildRandomColorPalette(5);
/**
* 限制数量
* @since 1.3.0
*/
private int limit = Integer.MAX_VALUE;

public WordCloudBs outPath(String outPath) {
this.outPath = outPath;
return this;
}

public WordCloudBs wordFrequency(IWordFrequency wordFrequency) {
this.wordFrequency = wordFrequency;
return this;
}

public WordCloudBs text(String text) {
this.text = text;
return this;
}

public WordCloudBs limit(int limit) {
this.limit = limit;
return this;
}

public WordCloudBs width(int width) {
this.width = width;
return this;
Expand All @@ -124,13 +127,13 @@ public WordCloudBs height(int height) {
return this;
}

public WordCloudBs collisionMode(CollisionMode collisionMode) {
this.collisionMode = collisionMode;
public WordCloudBs padding(int padding) {
this.padding = padding;
return this;
}

public WordCloudBs padding(int padding) {
this.padding = padding;
public WordCloudBs collisionMode(CollisionMode collisionMode) {
this.collisionMode = collisionMode;
return this;
}

Expand All @@ -139,23 +142,33 @@ public WordCloudBs backgroundColor(Color backgroundColor) {
return this;
}

public WordCloudBs background(Background background) {
public WordCloudBs wordFrequency(IWordFrequency wordFrequency) {
this.wordFrequency = wordFrequency;
return this;
}

public WordCloudBs background(IBackground background) {
this.background = background;
return this;
}

public WordCloudBs fontScalar(FontScalar fontScalar) {
public WordCloudBs colorPalette(IColorPalette colorPalette) {
this.colorPalette = colorPalette;
return this;
}

public WordCloudBs fontScalar(IWordFontScalar fontScalar) {
this.fontScalar = fontScalar;
return this;
}

public WordCloudBs kumoFont(KumoFont kumoFont) {
public WordCloudBs kumoFont(IWordKumoFont kumoFont) {
this.kumoFont = kumoFont;
return this;
}

public WordCloudBs colorPalette(ColorPalette colorPalette) {
this.colorPalette = colorPalette;
public WordCloudBs limit(int limit) {
this.limit = limit;
return this;
}

Expand All @@ -173,32 +186,17 @@ public void wordCloud() {
final WordCloud wordCloud = new WordCloud(dimension, collisionMode);
wordCloud.setPadding(padding);
wordCloud.setBackgroundColor(this.backgroundColor);
if(background != null) {
wordCloud.setBackground(background);
}

wordCloud.setKumoFont(kumoFont);
wordCloud.setColorPalette(colorPalette);
wordCloud.setFontScalar(fontScalar);
wordCloud.setColorPalette(colorPalette.color());
Background backgroundVal = background.background();
if(backgroundVal != null) {
wordCloud.setBackground(backgroundVal);
}
wordCloud.setFontScalar(fontScalar.fontScalar());
wordCloud.setKumoFont(kumoFont.font());

wordCloud.build(wordFrequencies);
wordCloud.writeToFile(this.outPath);
}

/**
* 构建随机的颜色
* @param n 个数
* @return 结果
* @since 1.1.0
*/
private static ColorPalette buildRandomColorPalette(final int n) {
final Random random = ThreadLocalRandom.current();

final Color[] colors = new Color[n];
for (int i = 0; i < colors.length; i++) {
colors[i] = new Color(random.nextInt(230) + 25, random.nextInt(230) + 25, random.nextInt(230) + 25);
}
return new ColorPalette(colors);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.github.houbb.word.cloud.support.background;

import com.github.houbb.heaven.util.common.ArgUtil;
import com.github.houbb.word.cloud.exception.WordCloudException;
import com.kennycason.kumo.bg.Background;
import com.kennycason.kumo.bg.PixelBoundryBackground;

import java.io.IOException;

/**
* 图片背景
* @author binbin.hou
* @since 1.3.0
*/
public class BackgroundImage implements IBackground{

private final String imagePath;

public BackgroundImage(String imagePath) {
ArgUtil.notEmpty(imagePath, "imagePath");
this.imagePath = imagePath;
}

/**
* 没有背景
*
* @return 背景
*/
public Background background() {
try {
return new PixelBoundryBackground(imagePath);
} catch (IOException e) {
throw new WordCloudException(e);
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.github.houbb.word.cloud.support.background;

import com.kennycason.kumo.bg.Background;

/**
* 背景
* @author binbin.hou
* @since 1.3.0
*/
public class BackgroundNone implements IBackground{

/**
* 没有背景
*
* @return 背景
*/
public Background background() {
return null;
}

}
Loading

0 comments on commit b59bf29

Please sign in to comment.