BarView.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698
  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 _config = require("../../config");
  20. var __DEV__ = _config.__DEV__;
  21. var echarts = require("../../echarts");
  22. var zrUtil = require("zrender/lib/core/util");
  23. var graphic = require("../../util/graphic");
  24. var _helper = require("./helper");
  25. var setLabel = _helper.setLabel;
  26. var Model = require("../../model/Model");
  27. var barItemStyle = require("./barItemStyle");
  28. var Path = require("zrender/lib/graphic/Path");
  29. var Group = require("zrender/lib/container/Group");
  30. var _throttle = require("../../util/throttle");
  31. var throttle = _throttle.throttle;
  32. var _createClipPathFromCoordSys = require("../helper/createClipPathFromCoordSys");
  33. var createClipPath = _createClipPathFromCoordSys.createClipPath;
  34. var Sausage = require("../../util/shape/sausage");
  35. /*
  36. * Licensed to the Apache Software Foundation (ASF) under one
  37. * or more contributor license agreements. See the NOTICE file
  38. * distributed with this work for additional information
  39. * regarding copyright ownership. The ASF licenses this file
  40. * to you under the Apache License, Version 2.0 (the
  41. * "License"); you may not use this file except in compliance
  42. * with the License. You may obtain a copy of the License at
  43. *
  44. * http://www.apache.org/licenses/LICENSE-2.0
  45. *
  46. * Unless required by applicable law or agreed to in writing,
  47. * software distributed under the License is distributed on an
  48. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  49. * KIND, either express or implied. See the License for the
  50. * specific language governing permissions and limitations
  51. * under the License.
  52. */
  53. var BAR_BORDER_WIDTH_QUERY = ['itemStyle', 'barBorderWidth'];
  54. var _eventPos = [0, 0]; // FIXME
  55. // Just for compatible with ec2.
  56. zrUtil.extend(Model.prototype, barItemStyle);
  57. function getClipArea(coord, data) {
  58. var coordSysClipArea = coord.getArea && coord.getArea();
  59. if (coord.type === 'cartesian2d') {
  60. var baseAxis = coord.getBaseAxis(); // When boundaryGap is false or using time axis. bar may exceed the grid.
  61. // We should not clip this part.
  62. // See test/bar2.html
  63. if (baseAxis.type !== 'category' || !baseAxis.onBand) {
  64. var expandWidth = data.getLayout('bandWidth');
  65. if (baseAxis.isHorizontal()) {
  66. coordSysClipArea.x -= expandWidth;
  67. coordSysClipArea.width += expandWidth * 2;
  68. } else {
  69. coordSysClipArea.y -= expandWidth;
  70. coordSysClipArea.height += expandWidth * 2;
  71. }
  72. }
  73. }
  74. return coordSysClipArea;
  75. }
  76. var _default = echarts.extendChartView({
  77. type: 'bar',
  78. render: function (seriesModel, ecModel, api) {
  79. this._updateDrawMode(seriesModel);
  80. var coordinateSystemType = seriesModel.get('coordinateSystem');
  81. if (coordinateSystemType === 'cartesian2d' || coordinateSystemType === 'polar') {
  82. this._isLargeDraw ? this._renderLarge(seriesModel, ecModel, api) : this._renderNormal(seriesModel, ecModel, api);
  83. } else {}
  84. return this.group;
  85. },
  86. incrementalPrepareRender: function (seriesModel, ecModel, api) {
  87. this._clear();
  88. this._updateDrawMode(seriesModel);
  89. },
  90. incrementalRender: function (params, seriesModel, ecModel, api) {
  91. // Do not support progressive in normal mode.
  92. this._incrementalRenderLarge(params, seriesModel);
  93. },
  94. _updateDrawMode: function (seriesModel) {
  95. var isLargeDraw = seriesModel.pipelineContext.large;
  96. if (this._isLargeDraw == null || isLargeDraw ^ this._isLargeDraw) {
  97. this._isLargeDraw = isLargeDraw;
  98. this._clear();
  99. }
  100. },
  101. _renderNormal: function (seriesModel, ecModel, api) {
  102. var group = this.group;
  103. var data = seriesModel.getData();
  104. var oldData = this._data;
  105. var coord = seriesModel.coordinateSystem;
  106. var baseAxis = coord.getBaseAxis();
  107. var isHorizontalOrRadial;
  108. if (coord.type === 'cartesian2d') {
  109. isHorizontalOrRadial = baseAxis.isHorizontal();
  110. } else if (coord.type === 'polar') {
  111. isHorizontalOrRadial = baseAxis.dim === 'angle';
  112. }
  113. var animationModel = seriesModel.isAnimationEnabled() ? seriesModel : null;
  114. var needsClip = seriesModel.get('clip', true);
  115. var coordSysClipArea = getClipArea(coord, data); // If there is clipPath created in large mode. Remove it.
  116. group.removeClipPath(); // We don't use clipPath in normal mode because we needs a perfect animation
  117. // And don't want the label are clipped.
  118. var roundCap = seriesModel.get('roundCap', true);
  119. var drawBackground = seriesModel.get('showBackground', true);
  120. var backgroundModel = seriesModel.getModel('backgroundStyle');
  121. var barBorderRadius = backgroundModel.get('barBorderRadius') || 0;
  122. var bgEls = [];
  123. var oldBgEls = this._backgroundEls || [];
  124. var createBackground = function (dataIndex) {
  125. var bgLayout = getLayout[coord.type](data, dataIndex);
  126. var bgEl = createBackgroundEl(coord, isHorizontalOrRadial, bgLayout);
  127. bgEl.useStyle(backgroundModel.getBarItemStyle()); // Only cartesian2d support borderRadius.
  128. if (coord.type === 'cartesian2d') {
  129. bgEl.setShape('r', barBorderRadius);
  130. }
  131. bgEls[dataIndex] = bgEl;
  132. return bgEl;
  133. };
  134. data.diff(oldData).add(function (dataIndex) {
  135. var itemModel = data.getItemModel(dataIndex);
  136. var layout = getLayout[coord.type](data, dataIndex, itemModel);
  137. if (drawBackground) {
  138. createBackground(dataIndex);
  139. } // If dataZoom in filteMode: 'empty', the baseValue can be set as NaN in "axisProxy".
  140. if (!data.hasValue(dataIndex)) {
  141. return;
  142. }
  143. if (needsClip) {
  144. // Clip will modify the layout params.
  145. // And return a boolean to determine if the shape are fully clipped.
  146. var isClipped = clip[coord.type](coordSysClipArea, layout);
  147. if (isClipped) {
  148. group.remove(el);
  149. return;
  150. }
  151. }
  152. var el = elementCreator[coord.type](dataIndex, layout, isHorizontalOrRadial, animationModel, false, roundCap);
  153. data.setItemGraphicEl(dataIndex, el);
  154. group.add(el);
  155. updateStyle(el, data, dataIndex, itemModel, layout, seriesModel, isHorizontalOrRadial, coord.type === 'polar');
  156. }).update(function (newIndex, oldIndex) {
  157. var itemModel = data.getItemModel(newIndex);
  158. var layout = getLayout[coord.type](data, newIndex, itemModel);
  159. if (drawBackground) {
  160. var bgEl;
  161. if (oldBgEls.length === 0) {
  162. bgEl = createBackground(oldIndex);
  163. } else {
  164. bgEl = oldBgEls[oldIndex];
  165. bgEl.useStyle(backgroundModel.getBarItemStyle()); // Only cartesian2d support borderRadius.
  166. if (coord.type === 'cartesian2d') {
  167. bgEl.setShape('r', barBorderRadius);
  168. }
  169. bgEls[newIndex] = bgEl;
  170. }
  171. var bgLayout = getLayout[coord.type](data, newIndex);
  172. var shape = createBackgroundShape(isHorizontalOrRadial, bgLayout, coord);
  173. graphic.updateProps(bgEl, {
  174. shape: shape
  175. }, animationModel, newIndex);
  176. }
  177. var el = oldData.getItemGraphicEl(oldIndex);
  178. if (!data.hasValue(newIndex)) {
  179. group.remove(el);
  180. return;
  181. }
  182. if (needsClip) {
  183. var isClipped = clip[coord.type](coordSysClipArea, layout);
  184. if (isClipped) {
  185. group.remove(el);
  186. return;
  187. }
  188. }
  189. if (el) {
  190. graphic.updateProps(el, {
  191. shape: layout
  192. }, animationModel, newIndex);
  193. } else {
  194. el = elementCreator[coord.type](newIndex, layout, isHorizontalOrRadial, animationModel, true, roundCap);
  195. }
  196. data.setItemGraphicEl(newIndex, el); // Add back
  197. group.add(el);
  198. updateStyle(el, data, newIndex, itemModel, layout, seriesModel, isHorizontalOrRadial, coord.type === 'polar');
  199. }).remove(function (dataIndex) {
  200. var el = oldData.getItemGraphicEl(dataIndex);
  201. if (coord.type === 'cartesian2d') {
  202. el && removeRect(dataIndex, animationModel, el);
  203. } else {
  204. el && removeSector(dataIndex, animationModel, el);
  205. }
  206. }).execute();
  207. var bgGroup = this._backgroundGroup || (this._backgroundGroup = new Group());
  208. bgGroup.removeAll();
  209. for (var i = 0; i < bgEls.length; ++i) {
  210. bgGroup.add(bgEls[i]);
  211. }
  212. group.add(bgGroup);
  213. this._backgroundEls = bgEls;
  214. this._data = data;
  215. },
  216. _renderLarge: function (seriesModel, ecModel, api) {
  217. this._clear();
  218. createLarge(seriesModel, this.group); // Use clipPath in large mode.
  219. var clipPath = seriesModel.get('clip', true) ? createClipPath(seriesModel.coordinateSystem, false, seriesModel) : null;
  220. if (clipPath) {
  221. this.group.setClipPath(clipPath);
  222. } else {
  223. this.group.removeClipPath();
  224. }
  225. },
  226. _incrementalRenderLarge: function (params, seriesModel) {
  227. this._removeBackground();
  228. createLarge(seriesModel, this.group, true);
  229. },
  230. dispose: zrUtil.noop,
  231. remove: function (ecModel) {
  232. this._clear(ecModel);
  233. },
  234. _clear: function (ecModel) {
  235. var group = this.group;
  236. var data = this._data;
  237. if (ecModel && ecModel.get('animation') && data && !this._isLargeDraw) {
  238. this._removeBackground();
  239. this._backgroundEls = [];
  240. data.eachItemGraphicEl(function (el) {
  241. if (el.type === 'sector') {
  242. removeSector(el.dataIndex, ecModel, el);
  243. } else {
  244. removeRect(el.dataIndex, ecModel, el);
  245. }
  246. });
  247. } else {
  248. group.removeAll();
  249. }
  250. this._data = null;
  251. },
  252. _removeBackground: function () {
  253. this.group.remove(this._backgroundGroup);
  254. this._backgroundGroup = null;
  255. }
  256. });
  257. var mathMax = Math.max;
  258. var mathMin = Math.min;
  259. var clip = {
  260. cartesian2d: function (coordSysBoundingRect, layout) {
  261. var signWidth = layout.width < 0 ? -1 : 1;
  262. var signHeight = layout.height < 0 ? -1 : 1; // Needs positive width and height
  263. if (signWidth < 0) {
  264. layout.x += layout.width;
  265. layout.width = -layout.width;
  266. }
  267. if (signHeight < 0) {
  268. layout.y += layout.height;
  269. layout.height = -layout.height;
  270. }
  271. var x = mathMax(layout.x, coordSysBoundingRect.x);
  272. var x2 = mathMin(layout.x + layout.width, coordSysBoundingRect.x + coordSysBoundingRect.width);
  273. var y = mathMax(layout.y, coordSysBoundingRect.y);
  274. var y2 = mathMin(layout.y + layout.height, coordSysBoundingRect.y + coordSysBoundingRect.height);
  275. layout.x = x;
  276. layout.y = y;
  277. layout.width = x2 - x;
  278. layout.height = y2 - y;
  279. var clipped = layout.width < 0 || layout.height < 0; // Reverse back
  280. if (signWidth < 0) {
  281. layout.x += layout.width;
  282. layout.width = -layout.width;
  283. }
  284. if (signHeight < 0) {
  285. layout.y += layout.height;
  286. layout.height = -layout.height;
  287. }
  288. return clipped;
  289. },
  290. polar: function (coordSysClipArea, layout) {
  291. var signR = layout.r0 <= layout.r ? 1 : -1; // Make sure r is larger than r0
  292. if (signR < 0) {
  293. var r = layout.r;
  294. layout.r = layout.r0;
  295. layout.r0 = r;
  296. }
  297. var r = mathMin(layout.r, coordSysClipArea.r);
  298. var r0 = mathMax(layout.r0, coordSysClipArea.r0);
  299. layout.r = r;
  300. layout.r0 = r0;
  301. var clipped = r - r0 < 0; // Reverse back
  302. if (signR < 0) {
  303. var r = layout.r;
  304. layout.r = layout.r0;
  305. layout.r0 = r;
  306. }
  307. return clipped;
  308. }
  309. };
  310. var elementCreator = {
  311. cartesian2d: function (dataIndex, layout, isHorizontal, animationModel, isUpdate) {
  312. var rect = new graphic.Rect({
  313. shape: zrUtil.extend({}, layout),
  314. z2: 1
  315. });
  316. rect.name = 'item'; // Animation
  317. if (animationModel) {
  318. var rectShape = rect.shape;
  319. var animateProperty = isHorizontal ? 'height' : 'width';
  320. var animateTarget = {};
  321. rectShape[animateProperty] = 0;
  322. animateTarget[animateProperty] = layout[animateProperty];
  323. graphic[isUpdate ? 'updateProps' : 'initProps'](rect, {
  324. shape: animateTarget
  325. }, animationModel, dataIndex);
  326. }
  327. return rect;
  328. },
  329. polar: function (dataIndex, layout, isRadial, animationModel, isUpdate, roundCap) {
  330. // Keep the same logic with bar in catesion: use end value to control
  331. // direction. Notice that if clockwise is true (by default), the sector
  332. // will always draw clockwisely, no matter whether endAngle is greater
  333. // or less than startAngle.
  334. var clockwise = layout.startAngle < layout.endAngle;
  335. var ShapeClass = !isRadial && roundCap ? Sausage : graphic.Sector;
  336. var sector = new ShapeClass({
  337. shape: zrUtil.defaults({
  338. clockwise: clockwise
  339. }, layout),
  340. z2: 1
  341. });
  342. sector.name = 'item'; // Animation
  343. if (animationModel) {
  344. var sectorShape = sector.shape;
  345. var animateProperty = isRadial ? 'r' : 'endAngle';
  346. var animateTarget = {};
  347. sectorShape[animateProperty] = isRadial ? 0 : layout.startAngle;
  348. animateTarget[animateProperty] = layout[animateProperty];
  349. graphic[isUpdate ? 'updateProps' : 'initProps'](sector, {
  350. shape: animateTarget
  351. }, animationModel, dataIndex);
  352. }
  353. return sector;
  354. }
  355. };
  356. function removeRect(dataIndex, animationModel, el) {
  357. // Not show text when animating
  358. el.style.text = null;
  359. graphic.updateProps(el, {
  360. shape: {
  361. width: 0
  362. }
  363. }, animationModel, dataIndex, function () {
  364. el.parent && el.parent.remove(el);
  365. });
  366. }
  367. function removeSector(dataIndex, animationModel, el) {
  368. // Not show text when animating
  369. el.style.text = null;
  370. graphic.updateProps(el, {
  371. shape: {
  372. r: el.shape.r0
  373. }
  374. }, animationModel, dataIndex, function () {
  375. el.parent && el.parent.remove(el);
  376. });
  377. }
  378. var getLayout = {
  379. // itemModel is only used to get borderWidth, which is not needed
  380. // when calculating bar background layout.
  381. cartesian2d: function (data, dataIndex, itemModel) {
  382. var layout = data.getItemLayout(dataIndex);
  383. var fixedLineWidth = itemModel ? getLineWidth(itemModel, layout) : 0; // fix layout with lineWidth
  384. var signX = layout.width > 0 ? 1 : -1;
  385. var signY = layout.height > 0 ? 1 : -1;
  386. return {
  387. x: layout.x + signX * fixedLineWidth / 2,
  388. y: layout.y + signY * fixedLineWidth / 2,
  389. width: layout.width - signX * fixedLineWidth,
  390. height: layout.height - signY * fixedLineWidth
  391. };
  392. },
  393. polar: function (data, dataIndex, itemModel) {
  394. var layout = data.getItemLayout(dataIndex);
  395. return {
  396. cx: layout.cx,
  397. cy: layout.cy,
  398. r0: layout.r0,
  399. r: layout.r,
  400. startAngle: layout.startAngle,
  401. endAngle: layout.endAngle
  402. };
  403. }
  404. };
  405. function isZeroOnPolar(layout) {
  406. return layout.startAngle != null && layout.endAngle != null && layout.startAngle === layout.endAngle;
  407. }
  408. function updateStyle(el, data, dataIndex, itemModel, layout, seriesModel, isHorizontal, isPolar) {
  409. var color = data.getItemVisual(dataIndex, 'color');
  410. var opacity = data.getItemVisual(dataIndex, 'opacity');
  411. var stroke = data.getVisual('borderColor');
  412. var itemStyleModel = itemModel.getModel('itemStyle');
  413. var hoverStyle = itemModel.getModel('emphasis.itemStyle').getBarItemStyle();
  414. if (!isPolar) {
  415. el.setShape('r', itemStyleModel.get('barBorderRadius') || 0);
  416. }
  417. el.useStyle(zrUtil.defaults({
  418. stroke: isZeroOnPolar(layout) ? 'none' : stroke,
  419. fill: isZeroOnPolar(layout) ? 'none' : color,
  420. opacity: opacity
  421. }, itemStyleModel.getBarItemStyle()));
  422. var cursorStyle = itemModel.getShallow('cursor');
  423. cursorStyle && el.attr('cursor', cursorStyle);
  424. var labelPositionOutside = isHorizontal ? layout.height > 0 ? 'bottom' : 'top' : layout.width > 0 ? 'left' : 'right';
  425. if (!isPolar) {
  426. setLabel(el.style, hoverStyle, itemModel, color, seriesModel, dataIndex, labelPositionOutside);
  427. }
  428. if (isZeroOnPolar(layout)) {
  429. hoverStyle.fill = hoverStyle.stroke = 'none';
  430. }
  431. graphic.setHoverStyle(el, hoverStyle);
  432. } // In case width or height are too small.
  433. function getLineWidth(itemModel, rawLayout) {
  434. var lineWidth = itemModel.get(BAR_BORDER_WIDTH_QUERY) || 0; // width or height may be NaN for empty data
  435. var width = isNaN(rawLayout.width) ? Number.MAX_VALUE : Math.abs(rawLayout.width);
  436. var height = isNaN(rawLayout.height) ? Number.MAX_VALUE : Math.abs(rawLayout.height);
  437. return Math.min(lineWidth, width, height);
  438. }
  439. var LargePath = Path.extend({
  440. type: 'largeBar',
  441. shape: {
  442. points: []
  443. },
  444. buildPath: function (ctx, shape) {
  445. // Drawing lines is more efficient than drawing
  446. // a whole line or drawing rects.
  447. var points = shape.points;
  448. var startPoint = this.__startPoint;
  449. var baseDimIdx = this.__baseDimIdx;
  450. for (var i = 0; i < points.length; i += 2) {
  451. startPoint[baseDimIdx] = points[i + baseDimIdx];
  452. ctx.moveTo(startPoint[0], startPoint[1]);
  453. ctx.lineTo(points[i], points[i + 1]);
  454. }
  455. }
  456. });
  457. function createLarge(seriesModel, group, incremental) {
  458. // TODO support polar
  459. var data = seriesModel.getData();
  460. var startPoint = [];
  461. var baseDimIdx = data.getLayout('valueAxisHorizontal') ? 1 : 0;
  462. startPoint[1 - baseDimIdx] = data.getLayout('valueAxisStart');
  463. var largeDataIndices = data.getLayout('largeDataIndices');
  464. var barWidth = data.getLayout('barWidth');
  465. var backgroundModel = seriesModel.getModel('backgroundStyle');
  466. var drawBackground = seriesModel.get('showBackground', true);
  467. if (drawBackground) {
  468. var points = data.getLayout('largeBackgroundPoints');
  469. var backgroundStartPoint = [];
  470. backgroundStartPoint[1 - baseDimIdx] = data.getLayout('backgroundStart');
  471. var bgEl = new LargePath({
  472. shape: {
  473. points: points
  474. },
  475. incremental: !!incremental,
  476. __startPoint: backgroundStartPoint,
  477. __baseDimIdx: baseDimIdx,
  478. __largeDataIndices: largeDataIndices,
  479. __barWidth: barWidth,
  480. silent: true,
  481. z2: 0
  482. });
  483. setLargeBackgroundStyle(bgEl, backgroundModel, data);
  484. group.add(bgEl);
  485. }
  486. var el = new LargePath({
  487. shape: {
  488. points: data.getLayout('largePoints')
  489. },
  490. incremental: !!incremental,
  491. __startPoint: startPoint,
  492. __baseDimIdx: baseDimIdx,
  493. __largeDataIndices: largeDataIndices,
  494. __barWidth: barWidth
  495. });
  496. group.add(el);
  497. setLargeStyle(el, seriesModel, data); // Enable tooltip and user mouse/touch event handlers.
  498. el.seriesIndex = seriesModel.seriesIndex;
  499. if (!seriesModel.get('silent')) {
  500. el.on('mousedown', largePathUpdateDataIndex);
  501. el.on('mousemove', largePathUpdateDataIndex);
  502. }
  503. } // Use throttle to avoid frequently traverse to find dataIndex.
  504. var largePathUpdateDataIndex = throttle(function (event) {
  505. var largePath = this;
  506. var dataIndex = largePathFindDataIndex(largePath, event.offsetX, event.offsetY);
  507. largePath.dataIndex = dataIndex >= 0 ? dataIndex : null;
  508. }, 30, false);
  509. function largePathFindDataIndex(largePath, x, y) {
  510. var baseDimIdx = largePath.__baseDimIdx;
  511. var valueDimIdx = 1 - baseDimIdx;
  512. var points = largePath.shape.points;
  513. var largeDataIndices = largePath.__largeDataIndices;
  514. var barWidthHalf = Math.abs(largePath.__barWidth / 2);
  515. var startValueVal = largePath.__startPoint[valueDimIdx];
  516. _eventPos[0] = x;
  517. _eventPos[1] = y;
  518. var pointerBaseVal = _eventPos[baseDimIdx];
  519. var pointerValueVal = _eventPos[1 - baseDimIdx];
  520. var baseLowerBound = pointerBaseVal - barWidthHalf;
  521. var baseUpperBound = pointerBaseVal + barWidthHalf;
  522. for (var i = 0, len = points.length / 2; i < len; i++) {
  523. var ii = i * 2;
  524. var barBaseVal = points[ii + baseDimIdx];
  525. var barValueVal = points[ii + valueDimIdx];
  526. if (barBaseVal >= baseLowerBound && barBaseVal <= baseUpperBound && (startValueVal <= barValueVal ? pointerValueVal >= startValueVal && pointerValueVal <= barValueVal : pointerValueVal >= barValueVal && pointerValueVal <= startValueVal)) {
  527. return largeDataIndices[i];
  528. }
  529. }
  530. return -1;
  531. }
  532. function setLargeStyle(el, seriesModel, data) {
  533. var borderColor = data.getVisual('borderColor') || data.getVisual('color');
  534. var itemStyle = seriesModel.getModel('itemStyle').getItemStyle(['color', 'borderColor']);
  535. el.useStyle(itemStyle);
  536. el.style.fill = null;
  537. el.style.stroke = borderColor;
  538. el.style.lineWidth = data.getLayout('barWidth');
  539. }
  540. function setLargeBackgroundStyle(el, backgroundModel, data) {
  541. var borderColor = backgroundModel.get('borderColor') || backgroundModel.get('color');
  542. var itemStyle = backgroundModel.getItemStyle(['color', 'borderColor']);
  543. el.useStyle(itemStyle);
  544. el.style.fill = null;
  545. el.style.stroke = borderColor;
  546. el.style.lineWidth = data.getLayout('barWidth');
  547. }
  548. function createBackgroundShape(isHorizontalOrRadial, layout, coord) {
  549. var coordLayout;
  550. var isPolar = coord.type === 'polar';
  551. if (isPolar) {
  552. coordLayout = coord.getArea();
  553. } else {
  554. coordLayout = coord.grid.getRect();
  555. }
  556. if (isPolar) {
  557. return {
  558. cx: coordLayout.cx,
  559. cy: coordLayout.cy,
  560. r0: isHorizontalOrRadial ? coordLayout.r0 : layout.r0,
  561. r: isHorizontalOrRadial ? coordLayout.r : layout.r,
  562. startAngle: isHorizontalOrRadial ? layout.startAngle : 0,
  563. endAngle: isHorizontalOrRadial ? layout.endAngle : Math.PI * 2
  564. };
  565. } else {
  566. return {
  567. x: isHorizontalOrRadial ? layout.x : coordLayout.x,
  568. y: isHorizontalOrRadial ? coordLayout.y : layout.y,
  569. width: isHorizontalOrRadial ? layout.width : coordLayout.width,
  570. height: isHorizontalOrRadial ? coordLayout.height : layout.height
  571. };
  572. }
  573. }
  574. function createBackgroundEl(coord, isHorizontalOrRadial, layout) {
  575. var ElementClz = coord.type === 'polar' ? graphic.Sector : graphic.Rect;
  576. return new ElementClz({
  577. shape: createBackgroundShape(isHorizontalOrRadial, layout, coord),
  578. silent: true,
  579. z2: 0
  580. });
  581. }
  582. module.exports = _default;