CalendarModel.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. var zrUtil = require("zrender/lib/core/util");
  2. var ComponentModel = require("../../model/Component");
  3. var _layout = require("../../util/layout");
  4. var getLayoutParams = _layout.getLayoutParams;
  5. var sizeCalculable = _layout.sizeCalculable;
  6. var mergeLayoutParam = _layout.mergeLayoutParam;
  7. var CalendarModel = ComponentModel.extend({
  8. type: 'calendar',
  9. /**
  10. * @type {module:echarts/coord/calendar/Calendar}
  11. */
  12. coordinateSystem: null,
  13. defaultOption: {
  14. zlevel: 0,
  15. z: 2,
  16. left: 80,
  17. top: 60,
  18. cellSize: 20,
  19. // horizontal vertical
  20. orient: 'horizontal',
  21. // month separate line style
  22. splitLine: {
  23. show: true,
  24. lineStyle: {
  25. color: '#000',
  26. width: 1,
  27. type: 'solid'
  28. }
  29. },
  30. // rect style temporarily unused emphasis
  31. itemStyle: {
  32. normal: {
  33. color: '#fff',
  34. borderWidth: 1,
  35. borderColor: '#ccc'
  36. }
  37. },
  38. // week text style
  39. dayLabel: {
  40. show: true,
  41. // a week first day
  42. firstDay: 0,
  43. // start end
  44. position: 'start',
  45. margin: '50%',
  46. // 50% of cellSize
  47. nameMap: 'en',
  48. color: '#000'
  49. },
  50. // month text style
  51. monthLabel: {
  52. show: true,
  53. // start end
  54. position: 'start',
  55. margin: 5,
  56. // center or left
  57. align: 'center',
  58. // cn en []
  59. nameMap: 'en',
  60. formatter: null,
  61. color: '#000'
  62. },
  63. // year text style
  64. yearLabel: {
  65. show: true,
  66. // top bottom left right
  67. position: null,
  68. margin: 30,
  69. formatter: null,
  70. color: '#ccc',
  71. fontFamily: 'sans-serif',
  72. fontWeight: 'bolder',
  73. fontSize: 20
  74. }
  75. },
  76. /**
  77. * @override
  78. */
  79. init: function (option, parentModel, ecModel, extraOpt) {
  80. var inputPositionParams = getLayoutParams(option);
  81. CalendarModel.superApply(this, 'init', arguments);
  82. mergeAndNormalizeLayoutParams(option, inputPositionParams);
  83. },
  84. /**
  85. * @override
  86. */
  87. mergeOption: function (option, extraOpt) {
  88. CalendarModel.superApply(this, 'mergeOption', arguments);
  89. mergeAndNormalizeLayoutParams(this.option, option);
  90. }
  91. });
  92. function mergeAndNormalizeLayoutParams(target, raw) {
  93. // Normalize cellSize
  94. var cellSize = target.cellSize;
  95. if (!zrUtil.isArray(cellSize)) {
  96. cellSize = target.cellSize = [cellSize, cellSize];
  97. } else if (cellSize.length === 1) {
  98. cellSize[1] = cellSize[0];
  99. }
  100. var ignoreSize = zrUtil.map([0, 1], function (hvIdx) {
  101. // If user have set `width` or both `left` and `right`, cellSize
  102. // will be automatically set to 'auto', otherwise the default
  103. // setting of cellSize will make `width` setting not work.
  104. if (sizeCalculable(raw, hvIdx)) {
  105. cellSize[hvIdx] = 'auto';
  106. }
  107. return cellSize[hvIdx] != null && cellSize[hvIdx] !== 'auto';
  108. });
  109. mergeLayoutParam(target, raw, {
  110. type: 'box',
  111. ignoreSize: ignoreSize
  112. });
  113. }
  114. var _default = CalendarModel;
  115. module.exports = _default;