ScrollableLegendModel.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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 LegendModel = require("./LegendModel");
  20. var _layout = require("../../util/layout");
  21. var mergeLayoutParam = _layout.mergeLayoutParam;
  22. var getLayoutParams = _layout.getLayoutParams;
  23. /*
  24. * Licensed to the Apache Software Foundation (ASF) under one
  25. * or more contributor license agreements. See the NOTICE file
  26. * distributed with this work for additional information
  27. * regarding copyright ownership. The ASF licenses this file
  28. * to you under the Apache License, Version 2.0 (the
  29. * "License"); you may not use this file except in compliance
  30. * with the License. You may obtain a copy of the License at
  31. *
  32. * http://www.apache.org/licenses/LICENSE-2.0
  33. *
  34. * Unless required by applicable law or agreed to in writing,
  35. * software distributed under the License is distributed on an
  36. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  37. * KIND, either express or implied. See the License for the
  38. * specific language governing permissions and limitations
  39. * under the License.
  40. */
  41. var ScrollableLegendModel = LegendModel.extend({
  42. type: 'legend.scroll',
  43. /**
  44. * @param {number} scrollDataIndex
  45. */
  46. setScrollDataIndex: function (scrollDataIndex) {
  47. this.option.scrollDataIndex = scrollDataIndex;
  48. },
  49. defaultOption: {
  50. scrollDataIndex: 0,
  51. pageButtonItemGap: 5,
  52. pageButtonGap: null,
  53. pageButtonPosition: 'end',
  54. // 'start' or 'end'
  55. pageFormatter: '{current}/{total}',
  56. // If null/undefined, do not show page.
  57. pageIcons: {
  58. horizontal: ['M0,0L12,-10L12,10z', 'M0,0L-12,-10L-12,10z'],
  59. vertical: ['M0,0L20,0L10,-20z', 'M0,0L20,0L10,20z']
  60. },
  61. pageIconColor: '#2f4554',
  62. pageIconInactiveColor: '#aaa',
  63. pageIconSize: 15,
  64. // Can be [10, 3], which represents [width, height]
  65. pageTextStyle: {
  66. color: '#333'
  67. },
  68. animationDurationUpdate: 800
  69. },
  70. /**
  71. * @override
  72. */
  73. init: function (option, parentModel, ecModel, extraOpt) {
  74. var inputPositionParams = getLayoutParams(option);
  75. ScrollableLegendModel.superCall(this, 'init', option, parentModel, ecModel, extraOpt);
  76. mergeAndNormalizeLayoutParams(this, option, inputPositionParams);
  77. },
  78. /**
  79. * @override
  80. */
  81. mergeOption: function (option, extraOpt) {
  82. ScrollableLegendModel.superCall(this, 'mergeOption', option, extraOpt);
  83. mergeAndNormalizeLayoutParams(this, this.option, option);
  84. }
  85. }); // Do not `ignoreSize` to enable setting {left: 10, right: 10}.
  86. function mergeAndNormalizeLayoutParams(legendModel, target, raw) {
  87. var orient = legendModel.getOrient();
  88. var ignoreSize = [1, 1];
  89. ignoreSize[orient.index] = 0;
  90. mergeLayoutParam(target, raw, {
  91. type: 'box',
  92. ignoreSize: ignoreSize
  93. });
  94. }
  95. var _default = ScrollableLegendModel;
  96. module.exports = _default;