forked from p81075629/datagear
完善内置图表插件,添加散点图、雷达图、漏斗图
This commit is contained in:
parent
739b4f292c
commit
3d104fabfb
|
@ -15,6 +15,13 @@ import java.util.Map;
|
|||
*/
|
||||
public interface DataSet extends Identifiable
|
||||
{
|
||||
/**
|
||||
* 获取名称。
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
String getName();
|
||||
|
||||
/**
|
||||
* 获取属性列表。
|
||||
* <p>
|
||||
|
|
|
@ -14,12 +14,12 @@ import java.util.Map;
|
|||
|
||||
import org.datagear.analysis.AbstractIdentifiable;
|
||||
import org.datagear.analysis.DataNameAndType;
|
||||
import org.datagear.analysis.DataSetResult;
|
||||
import org.datagear.analysis.DataSet;
|
||||
import org.datagear.analysis.DataSetException;
|
||||
import org.datagear.analysis.DataSetExport;
|
||||
import org.datagear.analysis.DataSet;
|
||||
import org.datagear.analysis.DataSetParam;
|
||||
import org.datagear.analysis.DataSetProperty;
|
||||
import org.datagear.analysis.DataSetResult;
|
||||
|
||||
/**
|
||||
* 抽象{@linkplain DataSet}。
|
||||
|
@ -29,6 +29,8 @@ import org.datagear.analysis.DataSetProperty;
|
|||
*/
|
||||
public abstract class AbstractDataSet extends AbstractIdentifiable implements DataSet
|
||||
{
|
||||
private String name;
|
||||
|
||||
private List<DataSetProperty> properties;
|
||||
|
||||
private List<DataSetParam> params;
|
||||
|
@ -40,12 +42,24 @@ public abstract class AbstractDataSet extends AbstractIdentifiable implements Da
|
|||
super();
|
||||
}
|
||||
|
||||
public AbstractDataSet(String id, List<DataSetProperty> properties)
|
||||
public AbstractDataSet(String id, String name, List<DataSetProperty> properties)
|
||||
{
|
||||
super(id);
|
||||
this.name = name;
|
||||
this.properties = properties;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name)
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DataSetProperty> getProperties()
|
||||
{
|
||||
|
|
|
@ -31,7 +31,7 @@ public class SimpleDashboardThemeSource implements DashboardThemeSource
|
|||
|
||||
public static final DashboardTheme THEME_DARK = new DashboardTheme("#000", "#EEE", "#333",
|
||||
new ChartTheme("#101010", "#EEE", "#202020", "#AAA", "#888", "#444", "#F58400", new String[] { "#5EF6FE",
|
||||
"#12CDD2", "#019DA2", "#24666C", "#73A373", "#EA7E53", "#EEDD78", "#73B9BC", "#7289AB", "#91CA8C" },
|
||||
"#91CA8C", "#EA7E53", "#24666C", "#73A373", "#019DA2", "#EEDD78", "#73B9BC", "#7289AB", "#12CDD2" },
|
||||
new Theme("#000", "#EEE", "#333")));
|
||||
|
||||
private Map<RenderStyle, DashboardTheme> dashboardThemes;
|
||||
|
|
|
@ -13,11 +13,11 @@ import java.sql.SQLException;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.datagear.analysis.DataSetResult;
|
||||
import org.datagear.analysis.DataSetException;
|
||||
import org.datagear.analysis.DataSet;
|
||||
import org.datagear.analysis.DataSetException;
|
||||
import org.datagear.analysis.DataSetParam;
|
||||
import org.datagear.analysis.DataSetProperty;
|
||||
import org.datagear.analysis.DataSetResult;
|
||||
import org.datagear.analysis.support.ParameterSqlResolver.ParameterSql;
|
||||
import org.datagear.util.JdbcUtil;
|
||||
import org.datagear.util.JdbcUtil.QueryResultSet;
|
||||
|
@ -46,10 +46,10 @@ public class SqlDataSet extends AbstractDataSet
|
|||
super();
|
||||
}
|
||||
|
||||
public SqlDataSet(String id, List<DataSetProperty> properties, ConnectionFactory connectionFactory,
|
||||
public SqlDataSet(String id, String name, List<DataSetProperty> properties, ConnectionFactory connectionFactory,
|
||||
String sql)
|
||||
{
|
||||
super(id, properties);
|
||||
super(id, name, properties);
|
||||
this.connectionFactory = connectionFactory;
|
||||
this.sql = sql;
|
||||
}
|
||||
|
|
|
@ -42,7 +42,7 @@ public class DirectoryHtmlChartPluginManager extends ConcurrentChartPluginManage
|
|||
|
||||
private HtmlChartPluginLoader htmlChartPluginLoader = new HtmlChartPluginLoader();
|
||||
|
||||
private long readCheckForReloadTimeThreashold = 5 * 60 * 1000;
|
||||
private long readCheckForReloadTimeThreashold = (LOGGER.isDebugEnabled() ? 0 : 5 * 60 * 1000);
|
||||
|
||||
private Map<String, String> pluginIdFileNameMap = new HashMap<String, String>();
|
||||
|
||||
|
|
|
@ -107,7 +107,7 @@ public class HtmlChartScriptObjectWriter extends AbstractHtmlScriptObjectWriter
|
|||
{
|
||||
public JsonDataSet(DataSet dataSet)
|
||||
{
|
||||
super(dataSet.getId(), dataSet.getProperties());
|
||||
super(dataSet.getId(), dataSet.getName(), dataSet.getProperties());
|
||||
setParams(dataSet.getParams());
|
||||
setExports(dataSet.getExports());
|
||||
}
|
||||
|
|
|
@ -14,9 +14,9 @@ import java.util.HashMap;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.datagear.analysis.DataSetResult;
|
||||
import org.datagear.analysis.DataSetParam;
|
||||
import org.datagear.analysis.DataSetProperty;
|
||||
import org.datagear.analysis.DataSetResult;
|
||||
import org.datagear.analysis.DataType;
|
||||
import org.datagear.util.JdbcUtil;
|
||||
import org.datagear.util.resource.SimpleConnectionFactory;
|
||||
|
@ -66,7 +66,7 @@ public class SqlDataSetTest extends DBTestSupport
|
|||
List<DataSetParam> dataSetParams = Arrays.asList(new DataSetParam("id", DataType.INTEGER, true),
|
||||
new DataSetParam("name", DataType.STRING, true));
|
||||
|
||||
SqlDataSet sqlDataSet = new SqlDataSet("1", dataSetProperties, connectionFactory, sql);
|
||||
SqlDataSet sqlDataSet = new SqlDataSet("1", "1", dataSetProperties, connectionFactory, sql);
|
||||
sqlDataSet.setParams(dataSetParams);
|
||||
|
||||
Map<String, Object> dataSetParamValues = new HashMap<String, Object>();
|
||||
|
|
|
@ -27,9 +27,6 @@ public class SqlDataSetEntity extends SqlDataSet implements CreateUserEntity<Str
|
|||
/** 授权资源类型 */
|
||||
public static final String AUTHORIZATION_RESOURCE_TYPE = "DataSet";
|
||||
|
||||
/** 名称 */
|
||||
private String name;
|
||||
|
||||
/** 创建用户 */
|
||||
private User createUser;
|
||||
|
||||
|
@ -45,11 +42,11 @@ public class SqlDataSetEntity extends SqlDataSet implements CreateUserEntity<Str
|
|||
this.createTime = new Date();
|
||||
}
|
||||
|
||||
public SqlDataSetEntity(String id, List<DataSetProperty> properties, SchemaConnectionFactory connectionFactory,
|
||||
String sql, String name, User createUser)
|
||||
public SqlDataSetEntity(String id, String name, List<DataSetProperty> properties,
|
||||
SchemaConnectionFactory connectionFactory,
|
||||
String sql, User createUser)
|
||||
{
|
||||
super(id, properties, connectionFactory, sql);
|
||||
this.name = name;
|
||||
super(id, name, properties, connectionFactory, sql);
|
||||
this.createTime = new Date();
|
||||
}
|
||||
|
||||
|
@ -78,16 +75,6 @@ public class SqlDataSetEntity extends SqlDataSet implements CreateUserEntity<Str
|
|||
setConnectionFactory(schemaConnectionFactory);
|
||||
}
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name)
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public User getCreateUser()
|
||||
{
|
||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -15,6 +15,9 @@
|
|||
|
||||
/**
|
||||
* 获取图表主题。
|
||||
*
|
||||
* @param chart
|
||||
* @return {...}
|
||||
*/
|
||||
util.chartTheme = function(chart)
|
||||
{
|
||||
|
@ -22,7 +25,10 @@
|
|||
};
|
||||
|
||||
/**
|
||||
* 获取渲染样式。
|
||||
* 获取渲染风格。
|
||||
*
|
||||
* @param chart
|
||||
* @return "..."
|
||||
*/
|
||||
util.chartRenderStyle = function(chart)
|
||||
{
|
||||
|
@ -87,9 +93,10 @@
|
|||
};
|
||||
|
||||
/**
|
||||
* 获取第一个图标数据集对象。
|
||||
* 获取第一个图表数据集对象。
|
||||
*
|
||||
* @param chart
|
||||
* @return {dataSet: [], propertySigns: {...}}
|
||||
*/
|
||||
util.firstChartDataSet = function(chart)
|
||||
{
|
||||
|
@ -99,6 +106,30 @@
|
|||
return chart.chartDataSets[0];
|
||||
};
|
||||
|
||||
/**
|
||||
* 获取图表数据集对象数组。
|
||||
*/
|
||||
util.chartDataSets = function(chart)
|
||||
{
|
||||
if(!chart || !chart.chartDataSets || chart.chartDataSets.length < 1)
|
||||
return [];
|
||||
|
||||
return chart.chartDataSets;
|
||||
};
|
||||
|
||||
/**
|
||||
* 获取图表名称。
|
||||
*
|
||||
* @param chartDataSet 图表数据集对象
|
||||
*/
|
||||
util.dataSetName = function(chartDataSet)
|
||||
{
|
||||
var dataSet = (chartDataSet.dataSet || chartDataSet);
|
||||
var name = (dataSet ? dataSet.name : "");
|
||||
|
||||
return (name ? name : "");
|
||||
};
|
||||
|
||||
/**
|
||||
* 获取指定标记的第一个数据集属性,没有则返回null。
|
||||
*
|
||||
|
@ -145,12 +176,12 @@
|
|||
}
|
||||
}
|
||||
|
||||
for(var i=0; i<signPropertyNames.length; i++)
|
||||
for(var i=0; i<dataSetProperties.length; i++)
|
||||
{
|
||||
for(var j=0; j<dataSetProperties.length; j++)
|
||||
for(var j=0; j<signPropertyNames.length; j++)
|
||||
{
|
||||
if(dataSetProperties[j].name == signPropertyNames[i])
|
||||
re.push(dataSetProperties[j]);
|
||||
if(dataSetProperties[i].name == signPropertyNames[j])
|
||||
re.push(dataSetProperties[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -160,14 +191,14 @@
|
|||
/**
|
||||
* 获取数据集属性标签,没有则返回空字符串。
|
||||
*
|
||||
* @param datasetProperty
|
||||
* @param dataSetProperty
|
||||
*/
|
||||
util.dataSetPropertyLabel = function(datasetProperty)
|
||||
util.dataSetPropertyLabel = function(dataSetProperty)
|
||||
{
|
||||
var label = (datasetProperty ? datasetProperty.label : null);
|
||||
var label = (dataSetProperty ? dataSetProperty.label : null);
|
||||
|
||||
if(!label && datasetProperty)
|
||||
label = datasetProperty.name;
|
||||
if(!label && dataSetProperty)
|
||||
label = dataSetProperty.name;
|
||||
|
||||
if(!label)
|
||||
label = "";
|
||||
|
@ -176,103 +207,179 @@
|
|||
};
|
||||
|
||||
/**
|
||||
* 返回第一个数据结果集。
|
||||
* 返回第一个数据集结果。
|
||||
*/
|
||||
util.firstResult = function(dataSetResults)
|
||||
util.resultFirst = function(dataSetResults)
|
||||
{
|
||||
if(!dataSetResults || dataSetResults.length < 1)
|
||||
return [];
|
||||
return {};
|
||||
|
||||
return dataSetResults[0];
|
||||
};
|
||||
|
||||
/**
|
||||
* 获取结果数据第一行的属性值。
|
||||
*
|
||||
* @param result 数据集结果对象、对象数组
|
||||
* @param property 属性对象、属性名、属性对象数组、属性名数组
|
||||
*/
|
||||
util.dataPropertyValue = function(result, property)
|
||||
util.resultIndex = function(dataSetResults, index)
|
||||
{
|
||||
if(property == null)
|
||||
return null;
|
||||
|
||||
var re = this.dataPropertyValues(result, property, 1);
|
||||
|
||||
if(property.length > 0)
|
||||
{
|
||||
for(var i=0; i< property.length; i++)
|
||||
re[i] = (re[i].length > 0 ? re[i][0] : null);
|
||||
if(!dataSetResults || !dataSetResults.length || dataSetResults.length < index)
|
||||
return {};
|
||||
|
||||
return re;
|
||||
}
|
||||
else
|
||||
return (re.length > 0 ? re[0] : null);
|
||||
return dataSetResults[index];
|
||||
};
|
||||
|
||||
/**
|
||||
* 获取结果数据属性值数组。
|
||||
* 获取数据集结果指定属性、指定行的单元格值。
|
||||
*
|
||||
* @param result 数据集结果对象、对象数组
|
||||
* @param property 属性对象、属性名、属性对象数组、属性名数组
|
||||
* @param count 获取结果数据的最多行数,可选,默认为全部
|
||||
* @param property 数据集属性对象、属性名
|
||||
* @param row 行索引,以0开始,默认为0
|
||||
*/
|
||||
util.dataPropertyValues = function(result, property, count)
|
||||
util.resultCell = function(result, property, row)
|
||||
{
|
||||
if(row == null)
|
||||
row = 0;
|
||||
|
||||
var re = this.resultRowArrays(result, property, row+1);
|
||||
|
||||
return (re.length > row ? re[row] : undefined);
|
||||
};
|
||||
|
||||
/**
|
||||
* 将数据集结果的行对象按照指定properties顺序转换为行值数组。
|
||||
*
|
||||
* @param result 数据集结果对象、对象数组
|
||||
* @param properties 数据集属性对象数组、属性名数组、属性对象、属性名
|
||||
* @param count 获取的最多行数,可选,默认为全部
|
||||
* @return properties为数组时:[[..., ...], ...];properties非数组时:[..., ...]
|
||||
*/
|
||||
util.resultRowArrays = function(result, properties, count)
|
||||
{
|
||||
var re = [];
|
||||
|
||||
if(property == null)
|
||||
if(properties == null)
|
||||
return re;
|
||||
|
||||
var datas = (result.length != null ? result : (result.datas || []));
|
||||
|
||||
var getCount = datas.length;
|
||||
if(count != null && count < getCount)
|
||||
getCount = count;
|
||||
|
||||
if(property.length > 0)
|
||||
if(properties.length > 0)
|
||||
{
|
||||
for(var i=0; i<property.length; i++)
|
||||
for(var i=0; i< getCount; i++)
|
||||
{
|
||||
var myValues = [];
|
||||
var rowObj = datas[i];
|
||||
var row = [];
|
||||
|
||||
var cm = property[i];
|
||||
for(var j=0; j<properties.length; j++)
|
||||
{
|
||||
var p = properties[j];
|
||||
|
||||
var name = (p ? (p.name || p) : undefined);
|
||||
if(!name)
|
||||
continue;
|
||||
|
||||
row[j] = rowObj[name];
|
||||
}
|
||||
|
||||
var name = (cm.name || cm);
|
||||
|
||||
for(var j=0; j< getCount; j++)
|
||||
myValues[j] = datas[j][name];
|
||||
|
||||
re[i] = myValues;
|
||||
re[i] = row;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var name = (property.name || property);
|
||||
var name = (properties ? (properties.name || properties) : undefined);
|
||||
|
||||
for(var i=0; i< getCount; i++)
|
||||
re[i] = datas[i][name];
|
||||
if(name)
|
||||
{
|
||||
for(var i=0; i< getCount; i++)
|
||||
{
|
||||
var rowObj = datas[i];
|
||||
re[i] = rowObj[name];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return re;
|
||||
};
|
||||
|
||||
/**
|
||||
* 获取结果数据的名称/值对象数组:[{name: ..., value: ...}, ...]。
|
||||
* 将数据集结果的行对象按照指定properties顺序转换为列值数组。
|
||||
*
|
||||
* @param result 数据集结果对象、对象数组
|
||||
* @param properties 数据集属性对象数组、属性名数组、属性对象、属性名
|
||||
* @param count 获取的最多行数,可选,默认为全部
|
||||
* @return properties为数组时:[[..., ...], ...];properties非数组时:[..., ...]
|
||||
*/
|
||||
util.resultColumnArrays = function(result, properties, count)
|
||||
{
|
||||
var re = [];
|
||||
|
||||
if(properties == null)
|
||||
return re;
|
||||
|
||||
var datas = (result.length != null ? result : (result.datas || []));
|
||||
|
||||
var getCount = datas.length;
|
||||
if(count != null && count < getCount)
|
||||
getCount = count;
|
||||
|
||||
if(properties.length > 0)
|
||||
{
|
||||
for(var i=0; i<properties.length; i++)
|
||||
{
|
||||
var p = properties[i];
|
||||
|
||||
var name = (p ? (p.name || p) : undefined);
|
||||
if(!name)
|
||||
continue;
|
||||
|
||||
var column = [];
|
||||
|
||||
for(var j=0; j< getCount; j++)
|
||||
column[j] = datas[j][name];
|
||||
|
||||
re[i] = column;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var name = (properties ? (properties.name || properties) : undefined);
|
||||
|
||||
if(name)
|
||||
{
|
||||
for(var i=0; i< getCount; i++)
|
||||
{
|
||||
var rowObj = datas[i];
|
||||
re[i] = rowObj[name];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return re;
|
||||
};
|
||||
|
||||
/**
|
||||
* 获取数据集结果的名称/值对象数组。
|
||||
*
|
||||
* @param result 数据集结果对象、对象数组
|
||||
* @param nameProperty 名称属性对象、属性名
|
||||
* @param valueProperty 值属性对象、属性名
|
||||
* @param count 获取结果数据的最多行数,可选,默认为全部
|
||||
* @return [{name: ..., value: ...}, ...]
|
||||
*/
|
||||
util.dataNameValueObjects = function(result, nameProperty, valueProperty)
|
||||
util.resultNameValueObjects = function(result, nameProperty, valueProperty, count)
|
||||
{
|
||||
var re = [];
|
||||
|
||||
var datas = (result.length != null ? result : (result.datas || []));
|
||||
|
||||
var getCount = datas.length;
|
||||
if(count != null && count < getCount)
|
||||
getCount = count;
|
||||
|
||||
nameProperty = (nameProperty.name || nameProperty);
|
||||
valueProperty = (valueProperty.name || valueProperty);
|
||||
|
||||
for(var i=0; i< datas.length; i++)
|
||||
for(var i=0; i< getCount; i++)
|
||||
{
|
||||
var obj =
|
||||
{
|
||||
|
|
|
@ -153,6 +153,20 @@ CREATE TABLE T_ANALYSIS
|
|||
VALUE FLOAT(10,2) NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE T_ANALYSIS_1
|
||||
(
|
||||
COL_NAME VARCHAR(50) NOT NULL,
|
||||
COL_DATE DATE NOT NULL,
|
||||
COL_VALUE FLOAT(10,2) NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE T_ANALYSIS_2
|
||||
(
|
||||
COL_NAME VARCHAR(50) NOT NULL,
|
||||
COL_X FLOAT(10,2) NOT NULL,
|
||||
COL_Y FLOAT(10,2) NOT NULL
|
||||
);
|
||||
|
||||
/*
|
||||
truncate table t_auto_generated_keys;
|
||||
truncate table t_data_export;
|
||||
|
|
Loading…
Reference in New Issue