SliderZoomView.js 23 KB

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