Browse Source

echarts饼图完善

pull/1/head
richie 9 years ago
parent
commit
5e276b06fe
  1. 11
      src/com/fr/solution/plugin/chart/echarts/common/glyph/EChartsGlyph.java
  2. 4
      src/com/fr/solution/plugin/chart/echarts/common/plot/EChartsPlot.java
  3. 40
      src/com/fr/solution/plugin/chart/echarts/common/ui/AbstractEChartsTypePane.java
  4. 9
      src/com/fr/solution/plugin/chart/echarts/pie/EChartsPie.java
  5. 14
      src/com/fr/solution/plugin/chart/echarts/pie/glyph/EChartsPiePlotGlyph.java
  6. BIN
      src/com/fr/solution/plugin/chart/echarts/pie/images/pie_type1.png
  7. BIN
      src/com/fr/solution/plugin/chart/echarts/pie/images/pie_type_area.png
  8. 0
      src/com/fr/solution/plugin/chart/echarts/pie/images/pie_type_none.png
  9. BIN
      src/com/fr/solution/plugin/chart/echarts/pie/images/pie_type_radius.png
  10. 21
      src/com/fr/solution/plugin/chart/echarts/pie/plot/EChartsPiePlot.java
  11. 16
      src/com/fr/solution/plugin/chart/echarts/pie/plot/RoseType.java
  12. 61
      src/com/fr/solution/plugin/chart/echarts/pie/ui/EChartsPieChartTypePane.java

11
src/com/fr/solution/plugin/chart/echarts/common/glyph/EChartsGlyph.java

