Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: chart CNMAP #732

Merged
merged 6 commits into from
Mar 16, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package com.rebuild.core.service.dashboard.charts;

import cn.devezhao.persist4j.Field;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.rebuild.core.DefinedException;
import com.rebuild.core.metadata.easymeta.DisplayType;
import com.rebuild.core.metadata.easymeta.EasyField;
import com.rebuild.core.metadata.easymeta.EasyMetaFactory;
import com.rebuild.utils.CommonsUtils;
import com.rebuild.utils.JSONUtils;
import org.apache.commons.lang.StringUtils;

import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.List;

/**
* 地图
*
* @author RB
* @since 3/16/2024
*/
public class CNMapChart extends ChartData {

protected CNMapChart(JSONObject config) {
super(config);
}

@Override
public JSON build() {
Dimension[] dims = getDimensions();
Dimension dim1 = dims[0];
Numerical[] nums = getNumericals();

Field locationOrDqClazz = dim1.getField();
EasyField easyField = EasyMetaFactory.valueOf(locationOrDqClazz);
if (easyField.getDisplayType() != DisplayType.LOCATION) {
throw new DefinedException("“地图”仅支持位置字段");
}

String sql = buildSql();
Object[][] array = createQuery(sql).setMaxResults(5000).array();

List<Object[]> datas = new ArrayList<>();
for (Object[] o : array) {
String map = (String) o[0];
if (StringUtils.isBlank(map)) continue;

String[] mapSplit = map.split(CommonsUtils.COMM_SPLITER_RE);
if (mapSplit.length != 2 || StringUtils.isBlank(mapSplit[1])) continue;

Object n = nums.length > 0 ? wrapAxisValue(nums[0], o[1]) : 0;
datas.add(new Object[]{mapSplit[0], mapSplit[1], n});
}

JSONObject renderOption = config.getJSONObject("option");

String numLabel = nums.length > 0 ? nums[0].getLabel() : null;

return JSONUtils.toJSONObject(
new String[]{"data", "name", "_renderOption"},
new Object[]{datas, numLabel, renderOption});
}

private String buildSql() {
Dimension[] dims = getDimensions();
Numerical[] nums = getNumericals();

if (nums.length > 0) {
return buildSql(dims[0], nums);
}

String sql = "select {0} from {1} where {2}";
sql = MessageFormat.format(sql,
dims[0].getSqlName(), getSourceEntity().getName(), getFilterSql());

return appendSqlSort(sql);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ public static ChartData create(JSONObject config, ID user) throws ChartsExceptio
return (ChartData) new ScatterChart(config).setUser(user);
} else if ("DATALIST2".equalsIgnoreCase(type)) {
return (ChartData) new DataList2Chart(config).setUser(user);
} else if ("CNMAP".equalsIgnoreCase(type)) {
return (ChartData) new CNMapChart(config).setUser(user);
} else {
for (BuiltinChart ch : getBuiltinCharts()) {
if (ch.getChartType().equalsIgnoreCase(type)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import java.util.Map;

/**
* 数据列表
* v36 数据列表
*
* @author devezhao
* @since 2/27/2024
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ private void putFields(List<String[]> dest, Entity entity, Field parent) {
|| dt == DisplayType.N2NREFERENCE
|| dt == DisplayType.TAG
|| dt == DisplayType.MULTISELECT
|| dt == DisplayType.LOCATION
|| dt == DisplayType.SIGN) {
continue;
}
Expand All @@ -147,6 +146,8 @@ private void putFields(List<String[]> dest, Entity entity, Field parent) {
type = "num";
} else if (dt == DisplayType.CLASSIFICATION) {
type = "clazz";
} else if (dt == DisplayType.LOCATION) {
type = "map";
}

dest.add(new String[]{
Expand Down
5 changes: 5 additions & 0 deletions src/main/resources/web/assets/css/chart-design.css
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,11 @@ a.ui-draggable.ui-draggable-dragging {
content: 'N';
}

.data-info .fields li.map a::before {
content: 'M';
color: #fbbc05;
}

.chart-type > a {
display: inline-block;
width: 40px;
Expand Down
5 changes: 5 additions & 0 deletions src/main/resources/web/assets/css/charts.css
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ See LICENSE and COMMERCIAL in the project root for license information.
.chart.ctable .table.line-number thead th:first-child,
.chart.ctable .table.line-number tbody th:first-child {
width: 50px;
color: #888;
}

.chart.ctable .table.sums tbody tr:last-child td {
Expand Down Expand Up @@ -581,3 +582,7 @@ See LICENSE and COMMERCIAL in the project root for license information.
border: 1px double #4285f4;
background-color: #f5f8fd;
}

.chart-box.CNMAP .chart-body {
margin-top: -5px;
}
16 changes: 14 additions & 2 deletions src/main/resources/web/assets/css/rb-page.css
Original file line number Diff line number Diff line change
Expand Up @@ -3854,13 +3854,25 @@ form {
display: block;
}

#asideWidgets .chart-box:hover .chart-oper a.J_source,
#asideWidgets .chart-box:hover .chart-oper a.J_fullscreen,
#asideWidgets .chart-box:hover .chart-oper a.J_chart-edit {
#asideWidgets .chart-box:hover .chart-oper a.J_chart-edit,
#asideWidgets .chart-box:hover .chart-oper a.J_export {
display: none !important;
}

#asideWidgets .charts-wrap > div {
margin-bottom: 25px;
margin-bottom: 20px;
}

#asideWidgets .charts-wrap > div.fullscreen {
position: fixed;
top: 60px !important;
left: 230px !important;
width: 100% !important;
height: 100% !important;
z-index: 9999;
background-color: #fff;
}

#asideWidgets .charts-wrap .ui-sortable-helper {
Expand Down
33 changes: 22 additions & 11 deletions src/main/resources/web/assets/js/charts/chart-design.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ $(document).ready(() => {
}

if (!wpc.chartId) {
$(`<h4 class="chart-undata must-center">${$L('当前图表无数据')}</h4>`).appendTo('#chart-preview')
render_preview_error($L('当前图表无数据'))
typeof window.startTour === 'function' && window.startTour(500)
}

Expand Down Expand Up @@ -372,7 +372,7 @@ const render_option = () => {

// Sort
const $sorts = $('.axis-editor .J_sort').removeClass('disabled')
if (ct === 'INDEX') {
if (['INDEX', 'CNMAP'].includes(ct)) {
$sorts.addClass('disabled')
} else if (ct === 'FUNNEL') {
if (numsAxis >= 1 && dimsAxis >= 1) $('.J_numerical .J_sort').addClass('disabled')
Expand All @@ -385,11 +385,11 @@ const render_option = () => {
// 生成预览
let render_preview_chart = null
const render_preview = (_color) => {
const $fs = $('a.J_filter > span:eq(1)')
const $filterLen = $('a.J_filter > span:eq(1)')
if (dataFilter && (dataFilter.items || []).length > 0) {
$fs.text(`(${dataFilter.items.length})`)
$filterLen.text(`(${dataFilter.items.length})`)
} else {
$fs.text('')
$filterLen.text('')
}

$setTimeout(
Expand All @@ -399,28 +399,39 @@ const render_preview = (_color) => {
render_preview_chart = null
}

const cfg = build_config()
if (!cfg) {
$('#chart-preview').html(`<h4 class="chart-undata must-center">${$L('当前图表无数据')}</h4>`)
const conf = build_config()
if (!conf) {
render_preview_error($L('当前图表无数据'))
return
}
if (cfg.option.useColor === '' && _color) cfg.option.useColor = _color

if (!(conf.type === 'CNMAP' || conf.type === 'DATALIST2')) {
if ($('.J_axis-dim span[data-type="map"]')[0]) {
render_preview_error($L('位置字段仅适用于“地图”图表'))
return
}
}

if (conf.option.useColor === '' && _color) conf.option.useColor = _color

$('#chart-preview').empty()
// eslint-disable-next-line no-undef
const c = detectChart(cfg)
const c = detectChart(conf)
if (c) {
renderRbcomp(c, 'chart-preview', function () {
render_preview_chart = this
})
} else {
$('#chart-preview').html(`<h4 class="chart-undata must-center">${$L('不支持的图表类型')}</h4>`)
render_preview_error($L('不支持的图表类型'))
}
},
400,
'chart-preview'
)
}
const render_preview_error = (err) => {
$('#chart-preview').html(`<h4 class="chart-undata must-center">${err}</h4>`)
}

// 构造配置
const build_config = () => {
Expand Down
Loading
Loading