ContinuousView.js 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800
  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. /**
  20. * AUTO-GENERATED FILE. DO NOT MODIFY.
  21. */
  22. /*
  23. * Licensed to the Apache Software Foundation (ASF) under one
  24. * or more contributor license agreements. See the NOTICE file
  25. * distributed with this work for additional information
  26. * regarding copyright ownership. The ASF licenses this file
  27. * to you under the Apache License, Version 2.0 (the
  28. * "License"); you may not use this file except in compliance
  29. * with the License. You may obtain a copy of the License at
  30. *
  31. * http://www.apache.org/licenses/LICENSE-2.0
  32. *
  33. * Unless required by applicable law or agreed to in writing,
  34. * software distributed under the License is distributed on an
  35. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  36. * KIND, either express or implied. See the License for the
  37. * specific language governing permissions and limitations
  38. * under the License.
  39. */
  40. import { __extends } from "tslib";
  41. import * as zrUtil from 'zrender/lib/core/util.js';
  42. import LinearGradient from 'zrender/lib/graphic/LinearGradient.js';
  43. import * as eventTool from 'zrender/lib/core/event.js';
  44. import VisualMapView from './VisualMapView.js';
  45. import * as graphic from '../../util/graphic.js';
  46. import * as numberUtil from '../../util/number.js';
  47. import sliderMove from '../helper/sliderMove.js';
  48. import * as helper from './helper.js';
  49. import * as modelUtil from '../../util/model.js';
  50. import { parsePercent } from 'zrender/lib/contain/text.js';
  51. import { setAsHighDownDispatcher } from '../../util/states.js';
  52. import { createSymbol } from '../../util/symbol.js';
  53. import ZRImage from 'zrender/lib/graphic/Image.js';
  54. import { getECData } from '../../util/innerStore.js';
  55. import { createTextStyle } from '../../label/labelStyle.js';
  56. var linearMap = numberUtil.linearMap;
  57. var each = zrUtil.each;
  58. var mathMin = Math.min;
  59. var mathMax = Math.max; // Arbitrary value
  60. var HOVER_LINK_SIZE = 12;
  61. var HOVER_LINK_OUT = 6; // Notice:
  62. // Any "interval" should be by the order of [low, high].
  63. // "handle0" (handleIndex === 0) maps to
  64. // low data value: this._dataInterval[0] and has low coord.
  65. // "handle1" (handleIndex === 1) maps to
  66. // high data value: this._dataInterval[1] and has high coord.
  67. // The logic of transform is implemented in this._createBarGroup.
  68. var ContinuousView =
  69. /** @class */
  70. function (_super) {
  71. __extends(ContinuousView, _super);
  72. function ContinuousView() {
  73. var _this = _super !== null && _super.apply(this, arguments) || this;
  74. _this.type = ContinuousView.type;
  75. _this._shapes = {};
  76. _this._dataInterval = [];
  77. _this._handleEnds = [];
  78. _this._hoverLinkDataIndices = [];
  79. return _this;
  80. }
  81. ContinuousView.prototype.doRender = function (visualMapModel, ecModel, api, payload) {
  82. this._api = api;
  83. if (!payload || payload.type !== 'selectDataRange' || payload.from !== this.uid) {
  84. this._buildView();
  85. }
  86. };
  87. ContinuousView.prototype._buildView = function () {
  88. this.group.removeAll();
  89. var visualMapModel = this.visualMapModel;
  90. var thisGroup = this.group;
  91. this._orient = visualMapModel.get('orient');
  92. this._useHandle = visualMapModel.get('calculable');
  93. this._resetInterval();
  94. this._renderBar(thisGroup);
  95. var dataRangeText = visualMapModel.get('text');
  96. this._renderEndsText(thisGroup, dataRangeText, 0);
  97. this._renderEndsText(thisGroup, dataRangeText, 1); // Do this for background size calculation.
  98. this._updateView(true); // After updating view, inner shapes is built completely,
  99. // and then background can be rendered.
  100. this.renderBackground(thisGroup); // Real update view
  101. this._updateView();
  102. this._enableHoverLinkToSeries();
  103. this._enableHoverLinkFromSeries();
  104. this.positionGroup(thisGroup);
  105. };
  106. ContinuousView.prototype._renderEndsText = function (group, dataRangeText, endsIndex) {
  107. if (!dataRangeText) {
  108. return;
  109. } // Compatible with ec2, text[0] map to high value, text[1] map low value.
  110. var text = dataRangeText[1 - endsIndex];
  111. text = text != null ? text + '' : '';
  112. var visualMapModel = this.visualMapModel;
  113. var textGap = visualMapModel.get('textGap');
  114. var itemSize = visualMapModel.itemSize;
  115. var barGroup = this._shapes.mainGroup;
  116. var position = this._applyTransform([itemSize[0] / 2, endsIndex === 0 ? -textGap : itemSize[1] + textGap], barGroup);
  117. var align = this._applyTransform(endsIndex === 0 ? 'bottom' : 'top', barGroup);
  118. var orient = this._orient;
  119. var textStyleModel = this.visualMapModel.textStyleModel;
  120. this.group.add(new graphic.Text({
  121. style: createTextStyle(textStyleModel, {
  122. x: position[0],
  123. y: position[1],
  124. verticalAlign: orient === 'horizontal' ? 'middle' : align,
  125. align: orient === 'horizontal' ? align : 'center',
  126. text: text
  127. })
  128. }));
  129. };
  130. ContinuousView.prototype._renderBar = function (targetGroup) {
  131. var visualMapModel = this.visualMapModel;
  132. var shapes = this._shapes;
  133. var itemSize = visualMapModel.itemSize;
  134. var orient = this._orient;
  135. var useHandle = this._useHandle;
  136. var itemAlign = helper.getItemAlign(visualMapModel, this.api, itemSize);
  137. var mainGroup = shapes.mainGroup = this._createBarGroup(itemAlign);
  138. var gradientBarGroup = new graphic.Group();
  139. mainGroup.add(gradientBarGroup); // Bar
  140. gradientBarGroup.add(shapes.outOfRange = createPolygon());
  141. gradientBarGroup.add(shapes.inRange = createPolygon(null, useHandle ? getCursor(this._orient) : null, zrUtil.bind(this._dragHandle, this, 'all', false), zrUtil.bind(this._dragHandle, this, 'all', true))); // A border radius clip.
  142. gradientBarGroup.setClipPath(new graphic.Rect({
  143. shape: {
  144. x: 0,
  145. y: 0,
  146. width: itemSize[0],
  147. height: itemSize[1],
  148. r: 3
  149. }
  150. }));
  151. var textRect = visualMapModel.textStyleModel.getTextRect('国');
  152. var textSize = mathMax(textRect.width, textRect.height); // Handle
  153. if (useHandle) {
  154. shapes.handleThumbs = [];
  155. shapes.handleLabels = [];
  156. shapes.handleLabelPoints = [];
  157. this._createHandle(visualMapModel, mainGroup, 0, itemSize, textSize, orient);
  158. this._createHandle(visualMapModel, mainGroup, 1, itemSize, textSize, orient);
  159. }
  160. this._createIndicator(visualMapModel, mainGroup, itemSize, textSize, orient);
  161. targetGroup.add(mainGroup);
  162. };
  163. ContinuousView.prototype._createHandle = function (visualMapModel, mainGroup, handleIndex, itemSize, textSize, orient) {
  164. var onDrift = zrUtil.bind(this._dragHandle, this, handleIndex, false);
  165. var onDragEnd = zrUtil.bind(this._dragHandle, this, handleIndex, true);
  166. var handleSize = parsePercent(visualMapModel.get('handleSize'), itemSize[0]);
  167. var handleThumb = createSymbol(visualMapModel.get('handleIcon'), -handleSize / 2, -handleSize / 2, handleSize, handleSize, null, true);
  168. var cursor = getCursor(this._orient);
  169. handleThumb.attr({
  170. cursor: cursor,
  171. draggable: true,
  172. drift: onDrift,
  173. ondragend: onDragEnd,
  174. onmousemove: function (e) {
  175. eventTool.stop(e.event);
  176. }
  177. });
  178. handleThumb.x = itemSize[0] / 2;
  179. handleThumb.useStyle(visualMapModel.getModel('handleStyle').getItemStyle());
  180. handleThumb.setStyle({
  181. strokeNoScale: true,
  182. strokeFirst: true
  183. });
  184. handleThumb.style.lineWidth *= 2;
  185. handleThumb.ensureState('emphasis').style = visualMapModel.getModel(['emphasis', 'handleStyle']).getItemStyle();
  186. setAsHighDownDispatcher(handleThumb, true);
  187. mainGroup.add(handleThumb); // Text is always horizontal layout but should not be effected by
  188. // transform (orient/inverse). So label is built separately but not
  189. // use zrender/graphic/helper/RectText, and is located based on view
  190. // group (according to handleLabelPoint) but not barGroup.
  191. var textStyleModel = this.visualMapModel.textStyleModel;
  192. var handleLabel = new graphic.Text({
  193. cursor: cursor,
  194. draggable: true,
  195. drift: onDrift,
  196. onmousemove: function (e) {
  197. // Fot mobile devicem, prevent screen slider on the button.
  198. eventTool.stop(e.event);
  199. },
  200. ondragend: onDragEnd,
  201. style: createTextStyle(textStyleModel, {
  202. x: 0,
  203. y: 0,
  204. text: ''
  205. })
  206. });
  207. handleLabel.ensureState('blur').style = {
  208. opacity: 0.1
  209. };
  210. handleLabel.stateTransition = {
  211. duration: 200
  212. };
  213. this.group.add(handleLabel);
  214. var handleLabelPoint = [handleSize, 0];
  215. var shapes = this._shapes;
  216. shapes.handleThumbs[handleIndex] = handleThumb;
  217. shapes.handleLabelPoints[handleIndex] = handleLabelPoint;
  218. shapes.handleLabels[handleIndex] = handleLabel;
  219. };
  220. ContinuousView.prototype._createIndicator = function (visualMapModel, mainGroup, itemSize, textSize, orient) {
  221. var scale = parsePercent(visualMapModel.get('indicatorSize'), itemSize[0]);
  222. var indicator = createSymbol(visualMapModel.get('indicatorIcon'), -scale / 2, -scale / 2, scale, scale, null, true);
  223. indicator.attr({
  224. cursor: 'move',
  225. invisible: true,
  226. silent: true,
  227. x: itemSize[0] / 2
  228. });
  229. var indicatorStyle = visualMapModel.getModel('indicatorStyle').getItemStyle();
  230. if (indicator instanceof ZRImage) {
  231. var pathStyle = indicator.style;
  232. indicator.useStyle(zrUtil.extend({
  233. // TODO other properties like x, y ?
  234. image: pathStyle.image,
  235. x: pathStyle.x,
  236. y: pathStyle.y,
  237. width: pathStyle.width,
  238. height: pathStyle.height
  239. }, indicatorStyle));
  240. } else {
  241. indicator.useStyle(indicatorStyle);
  242. }
  243. mainGroup.add(indicator);
  244. var textStyleModel = this.visualMapModel.textStyleModel;
  245. var indicatorLabel = new graphic.Text({
  246. silent: true,
  247. invisible: true,
  248. style: createTextStyle(textStyleModel, {
  249. x: 0,
  250. y: 0,
  251. text: ''
  252. })
  253. });
  254. this.group.add(indicatorLabel);
  255. var indicatorLabelPoint = [(orient === 'horizontal' ? textSize / 2 : HOVER_LINK_OUT) + itemSize[0] / 2, 0];
  256. var shapes = this._shapes;
  257. shapes.indicator = indicator;
  258. shapes.indicatorLabel = indicatorLabel;
  259. shapes.indicatorLabelPoint = indicatorLabelPoint;
  260. this._firstShowIndicator = true;
  261. };
  262. ContinuousView.prototype._dragHandle = function (handleIndex, isEnd, // dx is event from ondragend if isEnd is true. It's not used
  263. dx, dy) {
  264. if (!this._useHandle) {
  265. return;
  266. }
  267. this._dragging = !isEnd;
  268. if (!isEnd) {
  269. // Transform dx, dy to bar coordination.
  270. var vertex = this._applyTransform([dx, dy], this._shapes.mainGroup, true);
  271. this._updateInterval(handleIndex, vertex[1]);
  272. this._hideIndicator(); // Considering realtime, update view should be executed
  273. // before dispatch action.
  274. this._updateView();
  275. } // dragEnd do not dispatch action when realtime.
  276. if (isEnd === !this.visualMapModel.get('realtime')) {
  277. // jshint ignore:line
  278. this.api.dispatchAction({
  279. type: 'selectDataRange',
  280. from: this.uid,
  281. visualMapId: this.visualMapModel.id,
  282. selected: this._dataInterval.slice()
  283. });
  284. }
  285. if (isEnd) {
  286. !this._hovering && this._clearHoverLinkToSeries();
  287. } else if (useHoverLinkOnHandle(this.visualMapModel)) {
  288. this._doHoverLinkToSeries(this._handleEnds[handleIndex], false);
  289. }
  290. };
  291. ContinuousView.prototype._resetInterval = function () {
  292. var visualMapModel = this.visualMapModel;
  293. var dataInterval = this._dataInterval = visualMapModel.getSelected();
  294. var dataExtent = visualMapModel.getExtent();
  295. var sizeExtent = [0, visualMapModel.itemSize[1]];
  296. this._handleEnds = [linearMap(dataInterval[0], dataExtent, sizeExtent, true), linearMap(dataInterval[1], dataExtent, sizeExtent, true)];
  297. };
  298. /**
  299. * @private
  300. * @param {(number|string)} handleIndex 0 or 1 or 'all'
  301. * @param {number} dx
  302. * @param {number} dy
  303. */
  304. ContinuousView.prototype._updateInterval = function (handleIndex, delta) {
  305. delta = delta || 0;
  306. var visualMapModel = this.visualMapModel;
  307. var handleEnds = this._handleEnds;
  308. var sizeExtent = [0, visualMapModel.itemSize[1]];
  309. sliderMove(delta, handleEnds, sizeExtent, handleIndex, // cross is forbiden
  310. 0);
  311. var dataExtent = visualMapModel.getExtent(); // Update data interval.
  312. this._dataInterval = [linearMap(handleEnds[0], sizeExtent, dataExtent, true), linearMap(handleEnds[1], sizeExtent, dataExtent, true)];
  313. };
  314. ContinuousView.prototype._updateView = function (forSketch) {
  315. var visualMapModel = this.visualMapModel;
  316. var dataExtent = visualMapModel.getExtent();
  317. var shapes = this._shapes;
  318. var outOfRangeHandleEnds = [0, visualMapModel.itemSize[1]];
  319. var inRangeHandleEnds = forSketch ? outOfRangeHandleEnds : this._handleEnds;
  320. var visualInRange = this._createBarVisual(this._dataInterval, dataExtent, inRangeHandleEnds, 'inRange');
  321. var visualOutOfRange = this._createBarVisual(dataExtent, dataExtent, outOfRangeHandleEnds, 'outOfRange');
  322. shapes.inRange.setStyle({
  323. fill: visualInRange.barColor // opacity: visualInRange.opacity
  324. }).setShape('points', visualInRange.barPoints);
  325. shapes.outOfRange.setStyle({
  326. fill: visualOutOfRange.barColor // opacity: visualOutOfRange.opacity
  327. }).setShape('points', visualOutOfRange.barPoints);
  328. this._updateHandle(inRangeHandleEnds, visualInRange);
  329. };
  330. ContinuousView.prototype._createBarVisual = function (dataInterval, dataExtent, handleEnds, forceState) {
  331. var opts = {
  332. forceState: forceState,
  333. convertOpacityToAlpha: true
  334. };
  335. var colorStops = this._makeColorGradient(dataInterval, opts);
  336. var symbolSizes = [this.getControllerVisual(dataInterval[0], 'symbolSize', opts), this.getControllerVisual(dataInterval[1], 'symbolSize', opts)];
  337. var barPoints = this._createBarPoints(handleEnds, symbolSizes);
  338. return {
  339. barColor: new LinearGradient(0, 0, 0, 1, colorStops),
  340. barPoints: barPoints,
  341. handlesColor: [colorStops[0].color, colorStops[colorStops.length - 1].color]
  342. };
  343. };
  344. ContinuousView.prototype._makeColorGradient = function (dataInterval, opts) {
  345. // Considering colorHue, which is not linear, so we have to sample
  346. // to calculate gradient color stops, but not only caculate head
  347. // and tail.
  348. var sampleNumber = 100; // Arbitrary value.
  349. var colorStops = [];
  350. var step = (dataInterval[1] - dataInterval[0]) / sampleNumber;
  351. colorStops.push({
  352. color: this.getControllerVisual(dataInterval[0], 'color', opts),
  353. offset: 0
  354. });
  355. for (var i = 1; i < sampleNumber; i++) {
  356. var currValue = dataInterval[0] + step * i;
  357. if (currValue > dataInterval[1]) {
  358. break;
  359. }
  360. colorStops.push({
  361. color: this.getControllerVisual(currValue, 'color', opts),
  362. offset: i / sampleNumber
  363. });
  364. }
  365. colorStops.push({
  366. color: this.getControllerVisual(dataInterval[1], 'color', opts),
  367. offset: 1
  368. });
  369. return colorStops;
  370. };
  371. ContinuousView.prototype._createBarPoints = function (handleEnds, symbolSizes) {
  372. var itemSize = this.visualMapModel.itemSize;
  373. return [[itemSize[0] - symbolSizes[0], handleEnds[0]], [itemSize[0], handleEnds[0]], [itemSize[0], handleEnds[1]], [itemSize[0] - symbolSizes[1], handleEnds[1]]];
  374. };
  375. ContinuousView.prototype._createBarGroup = function (itemAlign) {
  376. var orient = this._orient;
  377. var inverse = this.visualMapModel.get('inverse');
  378. return new graphic.Group(orient === 'horizontal' && !inverse ? {
  379. scaleX: itemAlign === 'bottom' ? 1 : -1,
  380. rotation: Math.PI / 2
  381. } : orient === 'horizontal' && inverse ? {
  382. scaleX: itemAlign === 'bottom' ? -1 : 1,
  383. rotation: -Math.PI / 2
  384. } : orient === 'vertical' && !inverse ? {
  385. scaleX: itemAlign === 'left' ? 1 : -1,
  386. scaleY: -1
  387. } : {
  388. scaleX: itemAlign === 'left' ? 1 : -1
  389. });
  390. };
  391. ContinuousView.prototype._updateHandle = function (handleEnds, visualInRange) {
  392. if (!this._useHandle) {
  393. return;
  394. }
  395. var shapes = this._shapes;
  396. var visualMapModel = this.visualMapModel;
  397. var handleThumbs = shapes.handleThumbs;
  398. var handleLabels = shapes.handleLabels;
  399. var itemSize = visualMapModel.itemSize;
  400. var dataExtent = visualMapModel.getExtent();
  401. each([0, 1], function (handleIndex) {
  402. var handleThumb = handleThumbs[handleIndex];
  403. handleThumb.setStyle('fill', visualInRange.handlesColor[handleIndex]);
  404. handleThumb.y = handleEnds[handleIndex];
  405. var val = linearMap(handleEnds[handleIndex], [0, itemSize[1]], dataExtent, true);
  406. var symbolSize = this.getControllerVisual(val, 'symbolSize');
  407. handleThumb.scaleX = handleThumb.scaleY = symbolSize / itemSize[0];
  408. handleThumb.x = itemSize[0] - symbolSize / 2; // Update handle label position.
  409. var textPoint = graphic.applyTransform(shapes.handleLabelPoints[handleIndex], graphic.getTransform(handleThumb, this.group));
  410. handleLabels[handleIndex].setStyle({
  411. x: textPoint[0],
  412. y: textPoint[1],
  413. text: visualMapModel.formatValueText(this._dataInterval[handleIndex]),
  414. verticalAlign: 'middle',
  415. align: this._orient === 'vertical' ? this._applyTransform('left', shapes.mainGroup) : 'center'
  416. });
  417. }, this);
  418. };
  419. ContinuousView.prototype._showIndicator = function (cursorValue, textValue, rangeSymbol, halfHoverLinkSize) {
  420. var visualMapModel = this.visualMapModel;
  421. var dataExtent = visualMapModel.getExtent();
  422. var itemSize = visualMapModel.itemSize;
  423. var sizeExtent = [0, itemSize[1]];
  424. var shapes = this._shapes;
  425. var indicator = shapes.indicator;
  426. if (!indicator) {
  427. return;
  428. }
  429. indicator.attr('invisible', false);
  430. var opts = {
  431. convertOpacityToAlpha: true
  432. };
  433. var color = this.getControllerVisual(cursorValue, 'color', opts);
  434. var symbolSize = this.getControllerVisual(cursorValue, 'symbolSize');
  435. var y = linearMap(cursorValue, dataExtent, sizeExtent, true);
  436. var x = itemSize[0] - symbolSize / 2;
  437. var oldIndicatorPos = {
  438. x: indicator.x,
  439. y: indicator.y
  440. }; // Update handle label position.
  441. indicator.y = y;
  442. indicator.x = x;
  443. var textPoint = graphic.applyTransform(shapes.indicatorLabelPoint, graphic.getTransform(indicator, this.group));
  444. var indicatorLabel = shapes.indicatorLabel;
  445. indicatorLabel.attr('invisible', false);
  446. var align = this._applyTransform('left', shapes.mainGroup);
  447. var orient = this._orient;
  448. var isHorizontal = orient === 'horizontal';
  449. indicatorLabel.setStyle({
  450. text: (rangeSymbol ? rangeSymbol : '') + visualMapModel.formatValueText(textValue),
  451. verticalAlign: isHorizontal ? align : 'middle',
  452. align: isHorizontal ? 'center' : align
  453. });
  454. var indicatorNewProps = {
  455. x: x,
  456. y: y,
  457. style: {
  458. fill: color
  459. }
  460. };
  461. var labelNewProps = {
  462. style: {
  463. x: textPoint[0],
  464. y: textPoint[1]
  465. }
  466. };
  467. if (visualMapModel.ecModel.isAnimationEnabled() && !this._firstShowIndicator) {
  468. var animationCfg = {
  469. duration: 100,
  470. easing: 'cubicInOut',
  471. additive: true
  472. };
  473. indicator.x = oldIndicatorPos.x;
  474. indicator.y = oldIndicatorPos.y;
  475. indicator.animateTo(indicatorNewProps, animationCfg);
  476. indicatorLabel.animateTo(labelNewProps, animationCfg);
  477. } else {
  478. indicator.attr(indicatorNewProps);
  479. indicatorLabel.attr(labelNewProps);
  480. }
  481. this._firstShowIndicator = false;
  482. var handleLabels = this._shapes.handleLabels;
  483. if (handleLabels) {
  484. for (var i = 0; i < handleLabels.length; i++) {
  485. // Fade out handle labels.
  486. // NOTE: Must use api enter/leave on emphasis/blur/select state. Or the global states manager will change it.
  487. this._api.enterBlur(handleLabels[i]);
  488. }
  489. }
  490. };
  491. ContinuousView.prototype._enableHoverLinkToSeries = function () {
  492. var self = this;
  493. this._shapes.mainGroup.on('mousemove', function (e) {
  494. self._hovering = true;
  495. if (!self._dragging) {
  496. var itemSize = self.visualMapModel.itemSize;
  497. var pos = self._applyTransform([e.offsetX, e.offsetY], self._shapes.mainGroup, true, true); // For hover link show when hover handle, which might be
  498. // below or upper than sizeExtent.
  499. pos[1] = mathMin(mathMax(0, pos[1]), itemSize[1]);
  500. self._doHoverLinkToSeries(pos[1], 0 <= pos[0] && pos[0] <= itemSize[0]);
  501. }
  502. }).on('mouseout', function () {
  503. // When mouse is out of handle, hoverLink still need
  504. // to be displayed when realtime is set as false.
  505. self._hovering = false;
  506. !self._dragging && self._clearHoverLinkToSeries();
  507. });
  508. };
  509. ContinuousView.prototype._enableHoverLinkFromSeries = function () {
  510. var zr = this.api.getZr();
  511. if (this.visualMapModel.option.hoverLink) {
  512. zr.on('mouseover', this._hoverLinkFromSeriesMouseOver, this);
  513. zr.on('mouseout', this._hideIndicator, this);
  514. } else {
  515. this._clearHoverLinkFromSeries();
  516. }
  517. };
  518. ContinuousView.prototype._doHoverLinkToSeries = function (cursorPos, hoverOnBar) {
  519. var visualMapModel = this.visualMapModel;
  520. var itemSize = visualMapModel.itemSize;
  521. if (!visualMapModel.option.hoverLink) {
  522. return;
  523. }
  524. var sizeExtent = [0, itemSize[1]];
  525. var dataExtent = visualMapModel.getExtent(); // For hover link show when hover handle, which might be below or upper than sizeExtent.
  526. cursorPos = mathMin(mathMax(sizeExtent[0], cursorPos), sizeExtent[1]);
  527. var halfHoverLinkSize = getHalfHoverLinkSize(visualMapModel, dataExtent, sizeExtent);
  528. var hoverRange = [cursorPos - halfHoverLinkSize, cursorPos + halfHoverLinkSize];
  529. var cursorValue = linearMap(cursorPos, sizeExtent, dataExtent, true);
  530. var valueRange = [linearMap(hoverRange[0], sizeExtent, dataExtent, true), linearMap(hoverRange[1], sizeExtent, dataExtent, true)]; // Consider data range is out of visualMap range, see test/visualMap-continuous.html,
  531. // where china and india has very large population.
  532. hoverRange[0] < sizeExtent[0] && (valueRange[0] = -Infinity);
  533. hoverRange[1] > sizeExtent[1] && (valueRange[1] = Infinity); // Do not show indicator when mouse is over handle,
  534. // otherwise labels overlap, especially when dragging.
  535. if (hoverOnBar) {
  536. if (valueRange[0] === -Infinity) {
  537. this._showIndicator(cursorValue, valueRange[1], '< ', halfHoverLinkSize);
  538. } else if (valueRange[1] === Infinity) {
  539. this._showIndicator(cursorValue, valueRange[0], '> ', halfHoverLinkSize);
  540. } else {
  541. this._showIndicator(cursorValue, cursorValue, '≈ ', halfHoverLinkSize);
  542. }
  543. } // When realtime is set as false, handles, which are in barGroup,
  544. // also trigger hoverLink, which help user to realize where they
  545. // focus on when dragging. (see test/heatmap-large.html)
  546. // When realtime is set as true, highlight will not show when hover
  547. // handle, because the label on handle, which displays a exact value
  548. // but not range, might mislead users.
  549. var oldBatch = this._hoverLinkDataIndices;
  550. var newBatch = [];
  551. if (hoverOnBar || useHoverLinkOnHandle(visualMapModel)) {
  552. newBatch = this._hoverLinkDataIndices = visualMapModel.findTargetDataIndices(valueRange);
  553. }
  554. var resultBatches = modelUtil.compressBatches(oldBatch, newBatch);
  555. this._dispatchHighDown('downplay', helper.makeHighDownBatch(resultBatches[0], visualMapModel));
  556. this._dispatchHighDown('highlight', helper.makeHighDownBatch(resultBatches[1], visualMapModel));
  557. };
  558. ContinuousView.prototype._hoverLinkFromSeriesMouseOver = function (e) {
  559. var el = e.target;
  560. var visualMapModel = this.visualMapModel;
  561. if (!el || getECData(el).dataIndex == null) {
  562. return;
  563. }
  564. var ecData = getECData(el);
  565. var dataModel = this.ecModel.getSeriesByIndex(ecData.seriesIndex);
  566. if (!visualMapModel.isTargetSeries(dataModel)) {
  567. return;
  568. }
  569. var data = dataModel.getData(ecData.dataType);
  570. var value = data.getStore().get(visualMapModel.getDataDimensionIndex(data), ecData.dataIndex);
  571. if (!isNaN(value)) {
  572. this._showIndicator(value, value);
  573. }
  574. };
  575. ContinuousView.prototype._hideIndicator = function () {
  576. var shapes = this._shapes;
  577. shapes.indicator && shapes.indicator.attr('invisible', true);
  578. shapes.indicatorLabel && shapes.indicatorLabel.attr('invisible', true);
  579. var handleLabels = this._shapes.handleLabels;
  580. if (handleLabels) {
  581. for (var i = 0; i < handleLabels.length; i++) {
  582. // Fade out handle labels.
  583. // NOTE: Must use api enter/leave on emphasis/blur/select state. Or the global states manager will change it.
  584. this._api.leaveBlur(handleLabels[i]);
  585. }
  586. }
  587. };
  588. ContinuousView.prototype._clearHoverLinkToSeries = function () {
  589. this._hideIndicator();
  590. var indices = this._hoverLinkDataIndices;
  591. this._dispatchHighDown('downplay', helper.makeHighDownBatch(indices, this.visualMapModel));
  592. indices.length = 0;
  593. };
  594. ContinuousView.prototype._clearHoverLinkFromSeries = function () {
  595. this._hideIndicator();
  596. var zr = this.api.getZr();
  597. zr.off('mouseover', this._hoverLinkFromSeriesMouseOver);
  598. zr.off('mouseout', this._hideIndicator);
  599. };
  600. ContinuousView.prototype._applyTransform = function (vertex, element, inverse, global) {
  601. var transform = graphic.getTransform(element, global ? null : this.group);
  602. return zrUtil.isArray(vertex) ? graphic.applyTransform(vertex, transform, inverse) : graphic.transformDirection(vertex, transform, inverse);
  603. }; // TODO: TYPE more specified payload types.
  604. ContinuousView.prototype._dispatchHighDown = function (type, batch) {
  605. batch && batch.length && this.api.dispatchAction({
  606. type: type,
  607. batch: batch
  608. });
  609. };
  610. /**
  611. * @override
  612. */
  613. ContinuousView.prototype.dispose = function () {
  614. this._clearHoverLinkFromSeries();
  615. this._clearHoverLinkToSeries();
  616. };
  617. /**
  618. * @override
  619. */
  620. ContinuousView.prototype.remove = function () {
  621. this._clearHoverLinkFromSeries();
  622. this._clearHoverLinkToSeries();
  623. };
  624. ContinuousView.type = 'visualMap.continuous';
  625. return ContinuousView;
  626. }(VisualMapView);
  627. function createPolygon(points, cursor, onDrift, onDragEnd) {
  628. return new graphic.Polygon({
  629. shape: {
  630. points: points
  631. },
  632. draggable: !!onDrift,
  633. cursor: cursor,
  634. drift: onDrift,
  635. onmousemove: function (e) {
  636. // Fot mobile devicem, prevent screen slider on the button.
  637. eventTool.stop(e.event);
  638. },
  639. ondragend: onDragEnd
  640. });
  641. }
  642. function getHalfHoverLinkSize(visualMapModel, dataExtent, sizeExtent) {
  643. var halfHoverLinkSize = HOVER_LINK_SIZE / 2;
  644. var hoverLinkDataSize = visualMapModel.get('hoverLinkDataSize');
  645. if (hoverLinkDataSize) {
  646. halfHoverLinkSize = linearMap(hoverLinkDataSize, dataExtent, sizeExtent, true) / 2;
  647. }
  648. return halfHoverLinkSize;
  649. }
  650. function useHoverLinkOnHandle(visualMapModel) {
  651. var hoverLinkOnHandle = visualMapModel.get('hoverLinkOnHandle');
  652. return !!(hoverLinkOnHandle == null ? visualMapModel.get('realtime') : hoverLinkOnHandle);
  653. }
  654. function getCursor(orient) {
  655. return orient === 'vertical' ? 'ns-resize' : 'ew-resize';
  656. }
  657. export default ContinuousView;