helper.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. var zrUtil = require("zrender/lib/core/util");
  2. var _layout = require("../../util/layout");
  3. var getLayoutRect = _layout.getLayoutRect;
  4. /**
  5. * @param {module:echarts/component/visualMap/VisualMapModel} visualMapModel\
  6. * @param {module:echarts/ExtensionAPI} api
  7. * @param {Array.<number>} itemSize always [short, long]
  8. * @return {string} 'left' or 'right' or 'top' or 'bottom'
  9. */
  10. function getItemAlign(visualMapModel, api, itemSize) {
  11. var modelOption = visualMapModel.option;
  12. var itemAlign = modelOption.align;
  13. if (itemAlign != null && itemAlign !== 'auto') {
  14. return itemAlign;
  15. } // Auto decision align.
  16. var ecSize = {
  17. width: api.getWidth(),
  18. height: api.getHeight()
  19. };
  20. var realIndex = modelOption.orient === 'horizontal' ? 1 : 0;
  21. var paramsSet = [['left', 'right', 'width'], ['top', 'bottom', 'height']];
  22. var reals = paramsSet[realIndex];
  23. var fakeValue = [0, null, 10];
  24. var layoutInput = {};
  25. for (var i = 0; i < 3; i++) {
  26. layoutInput[paramsSet[1 - realIndex][i]] = fakeValue[i];
  27. layoutInput[reals[i]] = i === 2 ? itemSize[0] : modelOption[reals[i]];
  28. }
  29. var rParam = [['x', 'width', 3], ['y', 'height', 0]][realIndex];
  30. var rect = getLayoutRect(layoutInput, ecSize, modelOption.padding);
  31. return reals[(rect.margin[rParam[2]] || 0) + rect[rParam[0]] + rect[rParam[1]] * 0.5 < ecSize[rParam[1]] * 0.5 ? 0 : 1];
  32. }
  33. /**
  34. * Prepare dataIndex for outside usage, where dataIndex means rawIndex, and
  35. * dataIndexInside means filtered index.
  36. */
  37. function convertDataIndex(batch) {
  38. zrUtil.each(batch || [], function (batchItem) {
  39. if (batch.dataIndex != null) {
  40. batch.dataIndexInside = batch.dataIndex;
  41. batch.dataIndex = null;
  42. }
  43. });
  44. return batch;
  45. }
  46. exports.getItemAlign = getItemAlign;
  47. exports.convertDataIndex = convertDataIndex;