SliderZoomView.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710
  1. var zrUtil = require("zrender/lib/core/util");
  2. var eventTool = require("zrender/lib/core/event");
  3. var graphic = require("../../util/graphic");
  4. var throttle = require("../../util/throttle");
  5. var DataZoomView = require("./DataZoomView");
  6. var numberUtil = require("../../util/number");
  7. var layout = require("../../util/layout");
  8. var sliderMove = require("../helper/sliderMove");
  9. var Rect = graphic.Rect;
  10. var linearMap = numberUtil.linearMap;
  11. var asc = numberUtil.asc;
  12. var bind = zrUtil.bind;
  13. var each = zrUtil.each; // Constants
  14. var DEFAULT_LOCATION_EDGE_GAP = 7;
  15. var DEFAULT_FRAME_BORDER_WIDTH = 1;
  16. var DEFAULT_FILLER_SIZE = 30;
  17. var HORIZONTAL = 'horizontal';
  18. var VERTICAL = 'vertical';
  19. var LABEL_GAP = 5;
  20. var SHOW_DATA_SHADOW_SERIES_TYPE = ['line', 'bar', 'candlestick', 'scatter'];
  21. var SliderZoomView = DataZoomView.extend({
  22. type: 'dataZoom.slider',
  23. init: function (ecModel, api) {
  24. /**
  25. * @private
  26. * @type {Object}
  27. */
  28. this._displayables = {};
  29. /**
  30. * @private
  31. * @type {string}
  32. */
  33. this._orient;
  34. /**
  35. * [0, 100]
  36. * @private
  37. */
  38. this._range;
  39. /**
  40. * [coord of the first handle, coord of the second handle]
  41. * @private
  42. */
  43. this._handleEnds;
  44. /**
  45. * [length, thick]
  46. * @private
  47. * @type {Array.<number>}
  48. */
  49. this._size;
  50. /**
  51. * @private
  52. * @type {number}
  53. */
  54. this._handleWidth;
  55. /**
  56. * @private
  57. * @type {number}
  58. */
  59. this._handleHeight;
  60. /**
  61. * @private
  62. */
  63. this._location;
  64. /**
  65. * @private
  66. */
  67. this._dragging;
  68. /**
  69. * @private
  70. */
  71. this._dataShadowInfo;
  72. this.api = api;
  73. },
  74. /**
  75. * @override
  76. */
  77. render: function (dataZoomModel, ecModel, api, payload) {
  78. SliderZoomView.superApply(this, 'render', arguments);
  79. throttle.createOrUpdate(this, '_dispatchZoomAction', this.dataZoomModel.get('throttle'), 'fixRate');
  80. this._orient = dataZoomModel.get('orient');
  81. if (this.dataZoomModel.get('show') === false) {
  82. this.group.removeAll();
  83. return;
  84. } // Notice: this._resetInterval() should not be executed when payload.type
  85. // is 'dataZoom', origin this._range should be maintained, otherwise 'pan'
  86. // or 'zoom' info will be missed because of 'throttle' of this.dispatchAction,
  87. if (!payload || payload.type !== 'dataZoom' || payload.from !== this.uid) {
  88. this._buildView();
  89. }
  90. this._updateView();
  91. },
  92. /**
  93. * @override
  94. */
  95. remove: function () {
  96. SliderZoomView.superApply(this, 'remove', arguments);
  97. throttle.clear(this, '_dispatchZoomAction');
  98. },
  99. /**
  100. * @override
  101. */
  102. dispose: function () {
  103. SliderZoomView.superApply(this, 'dispose', arguments);
  104. throttle.clear(this, '_dispatchZoomAction');
  105. },
  106. _buildView: function () {
  107. var thisGroup = this.group;
  108. thisGroup.removeAll();
  109. this._resetLocation();
  110. this._resetInterval();
  111. var barGroup = this._displayables.barGroup = new graphic.Group();
  112. this._renderBackground();
  113. this._renderHandle();
  114. this._renderDataShadow();
  115. thisGroup.add(barGroup);
  116. this._positionGroup();
  117. },
  118. /**
  119. * @private
  120. */
  121. _resetLocation: function () {
  122. var dataZoomModel = this.dataZoomModel;
  123. var api = this.api; // If some of x/y/width/height are not specified,
  124. // auto-adapt according to target grid.
  125. var coordRect = this._findCoordRect();
  126. var ecSize = {
  127. width: api.getWidth(),
  128. height: api.getHeight()
  129. }; // Default align by coordinate system rect.
  130. var positionInfo = this._orient === HORIZONTAL ? {
  131. // Why using 'right', because right should be used in vertical,
  132. // and it is better to be consistent for dealing with position param merge.
  133. right: ecSize.width - coordRect.x - coordRect.width,
  134. top: ecSize.height - DEFAULT_FILLER_SIZE - DEFAULT_LOCATION_EDGE_GAP,
  135. width: coordRect.width,
  136. height: DEFAULT_FILLER_SIZE
  137. } : {
  138. // vertical
  139. right: DEFAULT_LOCATION_EDGE_GAP,
  140. top: coordRect.y,
  141. width: DEFAULT_FILLER_SIZE,
  142. height: coordRect.height
  143. }; // Do not write back to option and replace value 'ph', because
  144. // the 'ph' value should be recalculated when resize.
  145. var layoutParams = layout.getLayoutParams(dataZoomModel.option); // Replace the placeholder value.
  146. zrUtil.each(['right', 'top', 'width', 'height'], function (name) {
  147. if (layoutParams[name] === 'ph') {
  148. layoutParams[name] = positionInfo[name];
  149. }
  150. });
  151. var layoutRect = layout.getLayoutRect(layoutParams, ecSize, dataZoomModel.padding);
  152. this._location = {
  153. x: layoutRect.x,
  154. y: layoutRect.y
  155. };
  156. this._size = [layoutRect.width, layoutRect.height];
  157. this._orient === VERTICAL && this._size.reverse();
  158. },
  159. /**
  160. * @private
  161. */
  162. _positionGroup: function () {
  163. var thisGroup = this.group;
  164. var location = this._location;
  165. var orient = this._orient; // Just use the first axis to determine mapping.
  166. var targetAxisModel = this.dataZoomModel.getFirstTargetAxisModel();
  167. var inverse = targetAxisModel && targetAxisModel.get('inverse');
  168. var barGroup = this._displayables.barGroup;
  169. var otherAxisInverse = (this._dataShadowInfo || {}).otherAxisInverse; // Transform barGroup.
  170. barGroup.attr(orient === HORIZONTAL && !inverse ? {
  171. scale: otherAxisInverse ? [1, 1] : [1, -1]
  172. } : orient === HORIZONTAL && inverse ? {
  173. scale: otherAxisInverse ? [-1, 1] : [-1, -1]
  174. } : orient === VERTICAL && !inverse ? {
  175. scale: otherAxisInverse ? [1, -1] : [1, 1],
  176. rotation: Math.PI / 2 // Dont use Math.PI, considering shadow direction.
  177. } : {
  178. scale: otherAxisInverse ? [-1, -1] : [-1, 1],
  179. rotation: Math.PI / 2
  180. }); // Position barGroup
  181. var rect = thisGroup.getBoundingRect([barGroup]);
  182. thisGroup.attr('position', [location.x - rect.x, location.y - rect.y]);
  183. },
  184. /**
  185. * @private
  186. */
  187. _getViewExtent: function () {
  188. return [0, this._size[0]];
  189. },
  190. _renderBackground: function () {
  191. var dataZoomModel = this.dataZoomModel;
  192. var size = this._size;
  193. var barGroup = this._displayables.barGroup;
  194. barGroup.add(new Rect({
  195. silent: true,
  196. shape: {
  197. x: 0,
  198. y: 0,
  199. width: size[0],
  200. height: size[1]
  201. },
  202. style: {
  203. fill: dataZoomModel.get('backgroundColor')
  204. },
  205. z2: -40
  206. })); // Click panel, over shadow, below handles.
  207. barGroup.add(new Rect({
  208. shape: {
  209. x: 0,
  210. y: 0,
  211. width: size[0],
  212. height: size[1]
  213. },
  214. style: {
  215. fill: 'transparent'
  216. },
  217. z2: 0,
  218. onclick: zrUtil.bind(this._onClickPanelClick, this)
  219. }));
  220. },
  221. _renderDataShadow: function () {
  222. var info = this._dataShadowInfo = this._prepareDataShadowInfo();
  223. if (!info) {
  224. return;
  225. }
  226. var size = this._size;
  227. var seriesModel = info.series;
  228. var data = seriesModel.getRawData();
  229. var otherDim = seriesModel.getShadowDim ? seriesModel.getShadowDim() // @see candlestick
  230. : info.otherDim;
  231. if (otherDim == null) {
  232. return;
  233. }
  234. var otherDataExtent = data.getDataExtent(otherDim); // Nice extent.
  235. var otherOffset = (otherDataExtent[1] - otherDataExtent[0]) * 0.3;
  236. otherDataExtent = [otherDataExtent[0] - otherOffset, otherDataExtent[1] + otherOffset];
  237. var otherShadowExtent = [0, size[1]];
  238. var thisShadowExtent = [0, size[0]];
  239. var areaPoints = [[size[0], 0], [0, 0]];
  240. var linePoints = [];
  241. var step = thisShadowExtent[1] / (data.count() - 1);
  242. var thisCoord = 0; // Optimize for large data shadow
  243. var stride = Math.round(data.count() / size[0]);
  244. var lastIsEmpty;
  245. data.each([otherDim], function (value, index) {
  246. if (stride > 0 && index % stride) {
  247. thisCoord += step;
  248. return;
  249. } // FIXME
  250. // Should consider axis.min/axis.max when drawing dataShadow.
  251. // FIXME
  252. // 应该使用统一的空判断?还是在list里进行空判断?
  253. var isEmpty = value == null || isNaN(value) || value === ''; // See #4235.
  254. var otherCoord = isEmpty ? 0 : linearMap(value, otherDataExtent, otherShadowExtent, true); // Attempt to draw data shadow precisely when there are empty value.
  255. if (isEmpty && !lastIsEmpty && index) {
  256. areaPoints.push([areaPoints[areaPoints.length - 1][0], 0]);
  257. linePoints.push([linePoints[linePoints.length - 1][0], 0]);
  258. } else if (!isEmpty && lastIsEmpty) {
  259. areaPoints.push([thisCoord, 0]);
  260. linePoints.push([thisCoord, 0]);
  261. }
  262. areaPoints.push([thisCoord, otherCoord]);
  263. linePoints.push([thisCoord, otherCoord]);
  264. thisCoord += step;
  265. lastIsEmpty = isEmpty;
  266. });
  267. var dataZoomModel = this.dataZoomModel; // var dataBackgroundModel = dataZoomModel.getModel('dataBackground');
  268. this._displayables.barGroup.add(new graphic.Polygon({
  269. shape: {
  270. points: areaPoints
  271. },
  272. style: zrUtil.defaults({
  273. fill: dataZoomModel.get('dataBackgroundColor')
  274. }, dataZoomModel.getModel('dataBackground.areaStyle').getAreaStyle()),
  275. silent: true,
  276. z2: -20
  277. }));
  278. this._displayables.barGroup.add(new graphic.Polyline({
  279. shape: {
  280. points: linePoints
  281. },
  282. style: dataZoomModel.getModel('dataBackground.lineStyle').getLineStyle(),
  283. silent: true,
  284. z2: -19
  285. }));
  286. },
  287. _prepareDataShadowInfo: function () {
  288. var dataZoomModel = this.dataZoomModel;
  289. var showDataShadow = dataZoomModel.get('showDataShadow');
  290. if (showDataShadow === false) {
  291. return;
  292. } // Find a representative series.
  293. var result;
  294. var ecModel = this.ecModel;
  295. dataZoomModel.eachTargetAxis(function (dimNames, axisIndex) {
  296. var seriesModels = dataZoomModel.getAxisProxy(dimNames.name, axisIndex).getTargetSeriesModels();
  297. zrUtil.each(seriesModels, function (seriesModel) {
  298. if (result) {
  299. return;
  300. }
  301. if (showDataShadow !== true && zrUtil.indexOf(SHOW_DATA_SHADOW_SERIES_TYPE, seriesModel.get('type')) < 0) {
  302. return;
  303. }
  304. var thisAxis = ecModel.getComponent(dimNames.axis, axisIndex).axis;
  305. var otherDim = getOtherDim(dimNames.name);
  306. var otherAxisInverse;
  307. var coordSys = seriesModel.coordinateSystem;
  308. if (otherDim != null && coordSys.getOtherAxis) {
  309. otherAxisInverse = coordSys.getOtherAxis(thisAxis).inverse;
  310. }
  311. result = {
  312. thisAxis: thisAxis,
  313. series: seriesModel,
  314. thisDim: dimNames.name,
  315. otherDim: otherDim,
  316. otherAxisInverse: otherAxisInverse
  317. };
  318. }, this);
  319. }, this);
  320. return result;
  321. },
  322. _renderHandle: function () {
  323. var displaybles = this._displayables;
  324. var handles = displaybles.handles = [];
  325. var handleLabels = displaybles.handleLabels = [];
  326. var barGroup = this._displayables.barGroup;
  327. var size = this._size;
  328. var dataZoomModel = this.dataZoomModel;
  329. barGroup.add(displaybles.filler = new Rect({
  330. draggable: true,
  331. cursor: getCursor(this._orient),
  332. drift: bind(this._onDragMove, this, 'all'),
  333. onmousemove: function (e) {
  334. // Fot mobile devicem, prevent screen slider on the button.
  335. eventTool.stop(e.event);
  336. },
  337. ondragstart: bind(this._showDataInfo, this, true),
  338. ondragend: bind(this._onDragEnd, this),
  339. onmouseover: bind(this._showDataInfo, this, true),
  340. onmouseout: bind(this._showDataInfo, this, false),
  341. style: {
  342. fill: dataZoomModel.get('fillerColor'),
  343. textPosition: 'inside'
  344. }
  345. })); // Frame border.
  346. barGroup.add(new Rect(graphic.subPixelOptimizeRect({
  347. silent: true,
  348. shape: {
  349. x: 0,
  350. y: 0,
  351. width: size[0],
  352. height: size[1]
  353. },
  354. style: {
  355. stroke: dataZoomModel.get('dataBackgroundColor') || dataZoomModel.get('borderColor'),
  356. lineWidth: DEFAULT_FRAME_BORDER_WIDTH,
  357. fill: 'rgba(0,0,0,0)'
  358. }
  359. })));
  360. each([0, 1], function (handleIndex) {
  361. var path = graphic.createIcon(dataZoomModel.get('handleIcon'), {
  362. cursor: getCursor(this._orient),
  363. draggable: true,
  364. drift: bind(this._onDragMove, this, handleIndex),
  365. onmousemove: function (e) {
  366. // Fot mobile devicem, prevent screen slider on the button.
  367. eventTool.stop(e.event);
  368. },
  369. ondragend: bind(this._onDragEnd, this),
  370. onmouseover: bind(this._showDataInfo, this, true),
  371. onmouseout: bind(this._showDataInfo, this, false)
  372. }, {
  373. x: -1,
  374. y: 0,
  375. width: 2,
  376. height: 2
  377. });
  378. var bRect = path.getBoundingRect();
  379. this._handleHeight = numberUtil.parsePercent(dataZoomModel.get('handleSize'), this._size[1]);
  380. this._handleWidth = bRect.width / bRect.height * this._handleHeight;
  381. path.setStyle(dataZoomModel.getModel('handleStyle').getItemStyle());
  382. var handleColor = dataZoomModel.get('handleColor'); // Compatitable with previous version
  383. if (handleColor != null) {
  384. path.style.fill = handleColor;
  385. }
  386. barGroup.add(handles[handleIndex] = path);
  387. var textStyleModel = dataZoomModel.textStyleModel;
  388. this.group.add(handleLabels[handleIndex] = new graphic.Text({
  389. silent: true,
  390. invisible: true,
  391. style: {
  392. x: 0,
  393. y: 0,
  394. text: '',
  395. textVerticalAlign: 'middle',
  396. textAlign: 'center',
  397. textFill: textStyleModel.getTextColor(),
  398. textFont: textStyleModel.getFont()
  399. },
  400. z2: 10
  401. }));
  402. }, this);
  403. },
  404. /**
  405. * @private
  406. */
  407. _resetInterval: function () {
  408. var range = this._range = this.dataZoomModel.getPercentRange();
  409. var viewExtent = this._getViewExtent();
  410. this._handleEnds = [linearMap(range[0], [0, 100], viewExtent, true), linearMap(range[1], [0, 100], viewExtent, true)];
  411. },
  412. /**
  413. * @private
  414. * @param {(number|string)} handleIndex 0 or 1 or 'all'
  415. * @param {number} delta
  416. */
  417. _updateInterval: function (handleIndex, delta) {
  418. var dataZoomModel = this.dataZoomModel;
  419. var handleEnds = this._handleEnds;
  420. var viewExtend = this._getViewExtent();
  421. var minMaxSpan = dataZoomModel.findRepresentativeAxisProxy().getMinMaxSpan();
  422. var percentExtent = [0, 100];
  423. sliderMove(delta, handleEnds, viewExtend, dataZoomModel.get('zoomLock') ? 'all' : handleIndex, minMaxSpan.minSpan != null ? linearMap(minMaxSpan.minSpan, percentExtent, viewExtend, true) : null, minMaxSpan.maxSpan != null ? linearMap(minMaxSpan.maxSpan, percentExtent, viewExtend, true) : null);
  424. this._range = asc([linearMap(handleEnds[0], viewExtend, percentExtent, true), linearMap(handleEnds[1], viewExtend, percentExtent, true)]);
  425. },
  426. /**
  427. * @private
  428. */
  429. _updateView: function (nonRealtime) {
  430. var displaybles = this._displayables;
  431. var handleEnds = this._handleEnds;
  432. var handleInterval = asc(handleEnds.slice());
  433. var size = this._size;
  434. each([0, 1], function (handleIndex) {
  435. // Handles
  436. var handle = displaybles.handles[handleIndex];
  437. var handleHeight = this._handleHeight;
  438. handle.attr({
  439. scale: [handleHeight / 2, handleHeight / 2],
  440. position: [handleEnds[handleIndex], size[1] / 2 - handleHeight / 2]
  441. });
  442. }, this); // Filler
  443. displaybles.filler.setShape({
  444. x: handleInterval[0],
  445. y: 0,
  446. width: handleInterval[1] - handleInterval[0],
  447. height: size[1]
  448. });
  449. this._updateDataInfo(nonRealtime);
  450. },
  451. /**
  452. * @private
  453. */
  454. _updateDataInfo: function (nonRealtime) {
  455. var dataZoomModel = this.dataZoomModel;
  456. var displaybles = this._displayables;
  457. var handleLabels = displaybles.handleLabels;
  458. var orient = this._orient;
  459. var labelTexts = ['', '']; // FIXME
  460. // date型,支持formatter,autoformatter(ec2 date.getAutoFormatter)
  461. if (dataZoomModel.get('showDetail')) {
  462. var axisProxy = dataZoomModel.findRepresentativeAxisProxy();
  463. if (axisProxy) {
  464. var axis = axisProxy.getAxisModel().axis;
  465. var range = this._range;
  466. var dataInterval = nonRealtime // See #4434, data and axis are not processed and reset yet in non-realtime mode.
  467. ? axisProxy.calculateDataWindow({
  468. start: range[0],
  469. end: range[1]
  470. }).valueWindow : axisProxy.getDataValueWindow();
  471. labelTexts = [this._formatLabel(dataInterval[0], axis), this._formatLabel(dataInterval[1], axis)];
  472. }
  473. }
  474. var orderedHandleEnds = asc(this._handleEnds.slice());
  475. setLabel.call(this, 0);
  476. setLabel.call(this, 1);
  477. function setLabel(handleIndex) {
  478. // Label
  479. // Text should not transform by barGroup.
  480. // Ignore handlers transform
  481. var barTransform = graphic.getTransform(displaybles.handles[handleIndex].parent, this.group);
  482. var direction = graphic.transformDirection(handleIndex === 0 ? 'right' : 'left', barTransform);
  483. var offset = this._handleWidth / 2 + LABEL_GAP;
  484. var textPoint = graphic.applyTransform([orderedHandleEnds[handleIndex] + (handleIndex === 0 ? -offset : offset), this._size[1] / 2], barTransform);
  485. handleLabels[handleIndex].setStyle({
  486. x: textPoint[0],
  487. y: textPoint[1],
  488. textVerticalAlign: orient === HORIZONTAL ? 'middle' : direction,
  489. textAlign: orient === HORIZONTAL ? direction : 'center',
  490. text: labelTexts[handleIndex]
  491. });
  492. }
  493. },
  494. /**
  495. * @private
  496. */
  497. _formatLabel: function (value, axis) {
  498. var dataZoomModel = this.dataZoomModel;
  499. var labelFormatter = dataZoomModel.get('labelFormatter');
  500. var labelPrecision = dataZoomModel.get('labelPrecision');
  501. if (labelPrecision == null || labelPrecision === 'auto') {
  502. labelPrecision = axis.getPixelPrecision();
  503. }
  504. var valueStr = value == null || isNaN(value) ? '' // FIXME Glue code
  505. : axis.type === 'category' || axis.type === 'time' ? axis.scale.getLabel(Math.round(value)) // param of toFixed should less then 20.
  506. : value.toFixed(Math.min(labelPrecision, 20));
  507. return zrUtil.isFunction(labelFormatter) ? labelFormatter(value, valueStr) : zrUtil.isString(labelFormatter) ? labelFormatter.replace('{value}', valueStr) : valueStr;
  508. },
  509. /**
  510. * @private
  511. * @param {boolean} showOrHide true: show, false: hide
  512. */
  513. _showDataInfo: function (showOrHide) {
  514. // Always show when drgging.
  515. showOrHide = this._dragging || showOrHide;
  516. var handleLabels = this._displayables.handleLabels;
  517. handleLabels[0].attr('invisible', !showOrHide);
  518. handleLabels[1].attr('invisible', !showOrHide);
  519. },
  520. _onDragMove: function (handleIndex, dx, dy) {
  521. this._dragging = true; // Transform dx, dy to bar coordination.
  522. var barTransform = this._displayables.barGroup.getLocalTransform();
  523. var vertex = graphic.applyTransform([dx, dy], barTransform, true);
  524. this._updateInterval(handleIndex, vertex[0]);
  525. var realtime = this.dataZoomModel.get('realtime');
  526. this._updateView(!realtime);
  527. if (realtime) {
  528. realtime && this._dispatchZoomAction();
  529. }
  530. },
  531. _onDragEnd: function () {
  532. this._dragging = false;
  533. this._showDataInfo(false);
  534. this._dispatchZoomAction();
  535. },
  536. _onClickPanelClick: function (e) {
  537. var size = this._size;
  538. var localPoint = this._displayables.barGroup.transformCoordToLocal(e.offsetX, e.offsetY);
  539. if (localPoint[0] < 0 || localPoint[0] > size[0] || localPoint[1] < 0 || localPoint[1] > size[1]) {
  540. return;
  541. }
  542. var handleEnds = this._handleEnds;
  543. var center = (handleEnds[0] + handleEnds[1]) / 2;
  544. this._updateInterval('all', localPoint[0] - center);
  545. this._updateView();
  546. this._dispatchZoomAction();
  547. },
  548. /**
  549. * This action will be throttled.
  550. * @private
  551. */
  552. _dispatchZoomAction: function () {
  553. var range = this._range;
  554. this.api.dispatchAction({
  555. type: 'dataZoom',
  556. from: this.uid,
  557. dataZoomId: this.dataZoomModel.id,
  558. start: range[0],
  559. end: range[1]
  560. });
  561. },
  562. /**
  563. * @private
  564. */
  565. _findCoordRect: function () {
  566. // Find the grid coresponding to the first axis referred by dataZoom.
  567. var rect;
  568. each(this.getTargetCoordInfo(), function (coordInfoList) {
  569. if (!rect && coordInfoList.length) {
  570. var coordSys = coordInfoList[0].model.coordinateSystem;
  571. rect = coordSys.getRect && coordSys.getRect();
  572. }
  573. });
  574. if (!rect) {
  575. var width = this.api.getWidth();
  576. var height = this.api.getHeight();
  577. rect = {
  578. x: width * 0.2,
  579. y: height * 0.2,
  580. width: width * 0.6,
  581. height: height * 0.6
  582. };
  583. }
  584. return rect;
  585. }
  586. });
  587. function getOtherDim(thisDim) {
  588. // FIXME
  589. // 这个逻辑和getOtherAxis里一致,但是写在这里是否不好
  590. var map = {
  591. x: 'y',
  592. y: 'x',
  593. radius: 'angle',
  594. angle: 'radius'
  595. };
  596. return map[thisDim];
  597. }
  598. function getCursor(orient) {
  599. return orient === 'vertical' ? 'ns-resize' : 'ew-resize';
  600. }
  601. var _default = SliderZoomView;
  602. module.exports = _default;