parseChartOption.js 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641
  1. /**
  2. * 将请求返回的图表展示数据解析为前台展示用的config
  3. */
  4. import moment from 'moment'
  5. import EllipsisTooltip from '../components/common/ellipsisTooltip/index'
  6. import { deepAssign, numberFormat } from '../utils/baseUtils'
  7. import STATISTICS_OPTION from '../components/chartDesigner/sections/statisticsOption.json'
  8. import themes from '../components/chartDesigner/sections/style/theme/index'
  9. import adapteGridPosition from './adapteGridPosition'
  10. export default function(viewType, data, chartConfig, themeName, styleConfig) {
  11. if(!data) {
  12. return {};
  13. }
  14. try {
  15. let theme = themes[themeName] || themes['default']
  16. let o, themeConfig;
  17. switch(viewType) {
  18. case 'bar': {
  19. themeConfig = Object.assign({}, theme.base, theme.bar);
  20. o = barOption(data, chartConfig, themeConfig, styleConfig);
  21. break;
  22. }
  23. case 'pie': {
  24. themeConfig = Object.assign({}, theme.base, theme.pie);
  25. o = pieOption(data, chartConfig, themeConfig, styleConfig);
  26. break;
  27. }
  28. case 'line': {
  29. themeConfig = Object.assign({}, theme.base, theme.line);
  30. o = lineOption(data, chartConfig, themeConfig, styleConfig);
  31. break;
  32. }
  33. case 'scatter': {
  34. themeConfig = Object.assign({}, theme.base, theme.scatter);
  35. o = scatterOption(data, chartConfig, themeConfig, styleConfig);
  36. break;
  37. }
  38. case 'aggregateTable': {
  39. themeConfig = theme.aggregateTable;
  40. o = aggregateTableOption(data, chartConfig, themeConfig, styleConfig);
  41. break;
  42. }case 'dataView' : {
  43. themeConfig = theme.dataView;
  44. o = dataViewOption(data, chartConfig, themeConfig, styleConfig);
  45. break;
  46. }
  47. default:{
  48. o = {};
  49. break;
  50. }
  51. }
  52. return o;
  53. }catch(e) {
  54. console.error(e);
  55. }
  56. }
  57. function barOption(data, barConfig, themeConfig, styleConfig) {
  58. const { xAxis, yAxis, groupBy } = barConfig;
  59. const { gridPosition, barMaxWidth, barMinHeight, barGap, stack, labelVisible, labelPosition, labelDistance,
  60. labelRotate, labelFormatter, xNameLocation, xNameGap, xNameRotate, xLabelHiddenCover, xLabelRotate,
  61. xLabelMargin, yNameLocation, yNameGap, yNameRotate, legendHidden: styleLegendHidden, legendInPagination,
  62. legendOrient : styleLegendOrient, legendPosition, legendFormatter, labelZeroVisible, } = styleConfig;
  63. let xTitle = xAxis?`${xAxis.column.label}${xAxis.granularity.value?'('+xAxis.granularity.label+')':''}`:null
  64. let yTitle = yAxis?`${yAxis.column.label}${yAxis.gauge.value?'('+yAxis.gauge.label+')':''}`:null
  65. data.serieses = data.serieses || [];
  66. let legendHidden = !!groupBy && !!groupBy.key ? styleLegendHidden : true,
  67. legendOrient = styleLegendOrient || 'vertical',
  68. legendTop = legendPosition ? ((legendPosition.top === '' || legendPosition.top === null || legendPosition.top === undefined) ? 50 : legendPosition.top) : 50,
  69. legendLeft = legendPosition ? ((legendPosition.left === '' || legendPosition.left === null || legendPosition.left === undefined) ? 'auto' : legendPosition.left) : 'auto',
  70. legendRight = legendPosition ? ((legendPosition.right === '' || legendPosition.right === null || legendPosition.right === undefined) ? '5%' : legendPosition.right) : '5%',
  71. legendBottom = legendPosition ? ((legendPosition.bottom === '' || legendPosition.bottom === null || legendPosition.bottom === undefined) ? 50 : legendPosition.bottom) : 50;
  72. let adapte_grid_position = adapteGridPosition({
  73. legendHidden,
  74. legendOrient,
  75. legendLeft,
  76. legendRight,
  77. legendTop,
  78. legendBottom,
  79. });
  80. let option = deepAssign({
  81. tooltip : {
  82. trigger: "axis",
  83. axisPointer: {
  84. type: "cross",
  85. label: {
  86. backgroundColor: "#6a7985"
  87. }
  88. }
  89. },
  90. legend: {
  91. show: !!groupBy && !!groupBy.key && (legendHidden === undefined ? true : !legendHidden),
  92. type: legendInPagination === undefined ? 'plain' : (!!legendInPagination ? 'scroll' : 'plain'),
  93. orient: legendOrient,
  94. top: legendTop,
  95. left: legendLeft,
  96. right: legendRight,
  97. bottom: legendBottom,
  98. formatter: legendFormatter || '{name}',
  99. },
  100. grid: {
  101. top: (gridPosition && gridPosition.top && gridPosition.top !== 'auto') ? ( // 已设置图域上边距
  102. gridPosition.top
  103. ) : adapte_grid_position.top,
  104. left: (gridPosition && gridPosition.left && gridPosition.left !== 'auto') ? ( // 已设置图域左边距
  105. gridPosition.left
  106. ) : adapte_grid_position.left,
  107. right: (gridPosition && gridPosition.right && gridPosition.right !== 'auto') ? ( // 已设置图域右边距
  108. gridPosition.right
  109. ) : adapte_grid_position.right,
  110. bottom: (gridPosition && gridPosition.bottom && gridPosition.bottom !== 'auto') ? ( // 已设置图域下边距
  111. gridPosition.bottom
  112. ) : adapte_grid_position.bottom,
  113. containLabel: true
  114. },
  115. xAxis: [{
  116. type: 'category',
  117. nameLocation: (xNameLocation === '' || xNameLocation === null || xNameLocation === undefined) ? 'end' : xNameLocation,
  118. nameGap: (xNameGap === '' || xNameGap === null || xNameGap === undefined) ? 15 : Number(xNameGap),
  119. nameRotate: (xNameRotate === '' || xNameRotate === null || xNameRotate === undefined) ? 0 : Number(xNameRotate),
  120. axisLabel: {
  121. interval: xLabelHiddenCover === undefined ? 'auto' : (!!xLabelHiddenCover ? 'auto' : 0),
  122. rotate: (xLabelRotate === '' || xLabelRotate === null || xLabelRotate === undefined) ? 0 : Number(xLabelRotate),
  123. margin: (xLabelMargin === '' || xLabelMargin === null || xLabelMargin === undefined) ? 8 : Number(xLabelMargin),
  124. },
  125. data: data.xAxis.map(d => {
  126. let gv= xAxis.granularity.value;
  127. let xv = d || '空';
  128. if(gv === 'halfYear') {
  129. let arr = d.split('-H');
  130. xv = arr[0] + ['上半年', '下半年'][arr[1] - 1]
  131. }else if(gv === 'month') {
  132. xv = d.replace('-M', '-');
  133. }else if(gv === 'quarter') {
  134. let arr = d.split('-Q');
  135. xv = arr[0] + '-' + ['一', '二', '三', '四'][arr[1] - 1] + '季度'
  136. }else if(gv === 'week') {
  137. let arr = d.split('-W');
  138. xv = arr[0] + '-' + arr[1] + '周'
  139. }
  140. return xv;
  141. }),
  142. name: xTitle || '横轴',
  143. }],
  144. yAxis: [{
  145. name: yTitle || '纵轴',
  146. type: 'value',
  147. nameLocation: (yNameLocation === '' || yNameLocation === null || yNameLocation === undefined) ? 'end' : yNameLocation,
  148. nameGap: (yNameGap === '' || yNameGap === null || yNameGap === undefined) ? 15 : Number(yNameGap),
  149. nameRotate: (yNameRotate === '' || yNameRotate === null || yNameRotate === undefined) ? 0 : Number(yNameRotate),
  150. }],
  151. series: data.serieses.map(s => {
  152. return {
  153. name: groupBy ? s.name : (yAxis.column.label || s.name),
  154. type: 'bar',
  155. data: s.value,
  156. barMaxWidth: barMaxWidth || 80,
  157. barMinHeight: barMinHeight || 0,
  158. barGap: barGap || '30%',
  159. stack: !!groupBy && !!groupBy.key && !!stack,
  160. label: {
  161. normal: {
  162. show: !!labelVisible,
  163. position: labelPosition || 'inside',
  164. distance: (labelDistance === '' || labelDistance === null || labelDistance === undefined) ? 5 : Number(labelDistance),
  165. rotate: (labelRotate === '' || labelRotate === null || labelRotate === undefined) ? 0 : Number(labelRotate),
  166. // formatter: (labelFormatter === '' || labelFormatter === null || labelFormatter === undefined) ? '{c}' : labelFormatter,
  167. formatter: !labelZeroVisible ? (params) => {
  168. const { name : a, seriesName: b, value: c} = params;
  169. // {a: 系列名 name} {b: 数据名 seriesName} {c: 数据值 value}
  170. const obj = { a, b, c };
  171. let str = labelFormatter || '{c}';
  172. if(c === 0) {
  173. return '';
  174. }else {
  175. return `${str.replace(/{([^{ ^}])+}/g, function(x, y) {
  176. let s;
  177. if(!Object.prototype.hasOwnProperty.call(obj, y)) {
  178. return x;
  179. }else {
  180. try {
  181. s = obj[y];
  182. }catch(e) {
  183. s = x;
  184. }
  185. }
  186. return s;
  187. })}`
  188. }
  189. } : ((labelFormatter === '' || labelFormatter === null || labelFormatter === undefined) ? '{c}' : labelFormatter),
  190. }
  191. }
  192. }
  193. }),
  194. dataZoom: {
  195. show: false
  196. }
  197. }, themeConfig);
  198. return option;
  199. }
  200. function lineOption(data, lineConfig, themeConfig, styleConfig) {
  201. const { gridPosition, legendHidden : styleLegendHidden, legendInPagination, legendOrient : styleLegendOrient, legendPosition, labelSymbol,
  202. legendFormatter, xNameLocation, xNameGap, xNameRotate, xLabelRotate, xLabelMargin,
  203. yNameLocation, yNameGap, yNameRotate, stack, labelVisible, labelPosition, labelDistance, labelRotate,
  204. labelFormatter, lineSmooth, labelSymbolSize } = styleConfig;
  205. const { xAxis, yAxis, groupBy } = lineConfig;
  206. let xTitle = xAxis?`${xAxis.column.label}${xAxis.granularity.value?'('+xAxis.granularity.label+')':''}`:null
  207. let yTitle = yAxis?`${yAxis.column.label}${yAxis.gauge.value?'('+yAxis.gauge.label+')':''}`:null
  208. data.serieses = data.serieses || [];
  209. let legendHidden = !!groupBy && !!groupBy.key ? styleLegendHidden : true,
  210. legendOrient = styleLegendOrient || 'vertical',
  211. legendTop = legendPosition ? ((legendPosition.top === '' || legendPosition.top === null || legendPosition.top === undefined) ? 50 : legendPosition.top) : 50,
  212. legendLeft = legendPosition ? ((legendPosition.left === '' || legendPosition.left === null || legendPosition.left === undefined) ? 'auto' : legendPosition.left) : 'auto',
  213. legendRight = legendPosition ? ((legendPosition.right === '' || legendPosition.right === null || legendPosition.right === undefined) ? '5%' : legendPosition.right) : '5%',
  214. legendBottom = legendPosition ? ((legendPosition.bottom === '' || legendPosition.bottom === null || legendPosition.bottom === undefined) ? 50 : legendPosition.bottom) : 50;
  215. let adapte_grid_position = adapteGridPosition({
  216. legendHidden,
  217. legendOrient,
  218. legendLeft,
  219. legendRight,
  220. legendTop,
  221. legendBottom,
  222. });
  223. let option = deepAssign({
  224. grid: {
  225. top: (gridPosition && gridPosition.top && gridPosition.top !== 'auto') ? ( // 已设置图域上边距
  226. gridPosition.top
  227. ) : adapte_grid_position.top,
  228. left: (gridPosition && gridPosition.left && gridPosition.left !== 'auto') ? ( // 已设置图域左边距
  229. gridPosition.left
  230. ) : adapte_grid_position.left,
  231. right: (gridPosition && gridPosition.right && gridPosition.right !== 'auto') ? ( // 已设置图域右边距
  232. gridPosition.right
  233. ) : adapte_grid_position.right,
  234. bottom: (gridPosition && gridPosition.bottom && gridPosition.bottom !== 'auto') ? ( // 已设置图域下边距
  235. gridPosition.bottom
  236. ) : adapte_grid_position.bottom,
  237. containLabel: true
  238. },
  239. tooltip: {
  240. trigger: 'axis',
  241. axisPointer: {
  242. type: 'cross'
  243. }
  244. },
  245. legend: {
  246. show: !!groupBy && !!groupBy.key && (legendHidden === undefined ? true : !legendHidden),
  247. type: legendInPagination === undefined ? 'plain' : (!!legendInPagination ? 'scroll' : 'plain'),
  248. orient: legendOrient,
  249. top: legendTop,
  250. left: legendLeft,
  251. right: legendRight,
  252. bottom: legendBottom,
  253. formatter: legendFormatter || '{name}',
  254. },
  255. xAxis: [{
  256. name: xTitle || '横轴',
  257. type: 'time',
  258. nameLocation: (xNameLocation === '' || xNameLocation === null || xNameLocation === undefined) ? 'end' : xNameLocation,
  259. nameGap: (xNameGap === '' || xNameGap === null || xNameGap === undefined) ? 15 : Number(xNameGap),
  260. nameRotate: (xNameRotate === '' || xNameRotate === null || xNameRotate === undefined) ? 0 : Number(xNameRotate),
  261. axisLabel: {
  262. rotate: (xLabelRotate === '' || xLabelRotate === null || xLabelRotate === undefined) ? 0 : Number(xLabelRotate),
  263. margin: (xLabelMargin === '' || xLabelMargin === null || xLabelMargin === undefined) ? 8 : Number(xLabelMargin),
  264. },
  265. }],
  266. yAxis: [{
  267. name: yTitle || '纵轴',
  268. type: 'value',
  269. nameLocation: (yNameLocation === '' || yNameLocation === null || yNameLocation === undefined) ? 'end' : yNameLocation,
  270. nameGap: (yNameGap === '' || yNameGap === null || yNameGap === undefined) ? 15 : Number(yNameGap),
  271. nameRotate: (yNameRotate === '' || yNameRotate === null || yNameRotate === undefined) ? 0 : Number(yNameRotate),
  272. }],
  273. series: (data.serieses || []).map(s => {
  274. return {
  275. name: s.name,
  276. type: 'line',
  277. stack: !!groupBy && !!groupBy.key && !!stack,
  278. label: {
  279. normal: {
  280. show: !!labelVisible,
  281. position: labelPosition || 'inside',
  282. distance: (labelDistance === '' || labelDistance === null || labelDistance === undefined) ? 5 : Number(labelDistance),
  283. rotate: (labelRotate === '' || labelRotate === null || labelRotate === undefined) ? 0 : Number(labelRotate),
  284. formatter: (labelFormatter === '' || labelFormatter === null || labelFormatter === undefined) ? '{c}' : labelFormatter,
  285. },
  286. },
  287. symbol: !labelSymbol ? 'emptyCircle' : labelSymbol,
  288. symbolSize: (labelSymbolSize === '' || labelSymbolSize === null || labelSymbolSize === undefined) ? 4 : Number(labelSymbolSize),
  289. smooth: !!lineSmooth,
  290. data: s.mdata.map(m => {
  291. return [m.date, m.value]
  292. }).sort((a, b) => {return new Date(a[0]).getTime() - new Date(b[0]).getTime()} )
  293. }
  294. }),
  295. dataZoom: {
  296. show: false
  297. }
  298. }, themeConfig, styleConfig);
  299. return option;
  300. }
  301. function pieOption(data, pieConfig, themeConfig, styleConfig) {
  302. let columnName = pieConfig.xAxis.column.label + (pieConfig.xAxis.granularity.value ? '('+pieConfig.xAxis.granularity.label+')' : '');
  303. const { pieCenter, pieRadius, legendHidden, legendInPagination, legendOrient, legendPosition, legendFormatter,
  304. labelHidden } = styleConfig;
  305. let option = deepAssign({
  306. tooltip : {
  307. trigger: 'item',
  308. formatter: "{a} <br/>{b} : {c} ({d}%)"
  309. },
  310. legend: {
  311. show: legendHidden === undefined ? true : !legendHidden,
  312. type: legendInPagination === undefined ? 'plain' : (!!legendInPagination ? 'scroll' : 'plain'),
  313. orient: legendOrient || 'vertical',
  314. top: legendPosition ? legendPosition.top || 50 : 50,
  315. left: legendPosition ? legendPosition.left || 'auto' : 'auto',
  316. right: legendPosition ? legendPosition.right || '5%' : '5%',
  317. bottom: legendPosition ? legendPosition.bottom || 50 : 50,
  318. formatter: legendFormatter || '{name}',
  319. data: data.xAxis.map(d => {
  320. let gv= pieConfig.xAxis.granularity.value;
  321. let xv = d;
  322. if(!d) {
  323. xv = '空';
  324. }else {
  325. if(gv === 'halfYear') {
  326. let arr = d.split('-H');
  327. xv = arr[0] + ['上半年', '下半年'][arr[1] - 1]
  328. }else if(gv === 'month') {
  329. xv = d.replace('-M', '-');
  330. }else if(gv === 'quarter') {
  331. let arr = d.split('-Q');
  332. xv = arr[0] + '-' + ['一', '二', '三', '四'][arr[1] - 1] + '季度'
  333. }else if(gv === 'week') {
  334. let arr = d.split('-W');
  335. xv = arr[0] + '-' + arr[1] + '周'
  336. }
  337. }
  338. return xv;
  339. }),
  340. },
  341. grid: {
  342. left: '10%',
  343. right: '10%',
  344. top: 100,
  345. bottom: 60,
  346. containLabel: true
  347. },
  348. series : [
  349. {
  350. name: columnName,
  351. type: 'pie',
  352. center: pieCenter ? [pieCenter[0] || '40%', pieCenter[1] || '50%'] : ['40%', '50%'],
  353. radius: pieRadius ? [pieRadius[0] || 0, pieRadius[1] || '75%'] : [0, '75%'],
  354. label: {
  355. normal: {
  356. show: labelHidden === undefined ? true : !labelHidden,
  357. },
  358. emphasis: {
  359. show: true,
  360. }
  361. },
  362. labelLine: {
  363. normal: {
  364. show: labelHidden === undefined ? true : !labelHidden,
  365. },
  366. emphasis: {
  367. show: true,
  368. }
  369. },
  370. avoidLabelOverlap: labelHidden === undefined ? true : !labelHidden,
  371. data: (data.serieses || [{ value: [] }])[0].value.map(v => {
  372. let obj = { ...v };
  373. if(!v.name) {
  374. obj.name = '空'
  375. }else {
  376. let gv= pieConfig.xAxis.granularity.value;
  377. if(gv === 'halfYear') {
  378. let arr = v.name.split('-H');
  379. obj.name = arr[0] + ['上半年', '下半年'][arr[1] - 1]
  380. }else if(gv === 'month') {
  381. obj.name = v.name.replace('-M', '-');
  382. }else if(gv === 'quarter') {
  383. let arr = v.name.split('-');
  384. obj.name = arr[0] + '-' + ['一', '二', '三', '四'][arr[1] - 1] + '季度'
  385. }else if(gv === 'week') {
  386. let arr = v.name.split('-');
  387. obj.name = arr[0] + '-' + arr[1] + '周'
  388. }
  389. }
  390. return obj;
  391. }),
  392. itemStyle: {
  393. emphasis: {
  394. shadowBlur: 10,
  395. shadowOffsetX: 0,
  396. shadowColor: 'rgba(0, 0, 0, 0.5)'
  397. }
  398. }
  399. }
  400. ]
  401. }, themeConfig);
  402. return option;
  403. }
  404. function scatterOption(data, scatterConfig, themeConfig, styleConfig) {
  405. const { gridPosition, legendHidden: styleLegendHidden, legendInPagination, legendOrient : styleLegendOrient, legendPosition,
  406. labelSymbol, legendFormatter, xNameLocation, xNameGap, xNameRotate, xLabelRotate, xLabelMargin,
  407. yNameLocation, yNameGap, yNameRotate, labelSymbolSize, xLabelHiddenCover } = styleConfig;
  408. const { xAxis, yAxis, groupBy } = scatterConfig;
  409. let xTitle = xAxis?`${xAxis.column.label}${xAxis.granularity.value?'('+xAxis.granularity.label+')':''}`:null
  410. let yTitle = yAxis?`${yAxis.column.label}${yAxis.gauge.value?'('+yAxis.gauge.label+')':''}`:null
  411. let legendHidden = !!groupBy && !!groupBy.key ? styleLegendHidden : true,
  412. legendOrient = styleLegendOrient || 'vertical',
  413. legendTop = legendPosition ? ((legendPosition.top === '' || legendPosition.top === null || legendPosition.top === undefined) ? 50 : legendPosition.top) : 50,
  414. legendLeft = legendPosition ? ((legendPosition.left === '' || legendPosition.left === null || legendPosition.left === undefined) ? 'auto' : legendPosition.left) : 'auto',
  415. legendRight = legendPosition ? ((legendPosition.right === '' || legendPosition.right === null || legendPosition.right === undefined) ? '5%' : legendPosition.right) : '5%',
  416. legendBottom = legendPosition ? ((legendPosition.bottom === '' || legendPosition.bottom === null || legendPosition.bottom === undefined) ? 50 : legendPosition.bottom) : 50;
  417. let adapte_grid_position = adapteGridPosition({
  418. legendHidden,
  419. legendOrient,
  420. legendLeft,
  421. legendRight,
  422. legendTop,
  423. legendBottom,
  424. });
  425. let option = deepAssign({
  426. grid: {
  427. top: (gridPosition && gridPosition.top && gridPosition.top !== 'auto') ? ( // 已设置图域上边距
  428. gridPosition.top
  429. ) : adapte_grid_position.top,
  430. left: (gridPosition && gridPosition.left && gridPosition.left !== 'auto') ? ( // 已设置图域左边距
  431. gridPosition.left
  432. ) : adapte_grid_position.left,
  433. right: (gridPosition && gridPosition.right && gridPosition.right !== 'auto') ? ( // 已设置图域右边距
  434. gridPosition.right
  435. ) : adapte_grid_position.right,
  436. bottom: (gridPosition && gridPosition.bottom && gridPosition.bottom !== 'auto') ? ( // 已设置图域下边距
  437. gridPosition.bottom
  438. ) : adapte_grid_position.bottom,
  439. containLabel: true
  440. },
  441. tooltip: {
  442. trigger: 'axis',
  443. axisPointer: {
  444. type: 'cross'
  445. }
  446. },
  447. legend: {
  448. show: !!groupBy && !!groupBy.key && (legendHidden === undefined ? true : !legendHidden),
  449. type: legendInPagination === undefined ? 'plain' : (!!legendInPagination ? 'scroll' : 'plain'),
  450. orient: legendOrient,
  451. top: legendTop,
  452. left: legendLeft,
  453. right: legendRight,
  454. bottom: legendBottom,
  455. formatter: legendFormatter || '{name}',
  456. },
  457. xAxis : [{
  458. type : 'value',
  459. name: xTitle || '横轴',
  460. nameLocation: (xNameLocation === '' || xNameLocation === null || xNameLocation === undefined) ? 'end' : xNameLocation,
  461. nameGap: (xNameGap === '' || xNameGap === null || xNameGap === undefined) ? 15 : Number(xNameGap),
  462. nameRotate: (xNameRotate === '' || xNameRotate === null || xNameRotate === undefined) ? 0 : Number(xNameRotate),
  463. axisLabel: {
  464. interval: xLabelHiddenCover === undefined ? 'auto' : (!!xLabelHiddenCover ? 'auto' : 0),
  465. rotate: (xLabelRotate === '' || xLabelRotate === null || xLabelRotate === undefined) ? 0 : Number(xLabelRotate),
  466. margin: (xLabelMargin === '' || xLabelMargin === null || xLabelMargin === undefined) ? 8 : Number(xLabelMargin),
  467. },
  468. scale:true,
  469. splitLine: {
  470. show: true
  471. }
  472. }],
  473. yAxis : [{
  474. type : 'value',
  475. name: yTitle || '纵轴',
  476. nameLocation: (yNameLocation === '' || yNameLocation === null || yNameLocation === undefined) ? 'end' : yNameLocation,
  477. nameGap: (yNameGap === '' || yNameGap === null || yNameGap === undefined) ? 15 : Number(yNameGap),
  478. nameRotate: (yNameRotate === '' || yNameRotate === null || yNameRotate === undefined) ? 0 : Number(yNameRotate),
  479. scale:true,
  480. splitLine: {
  481. show: true
  482. },
  483. }],
  484. series : (data.serieses || []).map(s => {
  485. return {
  486. name: s.name,
  487. type: 'scatter',
  488. symbol: !labelSymbol ? 'circle' : labelSymbol,
  489. symbolSize: (labelSymbolSize === '' || labelSymbolSize === null || labelSymbolSize === undefined) ? 10 : Number(labelSymbolSize),
  490. data: s.mdata.map(m => {
  491. return [m.date, m.value]
  492. })
  493. }
  494. }),
  495. dataZoom: {
  496. show: false
  497. }
  498. }, themeConfig);
  499. return option;
  500. }
  501. function aggregateTableOption( data, aggregateTableConfig, themeConfig, styleConfig) {
  502. const { targetColumn, groupBy, statistics: statisticsNames } = aggregateTableConfig;
  503. const { direction } = styleConfig;
  504. let statistics = STATISTICS_OPTION.filter(o => statisticsNames.indexOf(o.value) !== -1).map(s => ({
  505. name: s.value,
  506. label: s.label
  507. })),
  508. group1Name = groupBy.length > 0 ? groupBy[0].key : null,
  509. group2Name = groupBy.length > 1 ? groupBy[1].key : null,
  510. group1s = [],
  511. group2s = [],
  512. tableData;
  513. const resData = data.valueList;
  514. if(!group1Name) { // 无分组
  515. let o = {};
  516. statistics.forEach(s => {
  517. o[s.name] = numberFormat(resData[s.name])
  518. });
  519. tableData = o;
  520. }else {
  521. if(!group2Name) { // 只有一个分组
  522. resData.forEach(d => {
  523. let v = d[group1Name];
  524. if(group1s.indexOf(v) === -1) {
  525. group1s.push(v);
  526. }
  527. });
  528. tableData = resData.map(d => {
  529. let o = {};
  530. statistics.forEach(s => {
  531. o[s.name] = numberFormat(d[s.name])
  532. });
  533. return o;
  534. });
  535. }else { // 有两个分组
  536. resData.forEach(d => {
  537. let v1 = d[group1Name];
  538. let v2 = d[group2Name];
  539. if(group1s.indexOf(v1) === -1) {
  540. group1s.push(v1);
  541. }
  542. if(group2s.indexOf(v2) === -1) {
  543. group2s.push(v2);
  544. }
  545. });
  546. tableData = group1s.map(g => {
  547. let obj = {},
  548. list = resData.filter(d => d[group1Name] === g)
  549. // .slice(0, 5);
  550. obj[group1Name] = g;
  551. obj['data'] = group2s.map(g => {
  552. let o = {};
  553. o[group2Name] = g;
  554. statistics.forEach(s => {
  555. let v = list.find(l => l[group2Name] === g);
  556. o[s.name] = v ? (typeof v[s.name] === 'number' ? numberFormat(v[s.name]) : '') : '';
  557. });
  558. return o;
  559. });
  560. return obj;
  561. });
  562. }
  563. }
  564. let option = {
  565. themeConfig,
  566. targetColumn,
  567. direction,
  568. group1Name: groupBy.length > 0 ? groupBy[0].key : null,
  569. group2Name: groupBy.length > 1 ? groupBy[1].key : null,
  570. group1s,
  571. group2s,
  572. statistics,
  573. data: tableData
  574. };
  575. console.log(option);
  576. return option;
  577. }
  578. function dataViewOption(data, dataViewConfig, themeConfig, styleConfig) {
  579. const { list, pageNum, pageSize, pages, total } = data.valueList;
  580. let columns = dataViewConfig.viewColumns || [];
  581. let dataSource = list || [];
  582. let option = {
  583. columns: columns.map(c => {
  584. let obj = {
  585. title: c.label,
  586. dataIndex: c.name,
  587. }
  588. if(c.type === 'time') {
  589. obj.render = (v, r, i) => {
  590. let text = v === null ? '空' : moment(v).isValid() ? moment(v).format('YYYY-MM-DD') : v
  591. return <EllipsisTooltip title={text}>{text}</EllipsisTooltip>
  592. }
  593. }else {
  594. obj.render = v => {
  595. let text = v === null ? '空' : v
  596. return <EllipsisTooltip title={text}>{text}</EllipsisTooltip>
  597. }
  598. }
  599. return obj;
  600. }),
  601. dataSource: dataSource.map((d, i) => {
  602. return { ...d, key: i}
  603. }),
  604. page: pageNum,
  605. pageSize,
  606. pages,
  607. total,
  608. };
  609. return option;
  610. }