mtr.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. "use strict";
  2. var __extends = (this && this.__extends) || (function () {
  3. var extendStatics = function (d, b) {
  4. extendStatics = Object.setPrototypeOf ||
  5. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  6. function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
  7. return extendStatics(d, b);
  8. };
  9. return function (d, b) {
  10. if (typeof b !== "function" && b !== null)
  11. throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
  12. extendStatics(d, b);
  13. function __() { this.constructor = d; }
  14. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  15. };
  16. })();
  17. var __read = (this && this.__read) || function (o, n) {
  18. var m = typeof Symbol === "function" && o[Symbol.iterator];
  19. if (!m) return o;
  20. var i = m.call(o), r, ar = [], e;
  21. try {
  22. while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
  23. }
  24. catch (error) { e = { error: error }; }
  25. finally {
  26. try {
  27. if (r && !r.done && (m = i["return"])) m.call(i);
  28. }
  29. finally { if (e) throw e.error; }
  30. }
  31. return ar;
  32. };
  33. var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
  34. if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
  35. if (ar || !(i in from)) {
  36. if (!ar) ar = Array.prototype.slice.call(from, 0, i);
  37. ar[i] = from[i];
  38. }
  39. }
  40. return to.concat(ar || Array.prototype.slice.call(from));
  41. };
  42. Object.defineProperty(exports, "__esModule", { value: true });
  43. exports.SVGmlabeledtr = exports.SVGmtr = void 0;
  44. var Wrapper_js_1 = require("../Wrapper.js");
  45. var mtr_js_1 = require("../../common/Wrappers/mtr.js");
  46. var mtr_js_2 = require("../../common/Wrappers/mtr.js");
  47. var mtr_js_3 = require("../../../core/MmlTree/MmlNodes/mtr.js");
  48. var SVGmtr = (function (_super) {
  49. __extends(SVGmtr, _super);
  50. function SVGmtr() {
  51. return _super !== null && _super.apply(this, arguments) || this;
  52. }
  53. SVGmtr.prototype.toSVG = function (parent) {
  54. var svg = this.standardSVGnode(parent);
  55. this.placeCells(svg);
  56. this.placeColor();
  57. };
  58. SVGmtr.prototype.placeCells = function (svg) {
  59. var cSpace = this.parent.getColumnHalfSpacing();
  60. var cLines = __spreadArray(__spreadArray([this.parent.fLine], __read(this.parent.cLines), false), [this.parent.fLine], false);
  61. var cWidth = this.parent.getComputedWidths();
  62. var scale = 1 / this.getBBox().rscale;
  63. var x = cLines[0];
  64. for (var i = 0; i < this.numCells; i++) {
  65. var child = this.getChild(i);
  66. child.toSVG(svg);
  67. x += this.placeCell(child, {
  68. x: x, y: 0, lSpace: cSpace[i] * scale, rSpace: cSpace[i + 1] * scale, w: cWidth[i] * scale,
  69. lLine: cLines[i] * scale, rLine: cLines[i + 1] * scale
  70. });
  71. }
  72. };
  73. SVGmtr.prototype.placeCell = function (cell, sizes) {
  74. var x = sizes.x, y = sizes.y, lSpace = sizes.lSpace, w = sizes.w, rSpace = sizes.rSpace, lLine = sizes.lLine, rLine = sizes.rLine;
  75. var scale = 1 / this.getBBox().rscale;
  76. var _a = __read([this.H * scale, this.D * scale], 2), h = _a[0], d = _a[1];
  77. var _b = __read([this.tSpace * scale, this.bSpace * scale], 2), t = _b[0], b = _b[1];
  78. var _c = __read(cell.placeCell(x + lSpace, y, w, h, d), 2), dx = _c[0], dy = _c[1];
  79. var W = lSpace + w + rSpace;
  80. cell.placeColor(-(dx + lSpace + lLine / 2), -(d + b + dy), W + (lLine + rLine) / 2, h + d + t + b);
  81. return W + rLine;
  82. };
  83. SVGmtr.prototype.placeColor = function () {
  84. var scale = 1 / this.getBBox().rscale;
  85. var adaptor = this.adaptor;
  86. var child = this.firstChild();
  87. if (child && adaptor.kind(child) === 'rect' && adaptor.getAttribute(child, 'data-bgcolor')) {
  88. var _a = __read([(this.tLine / 2) * scale, (this.bLine / 2) * scale], 2), TL = _a[0], BL = _a[1];
  89. var _b = __read([this.tSpace * scale, this.bSpace * scale], 2), TS = _b[0], BS = _b[1];
  90. var _c = __read([this.H * scale, this.D * scale], 2), H = _c[0], D = _c[1];
  91. adaptor.setAttribute(child, 'y', this.fixed(-(D + BS + BL)));
  92. adaptor.setAttribute(child, 'width', this.fixed(this.parent.getWidth() * scale));
  93. adaptor.setAttribute(child, 'height', this.fixed(TL + TS + H + D + BS + BL));
  94. }
  95. };
  96. SVGmtr.kind = mtr_js_3.MmlMtr.prototype.kind;
  97. return SVGmtr;
  98. }((0, mtr_js_1.CommonMtrMixin)(Wrapper_js_1.SVGWrapper)));
  99. exports.SVGmtr = SVGmtr;
  100. var SVGmlabeledtr = (function (_super) {
  101. __extends(SVGmlabeledtr, _super);
  102. function SVGmlabeledtr() {
  103. return _super !== null && _super.apply(this, arguments) || this;
  104. }
  105. SVGmlabeledtr.prototype.toSVG = function (parent) {
  106. _super.prototype.toSVG.call(this, parent);
  107. var child = this.childNodes[0];
  108. if (child) {
  109. child.toSVG(this.parent.labels);
  110. }
  111. };
  112. SVGmlabeledtr.kind = mtr_js_3.MmlMlabeledtr.prototype.kind;
  113. return SVGmlabeledtr;
  114. }((0, mtr_js_2.CommonMlabeledtrMixin)(SVGmtr)));
  115. exports.SVGmlabeledtr = SVGmlabeledtr;
  116. //# sourceMappingURL=mtr.js.map