forked from p85126437/datagear
[analysis]图表数据集参数定义由ChartDefinition.dataSetParamValues改至ChartDataSet.paramValues,这样可以更灵活地针对图表的每个数据集单独定义参数
This commit is contained in:
parent
ed222e2ce5
commit
c057324642
|
@ -37,7 +37,6 @@ public class Chart extends ChartDefinition
|
|||
{
|
||||
super(chartDefinition.getId(), chartDefinition.getName(), chartDefinition.getChartDataSets());
|
||||
setChartParamValues(chartDefinition.getChartParamValues());
|
||||
setDataSetParamValues(chartDefinition.getDataSetParamValues());
|
||||
setUpdateInterval(chartDefinition.getUpdateInterval());
|
||||
|
||||
this.plugin = plugin;
|
||||
|
|
|
@ -7,13 +7,14 @@
|
|||
*/
|
||||
package org.datagear.analysis;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* 图表数据集。
|
||||
* <p>
|
||||
* 此类描述图表关联的某个{@linkplain DataSet}以及对其{@linkplain DataSet#getProperties()}设置的对应标记,这些标记通常是{@linkplain DataSign#getName()}。
|
||||
* 此类描述图表关联的某个{@linkplain DataSet}信息。
|
||||
* </p>
|
||||
*
|
||||
* @author datagear@163.com
|
||||
|
@ -24,8 +25,16 @@ public class ChartDataSet
|
|||
/** 数据集 */
|
||||
private DataSet dataSet;
|
||||
|
||||
/** 数据集属性-标记映射表 */
|
||||
private Map<String, Set<String>> propertySigns;
|
||||
/** 数据集属性标记映射表 */
|
||||
@SuppressWarnings("unchecked")
|
||||
private Map<String, Set<String>> propertySigns = Collections.EMPTY_MAP;
|
||||
|
||||
/** 数据集别名 */
|
||||
private String alias;
|
||||
|
||||
/** 数据集参数值映射表 */
|
||||
@SuppressWarnings("unchecked")
|
||||
private Map<String, Object> paramValues = Collections.EMPTY_MAP;
|
||||
|
||||
public ChartDataSet()
|
||||
{
|
||||
|
@ -48,11 +57,12 @@ public class ChartDataSet
|
|||
this.dataSet = dataSet;
|
||||
}
|
||||
|
||||
public boolean hasPropertySign()
|
||||
{
|
||||
return (this.propertySigns != null && !this.propertySigns.isEmpty());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取数据集属性标记映射表,其关键字是{@linkplain #getDataSet()}的{@linkplain DataSetProperty#getName()}、
|
||||
* 值则{@linkplain Chart#getPlugin()}的{@linkplain ChartPlugin#getDataSigns()}的{@linkplain DataSign#getName()}集合。
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Map<String, Set<String>> getPropertySigns()
|
||||
{
|
||||
return propertySigns;
|
||||
|
@ -62,4 +72,83 @@ public class ChartDataSet
|
|||
{
|
||||
this.propertySigns = propertySigns;
|
||||
}
|
||||
|
||||
public boolean hasAlias()
|
||||
{
|
||||
return (this.alias != null && !this.alias.isEmpty());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取数据集别名。
|
||||
* <p>
|
||||
* 一个图表可能多次包含同一个数据集,此别名可在图表展示时用于区分显示。
|
||||
* </p>
|
||||
*
|
||||
* @return 返回{@code null}或空表示无别名
|
||||
*/
|
||||
public String getAlias()
|
||||
{
|
||||
return alias;
|
||||
}
|
||||
|
||||
public void setAlias(String alias)
|
||||
{
|
||||
this.alias = alias;
|
||||
}
|
||||
|
||||
public Map<String, Object> getParamValues()
|
||||
{
|
||||
return paramValues;
|
||||
}
|
||||
|
||||
public void setParamValues(Map<String, Object> paramValues)
|
||||
{
|
||||
this.paramValues = paramValues;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@linkplain #getResult()}是否可用。
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public boolean isResultReady()
|
||||
{
|
||||
return this.dataSet.isReady(this.paramValues);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取{@linkplain #getDataSet()}的{@linkplain DataSetResult}。
|
||||
* </p>
|
||||
* 调用此方法前应该确保{@linkplain #isResultReady()}返回{@code true}。
|
||||
* </p>
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public DataSetResult getResult()
|
||||
{
|
||||
return this.dataSet.getResult(this.paramValues);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@linkplain #getResult(Map)}是否可用。
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public boolean isResultReady(Map<String, ?> paramValues)
|
||||
{
|
||||
return this.dataSet.isReady(paramValues);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取{@linkplain #getDataSet()}的{@linkplain DataSetResult}。
|
||||
* </p>
|
||||
* 调用此方法前应该确保{@linkplain #isResultReady(Map)}返回{@code true}。
|
||||
* </p>
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public DataSetResult getResult(Map<String, ?> paramValues)
|
||||
{
|
||||
return this.dataSet.getResult(paramValues);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
package org.datagear.analysis;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
|
@ -36,9 +37,6 @@ public class ChartDefinition extends AbstractIdentifiable
|
|||
/** 图表参数值映射表 */
|
||||
private Map<String, Object> chartParamValues = new HashMap<>();
|
||||
|
||||
/** 数据集参数值映射表 */
|
||||
private Map<String, Object> dataSetParamValues = new HashMap<>();
|
||||
|
||||
/** 图表更新间隔毫秒数 */
|
||||
private int updateInterval = -1;
|
||||
|
||||
|
@ -84,16 +82,6 @@ public class ChartDefinition extends AbstractIdentifiable
|
|||
this.chartParamValues = chartParamValues;
|
||||
}
|
||||
|
||||
public Map<String, Object> getDataSetParamValues()
|
||||
{
|
||||
return dataSetParamValues;
|
||||
}
|
||||
|
||||
public void setDataSetParamValues(Map<String, Object> dataSetParamValues)
|
||||
{
|
||||
this.dataSetParamValues = dataSetParamValues;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取图表更新间隔毫秒数。
|
||||
*
|
||||
|
@ -133,83 +121,28 @@ public class ChartDefinition extends AbstractIdentifiable
|
|||
}
|
||||
|
||||
/**
|
||||
* 获取图表数据集参数值。
|
||||
* 获取指定索引的默认{@linkplain DataSetResult}。
|
||||
*
|
||||
* @param name
|
||||
* @return
|
||||
* @param index
|
||||
* @return 如果{@linkplain ChartDataSet#isResultReady()}为{@code false},将返回{@code null}。
|
||||
* @throws DataSetException
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> T getDataSetParamValue(String name)
|
||||
public DataSetResult getDataSetResult(int index) throws DataSetException
|
||||
{
|
||||
return (T) this.dataSetParamValues.get(name);
|
||||
if (this.chartDataSets[index].isResultReady())
|
||||
return this.chartDataSets[index].getResult();
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置图表数据集参数值。
|
||||
* 获取默认{@linkplain DataSetResult}数组。
|
||||
*
|
||||
* @param name
|
||||
* @param value
|
||||
*/
|
||||
public void setDataSetParamValue(String name, Object value)
|
||||
{
|
||||
this.dataSetParamValues.put(name, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@linkplain #getDataSetParamValues()}是否满足执行{@linkplain #getDataSetResults()}。
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public boolean isReadyForDataSetResults()
|
||||
{
|
||||
return isReadyForDataSetResults(this.dataSetParamValues);
|
||||
}
|
||||
|
||||
/**
|
||||
* 给定参数集是否满足执行{@linkplain #getDataSetResults(Map)}。
|
||||
*
|
||||
* @param dataSetParamValues
|
||||
* @return
|
||||
*/
|
||||
public boolean isReadyForDataSetResults(Map<String, ?> dataSetParamValues)
|
||||
{
|
||||
if (this.chartDataSets == null || this.chartDataSets.length == 0)
|
||||
return true;
|
||||
|
||||
for (ChartDataSet chartDataSet : this.chartDataSets)
|
||||
{
|
||||
if (!chartDataSet.getDataSet().isReady(dataSetParamValues))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取此图表的所有{@linkplain DataSetResult}。
|
||||
* </p>
|
||||
* 调用此方法前应该确保{@linkplain #isReadyForDataSetResults()}返回{@code true}。
|
||||
* </p>
|
||||
*
|
||||
* @return
|
||||
* @return 如果{@linkplain #getChartDataSets()}指定索引的{@linkplain ChartDataSet#isResultReady()}为{@code false},
|
||||
* 返回数组对应元素将为{@code null}。
|
||||
* @throws DataSetException
|
||||
*/
|
||||
public DataSetResult[] getDataSetResults() throws DataSetException
|
||||
{
|
||||
return getDataSetResults(this.dataSetParamValues);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取此图表的所有{@linkplain DataSetResult}。
|
||||
* </p>
|
||||
* 调用此方法前应该确保{@linkplain #isReadyForDataSetResults(Map)}返回{@code true}。
|
||||
* </p>
|
||||
*
|
||||
* @param dataSetParamValues
|
||||
* @return
|
||||
* @throws DataSetException
|
||||
*/
|
||||
public DataSetResult[] getDataSetResults(Map<String, ?> dataSetParamValues) throws DataSetException
|
||||
{
|
||||
if (this.chartDataSets == null || this.chartDataSets.length == 0)
|
||||
return new DataSetResult[0];
|
||||
|
@ -217,7 +150,51 @@ public class ChartDefinition extends AbstractIdentifiable
|
|||
DataSetResult[] results = new DataSetResult[this.chartDataSets.length];
|
||||
|
||||
for (int i = 0; i < this.chartDataSets.length; i++)
|
||||
results[i] = this.chartDataSets[i].getDataSet().getResult(dataSetParamValues);
|
||||
results[i] = getDataSetResult(i);
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定索引和参数的{@linkplain DataSetResult}。
|
||||
*
|
||||
* @param index
|
||||
* @param dataSetParamValues 允许为{@code null}
|
||||
* @return 如果{@code dataSetParamValues}为{@code null},或者{@linkplain ChartDataSet#isResultReady(Map)}为{@code false},将返回{@code null}。
|
||||
* @throws DataSetException
|
||||
*/
|
||||
public DataSetResult getDataSetResult(int index, Map<String, ?> dataSetParamValues) throws DataSetException
|
||||
{
|
||||
if (dataSetParamValues == null)
|
||||
return null;
|
||||
else if (this.chartDataSets[index].isResultReady(dataSetParamValues))
|
||||
return this.chartDataSets[index].getResult(dataSetParamValues);
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定参数的{@linkplain DataSetResult}数组。
|
||||
*
|
||||
* @param dataSetParamValuess 允许为{@code null}
|
||||
* @return 如果{@code dataSetParamValuess}指定元素为{@code null},
|
||||
* 或者{@linkplain #getChartDataSets()}指定索引的{@linkplain ChartDataSet#isResultReady(Map)}为{@code false},返回数组对应元素将为{@code null}。
|
||||
* @throws DataSetException
|
||||
*/
|
||||
public DataSetResult[] getDataSetResults(List<? extends Map<String, ?>> dataSetParamValuess) throws DataSetException
|
||||
{
|
||||
if (this.chartDataSets == null || this.chartDataSets.length == 0)
|
||||
return new DataSetResult[0];
|
||||
|
||||
DataSetResult[] results = new DataSetResult[this.chartDataSets.length];
|
||||
|
||||
int pvSize = (dataSetParamValuess == null ? 0 : dataSetParamValuess.size());
|
||||
|
||||
for (int i = 0; i < this.chartDataSets.length; i++)
|
||||
{
|
||||
Map<String, ?> dataSetParamValues = (i >= pvSize ? null : dataSetParamValuess.get(i));
|
||||
results[i] = getDataSetResult(i, dataSetParamValues);
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
@ -240,7 +217,6 @@ public class ChartDefinition extends AbstractIdentifiable
|
|||
to.setName(from.name);
|
||||
to.setChartDataSets(from.chartDataSets);
|
||||
to.setChartParamValues(from.chartParamValues);
|
||||
to.setDataSetParamValues(from.dataSetParamValues);
|
||||
to.setUpdateInterval(from.updateInterval);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -99,28 +99,21 @@ public class Dashboard extends AbstractIdentifiable
|
|||
}
|
||||
|
||||
/**
|
||||
* 获取此看板所有无需参数的图表的数据集结果。
|
||||
* 获取此看板所有图表的默认数据集结果。
|
||||
*
|
||||
* @return
|
||||
* @return 返回映射表的值数组元素可能为{@code null},具体参考{@linkplain ChartDefinition#getDataSetResults()}
|
||||
* @throws DataSetException
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public Map<String, DataSetResult[]> getDataSetResults() throws DataSetException
|
||||
{
|
||||
if (this.charts == null || this.charts.isEmpty())
|
||||
return Collections.EMPTY_MAP;
|
||||
|
||||
Map<String, DataSetResult[]> resultsMap = new HashMap<>();
|
||||
|
||||
if (this.charts == null || this.charts.isEmpty())
|
||||
return resultsMap;
|
||||
|
||||
for (Chart chart : this.charts)
|
||||
{
|
||||
if (!chart.isReadyForDataSetResults())
|
||||
continue;
|
||||
|
||||
DataSetResult[] results = chart.getDataSetResults();
|
||||
|
||||
if (results != null)
|
||||
resultsMap.put(chart.getId(), results);
|
||||
}
|
||||
resultsMap.put(chart.getId(), chart.getDataSetResults());
|
||||
|
||||
return resultsMap;
|
||||
}
|
||||
|
@ -133,9 +126,8 @@ public class Dashboard extends AbstractIdentifiable
|
|||
* @return
|
||||
* @throws DataSetException
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public Map<String, DataSetResult[]> getDataSetResults(Set<String> chartIds,
|
||||
Map<String, Map<String, ?>> dataSetParamValuess) throws DataSetException
|
||||
Map<String, ? extends List<? extends Map<String, ?>>> dataSetParamValuess) throws DataSetException
|
||||
{
|
||||
Map<String, DataSetResult[]> resultsMap = new HashMap<>();
|
||||
|
||||
|
@ -147,9 +139,7 @@ public class Dashboard extends AbstractIdentifiable
|
|||
if (!chartIds.contains(chart.getId()))
|
||||
continue;
|
||||
|
||||
Map<String, ?> myParamValues = dataSetParamValuess.get(chart.getId());
|
||||
if (myParamValues == null)
|
||||
myParamValues = Collections.EMPTY_MAP;
|
||||
List<? extends Map<String, ?>> myParamValues = dataSetParamValuess.get(chart.getId());
|
||||
|
||||
DataSetResult[] results = chart.getDataSetResults(myParamValues);
|
||||
resultsMap.put(chart.getId(), results);
|
||||
|
|
|
@ -74,7 +74,7 @@ public interface DataSet extends Identifiable
|
|||
DataSetExport getExport(String name);
|
||||
|
||||
/**
|
||||
* 给定的参数映射表是否是为{@linkplain #getResult(Map)}准备好的。
|
||||
* 给定的参数映射表是否可用于{@linkplain #getResult(Map)}。
|
||||
*
|
||||
* @param paramValues
|
||||
* @return
|
||||
|
|
|
@ -7,11 +7,12 @@
|
|||
*/
|
||||
package org.datagear.analysis.support;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.datagear.analysis.DataSetResult;
|
||||
import org.datagear.analysis.DataSetException;
|
||||
import org.datagear.analysis.DataSetResult;
|
||||
|
||||
/**
|
||||
* 映射表{@linkplain DataSetResult}。
|
||||
|
@ -26,7 +27,8 @@ public class MapDataSetResult implements DataSetResult
|
|||
{
|
||||
private List<Map<String, ?>> datas;
|
||||
|
||||
private Map<String, ?> exportValues;
|
||||
@SuppressWarnings("unchecked")
|
||||
private Map<String, ?> exportValues = Collections.EMPTY_MAP;
|
||||
|
||||
public MapDataSetResult()
|
||||
{
|
||||
|
@ -60,11 +62,6 @@ public class MapDataSetResult implements DataSetResult
|
|||
return ((Map<String, Object>) data).get(name);
|
||||
}
|
||||
|
||||
public boolean hasExportValue()
|
||||
{
|
||||
return (this.exportValues != null && !this.exportValues.isEmpty());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, ?> getExportValues()
|
||||
{
|
||||
|
|
|
@ -68,7 +68,6 @@ public class SqlDataSetTest extends DBTestSupport
|
|||
|
||||
SqlDataSet sqlDataSet = new SqlDataSet("1", "1", dataSetProperties, connectionFactory, sql);
|
||||
sqlDataSet.setParams(dataSetParams);
|
||||
sqlDataSet.setSqlDataSetSqlResolver(new SqlDataSetFmkSqlResolver());
|
||||
|
||||
{
|
||||
Map<String, Object> dataSetParamValues = new HashMap<>();
|
||||
|
|
|
@ -344,11 +344,7 @@ public class HtmlChartWidgetEntityServiceImpl
|
|||
{
|
||||
ChartDataSet chartDataSet = chartDataSets[i];
|
||||
|
||||
String propertySignsJson = "";
|
||||
if (chartDataSet.hasPropertySign())
|
||||
{
|
||||
propertySignsJson = JsonSupport.generate(chartDataSet.getPropertySigns(), "");
|
||||
}
|
||||
String propertySignsJson = JsonSupport.generate(chartDataSet.getPropertySigns(), "");
|
||||
|
||||
WidgetDataSetRelation relation = new WidgetDataSetRelation(obj.getId(), chartDataSet.getDataSet().getId(),
|
||||
i + 1);
|
||||
|
|
|
@ -14,6 +14,7 @@ import java.util.Collections;
|
|||
import java.util.EnumSet;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
|
@ -142,7 +143,7 @@ public class AbstractDataAnalysisController extends AbstractController
|
|||
{
|
||||
String dashboardId = (String) dashboardParams.get(webContext.getDashboardIdParam());
|
||||
Collection<String> chartIds = (Collection<String>) dashboardParams.get(webContext.getChartIdsParam());
|
||||
Map<String, Map<String, ?>> chartsParamValues = (Map<String, Map<String, ?>>) dashboardParams
|
||||
Map<String, ? extends List<? extends Map<String, ?>>> chartsParamValues = (Map<String, ? extends List<? extends Map<String, ?>>>) dashboardParams
|
||||
.get(webContext.getChartsParamValuesParam());
|
||||
|
||||
if (StringUtil.isEmpty(dashboardId))
|
||||
|
|
|
@ -328,7 +328,12 @@
|
|||
for(var i=0; i<charts.length; i++)
|
||||
{
|
||||
chartIds[i] = charts[i].id;
|
||||
chartsParamValues[charts[i].id] = charts[i].paramValues();
|
||||
var chartDataSets = (charts[i].chartDataSets || []);
|
||||
var myParamValuess = [];
|
||||
for(var j=0; j<chartDataSets.length; j++)
|
||||
myParamValuess.push({});
|
||||
|
||||
chartsParamValues[charts[i].id] = myParamValuess;
|
||||
}
|
||||
|
||||
data[webContext.chartIdsParam] = chartIds;
|
||||
|
|
Loading…
Reference in New Issue