continuous.js 25 KB

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