plotList.js 2.9 KB

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