You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
1.4 KiB
47 lines
1.4 KiB
package com.animal.command;
|
|
|
|
import com.animal.model.Animal;
|
|
import com.animal.visualization.AnimalVisualization;
|
|
import com.animal.exception.CrawlerException;
|
|
|
|
import java.io.IOException;
|
|
import java.util.List;
|
|
|
|
/**
|
|
* 可视化命令 - 生成可视化图表
|
|
*/
|
|
public class VisualizeCommand implements Command {
|
|
private List<Animal> animals;
|
|
|
|
public VisualizeCommand(List<Animal> animals) {
|
|
this.animals = animals;
|
|
}
|
|
|
|
@Override
|
|
public void execute() throws CrawlerException {
|
|
if (animals == null || animals.isEmpty()) {
|
|
throw new CrawlerException("没有可可视化的数据,请先执行爬取命令");
|
|
}
|
|
|
|
AnimalVisualization visualization = new AnimalVisualization();
|
|
|
|
try {
|
|
System.out.println("正在生成可视化图表...");
|
|
visualization.createStatusDistributionChart(animals);
|
|
visualization.createPopulationChart(animals);
|
|
System.out.println("可视化图表生成完成!");
|
|
} catch (IOException e) {
|
|
throw new CrawlerException("生成图表失败: " + e.getMessage(), e);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public String getName() {
|
|
return "visualize";
|
|
}
|
|
|
|
@Override
|
|
public String getDescription() {
|
|
return "生成可视化图表(保护状态饼图和种群数量柱状图)";
|
|
}
|
|
}
|
|
|