transChartOption.ts 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. // import { EChartsOption } from "echarts";
  2. // import { isArray } from "element-plus/es/utils";
  3. // import { set } from "lodash-es";
  4. // /* 配置表单 转 echartsOption */
  5. // export const config2Option = (config: Record<string, any>) => {
  6. // const option: EChartsOption = {};
  7. // option.grid = {};
  8. // // 标题
  9. // option.title = {};
  10. // option.title.show = isArray(config.showTitle)
  11. // ? !!config.showTitle?.[0]
  12. // : !!config.showTitle;
  13. // option.title.text = `title|${config.titleText}`;
  14. // option.title.left = config.titlePosition;
  15. // option.title.textStyle = {
  16. // rich: {
  17. // title: {
  18. // color: config.titleStyle.color,
  19. // fontSize: config.titleStyle.size,
  20. // fontWeight: config.titleStyle.bold ? "bold" : "normal",
  21. // fontStyle: config.titleStyle.italic ? "italic" : "normal",
  22. // },
  23. // },
  24. // };
  25. // option.title.backgroundColor = config.titleBackground.color;
  26. // option.title.textStyle.opacity = config.titleOpacity / 100;
  27. // option.title.borderRadius = config.titleBorderRadius;
  28. // // 图例
  29. // option.legend = {};
  30. // option.legend.show = isArray(config.showLegend)
  31. // ? !!config.showLegend?.[0]
  32. // : !!config.showLegend;
  33. // switch (config.legendPosition) {
  34. // case "top":
  35. // option.legend.top = 0;
  36. // option.legend.left = "center";
  37. // break;
  38. // case "bottom":
  39. // option.legend.bottom = 0;
  40. // option.legend.left = "center";
  41. // break;
  42. // case "left":
  43. // option.legend.orient = "vertical";
  44. // option.legend.left = 0;
  45. // option.legend.top = "middle";
  46. // break;
  47. // case "right":
  48. // option.legend.orient = "vertical";
  49. // option.legend.right = 0;
  50. // option.legend.top = "middle";
  51. // break;
  52. // }
  53. // option.legend.formatter = `{legendTitle|{name}}`;
  54. // option.legend.textStyle = {
  55. // rich: {
  56. // legendTitle: {
  57. // color: config.legendStyle.color,
  58. // fontSize: config.legendStyle.size,
  59. // fontWeight: config.legendStyle.bold ? "bold" : "normal",
  60. // fontStyle: config.legendStyle.italic ? "italic" : "normal",
  61. // },
  62. // },
  63. // };
  64. // option.legend.borderWidth = config.legendBorderWidth;
  65. // option.legend.borderColor = config.legendBorderColor;
  66. // option.legend.borderRadius = config.legendBorderRadius;
  67. // option.legend.backgroundColor = config.legendBackground.color;
  68. // if (config.legendShadow) {
  69. // option.legend.shadowBlur = 10;
  70. // option.legend.shadowColor = "rgba(0, 0, 0, 0.5)";
  71. // option.legend.shadowOffsetX = 0;
  72. // option.legend.shadowOffsetY = 0;
  73. // }
  74. // // 标签
  75. // // TODO 标签加入到series中
  76. // const optionLabel: Record<string, any> = {};
  77. // optionLabel.show = isArray(config.showLabel)
  78. // ? !!config.showLabel?.[0]
  79. // : !!config.showLabel;
  80. // optionLabel.formatter = (res: any) => {
  81. // let str: string = "";
  82. // (config.labelValueType || []).forEach((key: string) => {
  83. // str += res[key] + " ";
  84. // });
  85. // return `{labelTitle|{${str}}}`;
  86. // };
  87. // optionLabel.color = config.labelColor;
  88. // optionLabel.rich = {
  89. // labelTitle: {
  90. // color: config.labelColor,
  91. // fontSize: config.labelStyle.size,
  92. // fontWeight: config.labelStyle.bold ? "bold" : "normal",
  93. // fontStyle: config.labelStyle.italic ? "italic" : "normal",
  94. // },
  95. // };
  96. // optionLabel.position = config.labelPosition;
  97. // optionLabel.rotate = config.labelDirection === "vertical" ? 90 : 0;
  98. // optionLabel.borderWidth = config.labelBorderWidth;
  99. // optionLabel.borderColor = config.labelBorderColor;
  100. // optionLabel.borderRadius = config.labelBorderRadius;
  101. // // 系列--暂时只配置颜色方案,其他配置组件内部处理
  102. // option.series = {};
  103. // option.series.color = config.colorScheme;
  104. // // X 轴
  105. // option.xAxis = {};
  106. // option.xAxis.type = config.xAxisType;
  107. // if (config.xAliasShowTitle && config.xAliasTitle) {
  108. // option.xAxis.name = config.xAliasTitle;
  109. // option.grid.bottom = 40; // 给标题留出空间
  110. // }
  111. // let positionMap = {
  112. // left: "start",
  113. // center: "middle",
  114. // right: "end",
  115. // };
  116. // type Position = "start" | "middle" | "end";
  117. // option.xAxis.nameLocation = (
  118. // config.xAliasPosition
  119. // ? positionMap[config.xAliasPosition as "left" | "center" | "right"]
  120. // : "middle"
  121. // ) as Position;
  122. // option.xAxis.nameTextStyle = {
  123. // color: config.xAliasStyle.color,
  124. // fontSize: config.xAliasStyle.size,
  125. // fontWeight: config.xAliasStyle.bold ? "bold" : "normal",
  126. // fontStyle: config.xAliasStyle.italic ? "italic" : "normal",
  127. // }
  128. // set(option, 'xAxias.axisLine.lineStyle.width', config.xAxisLineWidth);
  129. // set(option, 'xAxias.axisLine.lineStyle.color', config.xAxisLineColor);
  130. // set(option, 'xAxias.axisLine.axisTick.color', config.xAxisTickColor);
  131. // };
  132. // /* echartsOption 转 配置表单 */
  133. // export const option2Config = (option: EChartsOption) => {};