ParallelSeries.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. var List = require("../../data/List");
  2. var zrUtil = require("zrender/lib/core/util");
  3. var SeriesModel = require("../../model/Series");
  4. var completeDimensions = require("../../data/helper/completeDimensions");
  5. var _default = SeriesModel.extend({
  6. type: 'series.parallel',
  7. dependencies: ['parallel'],
  8. visualColorAccessPath: 'lineStyle.normal.color',
  9. getInitialData: function (option, ecModel) {
  10. var parallelModel = ecModel.getComponent('parallel', this.get('parallelIndex'));
  11. var parallelAxisIndices = parallelModel.parallelAxisIndex;
  12. var rawData = option.data;
  13. var modelDims = parallelModel.dimensions;
  14. var dataDims = generateDataDims(modelDims, rawData);
  15. var dataDimsInfo = zrUtil.map(dataDims, function (dim, dimIndex) {
  16. var modelDimsIndex = zrUtil.indexOf(modelDims, dim);
  17. var axisModel = modelDimsIndex >= 0 && ecModel.getComponent('parallelAxis', parallelAxisIndices[modelDimsIndex]);
  18. if (axisModel && axisModel.get('type') === 'category') {
  19. translateCategoryValue(axisModel, dim, rawData);
  20. return {
  21. name: dim,
  22. type: 'ordinal'
  23. };
  24. } else if (modelDimsIndex < 0) {
  25. return completeDimensions.guessOrdinal(rawData, dimIndex) ? {
  26. name: dim,
  27. type: 'ordinal'
  28. } : dim;
  29. } else {
  30. return dim;
  31. }
  32. });
  33. var list = new List(dataDimsInfo, this);
  34. list.initData(rawData); // Anication is forbiden in progressive data mode.
  35. if (this.option.progressive) {
  36. this.option.animation = false;
  37. }
  38. return list;
  39. },
  40. /**
  41. * User can get data raw indices on 'axisAreaSelected' event received.
  42. *
  43. * @public
  44. * @param {string} activeState 'active' or 'inactive' or 'normal'
  45. * @return {Array.<number>} Raw indices
  46. */
  47. getRawIndicesByActiveState: function (activeState) {
  48. var coordSys = this.coordinateSystem;
  49. var data = this.getData();
  50. var indices = [];
  51. coordSys.eachActiveState(data, function (theActiveState, dataIndex) {
  52. if (activeState === theActiveState) {
  53. indices.push(data.getRawIndex(dataIndex));
  54. }
  55. });
  56. return indices;
  57. },
  58. defaultOption: {
  59. zlevel: 0,
  60. // 一级层叠
  61. z: 2,
  62. // 二级层叠
  63. coordinateSystem: 'parallel',
  64. parallelIndex: 0,
  65. label: {
  66. normal: {
  67. show: false
  68. },
  69. emphasis: {
  70. show: false
  71. }
  72. },
  73. inactiveOpacity: 0.05,
  74. activeOpacity: 1,
  75. lineStyle: {
  76. normal: {
  77. width: 1,
  78. opacity: 0.45,
  79. type: 'solid'
  80. }
  81. },
  82. progressive: false,
  83. // 100
  84. smooth: false,
  85. animationEasing: 'linear'
  86. }
  87. });
  88. function translateCategoryValue(axisModel, dim, rawData) {
  89. var axisData = axisModel.get('data');
  90. var numberDim = convertDimNameToNumber(dim);
  91. if (axisData && axisData.length) {
  92. zrUtil.each(rawData, function (dataItem) {
  93. if (!dataItem) {
  94. return;
  95. } // FIXME
  96. // time consuming, should use hash?
  97. var index = zrUtil.indexOf(axisData, dataItem[numberDim]);
  98. dataItem[numberDim] = index >= 0 ? index : NaN;
  99. });
  100. } // FIXME
  101. // 如果没有设置axis data, 应自动算出,或者提示。
  102. }
  103. function convertDimNameToNumber(dimName) {
  104. return +dimName.replace('dim', '');
  105. }
  106. function generateDataDims(modelDims, rawData) {
  107. // parallelModel.dimension should not be regarded as data
  108. // dimensions. Consider dimensions = ['dim4', 'dim2', 'dim6'];
  109. // We detect max dim by parallelModel.dimensions and fist
  110. // item in rawData arbitrarily.
  111. var maxDimNum = 0;
  112. zrUtil.each(modelDims, function (dimName) {
  113. var numberDim = convertDimNameToNumber(dimName);
  114. numberDim > maxDimNum && (maxDimNum = numberDim);
  115. });
  116. var firstItem = rawData[0];
  117. if (firstItem && firstItem.length - 1 > maxDimNum) {
  118. maxDimNum = firstItem.length - 1;
  119. }
  120. var dataDims = [];
  121. for (var i = 0; i <= maxDimNum; i++) {
  122. dataDims.push('dim' + i);
  123. }
  124. return dataDims;
  125. }
  126. module.exports = _default;