config.ts 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. import { echartOptionProfixHandle, PublicConfigClass } from '@/packages/public'
  2. import { ScatterCommonConfig } from './index'
  3. import { CreateComponentType } from '@/packages/index.d'
  4. import cloneDeep from 'lodash/cloneDeep'
  5. import dataJson from './data.json'
  6. export const includes = ['legend', 'xAxis', 'yAxis', 'grid']
  7. export const seriesItem = {
  8. type: 'scatter',
  9. emphasis: {
  10. focus: 'series'
  11. },
  12. symbolSize: 12,
  13. markArea: {
  14. silent: true,
  15. itemStyle: {
  16. color: 'transparent',
  17. borderWidth: 1,
  18. borderType: 'dashed'
  19. },
  20. data: [
  21. [
  22. {
  23. xAxis: 'min',
  24. yAxis: 'min'
  25. },
  26. {
  27. xAxis: 'max',
  28. yAxis: 'max'
  29. }
  30. ]
  31. ]
  32. },
  33. markPoint: {
  34. symbol: 'pin',
  35. symbolSize: 50,
  36. data: [
  37. { type: 'max', name: 'Max' },
  38. { type: 'min', name: 'Min' }
  39. ]
  40. }
  41. }
  42. export const option = {
  43. dataset: dataJson,
  44. tooltip: {
  45. showDelay: 0,
  46. formatter: (params: { value: string | any[]; seriesName: string; name: string }) => {
  47. // console.log(params)
  48. return params.value.length > 1
  49. ? `${params.seriesName}:<br />${params.value[0]} ${params.value[1]}`
  50. : `${params.seriesName}:<br />${params.name} ${params.value}`
  51. },
  52. axisPointer: {
  53. show: true,
  54. type: 'cross',
  55. lineStyle: {
  56. type: 'dashed',
  57. width: 1
  58. }
  59. }
  60. },
  61. xAxis: {
  62. scale: true
  63. },
  64. yAxis: {
  65. scale: true
  66. },
  67. series: dataJson.map((item, index) => ({
  68. ...seriesItem,
  69. datasetIndex: index
  70. }))
  71. }
  72. export default class Config extends PublicConfigClass implements CreateComponentType {
  73. public key = ScatterCommonConfig.key
  74. public chartConfig = cloneDeep(ScatterCommonConfig)
  75. // 图表配置项
  76. public option = echartOptionProfixHandle(option, includes)
  77. }