|
|
|
package com.finebi.plugin.custom.component;
|
|
|
|
|
|
|
|
import com.finebi.common.context.OperationContext;
|
|
|
|
import com.finebi.provider.api.component.AbstractCustomComponentProvider;
|
|
|
|
import com.finebi.provider.api.component.CustomComponentContext;
|
|
|
|
import com.finebi.provider.api.component.DataModel;
|
|
|
|
import com.fr.general.IOUtils;
|
|
|
|
import com.fr.plugin.transform.ExecuteFunctionRecord;
|
|
|
|
import com.fr.plugin.transform.FunctionRecorder;
|
|
|
|
import com.fr.web.struct.AssembleComponent;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
@FunctionRecorder
|
|
|
|
public class DemoComponentProvider extends AbstractCustomComponentProvider {
|
|
|
|
/**
|
|
|
|
* 自定义图表名称
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public String getName() {
|
|
|
|
return "自定义图表demo";
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 自定义图表类型
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public String getType() {
|
|
|
|
return "demo";
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 自定义图表 icon
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public String getIcon() {
|
|
|
|
return "http://webapi.amap.com/theme/v1.3/mapinfo_05.png";
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 空自定义图表提示,不写默认取 icon
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public String getPreviewIcon() {
|
|
|
|
return "http://webapi.amap.com/theme/v1.3/mapinfo_05.png";
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 自定义图表预览 dom,注入依赖文件和挂载节点,可以获取 context
|
|
|
|
* @param context 上下文
|
|
|
|
*/
|
|
|
|
@ExecuteFunctionRecord
|
|
|
|
@Override
|
|
|
|
public String getPreviewPageHTML(OperationContext context) {
|
|
|
|
return "<link rel=\"stylesheet\" type=\"text/css\" href=\"https://fanruan.design/fineui/2.0/fineui.min.css\" />" +
|
|
|
|
"<script src=\"https://fanruan.design/fineui/2.0/fineui.min.js\"></script>" +
|
|
|
|
"<div>context: </div>" + context.getSystemInfo() + context.getUserInfo() +
|
|
|
|
"<div id=\"container\">这是预览</div>";
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 自定义图表编辑 dom,不写默认取预览
|
|
|
|
* @param context 上下文
|
|
|
|
*/
|
|
|
|
@ExecuteFunctionRecord
|
|
|
|
@Override
|
|
|
|
public String getEditPageHTML(OperationContext context) {
|
|
|
|
return "<link rel=\"stylesheet\" type=\"text/css\" href=\"https://fanruan.design/fineui/2.0/fineui.min.css\" />" +
|
|
|
|
"<script src=\"https://fanruan.design/fineui/2.0/fineui.min.js\"></script>" +
|
|
|
|
"<div>context: </div>" + context.getSystemInfo().getServletURL() + context.getUserInfo().getDisplayName() +
|
|
|
|
"<div id=\"container\">这是编辑</div>";
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 自定义图表渲染 js、css 注入
|
|
|
|
* @param context 上下文
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public AssembleComponent previewClient(OperationContext context) {
|
|
|
|
return CustomComponent.KEY;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 自定义图表配置文件
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public String config() {
|
|
|
|
return IOUtils.readResourceAsString("com/finebi/plugin/custom/component/config.json");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 返回是否需要进行自定义数据处理
|
|
|
|
*
|
|
|
|
* @param customComponentContext 自定义图表相关的上下文信息,目前包含前端传的查询配置
|
|
|
|
* @return 是否需要进行自定义数据处理
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public boolean needDataProcess(CustomComponentContext customComponentContext) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 对BI计算后即将返回前端的数据进行自定义处理
|
|
|
|
*
|
|
|
|
* @param dataModels 数据模型
|
|
|
|
* @param customComponentContext 自定义图表相关的上下文信息,目前包含前端传的查询配置
|
|
|
|
* @return 处理过的数据模型
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public List<DataModel> process(List<DataModel> dataModels, CustomComponentContext customComponentContext) {
|
|
|
|
|
|
|
|
return dataModels.stream().map(dataModel -> new DataModel() {
|
|
|
|
@Override
|
|
|
|
public List<String> getFields() {
|
|
|
|
return dataModel.getFields();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public List<List<Object>> getColData() {
|
|
|
|
List<List<Object>> colData = new ArrayList<>(dataModel.getFields().size());
|
|
|
|
dataModel.getColData().forEach(d -> colData.add(Collections.singletonList(d.get(0))));
|
|
|
|
return colData;
|
|
|
|
}
|
|
|
|
}).collect(Collectors.toList());
|
|
|
|
}
|
|
|
|
}
|