ScrollableLegendModel.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. var LegendModel = require("./LegendModel");
  2. var _layout = require("../../util/layout");
  3. var mergeLayoutParam = _layout.mergeLayoutParam;
  4. var getLayoutParams = _layout.getLayoutParams;
  5. var ScrollableLegendModel = LegendModel.extend({
  6. type: 'legend.scroll',
  7. /**
  8. * @param {number} scrollDataIndex
  9. */
  10. setScrollDataIndex: function (scrollDataIndex) {
  11. this.option.scrollDataIndex = scrollDataIndex;
  12. },
  13. defaultOption: {
  14. scrollDataIndex: 0,
  15. pageButtonItemGap: 5,
  16. pageButtonGap: null,
  17. pageButtonPosition: 'end',
  18. // 'start' or 'end'
  19. pageFormatter: '{current}/{total}',
  20. // If null/undefined, do not show page.
  21. pageIcons: {
  22. horizontal: ['M0,0L12,-10L12,10z', 'M0,0L-12,-10L-12,10z'],
  23. vertical: ['M0,0L20,0L10,-20z', 'M0,0L20,0L10,20z']
  24. },
  25. pageIconColor: '#2f4554',
  26. pageIconInactiveColor: '#aaa',
  27. pageIconSize: 15,
  28. // Can be [10, 3], which represents [width, height]
  29. pageTextStyle: {
  30. color: '#333'
  31. },
  32. animationDurationUpdate: 800
  33. },
  34. /**
  35. * @override
  36. */
  37. init: function (option, parentModel, ecModel, extraOpt) {
  38. var inputPositionParams = getLayoutParams(option);
  39. ScrollableLegendModel.superCall(this, 'init', option, parentModel, ecModel, extraOpt);
  40. mergeAndNormalizeLayoutParams(this, option, inputPositionParams);
  41. },
  42. /**
  43. * @override
  44. */
  45. mergeOption: function (option, extraOpt) {
  46. ScrollableLegendModel.superCall(this, 'mergeOption', option, extraOpt);
  47. mergeAndNormalizeLayoutParams(this, this.option, option);
  48. },
  49. getOrient: function () {
  50. return this.get('orient') === 'vertical' ? {
  51. index: 1,
  52. name: 'vertical'
  53. } : {
  54. index: 0,
  55. name: 'horizontal'
  56. };
  57. }
  58. }); // Do not `ignoreSize` to enable setting {left: 10, right: 10}.
  59. function mergeAndNormalizeLayoutParams(legendModel, target, raw) {
  60. var orient = legendModel.getOrient();
  61. var ignoreSize = [1, 1];
  62. ignoreSize[orient.index] = 0;
  63. mergeLayoutParam(target, raw, {
  64. type: 'box',
  65. ignoreSize: ignoreSize
  66. });
  67. }
  68. var _default = ScrollableLegendModel;
  69. module.exports = _default;