plotList.js 3.5 KB

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