helper.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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 zrUtil = require("zrender/lib/core/util");
  20. var createListFromArray = require("./chart/helper/createListFromArray");
  21. var axisHelper = require("./coord/axisHelper");
  22. var axisModelCommonMixin = require("./coord/axisModelCommonMixin");
  23. var Model = require("./model/Model");
  24. var _layout = require("./util/layout");
  25. var getLayoutRect = _layout.getLayoutRect;
  26. exports.getLayoutRect = _layout.getLayoutRect;
  27. var _dataStackHelper = require("./data/helper/dataStackHelper");
  28. var enableDataStack = _dataStackHelper.enableDataStack;
  29. var isDimensionStacked = _dataStackHelper.isDimensionStacked;
  30. var getStackedDimension = _dataStackHelper.getStackedDimension;
  31. var _completeDimensions = require("./data/helper/completeDimensions");
  32. exports.completeDimensions = _completeDimensions;
  33. var _createDimensions = require("./data/helper/createDimensions");
  34. exports.createDimensions = _createDimensions;
  35. var _symbol = require("./util/symbol");
  36. exports.createSymbol = _symbol.createSymbol;
  37. /*
  38. * Licensed to the Apache Software Foundation (ASF) under one
  39. * or more contributor license agreements. See the NOTICE file
  40. * distributed with this work for additional information
  41. * regarding copyright ownership. The ASF licenses this file
  42. * to you under the Apache License, Version 2.0 (the
  43. * "License"); you may not use this file except in compliance
  44. * with the License. You may obtain a copy of the License at
  45. *
  46. * http://www.apache.org/licenses/LICENSE-2.0
  47. *
  48. * Unless required by applicable law or agreed to in writing,
  49. * software distributed under the License is distributed on an
  50. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  51. * KIND, either express or implied. See the License for the
  52. * specific language governing permissions and limitations
  53. * under the License.
  54. */
  55. // import createGraphFromNodeEdge from './chart/helper/createGraphFromNodeEdge';
  56. /**
  57. * Create a muti dimension List structure from seriesModel.
  58. * @param {module:echarts/model/Model} seriesModel
  59. * @return {module:echarts/data/List} list
  60. */
  61. function createList(seriesModel) {
  62. return createListFromArray(seriesModel.getSource(), seriesModel);
  63. } // export function createGraph(seriesModel) {
  64. // var nodes = seriesModel.get('data');
  65. // var links = seriesModel.get('links');
  66. // return createGraphFromNodeEdge(nodes, links, seriesModel);
  67. // }
  68. var dataStack = {
  69. isDimensionStacked: isDimensionStacked,
  70. enableDataStack: enableDataStack,
  71. getStackedDimension: getStackedDimension
  72. };
  73. /**
  74. * Create a symbol element with given symbol configuration: shape, x, y, width, height, color
  75. * @param {string} symbolDesc
  76. * @param {number} x
  77. * @param {number} y
  78. * @param {number} w
  79. * @param {number} h
  80. * @param {string} color
  81. */
  82. /**
  83. * Create scale
  84. * @param {Array.<number>} dataExtent
  85. * @param {Object|module:echarts/Model} option
  86. */
  87. function createScale(dataExtent, option) {
  88. var axisModel = option;
  89. if (!Model.isInstance(option)) {
  90. axisModel = new Model(option);
  91. zrUtil.mixin(axisModel, axisModelCommonMixin);
  92. }
  93. var scale = axisHelper.createScaleByModel(axisModel);
  94. scale.setExtent(dataExtent[0], dataExtent[1]);
  95. axisHelper.niceScaleExtent(scale, axisModel);
  96. return scale;
  97. }
  98. /**
  99. * Mixin common methods to axis model,
  100. *
  101. * Inlcude methods
  102. * `getFormattedLabels() => Array.<string>`
  103. * `getCategories() => Array.<string>`
  104. * `getMin(origin: boolean) => number`
  105. * `getMax(origin: boolean) => number`
  106. * `getNeedCrossZero() => boolean`
  107. * `setRange(start: number, end: number)`
  108. * `resetRange()`
  109. */
  110. function mixinAxisModelCommonMethods(Model) {
  111. zrUtil.mixin(Model, axisModelCommonMixin);
  112. }
  113. exports.createList = createList;
  114. exports.dataStack = dataStack;
  115. exports.createScale = createScale;
  116. exports.mixinAxisModelCommonMethods = mixinAxisModelCommonMethods;