continuous.js 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. var tslib_1 = require("tslib");
  4. var util_1 = require("@antv/util");
  5. var theme_1 = require("../util/theme");
  6. var util_2 = require("../util/util");
  7. var base_1 = require("./base");
  8. var HANDLER_HEIGHT_RATIO = 1.4;
  9. var HANDLER_TRIANGLE_RATIO = 0.4;
  10. var ContinueLegend = /** @class */ (function (_super) {
  11. tslib_1.__extends(ContinueLegend, _super);
  12. function ContinueLegend() {
  13. return _super !== null && _super.apply(this, arguments) || this;
  14. }
  15. ContinueLegend.prototype.getDefaultCfg = function () {
  16. var cfg = _super.prototype.getDefaultCfg.call(this);
  17. return tslib_1.__assign(tslib_1.__assign({}, cfg), { type: 'continue', min: 0, max: 100, value: null, colors: [], track: {}, rail: {}, label: {}, handler: {}, slidable: true, tip: null, step: null, maxWidth: null, maxHeight: null, defaultCfg: {
  18. label: {
  19. align: 'rail',
  20. spacing: 5,
  21. formatter: null,
  22. style: {
  23. fontSize: 12,
  24. fill: theme_1.default.textColor,
  25. textBaseline: 'middle',
  26. fontFamily: theme_1.default.fontFamily,
  27. },
  28. },
  29. handler: {
  30. size: 10,
  31. style: {
  32. fill: '#fff',
  33. stroke: '#333',
  34. },
  35. },
  36. track: {},
  37. rail: {
  38. type: 'color',
  39. size: 20,
  40. defaultLength: 100,
  41. style: {
  42. fill: '#DCDEE2',
  43. },
  44. },
  45. title: {
  46. spacing: 5,
  47. style: {
  48. fill: theme_1.default.textColor,
  49. fontSize: 12,
  50. textAlign: 'start',
  51. textBaseline: 'top',
  52. },
  53. },
  54. } });
  55. };
  56. ContinueLegend.prototype.isSlider = function () {
  57. return true;
  58. };
  59. // 实现 IList 接口
  60. ContinueLegend.prototype.getValue = function () {
  61. return this.getCurrentValue();
  62. };
  63. ContinueLegend.prototype.getRange = function () {
  64. return {
  65. min: this.get('min'),
  66. max: this.get('max'),
  67. };
  68. };
  69. // 改变 range
  70. ContinueLegend.prototype.setRange = function (min, max) {
  71. this.update({
  72. min: min,
  73. max: max,
  74. });
  75. };
  76. ContinueLegend.prototype.setValue = function (value) {
  77. var originValue = this.getValue();
  78. this.set('value', value);
  79. var group = this.get('group');
  80. this.resetTrackClip();
  81. if (this.get('slidable')) {
  82. this.resetHandlers(group);
  83. }
  84. this.delegateEmit('valuechanged', {
  85. originValue: originValue,
  86. value: value,
  87. });
  88. };
  89. ContinueLegend.prototype.initEvent = function () {
  90. var group = this.get('group');
  91. this.bindSliderEvent(group);
  92. this.bindRailEvent(group);
  93. this.bindTrackEvent(group);
  94. };
  95. ContinueLegend.prototype.drawLegendContent = function (group) {
  96. this.drawRail(group);
  97. this.drawLabels(group);
  98. this.fixedElements(group); // 调整各个图形位置,适应宽高的限制
  99. this.resetTrack(group);
  100. this.resetTrackClip(group);
  101. if (this.get('slidable')) {
  102. this.resetHandlers(group);
  103. }
  104. };
  105. ContinueLegend.prototype.bindSliderEvent = function (group) {
  106. this.bindHandlersEvent(group);
  107. };
  108. ContinueLegend.prototype.bindHandlersEvent = function (group) {
  109. var _this = this;
  110. group.on('legend-handler-min:drag', function (ev) {
  111. var minValue = _this.getValueByCanvasPoint(ev.x, ev.y);
  112. var currentValue = _this.getCurrentValue();
  113. var maxValue = currentValue[1];
  114. if (maxValue < minValue) {
  115. // 如果小于最小值,则调整最小值
  116. maxValue = minValue;
  117. }
  118. _this.setValue([minValue, maxValue]);
  119. });
  120. group.on('legend-handler-max:drag', function (ev) {
  121. var maxValue = _this.getValueByCanvasPoint(ev.x, ev.y);
  122. var currentValue = _this.getCurrentValue();
  123. var minValue = currentValue[0];
  124. if (minValue > maxValue) {
  125. // 如果小于最小值,则调整最小值
  126. minValue = maxValue;
  127. }
  128. _this.setValue([minValue, maxValue]);
  129. });
  130. };
  131. ContinueLegend.prototype.bindRailEvent = function (group) { };
  132. ContinueLegend.prototype.bindTrackEvent = function (group) {
  133. var _this = this;
  134. var prePoint = null;
  135. group.on('legend-track:dragstart', function (ev) {
  136. prePoint = {
  137. x: ev.x,
  138. y: ev.y,
  139. };
  140. });
  141. group.on('legend-track:drag', function (ev) {
  142. if (!prePoint) {
  143. return;
  144. }
  145. var preValue = _this.getValueByCanvasPoint(prePoint.x, prePoint.y);
  146. var curValue = _this.getValueByCanvasPoint(ev.x, ev.y);
  147. var currentValue = _this.getCurrentValue();
  148. var curDiff = currentValue[1] - currentValue[0];
  149. var range = _this.getRange();
  150. var dValue = curValue - preValue;
  151. if (dValue < 0) {
  152. // 减小, 同时未出边界
  153. if (currentValue[0] + dValue > range.min) {
  154. _this.setValue([currentValue[0] + dValue, currentValue[1] + dValue]);
  155. }
  156. else {
  157. _this.setValue([range.min, range.min + curDiff]);
  158. }
  159. // && ||
  160. }
  161. else if (dValue > 0) {
  162. if (dValue > 0 && currentValue[1] + dValue < range.max) {
  163. _this.setValue([currentValue[0] + dValue, currentValue[1] + dValue]);
  164. }
  165. else {
  166. _this.setValue([range.max - curDiff, range.max]);
  167. }
  168. }
  169. prePoint = {
  170. x: ev.x,
  171. y: ev.y,
  172. };
  173. });
  174. group.on('legend-track:dragend', function (ev) {
  175. prePoint = null;
  176. });
  177. };
  178. ContinueLegend.prototype.drawLabels = function (group) {
  179. this.drawLabel('min', group);
  180. this.drawLabel('max', group);
  181. };
  182. ContinueLegend.prototype.drawLabel = function (name, group) {
  183. var labelCfg = this.get('label');
  184. var style = labelCfg.style;
  185. var labelAlign = labelCfg.align;
  186. var labelFormatter = labelCfg.formatter;
  187. var value = this.get(name);
  188. var alignAttrs = this.getLabelAlignAttrs(name, labelAlign);
  189. var localId = "label-" + name;
  190. this.addShape(group, {
  191. type: 'text',
  192. id: this.getElementId(localId),
  193. name: "legend-label-" + name,
  194. attrs: tslib_1.__assign(tslib_1.__assign({ x: 0, y: 0, text: util_1.isFunction(labelFormatter) ? labelFormatter(value) : value }, style), alignAttrs),
  195. });
  196. };
  197. // 获取文本的对齐方式,为了自适应真实操碎了心
  198. ContinueLegend.prototype.getLabelAlignAttrs = function (name, align) {
  199. var isVertical = this.isVertical();
  200. var textAlign = 'center';
  201. var textBaseline = 'middle';
  202. if (isVertical) {
  203. // 垂直布局的所有的文本都左对齐
  204. textAlign = 'start';
  205. if (align !== 'rail') {
  206. if (name === 'min') {
  207. textBaseline = 'top';
  208. }
  209. else {
  210. textBaseline = 'bottom';
  211. }
  212. }
  213. else {
  214. textBaseline = 'top';
  215. }
  216. }
  217. else {
  218. if (align !== 'rail') {
  219. textBaseline = 'top';
  220. if (name === 'min') {
  221. textAlign = 'start';
  222. }
  223. else {
  224. textAlign = 'end';
  225. }
  226. }
  227. else {
  228. textAlign = 'start';
  229. textBaseline = 'middle';
  230. }
  231. }
  232. return {
  233. textAlign: textAlign,
  234. textBaseline: textBaseline,
  235. };
  236. };
  237. ContinueLegend.prototype.getRailPath = function (x, y, w, h) {
  238. var railCfg = this.get('rail');
  239. var size = railCfg.size, defaultLength = railCfg.defaultLength, type = railCfg.type;
  240. var isVertical = this.isVertical();
  241. var length = defaultLength;
  242. var width = w;
  243. var height = h;
  244. if (!width) {
  245. width = isVertical ? size : length;
  246. }
  247. if (!height) {
  248. height = isVertical ? length : size;
  249. }
  250. var path = [];
  251. if (type === 'color') {
  252. path.push(['M', x, y]);
  253. path.push(['L', x + width, y]);
  254. path.push(['L', x + width, y + height]);
  255. path.push(['L', x, y + height]);
  256. path.push(['Z']);
  257. }
  258. else {
  259. path.push(['M', x + width, y]);
  260. path.push(['L', x + width, y + height]);
  261. path.push(['L', x, y + height]);
  262. path.push(['Z']);
  263. }
  264. return path;
  265. };
  266. ContinueLegend.prototype.drawRail = function (group) {
  267. var railCfg = this.get('rail');
  268. var style = railCfg.style;
  269. this.addShape(group, {
  270. type: 'path',
  271. id: this.getElementId('rail'),
  272. name: 'legend-rail',
  273. attrs: tslib_1.__assign({ path: this.getRailPath(0, 0) }, style),
  274. });
  275. };
  276. // 将传入的颜色转换成渐变色
  277. ContinueLegend.prototype.getTrackColor = function (colors) {
  278. var count = colors.length;
  279. if (!count) {
  280. return null;
  281. }
  282. if (count === 1) {
  283. return colors[0];
  284. }
  285. var color; // 最终形态 l(0) 0:colors[0] 0.5:colors[1] 1:colors[2];
  286. if (this.isVertical()) {
  287. // 根据方向设置渐变方向
  288. color = 'l(90)';
  289. }
  290. else {
  291. color = 'l(0)';
  292. }
  293. for (var i = 0; i < count; i++) {
  294. var percent = i / (count - 1);
  295. color += " " + percent + ":" + colors[i];
  296. }
  297. return color;
  298. };
  299. ContinueLegend.prototype.getTrackPath = function (group) {
  300. var railShape = this.getRailShape(group);
  301. var path = railShape.attr('path');
  302. return util_1.clone(path);
  303. };
  304. ContinueLegend.prototype.getClipTrackAttrs = function (group) {
  305. var value = this.getCurrentValue();
  306. var min = value[0], max = value[1];
  307. var railBBox = this.getRailBBox(group);
  308. var startPoint = this.getPointByValue(min, group);
  309. var endPoint = this.getPointByValue(max, group);
  310. var isVertical = this.isVertical();
  311. var x;
  312. var y;
  313. var width;
  314. var height;
  315. if (isVertical) {
  316. x = railBBox.minX;
  317. y = startPoint.y;
  318. width = railBBox.width;
  319. height = endPoint.y - startPoint.y;
  320. }
  321. else {
  322. x = startPoint.x;
  323. y = railBBox.minY;
  324. width = endPoint.x - startPoint.x;
  325. height = railBBox.height;
  326. }
  327. return {
  328. x: x,
  329. y: y,
  330. width: width,
  331. height: height,
  332. };
  333. };
  334. // 获取 track 的属性,由 path 和 颜色构成
  335. ContinueLegend.prototype.getTrackAttrs = function (group) {
  336. var trackCfg = this.get('track');
  337. var colors = this.get('colors');
  338. var path = this.getTrackPath(group);
  339. return util_1.mix({
  340. path: path,
  341. fill: this.getTrackColor(colors),
  342. }, trackCfg.style);
  343. };
  344. ContinueLegend.prototype.resetTrackClip = function (group) {
  345. var container = group || this.get('group');
  346. var trackId = this.getElementId('track');
  347. var trackShape = container.findById(trackId);
  348. var clipShape = trackShape.getClip();
  349. var attrs = this.getClipTrackAttrs(group);
  350. if (!clipShape) {
  351. trackShape.setClip({
  352. type: 'rect',
  353. attrs: attrs,
  354. });
  355. }
  356. else {
  357. clipShape.attr(attrs);
  358. }
  359. };
  360. ContinueLegend.prototype.resetTrack = function (group) {
  361. var trackId = this.getElementId('track');
  362. var trackShape = group.findById(trackId);
  363. var trackAttrs = this.getTrackAttrs(group);
  364. if (trackShape) {
  365. trackShape.attr(trackAttrs);
  366. }
  367. else {
  368. this.addShape(group, {
  369. type: 'path',
  370. id: trackId,
  371. draggable: this.get('slidable'),
  372. name: 'legend-track',
  373. attrs: trackAttrs,
  374. });
  375. }
  376. };
  377. ContinueLegend.prototype.getPointByValue = function (value, group) {
  378. var _a = this.getRange(), min = _a.min, max = _a.max;
  379. var percent = (value - min) / (max - min);
  380. var bbox = this.getRailBBox(group);
  381. var isVertcal = this.isVertical();
  382. var point = { x: 0, y: 0 };
  383. if (isVertcal) {
  384. point.x = bbox.minX + bbox.width / 2;
  385. point.y = util_2.getValueByPercent(bbox.minY, bbox.maxY, percent);
  386. }
  387. else {
  388. point.x = util_2.getValueByPercent(bbox.minX, bbox.maxX, percent);
  389. point.y = bbox.minY + bbox.height / 2;
  390. }
  391. return point;
  392. };
  393. ContinueLegend.prototype.getRailShape = function (group) {
  394. var container = group || this.get('group');
  395. return container.findById(this.getElementId('rail'));
  396. };
  397. // 获取滑轨的宽高信息
  398. ContinueLegend.prototype.getRailBBox = function (group) {
  399. var railShape = this.getRailShape(group);
  400. var bbox = railShape.getBBox();
  401. return bbox;
  402. };
  403. ContinueLegend.prototype.getRailCanvasBBox = function () {
  404. var container = this.get('group');
  405. var railShape = container.findById(this.getElementId('rail'));
  406. var bbox = railShape.getCanvasBBox();
  407. return bbox;
  408. };
  409. // 是否垂直
  410. ContinueLegend.prototype.isVertical = function () {
  411. return this.get('layout') === 'vertical';
  412. };
  413. // 用于交互时
  414. ContinueLegend.prototype.getValueByCanvasPoint = function (x, y) {
  415. var _a = this.getRange(), min = _a.min, max = _a.max;
  416. var bbox = this.getRailCanvasBBox(); // 因为 x, y 是画布坐标
  417. var isVertcal = this.isVertical();
  418. var step = this.get('step');
  419. var percent;
  420. if (isVertcal) {
  421. // 垂直时计算 y
  422. percent = (y - bbox.minY) / bbox.height;
  423. }
  424. else {
  425. // 水平时计算 x
  426. percent = (x - bbox.minX) / bbox.width;
  427. }
  428. var value = util_2.getValueByPercent(min, max, percent);
  429. if (step) {
  430. var count = Math.round((value - min) / step);
  431. value = min + count * step; // 移动到最近的
  432. }
  433. if (value > max) {
  434. value = max;
  435. }
  436. if (value < min) {
  437. value = min;
  438. }
  439. return value;
  440. };
  441. // 当前选中的范围
  442. ContinueLegend.prototype.getCurrentValue = function () {
  443. var value = this.get('value');
  444. if (!value) {
  445. var values = this.get('values');
  446. if (!values) {
  447. return [this.get('min'), this.get('max')];
  448. }
  449. // 如果没有定义,取最大范围 最小值 为 values 中的最小值, 如果最小值 超过了 定义的最大值 则 做限制 最大值 反之
  450. return [Math.max(Math.min.apply(Math, tslib_1.__spreadArrays(values, [this.get('max')])), this.get('min')), Math.min(Math.max.apply(Math, tslib_1.__spreadArrays(values, [this.get('min')])), this.get('max'))];
  451. }
  452. return value;
  453. };
  454. // 重置滑块 handler
  455. ContinueLegend.prototype.resetHandlers = function (group) {
  456. var currentValue = this.getCurrentValue();
  457. var min = currentValue[0], max = currentValue[1];
  458. this.resetHandler(group, 'min', min);
  459. this.resetHandler(group, 'max', max);
  460. };
  461. // 获取滑块的 path
  462. ContinueLegend.prototype.getHandlerPath = function (handlerCfg, point) {
  463. var isVertical = this.isVertical();
  464. var path = [];
  465. var width = handlerCfg.size;
  466. var x = point.x, y = point.y;
  467. var height = width * HANDLER_HEIGHT_RATIO;
  468. var halfWidth = width / 2;
  469. var oneSixthWidth = width / 6;
  470. if (isVertical) {
  471. /**
  472. * 竖直情况下的滑块 handler,左侧顶点是 x,y
  473. * /----|
  474. * -- |
  475. * -- |
  476. * \----|
  477. */
  478. var triangleX = x + height * HANDLER_TRIANGLE_RATIO;
  479. path.push(['M', x, y]);
  480. path.push(['L', triangleX, y + halfWidth]);
  481. path.push(['L', x + height, y + halfWidth]);
  482. path.push(['L', x + height, y - halfWidth]);
  483. path.push(['L', triangleX, y - halfWidth]);
  484. path.push(['Z']);
  485. // 绘制两条横线
  486. path.push(['M', triangleX, y + oneSixthWidth]);
  487. path.push(['L', x + height - 2, y + oneSixthWidth]);
  488. path.push(['M', triangleX, y - oneSixthWidth]);
  489. path.push(['L', x + height - 2, y - oneSixthWidth]);
  490. }
  491. else {
  492. /**
  493. * 水平情况下的滑块,上面顶点处是 x,y
  494. * / \
  495. * | | | |
  496. * | | | |
  497. * -----
  498. */
  499. var triangleY = y + height * HANDLER_TRIANGLE_RATIO;
  500. path.push(['M', x, y]);
  501. path.push(['L', x - halfWidth, triangleY]);
  502. path.push(['L', x - halfWidth, y + height]);
  503. path.push(['L', x + halfWidth, y + height]);
  504. path.push(['L', x + halfWidth, triangleY]);
  505. path.push(['Z']);
  506. // 绘制两条竖线
  507. path.push(['M', x - oneSixthWidth, triangleY]);
  508. path.push(['L', x - oneSixthWidth, y + height - 2]);
  509. path.push(['M', x + oneSixthWidth, triangleY]);
  510. path.push(['L', x + oneSixthWidth, y + height - 2]);
  511. }
  512. return path;
  513. };
  514. // 调整 handler 的位置,如果未存在则绘制
  515. ContinueLegend.prototype.resetHandler = function (group, name, value) {
  516. var point = this.getPointByValue(value, group);
  517. var handlerCfg = this.get('handler');
  518. var path = this.getHandlerPath(handlerCfg, point);
  519. var id = this.getElementId("handler-" + name);
  520. var handlerShape = group.findById(id);
  521. var isVertical = this.isVertical();
  522. if (handlerShape) {
  523. handlerShape.attr('path', path);
  524. }
  525. else {
  526. this.addShape(group, {
  527. type: 'path',
  528. name: "legend-handler-" + name,
  529. draggable: true,
  530. id: id,
  531. attrs: tslib_1.__assign(tslib_1.__assign({ path: path }, handlerCfg.style), { cursor: isVertical ? 'ns-resize' : 'ew-resize' }),
  532. });
  533. }
  534. };
  535. // 当设置了 maxWidth, maxHeight 时调整 rail 的宽度,
  536. // 文本的位置
  537. ContinueLegend.prototype.fixedElements = function (group) {
  538. var railShape = group.findById(this.getElementId('rail'));
  539. var minLabel = group.findById(this.getElementId('label-min'));
  540. var maxLabel = group.findById(this.getElementId('label-max'));
  541. var startPoint = this.getDrawPoint();
  542. if (this.isVertical()) {
  543. // 横向布局
  544. this.fixedVertail(minLabel, maxLabel, railShape, startPoint);
  545. }
  546. else {
  547. // 水平布局
  548. this.fixedHorizontal(minLabel, maxLabel, railShape, startPoint);
  549. }
  550. };
  551. ContinueLegend.prototype.fitRailLength = function (minLabelBBox, maxLabelBBox, railBBox, railShape) {
  552. var isVertical = this.isVertical();
  553. var lengthField = isVertical ? 'height' : 'width';
  554. var labelCfg = this.get('label');
  555. var labelAlign = labelCfg.align;
  556. var spacing = labelCfg.spacing;
  557. var maxLength = this.get("max" + util_1.upperFirst(lengthField)); // get('maxWidth')
  558. if (maxLength) {
  559. var elementsLength = labelAlign === 'rail'
  560. ? railBBox[lengthField] + minLabelBBox[lengthField] + maxLabelBBox[lengthField] + spacing * 2
  561. : railBBox[lengthField];
  562. var diff = elementsLength - maxLength;
  563. if (diff > 0) {
  564. // 大于限制的长度
  565. this.changeRailLength(railShape, lengthField, railBBox[lengthField] - diff);
  566. }
  567. }
  568. };
  569. ContinueLegend.prototype.changeRailLength = function (railShape, lengthField, length) {
  570. var bbox = railShape.getBBox();
  571. var path;
  572. if (lengthField === 'height') {
  573. path = this.getRailPath(bbox.x, bbox.y, bbox.width, length);
  574. }
  575. else {
  576. path = this.getRailPath(bbox.x, bbox.y, length, bbox.height);
  577. }
  578. railShape.attr('path', path);
  579. };
  580. ContinueLegend.prototype.changeRailPosition = function (railShape, x, y) {
  581. var bbox = railShape.getBBox();
  582. var path = this.getRailPath(x, y, bbox.width, bbox.height);
  583. railShape.attr('path', path);
  584. };
  585. ContinueLegend.prototype.fixedHorizontal = function (minLabel, maxLabel, railShape, startPoint) {
  586. var labelCfg = this.get('label');
  587. var labelAlign = labelCfg.align;
  588. var spacing = labelCfg.spacing;
  589. var railBBox = railShape.getBBox();
  590. var minLabelBBox = minLabel.getBBox();
  591. var maxLabelBBox = maxLabel.getBBox();
  592. var railHeight = railBBox.height; // 取 rail 的高度,作为高度
  593. this.fitRailLength(minLabelBBox, maxLabelBBox, railBBox, railShape);
  594. railBBox = railShape.getBBox();
  595. if (labelAlign === 'rail') {
  596. // 沿着 rail 方向
  597. minLabel.attr({
  598. x: startPoint.x,
  599. y: startPoint.y + railHeight / 2,
  600. });
  601. this.changeRailPosition(railShape, startPoint.x + minLabelBBox.width + spacing, startPoint.y);
  602. maxLabel.attr({
  603. x: startPoint.x + minLabelBBox.width + railBBox.width + spacing * 2,
  604. y: startPoint.y + railHeight / 2,
  605. });
  606. }
  607. else if (labelAlign === 'top') {
  608. minLabel.attr({
  609. x: startPoint.x,
  610. y: startPoint.y,
  611. });
  612. maxLabel.attr({
  613. x: startPoint.x + railBBox.width,
  614. y: startPoint.y,
  615. });
  616. this.changeRailPosition(railShape, startPoint.x, startPoint.y + minLabelBBox.height + spacing);
  617. }
  618. else {
  619. this.changeRailPosition(railShape, startPoint.x, startPoint.y);
  620. minLabel.attr({
  621. x: startPoint.x,
  622. y: startPoint.y + railBBox.height + spacing,
  623. });
  624. maxLabel.attr({
  625. x: startPoint.x + railBBox.width,
  626. y: startPoint.y + railBBox.height + spacing,
  627. });
  628. }
  629. };
  630. ContinueLegend.prototype.fixedVertail = function (minLabel, maxLabel, railShape, startPoint) {
  631. var labelCfg = this.get('label');
  632. var labelAlign = labelCfg.align;
  633. var spacing = labelCfg.spacing;
  634. var railBBox = railShape.getBBox();
  635. var minLabelBBox = minLabel.getBBox();
  636. var maxLabelBBox = maxLabel.getBBox();
  637. this.fitRailLength(minLabelBBox, maxLabelBBox, railBBox, railShape);
  638. railBBox = railShape.getBBox();
  639. if (labelAlign === 'rail') {
  640. // 沿着 rail 方向
  641. minLabel.attr({
  642. x: startPoint.x,
  643. y: startPoint.y,
  644. });
  645. this.changeRailPosition(railShape, startPoint.x, startPoint.y + minLabelBBox.height + spacing);
  646. maxLabel.attr({
  647. x: startPoint.x,
  648. y: startPoint.y + minLabelBBox.height + railBBox.height + spacing * 2,
  649. });
  650. }
  651. else if (labelAlign === 'right') {
  652. minLabel.attr({
  653. x: startPoint.x + railBBox.width + spacing,
  654. y: startPoint.y,
  655. });
  656. this.changeRailPosition(railShape, startPoint.x, startPoint.y);
  657. maxLabel.attr({
  658. x: startPoint.x + railBBox.width + spacing,
  659. y: startPoint.y + railBBox.height,
  660. });
  661. }
  662. else {
  663. // left
  664. var maxLabelWidth = Math.max(minLabelBBox.width, maxLabelBBox.width);
  665. minLabel.attr({
  666. x: startPoint.x,
  667. y: startPoint.y,
  668. });
  669. this.changeRailPosition(railShape, startPoint.x + maxLabelWidth + spacing, startPoint.y);
  670. maxLabel.attr({
  671. x: startPoint.x,
  672. y: startPoint.y + railBBox.height,
  673. });
  674. }
  675. };
  676. return ContinueLegend;
  677. }(base_1.default));
  678. exports.default = ContinueLegend;
  679. //# sourceMappingURL=continuous.js.map