pie.ts 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 { DimetionType } from '../../components/Widget'
  21. export default function () {
  22. return {
  23. chartOption: {
  24. type: 'pie'
  25. },
  26. calcPieCenterAndRadius (
  27. dimetionAxis: DimetionType,
  28. containerWidth: number,
  29. containerHeight: number,
  30. elementSize: number,
  31. unitMetricLengthArr: number[],
  32. horizontalRecordCountOfCol: number,
  33. verticalRecordCountOfRow: number,
  34. lineRecordSum: number,
  35. lineCount: number,
  36. unitCount: number,
  37. metricCount: number,
  38. recordCount: number,
  39. lineIndex: number,
  40. unitIndex: number,
  41. metricIndex: number,
  42. recordIndex: number
  43. ): { center: string[], radius: string[]} {
  44. let center
  45. let radius
  46. if (dimetionAxis === 'col') {
  47. const verticalPer = 100 / lineCount / metricCount
  48. const horizontalPer = 100 / horizontalRecordCountOfCol
  49. center = [
  50. `${horizontalPer * (recordIndex + lineRecordSum + 1) - horizontalPer / 2}%`,
  51. `${verticalPer * (metricIndex + metricCount * lineIndex + 1) - verticalPer / 2}%`
  52. ]
  53. if (containerWidth > containerHeight) {
  54. const rate = Math.min(elementSize / unitMetricLengthArr[0], 1)
  55. radius = ['0%', `${100 / metricCount / lineCount * rate * .75}%`]
  56. } else {
  57. const rate = Math.min(unitMetricLengthArr[0] / elementSize, 1)
  58. radius = ['0%', `${100 / horizontalRecordCountOfCol * rate * .75}%`]
  59. }
  60. } else {
  61. const verticalPer = 100 / verticalRecordCountOfRow
  62. const horizontalPer = 100 / unitCount / metricCount
  63. center = [
  64. `${horizontalPer * (metricIndex + metricCount * unitIndex + 1) - horizontalPer / 2}%`,
  65. `${verticalPer * (verticalRecordCountOfRow - recordIndex - lineIndex * recordCount) - verticalPer / 2}%`
  66. ]
  67. if (containerWidth > containerHeight) {
  68. const rate = Math.min(unitMetricLengthArr[1] / elementSize, 1)
  69. radius = ['0%', `${100 / verticalRecordCountOfRow * rate * .75}%`]
  70. } else {
  71. const rate = Math.min(elementSize / unitMetricLengthArr[1], 1)
  72. radius = ['0%', `${100 / metricCount / unitCount * rate * .75}%`]
  73. }
  74. }
  75. return { center, radius }
  76. }
  77. }
  78. }