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.
243 lines
7.5 KiB
243 lines
7.5 KiB
7 years ago
|
package com.fr.plugin.demo.fun;
|
||
7 years ago
|
|
||
|
import com.fr.extended.chart.AbstractChart;
|
||
|
import com.fr.extended.chart.HyperLinkPara;
|
||
7 years ago
|
import com.fr.extended.chart.StringFormula;
|
||
7 years ago
|
import com.fr.extended.chart.export.ExportProcessor;
|
||
|
import com.fr.extended.chart.export.JSExportProcessor;
|
||
|
import com.fr.general.GeneralUtils;
|
||
7 years ago
|
import com.fr.intelli.record.Focus;
|
||
|
import com.fr.intelli.record.Original;
|
||
7 years ago
|
import com.fr.json.JSON;
|
||
|
import com.fr.json.JSONArray;
|
||
|
import com.fr.json.JSONException;
|
||
|
import com.fr.json.JSONFactory;
|
||
|
import com.fr.json.JSONObject;
|
||
7 years ago
|
import com.fr.record.analyzer.EnableMetrics;
|
||
7 years ago
|
import com.fr.stable.AssistUtils;
|
||
7 years ago
|
import com.fr.stable.web.Repository;
|
||
|
import com.fr.stable.xml.XMLPrintWriter;
|
||
|
import com.fr.stable.xml.XMLableReader;
|
||
|
|
||
|
import java.util.ArrayList;
|
||
|
import java.util.List;
|
||
|
|
||
|
/**
|
||
|
* Created by shine on 2018/3/24.
|
||
|
*/
|
||
7 years ago
|
@EnableMetrics
|
||
|
public class DemoChart extends AbstractChart<DemoDataConfig> {
|
||
7 years ago
|
|
||
|
private static final String ID = "DEMO_CHART";
|
||
|
private static final String NAME = "DEMO图表";
|
||
|
|
||
7 years ago
|
private StringFormula titleFormula = new StringFormula();
|
||
7 years ago
|
|
||
7 years ago
|
private ThemeType themeType = ThemeType.DARK;
|
||
|
|
||
7 years ago
|
private boolean threeDimensional = false;
|
||
|
|
||
|
public boolean isThreeDimensional() {
|
||
|
return threeDimensional;
|
||
|
}
|
||
|
|
||
|
public void setThreeDimensional(boolean threeDimensional) {
|
||
|
this.threeDimensional = threeDimensional;
|
||
|
}
|
||
|
|
||
7 years ago
|
public ThemeType getThemeType() {
|
||
|
return themeType;
|
||
|
}
|
||
|
|
||
|
public void setThemeType(ThemeType themeType) {
|
||
|
this.themeType = themeType;
|
||
|
}
|
||
|
|
||
7 years ago
|
public StringFormula getTitleFormula() {
|
||
7 years ago
|
return titleFormula;
|
||
|
}
|
||
|
|
||
7 years ago
|
public void setTitleFormula(StringFormula titleFormula) {
|
||
7 years ago
|
this.titleFormula = titleFormula;
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
protected void readAttr(XMLableReader reader) {
|
||
|
super.readAttr(reader);
|
||
7 years ago
|
this.setThemeType(ThemeType.parseInt(reader.getAttrAsInt("theme", 0)));
|
||
7 years ago
|
this.setThreeDimensional(reader.getAttrAsBoolean("threeD", false));
|
||
7 years ago
|
this.getTitleFormula().readAttr("title", reader);
|
||
7 years ago
|
}
|
||
|
|
||
|
@Override
|
||
|
protected void writeAttr(XMLPrintWriter writer) {
|
||
|
super.writeAttr(writer);
|
||
7 years ago
|
writer.attr("theme", getThemeType().ordinal());
|
||
7 years ago
|
writer.attr("threeD", isThreeDimensional());
|
||
7 years ago
|
this.getTitleFormula().writeAttr("title", writer);
|
||
7 years ago
|
}
|
||
|
|
||
7 years ago
|
@Override
|
||
|
public Object clone() throws CloneNotSupportedException {
|
||
|
DemoChart result = (DemoChart) super.clone();
|
||
7 years ago
|
if (getTitleFormula() != null) {
|
||
|
result.setTitleFormula(this.getTitleFormula().clone());
|
||
|
}
|
||
7 years ago
|
result.setThemeType(this.getThemeType());
|
||
7 years ago
|
result.setThreeDimensional(this.isThreeDimensional());
|
||
7 years ago
|
return result;
|
||
|
}
|
||
|
|
||
|
|
||
7 years ago
|
@Override
|
||
|
protected String getChartID() {
|
||
|
return ID;
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public String getChartName() {
|
||
|
return NAME;
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
protected String demoImagePath() {
|
||
|
return "com/fr/plugin/demo/demo.png";
|
||
|
}
|
||
|
|
||
|
@Override
|
||
7 years ago
|
@Focus(id = DemoChartConstants.PLUGIN_ID, text = "", source = Original.PLUGIN)
|
||
7 years ago
|
protected void addJSON(DemoDataConfig dataConfig, JSONObject jsonObject, Repository repo, JSONPara para) throws JSONException {
|
||
7 years ago
|
jsonObject.put("theme", getThemeType() == ThemeType.DARK ? "dark" : "sth whatever");
|
||
7 years ago
|
|
||
7 years ago
|
jsonObject.put("title", JSONFactory.createJSON(JSON.OBJECT).put("text", getTitleFormula().getResult()));
|
||
7 years ago
|
|
||
|
JSONArray array = JSONFactory.createJSON(JSON.ARRAY);
|
||
|
|
||
|
double maxValue = Double.MIN_VALUE;
|
||
|
|
||
7 years ago
|
if (dataConfig != null) {
|
||
|
List<Object> xValues = dataConfig.getX().getValues();
|
||
|
List<Object> yValues = dataConfig.getY().getValues();
|
||
|
List<Object> zValues = dataConfig.getZ().getValues();
|
||
|
|
||
7 years ago
|
// jsonObject.put("targetName", dataConfig.getTargetName());
|
||
7 years ago
|
|
||
7 years ago
|
// List<Object> expectList = dataConfig.getExpect().getValues();
|
||
|
// List<Object> actualList = dataConfig.getActual().getValues();
|
||
|
|
||
|
List<Object> customNames = dataConfig.getCustomNameField().getValues();
|
||
|
List<Object> customValues = dataConfig.getCustomValueField().getValues();
|
||
7 years ago
|
|
||
7 years ago
|
for (int i = 0, len = xValues.size(); i < len; i++) {
|
||
|
maxValue = Math.max(GeneralUtils.objectToNumber(zValues.get(i)).doubleValue(), maxValue);
|
||
|
|
||
|
array.put(JSONFactory.createJSON(JSON.ARRAY).put(xValues.get(i)).put(yValues.get(i)).put(zValues.get(i)));
|
||
|
}
|
||
7 years ago
|
}
|
||
|
|
||
|
jsonObject.put("series", JSONFactory.createJSON(JSON.OBJECT).put("type", "bar3D").put("data", array)
|
||
|
.put("bevelSize", 0.2).put("bevelSmoothness", 2).put("shading", "color"));
|
||
|
|
||
|
jsonObject.put("xAxis3D", JSONFactory.createJSON(JSON.OBJECT).put("type", "category"))
|
||
|
.put("yAxis3D", JSONFactory.createJSON(JSON.OBJECT).put("type", "category"))
|
||
|
.put("zAxis3D", JSONFactory.createJSON(JSON.OBJECT).put("type", "value"));
|
||
|
|
||
|
jsonObject.put("grid3D", JSONFactory.createJSON(JSON.OBJECT).put("boxWidth", 200).put("boxDepth", 80));
|
||
|
|
||
|
jsonObject.put("visualMap", JSONFactory.createJSON(JSON.OBJECT)
|
||
|
.put("max", maxValue)
|
||
|
.put("color", JSONFactory.createJSON(JSON.ARRAY).put("#d94e5d").put("#eac736").put("#50a3ba")));
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
protected String[] requiredJS() {
|
||
|
return new String[]{
|
||
|
"com/fr/plugin/demo/demoWrapper.js",
|
||
|
"com/fr/plugin/demo/echarts.js",
|
||
|
"com/fr/plugin/demo/echarts-gl.js"
|
||
|
};
|
||
|
}
|
||
|
|
||
7 years ago
|
@Override
|
||
|
protected String[] requiredCSS() {
|
||
|
return new String[]{
|
||
|
"com/fr/plugin/demo/demo.css"
|
||
|
};
|
||
|
}
|
||
|
|
||
7 years ago
|
@Override
|
||
|
protected String wrapperName() {
|
||
|
return "demoWrapper";
|
||
|
}
|
||
|
|
||
|
private static final HyperLinkPara X = new HyperLinkPara() {
|
||
|
@Override
|
||
|
public String getName() {
|
||
|
return "X轴";
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public String getFormulaContent() {
|
||
|
return "X";
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public String[] getProps() {
|
||
|
return new String[]{"data", "0"};
|
||
|
}
|
||
|
};
|
||
|
|
||
|
private static final HyperLinkPara Y = new HyperLinkPara() {
|
||
|
@Override
|
||
|
public String getName() {
|
||
|
return "Y轴";
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public String getFormulaContent() {
|
||
|
return "Y";
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public String[] getProps() {
|
||
|
return new String[]{"data", "1"};
|
||
|
}
|
||
|
};
|
||
|
|
||
|
private static final HyperLinkPara[] PARAS = new HyperLinkPara[]{
|
||
|
X,
|
||
|
Y
|
||
|
};
|
||
|
|
||
|
@Override
|
||
|
protected HyperLinkPara[] hyperLinkParas() {
|
||
|
return PARAS;
|
||
|
}
|
||
|
|
||
|
@Override
|
||
7 years ago
|
protected List<StringFormula> formulas() {
|
||
|
List<StringFormula> list = new ArrayList<StringFormula>();
|
||
7 years ago
|
list.add(this.getTitleFormula());
|
||
|
return list;
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
protected ExportProcessor createExportProcessor() {
|
||
|
return new JSExportProcessor();
|
||
|
}
|
||
|
|
||
7 years ago
|
@Override
|
||
|
public int hashCode() {
|
||
|
return super.hashCode() + AssistUtils.hashCode(this.getTitleFormula(), this.getThemeType(), this.isThreeDimensional());
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public boolean equals(Object ob) {
|
||
|
return super.equals(ob)
|
||
|
&& ob instanceof DemoChart
|
||
|
&& AssistUtils.equals(this.getTitleFormula(), ((DemoChart) ob).getTitleFormula())
|
||
|
&& AssistUtils.equals(this.getThemeType(), ((DemoChart) ob).getThemeType())
|
||
|
&& AssistUtils.equals(this.isThreeDimensional(), ((DemoChart) ob).isThreeDimensional());
|
||
|
}
|
||
7 years ago
|
}
|