PageRenderTime 20ms CodeModel.GetById 7ms RepoModel.GetById 1ms app.codeStats 0ms

/timeline/ext/planning/scripts/ether-painters.js

http://showslow.googlecode.com/
JavaScript | 176 lines | 141 code | 27 blank | 8 comment | 20 complexity | 08edb6e5459dc7cff644696f38f97440 MD5 | raw file
  1. /*==================================================
  2. * Planning Ether Painter
  3. *==================================================
  4. */
  5. Timeline.PlanningEtherPainter = function(params, band, timeline) {
  6. this._params = params;
  7. this._intervalUnit = params.intervalUnit;
  8. this._multiple = ("multiple" in params) ? params.multiple : 1;
  9. this._theme = params.theme;
  10. };
  11. Timeline.PlanningEtherPainter.prototype.initialize = function(band, timeline) {
  12. this._band = band;
  13. this._timeline = timeline;
  14. this._backgroundLayer = band.createLayerDiv(0);
  15. this._backgroundLayer.setAttribute("name", "ether-background"); // for debugging
  16. this._backgroundLayer.style.background = this._theme.ether.backgroundColors[band.getIndex()];
  17. this._markerLayer = null;
  18. this._lineLayer = null;
  19. var align = ("align" in this._params && typeof this._params.align == "string") ? this._params.align :
  20. this._theme.ether.interval.marker[timeline.isHorizontal() ? "hAlign" : "vAlign"];
  21. var showLine = ("showLine" in this._params) ? this._params.showLine :
  22. this._theme.ether.interval.line.show;
  23. this._intervalMarkerLayout = new Timeline.PlanningEtherMarkerLayout(
  24. this._timeline, this._band, this._theme, align, showLine);
  25. this._highlight = new Timeline.EtherHighlight(
  26. this._timeline, this._band, this._theme, this._backgroundLayer);
  27. }
  28. Timeline.PlanningEtherPainter.prototype.setHighlight = function(startDate, endDate) {
  29. this._highlight.position(startDate, endDate);
  30. }
  31. Timeline.PlanningEtherPainter.prototype.paint = function() {
  32. if (this._markerLayer) {
  33. this._band.removeLayerDiv(this._markerLayer);
  34. }
  35. this._markerLayer = this._band.createLayerDiv(100);
  36. this._markerLayer.setAttribute("name", "ether-markers"); // for debugging
  37. this._markerLayer.style.display = "none";
  38. if (this._lineLayer) {
  39. this._band.removeLayerDiv(this._lineLayer);
  40. }
  41. this._lineLayer = this._band.createLayerDiv(1);
  42. this._lineLayer.setAttribute("name", "ether-lines"); // for debugging
  43. this._lineLayer.style.display = "none";
  44. var minDate = Math.max(0, Math.ceil(Timeline.PlanningUnit.toNumber(this._band.getMinDate())));
  45. var maxDate = Math.floor(Timeline.PlanningUnit.toNumber(this._band.getMaxDate()));
  46. var hasMore = function() {
  47. return minDate < maxDate;
  48. };
  49. var change = 1;
  50. var multiple = this._multiple;
  51. switch (this._intervalUnit) {
  52. case Timeline.PlanningUnit.DAY: change = 1; break;
  53. case Timeline.PlanningUnit.WEEK: change = 7; break;
  54. case Timeline.PlanningUnit.MONTH: change = 28; break;
  55. case Timeline.PlanningUnit.QUARTER: change = 28 * 3; break;
  56. case Timeline.PlanningUnit.YEAR: change = 28 * 12; break;
  57. }
  58. var increment = function() {
  59. minDate += change * multiple;
  60. };
  61. var labeller = this._band.getLabeller();
  62. while (true) {
  63. this._intervalMarkerLayout.createIntervalMarker(
  64. Timeline.PlanningUnit.fromNumber(minDate),
  65. labeller,
  66. this._intervalUnit,
  67. this._markerLayer,
  68. this._lineLayer
  69. );
  70. if (hasMore()) {
  71. increment();
  72. } else {
  73. break;
  74. }
  75. }
  76. this._markerLayer.style.display = "block";
  77. this._lineLayer.style.display = "block";
  78. };
  79. Timeline.PlanningEtherPainter.prototype.softPaint = function() {
  80. };
  81. /*==================================================
  82. * Planning Ether Marker Layout
  83. *==================================================
  84. */
  85. Timeline.PlanningEtherMarkerLayout = function(timeline, band, theme, align, showLine) {
  86. var horizontal = timeline.isHorizontal();
  87. if (horizontal) {
  88. if (align == "Top") {
  89. this.positionDiv = function(div, offset) {
  90. div.style.left = offset + "px";
  91. div.style.top = "0px";
  92. };
  93. } else {
  94. this.positionDiv = function(div, offset) {
  95. div.style.left = offset + "px";
  96. div.style.bottom = "0px";
  97. };
  98. }
  99. } else {
  100. if (align == "Left") {
  101. this.positionDiv = function(div, offset) {
  102. div.style.top = offset + "px";
  103. div.style.left = "0px";
  104. };
  105. } else {
  106. this.positionDiv = function(div, offset) {
  107. div.style.top = offset + "px";
  108. div.style.right = "0px";
  109. };
  110. }
  111. }
  112. var markerTheme = theme.ether.interval.marker;
  113. var lineTheme = theme.ether.interval.line;
  114. var stylePrefix = (horizontal ? "h" : "v") + align;
  115. var labelStyler = markerTheme[stylePrefix + "Styler"];
  116. var emphasizedLabelStyler = markerTheme[stylePrefix + "EmphasizedStyler"];
  117. this.createIntervalMarker = function(date, labeller, unit, markerDiv, lineDiv) {
  118. var offset = Math.round(band.dateToPixelOffset(date));
  119. if (showLine) {
  120. var divLine = timeline.getDocument().createElement("div");
  121. divLine.style.position = "absolute";
  122. if (lineTheme.opacity < 100) {
  123. Timeline.Graphics.setOpacity(divLine, lineTheme.opacity);
  124. }
  125. if (horizontal) {
  126. divLine.style.borderLeft = "1px solid " + lineTheme.color;
  127. divLine.style.left = offset + "px";
  128. divLine.style.width = "1px";
  129. divLine.style.top = "0px";
  130. divLine.style.height = "100%";
  131. } else {
  132. divLine.style.borderTop = "1px solid " + lineTheme.color;
  133. divLine.style.top = offset + "px";
  134. divLine.style.height = "1px";
  135. divLine.style.left = "0px";
  136. divLine.style.width = "100%";
  137. }
  138. lineDiv.appendChild(divLine);
  139. }
  140. var label = labeller.labelInterval(date, unit);
  141. var div = timeline.getDocument().createElement("div");
  142. div.innerHTML = label.text;
  143. div.style.position = "absolute";
  144. (label.emphasized ? emphasizedLabelStyler : labelStyler)(div);
  145. this.positionDiv(div, offset);
  146. markerDiv.appendChild(div);
  147. return div;
  148. };
  149. };