plotList.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. * @description: webpack读取当前文件夹下的所有 图表的js文件配置, 生成g2Plot配置列表
  3. * @Date: 2023-03-28 10:40:22
  4. * @Author: xing.heng
  5. */
  6. import { dataConfig, settingConfig } from '../PlotRender/settingConfig'
  7. import { mapData } from 'data-room-ui/BasicComponents/Map/settingConfig'
  8. import { FlyMapData } from 'data-room-ui/BasicComponents/FlyMap/settingConfig'
  9. import { candlestickData } from 'data-room-ui/BasicComponents/Candlestick/settingConfig'
  10. import { sankeyData } from 'data-room-ui/BasicComponents/Sankey/settingConfig'
  11. // import _ from 'lodash'
  12. import cloneDeep from 'lodash/cloneDeep'
  13. import sortList from './plotListSort'
  14. // 遍历 当前文件夹下的所有文件,找到中文.js文件,然后导出
  15. const files = require.context('./', true, /[\u4e00-\u9fa5]+.js$/)
  16. const plotList = getPlotList(files)
  17. const customPlots = getCustomPlots()
  18. // 获取plot配置
  19. function getPlotList (files) {
  20. const configMapList = {}
  21. files.keys().forEach((key) => {
  22. // ./折线图/基础折线图.js
  23. // 取到 "基础折线图"
  24. const configName = key.split('/')[2].replace('.js', '')
  25. configMapList[configName] = files(key).default
  26. })
  27. const plotList = []
  28. for (const configMapKey in configMapList) {
  29. const index = sortList.findIndex((item) => item === configMapKey)
  30. const config = configMapList[configMapKey]
  31. plotList[index] = {
  32. version: config.version,
  33. category: configMapKey,
  34. name: config.name,
  35. title: config.title,
  36. border: { type: '', titleHeight: 60, fontSize: 16, isTitle: true, padding: [16, 16, 16, 16] },
  37. icon: null,
  38. img: require(`../G2Plots/images/componentLogo/${config.title}.png`),
  39. className:
  40. 'com.gccloud.dataroom.core.module.chart.components.CustomComponentChart',
  41. w: config?.option?.width || 450,
  42. h: config?.option?.height || 320,
  43. x: 0,
  44. y: 0,
  45. rotateX: config.rotateX || 0,
  46. rotateY: config.rotateY || 0,
  47. rotateZ: config.rotateZ || 0,
  48. perspective: config.perspective || 0,
  49. skewX: config.skewX || 0,
  50. skewY: config.skewY || 0,
  51. type: 'customComponent',
  52. chartType: config.chartType,
  53. loading: false,
  54. option: {
  55. ...config.option,
  56. ...cloneDeep(settingConfig)
  57. },
  58. setting: config.setting, // 右侧面板自定义配置
  59. dataHandler: config.dataHandler, // 数据自定义处理js脚本
  60. optionHandler: config.optionHandler, // 配置自定义处理js脚本
  61. ...cloneDeep(dataConfig)
  62. }
  63. }
  64. return plotList
  65. }
  66. export function getCustomPlots () {
  67. const customList = window.BS_CONFIG?.customPlots || []
  68. const list = []
  69. customList.forEach((config) => {
  70. list.push({
  71. version: config.version,
  72. category: config.category,
  73. name: config.name,
  74. title: config.title,
  75. border: { type: '', titleHeight: 60, fontSize: 16, isTitle: true, padding: [16, 16, 16, 16] },
  76. icon: null,
  77. img: config.img,
  78. className:
  79. 'com.gccloud.dataroom.core.module.chart.components.CustomComponentChart',
  80. w: 450,
  81. h: 320,
  82. x: 0,
  83. y: 0,
  84. type: 'customComponent',
  85. chartType: config.chartType,
  86. option: {
  87. ...config.option,
  88. ...cloneDeep(settingConfig)
  89. },
  90. setting: config.setting, // 右侧面板自定义配置
  91. dataHandler: config.dataHandler, // 数据自定义处理js脚本
  92. optionHandler: config.optionHandler, // 配置自定义处理js脚本
  93. ...cloneDeep(dataConfig)
  94. })
  95. })
  96. return list
  97. }
  98. const plots = [...plotList, ...customPlots, sankeyData, candlestickData, mapData, FlyMapData]
  99. console.log('plotList', plots)
  100. export default plots