com.datastax.data.exploration.service.chart.impl.Scatter3DServiceImpl Maven / Gradle / Ivy
package com.datastax.data.exploration.service.chart.impl;
import com.alibaba.fastjson.JSONObject;
import com.datastax.data.exploration.biz.datatable.DataTable;
import com.datastax.data.exploration.biz.datatable.DataType;
import com.datastax.data.exploration.common.DataTypeHandler;
import com.datastax.data.exploration.common.File2DataTable;
import com.datastax.data.exploration.service.chart.Scatter3DService;
import com.datastax.data.exploration.util.Consts;
import org.javatuples.Pair;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import java.util.List;
import static com.datastax.data.exploration.util.CommonUtil.columnIndex;
import static com.datastax.data.exploration.util.CommonUtil.getFormat;
/**
* 散点3D图
*
* @author songfu 2018/1/16
*/
@Service("scatter3DService")
public class Scatter3DServiceImpl implements Scatter3DService {
private static final Logger logger = LoggerFactory.getLogger(ScatterServiceImpl.class);
/**
* 获取散点3D图初始化数据
*
* @param id 数据集id
* @return 返回的是散点3D图初始化数据(JSONObeject对象)
*/
@Override
public JSONObject scatter3DInit(String id) {
List axisX = DataTypeHandler.noText(File2DataTable.tableSchema(id));
if (axisX.size() == 0) {
axisX.add(Consts.NONE);
}
JSONObject json = new JSONObject();
json.put("axisX", axisX);
json.put("axisY", axisX);
json.put("axisZ", axisX);
json.put("color", axisX);
return json;
}
/**
* 获取散点3D图展示的数据
*
* @param id 数据集id
* @param axisX 散点3D图x轴
* @param axisY 散点3D图y轴
* @param axisZ 散点3D图y轴
* @param color 散点3D图color维度
* @return 返回的是散点3D图展示的数据(JSONObeject对象)
*/
@Override
public JSONObject scatter3DSelect(String id, String axisX, String axisY, String axisZ, String color) {
DataTable table = File2DataTable.exactTable(id);
String[] type = {typeAndformat(table, axisX).getValue0()
, typeAndformat(table, axisY).getValue0()
, typeAndformat(table, axisZ).getValue0()
, typeAndformat(table, color).getValue0()};
String[] format = {typeAndformat(table, axisX).getValue1()
, typeAndformat(table, axisY).getValue1()
, typeAndformat(table, axisZ).getValue1()
, typeAndformat(table, color).getValue1()};
JSONObject json = new JSONObject();
json.put("data", table.getRows().dataDimen4(axisX, axisY, axisZ, color));
json.put("type", type);
json.put("format", format);
return json;
}
private Pair typeAndformat(DataTable table, String column) {
DataType dataType = table.getColumns().getColumn(column).getType();
return new Pair<>(dataType.getName(), getFormat(dataType));
}
}