|
|
@@ -2,22 +2,22 @@ function converter(data) {
|
|
|
let { content } = data;
|
|
|
let { title, items } = content;
|
|
|
let itemsarr = items instanceof Array ? items : [items];
|
|
|
-
|
|
|
+
|
|
|
let me = this;
|
|
|
let newItems = itemsarr.map(function (v, i) {
|
|
|
let type = v.type;
|
|
|
- if(type == 'form') {
|
|
|
+ if (type == 'form') {
|
|
|
return formConfig(v);
|
|
|
- }else if(type == 'table') {
|
|
|
+ } else if (type == 'table') {
|
|
|
return tableConfig(v);
|
|
|
- }else if(type == 'bar') {
|
|
|
+ } else if (type == 'bar') {
|
|
|
return barConfig(v);
|
|
|
- }else if(type == 'line') {
|
|
|
+ } else if (type == 'line') {
|
|
|
return lineConfig(v);
|
|
|
- }else if(type == 'pie') {
|
|
|
+ } else if (type == 'pie') {
|
|
|
return pieConfig(v);
|
|
|
- }else {
|
|
|
-
|
|
|
+ } else {
|
|
|
+
|
|
|
}
|
|
|
});
|
|
|
return {
|
|
|
@@ -37,7 +37,7 @@ function titleConfig(title) {
|
|
|
|
|
|
function formConfig(model) {
|
|
|
let { type, header, config, layout } = model;
|
|
|
- let { fontSize, fieldstyle, valuestyle, columns, data} = config;
|
|
|
+ let { fontSize, fieldstyle, valuestyle, columns, data } = config;
|
|
|
data = data.map((d) => {
|
|
|
d.field = {
|
|
|
text: d.field.text,
|
|
|
@@ -66,7 +66,7 @@ function formConfig(model) {
|
|
|
|
|
|
function tableConfig(model) {
|
|
|
let { type, config, layout } = model;
|
|
|
- let { fontSize, title, cls, render, columns, data, rowHeight, interval} = config;
|
|
|
+ let { fontSize, title, cls, render, columns, data, rowHeight, interval } = config;
|
|
|
return {
|
|
|
type: 'table',
|
|
|
config: {
|
|
|
@@ -80,7 +80,7 @@ function tableConfig(model) {
|
|
|
v.render = renderFunction(v.render);
|
|
|
return v;
|
|
|
}),
|
|
|
- data: data.map((v, i)=> {
|
|
|
+ data: data.map((v, i) => {
|
|
|
v.key = i;
|
|
|
return v;
|
|
|
})
|
|
|
@@ -91,9 +91,9 @@ function tableConfig(model) {
|
|
|
|
|
|
function barConfig(model) {
|
|
|
let { type, config, layout } = model;
|
|
|
- let { fontSize, title, subtitle, xtitle, xtype, xfields, ytitle, ytype, yfields, series} = config;
|
|
|
-
|
|
|
- let xf = (xfields instanceof Array) ? xfields : (xfields.replace(['['],'').replace([']'],'').split(','));
|
|
|
+ let { fontSize, title, subtitle, xtitle, xtype, xfields, ytitle, ytype, yfields, series } = config;
|
|
|
+
|
|
|
+ let xf = (xfields instanceof Array) ? xfields : (xfields.replace(['['], '').replace([']'], '').split(','));
|
|
|
return {
|
|
|
type: 'charts',
|
|
|
config: {
|
|
|
@@ -128,11 +128,12 @@ function barConfig(model) {
|
|
|
name: xtitle,
|
|
|
nameGap: 5,
|
|
|
nameRotate: 270,
|
|
|
+ nameLocation: 'end',
|
|
|
nameTextStyle: {
|
|
|
fontSize: getFontSize() * .7
|
|
|
},
|
|
|
axisLabel: {
|
|
|
- rotate: getScreenSize().width * layout.w / xf.length / 100 < 80 ? 45 : 0,
|
|
|
+ rotate: getScreenSize().width * layout.w / xf.length / 100 < 80 ? 45 : 0,
|
|
|
interval: 0,
|
|
|
textStyle: {
|
|
|
fontSize: getFontSize() * .7
|
|
|
@@ -161,8 +162,8 @@ function barConfig(model) {
|
|
|
|
|
|
function lineConfig(model) {
|
|
|
let { type, config, layout } = model;
|
|
|
- let { fontSize, title, subtitle, xtitle, xtype, xfields, ytitle, ytype, yfields, series} = config;
|
|
|
- let xf = (xfields instanceof Array) ? xfields : (xfields.replace(['['],'').replace([']'],'').split(','));
|
|
|
+ let { fontSize, title, subtitle, xtitle, xtype, xfields, ytitle, ytype, yfields, series } = config;
|
|
|
+ let xf = (xfields instanceof Array) ? xfields : (xfields.replace(['['], '').replace([']'], '').split(','));
|
|
|
return {
|
|
|
type: 'charts',
|
|
|
config: {
|
|
|
@@ -189,16 +190,17 @@ function lineConfig(model) {
|
|
|
})
|
|
|
},
|
|
|
xAxis: [{
|
|
|
- type : xtype,
|
|
|
- data : xf,
|
|
|
+ type: xtype,
|
|
|
+ data: xf,
|
|
|
name: xtitle,
|
|
|
nameRotate: 270,
|
|
|
+ nameLocation: 'end',
|
|
|
nameGap: 5,
|
|
|
nameTextStyle: {
|
|
|
fontSize: fontSize || getFontSize() * .7
|
|
|
},
|
|
|
axisLabel: {
|
|
|
- rotate: getScreenSize().width * layout.w / xf.length / 100 < 80 ? 45 : 0,
|
|
|
+ rotate: getScreenSize().width * layout.w / xf.length / 100 < 80 ? 45 : 0,
|
|
|
interval: 0,
|
|
|
textStyle: {
|
|
|
fontSize: fontSize || getFontSize() * .7
|
|
|
@@ -218,7 +220,16 @@ function lineConfig(model) {
|
|
|
}
|
|
|
}
|
|
|
}],
|
|
|
- series: getLineSeries(fontSize, series)
|
|
|
+ series: getLineSeries(fontSize, series),
|
|
|
+ dataZoom: [
|
|
|
+ {
|
|
|
+ type: 'slider',
|
|
|
+ show: false,
|
|
|
+ xAxisIndex: [0],
|
|
|
+ start: 0,
|
|
|
+ endValue: Math.round(getScreenSize().width * layout.w / 100 / 60) >= series[0].data.length ? series[0].data.length - 1 : Math.round(getScreenSize().width * layout.w / 100 / 60),
|
|
|
+ }
|
|
|
+ ],
|
|
|
}
|
|
|
},
|
|
|
layout: getLayout(layout)
|
|
|
@@ -227,7 +238,7 @@ function lineConfig(model) {
|
|
|
|
|
|
function pieConfig(model) {
|
|
|
let { type, config, layout } = model;
|
|
|
- let { fontSize, title, subtitle, series} = config;
|
|
|
+ let { fontSize, title, subtitle, series } = config;
|
|
|
series = series.map((v, i) => {
|
|
|
v.value = v.data;
|
|
|
return v;
|
|
|
@@ -252,8 +263,8 @@ function pieConfig(model) {
|
|
|
function renderFunction(funcStr) {
|
|
|
let func = function (_v, _r, _i) { return { children: _v, props: {} } };
|
|
|
try {
|
|
|
- func = (new Function("return "+funcStr))();
|
|
|
- }catch(ex) {
|
|
|
+ func = (new Function("return " + funcStr))();
|
|
|
+ } catch (ex) {
|
|
|
// console.log('parsing failed', ex);
|
|
|
}
|
|
|
return func;
|
|
|
@@ -298,7 +309,7 @@ function getBarSeries(fontSize, layout, series) {
|
|
|
barGap: 0
|
|
|
}
|
|
|
s = series.map((v, i) => {
|
|
|
- let m = Object.assign({},model);
|
|
|
+ let m = Object.assign({}, model);
|
|
|
m.name = v.name;
|
|
|
m.data = v.data instanceof Array ? v.data : [v.data];
|
|
|
return m;
|
|
|
@@ -310,6 +321,20 @@ function getLineSeries(fontSize, series) {
|
|
|
let s = [];
|
|
|
const model = {
|
|
|
type: 'line',
|
|
|
+ smooth: false,
|
|
|
+ markLine: {
|
|
|
+ symbol: '',
|
|
|
+ label: {
|
|
|
+ normal: {
|
|
|
+ show: false
|
|
|
+ }
|
|
|
+ },
|
|
|
+ data: [{
|
|
|
+ name: '起始位置',
|
|
|
+ yAxis: null,
|
|
|
+ xAxis: ''
|
|
|
+ }]
|
|
|
+ },
|
|
|
label: {
|
|
|
normal: {
|
|
|
show: true,
|
|
|
@@ -322,7 +347,7 @@ function getLineSeries(fontSize, series) {
|
|
|
}
|
|
|
}
|
|
|
s = series.map((v, i) => {
|
|
|
- let m = Object.assign({},model);
|
|
|
+ let m = Object.assign({}, model);
|
|
|
m.name = v.name;
|
|
|
m.data = v.data instanceof Array ? v.data : [v.data];
|
|
|
return m;
|
|
|
@@ -334,8 +359,6 @@ function getPieSeries(fontSize, layout, series) {
|
|
|
let data = series instanceof Array ? series : [series];
|
|
|
const model = {
|
|
|
type: 'pie',
|
|
|
- radius: `${layout.w * .7}%`,
|
|
|
- center: getScreenSize().height * layout.h / 100 > 400 ? ['50%', '60%'] : (layout.w * getScreenSize().width / 100 < 450 ? ['50%', '55%'] : ['35%', '50%']),
|
|
|
label: {
|
|
|
normal: {
|
|
|
textStyle: {
|
|
|
@@ -345,18 +368,14 @@ function getPieSeries(fontSize, layout, series) {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- let s = Object.assign({},model);
|
|
|
+ let s = Object.assign({}, model);
|
|
|
s.name = '';
|
|
|
- s.data = data.map((d, i) => {d.name = d.name || 'Unkonw';return d;});
|
|
|
+ s.data = data.map((d, i) => { d.name = d.name || 'Unkonw'; return d; });
|
|
|
return [s];
|
|
|
}
|
|
|
|
|
|
function getPieLegend(fontSize, layout, series) {
|
|
|
let legend = {
|
|
|
- show: (layout.w * getScreenSize().width / 100 > 450 || layout.h * getScreenSize().height / 100 > 400),
|
|
|
- top: (getScreenSize().height * layout.h / 100 > 400 ? '20%' : '15%'),
|
|
|
- right: (getScreenSize().height * layout.h / 100 > 400 ? 'auto' : '5%'),
|
|
|
- orient: (getScreenSize().height * layout.h / 100 > 400 ? 'horizontal' : 'vertical'),
|
|
|
padding: 0,
|
|
|
itemGap: layout.w / 10,
|
|
|
textStyle: {
|
|
|
@@ -371,32 +390,32 @@ function getPieLegend(fontSize, layout, series) {
|
|
|
|
|
|
function getLayout(layout) {
|
|
|
let l = {};
|
|
|
- for(let k in layout) {
|
|
|
- l[k] = layout[k]/10
|
|
|
+ for (let k in layout) {
|
|
|
+ l[k] = layout[k] / 10
|
|
|
}
|
|
|
return l;
|
|
|
}
|
|
|
|
|
|
function parseStyleStr(str) {
|
|
|
- if(!str) {
|
|
|
+ if (!str) {
|
|
|
return {};
|
|
|
}
|
|
|
- if(typeof str == 'object') {
|
|
|
+ if (typeof str == 'object') {
|
|
|
return str;
|
|
|
}
|
|
|
- str = str+'';
|
|
|
- str = str.replace(/\s+/g,"");
|
|
|
+ str = str + '';
|
|
|
+ str = str.replace(/\s+/g, "");
|
|
|
let arr = str.split(';');
|
|
|
- let objArr = arr.map(function(v, i) {
|
|
|
+ let objArr = arr.map(function (v, i) {
|
|
|
let arr = v.split(':');
|
|
|
let obj = {};
|
|
|
obj[arr[0]] = arr[1];
|
|
|
return obj
|
|
|
});
|
|
|
let obj = {}
|
|
|
- objArr.map(function(v,i) {
|
|
|
- for(let k in v) {
|
|
|
- if(k) {
|
|
|
+ objArr.map(function (v, i) {
|
|
|
+ for (let k in v) {
|
|
|
+ if (k) {
|
|
|
obj[k] = v[k]
|
|
|
}
|
|
|
}
|
|
|
@@ -408,12 +427,12 @@ function getScreenSize() {
|
|
|
let root = document.getElementById('root');
|
|
|
let height = root.offsetHeight;
|
|
|
let width = root.offsetWidth;
|
|
|
- return {height, width};
|
|
|
+ return { height, width };
|
|
|
}
|
|
|
|
|
|
function getFontSize() {
|
|
|
- let {height, width} = getScreenSize();
|
|
|
- return width / 300 * 2 + 16 + Math.round(width/1000) * 2;
|
|
|
+ let { height, width } = getScreenSize();
|
|
|
+ return width / 300 * 2 + 16 + Math.round(width / 1000) * 2;
|
|
|
}
|
|
|
|
|
|
-export {converter};
|
|
|
+export { converter };
|