完善analysis模块基础API

This commit is contained in:
datagear 2019-12-03 21:44:14 +08:00
parent ad70144db9
commit 72322da672
22 changed files with 692 additions and 220 deletions

View File

@ -0,0 +1,53 @@
/*
* Copyright (c) 2018 datagear.tech. All Rights Reserved.
*/
package org.datagear.analysis;
import java.util.HashMap;
import java.util.Map;
/**
* 抽象{@linkplain ChartRenderContext}
*
* @author datagear@163.com
*
*/
public abstract class AbstractChartRenderContext implements ChartRenderContext
{
private Map<String, Object> attributes = new HashMap<String, Object>();
public AbstractChartRenderContext()
{
}
public void setAttributes(Map<String, Object> attributes)
{
this.attributes = attributes;
}
@SuppressWarnings("unchecked")
@Override
public <T> T getAttribute(String name)
{
return (T) (this.attributes == null ? null : this.attributes.get(name));
}
@Override
public void setAttribute(String name, Object value)
{
this.attributes.put(name, value);
}
@Override
public boolean hasAttribute(String name)
{
return this.attributes.containsKey(name);
}
@Override
public Map<String, ?> getAttributes()
{
return this.attributes;
}
}

View File

@ -16,7 +16,16 @@ package org.datagear.analysis;
public interface Chart
{
/**
* 绘制
* 获取{@linkplain ChartPropertyValues}
*
* @return
*/
void render();
ChartPropertyValues getChartOptions();
/**
* 获取{@linkplain DataSetFactory}
*
* @return
*/
DataSetFactory[] getDataSetFactories();
}

View File

@ -1,19 +0,0 @@
/*
* Copyright (c) 2018 datagear.tech. All Rights Reserved.
*/
/**
*
*/
package org.datagear.analysis;
/**
* 图表上下文
*
* @author datagear@163.com
*
*/
public interface ChartContext
{
}

View File

@ -7,22 +7,92 @@
*/
package org.datagear.analysis;
import java.util.List;
import org.datagear.util.i18n.Label;
/**
* 图表插件
*
* @author datagear@163.com
*
* @param <T>
*/
public interface ChartPlugin<T extends ChartContext>
public interface ChartPlugin
{
/**
* 获取名称
*
* @return
*/
String getName();
String getLabel();
/**
* 获取名称标签
* <p>
* 返回{@code null}表示无名称标签
* </p>
*
* @return
*/
Label getNameLabel();
String getIcon();
/**
* 获取描述标签
* <p>
* 返回{@code null}表示无描述标签
* </p>
*
* @return
*/
Label getDescLabel();
ChartProperties getChartProperties();
/**
* 获取使用指南标签
* <p>
* 返回{@code null}表示无使用标签
* </p>
*
* @return
*/
Label getManualLabel();
Chart getChart(T chartContext, ChartOptions chartOptions, DataSet... dataSet);
/**
* 获取图标
* <p>
* 返回{@code null}表示无图标
* </p>
*
* @param theme
* @return
*/
Icon getIcon(String theme);
/**
* 获取{@linkplain ChartProperty}列表
* <p>
* 返回{@code null}或者空列表表示没有
* </p>
*
* @return
*/
List<ChartProperty> getChartProperties();
/**
* 是否支持在指定类型{@linkplain ChartRenderContext}中绘制图表
*
* @param chartContextType
* @return
*/
boolean supports(Class<? extends ChartRenderContext> chartRenderContextType);
/**
* 绘制图表
*
* @param chartRenderContext
* @param chartPropertyValues
* @param dataSetFactories
* @return
*/
Chart renderChart(ChartRenderContext chartRenderContext, ChartPropertyValues chartPropertyValues,
DataSetFactory... dataSetFactories);
}

View File

@ -7,18 +7,48 @@ package org.datagear.analysis;
import java.util.List;
/**
* 图表插件管理器
* {@linkplain ChartPlugin}管理器
*
* @author datagear@163.com
*
*/
public interface ChartPluginManager
{
<T extends ChartContext> ChartPlugin<T> get(String name);
/**
* 注册一个{@linkplain ChartPlugin}
*
* @param chartPlugin
*/
void register(ChartPlugin chartPlugin);
<T extends ChartContext> List<ChartPlugin<T>> find(Class<T> chartContextType);
/**
* 移除指定名称的{@linkplain ChartPlugin}
*
* @param name
* @return 被移除的{@linkplain ChartPlugin}或者{@code null}
*/
ChartPlugin remove(String name);
List<ChartPlugin<?>> getAll();
/**
* 获取指定名称的{@linkplain ChartPlugin}
*
* @param name
* @return
*/
ChartPlugin get(String name);
void register(ChartPlugin<?> chartPlugin);
/**
* 获取支持指定类型{@linkplain ChartRenderContext}的所有{@linkplain ChartPlugin}
*
* @param chartRenderContextType
* @return
*/
List<? extends ChartPlugin> getAll(Class<? extends ChartRenderContext> chartRenderContextType);
/**
* 获取所有{@linkplain ChartPlugin}
*
* @return
*/
List<? extends ChartPlugin> getAll();
}

