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.
245 lines
7.6 KiB
245 lines
7.6 KiB
package com.fr.plugin.demo; |
|
|
|
import com.fr.base.BaseFormula; |
|
import com.fr.extended.chart.AbstractChart; |
|
import com.fr.extended.chart.ExtendedHelper; |
|
import com.fr.extended.chart.HyperLinkPara; |
|
import com.fr.extended.chart.export.ExportProcessor; |
|
import com.fr.extended.chart.export.JSExportProcessor; |
|
import com.fr.general.GeneralUtils; |
|
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; |
|
import com.fr.plugin.transform.ExecuteFunctionRecord; |
|
import com.fr.plugin.transform.FunctionRecorder; |
|
import com.fr.stable.AssistUtils; |
|
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. |
|
*/ |
|
@FunctionRecorder |
|
public class DemoChart extends AbstractChart<DemoDataConfig>{ |
|
|
|
private static final String ID = "DEMO_CHART"; |
|
private static final String NAME = "DEMO图表"; |
|
|
|
private BaseFormula titleFormula; |
|
|
|
private ThemeType themeType = ThemeType.DARK; |
|
|
|
private boolean threeDimensional = false; |
|
|
|
public boolean isThreeDimensional() { |
|
return threeDimensional; |
|
} |
|
|
|
public void setThreeDimensional(boolean threeDimensional) { |
|
this.threeDimensional = threeDimensional; |
|
} |
|
|
|
public ThemeType getThemeType() { |
|
return themeType; |
|
} |
|
|
|
public void setThemeType(ThemeType themeType) { |
|
this.themeType = themeType; |
|
} |
|
|
|
public BaseFormula getTitleFormula() { |
|
return titleFormula; |
|
} |
|
|
|
public void setTitleFormula(BaseFormula titleFormula) { |
|
this.titleFormula = titleFormula; |
|
} |
|
|
|
@Override |
|
protected void readAttr(XMLableReader reader) { |
|
super.readAttr(reader); |
|
this.setThemeType(ThemeType.parseInt(reader.getAttrAsInt("theme", 0))); |
|
this.setThreeDimensional(reader.getAttrAsBoolean("threeD", false)); |
|
this.setTitleFormula(ExtendedHelper.readFormula(reader, "title")); |
|
} |
|
|
|
@Override |
|
protected void writeAttr(XMLPrintWriter writer) { |
|
super.writeAttr(writer); |
|
writer.attr("theme", getThemeType().ordinal()); |
|
writer.attr("threeD", isThreeDimensional()); |
|
ExtendedHelper.writeFormula(this.getTitleFormula(), writer, "title"); |
|
} |
|
|
|
@Override |
|
public Object clone() throws CloneNotSupportedException { |
|
DemoChart result = (DemoChart) super.clone(); |
|
if (getTitleFormula() != null) { |
|
result.setTitleFormula(this.getTitleFormula().clone()); |
|
} |
|
result.setThemeType(this.getThemeType()); |
|
result.setThreeDimensional(this.isThreeDimensional()); |
|
return result; |
|
} |
|
|
|
@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()) |
|
; |
|
} |
|
|
|
@Override |
|
protected String getChartID() { |
|
return ID; |
|
} |
|
|
|
@Override |
|
public String getChartName() { |
|
return NAME; |
|
} |
|
|
|
@Override |
|
protected String demoImagePath() { |
|
return "com/fr/plugin/demo/demo.png"; |
|
} |
|
|
|
@ExecuteFunctionRecord |
|
@Override |
|
protected void addJSON(DemoDataConfig dataConfig, JSONObject jsonObject, Repository repo) throws JSONException { |
|
jsonObject.put("theme", getThemeType() == ThemeType.DARK ? "dark" : "sth whatever"); |
|
|
|
jsonObject.put("title", JSONFactory.createJSON(JSON.OBJECT).put("text", ExtendedHelper.getFormulaResult(titleFormula))); |
|
|
|
JSONArray array = JSONFactory.createJSON(JSON.ARRAY); |
|
|
|
double maxValue = Double.MIN_VALUE; |
|
|
|
if (dataConfig != null) { |
|
List<Object> xValues = dataConfig.getX().getValues(); |
|
List<Object> yValues = dataConfig.getY().getValues(); |
|
List<Object> zValues = dataConfig.getZ().getValues(); |
|
|
|
jsonObject.put("targetName", dataConfig.getTargetName()); |
|
|
|
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))); |
|
} |
|
} |
|
|
|
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" |
|
}; |
|
} |
|
|
|
@Override |
|
protected String[] requiredCSS() { |
|
return new String[]{ |
|
"com/fr/plugin/demo/demo.css" |
|
}; |
|
} |
|
|
|
@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 |
|
protected List<BaseFormula> formulas() { |
|
List<BaseFormula> list = new ArrayList<BaseFormula>(); |
|
list.add(this.getTitleFormula()); |
|
return list; |
|
} |
|
|
|
@Override |
|
protected ExportProcessor createExportProcessor() { |
|
return new JSExportProcessor(); |
|
} |
|
|
|
// @Override |
|
// protected DemoDataConfig designerDataConfig() { |
|
// DemoDataConfig demoDataConfig = new DemoDataConfig(); |
|
// demoDataConfig.setX(new ExtendedField("days", new String[]{"Monday","Tuesday"})); |
|
// demoDataConfig.setY(new ExtendedField("name", new String[]{"Lily", "Marks"})); |
|
// demoDataConfig.setZ(new ExtendedField("money", new String[]{"100", "200"})); |
|
// return super.designerDataConfig(); |
|
// } |
|
}
|
|
|