RadarModel.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing,
  13. * software distributed under the License is distributed on an
  14. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15. * KIND, either express or implied. See the License for the
  16. * specific language governing permissions and limitations
  17. * under the License.
  18. */
  19. var echarts = require("../../echarts");
  20. var zrUtil = require("zrender/lib/core/util");
  21. var axisDefault = require("../axisDefault");
  22. var Model = require("../../model/Model");
  23. var axisModelCommonMixin = require("../axisModelCommonMixin");
  24. /*
  25. * Licensed to the Apache Software Foundation (ASF) under one
  26. * or more contributor license agreements. See the NOTICE file
  27. * distributed with this work for additional information
  28. * regarding copyright ownership. The ASF licenses this file
  29. * to you under the Apache License, Version 2.0 (the
  30. * "License"); you may not use this file except in compliance
  31. * with the License. You may obtain a copy of the License at
  32. *
  33. * http://www.apache.org/licenses/LICENSE-2.0
  34. *
  35. * Unless required by applicable law or agreed to in writing,
  36. * software distributed under the License is distributed on an
  37. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  38. * KIND, either express or implied. See the License for the
  39. * specific language governing permissions and limitations
  40. * under the License.
  41. */
  42. var valueAxisDefault = axisDefault.valueAxis;
  43. function defaultsShow(opt, show) {
  44. return zrUtil.defaults({
  45. show: show
  46. }, opt);
  47. }
  48. var RadarModel = echarts.extendComponentModel({
  49. type: 'radar',
  50. optionUpdated: function () {
  51. var boundaryGap = this.get('boundaryGap');
  52. var splitNumber = this.get('splitNumber');
  53. var scale = this.get('scale');
  54. var axisLine = this.get('axisLine');
  55. var axisTick = this.get('axisTick');
  56. var axisType = this.get('axisType');
  57. var axisLabel = this.get('axisLabel');
  58. var nameTextStyle = this.get('name');
  59. var showName = this.get('name.show');
  60. var nameFormatter = this.get('name.formatter');
  61. var nameGap = this.get('nameGap');
  62. var triggerEvent = this.get('triggerEvent');
  63. var indicatorModels = zrUtil.map(this.get('indicator') || [], function (indicatorOpt) {
  64. // PENDING
  65. if (indicatorOpt.max != null && indicatorOpt.max > 0 && !indicatorOpt.min) {
  66. indicatorOpt.min = 0;
  67. } else if (indicatorOpt.min != null && indicatorOpt.min < 0 && !indicatorOpt.max) {
  68. indicatorOpt.max = 0;
  69. }
  70. var iNameTextStyle = nameTextStyle;
  71. if (indicatorOpt.color != null) {
  72. iNameTextStyle = zrUtil.defaults({
  73. color: indicatorOpt.color
  74. }, nameTextStyle);
  75. } // Use same configuration
  76. indicatorOpt = zrUtil.merge(zrUtil.clone(indicatorOpt), {
  77. boundaryGap: boundaryGap,
  78. splitNumber: splitNumber,
  79. scale: scale,
  80. axisLine: axisLine,
  81. axisTick: axisTick,
  82. axisType: axisType,
  83. axisLabel: axisLabel,
  84. // Compatible with 2 and use text
  85. name: indicatorOpt.text,
  86. nameLocation: 'end',
  87. nameGap: nameGap,
  88. // min: 0,
  89. nameTextStyle: iNameTextStyle,
  90. triggerEvent: triggerEvent
  91. }, false);
  92. if (!showName) {
  93. indicatorOpt.name = '';
  94. }
  95. if (typeof nameFormatter === 'string') {
  96. var indName = indicatorOpt.name;
  97. indicatorOpt.name = nameFormatter.replace('{value}', indName != null ? indName : '');
  98. } else if (typeof nameFormatter === 'function') {
  99. indicatorOpt.name = nameFormatter(indicatorOpt.name, indicatorOpt);
  100. }
  101. var model = zrUtil.extend(new Model(indicatorOpt, null, this.ecModel), axisModelCommonMixin); // For triggerEvent.
  102. model.mainType = 'radar';
  103. model.componentIndex = this.componentIndex;
  104. return model;
  105. }, this);
  106. this.getIndicatorModels = function () {
  107. return indicatorModels;
  108. };
  109. },
  110. defaultOption: {
  111. zlevel: 0,
  112. z: 0,
  113. center: ['50%', '50%'],
  114. radius: '75%',
  115. startAngle: 90,
  116. name: {
  117. show: true // formatter: null
  118. // textStyle: {}
  119. },
  120. boundaryGap: [0, 0],
  121. splitNumber: 5,
  122. nameGap: 15,
  123. scale: false,
  124. // Polygon or circle
  125. shape: 'polygon',
  126. axisLine: zrUtil.merge({
  127. lineStyle: {
  128. color: '#bbb'
  129. }
  130. }, valueAxisDefault.axisLine),
  131. axisLabel: defaultsShow(valueAxisDefault.axisLabel, false),
  132. axisTick: defaultsShow(valueAxisDefault.axisTick, false),
  133. axisType: 'interval',
  134. splitLine: defaultsShow(valueAxisDefault.splitLine, true),
  135. splitArea: defaultsShow(valueAxisDefault.splitArea, true),
  136. // {text, min, max}
  137. indicator: []
  138. }
  139. });
  140. var _default = RadarModel;
  141. module.exports = _default;