View File

@ -1,50 +0,0 @@
/*
* Copyright (c) 2018 datagear.tech. All Rights Reserved.
*/
/**
*
*/
package org.datagear.analysis;
import java.util.Collections;
import java.util.List;
/**
* 图表可设置属性集
*
* @author datagear@163.com
*
*/
public class ChartProperties
{
@SuppressWarnings("unchecked")
private List<ChartProperty> properties = Collections.EMPTY_LIST;
public ChartProperties()
{
super();
}
public ChartProperties(List<ChartProperty> properties)
{
super();
this.properties = properties;
}
public List<ChartProperty> getProperties()
{
return properties;
}
public void setProperties(List<ChartProperty> properties)
{
this.properties = properties;
}
@Override
public String toString()
{
return getClass().getSimpleName() + " [properties=" + properties + "]";
}
}

View File

@ -4,29 +4,39 @@
package org.datagear.analysis;
import java.util.Collections;
import java.util.List;
import org.datagear.analysis.constraint.Constraint;
import org.datagear.util.i18n.Label;
/**
* 图表可设置属性
* 图表属性
* <p>
* 此类表示可由用户在界面输入设置的图表属性
* </p>
*
* @author datagear@163.com
*
*/
public class ChartProperty
{
/** 名称 */
private String name;
/** 类型 */
private PropertyType type;
private String label;
/** 名称标签 */
private Label nameLabel;
/** 描述标签 */
private Label descLabel;
/** 默认值 */
private Object defaultValue;
@SuppressWarnings("unchecked")
private List<Constraint> constraints = Collections.EMPTY_LIST;
/** 约束 */
private List<Constraint> constraints;
public ChartProperty()
{
@ -59,14 +69,39 @@ public class ChartProperty
this.type = type;
}
public String getLabel()
public boolean hasNameLabel()
{
return label;
return (this.nameLabel != null);
}
public void setLabel(String label)
public Label getNameLabel()
{
this.label = label;
return nameLabel;
}
public void setNameLabel(Label nameLabel)
{
this.nameLabel = nameLabel;
}
public boolean hasDescLabel()
{
return (this.descLabel != null);
}
public Label getDescLabel()
{
return descLabel;
}
public void setDescLabel(Label descLabel)
{
this.descLabel = descLabel;
}
public boolean hasDefaultValue()
{
return (this.defaultValue != null);
}
public Object getDefaultValue()
@ -79,6 +114,11 @@ public class ChartProperty
this.defaultValue = defaultValue;
}
public boolean hasConstraint()
{
return (this.constraints != null && !this.constraints.isEmpty());
}
public List<Constraint> getConstraints()
{
return constraints;

View File

@ -2,35 +2,38 @@
* Copyright (c) 2018 datagear.tech. All Rights Reserved.
*/
/**
*
*/
package org.datagear.analysis;
import java.util.Collections;
import java.util.Map;
/**
* 图表设置项集
* 图表属性值集合
* <p>
* 此类用于表示用户对{@linkplain ChartPlugin#getChartProperties()}的输入集
* </p>
*
* @author datagear@163.com
*
*/
public class ChartOptions
public class ChartPropertyValues
{
@SuppressWarnings("unchecked")
private Map<String, ?> options = Collections.EMPTY_MAP;
private Map<String, ?> options;
public ChartOptions()
public ChartPropertyValues()
{
}
public ChartOptions(Map<String, ?> options)
public ChartPropertyValues(Map<String, ?> options)
{
super();
this.options = options;
}
public boolean hasOption()
{
return (this.options != null && !this.options.isEmpty());
}
public Map<String, ?> getOptions()
{
return options;

View File

@ -0,0 +1,51 @@
/*
* Copyright (c) 2018 datagear.tech. All Rights Reserved.
*/
/**
*
*/
package org.datagear.analysis;
import java.util.Map;
/**
* 图表渲染上下文
*
* @author datagear@163.com
*
*/
public interface ChartRenderContext
{
/**
* 获取属性
*
* @param <T>
* @param name
* @return
*/
<T> T getAttribute(String name);
/**
* 设置属性
*
* @param name
* @param value
*/
void setAttribute(String name, Object value);
/**
* 是否有指定属性
*
* @param name
* @return
*/
boolean hasAttribute(String name);
/**
* 获取所有属性
*
* @return
*/
Map<String, ?> getAttributes();
}

View File

@ -15,21 +15,24 @@ package org.datagear.analysis;
*/
public class ColumnMeta
{
/** 名称 */
private String name;
private String type;
/** 数据类型 */
private DataType dataType;
/** 展示标签 */
private String label;
public ColumnMeta()
{
}
public ColumnMeta(String name, String type)
public ColumnMeta(String name, DataType dataType)
{
super();
this.name = name;
this.type = type;
this.dataType = dataType;
}
public String getName()
@ -42,14 +45,19 @@ public class ColumnMeta
this.name = name;
}
public String getType()
public DataType getDataType()
{
return type;
return dataType;
}
public void setType(String type)
public void setDataType(DataType dataType)
{
this.type = type;
this.dataType = dataType;
}
public boolean hasLabel()
{
return (this.label != null && !this.label.isEmpty());
}
public String getLabel()
@ -65,6 +73,6 @@ public class ColumnMeta
@Override
public String toString()
{
return getClass().getSimpleName() + " [name=" + name + ", type=" + type + "]";
return getClass().getSimpleName() + " [name=" + name + ", dataType=" + dataType + "]";
}
}

View File

@ -15,9 +15,17 @@ import java.util.Map;
*/
public interface DataSet
{
String getName();
/**
* 获取{@linkplain DataSetMeta}
*
* @return
*/
DataSetMeta getMeta();
/**
* 获取数据
*
* @return
*/
List<? extends Map<String, ?>> getDatas();
}

View File

@ -0,0 +1,37 @@
/*
* Copyright (c) 2018 datagear.tech. All Rights Reserved.
*/
/**
*
*/
package org.datagear.analysis;
import java.util.List;
/**
* 数据集工厂
*
* @author datagear@163.com
*
*/
public interface DataSetFactory
{
/**
* 获取{@linkplain DataSetParam}列表
* <p>
* 返回{@code null}或者空列表表示没有
* </p>
*
* @return
*/
List<DataSetParam> getDataSetParams();
/**
* 获取{@linkplain DataSet}
*
* @param dataSetParamValues
* @return
*/
DataSet getDataSet(DataSetParamValues dataSetParamValues);
}

View File

@ -0,0 +1,87 @@
/*
* Copyright (c) 2018 datagear.tech. All Rights Reserved.
*/
package org.datagear.analysis;
/**
* 数据集参数
* <p>
* 此类表示{@linkplain DataSetFactory}创建{@linkplain DataSet}所需要的输入参数信息
* </p>
*
* @author datagear@163.com
*
*/
public class DataSetParam
{
/** 名称 */
private String name;
/** 参数类型 */
private DataType type;
/** 是否必须 */
private boolean required;
/** 默认值 */
private Object defaultValue;
public DataSetParam()
{
}
public DataSetParam(String name, DataType type, boolean required)
{
super();
this.name = name;
this.type = type;
this.required = required;
}
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
public DataType getType()
{
return type;
}
public void setType(DataType type)
{
this.type = type;
}
public boolean isRequired()
{
return required;
}
public void setRequired(boolean required)
{
this.required = required;
}
public Object getDefaultValue()
{
return defaultValue;
}
public void setDefaultValue(Object defaultValue)
{
this.defaultValue = defaultValue;
}
@Override
public String toString()
{
return getClass().getSimpleName() + " [name=" + name + ", type=" + type + "]";
}
}

View File

@ -0,0 +1,50 @@
/*
* Copyright (c) 2018 datagear.tech. All Rights Reserved.
*/
/**
*
*/
package org.datagear.analysis;
import java.util.Map;
/**
* 数据集参数值集合
* <p>
* 此类表示{@linkplain DataSetFactory}创建{@linkplain DataSet}所需要的参数值集
* </p>
*
* @author datagear@163.com
*
*/
public class DataSetParamValues
{
private Map<String, ?> values;
public DataSetParamValues()
{
}
public DataSetParamValues(Map<String, ?> values)
{
super();
this.values = values;
}
public Map<String, ?> getValues()
{
return values;
}
public void setValues(Map<String, ?> values)
{
this.values = values;
}
@SuppressWarnings("unchecked")
public <T> T getValue(String name)
{
return (T) (this.values == null ? null : this.values.get(name));
}
}

View File

@ -0,0 +1,38 @@
/*
* Copyright (c) 2018 datagear.tech. All Rights Reserved.
*/
/**
*
*/
package org.datagear.analysis;
/**
* 数据类型
*
* @author datagear@163.com
*
*/
public enum DataType
{
/** 字符串 */
STRING,
/** 布尔值 */
BOOLEAN,
/** 整数 */
INTEGER,
/** 小数 */
DECIMAL,
/** 日期 */
DATE,
/** 时间 */
TIME,
/** 时间戳 */
TIMESTAMP
}

View File

@ -1,41 +0,0 @@
/*
* Copyright (c) 2018 datagear.tech. All Rights Reserved.
*/
/**
*
*/
package org.datagear.analysis;
import java.io.Writer;
/**
* HTML图表上下文
*
* @author datagear@163.com
*
*/
public class HtmlChartContext implements ChartContext
{
private Writer out;
public HtmlChartContext()
{
}
public HtmlChartContext(Writer out)
{
super();
this.out = out;
}
public Writer getOut()
{
return out;
}
public void setOut(Writer out)
{
this.out = out;
}
}

View File

@ -0,0 +1,23 @@
/*
* Copyright (c) 2018 datagear.tech. All Rights Reserved.
*/
package org.datagear.analysis;
import java.io.Writer;
/**
* HTML图表渲染上下文
*
* @author datagear@163.com
*
*/
public interface HtmlChartRenderContext extends ChartRenderContext
{
/**
* 获取用于输出{@linkplain Chart}的输出流
*
* @return
*/
public Writer getOut();
}

View File

@ -0,0 +1,33 @@
/*
* Copyright (c) 2018 datagear.tech. All Rights Reserved.
*/
/**
*
*/
package org.datagear.analysis;
import java.io.InputStream;
/**
* 图标
*
* @author datagear@163.com
*
*/
public interface Icon
{
/**
* 获取图标输入流
*
* @return
*/
InputStream getInputStream();
/**
* 获取图标扩展名比如{@code pngjpeg}
*
* @return
*/
String getExtension();
}

View File

@ -8,7 +8,7 @@
package org.datagear.analysis;
/**
* 图表属性类型
* 图表可设置属性类型
*
* @author datagear@163.com
*

View File

@ -11,4 +11,12 @@
<artifactId>datagear-model</artifactId>
<name>datagear-model</name>
<dependencies>
<dependency>
<groupId>org.datagear</groupId>
<artifactId>datagear-util</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>

View File

@ -4,7 +4,6 @@
package org.datagear.model;
import java.io.Serializable;
import java.util.Locale;
import java.util.Map;
@ -14,14 +13,10 @@ import java.util.Map;
* @author datagear@163.com
*
*/
public class Label implements Serializable
public class Label extends org.datagear.util.i18n.Label
{
private static final long serialVersionUID = 1L;
private String value;
private Map<Locale, String> localeValues;
public Label()
{
super();
@ -29,70 +24,11 @@ public class Label implements Serializable
public Label(String value)
{
super();
this.value = value;
super(value);
}
public Label(String value, Map<Locale, String> localeValues)
{
super();
this.value = value;
this.localeValues = localeValues;
}
/**
* 获取标签默认值
*
* @return
*/
public String getValue()
{
return this.value;
}
/**
* 设置标签默认值
*
* @param value
*/
public void setValue(String value)
{
this.value = value;
}
/**
* 获取指定{@linkplain Locale}的标签值
*
* @param locale
* @return
*/
public String getValue(Locale locale)
{
String value = (this.localeValues == null ? null : this.localeValues.get(locale));
if (value == null)
value = this.value;
return value;
}
/**
* 获取地区标签值映射表
*
* @return
*/
public Map<Locale, String> getLocaleValues()
{
return this.localeValues;
}
/**
* 设置地区标签值映射表
*
* @param localeValues
*/
public void setLocaleValues(Map<Locale, String> localeValues)
{
this.localeValues = localeValues;
super(value, localeValues);
}
}

View File

@ -0,0 +1,98 @@
/*
* Copyright 2018 datagear.tech. All Rights Reserved.
*/
package org.datagear.util.i18n;
import java.io.Serializable;
import java.util.Locale;
import java.util.Map;
/**
* 标签
*
* @author datagear@163.com
*
*/
public class Label implements Serializable
{
private static final long serialVersionUID = 1L;
private String value;
private Map<Locale, String> localeValues;
public Label()
{
super();
}
public Label(String value)
{
super();
this.value = value;
}
public Label(String value, Map<Locale, String> localeValues)
{
super();
this.value = value;
this.localeValues = localeValues;
}
/**
* 获取标签默认值
*
* @return
*/
public String getValue()
{
return this.value;
}
/**
* 设置标签默认值
*
* @param value
*/
public void setValue(String value)
{
this.value = value;
}
/**
* 获取指定{@linkplain Locale}的标签值
*
* @param locale
* @return
*/
public String getValue(Locale locale)
{
String value = (this.localeValues == null ? null : this.localeValues.get(locale));
if (value == null)
value = this.value;
return value;
}
/**
* 获取地区标签值映射表
*
* @return
*/
public Map<Locale, String> getLocaleValues()
{
return this.localeValues;
}
/**
* 设置地区标签值映射表
*
* @param localeValues
*/
public void setLocaleValues(Map<Locale, String> localeValues)
{
this.localeValues = localeValues;
}
}