@ -24,7 +24,6 @@ public class EChartsGlyph extends ChartGlyph {
if (legendGlyph != null) {
jo.put("legend", legendGlyph.toJSONObject(repo));
}
//jo.put("dataRange", createDataRange(repo));
EChartsPlotGlyph plotGlyph = (EChartsPlotGlyph) getPlotGlyph();
if (plotGlyph != null) {
jo.put("series", plotGlyph.toSeriesData(repo));
@ -37,14 +36,4 @@ public class EChartsGlyph extends ChartGlyph {
return JSONObject.create()
.put("trigger", "item");
}
private JSONObject createDataRange(Repository repo) throws JSONException {
return JSONObject.create()
.put("min", 0)
.put("max", 2500)
.put("x", "left")
.put("y", "bottom")
.put("text", JSONArray.create().put("高").put("低"));
}
}

4
src/com/fr/solution/plugin/chart/echarts/common/plot/EChartsPlot.java

@ -24,6 +24,10 @@ public abstract class EChartsPlot extends Plot {
@Override
public EChartsLegendGlyph createLegendGlyph(PlotGlyph plotGlyph) {
EChartsLegend legend = (EChartsLegend) getLegend();
if (legend == null) {
legend = new EChartsLegend();
setLegend(legend);
}
return legend.createLegendGlyph(createLegendItems(plotGlyph));
}

40
src/com/fr/solution/plugin/chart/echarts/common/ui/AbstractEChartsTypePane.java

@ -1,10 +1,12 @@
package com.fr.solution.plugin.chart.echarts.common.ui;
import com.fr.chart.chartattr.Chart;
import com.fr.chart.chartattr.Legend;
import com.fr.chart.chartattr.Plot;
import com.fr.chart.chartglyph.ConditionCollection;
import com.fr.design.mainframe.chart.gui.type.AbstractChartTypePane;
import com.fr.design.mainframe.chart.gui.type.ChartImagePane;
import com.fr.general.FRLogger;
import com.fr.solution.plugin.chart.echarts.common.base.ECharts;
import java.util.ArrayList;
@ -13,7 +15,6 @@ import java.util.List;
public abstract class AbstractEChartsTypePane extends AbstractChartTypePane{
private static final long serialVersionUID = 7743244512351499265L;
//新图表暂时还没有平面3d,渐变高光等布局。
@Override
protected List<ChartImagePane> initStyleList() {
return new ArrayList<ChartImagePane>();
@ -25,6 +26,35 @@ public abstract class AbstractEChartsTypePane extends AbstractChartTypePane{
};
}
@Override
protected String[] getTypeIconPath() {
return getIconsOfTypes();
}
public abstract String[] getIconsOfTypes();
/**
* 不同字类型图表的名字
* @return 名字
*/
public abstract String[] getNamesOfTypes();
public abstract Plot getSelectedClonedPlot();
@Override
protected List<ChartImagePane> initDemoList() {
List <ChartImagePane> demoList = new ArrayList<ChartImagePane>();
String[] iconPaths = getTypeIconPath();
String[] names = getNamesOfTypes();
ChartImagePane pane = new ChartImagePane(iconPaths[0], names[0]);
pane.isPressing = true;
demoList.add(pane);
demoList.add(new ChartImagePane(iconPaths[1], names[1]));
demoList.add(new ChartImagePane(iconPaths[2], names[2]));
return demoList;
}
/**
* 保存界面属性
*/
@ -62,7 +92,13 @@ public abstract class AbstractEChartsTypePane extends AbstractChartTypePane{
* 同一个图表 类型之间切换
*/
protected void cloneOldPlot2New(Plot oldPlot, Plot newPlot) {
try {
if (oldPlot.getLegend() != null) {
newPlot.setLegend((Legend) oldPlot.getLegend().clone());
}
} catch (CloneNotSupportedException e) {
FRLogger.getLogger().error(e.getMessage(), e);
}
}
protected void cloneOldConditionCollection(Plot oldPlot, Plot newPlot) throws CloneNotSupportedException{

9
src/com/fr/solution/plugin/chart/echarts/pie/EChartsPie.java

@ -5,21 +5,22 @@ import com.fr.general.Inter;
import com.fr.solution.plugin.chart.echarts.common.base.AbstractIndependentEChartsProvider;
import com.fr.solution.plugin.chart.echarts.common.base.ECharts;
import com.fr.solution.plugin.chart.echarts.pie.plot.EChartsPiePlot;
import com.fr.solution.plugin.chart.echarts.pie.plot.PieType;
import com.fr.solution.plugin.chart.echarts.pie.plot.RoseType;
/**
* Created by richie on 16/2/18.
*/
public class EChartsPie extends AbstractIndependentEChartsProvider {
private static ECharts createPie(PieType type) {
private static ECharts createPie(RoseType type) {
EChartsPiePlot plot = new EChartsPiePlot(type);
return new ECharts(plot);
}
public static ECharts[] charts = new ECharts[] {
createPie(PieType.REGULAR),
createPie(PieType.CIRCLE)
createPie(RoseType.NONE),
createPie(RoseType.AREA),
createPie(RoseType.RADIUS),
};

14
src/com/fr/solution/plugin/chart/echarts/pie/glyph/EChartsPiePlotGlyph.java

@ -7,12 +7,24 @@ import com.fr.json.JSONException;
import com.fr.json.JSONFunction;
import com.fr.json.JSONObject;
import com.fr.solution.plugin.chart.echarts.common.glyph.EChartsPlotGlyph;
import com.fr.solution.plugin.chart.echarts.pie.plot.RoseType;
import com.fr.stable.web.Repository;
/**
* Created by richie on 16/2/18.
*/
public class EChartsPiePlotGlyph extends EChartsPlotGlyph {
private RoseType roseType;
public EChartsPiePlotGlyph() {
this(RoseType.NONE);
}
public EChartsPiePlotGlyph(RoseType roseType) {
this.roseType = roseType;
}
@Override
public String getPlotGlyphType() {
return "EChartsPiePlotGlyph";
@ -28,6 +40,7 @@ public class EChartsPiePlotGlyph extends EChartsPlotGlyph {
JSONObject wrapper = JSONObject.create();
result.put(wrapper);
wrapper.put("type", "pie");
wrapper.put("roseType", roseType.toTypeString());
wrapper.put("itemStyle",
JSONObject.create().put("normal",
JSONObject.create().put("label",
@ -39,7 +52,6 @@ public class EChartsPiePlotGlyph extends EChartsPlotGlyph {
String name = series.getSeriesName();
JSONObject item = JSONObject.create();
data.put(item);
item.put("name", name);
if (series.getDataPointCount() > 0) {
DataPoint dataPoint = series.getDataPoint(0);

BIN
src/com/fr/solution/plugin/chart/echarts/pie/images/pie_type1.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.8 KiB

BIN
src/com/fr/solution/plugin/chart/echarts/pie/images/pie_type_area.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 1017 B

0
src/com/fr/solution/plugin/chart/echarts/pie/images/pie_type2.png → src/com/fr/solution/plugin/chart/echarts/pie/images/pie_type_none.png

Before

Width:  |  Height:  |  Size: 4.6 KiB

After

Width:  |  Height:  |  Size: 4.6 KiB

BIN
src/com/fr/solution/plugin/chart/echarts/pie/images/pie_type_radius.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

21
src/com/fr/solution/plugin/chart/echarts/pie/plot/EChartsPiePlot.java

@ -20,23 +20,23 @@ import com.fr.stable.xml.XMLableReader;
public class EChartsPiePlot extends EChartsPlot {
private PieType pieType;
private RoseType pieType;
public EChartsPiePlot() {
this(PieType.REGULAR);
this(RoseType.NONE);
}
public EChartsPiePlot(PieType pieType) {
public EChartsPiePlot(RoseType pieType) {
this.pieType = pieType;
}
public void setPieType(PieType pieType) {
this.pieType = pieType;
public RoseType getPieType() {
return pieType;
}
@Override
public PlotGlyph createPlotGlyph(ChartData chartData) {
PlotGlyph glyph = new EChartsPiePlotGlyph();
PlotGlyph glyph = new EChartsPiePlotGlyph(pieType );
install4PlotGlyph(glyph, chartData);
return glyph;
}
@ -76,7 +76,7 @@ public class EChartsPiePlot extends EChartsPlot {
String tagName = reader.getTagName();
if (tagName.equals("PieAttr4ECharts")) {
pieType = PieType.parse(reader.getAttrAsString("pieType", StringUtils.EMPTY));
pieType = RoseType.parse(reader.getAttrAsString("pieType", StringUtils.EMPTY));
}
}
}
@ -96,4 +96,11 @@ public class EChartsPiePlot extends EChartsPlot {
&& super.equals(ob)
&& ComparatorUtils.equals(((EChartsPiePlot) ob).pieType, pieType);
}
@Override
public Object clone() throws CloneNotSupportedException {
EChartsPiePlot cloned = (EChartsPiePlot) super.clone();
cloned.pieType = pieType;
return cloned;
}
}

16
src/com/fr/solution/plugin/chart/echarts/pie/plot/PieType.java → src/com/fr/solution/plugin/chart/echarts/pie/plot/RoseType.java

@ -5,13 +5,13 @@ import com.fr.general.ComparatorUtils;
/**
* Created by richie on 16/2/18.
*/
public enum PieType {
public enum RoseType {
REGULAR("regular"), CIRCLE("circle");
NONE("none"), AREA("area"), RADIUS("radius");
private String type;
PieType(String type) {
RoseType(String type) {
this.type = type;
}
@ -19,22 +19,22 @@ public enum PieType {
return type;
}
private static PieType[] positions;
private static RoseType[] positions;
/**
* 将字符串转换成枚举类型
* @param p 待转换的整数
* @return 枚举
*/
public static PieType parse(String p) {
public static RoseType parse(String p) {
if (positions == null) {
positions = PieType.values();
positions = RoseType.values();
}
for (PieType ip : positions) {
for (RoseType ip : positions) {
if (ComparatorUtils.equals(p, ip.type)) {
return ip;
}
}
return REGULAR;
return NONE;
}
}

61
src/com/fr/solution/plugin/chart/echarts/pie/ui/EChartsPieChartTypePane.java

@ -1,8 +1,11 @@
package com.fr.solution.plugin.chart.echarts.pie.ui;
import com.fr.chart.chartattr.Chart;
import com.fr.chart.chartattr.Plot;
import com.fr.design.mainframe.chart.gui.type.ChartImagePane;
import com.fr.general.FRLogger;
import com.fr.general.Inter;
import com.fr.solution.plugin.chart.echarts.common.base.ECharts;
import com.fr.solution.plugin.chart.echarts.pie.EChartsPie;
import com.fr.solution.plugin.chart.echarts.pie.plot.EChartsPiePlot;
import com.fr.solution.plugin.chart.echarts.common.ui.AbstractEChartsTypePane;
@ -23,12 +26,6 @@ public class EChartsPieChartTypePane extends AbstractEChartsTypePane {
return Inter.getLocText("Plugin-ECharts_Pie");
}
public void updateBean(Chart chart) {
if (chart != null) {
chart.setPlot(new EChartsPiePlot());
}
}
/**
* 界面是否接受
*
@ -44,23 +41,53 @@ public class EChartsPieChartTypePane extends AbstractEChartsTypePane {
return EChartsPie.charts[0];
}
@Override
public void populateBean(Chart chart) {
for(ChartImagePane imagePane : typeDemo) {
imagePane.isPressing = false;
}
Plot plot = chart.getPlot();
if(plot instanceof EChartsPiePlot) {
lastTypeIndex = ((EChartsPiePlot)plot).getPieType().ordinal();
typeDemo.get(lastTypeIndex).isPressing = true;
}
checkDemosBackground();
}
@Override
public Plot getSelectedClonedPlot() {
EChartsPiePlot newPlot = null;
Chart[] pieChart = EChartsPie.charts;
for(int i = 0, len = pieChart.length; i < len; i++){
if(typeDemo.get(i).isPressing){
newPlot = (EChartsPiePlot)pieChart[i].getPlot();
}
}
Plot cloned = null;
try {
cloned = (Plot)newPlot.clone();
} catch (CloneNotSupportedException e) {
FRLogger.getLogger().error("Error In ColumnChart");
}
return cloned;
}
@Override
protected List<ChartImagePane> initDemoList() {
List <ChartImagePane> demoList = new ArrayList<ChartImagePane>();
String[] iconPaths = getTypeIconPath();
ChartImagePane pane = new ChartImagePane(iconPaths[0], "Regular");
pane.isPressing = true;
demoList.add(pane);
demoList.add(new ChartImagePane(iconPaths[1], "Circle"));
return demoList;
public String[] getIconsOfTypes() {
return new String[]{
"/com/fr/solution/plugin/chart/echarts/pie/images/pie_type_none.png",
"/com/fr/solution/plugin/chart/echarts/pie/images/pie_type_area.png",
"/com/fr/solution/plugin/chart/echarts/pie/images/pie_type_radius.png",
};
}
@Override
protected String[] getTypeIconPath() {
public String[] getNamesOfTypes() {
return new String[]{
"/com/fr/solution/plugin/chart/echarts/pie/images/pie_type1.png",
"/com/fr/solution/plugin/chart/echarts/pie/images/pie_type2.png"
"Normal",
"Area",
"Redius"
};
}
}
Loading…
Cancel
Save