RadarModel.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. var echarts = require("../../echarts");
  2. var zrUtil = require("zrender/lib/core/util");
  3. var axisDefault = require("../axisDefault");
  4. var Model = require("../../model/Model");
  5. var axisModelCommonMixin = require("../axisModelCommonMixin");
  6. var valueAxisDefault = axisDefault.valueAxis;
  7. function defaultsShow(opt, show) {
  8. return zrUtil.defaults({
  9. show: show
  10. }, opt);
  11. }
  12. var RadarModel = echarts.extendComponentModel({
  13. type: 'radar',
  14. optionUpdated: function () {
  15. var boundaryGap = this.get('boundaryGap');
  16. var splitNumber = this.get('splitNumber');
  17. var scale = this.get('scale');
  18. var axisLine = this.get('axisLine');
  19. var axisTick = this.get('axisTick');
  20. var axisLabel = this.get('axisLabel');
  21. var nameTextStyle = this.get('name');
  22. var showName = this.get('name.show');
  23. var nameFormatter = this.get('name.formatter');
  24. var nameGap = this.get('nameGap');
  25. var triggerEvent = this.get('triggerEvent');
  26. var indicatorModels = zrUtil.map(this.get('indicator') || [], function (indicatorOpt) {
  27. // PENDING
  28. if (indicatorOpt.max != null && indicatorOpt.max > 0 && !indicatorOpt.min) {
  29. indicatorOpt.min = 0;
  30. } else if (indicatorOpt.min != null && indicatorOpt.min < 0 && !indicatorOpt.max) {
  31. indicatorOpt.max = 0;
  32. }
  33. var iNameTextStyle = nameTextStyle;
  34. if (indicatorOpt.color != null) {
  35. iNameTextStyle = zrUtil.defaults({
  36. color: indicatorOpt.color
  37. }, nameTextStyle);
  38. } // Use same configuration
  39. indicatorOpt = zrUtil.merge(zrUtil.clone(indicatorOpt), {
  40. boundaryGap: boundaryGap,
  41. splitNumber: splitNumber,
  42. scale: scale,
  43. axisLine: axisLine,
  44. axisTick: axisTick,
  45. axisLabel: axisLabel,
  46. // Competitable with 2 and use text
  47. name: indicatorOpt.text,
  48. nameLocation: 'end',
  49. nameGap: nameGap,
  50. // min: 0,
  51. nameTextStyle: iNameTextStyle,
  52. triggerEvent: triggerEvent
  53. }, false);
  54. if (!showName) {
  55. indicatorOpt.name = '';
  56. }
  57. if (typeof nameFormatter === 'string') {
  58. var indName = indicatorOpt.name;
  59. indicatorOpt.name = nameFormatter.replace('{value}', indName != null ? indName : '');
  60. } else if (typeof nameFormatter === 'function') {
  61. indicatorOpt.name = nameFormatter(indicatorOpt.name, indicatorOpt);
  62. }
  63. var model = zrUtil.extend(new Model(indicatorOpt, null, this.ecModel), axisModelCommonMixin); // For triggerEvent.
  64. model.mainType = 'radar';
  65. model.componentIndex = this.componentIndex;
  66. return model;
  67. }, this);
  68. this.getIndicatorModels = function () {
  69. return indicatorModels;
  70. };
  71. },
  72. defaultOption: {
  73. zlevel: 0,
  74. z: 0,
  75. center: ['50%', '50%'],
  76. radius: '75%',
  77. startAngle: 90,
  78. name: {
  79. show: true // formatter: null
  80. // textStyle: {}
  81. },
  82. boundaryGap: [0, 0],
  83. splitNumber: 5,
  84. nameGap: 15,
  85. scale: false,
  86. // Polygon or circle
  87. shape: 'polygon',
  88. axisLine: zrUtil.merge({
  89. lineStyle: {
  90. color: '#bbb'
  91. }
  92. }, valueAxisDefault.axisLine),
  93. axisLabel: defaultsShow(valueAxisDefault.axisLabel, false),
  94. axisTick: defaultsShow(valueAxisDefault.axisTick, false),
  95. splitLine: defaultsShow(valueAxisDefault.splitLine, true),
  96. splitArea: defaultsShow(valueAxisDefault.splitArea, true),
  97. // {text, min, max}
  98. indicator: []
  99. }
  100. });
  101. var _default = RadarModel;
  102. module.exports = _default;