From 25f188add6dece51f0e3652924b342ff550b13f3 Mon Sep 17 00:00:00 2001
From: datagear
+ * 支持的JS定义格式:
+ *
+ * 此类从上述格式的输入流解析{@linkplain JsDefContent}对象,其中:
+ *
+ * {@linkplain JsDefContent#getPluginJson()}为上述格式中将
+ * {@linkplain JsDefContent#getPluginChartRender()}为上述格式中
+ * 读取停止位置为:
+ *
+ *
+ * {
+ * id: ...,
+ * nameLabel: ...,
+ * ...,
+ * chartRender: {...},
+ * ...
+ * }
+ *
+ * chartRender: {...}
替换为chartRender: {}
的内容。
+ * chartRender
属性值部分的内容:{...}
+ * {
之前的位置开始读取{@linkplain JsChartRenderer}内容。
+ * }
+ *
*
- * |---- properties.json
- * |---- chart.js
+ * |---- plugin.js
*
*
*
- * properties.json
用于定义{@linkplain HtmlChartPlugin}本身的属性。
+ * 上述文件格式规范如下:
*
+ *
+ * {
+ * id : "...",
+ * nameLabel : { value : "...", localeValues : { "zh" : "...", "en" : "..." }},
+ * ...,
+ * chartRender: { ... },
+ * ...
+ * }
+ *
+ *
*
- * 如果properties.json
中定义了插件图标,比如:
+ * 如果plugin.js
中定义了插件图标,比如:
*
* icons : { "LIGHT" : "icons/light.png" }
@@ -52,10 +64,10 @@ import org.datagear.util.StringUtil;
*
* ,那么上述文件结构中还应有icons/light.png
文件。
*
chart.js
用于定义{@linkplain HtmlChartPlugin}的图表渲染逻辑。
+ * chartRender
用于定义{@linkplain HtmlChartPlugin#getChartRenderer()}内容。
*
*
- * 默认地,上述两个文件都应该为UTF-8
编码。
+ * 默认地,上述文件应该为UTF-8
编码。
*
* var [varName]= * { ... }; - * [varName].jsChartRender= + * [varName].chartRender= * {...}; ** @@ -63,7 +61,7 @@ public class HtmlChartPluginScriptObjectWriter extends AbstractHtmlScriptObjectW writeJsonObject(out, jsonPlugin); out.write(";"); writeNewLine(out); - writeJsChartRender(out, plugin, varName); + writeHtmlChartRender(out, plugin, varName); } /** @@ -73,14 +71,14 @@ public class HtmlChartPluginScriptObjectWriter extends AbstractHtmlScriptObjectW * @param chart * @throws IOException */ - protected void writeJsChartRender(Writer out, HtmlChartPlugin> plugin, String varName) throws IOException + protected void writeHtmlChartRender(Writer out, HtmlChartPlugin> plugin, String varName) throws IOException { - out.write(varName + "." + JS_CHART_RENDER_NAME + "="); + out.write(varName + "." + HtmlChartPlugin.PROPERTY_CHART_RENDER + "="); writeNewLine(out); - JsChartRenderer jsChartRenderer = plugin.getJsChartRenderer(); + JsChartRenderer chartRenderer = plugin.getChartRenderer(); - Reader reader = jsChartRenderer.getReader(); + Reader reader = chartRenderer.getReader(); try { diff --git a/datagear-analysis/src/main/java/org/datagear/analysis/support/html/HtmlTplDashboardWidgetFmkRenderer.java b/datagear-analysis/src/main/java/org/datagear/analysis/support/html/HtmlTplDashboardWidgetFmkRenderer.java index dd202e1b..578aacd6 100644 --- a/datagear-analysis/src/main/java/org/datagear/analysis/support/html/HtmlTplDashboardWidgetFmkRenderer.java +++ b/datagear-analysis/src/main/java/org/datagear/analysis/support/html/HtmlTplDashboardWidgetFmkRenderer.java @@ -206,6 +206,28 @@ public class HtmlTplDashboardWidgetFmkRendererexte return dataModel; } + /** + * 设置用于渲染Freemark看板图表的{@linkplain HtmlChartPluginRenderOption}。 + * + * @param renderContext + * @param dashboardVarName + * @return + */ + protected HtmlChartPluginRenderOption setHtmlChartPluginRenderOption(RenderContext renderContext, + String dashboardVarName) + { + HtmlChartPluginRenderOption option = new HtmlChartPluginRenderOption(); + option.setNotWriteChartElement(false); + option.setNotWriteScriptTag(false); + option.setNotWriteInvoke(true); + option.setNotWriteRenderContextObject(true); + option.setRenderContextVarName(dashboardVarName + ".renderContext"); + + HtmlChartPluginRenderOption.setOption(renderContext, option); + + return option; + } + /** * HTML看板渲染数据模型。 * @@ -401,28 +423,6 @@ public class HtmlTplDashboardWidgetFmkRenderer exte } } - /** - * 设置用于渲染Freemark看板图表的{@linkplain HtmlChartPluginRenderOption}。 - * - * @param renderContext - * @param dashboardVarName - * @return - */ - protected HtmlChartPluginRenderOption setHtmlChartPluginRenderOption(RenderContext renderContext, - String dashboardVarName) - { - HtmlChartPluginRenderOption option = new HtmlChartPluginRenderOption(); - option.setNotWriteChartElement(false); - option.setNotWriteScriptTag(false); - option.setNotWriteInvoke(true); - option.setNotWriteRenderContextObject(true); - option.setRenderContextVarName(dashboardVarName + ".renderContext"); - - HtmlChartPluginRenderOption.setOption(renderContext, option); - - return option; - } - /** * “@chart”指令。 * @@ -461,7 +461,7 @@ public class HtmlTplDashboardWidgetFmkRenderer exte option.setChartElementId(elementId); option.setChartVarName(var); - HtmlChart chart = chartWidget.render(renderContext); + HtmlChart chart = writeHtmlChart(chartWidget, renderContext); List charts = htmlDashboard.getCharts(); if (charts == null) diff --git a/datagear-analysis/src/main/java/org/datagear/analysis/support/html/HtmlTplDashboardWidgetHtmlRenderer.java b/datagear-analysis/src/main/java/org/datagear/analysis/support/html/HtmlTplDashboardWidgetHtmlRenderer.java index 762f45e2..1d6f0e38 100644 --- a/datagear-analysis/src/main/java/org/datagear/analysis/support/html/HtmlTplDashboardWidgetHtmlRenderer.java +++ b/datagear-analysis/src/main/java/org/datagear/analysis/support/html/HtmlTplDashboardWidgetHtmlRenderer.java @@ -387,7 +387,7 @@ public class HtmlTplDashboardWidgetHtmlRenderer ext option.setPluginVarName(chartPluginVarNames.get(i)); option.setChartVarName(chartVarName); - HtmlChart chart = chartWidget.render(renderContext); + HtmlChart chart = writeHtmlChart(chartWidget, renderContext); charts.add(chart); } diff --git a/datagear-analysis/src/main/java/org/datagear/analysis/support/html/HtmlTplDashboardWidgetRenderer.java b/datagear-analysis/src/main/java/org/datagear/analysis/support/html/HtmlTplDashboardWidgetRenderer.java index 9e7a0fea..7e696da1 100644 --- a/datagear-analysis/src/main/java/org/datagear/analysis/support/html/HtmlTplDashboardWidgetRenderer.java +++ b/datagear-analysis/src/main/java/org/datagear/analysis/support/html/HtmlTplDashboardWidgetRenderer.java @@ -21,6 +21,7 @@ import org.datagear.analysis.ChartTheme; import org.datagear.analysis.Dashboard; import org.datagear.analysis.DashboardTheme; import org.datagear.analysis.DashboardThemeSource; +import org.datagear.analysis.RenderContext; import org.datagear.analysis.RenderException; import org.datagear.analysis.RenderStyle; import org.datagear.analysis.Theme; @@ -91,6 +92,10 @@ public abstract class HtmlTplDashboardWidgetRenderer htmlChartPluginForNotFound = new ValueHtmlChartPlugin ( - StringUtil.firstLowerCase(Global.PRODUCT_NAME_EN) + "HtmlChartPluginForNotFound"); + StringUtil.firstLowerCase(Global.PRODUCT_NAME_EN) + "HtmlChartPluginForNotFound", + PROPERTY_VALUE_FOR_NOT_FOUND); + + private HtmlChartPlugin htmlChartPluginForRenderException = new ValueHtmlChartPlugin ( + StringUtil.firstLowerCase(Global.PRODUCT_NAME_EN) + "HtmlChartPluginForRenderException", + PROPERTY_VALUE_FOR_RENDER_EXCEPTION); /** 内置导入内容 */ private List dashboardImports; @@ -224,6 +234,17 @@ public abstract class HtmlTplDashboardWidgetRenderer getHtmlChartPluginForRenderException() + { + return htmlChartPluginForRenderException; + } + + public void setHtmlChartPluginForRenderException( + HtmlChartPlugin htmlChartPluginForRenderException) + { + this.htmlChartPluginForRenderException = htmlChartPluginForRenderException; + } + public List getDashboardImports() { return dashboardImports; @@ -658,7 +679,7 @@ public abstract class HtmlTplDashboardWidgetRenderer widget = new HtmlChartWidget (IDUtil.uuid(), "HtmlChartWidgetForNotFound", this.htmlChartPluginForNotFound); - widget.addChartPropertyValue(ValueHtmlChartPlugin.VALUE_CHART_PROPERTY_NAME, + widget.addChartPropertyValue(PROPERTY_VALUE_FOR_NOT_FOUND, "Chart '" + (notFoundWidgetId == null ? "" : notFoundWidgetId) + "' Not Found"); return widget; @@ -721,10 +742,13 @@ public abstract class HtmlTplDashboardWidgetRenderer chartWidget, + HtmlRenderContext renderContext) throws RenderException + { + return chartWidget.render(renderContext); + } + /** * 写看板主题样式。 * diff --git a/datagear-analysis/src/main/java/org/datagear/analysis/support/html/TextParserSupport.java b/datagear-analysis/src/main/java/org/datagear/analysis/support/html/TextParserSupport.java new file mode 100644 index 00000000..331a2a65 --- /dev/null +++ b/datagear-analysis/src/main/java/org/datagear/analysis/support/html/TextParserSupport.java @@ -0,0 +1,458 @@ +/* + * Copyright (c) 2018 datagear.tech. All Rights Reserved. + */ + +/** + * + */ +package org.datagear.analysis.support.html; + +import java.io.IOException; +import java.io.Reader; + +/** + * 文本解析支持类。 + * + * @author datagear@163.com + * + */ +public class TextParserSupport +{ + public TextParserSupport() + { + super(); + } + + /** + * 读取最多指定字符数的字符串。 + * + * @param reader + * @param count + * @return + * @throws IOException + */ + public String readString(Reader reader, int count) throws IOException + { + char[] chars = new char[count]; + + int readed = reader.read(chars); + + return new String(chars, 0, readed); + } + + /** + * 读取最多指定字符。 + * + * @param reader + * @param cache + * @param count + * @return + * @throws IOException + */ + public void readChars(Reader reader, StringBuilder cache, int count) throws IOException + { + for (int i = 0; i < count; i++) + { + int c = reader.read(); + + if (isValidReadChar(c)) + appendChar(cache, c); + else + break; + } + } + + /** + * 读取到{@code '}或者{@code "}引号的下一个字符。 + * + * 下一个字符不会写入{@code quoted}。 + *
+ * + * @param in + * @param quoted + * @param quote + * {@code '}或者{@code "} + * @return 引号的下一个字符、-1 + * @throws IOException + */ + public int readQuoted(Reader in, StringBuilder quoted, int quote) throws IOException + { + int c = -1; + boolean inEscape = false; + + while ((c = in.read()) > -1) + { + appendChar(quoted, c); + + if (inEscape) + inEscape = false; + else + { + if (c == '\\') + inEscape = true; + else if (c == quote) + break; + } + } + + if (c == quote) + c = in.read(); + + return c; + } + + /** + * 读取到{@linkplain Predicate#test(char)}为{@code false}。 + * + * @param in + * @param out + * 读取字符写入缓存,为{@code null}则不写入 + * @param predicate + * @param appendLast + * 结束字符是否也写入缓存 + * @return + * @throws IOException + */ + public int readUntil(Reader in, StringBuilder out, Predicate predicate, boolean appendLast) throws IOException + { + int c = -1; + + while ((c = in.read()) > -1) + { + if (predicate.test(c)) + appendCharIfNotNull(out, c); + else + { + if (appendLast) + appendCharIfNotNull(out, c); + + break; + } + } + + return c; + } + + /** + * 跳过空格或者注释。 + * + * @param in + * @param out + * 读取字符写入缓存,为{@code null}则不写入 + * @param appendLast + * 结束字符是否也写入缓存 + * @return 非空格或注释的内容、空字符串 + * @throws IOException + */ + public String skipWhitespaceOrBlockLineComment(Reader in, StringBuilder out, boolean appendLast) throws IOException + { + int c = skipWhitespace(in, out, false); + + if (c == -1) + return new String(""); + else if (c == '/') + { + int next = in.read(); + + boolean isComment = false; + + // 行注释 + if (next == '/') + { + appendCharIfNotNull(out, c); + appendCharIfNotNull(out, next); + c = skipLineComment(in, out, false); + isComment = true; + } + // 块注释 + else if (next == '*') + { + appendCharIfNotNull(out, c); + appendCharIfNotNull(out, next); + c = skipBlockComment(in, out, false); + isComment = true; + } + + if (isComment) + { + if (isWhitespace(c)) + { + appendCharIfNotNull(out, c); + return skipWhitespaceOrBlockLineComment(in, out, appendLast); + } + else + { + if (appendLast) + appendCharIfNotNull(out, c); + + StringBuilder sb = new StringBuilder(); + appendChar(sb, c); + + return sb.toString(); + } + } + else + { + if (appendLast) + appendCharIfNotNull(out, c); + + StringBuilder sb = new StringBuilder(); + appendChar(sb, c); + + if (isValidReadChar(next)) + appendChar(sb, next); + + return sb.toString(); + } + } + else + { + if (appendLast) + appendCharIfNotNull(out, c); + + StringBuilder sb = new StringBuilder(); + appendChar(sb, c); + + return sb.toString(); + } + } + + /** + * 读取到行注释“//
”结束。 + * + * @param in + * @param out + * 读取字符写入缓存,为{@code null}则不写入 + * @param appendLast + * 结束字符是否也写入缓存 + * @return 注释结束符的下一个字符、-1 + * @throws IOException + */ + public int skipLineComment(Reader in, StringBuilder out, boolean appendLast) throws IOException + { + int c = -1; + + while ((c = in.read()) > -1) + { + appendCharIfNotNull(out, c); + + if (c == '\n') + break; + } + + if (c == '\n') + { + c = in.read(); + + if (appendLast) + appendCharIfValid(out, c); + } + + return c; + } + + /** + * 读取到块注释“*
/
”结束。 + * + * @param in + * @param out + * 读取字符写入缓存,为{@code null}则不写入 + * @param appendLast + * 结束字符是否也写入缓存 + * @return 注释结束的下一个字符、-1 + * @throws IOException + */ + public int skipBlockComment(Reader in, StringBuilder out, boolean appendLast) throws IOException + { + int c = -1; + + while ((c = in.read()) > -1) + { + appendCharIfNotNull(out, c); + + if (c == '/') + { + int len = out.length(); + int prev = (len > 1 ? out.charAt(len - 2) : -1); + + if (prev == '*') + break; + } + } + + if (c == '/') + { + c = in.read(); + + if (appendLast) + appendCharIfValid(out, c); + } + + return c; + } + + /** + * 读取到非空格。 + * + * @param in + * @param out + * 读取字符写入缓存,为{@code null}则不写入 + * @param appendLast + * 结束字符是否也写入缓存 + * @return 非空格字符、-1 + * @throws IOException + */ + public int skipWhitespace(Reader in, StringBuilder out, boolean appendLast) throws IOException + { + int c = -1; + + while ((c = in.read()) > -1) + { + if (isWhitespace(c)) + appendCharIfNotNull(out, c); + else + { + if (appendLast) + appendCharIfNotNull(out, c); + + break; + } + } + + return c; + } + + /** + * 追加字符。 + * + * @param sb + * @param c + */ + public void appendChar(StringBuilder sb, int c) + { + sb.appendCodePoint(c); + } + + /** + * 追加字符。 + *+ * 如果{@code sb}为{@code null},则什么也不做并返回{@code false}。 + *
+ * + * @param sb + * @param c + * @return + */ + public boolean appendCharIfNotNull(StringBuilder sb, int c) + { + if (sb == null) + return false; + + sb.appendCodePoint(c); + return true; + } + + /** + * 追加字符。 + *+ * 如果{@code sb}为{@code null}或者{@code c}不是合法字符,则什么也不做并返回{@code false}。 + *
+ * + * @param sb + * @param c + * @return + */ + public boolean appendCharIfValid(StringBuilder sb, int c) + { + if (sb == null) + return false; + + if (!isValidReadChar(c)) + return false; + + sb.appendCodePoint(c); + return true; + } + + /** + * 是否是有效的读取字符。 + * + * @param c + * @return + */ + public boolean isValidReadChar(int c) + { + return c > -1; + } + + /** + * 是否空格字符。 + * + * @param c + * @return + */ + public boolean isWhitespace(int c) + { + return Character.isWhitespace(c); + } + + /** + * 删除末尾字符。 + * + * @param sb + * @param count + */ + public void deleteTail(StringBuilder sb, int count) + { + int len = sb.length(); + + sb.delete(len - count, len); + } + + /** + * 清除{@linkplain StringBuilder}。 + * + * @param sb + */ + public void clear(StringBuilder sb) + { + if (sb == null) + return; + + sb.delete(0, sb.length()); + } + + public StringBuilder createStringBuilder() + { + return new StringBuilder(); + } + + public static interface Predicate + { + /** + * 判断字符是否合法。 + * + * @param c + * @return + */ + boolean test(int c); + } + + public static class WhitespacePredicate implements Predicate + { + @Override + public boolean test(int c) + { + return Character.isWhitespace(c); + } + } + + public static class NotWhitespacePredicate implements Predicate + { + @Override + public boolean test(int c) + { + return !Character.isWhitespace(c); + } + } +} diff --git a/datagear-analysis/src/main/java/org/datagear/analysis/support/html/ValueHtmlChartPlugin.java b/datagear-analysis/src/main/java/org/datagear/analysis/support/html/ValueHtmlChartPlugin.java index 93d823af..ae5ae38e 100644 --- a/datagear-analysis/src/main/java/org/datagear/analysis/support/html/ValueHtmlChartPlugin.java +++ b/datagear-analysis/src/main/java/org/datagear/analysis/support/html/ValueHtmlChartPlugin.java @@ -12,12 +12,13 @@ import java.util.Map; import org.datagear.analysis.ChartDataSet; import org.datagear.analysis.RenderException; +import org.datagear.util.StringUtil; import org.datagear.util.i18n.Label; /** * 仅渲染指定内容值的{@linkplain HtmlChartPlugin}。 *- * 它从{@linkplain HtmlRenderContext}中获取{@linkplain #getValueAttributeName()}的属性值,并将其作为图表内容渲染。 + * 它从{@code chartPropertyValues}中获取{@linkplain #getValueChartPropertyName()}的属性值,并将其作为图表内容渲染。 *
* * @author datagear@163.com @@ -25,36 +26,43 @@ import org.datagear.util.i18n.Label; */ public class ValueHtmlChartPluginextends HtmlChartPlugin { - public static final String VALUE_CHART_PROPERTY_NAME = "valueHtmlChartPluginValue"; - - protected static final StringJsChartRenderer JS_CHART_RENDERER = new StringJsChartRenderer( - "{" + HtmlChartPlugin.HTML_NEW_LINE + - // - " render : function(chart)" + HtmlChartPlugin.HTML_NEW_LINE + - // - " {" + HtmlChartPlugin.HTML_NEW_LINE + - // - " var element = document.getElementById(chart.elementId);" + HtmlChartPlugin.HTML_NEW_LINE + - // - " var propertyValues = (chart.propertyValues || {});" + HtmlChartPlugin.HTML_NEW_LINE + - // - " element.innerHTML=propertyValues['" + VALUE_CHART_PROPERTY_NAME + "'];" - + HtmlChartPlugin.HTML_NEW_LINE + - // - " }," + HtmlChartPlugin.HTML_NEW_LINE + - // - " update : function(){}" + HtmlChartPlugin.HTML_NEW_LINE + - // - "}"); + private String valueChartPropertyName; public ValueHtmlChartPlugin() { super(); } - public ValueHtmlChartPlugin(String id) + public ValueHtmlChartPlugin(String id, String valueChartPropertyName) { - super(id, new Label("ValueHtmlChartPlugin"), JS_CHART_RENDERER); + super(); + super.setId(id); + super.setNameLabel(new Label("ValueHtmlChartPlugin")); + super.setChartRenderer(buildJsChartRenderer(valueChartPropertyName)); + this.valueChartPropertyName = valueChartPropertyName; + } + + public String getValueChartPropertyName() + { + return valueChartPropertyName; + } + + public void setValueChartPropertyName(String valueChartPropertyName) + { + this.valueChartPropertyName = valueChartPropertyName; + super.setChartRenderer(buildJsChartRenderer(valueChartPropertyName)); + } + + @Override + public JsChartRenderer getChartRenderer() + { + return super.getChartRenderer(); + } + + @Override + public void setChartRenderer(JsChartRenderer chartRenderer) + { + throw new UnsupportedOperationException(); } @Override @@ -68,4 +76,27 @@ public class ValueHtmlChartPlugin extends HtmlChart return super.renderChart(renderContext, myChartPropertyValues, chartDataSets); } + + protected StringJsChartRenderer buildJsChartRenderer(String valueChartPropertyName) + { + return new StringJsChartRenderer("{" + HtmlChartPlugin.HTML_NEW_LINE + // + + " render : function(chart)" + HtmlChartPlugin.HTML_NEW_LINE + // + + " {" + HtmlChartPlugin.HTML_NEW_LINE + + // + " var element = document.getElementById(chart.elementId);" + HtmlChartPlugin.HTML_NEW_LINE + // + + " var propertyValues = (chart.propertyValues || {});" + HtmlChartPlugin.HTML_NEW_LINE + // + + " element.innerHTML=propertyValues['" + + StringUtil.escapeJavaScriptStringValue(valueChartPropertyName) + "'];" + HtmlChartPlugin.HTML_NEW_LINE + + // + + " }," + HtmlChartPlugin.HTML_NEW_LINE + // + + " update : function(){}" + HtmlChartPlugin.HTML_NEW_LINE + // + + "}"); + } } diff --git a/datagear-analysis/src/test/java/org/datagear/analysis/support/JsonChartPluginPropertiesResolverTest.java b/datagear-analysis/src/test/java/org/datagear/analysis/support/JsonChartPluginPropertiesResolverTest.java index 05473052..124266d8 100644 --- a/datagear-analysis/src/test/java/org/datagear/analysis/support/JsonChartPluginPropertiesResolverTest.java +++ b/datagear-analysis/src/test/java/org/datagear/analysis/support/JsonChartPluginPropertiesResolverTest.java @@ -9,6 +9,7 @@ import java.util.Set; import org.datagear.analysis.Chart; import org.datagear.analysis.ChartDataSet; +import org.datagear.analysis.ChartPlugin; import org.datagear.analysis.ChartProperty; import org.datagear.analysis.DataSign; import org.datagear.analysis.PropertyType; @@ -45,24 +46,24 @@ public class JsonChartPluginPropertiesResolverTest Map properties = jsonChartPluginPropertiesResolver .resolveChartPluginProperties(jsonInputStream, "UTF-8"); - Assert.assertEquals("pie-chart", properties.get(JsonChartPluginPropertiesResolver.CHART_PLUGIN_ID)); + Assert.assertEquals("pie-chart", properties.get(ChartPlugin.PROPERTY_ID)); { - Label nameLabel = (Label) properties.get(JsonChartPluginPropertiesResolver.CHART_PLUGIN_NAME_LABEL); + Label nameLabel = (Label) properties.get(ChartPlugin.PROPERTY_NAME_LABEL); Assert.assertEquals("饼图", nameLabel.getValue()); Assert.assertEquals("pie chart", nameLabel.getValue(Label.toLocale("en"))); Assert.assertEquals("饼图中文", nameLabel.getValue(Label.toLocale("zh"))); } { - Label descLabel = (Label) properties.get(JsonChartPluginPropertiesResolver.CHART_PLUGIN_DESC_LABEL); + Label descLabel = (Label) properties.get(ChartPlugin.PROPERTY_DESC_LABEL); Assert.assertEquals("饼图描述", descLabel.getValue()); Assert.assertEquals("pie chart desc", descLabel.getValue(Label.toLocale("en"))); Assert.assertEquals("饼图描述中文", descLabel.getValue(Label.toLocale("zh"))); } { - Label manualLabel = (Label) properties.get(JsonChartPluginPropertiesResolver.CHART_PLUGIN_MANUAL_LABEL); + Label manualLabel = (Label) properties.get(ChartPlugin.PROPERTY_MANUAL_LABEL); Assert.assertEquals("饼图指南", manualLabel.getValue()); Assert.assertEquals("pie chart manual", manualLabel.getValue(Label.toLocale("en"))); Assert.assertEquals("饼图指南中文", manualLabel.getValue(Label.toLocale("zh"))); @@ -71,7 +72,7 @@ public class JsonChartPluginPropertiesResolverTest { @SuppressWarnings("unchecked") Map icons = (Map ) properties - .get(JsonChartPluginPropertiesResolver.CHART_PLUGIN_ICONS); + .get(ChartPlugin.PROPERTY_ICONS); Assert.assertEquals("icon-0.png", icons.get(RenderStyle.LIGHT).getLocation()); Assert.assertEquals("icon-1.png", icons.get(RenderStyle.DARK).getLocation()); @@ -79,7 +80,7 @@ public class JsonChartPluginPropertiesResolverTest @SuppressWarnings("unchecked") List chartProperties = (List ) properties - .get(JsonChartPluginPropertiesResolver.CHART_PLUGIN_CHART_PROPERTIES); + .get(ChartPlugin.PROPERTY_CHART_PROPERTIES); { ChartProperty chartProperty = chartProperties.get(0); @@ -134,8 +135,7 @@ public class JsonChartPluginPropertiesResolverTest } @SuppressWarnings("unchecked") - List dataSigns = (List ) properties - .get(JsonChartPluginPropertiesResolver.CHART_PLUGIN_DATA_SIGNS); + List dataSigns = (List ) properties.get(ChartPlugin.PROPERTY_DATA_SIGNS); { DataSign dataSign = dataSigns.get(0); diff --git a/datagear-analysis/src/test/java/org/datagear/analysis/support/html/HtmlChartPluginJsDefResolverTest.java b/datagear-analysis/src/test/java/org/datagear/analysis/support/html/HtmlChartPluginJsDefResolverTest.java new file mode 100644 index 00000000..29e8cb99 --- /dev/null +++ b/datagear-analysis/src/test/java/org/datagear/analysis/support/html/HtmlChartPluginJsDefResolverTest.java @@ -0,0 +1,153 @@ +/* + * Copyright (c) 2018 datagear.tech. All Rights Reserved. + */ + +/** + * + */ +package org.datagear.analysis.support.html; + +import java.io.IOException; + +import org.datagear.analysis.support.html.HtmlChartPluginJsDefResolver.JsDefContent; +import org.junit.Assert; +import org.junit.Test; + +/** + * {@linkplain HtmlChartPluginJsDefResolver}单元测试类。 + * + * @author datagear@163.com + * + */ +public class HtmlChartPluginJsDefResolverTest +{ + private HtmlChartPluginJsDefResolver resolver = new HtmlChartPluginJsDefResolver(); + + @Test + public void resolveTest() throws IOException + { + // 无引号 + { + String text = "{a: 'a', b : 'b', chartRender:{render:function() {}}}"; + + JsDefContent content = resolver.resolve(text); + + Assert.assertEquals("{a: 'a', b : 'b', chartRender:{}}", content.getPluginJson()); + Assert.assertEquals("{render:function() {}}", content.getPluginChartRender()); + } + { + String text = "{a: 'a', chartRender:{render:function() {}}, b : 'b'}"; + + JsDefContent content = resolver.resolve(text); + + Assert.assertEquals("{a: 'a', chartRender:{}, b : 'b'}", content.getPluginJson()); + Assert.assertEquals("{render:function() {}}", content.getPluginChartRender()); + } + { + String text = "{chartRender:{render:function() {}}, a: 'a', b : 'b'}"; + + JsDefContent content = resolver.resolve(text); + + Assert.assertEquals("{chartRender:{}, a: 'a', b : 'b'}", content.getPluginJson()); + Assert.assertEquals("{render:function() {}}", content.getPluginChartRender()); + } + + // 单引号 + { + String text = "{a: 'a', b : 'b', 'chartRender':{render:function() {}}}"; + + JsDefContent content = resolver.resolve(text); + + Assert.assertEquals("{a: 'a', b : 'b', 'chartRender':{}}", content.getPluginJson()); + Assert.assertEquals("{render:function() {}}", content.getPluginChartRender()); + } + { + String text = "{a: 'a', 'chartRender':{render:function() {}}, b : 'b'}"; + + JsDefContent content = resolver.resolve(text); + + Assert.assertEquals("{a: 'a', 'chartRender':{}, b : 'b'}", content.getPluginJson()); + Assert.assertEquals("{render:function() {}}", content.getPluginChartRender()); + } + { + String text = "{'chartRender':{render:function() {}}, a: 'a', b : 'b'}"; + + JsDefContent content = resolver.resolve(text); + + Assert.assertEquals("{'chartRender':{}, a: 'a', b : 'b'}", content.getPluginJson()); + Assert.assertEquals("{render:function() {}}", content.getPluginChartRender()); + } + + // 双引号 + { + String text = "{a: 'a', b : 'b', \"chartRender\":{render:function() {}}}"; + + JsDefContent content = resolver.resolve(text); + + Assert.assertEquals("{a: 'a', b : 'b', \"chartRender\":{}}", content.getPluginJson()); + Assert.assertEquals("{render:function() {}}", content.getPluginChartRender()); + } + { + String text = "{a: 'a', \"chartRender\":{render:function() {}}, b : 'b'}"; + + JsDefContent content = resolver.resolve(text); + + Assert.assertEquals("{a: 'a', \"chartRender\":{}, b : 'b'}", content.getPluginJson()); + Assert.assertEquals("{render:function() {}}", content.getPluginChartRender()); + } + { + String text = "{\"chartRender\":{render:function() {}}, a: 'a', b : 'b'}"; + + JsDefContent content = resolver.resolve(text); + + Assert.assertEquals("{\"chartRender\":{}, a: 'a', b : 'b'}", content.getPluginJson()); + Assert.assertEquals("{render:function() {}}", content.getPluginChartRender()); + } + + // 带注释 + { + String text = "{a: 'a', b : 'b', /*sdf*/chartRender/*sdf*/:{render:function() {}}}"; + + JsDefContent content = resolver.resolve(text); + + Assert.assertEquals("{a: 'a', b : 'b', /*sdf*/chartRender/*sdf*/:{}}", content.getPluginJson()); + Assert.assertEquals("{render:function() {}}", content.getPluginChartRender()); + } + { + String text = "{a: 'a', b : 'b', /*sdf*/ chartRender /*sdf*/ :{render:function() {}}}"; + + JsDefContent content = resolver.resolve(text); + + Assert.assertEquals("{a: 'a', b : 'b', /*sdf*/ chartRender /*sdf*/ :{}}", content.getPluginJson()); + Assert.assertEquals("{render:function() {}}", content.getPluginChartRender()); + } + { + String text = "{a: 'a', b : 'b', //sdf\nchartRender//sdf\n:{render:function() {}}}"; + + JsDefContent content = resolver.resolve(text); + + Assert.assertEquals("{a: 'a', b : 'b', //sdf\nchartRender//sdf\n:{}}", content.getPluginJson()); + Assert.assertEquals("{render:function() {}}", content.getPluginChartRender()); + } + { + String text = "{a: 'a', b : 'b', //sdf\n chartRender //sdf\n :{render:function() {}}}"; + + JsDefContent content = resolver.resolve(text); + + Assert.assertEquals("{a: 'a', b : 'b', //sdf\n chartRender //sdf\n :{}}", content.getPluginJson()); + Assert.assertEquals("{render:function() {}}", content.getPluginChartRender()); + } + + // 复杂内容 + + { + String text = "{a: 'a', b : 'b', //sdf\n chartRender //sdf\n :{render:function() { if(a==b) {}; /*sdf*/ \n\n //sdf\n var a= {}; }}}"; + + JsDefContent content = resolver.resolve(text); + + Assert.assertEquals("{a: 'a', b : 'b', //sdf\n chartRender //sdf\n :{}}", content.getPluginJson()); + Assert.assertEquals("{render:function() { if(a==b) {}; /*sdf*/ \n\n //sdf\n var a= {}; }}", + content.getPluginChartRender()); + } + } +} diff --git a/datagear-analysis/src/test/java/org/datagear/analysis/support/html/HtmlChartPluginTest.java b/datagear-analysis/src/test/java/org/datagear/analysis/support/html/HtmlChartPluginTest.java index a250f673..2d940b56 100644 --- a/datagear-analysis/src/test/java/org/datagear/analysis/support/html/HtmlChartPluginTest.java +++ b/datagear-analysis/src/test/java/org/datagear/analysis/support/html/HtmlChartPluginTest.java @@ -7,15 +7,12 @@ */ package org.datagear.analysis.support.html; -import java.io.InputStream; +import java.io.File; import java.io.StringWriter; import java.util.Locale; -import java.util.Map; import org.datagear.analysis.ChartDataSet; import org.datagear.analysis.RenderStyle; -import org.datagear.analysis.support.JsonChartPluginPropertiesResolver; -import org.datagear.analysis.support.LocationResource; import org.datagear.analysis.support.SimpleDashboardThemeSource; import org.datagear.analysis.support.html.HtmlRenderContext.WebContext; import org.junit.Assert; @@ -27,8 +24,6 @@ import org.junit.Test; */ public class HtmlChartPluginTest { - private static JsonChartPluginPropertiesResolver jsonChartPluginPropertiesResolver = new JsonChartPluginPropertiesResolver(); - public HtmlChartPluginTest() throws Throwable { super(); @@ -74,16 +69,11 @@ public class HtmlChartPluginTest public static HtmlChartPlugin createHtmlChartPlugin() throws Exception { - InputStream jsonInputStream = HtmlChartPluginTest.class.getClassLoader() - .getResourceAsStream("org/datagear/analysis/support/html/HtmlChartPlugin.config.json"); - Map properties = jsonChartPluginPropertiesResolver.resolveChartPluginProperties(jsonInputStream, - "UTF-8"); + File directory = new File("src/test/resources/org/datagear/analysis/support/html/HtmlChartPluginTest"); - HtmlChartPlugin htmlChartPlugin = new HtmlChartPlugin (); - jsonChartPluginPropertiesResolver.setChartPluginProperties(htmlChartPlugin, properties); - - htmlChartPlugin.setJsChartRenderer(new LocationJsChartRenderer( - LocationResource.toClasspathLocation("org/datagear/analysis/support/html/HtmlChartPlugin.chart.js"))); + @SuppressWarnings("unchecked") + HtmlChartPlugin htmlChartPlugin = (HtmlChartPlugin ) new HtmlChartPluginLoader() + .load(directory); return htmlChartPlugin; } diff --git a/datagear-analysis/src/test/resources/org/datagear/analysis/support/html/HtmlChartPlugin.chart.js b/datagear-analysis/src/test/resources/org/datagear/analysis/support/html/HtmlChartPlugin.chart.js deleted file mode 100644 index 3e1b2128..00000000 --- a/datagear-analysis/src/test/resources/org/datagear/analysis/support/html/HtmlChartPlugin.chart.js +++ /dev/null @@ -1,24 +0,0 @@ -{ - render: function(chart) - { - var element = document.getElementById(chart.elementId); - var innerHtml = "my chart"; - - if(chart.renderContext && chart.renderContext.attributes && chart.renderContext.attributes.chartTheme) - { - var graphColors = (chart.renderContext.attributes.chartTheme.graphColors || []); - - for(var i=0; i< graphColors.length; i++) - { - innerHtml +=" "; - } - } - - element.innerHTML = innerHtml; - }, - update: function(chart, results) - { - var element = document.getElementById(chart.elementId); - element.innerHTML += "update"; - } -} diff --git a/datagear-analysis/src/test/resources/org/datagear/analysis/support/html/HtmlChartPlugin.config.json b/datagear-analysis/src/test/resources/org/datagear/analysis/support/html/HtmlChartPlugin.config.json deleted file mode 100644 index 2b78f808..00000000 --- a/datagear-analysis/src/test/resources/org/datagear/analysis/support/html/HtmlChartPlugin.config.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - id : 'pie-chart', - nameLabel : - { - value : '饼图', - localeValues : - { - 'en' : 'pie chart', - 'zh' : '饼图中文' - } - } -} \ No newline at end of file diff --git a/datagear-analysis/src/test/resources/org/datagear/analysis/support/html/htmlChartPluginLoaders/plugin01/chart.js b/datagear-analysis/src/test/resources/org/datagear/analysis/support/html/htmlChartPluginLoaders/plugin01/chart.js deleted file mode 100644 index 5dae7ec6..00000000 --- a/datagear-analysis/src/test/resources/org/datagear/analysis/support/html/htmlChartPluginLoaders/plugin01/chart.js +++ /dev/null @@ -1,6 +0,0 @@ -(function(chart) -{ - chart.render = function(){}; - chart.update = function(dataSets){}; -}) -($CHART); diff --git a/datagear-analysis/src/test/resources/org/datagear/analysis/support/html/htmlChartPluginLoaders/plugin01/properties.json b/datagear-analysis/src/test/resources/org/datagear/analysis/support/html/htmlChartPluginLoaders/plugin01/plugin.js similarity index 82% rename from datagear-analysis/src/test/resources/org/datagear/analysis/support/html/htmlChartPluginLoaders/plugin01/properties.json rename to datagear-analysis/src/test/resources/org/datagear/analysis/support/html/htmlChartPluginLoaders/plugin01/plugin.js index eaea04c4..2f5e2ac5 100644 --- a/datagear-analysis/src/test/resources/org/datagear/analysis/support/html/htmlChartPluginLoaders/plugin01/properties.json +++ b/datagear-analysis/src/test/resources/org/datagear/analysis/support/html/htmlChartPluginLoaders/plugin01/plugin.js @@ -10,5 +10,6 @@ } }, icons : { "light" : "icon-01.png", "dark" : "icons/icon-02.png" }, - order : 4 + order : 4, + chartRender : {} } \ No newline at end of file diff --git a/datagear-analysis/src/test/resources/org/datagear/analysis/support/html/htmlChartPluginLoaders/plugin02/chart.js b/datagear-analysis/src/test/resources/org/datagear/analysis/support/html/htmlChartPluginLoaders/plugin02/chart.js deleted file mode 100644 index 5dae7ec6..00000000 --- a/datagear-analysis/src/test/resources/org/datagear/analysis/support/html/htmlChartPluginLoaders/plugin02/chart.js +++ /dev/null @@ -1,6 +0,0 @@ -(function(chart) -{ - chart.render = function(){}; - chart.update = function(dataSets){}; -}) -($CHART); diff --git a/datagear-analysis/src/test/resources/org/datagear/analysis/support/html/htmlChartPluginLoaders/plugin02/properties.json b/datagear-analysis/src/test/resources/org/datagear/analysis/support/html/htmlChartPluginLoaders/plugin02/plugin.js similarity index 82% rename from datagear-analysis/src/test/resources/org/datagear/analysis/support/html/htmlChartPluginLoaders/plugin02/properties.json rename to datagear-analysis/src/test/resources/org/datagear/analysis/support/html/htmlChartPluginLoaders/plugin02/plugin.js index d9d2cb31..c559a5d3 100644 --- a/datagear-analysis/src/test/resources/org/datagear/analysis/support/html/htmlChartPluginLoaders/plugin02/properties.json +++ b/datagear-analysis/src/test/resources/org/datagear/analysis/support/html/htmlChartPluginLoaders/plugin02/plugin.js @@ -10,5 +10,6 @@ } }, icons : { "light" : "icon-01.png", "dark" : "icons/icon-02.png" }, - order : 3 + order : 3, + chartRender : {} } \ No newline at end of file diff --git a/datagear-analysis/src/test/resources/org/datagear/analysis/support/html/htmlChartPluginLoaders/plugin03.zip b/datagear-analysis/src/test/resources/org/datagear/analysis/support/html/htmlChartPluginLoaders/plugin03.zip index 9969fd228bf63288d1b195015563551cf36a555b..58a4cada2647e4f7f59de0c23d5bc57d48abae3c 100644 GIT binary patch delta 350 zcmX@j{)u&B?Ueec73KkVFZWE_!N9=q6Nov1xFDxAJu^=)tJt;ImhX@OPwR7q!gdXB zu{y7tRcvZ(-!4Sux_GSKlDgnk&k;req4WfIo&rgY>j(T)BXoY(&Yw5?VZ+N7_ZYEd zep`8;6}3zZjgDAhDk1mKRp_>6FmvbKkAHUB-=E%YKJ#R9SZadnmM>-NjXA?6tC?dEOyXdOd!dy&mXk$gpqrObj-Bq!gI<`Sj^b ze`o)l`X^(V_*y6M{jcW~Q(kk_{jK=qk4!R?BbfLY878MQ#V{I7KEf2v7&2Lg*(DXz z!zw^8gMb1McL6cn`&?il1_nk32?piN%B;5+uQKWsEQ|xuPSMZ2Ky-jND;rP`0}Buq MGcqt_0x<&v08T-H?*IS* delta 577 zcmeywdYZjHz?+#xgn@y9gW-DZWdF#thxy?^UKUt{fgw2~v8Y5ZtJt?^BUgihi0gBf z{|6U3POnptTC{ZMFUE`FTO;<&oBZRwE!UB^a_1htvSo9BF1p29XVOF^&xB=BqS`wkJ8d_UZT+;LKHD$b=*>>7VGQt|$TX=wqG7WCObx&CbwEp>0Wm)i z7Zl|eq!yKArWONj&(Cu`W60NJAj0-wr^=m$FE6o*7Cz=V_fAwQV@<0_!GsdCj||6- z81Il~-`n%Zv}V1^u04Cc|BsK8XLEUKvUJb2*o8iO9tgU) *7x1DC;!*SZGT;0RgfdY)9#i! zHM8N%l+4g6y3KPFEjpiHz9piwNJqTv^Xb_)Z>a5C`p+}9IFnH&@xi_TZ$>7223*0a z0`wmUD1b=@O?W7CL4_C@Bp6s#H >p!K!rp2M5Y zn*CErnra*od1L*_2|DX$Z}8ONS;@+;(3HMGoO^H2v22UYjJa(yzt`@`Y-3&~ELRvg z!|JNpjMIW{VY!J5uO(Eph ~Jh7rsAeH~Ig(>u+z(<(uTuy;#-#_)gux%pC?+XSEu4FDQ^{nS5wj(h=81cb-k3 zetF(Go2UC!$~i4WoUH!*SB>b|ASS;xezGl-79+#t45k=HgULsk!Wly*%QCy9VtQ5u z=v@#{0OBqnhI^e0EX2UT$RNRxmcFay?ZvB%PnZ*`L9|o!GcOPw;LXYg)Wg66gvE>u K44FX8zyJU+jD;ou delta 578 zcmeywdWO9|z?+#xgn@y9gW-DZWdF#thxy?^UKUt{fgw2~v8Y5ZtJt?^BUgihi0gBf z{|6U3POnptTC{ZMFUE`FTO;<&oBZRwE!UB^a_1htvSo9BF1p29XVOF^&x B=BqS`wkJ8d_UZT+;LKHD$b=*>>7VGQt|$TX=wqhYfDYKt1v^*~FX0Wm)i z7Zl|eq!yKArWONj&(Cu`W60NJAj0-wr^=m$FE6o*_6VmJl&!zukgU6;p?S&XPId#e zc?a)Wyhs&U|FBy1;?t*l|NsB=%RoVEx#rWY@3>MQvGyw%C23Dj(lzyc=;Tu7R4(+e zz^4A)`R`BbAF5sqRofDic)P;3=+M%KC$<_*N?W=?w<7+H_rL$2cg40}ZcKihU}2)Q z+J||`a-Y?UawOmI9QK^!lO4RFV^hqHv- zxr#<_U2aLWd6;LXTn&wwjj zRe&A@0R=Frg$QOYs1PHA1Ouz;#!`oER~e^>#mB(t$x=)T{M-!4`fDdoVT@s1JNYAH zIOE01o=h&;n8Asxo}CdRaFK20zn^r(323W+{Eh=4y29?vdJrAp&B_LHEh`XS1{(1g Hh#43FjkC)1 diff --git a/datagear-analysis/src/test/resources/org/datagear/analysis/support/html/htmlChartPluginTest/plugin.js b/datagear-analysis/src/test/resources/org/datagear/analysis/support/html/htmlChartPluginTest/plugin.js new file mode 100644 index 00000000..bc16df6e --- /dev/null +++ b/datagear-analysis/src/test/resources/org/datagear/analysis/support/html/htmlChartPluginTest/plugin.js @@ -0,0 +1,37 @@ +{ + id : 'pie-chart', + nameLabel : + { + value : '饼图', + localeValues : + { + 'en' : 'pie chart', + 'zh' : '饼图中文' + } + }, + chartRender: + { + render: function(chart) + { + var element = document.getElementById(chart.elementId); + var innerHtml = "my chart"; + + if(chart.renderContext && chart.renderContext.attributes && chart.renderContext.attributes.chartTheme) + { + var graphColors = (chart.renderContext.attributes.chartTheme.graphColors || []); + + for(var i=0; i< graphColors.length; i++) + { + innerHtml +=" "; + } + } + + element.innerHTML = innerHtml; + }, + update: function(chart, results) + { + var element = document.getElementById(chart.elementId); + element.innerHTML += "update"; + } + } +} diff --git a/datagear-analysis/src/test/resources/org/datagear/analysis/support/html/htmlTplDashboardWidgets/html/widget01/index.html b/datagear-analysis/src/test/resources/org/datagear/analysis/support/html/htmlTplDashboardWidgets/html/widget01/index.html index 17ea6039..82f382a0 100644 --- a/datagear-analysis/src/test/resources/org/datagear/analysis/support/html/htmlTplDashboardWidgets/html/widget01/index.html +++ b/datagear-analysis/src/test/resources/org/datagear/analysis/support/html/htmlTplDashboardWidgets/html/widget01/index.html @@ -10,7 +10,7 @@ var dashboardRenderer = for(var i=0; ilocaleValues; diff --git a/datagear-web/src/main/resources/org/datagear/web/chartPlugin/datagear-chart-bar-0.1.0/chart.js b/datagear-web/src/main/resources/org/datagear/web/chartPlugin/datagear-chart-bar-0.1.0/chart.js deleted file mode 100644 index 4bd35c27..00000000 --- a/datagear-web/src/main/resources/org/datagear/web/chartPlugin/datagear-chart-bar-0.1.0/chart.js +++ /dev/null @@ -1,43 +0,0 @@ -{ -/** - * 依赖: - * chartUtil - * echarts - */ - render: function(chart) - { - chart.echarts = {}; - - var options = - { - xAxis: { - type: 'category', - boundaryGap: false, - data: [] - }, - yAxis: { - type: 'value' - }, - series: [{ - data: [], - type: 'bar' - }] - }; - - chart.echarts.chart = chartUtil.echarts.init(chart, options); - }, - update: function(chart, results) - { - var chartDataSet = chartUtil.firstChartDataSet(chart); - var result = chartUtil.firstResult(results); - - var xp = chartUtil.dataSetPropertyOfSign(chartDataSet, "x-value"); - var yp = chartUtil.dataSetPropertyOfSign(chartDataSet, "y-value"); - - var xdatas = chartUtil.dataPropertyValues(result, xp); - var ydatas = chartUtil.dataPropertyValues(result, yp); - - var options = { xAxis : { data : xdatas }, series : [ { data : ydatas } ] }; - chart.echarts.chart.setOption(options); - } -} \ No newline at end of file diff --git a/datagear-web/src/main/resources/org/datagear/web/chartPlugin/datagear-chart-bar-0.1.0/plugin.js b/datagear-web/src/main/resources/org/datagear/web/chartPlugin/datagear-chart-bar-0.1.0/plugin.js new file mode 100644 index 00000000..95e55912 --- /dev/null +++ b/datagear-web/src/main/resources/org/datagear/web/chartPlugin/datagear-chart-bar-0.1.0/plugin.js @@ -0,0 +1,56 @@ +{ + id : 'datagear-chart-bar', + nameLabel : '柱状图', + descLabel : '柱状图', + dataSigns : + [ + { name : "x-value", nameLabel : "横坐标", occurRequired: true, occurMultiple: false }, + { name : "y-value", nameLabel : "纵坐标", occurRequired: true, occurMultiple: true } + ], + version: "0.1.0", + order : 1, + chartRender: + { + /** + * 依赖: + * chartUtil + * echarts + */ + render: function(chart) + { + chart.echarts = {}; + + var options = + { + xAxis: { + type: 'category', + boundaryGap: false, + data: [] + }, + yAxis: { + type: 'value' + }, + series: [{ + data: [], + type: 'bar' + }] + }; + + chart.echarts.chart = chartUtil.echarts.init(chart, options); + }, + update: function(chart, results) + { + var chartDataSet = chartUtil.firstChartDataSet(chart); + var result = chartUtil.firstResult(results); + + var xp = chartUtil.dataSetPropertyOfSign(chartDataSet, "x-value"); + var yp = chartUtil.dataSetPropertyOfSign(chartDataSet, "y-value"); + + var xdatas = chartUtil.dataPropertyValues(result, xp); + var ydatas = chartUtil.dataPropertyValues(result, yp); + + var options = { xAxis : { data : xdatas }, series : [ { data : ydatas } ] }; + chart.echarts.chart.setOption(options); + } + } +} \ No newline at end of file diff --git a/datagear-web/src/main/resources/org/datagear/web/chartPlugin/datagear-chart-bar-0.1.0/properties.json b/datagear-web/src/main/resources/org/datagear/web/chartPlugin/datagear-chart-bar-0.1.0/properties.json deleted file mode 100644 index c54cdd3d..00000000 --- a/datagear-web/src/main/resources/org/datagear/web/chartPlugin/datagear-chart-bar-0.1.0/properties.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - id : 'datagear-chart-bar', - nameLabel : '柱状图', - descLabel : '柱状图', - dataSigns : - [ - { name : "x-value", nameLabel : "横坐标", occurRequired: true, occurMultiple: false }, - { name : "y-value", nameLabel : "纵坐标", occurRequired: true, occurMultiple: true } - ], - version: "0.1.0", - order : 1 -} \ No newline at end of file diff --git a/datagear-web/src/main/resources/org/datagear/web/chartPlugin/datagear-chart-line-0.1.0/chart.js b/datagear-web/src/main/resources/org/datagear/web/chartPlugin/datagear-chart-line-0.1.0/chart.js deleted file mode 100644 index 359b3247..00000000 --- a/datagear-web/src/main/resources/org/datagear/web/chartPlugin/datagear-chart-line-0.1.0/chart.js +++ /dev/null @@ -1,43 +0,0 @@ -{ -/** - * 依赖: - * chartUtil - * echarts - */ - render: function(chart) - { - chart.echarts = {}; - - var options = - { - xAxis: { - type: 'category', - boundaryGap: false, - data: [] - }, - yAxis: { - type: 'value', - }, - series: [{ - data: [], - type: 'line' - }] - }; - - chart.echarts.chart = chartUtil.echarts.init(chart, options); - }, - update: function(chart, results) - { - var chartDataSet = chartUtil.firstChartDataSet(chart); - var result = chartUtil.firstResult(results); - - var xp = chartUtil.dataSetPropertyOfSign(chartDataSet, "x-value"); - var yp = chartUtil.dataSetPropertyOfSign(chartDataSet, "y-value"); - - var xdatas = chartUtil.dataPropertyValues(result, xp); - var ydatas = chartUtil.dataPropertyValues(result, yp); - - var options = { xAxis : { data : xdatas }, series : [ { data : ydatas } ] }; - chart.echarts.chart.setOption(options); - } -} \ No newline at end of file diff --git a/datagear-web/src/main/resources/org/datagear/web/chartPlugin/datagear-chart-line-0.1.0/plugin.js b/datagear-web/src/main/resources/org/datagear/web/chartPlugin/datagear-chart-line-0.1.0/plugin.js new file mode 100644 index 00000000..42a54567 --- /dev/null +++ b/datagear-web/src/main/resources/org/datagear/web/chartPlugin/datagear-chart-line-0.1.0/plugin.js @@ -0,0 +1,56 @@ +{ + id : 'datagear-chart-line', + nameLabel : '折线图', + descLabel : '折线图', + dataSigns : + [ + { name : "x-value", nameLabel : "横坐标", occurRequired: true, occurMultiple: false }, + { name : "y-value", nameLabel : "纵坐标", occurRequired: true, occurMultiple: true } + ], + version: "0.1.0", + order : 0, + chartRender: + { + /** + * 依赖: + * chartUtil + * echarts + */ + render: function(chart) + { + chart.echarts = {}; + + var options = + { + xAxis: { + type: 'category', + boundaryGap: false, + data: [] + }, + yAxis: { + type: 'value', + }, + series: [{ + data: [], + type: 'line' + }] + }; + + chart.echarts.chart = chartUtil.echarts.init(chart, options); + }, + update: function(chart, results) + { + var chartDataSet = chartUtil.firstChartDataSet(chart); + var result = chartUtil.firstResult(results); + + var xp = chartUtil.dataSetPropertyOfSign(chartDataSet, "x-value"); + var yp = chartUtil.dataSetPropertyOfSign(chartDataSet, "y-value"); + + var xdatas = chartUtil.dataPropertyValues(result, xp); + var ydatas = chartUtil.dataPropertyValues(result, yp); + + var options = { xAxis : { data : xdatas }, series : [ { data : ydatas } ] }; + chart.echarts.chart.setOption(options); + } + } +} \ No newline at end of file diff --git a/datagear-web/src/main/resources/org/datagear/web/chartPlugin/datagear-chart-line-0.1.0/properties.json b/datagear-web/src/main/resources/org/datagear/web/chartPlugin/datagear-chart-line-0.1.0/properties.json deleted file mode 100644 index 6b9632e6..00000000 --- a/datagear-web/src/main/resources/org/datagear/web/chartPlugin/datagear-chart-line-0.1.0/properties.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - id : 'datagear-chart-line', - nameLabel : '折线图', - descLabel : '折线图', - dataSigns : - [ - { name : "x-value", nameLabel : "横坐标", occurRequired: true, occurMultiple: false }, - { name : "y-value", nameLabel : "纵坐标", occurRequired: true, occurMultiple: true } - ], - version: "0.1.0", - order : 0 -} \ No newline at end of file diff --git a/datagear-web/src/main/resources/org/datagear/web/chartPlugin/datagear-chart-pie-0.1.0/chart.js b/datagear-web/src/main/resources/org/datagear/web/chartPlugin/datagear-chart-pie-0.1.0/chart.js deleted file mode 100644 index 127a77cc..00000000 --- a/datagear-web/src/main/resources/org/datagear/web/chartPlugin/datagear-chart-pie-0.1.0/chart.js +++ /dev/null @@ -1,60 +0,0 @@ -{ -/** - * 依赖: - * chartUtil - * echarts - */ - render: function(chart) - { - chart.echarts = {}; - - var options = - { - tooltip: - { - trigger: 'item', - formatter: '{a}
{b} : {c} ({d}%)' - }, - legend: - { - orient: 'vertical', - left: 'left' - }, - series: - [ - { - name : "", - type: 'pie', - radius: '55%', - center: ['50%', '60%'], - data: [], - emphasis: - { - itemStyle: - { - shadowBlur: 10, - shadowOffsetX: 0, - shadowColor: chartUtil.chartTheme(chart).envLeastColor - } - } - } - ] - }; - - chart.echarts.chart = chartUtil.echarts.init(chart, options); - }, - update: function(chart, results) - { - var chartDataSet = chartUtil.firstChartDataSet(chart); - var result = chartUtil.firstResult(results); - - var np = chartUtil.dataSetPropertyOfSign(chartDataSet, "name"); - var vp = chartUtil.dataSetPropertyOfSign(chartDataSet, "value"); - - var legendData = chartUtil.dataPropertyValues(result, np); - var datas = chartUtil.dataNameValueObjects(result, np, vp); - - var options = { legend : { data : legendData }, series : [ { name : chartUtil.propertyValueName(chart), data : datas } ] }; - chart.echarts.chart.setOption(options); - } -} \ No newline at end of file diff --git a/datagear-web/src/main/resources/org/datagear/web/chartPlugin/datagear-chart-pie-0.1.0/plugin.js b/datagear-web/src/main/resources/org/datagear/web/chartPlugin/datagear-chart-pie-0.1.0/plugin.js new file mode 100644 index 00000000..cefab989 --- /dev/null +++ b/datagear-web/src/main/resources/org/datagear/web/chartPlugin/datagear-chart-pie-0.1.0/plugin.js @@ -0,0 +1,73 @@ +{ + id : 'datagear-chart-pie', + nameLabel : '饼图', + descLabel : '饼图', + dataSigns : + [ + { name : "name", nameLabel : "名称", occurRequired: true, occurMultiple: false }, + { name : "value", nameLabel : "数值", occurRequired: true, occurMultiple: true } + ], + version: "0.1.0", + order : 2, + chartRender: + { + /** + * 依赖: + * chartUtil + * echarts + */ + render: function(chart) + { + chart.echarts = {}; + + var options = + { + tooltip: + { + trigger: 'item', + formatter: '{a}
{b} : {c} ({d}%)' + }, + legend: + { + orient: 'vertical', + left: 'left' + }, + series: + [ + { + name : "", + type: 'pie', + radius: '55%', + center: ['50%', '60%'], + data: [], + emphasis: + { + itemStyle: + { + shadowBlur: 10, + shadowOffsetX: 0, + shadowColor: chartUtil.chartTheme(chart).envLeastColor + } + } + } + ] + }; + + chart.echarts.chart = chartUtil.echarts.init(chart, options); + }, + update: function(chart, results) + { + var chartDataSet = chartUtil.firstChartDataSet(chart); + var result = chartUtil.firstResult(results); + + var np = chartUtil.dataSetPropertyOfSign(chartDataSet, "name"); + var vp = chartUtil.dataSetPropertyOfSign(chartDataSet, "value"); + + var legendData = chartUtil.dataPropertyValues(result, np); + var datas = chartUtil.dataNameValueObjects(result, np, vp); + + var options = { legend : { data : legendData }, series : [ { name : chartUtil.propertyValueName(chart), data : datas } ] }; + chart.echarts.chart.setOption(options); + } + } +} \ No newline at end of file diff --git a/datagear-web/src/main/resources/org/datagear/web/chartPlugin/datagear-chart-pie-0.1.0/properties.json b/datagear-web/src/main/resources/org/datagear/web/chartPlugin/datagear-chart-pie-0.1.0/properties.json deleted file mode 100644 index 0cefdfe8..00000000 --- a/datagear-web/src/main/resources/org/datagear/web/chartPlugin/datagear-chart-pie-0.1.0/properties.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - id : 'datagear-chart-pie', - nameLabel : '饼图', - descLabel : '饼图', - dataSigns : - [ - { name : "name", nameLabel : "名称", occurRequired: true, occurMultiple: false }, - { name : "value", nameLabel : "数值", occurRequired: true, occurMultiple: true } - ], - version: "0.1.0", - order : 2 -} \ No newline at end of file diff --git a/datagear-web/src/main/webapp/static/script/datagear-dashboard-renderer.js b/datagear-web/src/main/webapp/static/script/datagear-dashboard-renderer.js index 1d8b2b32..c3fcba13 100644 --- a/datagear-web/src/main/webapp/static/script/datagear-dashboard-renderer.js +++ b/datagear-web/src/main/webapp/static/script/datagear-dashboard-renderer.js @@ -33,7 +33,7 @@ try { - chart.plugin.jsChartRender.render(chart); + chart.plugin.chartRender.render(chart); } catch(e) { @@ -180,7 +180,7 @@ doUpdate=this.listener.onUpdateChart(dashboard, chart, results, this); if(doUpdate != false) - chart.plugin.jsChartRender.update(chart, results); + chart.plugin.chartRender.update(chart, results); }; renderer.handleError = function(e)