f2fce190827d19a9e36e9a4dfb8c0cb68ee48f103ac322e6298b23d9088bb2cd98878074882c2a5a82ed00b157752424dbbb0ff96b38c110e498a6e166fce3 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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. /**
  20. * AUTO-GENERATED FILE. DO NOT MODIFY.
  21. */
  22. /*
  23. * Licensed to the Apache Software Foundation (ASF) under one
  24. * or more contributor license agreements. See the NOTICE file
  25. * distributed with this work for additional information
  26. * regarding copyright ownership. The ASF licenses this file
  27. * to you under the Apache License, Version 2.0 (the
  28. * "License"); you may not use this file except in compliance
  29. * with the License. You may obtain a copy of the License at
  30. *
  31. * http://www.apache.org/licenses/LICENSE-2.0
  32. *
  33. * Unless required by applicable law or agreed to in writing,
  34. * software distributed under the License is distributed on an
  35. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  36. * KIND, either express or implied. See the License for the
  37. * specific language governing permissions and limitations
  38. * under the License.
  39. */
  40. import { __extends } from "tslib";
  41. import * as echarts from '../../../core/echarts.js';
  42. import * as zrUtil from 'zrender/lib/core/util.js';
  43. import { ToolboxFeature } from '../featureManager.js';
  44. import { SINGLE_REFERRING } from '../../../util/model.js';
  45. var INNER_STACK_KEYWORD = '__ec_magicType_stack__';
  46. var ICON_TYPES = ['line', 'bar', 'stack']; // stack and tiled appears in pair for the title
  47. var TITLE_TYPES = ['line', 'bar', 'stack', 'tiled'];
  48. var radioTypes = [['line', 'bar'], ['stack']];
  49. var MagicType =
  50. /** @class */
  51. function (_super) {
  52. __extends(MagicType, _super);
  53. function MagicType() {
  54. return _super !== null && _super.apply(this, arguments) || this;
  55. }
  56. MagicType.prototype.getIcons = function () {
  57. var model = this.model;
  58. var availableIcons = model.get('icon');
  59. var icons = {};
  60. zrUtil.each(model.get('type'), function (type) {
  61. if (availableIcons[type]) {
  62. icons[type] = availableIcons[type];
  63. }
  64. });
  65. return icons;
  66. };
  67. MagicType.getDefaultOption = function (ecModel) {
  68. var defaultOption = {
  69. show: true,
  70. type: [],
  71. // Icon group
  72. icon: {
  73. line: 'M4.1,28.9h7.1l9.3-22l7.4,38l9.7-19.7l3,12.8h14.9M4.1,58h51.4',
  74. bar: 'M6.7,22.9h10V48h-10V22.9zM24.9,13h10v35h-10V13zM43.2,2h10v46h-10V2zM3.1,58h53.7',
  75. // eslint-disable-next-line
  76. stack: 'M8.2,38.4l-8.4,4.1l30.6,15.3L60,42.5l-8.1-4.1l-21.5,11L8.2,38.4z M51.9,30l-8.1,4.2l-13.4,6.9l-13.9-6.9L8.2,30l-8.4,4.2l8.4,4.2l22.2,11l21.5-11l8.1-4.2L51.9,30z M51.9,21.7l-8.1,4.2L35.7,30l-5.3,2.8L24.9,30l-8.4-4.1l-8.3-4.2l-8.4,4.2L8.2,30l8.3,4.2l13.9,6.9l13.4-6.9l8.1-4.2l8.1-4.1L51.9,21.7zM30.4,2.2L-0.2,17.5l8.4,4.1l8.3,4.2l8.4,4.2l5.5,2.7l5.3-2.7l8.1-4.2l8.1-4.2l8.1-4.1L30.4,2.2z' // jshint ignore:line
  77. },
  78. // `line`, `bar`, `stack`, `tiled`
  79. title: ecModel.getLocaleModel().get(['toolbox', 'magicType', 'title']),
  80. option: {},
  81. seriesIndex: {}
  82. };
  83. return defaultOption;
  84. };
  85. MagicType.prototype.onclick = function (ecModel, api, type) {
  86. var model = this.model;
  87. var seriesIndex = model.get(['seriesIndex', type]); // Not supported magicType
  88. if (!seriesOptGenreator[type]) {
  89. return;
  90. }
  91. var newOption = {
  92. series: []
  93. };
  94. var generateNewSeriesTypes = function (seriesModel) {
  95. var seriesType = seriesModel.subType;
  96. var seriesId = seriesModel.id;
  97. var newSeriesOpt = seriesOptGenreator[type](seriesType, seriesId, seriesModel, model);
  98. if (newSeriesOpt) {
  99. // PENDING If merge original option?
  100. zrUtil.defaults(newSeriesOpt, seriesModel.option);
  101. newOption.series.push(newSeriesOpt);
  102. } // Modify boundaryGap
  103. var coordSys = seriesModel.coordinateSystem;
  104. if (coordSys && coordSys.type === 'cartesian2d' && (type === 'line' || type === 'bar')) {
  105. var categoryAxis = coordSys.getAxesByScale('ordinal')[0];
  106. if (categoryAxis) {
  107. var axisDim = categoryAxis.dim;
  108. var axisType = axisDim + 'Axis';
  109. var axisModel = seriesModel.getReferringComponents(axisType, SINGLE_REFERRING).models[0];
  110. var axisIndex = axisModel.componentIndex;
  111. newOption[axisType] = newOption[axisType] || [];
  112. for (var i = 0; i <= axisIndex; i++) {
  113. newOption[axisType][axisIndex] = newOption[axisType][axisIndex] || {};
  114. }
  115. newOption[axisType][axisIndex].boundaryGap = type === 'bar';
  116. }
  117. }
  118. };
  119. zrUtil.each(radioTypes, function (radio) {
  120. if (zrUtil.indexOf(radio, type) >= 0) {
  121. zrUtil.each(radio, function (item) {
  122. model.setIconStatus(item, 'normal');
  123. });
  124. }
  125. });
  126. model.setIconStatus(type, 'emphasis');
  127. ecModel.eachComponent({
  128. mainType: 'series',
  129. query: seriesIndex == null ? null : {
  130. seriesIndex: seriesIndex
  131. }
  132. }, generateNewSeriesTypes);
  133. var newTitle;
  134. var currentType = type; // Change title of stack
  135. if (type === 'stack') {
  136. // use titles in model instead of ecModel
  137. // as stack and tiled appears in pair, just flip them
  138. // no need of checking stack state
  139. newTitle = zrUtil.merge({
  140. stack: model.option.title.tiled,
  141. tiled: model.option.title.stack
  142. }, model.option.title);
  143. if (model.get(['iconStatus', type]) !== 'emphasis') {
  144. currentType = 'tiled';
  145. }
  146. }
  147. api.dispatchAction({
  148. type: 'changeMagicType',
  149. currentType: currentType,
  150. newOption: newOption,
  151. newTitle: newTitle,
  152. featureName: 'magicType'
  153. });
  154. };
  155. return MagicType;
  156. }(ToolboxFeature);
  157. var seriesOptGenreator = {
  158. 'line': function (seriesType, seriesId, seriesModel, model) {
  159. if (seriesType === 'bar') {
  160. return zrUtil.merge({
  161. id: seriesId,
  162. type: 'line',
  163. // Preserve data related option
  164. data: seriesModel.get('data'),
  165. stack: seriesModel.get('stack'),
  166. markPoint: seriesModel.get('markPoint'),
  167. markLine: seriesModel.get('markLine')
  168. }, model.get(['option', 'line']) || {}, true);
  169. }
  170. },
  171. 'bar': function (seriesType, seriesId, seriesModel, model) {
  172. if (seriesType === 'line') {
  173. return zrUtil.merge({
  174. id: seriesId,
  175. type: 'bar',
  176. // Preserve data related option
  177. data: seriesModel.get('data'),
  178. stack: seriesModel.get('stack'),
  179. markPoint: seriesModel.get('markPoint'),
  180. markLine: seriesModel.get('markLine')
  181. }, model.get(['option', 'bar']) || {}, true);
  182. }
  183. },
  184. 'stack': function (seriesType, seriesId, seriesModel, model) {
  185. var isStack = seriesModel.get('stack') === INNER_STACK_KEYWORD;
  186. if (seriesType === 'line' || seriesType === 'bar') {
  187. model.setIconStatus('stack', isStack ? 'normal' : 'emphasis');
  188. return zrUtil.merge({
  189. id: seriesId,
  190. stack: isStack ? '' : INNER_STACK_KEYWORD
  191. }, model.get(['option', 'stack']) || {}, true);
  192. }
  193. }
  194. }; // TODO: SELF REGISTERED.
  195. echarts.registerAction({
  196. type: 'changeMagicType',
  197. event: 'magicTypeChanged',
  198. update: 'prepareAndUpdate'
  199. }, function (payload, ecModel) {
  200. ecModel.mergeOption(payload.newOption);
  201. });
  202. export default MagicType;