diff --git a/src/com/fr/solution/plugin/chart/echarts/common/glyph/EChartsGlyph.java b/src/com/fr/solution/plugin/chart/echarts/common/glyph/EChartsGlyph.java index f0bbac3..c1b2518 100644 --- a/src/com/fr/solution/plugin/chart/echarts/common/glyph/EChartsGlyph.java +++ b/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("低")); - } } \ No newline at end of file diff --git a/src/com/fr/solution/plugin/chart/echarts/common/plot/EChartsPlot.java b/src/com/fr/solution/plugin/chart/echarts/common/plot/EChartsPlot.java index 9c3ce11..a445a3b 100644 --- a/src/com/fr/solution/plugin/chart/echarts/common/plot/EChartsPlot.java +++ b/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)); } diff --git a/src/com/fr/solution/plugin/chart/echarts/common/ui/AbstractEChartsTypePane.java b/src/com/fr/solution/plugin/chart/echarts/common/ui/AbstractEChartsTypePane.java index 8057543..0f3f498 100644 --- a/src/com/fr/solution/plugin/chart/echarts/common/ui/AbstractEChartsTypePane.java +++ b/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 initStyleList() { return new ArrayList(); @@ -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 initDemoList() { + List demoList = new ArrayList(); + 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{ diff --git a/src/com/fr/solution/plugin/chart/echarts/pie/EChartsPie.java b/src/com/fr/solution/plugin/chart/echarts/pie/EChartsPie.java index bca7ed8..e46f745 100644 --- a/src/com/fr/solution/plugin/chart/echarts/pie/EChartsPie.java +++ b/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), }; diff --git a/src/com/fr/solution/plugin/chart/echarts/pie/glyph/EChartsPiePlotGlyph.java b/src/com/fr/solution/plugin/chart/echarts/pie/glyph/EChartsPiePlotGlyph.java index 642c707..06bc983 100644 --- a/src/com/fr/solution/plugin/chart/echarts/pie/glyph/EChartsPiePlotGlyph.java +++ b/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); diff --git a/src/com/fr/solution/plugin/chart/echarts/pie/images/pie_type1.png b/src/com/fr/solution/plugin/chart/echarts/pie/images/pie_type1.png deleted file mode 100644 index 10e2bbe..0000000 Binary files a/src/com/fr/solution/plugin/chart/echarts/pie/images/pie_type1.png and /dev/null differ diff --git a/src/com/fr/solution/plugin/chart/echarts/pie/images/pie_type_area.png b/src/com/fr/solution/plugin/chart/echarts/pie/images/pie_type_area.png new file mode 100644 index 0000000..2b81600 Binary files /dev/null and b/src/com/fr/solution/plugin/chart/echarts/pie/images/pie_type_area.png differ diff --git a/src/com/fr/solution/plugin/chart/echarts/pie/images/pie_type2.png b/src/com/fr/solution/plugin/chart/echarts/pie/images/pie_type_none.png similarity index 100% rename from src/com/fr/solution/plugin/chart/echarts/pie/images/pie_type2.png rename to src/com/fr/solution/plugin/chart/echarts/pie/images/pie_type_none.png diff --git a/src/com/fr/solution/plugin/chart/echarts/pie/images/pie_type_radius.png b/src/com/fr/solution/plugin/chart/echarts/pie/images/pie_type_radius.png new file mode 100644 index 0000000..a3a95a3 Binary files /dev/null and b/src/com/fr/solution/plugin/chart/echarts/pie/images/pie_type_radius.png differ diff --git a/src/com/fr/solution/plugin/chart/echarts/pie/plot/EChartsPiePlot.java b/src/com/fr/solution/plugin/chart/echarts/pie/plot/EChartsPiePlot.java index e465f65..6625056 100644 --- a/src/com/fr/solution/plugin/chart/echarts/pie/plot/EChartsPiePlot.java +++ b/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; + } } diff --git a/src/com/fr/solution/plugin/chart/echarts/pie/plot/PieType.java b/src/com/fr/solution/plugin/chart/echarts/pie/plot/RoseType.java similarity index 64% rename from src/com/fr/solution/plugin/chart/echarts/pie/plot/PieType.java rename to src/com/fr/solution/plugin/chart/echarts/pie/plot/RoseType.java index 113111c..3f84ddb 100644 --- a/src/com/fr/solution/plugin/chart/echarts/pie/plot/PieType.java +++ b/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; } } diff --git a/src/com/fr/solution/plugin/chart/echarts/pie/ui/EChartsPieChartTypePane.java b/src/com/fr/solution/plugin/chart/echarts/pie/ui/EChartsPieChartTypePane.java index 00167f9..481a2b4 100644 --- a/src/com/fr/solution/plugin/chart/echarts/pie/ui/EChartsPieChartTypePane.java +++ b/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 - protected List initDemoList() { - List demoList = new ArrayList(); - 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 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 + 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" }; } } \ No newline at end of file