CalendarModel.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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 zrUtil = require("zrender/lib/core/util");
  20. var ComponentModel = require("../../model/Component");
  21. var _layout = require("../../util/layout");
  22. var getLayoutParams = _layout.getLayoutParams;
  23. var sizeCalculable = _layout.sizeCalculable;
  24. var mergeLayoutParam = _layout.mergeLayoutParam;
  25. /*
  26. * Licensed to the Apache Software Foundation (ASF) under one
  27. * or more contributor license agreements. See the NOTICE file
  28. * distributed with this work for additional information
  29. * regarding copyright ownership. The ASF licenses this file
  30. * to you under the Apache License, Version 2.0 (the
  31. * "License"); you may not use this file except in compliance
  32. * with the License. You may obtain a copy of the License at
  33. *
  34. * http://www.apache.org/licenses/LICENSE-2.0
  35. *
  36. * Unless required by applicable law or agreed to in writing,
  37. * software distributed under the License is distributed on an
  38. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  39. * KIND, either express or implied. See the License for the
  40. * specific language governing permissions and limitations
  41. * under the License.
  42. */
  43. var CalendarModel = ComponentModel.extend({
  44. type: 'calendar',
  45. /**
  46. * @type {module:echarts/coord/calendar/Calendar}
  47. */
  48. coordinateSystem: null,
  49. defaultOption: {
  50. zlevel: 0,
  51. z: 2,
  52. left: 80,
  53. top: 60,
  54. cellSize: 20,
  55. // horizontal vertical
  56. orient: 'horizontal',
  57. // month separate line style
  58. splitLine: {
  59. show: true,
  60. lineStyle: {
  61. color: '#000',
  62. width: 1,
  63. type: 'solid'
  64. }
  65. },
  66. // rect style temporarily unused emphasis
  67. itemStyle: {
  68. color: '#fff',
  69. borderWidth: 1,
  70. borderColor: '#ccc'
  71. },
  72. // week text style
  73. dayLabel: {
  74. show: true,
  75. // a week first day
  76. firstDay: 0,
  77. // start end
  78. position: 'start',
  79. margin: '50%',
  80. // 50% of cellSize
  81. nameMap: 'en',
  82. color: '#000'
  83. },
  84. // month text style
  85. monthLabel: {
  86. show: true,
  87. // start end
  88. position: 'start',
  89. margin: 5,
  90. // center or left
  91. align: 'center',
  92. // cn en []
  93. nameMap: 'en',
  94. formatter: null,
  95. color: '#000'
  96. },
  97. // year text style
  98. yearLabel: {
  99. show: true,
  100. // top bottom left right
  101. position: null,
  102. margin: 30,
  103. formatter: null,
  104. color: '#ccc',
  105. fontFamily: 'sans-serif',
  106. fontWeight: 'bolder',
  107. fontSize: 20
  108. }
  109. },
  110. /**
  111. * @override
  112. */
  113. init: function (option, parentModel, ecModel, extraOpt) {
  114. var inputPositionParams = getLayoutParams(option);
  115. CalendarModel.superApply(this, 'init', arguments);
  116. mergeAndNormalizeLayoutParams(option, inputPositionParams);
  117. },
  118. /**
  119. * @override
  120. */
  121. mergeOption: function (option, extraOpt) {
  122. CalendarModel.superApply(this, 'mergeOption', arguments);
  123. mergeAndNormalizeLayoutParams(this.option, option);
  124. }
  125. });
  126. function mergeAndNormalizeLayoutParams(target, raw) {
  127. // Normalize cellSize
  128. var cellSize = target.cellSize;
  129. if (!zrUtil.isArray(cellSize)) {
  130. cellSize = target.cellSize = [cellSize, cellSize];
  131. } else if (cellSize.length === 1) {
  132. cellSize[1] = cellSize[0];
  133. }
  134. var ignoreSize = zrUtil.map([0, 1], function (hvIdx) {
  135. // If user have set `width` or both `left` and `right`, cellSize
  136. // will be automatically set to 'auto', otherwise the default
  137. // setting of cellSize will make `width` setting not work.
  138. if (sizeCalculable(raw, hvIdx)) {
  139. cellSize[hvIdx] = 'auto';
  140. }
  141. return cellSize[hvIdx] != null && cellSize[hvIdx] !== 'auto';
  142. });
  143. mergeLayoutParam(target, raw, {
  144. type: 'box',
  145. ignoreSize: ignoreSize
  146. });
  147. }
  148. var _default = CalendarModel;
  149. module.exports = _default;