helper.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. import * as zrUtil from 'zrender/src/core/util';
  20. import createListFromArray from './chart/helper/createListFromArray';
  21. // import createGraphFromNodeEdge from './chart/helper/createGraphFromNodeEdge';
  22. import * as axisHelper from './coord/axisHelper';
  23. import axisModelCommonMixin from './coord/axisModelCommonMixin';
  24. import Model from './model/Model';
  25. import {getLayoutRect} from './util/layout';
  26. import {
  27. enableDataStack,
  28. isDimensionStacked,
  29. getStackedDimension
  30. } from './data/helper/dataStackHelper';
  31. /**
  32. * Create a muti dimension List structure from seriesModel.
  33. * @param {module:echarts/model/Model} seriesModel
  34. * @return {module:echarts/data/List} list
  35. */
  36. export function createList(seriesModel) {
  37. return createListFromArray(seriesModel.getSource(), seriesModel);
  38. }
  39. // export function createGraph(seriesModel) {
  40. // var nodes = seriesModel.get('data');
  41. // var links = seriesModel.get('links');
  42. // return createGraphFromNodeEdge(nodes, links, seriesModel);
  43. // }
  44. export {getLayoutRect};
  45. /**
  46. * // TODO: @deprecated
  47. */
  48. export {default as completeDimensions} from './data/helper/completeDimensions';
  49. export {default as createDimensions} from './data/helper/createDimensions';
  50. export var dataStack = {
  51. isDimensionStacked: isDimensionStacked,
  52. enableDataStack: enableDataStack,
  53. getStackedDimension: getStackedDimension
  54. };
  55. /**
  56. * Create a symbol element with given symbol configuration: shape, x, y, width, height, color
  57. * @param {string} symbolDesc
  58. * @param {number} x
  59. * @param {number} y
  60. * @param {number} w
  61. * @param {number} h
  62. * @param {string} color
  63. */
  64. export {createSymbol} from './util/symbol';
  65. /**
  66. * Create scale
  67. * @param {Array.<number>} dataExtent
  68. * @param {Object|module:echarts/Model} option
  69. */
  70. export function createScale(dataExtent, option) {
  71. var axisModel = option;
  72. if (!Model.isInstance(option)) {
  73. axisModel = new Model(option);
  74. zrUtil.mixin(axisModel, axisModelCommonMixin);
  75. }
  76. var scale = axisHelper.createScaleByModel(axisModel);
  77. scale.setExtent(dataExtent[0], dataExtent[1]);
  78. axisHelper.niceScaleExtent(scale, axisModel);
  79. return scale;
  80. }
  81. /**
  82. * Mixin common methods to axis model,
  83. *
  84. * Inlcude methods
  85. * `getFormattedLabels() => Array.<string>`
  86. * `getCategories() => Array.<string>`
  87. * `getMin(origin: boolean) => number`
  88. * `getMax(origin: boolean) => number`
  89. * `getNeedCrossZero() => boolean`
  90. * `setRange(start: number, end: number)`
  91. * `resetRange()`
  92. */
  93. export function mixinAxisModelCommonMethods(Model) {
  94. zrUtil.mixin(Model, axisModelCommonMixin);
  95. }