forked from p81075629/datagear
[analysis]完善HTML图表插件、看板逻辑
This commit is contained in:
parent
96a962edab
commit
d26664a71d
|
@ -1,52 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2018 datagear.tech. All Rights Reserved.
|
||||
*/
|
||||
package org.datagear.analysis;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 看板部件。
|
||||
* <p>
|
||||
* 它可在{@linkplain RenderContext}中渲染自己所描述的{@linkplain Dashboard}。
|
||||
* </p>
|
||||
*
|
||||
* @author datagear@163.com
|
||||
*
|
||||
*/
|
||||
public abstract class DashboardWidget<T extends RenderContext> extends AbstractIdentifiable
|
||||
{
|
||||
private List<ChartWidget<T>> chartWidgets;
|
||||
|
||||
public DashboardWidget()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public DashboardWidget(String id, List<? extends ChartWidget<T>> chartWidgets)
|
||||
{
|
||||
super(id);
|
||||
this.chartWidgets = (List<ChartWidget<T>>) chartWidgets;
|
||||
}
|
||||
|
||||
public List<ChartWidget<T>> getChartWidgets()
|
||||
{
|
||||
return chartWidgets;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void setChartWidgets(List<? extends ChartWidget<T>> chartWidgets)
|
||||
{
|
||||
this.chartWidgets = (List<ChartWidget<T>>) chartWidgets;
|
||||
}
|
||||
|
||||
/**
|
||||
* 渲染{@linkplain Dashboard}。
|
||||
*
|
||||
* @param renderContext
|
||||
* @return
|
||||
* @throws RenderException
|
||||
*/
|
||||
public abstract Dashboard render(T renderContext) throws RenderException;
|
||||
}
|
|
@ -0,0 +1,91 @@
|
|||
/*
|
||||
* Copyright (c) 2018 datagear.tech. All Rights Reserved.
|
||||
*/
|
||||
package org.datagear.analysis;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.StringReader;
|
||||
|
||||
import org.datagear.analysis.support.LocationResource;
|
||||
import org.datagear.util.IOUtil;
|
||||
|
||||
/**
|
||||
* 模板看板部件。
|
||||
* <p>
|
||||
* 它可在{@linkplain RenderContext}中渲染自己的模板({@linkplain #getTemplate()})所描述的{@linkplain Dashboard}。
|
||||
* </p>
|
||||
*
|
||||
* @author datagear@163.com
|
||||
*
|
||||
*/
|
||||
public abstract class TemplateDashboardWidget<T extends RenderContext> extends AbstractIdentifiable
|
||||
{
|
||||
private String template;
|
||||
|
||||
private String templateEncoding = "UTF-8";
|
||||
|
||||
public TemplateDashboardWidget()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public TemplateDashboardWidget(String id, String template)
|
||||
{
|
||||
super(id);
|
||||
this.template = template;
|
||||
}
|
||||
|
||||
public String getTemplate()
|
||||
{
|
||||
return template;
|
||||
}
|
||||
|
||||
public void setTemplate(String template)
|
||||
{
|
||||
this.template = template;
|
||||
}
|
||||
|
||||
public String getTemplateEncoding()
|
||||
{
|
||||
return templateEncoding;
|
||||
}
|
||||
|
||||
public void setTemplateEncoding(String templateEncoding)
|
||||
{
|
||||
this.templateEncoding = templateEncoding;
|
||||
}
|
||||
|
||||
/**
|
||||
* 渲染{@linkplain Dashboard}。
|
||||
*
|
||||
* @param renderContext
|
||||
* @return
|
||||
* @throws RenderException
|
||||
*/
|
||||
public abstract Dashboard render(T renderContext) throws RenderException;
|
||||
|
||||
/**
|
||||
* 获取{@linkplain #getTemplate()}的输入流。
|
||||
*
|
||||
* @return
|
||||
* @throws IOException
|
||||
*/
|
||||
protected BufferedReader getTemplateReader() throws IOException
|
||||
{
|
||||
BufferedReader reader = null;
|
||||
|
||||
if (LocationResource.isFileLocation(this.template)
|
||||
|| LocationResource.isClasspathLocation(this.template))
|
||||
{
|
||||
LocationResource resource = new LocationResource(this.template);
|
||||
reader = IOUtil.getReader(resource.getInputStream(), this.templateEncoding);
|
||||
}
|
||||
else
|
||||
{
|
||||
reader = new BufferedReader(new StringReader(this.template));
|
||||
}
|
||||
|
||||
return reader;
|
||||
}
|
||||
}
|
|
@ -2,10 +2,15 @@
|
|||
* Copyright (c) 2018 datagear.tech. All Rights Reserved.
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package org.datagear.analysis;
|
||||
package org.datagear.analysis.support;
|
||||
|
||||
import org.datagear.analysis.AbstractIdentifiable;
|
||||
import org.datagear.analysis.Chart;
|
||||
import org.datagear.analysis.ChartPlugin;
|
||||
import org.datagear.analysis.ChartPropertyValues;
|
||||
import org.datagear.analysis.DataSetFactory;
|
||||
import org.datagear.analysis.RenderContext;
|
||||
import org.datagear.analysis.RenderException;
|
||||
|
||||
/**
|
||||
* 图表部件。
|
|
@ -0,0 +1,24 @@
|
|||
/*
|
||||
* Copyright (c) 2018 datagear.tech. All Rights Reserved.
|
||||
*/
|
||||
|
||||
package org.datagear.analysis.support;
|
||||
|
||||
import org.datagear.analysis.RenderContext;
|
||||
|
||||
/**
|
||||
* {@linkplain ChartWidget}源。
|
||||
*
|
||||
* @author datagear@163.com
|
||||
*
|
||||
*/
|
||||
public interface ChartWidgetSource
|
||||
{
|
||||
/**
|
||||
* 获取指定ID的{@linkplain ChartWidget}。
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
<T extends RenderContext> ChartWidget<T> getChartWidget(String id);
|
||||
}
|
|
@ -1,70 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2018 datagear.tech. All Rights Reserved.
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package org.datagear.analysis.support.html;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.datagear.analysis.ChartWidget;
|
||||
import org.datagear.analysis.Dashboard;
|
||||
import org.datagear.analysis.DashboardWidget;
|
||||
import org.datagear.analysis.RenderException;
|
||||
|
||||
/**
|
||||
* HTML {@linkplain DashboardWidget}。
|
||||
* <p>
|
||||
* 此类将看板代码(HTML、JavaScript)输出至{@linkplain HtmlRenderContext#getWriter()}。
|
||||
* </p>
|
||||
*
|
||||
* @author datagear@163.com
|
||||
*
|
||||
*/
|
||||
public class HtmlDashboardWidget<T extends HtmlRenderContext> extends DashboardWidget<T>
|
||||
{
|
||||
/** 看板HTML模板 */
|
||||
private String template;
|
||||
|
||||
/** 换行符 */
|
||||
private String newLine = "\r\n";
|
||||
|
||||
public HtmlDashboardWidget()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public HtmlDashboardWidget(String id, List<? extends ChartWidget<T>> chartWidgets, String template)
|
||||
{
|
||||
super(id, chartWidgets);
|
||||
this.template = template;
|
||||
}
|
||||
|
||||
public String getTemplate()
|
||||
{
|
||||
return template;
|
||||
}
|
||||
|
||||
public void setTemplate(String template)
|
||||
{
|
||||
this.template = template;
|
||||
}
|
||||
|
||||
public String getNewLine()
|
||||
{
|
||||
return newLine;
|
||||
}
|
||||
|
||||
public void setNewLine(String newLine)
|
||||
{
|
||||
this.newLine = newLine;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dashboard render(T renderContext) throws RenderException
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,63 @@
|
|||
/*
|
||||
* Copyright (c) 2018 datagear.tech. All Rights Reserved.
|
||||
*/
|
||||
|
||||
package org.datagear.analysis.support.html;
|
||||
|
||||
import org.datagear.analysis.Dashboard;
|
||||
import org.datagear.analysis.RenderException;
|
||||
import org.datagear.analysis.TemplateDashboardWidget;
|
||||
import org.datagear.analysis.support.ChartWidget;
|
||||
import org.datagear.analysis.support.ChartWidgetSource;
|
||||
|
||||
/**
|
||||
* HTML {@linkplain TemplateDashboardWidget}。
|
||||
* <p>
|
||||
* 此类将看板代码(HTML、JavaScript)输出至{@linkplain HtmlRenderContext#getWriter()}。
|
||||
* </p>
|
||||
*
|
||||
* @author datagear@163.com
|
||||
*
|
||||
*/
|
||||
public class HtmlTemplateDashboardWidget<T extends HtmlRenderContext> extends TemplateDashboardWidget<T>
|
||||
{
|
||||
private ChartWidgetSource chartWidgetSource;
|
||||
|
||||
public HtmlTemplateDashboardWidget()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public HtmlTemplateDashboardWidget(String id, String template, ChartWidgetSource chartWidgetSource)
|
||||
{
|
||||
super(id, template);
|
||||
this.chartWidgetSource = chartWidgetSource;
|
||||
}
|
||||
|
||||
public ChartWidgetSource getChartWidgetSource()
|
||||
{
|
||||
return chartWidgetSource;
|
||||
}
|
||||
|
||||
public void setChartWidgetSource(ChartWidgetSource chartWidgetSource)
|
||||
{
|
||||
this.chartWidgetSource = chartWidgetSource;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dashboard render(T renderContext) throws RenderException
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定ID的{@linkplain ChartWidget}。
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
protected ChartWidget<T> getChartWidget(String id)
|
||||
{
|
||||
return this.chartWidgetSource.getChartWidget(id);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue