提交 91157367 authored 作者: junjie's avatar junjie

feat: 散点图、气泡图

上级 9ec5e808
...@@ -15,6 +15,8 @@ public class ChartViewWithBLOBs extends ChartView implements Serializable { ...@@ -15,6 +15,8 @@ public class ChartViewWithBLOBs extends ChartView implements Serializable {
private String extStack; private String extStack;
private String extBubble;
private String customAttr; private String customAttr;
private String customStyle; private String customStyle;
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
<result column="x_axis" jdbcType="LONGVARCHAR" property="xAxis" /> <result column="x_axis" jdbcType="LONGVARCHAR" property="xAxis" />
<result column="y_axis" jdbcType="LONGVARCHAR" property="yAxis" /> <result column="y_axis" jdbcType="LONGVARCHAR" property="yAxis" />
<result column="ext_stack" jdbcType="LONGVARCHAR" property="extStack" /> <result column="ext_stack" jdbcType="LONGVARCHAR" property="extStack" />
<result column="ext_bubble" jdbcType="LONGVARCHAR" property="extBubble" />
<result column="custom_attr" jdbcType="LONGVARCHAR" property="customAttr" /> <result column="custom_attr" jdbcType="LONGVARCHAR" property="customAttr" />
<result column="custom_style" jdbcType="LONGVARCHAR" property="customStyle" /> <result column="custom_style" jdbcType="LONGVARCHAR" property="customStyle" />
<result column="custom_filter" jdbcType="LONGVARCHAR" property="customFilter" /> <result column="custom_filter" jdbcType="LONGVARCHAR" property="customFilter" />
...@@ -86,8 +87,8 @@ ...@@ -86,8 +87,8 @@
style_priority style_priority
</sql> </sql>
<sql id="Blob_Column_List"> <sql id="Blob_Column_List">
x_axis, y_axis, ext_stack, custom_attr, custom_style, custom_filter, drill_fields, x_axis, y_axis, ext_stack, ext_bubble, custom_attr, custom_style, custom_filter,
snapshot drill_fields, snapshot
</sql> </sql>
<select id="selectByExampleWithBLOBs" parameterType="io.dataease.base.domain.ChartViewExample" resultMap="ResultMapWithBLOBs"> <select id="selectByExampleWithBLOBs" parameterType="io.dataease.base.domain.ChartViewExample" resultMap="ResultMapWithBLOBs">
select select
...@@ -142,16 +143,16 @@ ...@@ -142,16 +143,16 @@
table_id, `type`, title, table_id, `type`, title,
create_by, create_time, update_time, create_by, create_time, update_time,
style_priority, x_axis, y_axis, style_priority, x_axis, y_axis,
ext_stack, custom_attr, custom_style, ext_stack, ext_bubble, custom_attr,
custom_filter, drill_fields, snapshot custom_style, custom_filter, drill_fields,
) snapshot)
values (#{id,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, #{sceneId,jdbcType=VARCHAR}, values (#{id,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, #{sceneId,jdbcType=VARCHAR},
#{tableId,jdbcType=VARCHAR}, #{type,jdbcType=VARCHAR}, #{title,jdbcType=VARCHAR}, #{tableId,jdbcType=VARCHAR}, #{type,jdbcType=VARCHAR}, #{title,jdbcType=VARCHAR},
#{createBy,jdbcType=VARCHAR}, #{createTime,jdbcType=BIGINT}, #{updateTime,jdbcType=BIGINT}, #{createBy,jdbcType=VARCHAR}, #{createTime,jdbcType=BIGINT}, #{updateTime,jdbcType=BIGINT},
#{stylePriority,jdbcType=VARCHAR}, #{xAxis,jdbcType=LONGVARCHAR}, #{yAxis,jdbcType=LONGVARCHAR}, #{stylePriority,jdbcType=VARCHAR}, #{xAxis,jdbcType=LONGVARCHAR}, #{yAxis,jdbcType=LONGVARCHAR},
#{extStack,jdbcType=LONGVARCHAR}, #{customAttr,jdbcType=LONGVARCHAR}, #{customStyle,jdbcType=LONGVARCHAR}, #{extStack,jdbcType=LONGVARCHAR}, #{extBubble,jdbcType=LONGVARCHAR}, #{customAttr,jdbcType=LONGVARCHAR},
#{customFilter,jdbcType=LONGVARCHAR}, #{drillFields,jdbcType=LONGVARCHAR}, #{snapshot,jdbcType=LONGVARCHAR} #{customStyle,jdbcType=LONGVARCHAR}, #{customFilter,jdbcType=LONGVARCHAR}, #{drillFields,jdbcType=LONGVARCHAR},
) #{snapshot,jdbcType=LONGVARCHAR})
</insert> </insert>
<insert id="insertSelective" parameterType="io.dataease.base.domain.ChartViewWithBLOBs"> <insert id="insertSelective" parameterType="io.dataease.base.domain.ChartViewWithBLOBs">
insert into chart_view insert into chart_view
...@@ -195,6 +196,9 @@ ...@@ -195,6 +196,9 @@
<if test="extStack != null"> <if test="extStack != null">
ext_stack, ext_stack,
</if> </if>
<if test="extBubble != null">
ext_bubble,
</if>
<if test="customAttr != null"> <if test="customAttr != null">
custom_attr, custom_attr,
</if> </if>
...@@ -251,6 +255,9 @@ ...@@ -251,6 +255,9 @@
<if test="extStack != null"> <if test="extStack != null">
#{extStack,jdbcType=LONGVARCHAR}, #{extStack,jdbcType=LONGVARCHAR},
</if> </if>
<if test="extBubble != null">
#{extBubble,jdbcType=LONGVARCHAR},
</if>
<if test="customAttr != null"> <if test="customAttr != null">
#{customAttr,jdbcType=LONGVARCHAR}, #{customAttr,jdbcType=LONGVARCHAR},
</if> </if>
...@@ -316,6 +323,9 @@ ...@@ -316,6 +323,9 @@
<if test="record.extStack != null"> <if test="record.extStack != null">
ext_stack = #{record.extStack,jdbcType=LONGVARCHAR}, ext_stack = #{record.extStack,jdbcType=LONGVARCHAR},
</if> </if>
<if test="record.extBubble != null">
ext_bubble = #{record.extBubble,jdbcType=LONGVARCHAR},
</if>
<if test="record.customAttr != null"> <if test="record.customAttr != null">
custom_attr = #{record.customAttr,jdbcType=LONGVARCHAR}, custom_attr = #{record.customAttr,jdbcType=LONGVARCHAR},
</if> </if>
...@@ -351,6 +361,7 @@ ...@@ -351,6 +361,7 @@
x_axis = #{record.xAxis,jdbcType=LONGVARCHAR}, x_axis = #{record.xAxis,jdbcType=LONGVARCHAR},
y_axis = #{record.yAxis,jdbcType=LONGVARCHAR}, y_axis = #{record.yAxis,jdbcType=LONGVARCHAR},
ext_stack = #{record.extStack,jdbcType=LONGVARCHAR}, ext_stack = #{record.extStack,jdbcType=LONGVARCHAR},
ext_bubble = #{record.extBubble,jdbcType=LONGVARCHAR},
custom_attr = #{record.customAttr,jdbcType=LONGVARCHAR}, custom_attr = #{record.customAttr,jdbcType=LONGVARCHAR},
custom_style = #{record.customStyle,jdbcType=LONGVARCHAR}, custom_style = #{record.customStyle,jdbcType=LONGVARCHAR},
custom_filter = #{record.customFilter,jdbcType=LONGVARCHAR}, custom_filter = #{record.customFilter,jdbcType=LONGVARCHAR},
...@@ -415,6 +426,9 @@ ...@@ -415,6 +426,9 @@
<if test="extStack != null"> <if test="extStack != null">
ext_stack = #{extStack,jdbcType=LONGVARCHAR}, ext_stack = #{extStack,jdbcType=LONGVARCHAR},
</if> </if>
<if test="extBubble != null">
ext_bubble = #{extBubble,jdbcType=LONGVARCHAR},
</if>
<if test="customAttr != null"> <if test="customAttr != null">
custom_attr = #{customAttr,jdbcType=LONGVARCHAR}, custom_attr = #{customAttr,jdbcType=LONGVARCHAR},
</if> </if>
...@@ -447,6 +461,7 @@ ...@@ -447,6 +461,7 @@
x_axis = #{xAxis,jdbcType=LONGVARCHAR}, x_axis = #{xAxis,jdbcType=LONGVARCHAR},
y_axis = #{yAxis,jdbcType=LONGVARCHAR}, y_axis = #{yAxis,jdbcType=LONGVARCHAR},
ext_stack = #{extStack,jdbcType=LONGVARCHAR}, ext_stack = #{extStack,jdbcType=LONGVARCHAR},
ext_bubble = #{extBubble,jdbcType=LONGVARCHAR},
custom_attr = #{customAttr,jdbcType=LONGVARCHAR}, custom_attr = #{customAttr,jdbcType=LONGVARCHAR},
custom_style = #{customStyle,jdbcType=LONGVARCHAR}, custom_style = #{customStyle,jdbcType=LONGVARCHAR},
custom_filter = #{customFilter,jdbcType=LONGVARCHAR}, custom_filter = #{customFilter,jdbcType=LONGVARCHAR},
......
...@@ -15,5 +15,5 @@ import java.util.List; ...@@ -15,5 +15,5 @@ import java.util.List;
public class Series { public class Series {
private String name; private String name;
private String type; private String type;
private List<BigDecimal> data; private List<Object> data;
} }
...@@ -40,6 +40,10 @@ public abstract class QueryProvider { ...@@ -40,6 +40,10 @@ public abstract class QueryProvider {
public abstract String getSQLAsTmpStack(String table, List<ChartViewFieldDTO> xAxis, List<ChartViewFieldDTO> yAxis, List<ChartCustomFilterDTO> customFilter, List<ChartExtFilterRequest> extFilterRequestList, List<ChartViewFieldDTO> extStack); public abstract String getSQLAsTmpStack(String table, List<ChartViewFieldDTO> xAxis, List<ChartViewFieldDTO> yAxis, List<ChartCustomFilterDTO> customFilter, List<ChartExtFilterRequest> extFilterRequestList, List<ChartViewFieldDTO> extStack);
public abstract String getSQLScatter(String table, List<ChartViewFieldDTO> xAxis, List<ChartViewFieldDTO> yAxis, List<ChartCustomFilterDTO> customFilter, List<ChartExtFilterRequest> extFilterRequestList, List<ChartViewFieldDTO> extBubble);
public abstract String getSQLAsTmpScatter(String table, List<ChartViewFieldDTO> xAxis, List<ChartViewFieldDTO> yAxis, List<ChartCustomFilterDTO> customFilter, List<ChartExtFilterRequest> extFilterRequestList, List<ChartViewFieldDTO> extBubble);
public abstract String searchTable(String table); public abstract String searchTable(String table);
public abstract String getSQLSummary(String table, List<ChartViewFieldDTO> yAxis, List<ChartCustomFilterDTO> customFilter, List<ChartExtFilterRequest> extFilterRequestList); public abstract String getSQLSummary(String table, List<ChartViewFieldDTO> yAxis, List<ChartCustomFilterDTO> customFilter, List<ChartExtFilterRequest> extFilterRequestList);
......
...@@ -407,6 +407,120 @@ public class DorisQueryProvider extends QueryProvider { ...@@ -407,6 +407,120 @@ public class DorisQueryProvider extends QueryProvider {
return getSQLStack("(" + table + ")", xAxis, yAxis, customFilter, extFilterRequestList, extStack); return getSQLStack("(" + table + ")", xAxis, yAxis, customFilter, extFilterRequestList, extStack);
} }
@Override
public String getSQLScatter(String table, List<ChartViewFieldDTO> xAxis, List<ChartViewFieldDTO> yAxis, List<ChartCustomFilterDTO> customFilter, List<ChartExtFilterRequest> extFilterRequestList, List<ChartViewFieldDTO> extBubble) {
SQLObj tableObj = SQLObj.builder()
.tableName((table.startsWith("(") && table.endsWith(")")) ? table : String.format(DorisConstants.KEYWORD_TABLE, table))
.tableAlias(String.format(TABLE_ALIAS_PREFIX, 0))
.build();
List<SQLObj> xFields = new ArrayList<>();
List<SQLObj> xWheres = new ArrayList<>();
List<SQLObj> xOrders = new ArrayList<>();
if (CollectionUtils.isNotEmpty(xAxis)) {
for (int i = 0; i < xAxis.size(); i++) {
ChartViewFieldDTO x = xAxis.get(i);
String originField;
if (ObjectUtils.isNotEmpty(x.getExtField()) && x.getExtField() == 2) {
// 解析origin name中有关联的字段生成sql表达式
originField = calcFieldRegex(x.getOriginName(), tableObj);
} else if (ObjectUtils.isNotEmpty(x.getExtField()) && x.getExtField() == 1) {
originField = String.format(DorisConstants.KEYWORD_FIX, tableObj.getTableAlias(), x.getDataeaseName());
} else {
originField = String.format(DorisConstants.KEYWORD_FIX, tableObj.getTableAlias(), x.getDataeaseName());
}
String fieldAlias = String.format(SQLConstants.FIELD_ALIAS_X_PREFIX, i);
// 处理横轴字段
xFields.add(getXFields(x, originField, fieldAlias));
// 处理横轴过滤
// xWheres.addAll(getXWheres(x, originField, fieldAlias));
// 处理横轴排序
if (StringUtils.isNotEmpty(x.getSort()) && !StringUtils.equalsIgnoreCase(x.getSort(), "none")) {
xOrders.add(SQLObj.builder()
.orderField(originField)
.orderAlias(fieldAlias)
.orderDirection(x.getSort())
.build());
}
}
}
List<SQLObj> yFields = new ArrayList<>();
List<SQLObj> yWheres = new ArrayList<>();
List<SQLObj> yOrders = new ArrayList<>();
List<ChartViewFieldDTO> yList = new ArrayList<>();
yList.addAll(yAxis);
yList.addAll(extBubble);
if (CollectionUtils.isNotEmpty(yList)) {
for (int i = 0; i < yList.size(); i++) {
ChartViewFieldDTO y = yList.get(i);
String originField;
if (ObjectUtils.isNotEmpty(y.getExtField()) && y.getExtField() == 2) {
// 解析origin name中有关联的字段生成sql表达式
originField = calcFieldRegex(y.getOriginName(), tableObj);
} else if (ObjectUtils.isNotEmpty(y.getExtField()) && y.getExtField() == 1) {
originField = String.format(DorisConstants.KEYWORD_FIX, tableObj.getTableAlias(), y.getDataeaseName());
} else {
originField = String.format(DorisConstants.KEYWORD_FIX, tableObj.getTableAlias(), y.getDataeaseName());
}
String fieldAlias = String.format(SQLConstants.FIELD_ALIAS_Y_PREFIX, i);
// 处理纵轴字段
yFields.add(getYFields(y, originField, fieldAlias));
// 处理纵轴过滤
yWheres.addAll(getYWheres(y, originField, fieldAlias));
// 处理纵轴排序
if (StringUtils.isNotEmpty(y.getSort()) && !StringUtils.equalsIgnoreCase(y.getSort(), "none")) {
yOrders.add(SQLObj.builder()
.orderField(originField)
.orderAlias(fieldAlias)
.orderDirection(y.getSort())
.build());
}
}
}
// 处理视图中字段过滤
List<SQLObj> customWheres = transCustomFilterList(tableObj, customFilter);
// 处理仪表板字段过滤
List<SQLObj> extWheres = transExtFilterList(tableObj, extFilterRequestList);
// 构建sql所有参数
List<SQLObj> fields = new ArrayList<>();
fields.addAll(xFields);
fields.addAll(yFields);
List<SQLObj> wheres = new ArrayList<>();
wheres.addAll(xWheres);
if (customWheres != null) wheres.addAll(customWheres);
if (extWheres != null) wheres.addAll(extWheres);
List<SQLObj> groups = new ArrayList<>();
groups.addAll(xFields);
// 外层再次套sql
List<SQLObj> orders = new ArrayList<>();
orders.addAll(xOrders);
orders.addAll(yOrders);
List<SQLObj> aggWheres = new ArrayList<>();
aggWheres.addAll(yWheres);
STGroup stg = new STGroupFile(SQLConstants.SQL_TEMPLATE);
ST st_sql = stg.getInstanceOf("querySql");
if (CollectionUtils.isNotEmpty(xFields)) st_sql.add("groups", xFields);
if (CollectionUtils.isNotEmpty(yFields)) st_sql.add("aggregators", yFields);
if (CollectionUtils.isNotEmpty(wheres)) st_sql.add("filters", wheres);
if (ObjectUtils.isNotEmpty(tableObj)) st_sql.add("table", tableObj);
String sql = st_sql.render();
ST st = stg.getInstanceOf("querySql");
SQLObj tableSQL = SQLObj.builder()
.tableName(String.format(DorisConstants.BRACKETS, sql))
.tableAlias(String.format(TABLE_ALIAS_PREFIX, 1))
.build();
if (CollectionUtils.isNotEmpty(aggWheres)) st.add("filters", aggWheres);
if (CollectionUtils.isNotEmpty(orders)) st.add("orders", orders);
if (ObjectUtils.isNotEmpty(tableSQL)) st.add("table", tableSQL);
return st.render();
}
@Override
public String getSQLAsTmpScatter(String table, List<ChartViewFieldDTO> xAxis, List<ChartViewFieldDTO> yAxis, List<ChartCustomFilterDTO> customFilter, List<ChartExtFilterRequest> extFilterRequestList, List<ChartViewFieldDTO> extBubble) {
return getSQLScatter("(" + table + ")", xAxis, yAxis, customFilter, extFilterRequestList, extBubble);
}
@Override @Override
public String searchTable(String table) { public String searchTable(String table) {
return "SELECT table_name FROM information_schema.TABLES WHERE table_name ='" + table + "'"; return "SELECT table_name FROM information_schema.TABLES WHERE table_name ='" + table + "'";
......
...@@ -354,29 +354,116 @@ public class MysqlQueryProvider extends QueryProvider { ...@@ -354,29 +354,116 @@ public class MysqlQueryProvider extends QueryProvider {
} }
} }
} }
List<SQLObj> stackFields = new ArrayList<>(); // 处理视图中字段过滤
List<SQLObj> stackOrders = new ArrayList<>(); List<SQLObj> customWheres = transCustomFilterList(tableObj, customFilter);
if (CollectionUtils.isNotEmpty(extStack)) { // 处理仪表板字段过滤
for (int i = 0; i < extStack.size(); i++) { List<SQLObj> extWheres = transExtFilterList(tableObj, extFilterRequestList);
ChartViewFieldDTO stack = extStack.get(i); // 构建sql所有参数
List<SQLObj> fields = new ArrayList<>();
fields.addAll(xFields);
fields.addAll(yFields);
List<SQLObj> wheres = new ArrayList<>();
wheres.addAll(xWheres);
if (customWheres != null) wheres.addAll(customWheres);
if (extWheres != null) wheres.addAll(extWheres);
List<SQLObj> groups = new ArrayList<>();
groups.addAll(xFields);
// 外层再次套sql
List<SQLObj> orders = new ArrayList<>();
orders.addAll(xOrders);
orders.addAll(yOrders);
List<SQLObj> aggWheres = new ArrayList<>();
aggWheres.addAll(yWheres);
STGroup stg = new STGroupFile(SQLConstants.SQL_TEMPLATE);
ST st_sql = stg.getInstanceOf("querySql");
if (CollectionUtils.isNotEmpty(xFields)) st_sql.add("groups", xFields);
if (CollectionUtils.isNotEmpty(yFields)) st_sql.add("aggregators", yFields);
if (CollectionUtils.isNotEmpty(wheres)) st_sql.add("filters", wheres);
if (ObjectUtils.isNotEmpty(tableObj)) st_sql.add("table", tableObj);
String sql = st_sql.render();
ST st = stg.getInstanceOf("querySql");
SQLObj tableSQL = SQLObj.builder()
.tableName(String.format(MySQLConstants.BRACKETS, sql))
.tableAlias(String.format(TABLE_ALIAS_PREFIX, 1))
.build();
if (CollectionUtils.isNotEmpty(aggWheres)) st.add("filters", aggWheres);
if (CollectionUtils.isNotEmpty(orders)) st.add("orders", orders);
if (ObjectUtils.isNotEmpty(tableSQL)) st.add("table", tableSQL);
return st.render();
}
@Override
public String getSQLAsTmpStack(String table, List<ChartViewFieldDTO> xAxis, List<ChartViewFieldDTO> yAxis, List<ChartCustomFilterDTO> customFilter, List<ChartExtFilterRequest> extFilterRequestList, List<ChartViewFieldDTO> extStack) {
return getSQLStack("(" + sqlFix(table) + ")", xAxis, yAxis, customFilter, extFilterRequestList, extStack);
}
@Override
public String getSQLScatter(String table, List<ChartViewFieldDTO> xAxis, List<ChartViewFieldDTO> yAxis, List<ChartCustomFilterDTO> customFilter, List<ChartExtFilterRequest> extFilterRequestList, List<ChartViewFieldDTO> extBubble) {
SQLObj tableObj = SQLObj.builder()
.tableName((table.startsWith("(") && table.endsWith(")")) ? table : String.format(MySQLConstants.KEYWORD_TABLE, table))
.tableAlias(String.format(TABLE_ALIAS_PREFIX, 0))
.build();
List<SQLObj> xFields = new ArrayList<>();
List<SQLObj> xWheres = new ArrayList<>();
List<SQLObj> xOrders = new ArrayList<>();
if (CollectionUtils.isNotEmpty(xAxis)) {
for (int i = 0; i < xAxis.size(); i++) {
ChartViewFieldDTO x = xAxis.get(i);
String originField; String originField;
if (ObjectUtils.isNotEmpty(stack.getExtField()) && stack.getExtField() == 2) { if (ObjectUtils.isNotEmpty(x.getExtField()) && x.getExtField() == 2) {
// 解析origin name中有关联的字段生成sql表达式 // 解析origin name中有关联的字段生成sql表达式
originField = calcFieldRegex(stack.getOriginName(), tableObj); originField = calcFieldRegex(x.getOriginName(), tableObj);
} else if (ObjectUtils.isNotEmpty(stack.getExtField()) && stack.getExtField() == 1) { } else if (ObjectUtils.isNotEmpty(x.getExtField()) && x.getExtField() == 1) {
originField = String.format(MySQLConstants.KEYWORD_FIX, tableObj.getTableAlias(), stack.getOriginName()); originField = String.format(MySQLConstants.KEYWORD_FIX, tableObj.getTableAlias(), x.getOriginName());
} else { } else {
originField = String.format(MySQLConstants.KEYWORD_FIX, tableObj.getTableAlias(), stack.getOriginName()); originField = String.format(MySQLConstants.KEYWORD_FIX, tableObj.getTableAlias(), x.getOriginName());
} }
String fieldAlias = String.format(SQLConstants.FIELD_ALIAS_X_PREFIX, i); String fieldAlias = String.format(SQLConstants.FIELD_ALIAS_X_PREFIX, i);
// 处理横轴字段 // 处理横轴字段
stackFields.add(getXFields(stack, originField, fieldAlias)); xFields.add(getXFields(x, originField, fieldAlias));
// 处理横轴过滤
// xWheres.addAll(getXWheres(x, originField, fieldAlias));
// 处理横轴排序 // 处理横轴排序
if (StringUtils.isNotEmpty(stack.getSort()) && !StringUtils.equalsIgnoreCase(stack.getSort(), "none")) { if (StringUtils.isNotEmpty(x.getSort()) && !StringUtils.equalsIgnoreCase(x.getSort(), "none")) {
stackOrders.add(SQLObj.builder() xOrders.add(SQLObj.builder()
.orderField(originField)
.orderAlias(fieldAlias)
.orderDirection(x.getSort())
.build());
}
}
}
List<SQLObj> yFields = new ArrayList<>();
List<SQLObj> yWheres = new ArrayList<>();
List<SQLObj> yOrders = new ArrayList<>();
List<ChartViewFieldDTO> yList = new ArrayList<>();
yList.addAll(yAxis);
yList.addAll(extBubble);
if (CollectionUtils.isNotEmpty(yList)) {
for (int i = 0; i < yList.size(); i++) {
ChartViewFieldDTO y = yList.get(i);
String originField;
if (ObjectUtils.isNotEmpty(y.getExtField()) && y.getExtField() == 2) {
// 解析origin name中有关联的字段生成sql表达式
originField = calcFieldRegex(y.getOriginName(), tableObj);
} else if (ObjectUtils.isNotEmpty(y.getExtField()) && y.getExtField() == 1) {
originField = String.format(MySQLConstants.KEYWORD_FIX, tableObj.getTableAlias(), y.getOriginName());
} else {
originField = String.format(MySQLConstants.KEYWORD_FIX, tableObj.getTableAlias(), y.getOriginName());
}
String fieldAlias = String.format(SQLConstants.FIELD_ALIAS_Y_PREFIX, i);
// 处理纵轴字段
yFields.add(getYFields(y, originField, fieldAlias));
// 处理纵轴过滤
yWheres.addAll(getYWheres(y, originField, fieldAlias));
// 处理纵轴排序
if (StringUtils.isNotEmpty(y.getSort()) && !StringUtils.equalsIgnoreCase(y.getSort(), "none")) {
yOrders.add(SQLObj.builder()
.orderField(originField) .orderField(originField)
.orderAlias(fieldAlias) .orderAlias(fieldAlias)
.orderDirection(stack.getSort()) .orderDirection(y.getSort())
.build()); .build());
} }
} }
...@@ -422,8 +509,8 @@ public class MysqlQueryProvider extends QueryProvider { ...@@ -422,8 +509,8 @@ public class MysqlQueryProvider extends QueryProvider {
} }
@Override @Override
public String getSQLAsTmpStack(String table, List<ChartViewFieldDTO> xAxis, List<ChartViewFieldDTO> yAxis, List<ChartCustomFilterDTO> customFilter, List<ChartExtFilterRequest> extFilterRequestList, List<ChartViewFieldDTO> extStack) { public String getSQLAsTmpScatter(String table, List<ChartViewFieldDTO> xAxis, List<ChartViewFieldDTO> yAxis, List<ChartCustomFilterDTO> customFilter, List<ChartExtFilterRequest> extFilterRequestList, List<ChartViewFieldDTO> extBubble) {
return getSQLStack("(" + sqlFix(table) + ")", xAxis, yAxis, customFilter, extFilterRequestList, extStack); return getSQLScatter("(" + sqlFix(table) + ")", xAxis, yAxis, customFilter, extFilterRequestList, extBubble);
} }
@Override @Override
......
...@@ -432,6 +432,120 @@ public class OracleQueryProvider extends QueryProvider { ...@@ -432,6 +432,120 @@ public class OracleQueryProvider extends QueryProvider {
return getSQLStack("(" + sqlFix(table) + ")", xAxis, yAxis, customFilter, extFilterRequestList, extStack); return getSQLStack("(" + sqlFix(table) + ")", xAxis, yAxis, customFilter, extFilterRequestList, extStack);
} }
@Override
public String getSQLScatter(String table, List<ChartViewFieldDTO> xAxis, List<ChartViewFieldDTO> yAxis, List<ChartCustomFilterDTO> customFilter, List<ChartExtFilterRequest> extFilterRequestList, List<ChartViewFieldDTO> extBubble) {
SQLObj tableObj = SQLObj.builder()
.tableName((table.startsWith("(") && table.endsWith(")")) ? table : String.format(OracleConstants.KEYWORD_TABLE, table))
.tableAlias(String.format(OracleConstants.ALIAS_FIX, String.format(TABLE_ALIAS_PREFIX, 0)))
.build();
List<SQLObj> xFields = new ArrayList<>();
List<SQLObj> xWheres = new ArrayList<>();
List<SQLObj> xOrders = new ArrayList<>();
if (CollectionUtils.isNotEmpty(xAxis)) {
for (int i = 0; i < xAxis.size(); i++) {
ChartViewFieldDTO x = xAxis.get(i);
String originField;
if (ObjectUtils.isNotEmpty(x.getExtField()) && x.getExtField() == 2) {
// 解析origin name中有关联的字段生成sql表达式
originField = calcFieldRegex(x.getOriginName(), tableObj);
} else if (ObjectUtils.isNotEmpty(x.getExtField()) && x.getExtField() == 1) {
originField = String.format(OracleConstants.KEYWORD_FIX, tableObj.getTableAlias(), x.getOriginName());
} else {
originField = String.format(OracleConstants.KEYWORD_FIX, tableObj.getTableAlias(), x.getOriginName());
}
String fieldAlias = String.format(OracleConstants.ALIAS_FIX, String.format(SQLConstants.FIELD_ALIAS_X_PREFIX, i));
// 处理横轴字段
xFields.add(getXFields(x, originField, fieldAlias));
// 处理横轴过滤
// xWheres.addAll(getXWheres(x, originField, fieldAlias));
// 处理横轴排序
if (StringUtils.isNotEmpty(x.getSort()) && !StringUtils.equalsIgnoreCase(x.getSort(), "none")) {
xOrders.add(SQLObj.builder()
.orderField(originField)
.orderAlias(fieldAlias)
.orderDirection(x.getSort())
.build());
}
}
}
List<SQLObj> yFields = new ArrayList<>();
List<SQLObj> yWheres = new ArrayList<>();
List<SQLObj> yOrders = new ArrayList<>();
List<ChartViewFieldDTO> yList = new ArrayList<>();
yList.addAll(yAxis);
yList.addAll(extBubble);
if (CollectionUtils.isNotEmpty(yList)) {
for (int i = 0; i < yList.size(); i++) {
ChartViewFieldDTO y = yList.get(i);
String originField;
if (ObjectUtils.isNotEmpty(y.getExtField()) && y.getExtField() == 2) {
// 解析origin name中有关联的字段生成sql表达式
originField = calcFieldRegex(y.getOriginName(), tableObj);
} else if (ObjectUtils.isNotEmpty(y.getExtField()) && y.getExtField() == 1) {
originField = String.format(OracleConstants.KEYWORD_FIX, tableObj.getTableAlias(), y.getOriginName());
} else {
originField = String.format(OracleConstants.KEYWORD_FIX, tableObj.getTableAlias(), y.getOriginName());
}
String fieldAlias = String.format(OracleConstants.ALIAS_FIX, String.format(SQLConstants.FIELD_ALIAS_Y_PREFIX, i));
// 处理纵轴字段
yFields.add(getYFields(y, originField, fieldAlias));
// 处理纵轴过滤
yWheres.addAll(getYWheres(y, originField, fieldAlias));
// 处理纵轴排序
if (StringUtils.isNotEmpty(y.getSort()) && !StringUtils.equalsIgnoreCase(y.getSort(), "none")) {
yOrders.add(SQLObj.builder()
.orderField(originField)
.orderAlias(fieldAlias)
.orderDirection(y.getSort())
.build());
}
}
}
// 处理视图中字段过滤
List<SQLObj> customWheres = transCustomFilterList(tableObj, customFilter);
// 处理仪表板字段过滤
List<SQLObj> extWheres = transExtFilterList(tableObj, extFilterRequestList);
// 构建sql所有参数
List<SQLObj> fields = new ArrayList<>();
fields.addAll(xFields);
fields.addAll(yFields);
List<SQLObj> wheres = new ArrayList<>();
wheres.addAll(xWheres);
if (customWheres != null) wheres.addAll(customWheres);
if (extWheres != null) wheres.addAll(extWheres);
List<SQLObj> groups = new ArrayList<>();
groups.addAll(xFields);
// 外层再次套sql
List<SQLObj> orders = new ArrayList<>();
orders.addAll(xOrders);
orders.addAll(yOrders);
List<SQLObj> aggWheres = new ArrayList<>();
aggWheres.addAll(yWheres);
STGroup stg = new STGroupFile(SQLConstants.SQL_TEMPLATE);
ST st_sql = stg.getInstanceOf("querySql");
if (CollectionUtils.isNotEmpty(xFields)) st_sql.add("groups", xFields);
if (CollectionUtils.isNotEmpty(yFields)) st_sql.add("aggregators", yFields);
if (CollectionUtils.isNotEmpty(wheres)) st_sql.add("filters", wheres);
if (ObjectUtils.isNotEmpty(tableObj)) st_sql.add("table", tableObj);
String sql = st_sql.render();
ST st = stg.getInstanceOf("querySql");
SQLObj tableSQL = SQLObj.builder()
.tableName(String.format(OracleConstants.BRACKETS, sql))
.tableAlias(String.format(TABLE_ALIAS_PREFIX, 1))
.build();
if (CollectionUtils.isNotEmpty(aggWheres)) st.add("filters", aggWheres);
if (CollectionUtils.isNotEmpty(orders)) st.add("orders", orders);
if (ObjectUtils.isNotEmpty(tableSQL)) st.add("table", tableSQL);
return st.render();
}
@Override
public String getSQLAsTmpScatter(String table, List<ChartViewFieldDTO> xAxis, List<ChartViewFieldDTO> yAxis, List<ChartCustomFilterDTO> customFilter, List<ChartExtFilterRequest> extFilterRequestList, List<ChartViewFieldDTO> extBubble) {
return getSQLScatter("(" + sqlFix(table) + ")", xAxis, yAxis, customFilter, extFilterRequestList, extBubble);
}
@Override @Override
public String searchTable(String table) { public String searchTable(String table) {
return "SELECT table_name FROM information_schema.TABLES WHERE table_name ='" + table + "'"; return "SELECT table_name FROM information_schema.TABLES WHERE table_name ='" + table + "'";
......
...@@ -193,6 +193,8 @@ public class ChartViewService { ...@@ -193,6 +193,8 @@ public class ChartViewService {
}.getType()); }.getType());
List<ChartViewFieldDTO> extStack = new Gson().fromJson(view.getExtStack(), new TypeToken<List<ChartViewFieldDTO>>() { List<ChartViewFieldDTO> extStack = new Gson().fromJson(view.getExtStack(), new TypeToken<List<ChartViewFieldDTO>>() {
}.getType()); }.getType());
List<ChartViewFieldDTO> extBubble = new Gson().fromJson(view.getExtBubble(), new TypeToken<List<ChartViewFieldDTO>>() {
}.getType());
List<ChartFieldCustomFilterDTO> fieldCustomFilter = new Gson().fromJson(view.getCustomFilter(), new TypeToken<List<ChartFieldCustomFilterDTO>>() { List<ChartFieldCustomFilterDTO> fieldCustomFilter = new Gson().fromJson(view.getCustomFilter(), new TypeToken<List<ChartFieldCustomFilterDTO>>() {
}.getType()); }.getType());
List<ChartCustomFilterDTO> customFilter = new ArrayList<>(); List<ChartCustomFilterDTO> customFilter = new ArrayList<>();
...@@ -262,6 +264,8 @@ public class ChartViewService { ...@@ -262,6 +264,8 @@ public class ChartViewService {
datasourceRequest.setQuery(qp.getSQLSummary(dataTableInfoDTO.getTable(), yAxis, customFilter, extFilterList)); datasourceRequest.setQuery(qp.getSQLSummary(dataTableInfoDTO.getTable(), yAxis, customFilter, extFilterList));
} else if (StringUtils.containsIgnoreCase(view.getType(), "stack")) { } else if (StringUtils.containsIgnoreCase(view.getType(), "stack")) {
datasourceRequest.setQuery(qp.getSQLStack(dataTableInfoDTO.getTable(), xAxis, yAxis, customFilter, extFilterList, extStack)); datasourceRequest.setQuery(qp.getSQLStack(dataTableInfoDTO.getTable(), xAxis, yAxis, customFilter, extFilterList, extStack));
} else if (StringUtils.containsIgnoreCase(view.getType(), "scatter")) {
datasourceRequest.setQuery(qp.getSQLScatter(dataTableInfoDTO.getTable(), xAxis, yAxis, customFilter, extFilterList, extBubble));
} else { } else {
datasourceRequest.setQuery(qp.getSQL(dataTableInfoDTO.getTable(), xAxis, yAxis, customFilter, extFilterList)); datasourceRequest.setQuery(qp.getSQL(dataTableInfoDTO.getTable(), xAxis, yAxis, customFilter, extFilterList));
} }
...@@ -270,6 +274,8 @@ public class ChartViewService { ...@@ -270,6 +274,8 @@ public class ChartViewService {
datasourceRequest.setQuery(qp.getSQLSummaryAsTmp(dataTableInfoDTO.getSql(), yAxis, customFilter, extFilterList)); datasourceRequest.setQuery(qp.getSQLSummaryAsTmp(dataTableInfoDTO.getSql(), yAxis, customFilter, extFilterList));
} else if (StringUtils.containsIgnoreCase(view.getType(), "stack")) { } else if (StringUtils.containsIgnoreCase(view.getType(), "stack")) {
datasourceRequest.setQuery(qp.getSQLAsTmpStack(dataTableInfoDTO.getSql(), xAxis, yAxis, customFilter, extFilterList, extStack)); datasourceRequest.setQuery(qp.getSQLAsTmpStack(dataTableInfoDTO.getSql(), xAxis, yAxis, customFilter, extFilterList, extStack));
} else if (StringUtils.containsIgnoreCase(view.getType(), "scatter")) {
datasourceRequest.setQuery(qp.getSQLAsTmpScatter(dataTableInfoDTO.getSql(), xAxis, yAxis, customFilter, extFilterList, extBubble));
} else { } else {
datasourceRequest.setQuery(qp.getSQLAsTmp(dataTableInfoDTO.getSql(), xAxis, yAxis, customFilter, extFilterList)); datasourceRequest.setQuery(qp.getSQLAsTmp(dataTableInfoDTO.getSql(), xAxis, yAxis, customFilter, extFilterList));
} }
...@@ -281,6 +287,8 @@ public class ChartViewService { ...@@ -281,6 +287,8 @@ public class ChartViewService {
datasourceRequest.setQuery(qp.getSQLSummaryAsTmp(sql, yAxis, customFilter, extFilterList)); datasourceRequest.setQuery(qp.getSQLSummaryAsTmp(sql, yAxis, customFilter, extFilterList));
} else if (StringUtils.containsIgnoreCase(view.getType(), "stack")) { } else if (StringUtils.containsIgnoreCase(view.getType(), "stack")) {
datasourceRequest.setQuery(qp.getSQLAsTmpStack(sql, xAxis, yAxis, customFilter, extFilterList, extStack)); datasourceRequest.setQuery(qp.getSQLAsTmpStack(sql, xAxis, yAxis, customFilter, extFilterList, extStack));
} else if (StringUtils.containsIgnoreCase(view.getType(), "scatter")) {
datasourceRequest.setQuery(qp.getSQLAsTmpScatter(sql, xAxis, yAxis, customFilter, extFilterList, extBubble));
} else { } else {
datasourceRequest.setQuery(qp.getSQLAsTmp(sql, xAxis, yAxis, customFilter, extFilterList)); datasourceRequest.setQuery(qp.getSQLAsTmp(sql, xAxis, yAxis, customFilter, extFilterList));
} }
...@@ -309,6 +317,8 @@ public class ChartViewService { ...@@ -309,6 +317,8 @@ public class ChartViewService {
datasourceRequest.setQuery(qp.getSQLSummary(tableName, yAxis, customFilter, extFilterList)); datasourceRequest.setQuery(qp.getSQLSummary(tableName, yAxis, customFilter, extFilterList));
} else if (StringUtils.containsIgnoreCase(view.getType(), "stack")) { } else if (StringUtils.containsIgnoreCase(view.getType(), "stack")) {
datasourceRequest.setQuery(qp.getSQLStack(tableName, xAxis, yAxis, customFilter, extFilterList, extStack)); datasourceRequest.setQuery(qp.getSQLStack(tableName, xAxis, yAxis, customFilter, extFilterList, extStack));
} else if (StringUtils.containsIgnoreCase(view.getType(), "scatter")) {
datasourceRequest.setQuery(qp.getSQLScatter(tableName, xAxis, yAxis, customFilter, extFilterList, extBubble));
} else { } else {
datasourceRequest.setQuery(qp.getSQL(tableName, xAxis, yAxis, customFilter, extFilterList)); datasourceRequest.setQuery(qp.getSQL(tableName, xAxis, yAxis, customFilter, extFilterList));
} }
...@@ -353,6 +363,8 @@ public class ChartViewService { ...@@ -353,6 +363,8 @@ public class ChartViewService {
Map<String, Object> mapChart; Map<String, Object> mapChart;
if (StringUtils.containsIgnoreCase(view.getType(), "stack")) { if (StringUtils.containsIgnoreCase(view.getType(), "stack")) {
mapChart = transStackChartData(xAxis, yAxis, view, data, extStack); mapChart = transStackChartData(xAxis, yAxis, view, data, extStack);
} else if (StringUtils.containsIgnoreCase(view.getType(), "scatter")) {
mapChart = transScatterData(xAxis, yAxis, view, data, extBubble);
} else { } else {
mapChart = transChartData(xAxis, yAxis, view, data); mapChart = transChartData(xAxis, yAxis, view, data);
} }
...@@ -405,6 +417,7 @@ public class ChartViewService { ...@@ -405,6 +417,7 @@ public class ChartViewService {
return result; return result;
} }
// 基础图形
private Map<String, Object> transChartData(List<ChartViewFieldDTO> xAxis, List<ChartViewFieldDTO> yAxis, ChartViewWithBLOBs view, List<String[]> data) { private Map<String, Object> transChartData(List<ChartViewFieldDTO> xAxis, List<ChartViewFieldDTO> yAxis, ChartViewWithBLOBs view, List<String[]> data) {
Map<String, Object> map = new HashMap<>(); Map<String, Object> map = new HashMap<>();
...@@ -442,6 +455,7 @@ public class ChartViewService { ...@@ -442,6 +455,7 @@ public class ChartViewService {
return map; return map;
} }
// 堆叠图
private Map<String, Object> transStackChartData(List<ChartViewFieldDTO> xAxis, List<ChartViewFieldDTO> yAxis, ChartViewWithBLOBs view, List<String[]> data, List<ChartViewFieldDTO> extStack) { private Map<String, Object> transStackChartData(List<ChartViewFieldDTO> xAxis, List<ChartViewFieldDTO> yAxis, ChartViewWithBLOBs view, List<String[]> data, List<ChartViewFieldDTO> extStack) {
Map<String, Object> map = new HashMap<>(); Map<String, Object> map = new HashMap<>();
...@@ -473,7 +487,7 @@ public class ChartViewService { ...@@ -473,7 +487,7 @@ public class ChartViewService {
Series series1 = new Series(); Series series1 = new Series();
series1.setName(s); series1.setName(s);
series1.setType(view.getType()); series1.setType(view.getType());
List<BigDecimal> list = new ArrayList<>(); List<Object> list = new ArrayList<>();
for (int i = 0; i < x.size(); i++) { for (int i = 0; i < x.size(); i++) {
list.add(defaultValue); list.add(defaultValue);
} }
...@@ -540,6 +554,60 @@ public class ChartViewService { ...@@ -540,6 +554,60 @@ public class ChartViewService {
return map; return map;
} }
// 散点图
private Map<String, Object> transScatterData(List<ChartViewFieldDTO> xAxis, List<ChartViewFieldDTO> yAxis, ChartViewWithBLOBs view, List<String[]> data, List<ChartViewFieldDTO> extBubble) {
Map<String, Object> map = new HashMap<>();
List<String> x = new ArrayList<>();
List<Series> series = new ArrayList<>();
for (ChartViewFieldDTO y : yAxis) {
Series series1 = new Series();
series1.setName(y.getName());
series1.setType(view.getType());
series1.setData(new ArrayList<>());
series.add(series1);
}
for (String[] d : data) {
StringBuilder a = new StringBuilder();
for (int i = 0; i < xAxis.size(); i++) {
if (i == xAxis.size() - 1) {
a.append(d[i]);
} else {
a.append(d[i]).append("\n");
}
}
x.add(a.toString());
for (int i = xAxis.size(); i < xAxis.size() + yAxis.size(); i++) {
int j = i - xAxis.size();
if (CollectionUtils.isNotEmpty(extBubble) && extBubble.size() > 0) {
try {
series.get(j).getData().add(new Object[]{
a.toString(),
new BigDecimal(StringUtils.isEmpty(d[i]) ? "0" : d[i]),
new BigDecimal(StringUtils.isEmpty(d[xAxis.size() + yAxis.size()]) ? "0" : d[xAxis.size() + yAxis.size()])
});
} catch (Exception e) {
series.get(j).getData().add(new Object[]{a.toString(), new BigDecimal(0), new BigDecimal(0)});
}
} else {
try {
series.get(j).getData().add(new Object[]{
a.toString(),
new BigDecimal(StringUtils.isEmpty(d[i]) ? "0" : d[i])
});
} catch (Exception e) {
series.get(j).getData().add(new Object[]{a.toString(), new BigDecimal(0)});
}
}
}
}
map.put("x", x);
map.put("series", series);
return map;
}
// 表格
private Map<String, Object> transTableNormal(List<ChartViewFieldDTO> xAxis, List<ChartViewFieldDTO> yAxis, ChartViewWithBLOBs view, List<String[]> data, List<ChartViewFieldDTO> extStack) { private Map<String, Object> transTableNormal(List<ChartViewFieldDTO> xAxis, List<ChartViewFieldDTO> yAxis, ChartViewWithBLOBs view, List<String[]> data, List<ChartViewFieldDTO> extStack) {
Map<String, Object> map = new TreeMap<>(); Map<String, Object> map = new TreeMap<>();
List<ChartViewFieldDTO> fields = new ArrayList<>(); List<ChartViewFieldDTO> fields = new ArrayList<>();
......
ALTER TABLE `chart_view` ADD COLUMN `ext_stack` LONGTEXT COMMENT '堆叠项' AFTER `y_axis`; ALTER TABLE `chart_view` ADD COLUMN `ext_stack` LONGTEXT COMMENT '堆叠项' AFTER `y_axis`;
UPDATE `chart_view` SET `ext_stack` = '[]'; UPDATE `chart_view` SET `ext_stack` = '[]';
ALTER TABLE `chart_view` ADD COLUMN `ext_bubble` LONGTEXT COMMENT '气泡大小' AFTER `ext_stack`;
UPDATE `chart_view` SET `ext_bubble` = '[]';
ALTER TABLE `dataset_table_field` MODIFY COLUMN `origin_name` LONGTEXT; ALTER TABLE `dataset_table_field` MODIFY COLUMN `origin_name` LONGTEXT;
......
...@@ -64,7 +64,7 @@ ...@@ -64,7 +64,7 @@
<!--要生成的数据库表 --> <!--要生成的数据库表 -->
<!-- <table tableName="sys_dict"/>--> <table tableName="chart_view"/>
<!-- <table tableName="sys_dict_item"/>--> <!-- <table tableName="sys_dict_item"/>-->
<!-- <table tableName="dataset_table_field"/>--> <!-- <table tableName="dataset_table_field"/>-->
<!-- <table tableName="v_chart">--> <!-- <table tableName="v_chart">-->
......
...@@ -828,7 +828,10 @@ export default { ...@@ -828,7 +828,10 @@ export default {
select_map_range: 'Please select map range', select_map_range: 'Please select map range',
area: 'Area', area: 'Area',
placeholder_field: 'Drag Field To Here', placeholder_field: 'Drag Field To Here',
axis_label_rotate: 'Label Rotate' axis_label_rotate: 'Label Rotate',
chart_scatter_bubble: 'Bubble',
chart_scatter: 'Scatter',
bubble_size: 'Bubble Size'
}, },
dataset: { dataset: {
sheet_warn: 'There are multiple sheet pages, and the first one is extracted by default', sheet_warn: 'There are multiple sheet pages, and the first one is extracted by default',
......
...@@ -828,7 +828,10 @@ export default { ...@@ -828,7 +828,10 @@ export default {
area: '地區', area: '地區',
stack_item: '堆疊項', stack_item: '堆疊項',
placeholder_field: '拖動字段至此處', placeholder_field: '拖動字段至此處',
axis_label_rotate: '標簽角度' axis_label_rotate: '標簽角度',
chart_scatter_bubble: '氣泡圖',
chart_scatter: '散點圖',
bubble_size: '氣泡大小'
}, },
dataset: { dataset: {
sheet_warn: '有多個sheet頁面,默認抽取第一個', sheet_warn: '有多個sheet頁面,默認抽取第一個',
......
...@@ -828,7 +828,10 @@ export default { ...@@ -828,7 +828,10 @@ export default {
area: '地区', area: '地区',
stack_item: '堆叠项', stack_item: '堆叠项',
placeholder_field: '拖动字段至此处', placeholder_field: '拖动字段至此处',
axis_label_rotate: '标签角度' axis_label_rotate: '标签角度',
chart_scatter_bubble: '气泡图',
chart_scatter: '散点图',
bubble_size: '气泡大小'
}, },
dataset: { dataset: {
sheet_warn: '有多个 Sheet 页,默认抽取第一个', sheet_warn: '有多个 Sheet 页,默认抽取第一个',
......
...@@ -37,7 +37,9 @@ export const DEFAULT_SIZE = { ...@@ -37,7 +37,9 @@ export const DEFAULT_SIZE = {
quotaFontSize: 18, quotaFontSize: 18,
spaceSplit: 10, spaceSplit: 10,
dimensionShow: true, dimensionShow: true,
quotaShow: true quotaShow: true,
scatterSymbol: 'circle',
scatterSymbolSize: 20
} }
export const DEFAULT_LABEL = { export const DEFAULT_LABEL = {
show: false, show: false,
...@@ -630,3 +632,61 @@ export const BASE_MAP = { ...@@ -630,3 +632,61 @@ export const BASE_MAP = {
} }
] ]
} }
export const BASE_SCATTER = {
title: {
text: '',
textStyle: {
fontWeight: 'normal'
}
},
grid: {
containLabel: true
},
tooltip: {},
legend: {
show: true,
type: 'scroll',
itemWidth: 10,
itemHeight: 10,
icon: 'rect',
data: []
},
xAxis: {
boundaryGap: false,
data: []
},
yAxis: {
type: 'value'
},
series: [],
dataZoom: [
{
type: 'slider',
show: false,
xAxisIndex: [0],
start: 0,
end: 100
},
{
type: 'slider',
show: false,
yAxisIndex: [0],
left: '93%',
start: 0,
end: 100
},
{
type: 'inside',
xAxisIndex: [0],
start: 0,
end: 100
},
{
type: 'inside',
yAxisIndex: [0],
start: 0,
end: 100
}
]
}
import { hexColorToRGBA } from '@/views/chart/chart/util'
import { componentStyle } from '../common/common'
export function baseScatterOption(chart_option, chart) {
// 处理shape attr
let customAttr = {}
if (chart.customAttr) {
customAttr = JSON.parse(chart.customAttr)
if (customAttr.color) {
chart_option.color = customAttr.color.colors
}
// tooltip
if (customAttr.tooltip) {
const tooltip = JSON.parse(JSON.stringify(customAttr.tooltip))
const reg = new RegExp('\n', 'g')
tooltip.formatter = tooltip.formatter.replace(reg, '<br/>')
chart_option.tooltip = tooltip
}
}
// 处理data
if (chart.data) {
chart_option.title.text = chart.title
chart_option.xAxis.data = chart.data.x
for (let i = 0; i < chart.data.series.length; i++) {
const y = chart.data.series[i]
// color
y.itemStyle = {
color: hexColorToRGBA(customAttr.color.colors[i % 9], customAttr.color.alpha)
}
// size
if (customAttr.size) {
y.symbol = customAttr.size.scatterSymbol ? customAttr.size.scatterSymbol : 'circle'
const extBubble = JSON.parse(chart.extBubble)
if (extBubble && extBubble.length > 0) {
y.symbolSize = funcSize
} else {
y.symbolSize = customAttr.size.scatterSymbolSize ? customAttr.size.scatterSymbolSize : 20
}
}
// label
if (customAttr.label) {
y.label = customAttr.label
}
y.type = 'scatter'
chart_option.legend.data.push(y.name)
chart_option.series.push(y)
}
}
// console.log(chart_option);
componentStyle(chart_option, chart)
return chart_option
}
const funcSize = function(data) {
return data[2]
}
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
</template> </template>
<script> <script>
import { BASE_BAR, BASE_LINE, HORIZONTAL_BAR, BASE_PIE, BASE_FUNNEL, BASE_RADAR, BASE_GAUGE, BASE_MAP } from '../chart/chart' import { BASE_BAR, BASE_LINE, HORIZONTAL_BAR, BASE_PIE, BASE_FUNNEL, BASE_RADAR, BASE_GAUGE, BASE_MAP, BASE_SCATTER } from '../chart/chart'
import { baseBarOption, stackBarOption, horizontalBarOption, horizontalStackBarOption } from '../chart/bar/bar' import { baseBarOption, stackBarOption, horizontalBarOption, horizontalStackBarOption } from '../chart/bar/bar'
import { baseLineOption, stackLineOption } from '../chart/line/line' import { baseLineOption, stackLineOption } from '../chart/line/line'
import { basePieOption, rosePieOption } from '../chart/pie/pie' import { basePieOption, rosePieOption } from '../chart/pie/pie'
...@@ -13,6 +13,7 @@ import { baseMapOption } from '../chart/map/map' ...@@ -13,6 +13,7 @@ import { baseMapOption } from '../chart/map/map'
import { baseFunnelOption } from '../chart/funnel/funnel' import { baseFunnelOption } from '../chart/funnel/funnel'
import { baseRadarOption } from '../chart/radar/radar' import { baseRadarOption } from '../chart/radar/radar'
import { baseGaugeOption } from '../chart/gauge/gauge' import { baseGaugeOption } from '../chart/gauge/gauge'
import { baseScatterOption } from '../chart/scatter/scatter'
// import eventBus from '@/components/canvas/utils/eventBus' // import eventBus from '@/components/canvas/utils/eventBus'
import { uuid } from 'vue-uuid' import { uuid } from 'vue-uuid'
import { geoJson } from '@/api/map/map' import { geoJson } from '@/api/map/map'
...@@ -95,6 +96,8 @@ export default { ...@@ -95,6 +96,8 @@ export default {
chart_option = baseRadarOption(JSON.parse(JSON.stringify(BASE_RADAR)), chart) chart_option = baseRadarOption(JSON.parse(JSON.stringify(BASE_RADAR)), chart)
} else if (chart.type === 'gauge') { } else if (chart.type === 'gauge') {
chart_option = baseGaugeOption(JSON.parse(JSON.stringify(BASE_GAUGE)), chart) chart_option = baseGaugeOption(JSON.parse(JSON.stringify(BASE_GAUGE)), chart)
} else if (chart.type === 'scatter') {
chart_option = baseScatterOption(JSON.parse(JSON.stringify(BASE_SCATTER)), chart)
} }
if (chart.type === 'map') { if (chart.type === 'map') {
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
<svg-icon v-if="item.sort === 'desc'" icon-class="sort-desc" class-name="field-icon-sort" /> <svg-icon v-if="item.sort === 'desc'" icon-class="sort-desc" class-name="field-icon-sort" />
</span> </span>
<span class="item-span-style" :title="item.name">{{ item.name }}</span> <span class="item-span-style" :title="item.name">{{ item.name }}</span>
<span v-if="item.summary" class="summary-span">{{ $t('chart.'+item.summary) }}</span>
</el-tag> </el-tag>
<el-dropdown v-else trigger="click" size="mini" @command="clickItem"> <el-dropdown v-else trigger="click" size="mini" @command="clickItem">
<span class="el-dropdown-link"> <span class="el-dropdown-link">
...@@ -23,10 +24,32 @@ ...@@ -23,10 +24,32 @@
<svg-icon v-if="item.sort === 'desc'" icon-class="sort-desc" class-name="field-icon-sort" /> <svg-icon v-if="item.sort === 'desc'" icon-class="sort-desc" class-name="field-icon-sort" />
</span> </span>
<span class="item-span-style" :title="item.name">{{ item.name }}</span> <span class="item-span-style" :title="item.name">{{ item.name }}</span>
<span v-if="item.summary" class="summary-span">{{ $t('chart.'+item.summary) }}</span>
<i class="el-icon-arrow-down el-icon--right" style="position: absolute;top: 6px;right: 10px;" /> <i class="el-icon-arrow-down el-icon--right" style="position: absolute;top: 6px;right: 10px;" />
</el-tag> </el-tag>
<el-dropdown-menu slot="dropdown"> <el-dropdown-menu slot="dropdown">
<el-dropdown-item> <el-dropdown-item v-show="conf && conf.includes('summary')">
<el-dropdown placement="right-start" size="mini" style="width: 100%" @command="summary">
<span class="el-dropdown-link inner-dropdown-menu">
<span>
<i class="el-icon-notebook-2" />
<span>{{ $t('chart.summary') }}</span>
<span class="summary-span-item">({{ $t('chart.'+item.summary) }})</span>
</span>
<i class="el-icon-arrow-right el-icon--right" />
</span>
<el-dropdown-menu slot="dropdown">
<el-dropdown-item v-if="item.id === 'count' || item.deType === 0 || item.deType === 1" :command="beforeSummary('count')">{{ $t('chart.count') }}</el-dropdown-item>
<el-dropdown-item v-if="item.id !== 'count' && item.deType !== 0 && item.deType !== 1" :command="beforeSummary('sum')">{{ $t('chart.sum') }}</el-dropdown-item>
<el-dropdown-item v-if="item.id !== 'count' && item.deType !== 0 && item.deType !== 1" :command="beforeSummary('avg')">{{ $t('chart.avg') }}</el-dropdown-item>
<el-dropdown-item v-if="item.id !== 'count' && item.deType !== 0 && item.deType !== 1" :command="beforeSummary('max')">{{ $t('chart.max') }}</el-dropdown-item>
<el-dropdown-item v-if="item.id !== 'count' && item.deType !== 0 && item.deType !== 1" :command="beforeSummary('min')">{{ $t('chart.min') }}</el-dropdown-item>
<el-dropdown-item v-if="item.id !== 'count' && item.deType !== 0 && item.deType !== 1" :command="beforeSummary('stddev_pop')">{{ $t('chart.stddev_pop') }}</el-dropdown-item>
<el-dropdown-item v-if="item.id !== 'count' && item.deType !== 0 && item.deType !== 1" :command="beforeSummary('var_pop')">{{ $t('chart.var_pop') }}</el-dropdown-item>
</el-dropdown-menu>
</el-dropdown>
</el-dropdown-item>
<el-dropdown-item v-show="conf && conf.includes('sort')">
<el-dropdown placement="right-start" size="mini" style="width: 100%" @command="sort"> <el-dropdown placement="right-start" size="mini" style="width: 100%" @command="sort">
<span class="el-dropdown-link inner-dropdown-menu"> <span class="el-dropdown-link inner-dropdown-menu">
<span> <span>
...@@ -67,6 +90,10 @@ export default { ...@@ -67,6 +90,10 @@ export default {
index: { index: {
type: Number, type: Number,
required: true required: true
},
conf: {
type: String,
required: true
} }
}, },
data() { data() {
...@@ -103,6 +130,16 @@ export default { ...@@ -103,6 +130,16 @@ export default {
type: type type: type
} }
}, },
summary(param) {
// console.log(param)
this.item.summary = param.type
this.$emit('onItemChange', this.item)
},
beforeSummary(type) {
return {
type: type
}
},
removeItem() { removeItem() {
this.item.index = this.index this.item.index = this.index
this.$emit('onItemRemove', this.item) this.$emit('onItemRemove', this.item)
...@@ -153,4 +190,16 @@ export default { ...@@ -153,4 +190,16 @@ export default {
text-overflow: ellipsis; text-overflow: ellipsis;
overflow: hidden; overflow: hidden;
} }
.summary-span-item{
margin-left: 4px;
color: #878d9f;
}
.summary-span{
margin-left: 4px;
color: #878d9f;
position: absolute;
right: 30px;
}
</style> </style>
...@@ -135,6 +135,22 @@ ...@@ -135,6 +135,22 @@
<el-input-number v-model="sizeForm.spaceSplit" size="mini" @change="changeBarSizeCase" /> <el-input-number v-model="sizeForm.spaceSplit" size="mini" @change="changeBarSizeCase" />
</el-form-item> </el-form-item>
</el-form> </el-form>
<el-form v-show="chart.type && chart.type.includes('scatter')" ref="sizeFormLine" :disabled="param && !hasDataPermission('manage',param.privileges)" :model="sizeForm" label-width="80px" size="mini">
<el-form-item :label="$t('chart.line_symbol')" class="form-item">
<el-select v-model="sizeForm.scatterSymbol" :placeholder="$t('chart.line_symbol')" @change="changeBarSizeCase">
<el-option
v-for="item in lineSymbolOptions"
:key="item.value"
:label="item.name"
:value="item.value"
/>
</el-select>
</el-form-item>
<el-form-item :label="$t('chart.line_symbol_size')" class="form-item form-item-slider">
<el-slider v-model="sizeForm.scatterSymbolSize" show-input :show-input-controls="false" input-size="mini" :min="0" :max="20" @change="changeBarSizeCase" />
</el-form-item>
</el-form>
</el-col> </el-col>
<!-- <el-popover--> <!-- <el-popover-->
<!-- placement="right"--> <!-- placement="right"-->
......
...@@ -747,6 +747,7 @@ export default { ...@@ -747,6 +747,7 @@ export default {
view.extStack = JSON.stringify([]) view.extStack = JSON.stringify([])
view.customFilter = JSON.stringify([]) view.customFilter = JSON.stringify([])
view.drillFields = JSON.stringify([]) view.drillFields = JSON.stringify([])
view.extBubble = JSON.stringify([])
post('/chart/view/save', view).then(response => { post('/chart/view/save', view).then(response => {
this.closeCreateChart() this.closeCreateChart()
this.$store.dispatch('chart/setTableId', null) this.$store.dispatch('chart/setTableId', null)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论