gauge.ts 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. /*
  2. * <<
  3. * Davinci
  4. * ==
  5. * Copyright (C) 2016 - 2017 EDP
  6. * ==
  7. * Licensed under the Apache License, Version 2.0 (the "License");
  8. * you may not use this file except in compliance with the License.
  9. * You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS,
  15. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. * See the License for the specific language governing permissions and
  17. * limitations under the License.
  18. * >>
  19. */
  20. import { IChartProps } from '../../components/Chart'
  21. import { decodeMetricName } from '../../components/util'
  22. import { EChartOption } from 'echarts'
  23. import { getFormattedValue } from '../../components/Config/Format'
  24. export default function (chartProps: IChartProps, drillOptions?: any) {
  25. const {
  26. width,
  27. height,
  28. data,
  29. cols,
  30. metrics,
  31. chartStyles
  32. } = chartProps
  33. const {
  34. axis,
  35. splitLine,
  36. gauge
  37. } = chartStyles
  38. const {
  39. radius,
  40. splitNumber,
  41. startAngle,
  42. endAngle,
  43. clockwise,
  44. prefix,
  45. suffix,
  46. showTitle,
  47. titleFontFamily,
  48. titleFontSize,
  49. titleColor,
  50. titleOffsetLeft,
  51. titleOffsetTop,
  52. showDetail,
  53. detailFontFamily,
  54. detailFontSize,
  55. detailColor,
  56. detailOffsetLeft,
  57. detailOffsetTop,
  58. showPointer,
  59. pointerLength,
  60. pointerWidth,
  61. customPointerColor,
  62. pointerColor,
  63. pointerBorderStyle,
  64. pointerBorderWidth,
  65. pointerBorderColor,
  66. axisLineSize,
  67. axisLineColor,
  68. showAxisTick,
  69. showAxisLabel,
  70. axisLabelDistance,
  71. axisLabelFontFamily,
  72. axisLabelFontSize,
  73. axisLabelColor,
  74. showSplitLine,
  75. splitLineLength,
  76. splitLineSize,
  77. splitLineStyle,
  78. splitLineColor
  79. } = gauge
  80. const max = gauge.max || 100
  81. let seriesObj = {}
  82. const seriesArr = []
  83. metrics.forEach((m) => {
  84. const decodedMetricName = decodeMetricName(m.name)
  85. seriesObj = {
  86. type: 'gauge',
  87. splitNumber,
  88. startAngle,
  89. endAngle,
  90. clockwise,
  91. max,
  92. radius: radius ? `${radius}%` : '75%',
  93. title: {
  94. show: showTitle,
  95. fontFamily: titleFontFamily,
  96. fontSize: titleFontSize,
  97. color: titleColor,
  98. offsetCenter: [
  99. titleOffsetLeft ? `${titleOffsetLeft}%` : 0,
  100. titleOffsetTop ? `${titleOffsetTop}%` : 0
  101. ]
  102. },
  103. detail: {
  104. show: showDetail,
  105. fontFamily: detailFontFamily,
  106. fontSize: detailFontSize,
  107. color: detailColor,
  108. offsetCenter: [
  109. detailOffsetLeft ? `${detailOffsetLeft}%` : 0,
  110. detailOffsetTop ? `${detailOffsetTop}%` : 0
  111. ],
  112. formatter: (value) => `${prefix}${getFormattedValue(Number(value) * 100 / max, m.format)}${suffix}`,
  113. // rich: {},
  114. // width: 240,
  115. // height: 240,
  116. // borderRadius: 120,
  117. // lineHeight: 240,
  118. // backgroundColor: '#05354a'
  119. },
  120. // animationDuration: 1000,
  121. // animationDurationUpdate: 1000,
  122. data: [{
  123. value: data.length ? data[0][`${m.agg}(${decodedMetricName})`] : 0,
  124. name: m.field.alias || decodedMetricName
  125. }],
  126. axisLine: {
  127. lineStyle: {
  128. width: axisLineSize,
  129. color: [
  130. [data.length ? data[0][`${m.agg}(${decodedMetricName})`] / max : 0, axisLineColor],
  131. [1, '#ddd']
  132. ]
  133. }
  134. },
  135. axisTick: {
  136. show: showAxisTick
  137. },
  138. axisLabel: {
  139. show: showAxisLabel,
  140. distance: axisLabelDistance,
  141. fontSize: axisLabelFontSize,
  142. fontFamily: axisLabelFontFamily,
  143. color: axisLabelColor
  144. },
  145. splitLine: {
  146. show: showSplitLine,
  147. length: splitLineLength,
  148. lineStyle: {
  149. color: splitLineColor,
  150. width: splitLineSize,
  151. type: splitLineStyle
  152. }
  153. },
  154. pointer: {
  155. show: showPointer,
  156. length: pointerLength ? `${pointerLength}%` : 0,
  157. width: pointerWidth
  158. },
  159. itemStyle: {
  160. color: customPointerColor ? pointerColor : 'auto',
  161. borderType: pointerBorderStyle,
  162. borderWidth: pointerBorderWidth,
  163. borderColor: pointerBorderColor
  164. }
  165. }
  166. seriesArr.push(seriesObj)
  167. })
  168. const tooltip: EChartOption.Tooltip = {
  169. trigger: 'item',
  170. formatter: '{b}: {c}'
  171. }
  172. return {
  173. tooltip,
  174. series: seriesArr
  175. }
  176. }