BarView.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665
  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. data.diff(oldData).add(function (dataIndex) {
  125. var itemModel = data.getItemModel(dataIndex);
  126. var layout = getLayout[coord.type](data, dataIndex, itemModel);
  127. if (drawBackground) {
  128. var bgLayout = getLayout[coord.type](data, dataIndex);
  129. var bgEl = createBackgroundEl(coord, isHorizontalOrRadial, bgLayout);
  130. bgEl.useStyle(backgroundModel.getBarItemStyle()); // Only cartesian2d support borderRadius.
  131. if (coord.type === 'cartesian2d') {
  132. bgEl.setShape('r', barBorderRadius);
  133. }
  134. bgEls[dataIndex] = bgEl;
  135. } // If dataZoom in filteMode: 'empty', the baseValue can be set as NaN in "axisProxy".
  136. if (!data.hasValue(dataIndex)) {
  137. return;
  138. }
  139. if (needsClip) {
  140. // Clip will modify the layout params.
  141. // And return a boolean to determine if the shape are fully clipped.
  142. var isClipped = clip[coord.type](coordSysClipArea, layout);
  143. if (isClipped) {
  144. group.remove(el);
  145. return;
  146. }
  147. }
  148. var el = elementCreator[coord.type](dataIndex, layout, isHorizontalOrRadial, animationModel, false, roundCap);
  149. data.setItemGraphicEl(dataIndex, el);
  150. group.add(el);
  151. updateStyle(el, data, dataIndex, itemModel, layout, seriesModel, isHorizontalOrRadial, coord.type === 'polar');
  152. }).update(function (newIndex, oldIndex) {
  153. var itemModel = data.getItemModel(newIndex);
  154. var layout = getLayout[coord.type](data, newIndex, itemModel);
  155. if (drawBackground) {
  156. var bgEl = oldBgEls[oldIndex];
  157. bgEl.useStyle(backgroundModel.getBarItemStyle()); // Only cartesian2d support borderRadius.
  158. if (coord.type === 'cartesian2d') {
  159. bgEl.setShape('r', barBorderRadius);
  160. }
  161. bgEls[newIndex] = bgEl;
  162. var bgLayout = getLayout[coord.type](data, newIndex);
  163. var shape = createBackgroundShape(isHorizontalOrRadial, bgLayout, coord);
  164. graphic.updateProps(bgEl, {
  165. shape: shape
  166. }, animationModel, newIndex);
  167. }
  168. var el = oldData.getItemGraphicEl(oldIndex);
  169. if (!data.hasValue(newIndex)) {
  170. group.remove(el);
  171. return;
  172. }
  173. if (needsClip) {
  174. var isClipped = clip[coord.type](coordSysClipArea, layout);
  175. if (isClipped) {
  176. group.remove(el);
  177. return;
  178. }
  179. }
  180. if (el) {
  181. graphic.updateProps(el, {
  182. shape: layout
  183. }, animationModel, newIndex);
  184. } else {
  185. el = elementCreator[coord.type](newIndex, layout, isHorizontalOrRadial, animationModel, true, roundCap);
  186. }
  187. data.setItemGraphicEl(newIndex, el); // Add back
  188. group.add(el);
  189. updateStyle(el, data, newIndex, itemModel, layout, seriesModel, isHorizontalOrRadial, coord.type === 'polar');
  190. }).remove(function (dataIndex) {
  191. var el = oldData.getItemGraphicEl(dataIndex);
  192. if (coord.type === 'cartesian2d') {
  193. el && removeRect(dataIndex, animationModel, el);
  194. } else {
  195. el && removeSector(dataIndex, animationModel, el);
  196. }
  197. }).execute();
  198. var bgGroup = this._backgroundGroup || (this._backgroundGroup = new Group());
  199. bgGroup.removeAll();
  200. for (var i = 0; i < bgEls.length; ++i) {
  201. bgGroup.add(bgEls[i]);
  202. }
  203. group.add(bgGroup);
  204. this._backgroundEls = bgEls;
  205. this._data = data;
  206. },
  207. _renderLarge: function (seriesModel, ecModel, api) {
  208. this._clear();
  209. createLarge(seriesModel, this.group); // Use clipPath in large mode.
  210. var clipPath = seriesModel.get('clip', true) ? createClipPath(seriesModel.coordinateSystem, false, seriesModel) : null;
  211. if (clipPath) {
  212. this.group.setClipPath(clipPath);
  213. } else {
  214. this.group.removeClipPath();
  215. }
  216. },
  217. _incrementalRenderLarge: function (params, seriesModel) {
  218. this._removeBackground();
  219. createLarge(seriesModel, this.group, true);
  220. },
  221. dispose: zrUtil.noop,
  222. remove: function (ecModel) {
  223. this._clear(ecModel);
  224. },
  225. _clear: function (ecModel) {
  226. var group = this.group;
  227. var data = this._data;
  228. if (ecModel && ecModel.get('animation') && data && !this._isLargeDraw) {
  229. this._removeBackground();
  230. this._backgroundEls = [];
  231. data.eachItemGraphicEl(function (el) {
  232. if (el.type === 'sector') {
  233. removeSector(el.dataIndex, ecModel, el);
  234. } else {
  235. removeRect(el.dataIndex, ecModel, el);
  236. }
  237. });
  238. } else {
  239. group.removeAll();
  240. }
  241. this._data = null;
  242. },
  243. _removeBackground: function () {
  244. this.group.remove(this._backgroundGroup);
  245. this._backgroundGroup = null;
  246. }
  247. });
  248. var mathMax = Math.max;
  249. var mathMin = Math.min;
  250. var clip = {
  251. cartesian2d: function (coordSysBoundingRect, layout) {
  252. var signWidth = layout.width < 0 ? -1 : 1;
  253. var signHeight = layout.height < 0 ? -1 : 1; // Needs positive width and height
  254. if (signWidth < 0) {
  255. layout.x += layout.width;
  256. layout.width = -layout.width;
  257. }
  258. if (signHeight < 0) {
  259. layout.y += layout.height;
  260. layout.height = -layout.height;
  261. }
  262. var x = mathMax(layout.x, coordSysBoundingRect.x);
  263. var x2 = mathMin(layout.x + layout.width, coordSysBoundingRect.x + coordSysBoundingRect.width);
  264. var y = mathMax(layout.y, coordSysBoundingRect.y);
  265. var y2 = mathMin(layout.y + layout.height, coordSysBoundingRect.y + coordSysBoundingRect.height);
  266. layout.x = x;
  267. layout.y = y;
  268. layout.width = x2 - x;
  269. layout.height = y2 - y;
  270. var clipped = layout.width < 0 || layout.height < 0; // Reverse back
  271. if (signWidth < 0) {
  272. layout.x += layout.width;
  273. layout.width = -layout.width;
  274. }
  275. if (signHeight < 0) {
  276. layout.y += layout.height;
  277. layout.height = -layout.height;
  278. }
  279. return clipped;
  280. },
  281. polar: function (coordSysClipArea) {
  282. return false;
  283. }
  284. };
  285. var elementCreator = {
  286. cartesian2d: function (dataIndex, layout, isHorizontal, animationModel, isUpdate) {
  287. var rect = new graphic.Rect({
  288. shape: zrUtil.extend({}, layout),
  289. z2: 1
  290. });
  291. rect.name = 'item'; // Animation
  292. if (animationModel) {
  293. var rectShape = rect.shape;
  294. var animateProperty = isHorizontal ? 'height' : 'width';
  295. var animateTarget = {};
  296. rectShape[animateProperty] = 0;
  297. animateTarget[animateProperty] = layout[animateProperty];
  298. graphic[isUpdate ? 'updateProps' : 'initProps'](rect, {
  299. shape: animateTarget
  300. }, animationModel, dataIndex);
  301. }
  302. return rect;
  303. },
  304. polar: function (dataIndex, layout, isRadial, animationModel, isUpdate, roundCap) {
  305. // Keep the same logic with bar in catesion: use end value to control
  306. // direction. Notice that if clockwise is true (by default), the sector
  307. // will always draw clockwisely, no matter whether endAngle is greater
  308. // or less than startAngle.
  309. var clockwise = layout.startAngle < layout.endAngle;
  310. var ShapeClass = !isRadial && roundCap ? Sausage : graphic.Sector;
  311. var sector = new ShapeClass({
  312. shape: zrUtil.defaults({
  313. clockwise: clockwise
  314. }, layout),
  315. z2: 1
  316. });
  317. sector.name = 'item'; // Animation
  318. if (animationModel) {
  319. var sectorShape = sector.shape;
  320. var animateProperty = isRadial ? 'r' : 'endAngle';
  321. var animateTarget = {};
  322. sectorShape[animateProperty] = isRadial ? 0 : layout.startAngle;
  323. animateTarget[animateProperty] = layout[animateProperty];
  324. graphic[isUpdate ? 'updateProps' : 'initProps'](sector, {
  325. shape: animateTarget
  326. }, animationModel, dataIndex);
  327. }
  328. return sector;
  329. }
  330. };
  331. function removeRect(dataIndex, animationModel, el) {
  332. // Not show text when animating
  333. el.style.text = null;
  334. graphic.updateProps(el, {
  335. shape: {
  336. width: 0
  337. }
  338. }, animationModel, dataIndex, function () {
  339. el.parent && el.parent.remove(el);
  340. });
  341. }
  342. function removeSector(dataIndex, animationModel, el) {
  343. // Not show text when animating
  344. el.style.text = null;
  345. graphic.updateProps(el, {
  346. shape: {
  347. r: el.shape.r0
  348. }
  349. }, animationModel, dataIndex, function () {
  350. el.parent && el.parent.remove(el);
  351. });
  352. }
  353. var getLayout = {
  354. // itemModel is only used to get borderWidth, which is not needed
  355. // when calculating bar background layout.
  356. cartesian2d: function (data, dataIndex, itemModel) {
  357. var layout = data.getItemLayout(dataIndex);
  358. var fixedLineWidth = itemModel ? getLineWidth(itemModel, layout) : 0; // fix layout with lineWidth
  359. var signX = layout.width > 0 ? 1 : -1;
  360. var signY = layout.height > 0 ? 1 : -1;
  361. return {
  362. x: layout.x + signX * fixedLineWidth / 2,
  363. y: layout.y + signY * fixedLineWidth / 2,
  364. width: layout.width - signX * fixedLineWidth,
  365. height: layout.height - signY * fixedLineWidth
  366. };
  367. },
  368. polar: function (data, dataIndex, itemModel) {
  369. var layout = data.getItemLayout(dataIndex);
  370. return {
  371. cx: layout.cx,
  372. cy: layout.cy,
  373. r0: layout.r0,
  374. r: layout.r,
  375. startAngle: layout.startAngle,
  376. endAngle: layout.endAngle
  377. };
  378. }
  379. };
  380. function isZeroOnPolar(layout) {
  381. return layout.startAngle != null && layout.endAngle != null && layout.startAngle === layout.endAngle;
  382. }
  383. function updateStyle(el, data, dataIndex, itemModel, layout, seriesModel, isHorizontal, isPolar) {
  384. var color = data.getItemVisual(dataIndex, 'color');
  385. var opacity = data.getItemVisual(dataIndex, 'opacity');
  386. var stroke = data.getVisual('borderColor');
  387. var itemStyleModel = itemModel.getModel('itemStyle');
  388. var hoverStyle = itemModel.getModel('emphasis.itemStyle').getBarItemStyle();
  389. if (!isPolar) {
  390. el.setShape('r', itemStyleModel.get('barBorderRadius') || 0);
  391. }
  392. el.useStyle(zrUtil.defaults({
  393. stroke: isZeroOnPolar(layout) ? 'none' : stroke,
  394. fill: isZeroOnPolar(layout) ? 'none' : color,
  395. opacity: opacity
  396. }, itemStyleModel.getBarItemStyle()));
  397. var cursorStyle = itemModel.getShallow('cursor');
  398. cursorStyle && el.attr('cursor', cursorStyle);
  399. var labelPositionOutside = isHorizontal ? layout.height > 0 ? 'bottom' : 'top' : layout.width > 0 ? 'left' : 'right';
  400. if (!isPolar) {
  401. setLabel(el.style, hoverStyle, itemModel, color, seriesModel, dataIndex, labelPositionOutside);
  402. }
  403. if (isZeroOnPolar(layout)) {
  404. hoverStyle.fill = hoverStyle.stroke = 'none';
  405. }
  406. graphic.setHoverStyle(el, hoverStyle);
  407. } // In case width or height are too small.
  408. function getLineWidth(itemModel, rawLayout) {
  409. var lineWidth = itemModel.get(BAR_BORDER_WIDTH_QUERY) || 0; // width or height may be NaN for empty data
  410. var width = isNaN(rawLayout.width) ? Number.MAX_VALUE : Math.abs(rawLayout.width);
  411. var height = isNaN(rawLayout.height) ? Number.MAX_VALUE : Math.abs(rawLayout.height);
  412. return Math.min(lineWidth, width, height);
  413. }
  414. var LargePath = Path.extend({
  415. type: 'largeBar',
  416. shape: {
  417. points: []
  418. },
  419. buildPath: function (ctx, shape) {
  420. // Drawing lines is more efficient than drawing
  421. // a whole line or drawing rects.
  422. var points = shape.points;
  423. var startPoint = this.__startPoint;
  424. var baseDimIdx = this.__baseDimIdx;
  425. for (var i = 0; i < points.length; i += 2) {
  426. startPoint[baseDimIdx] = points[i + baseDimIdx];
  427. ctx.moveTo(startPoint[0], startPoint[1]);
  428. ctx.lineTo(points[i], points[i + 1]);
  429. }
  430. }
  431. });
  432. function createLarge(seriesModel, group, incremental) {
  433. // TODO support polar
  434. var data = seriesModel.getData();
  435. var startPoint = [];
  436. var baseDimIdx = data.getLayout('valueAxisHorizontal') ? 1 : 0;
  437. startPoint[1 - baseDimIdx] = data.getLayout('valueAxisStart');
  438. var largeDataIndices = data.getLayout('largeDataIndices');
  439. var barWidth = data.getLayout('barWidth');
  440. var backgroundModel = seriesModel.getModel('backgroundStyle');
  441. var drawBackground = seriesModel.get('showBackground', true);
  442. if (drawBackground) {
  443. var points = data.getLayout('largeBackgroundPoints');
  444. var backgroundStartPoint = [];
  445. backgroundStartPoint[1 - baseDimIdx] = data.getLayout('backgroundStart');
  446. var bgEl = new LargePath({
  447. shape: {
  448. points: points
  449. },
  450. incremental: !!incremental,
  451. __startPoint: backgroundStartPoint,
  452. __baseDimIdx: baseDimIdx,
  453. __largeDataIndices: largeDataIndices,
  454. __barWidth: barWidth,
  455. silent: true,
  456. z2: 0
  457. });
  458. setLargeBackgroundStyle(bgEl, backgroundModel, data);
  459. group.add(bgEl);
  460. }
  461. var el = new LargePath({
  462. shape: {
  463. points: data.getLayout('largePoints')
  464. },
  465. incremental: !!incremental,
  466. __startPoint: startPoint,
  467. __baseDimIdx: baseDimIdx,
  468. __largeDataIndices: largeDataIndices,
  469. __barWidth: barWidth
  470. });
  471. group.add(el);
  472. setLargeStyle(el, seriesModel, data); // Enable tooltip and user mouse/touch event handlers.
  473. el.seriesIndex = seriesModel.seriesIndex;
  474. if (!seriesModel.get('silent')) {
  475. el.on('mousedown', largePathUpdateDataIndex);
  476. el.on('mousemove', largePathUpdateDataIndex);
  477. }
  478. } // Use throttle to avoid frequently traverse to find dataIndex.
  479. var largePathUpdateDataIndex = throttle(function (event) {
  480. var largePath = this;
  481. var dataIndex = largePathFindDataIndex(largePath, event.offsetX, event.offsetY);
  482. largePath.dataIndex = dataIndex >= 0 ? dataIndex : null;
  483. }, 30, false);
  484. function largePathFindDataIndex(largePath, x, y) {
  485. var baseDimIdx = largePath.__baseDimIdx;
  486. var valueDimIdx = 1 - baseDimIdx;
  487. var points = largePath.shape.points;
  488. var largeDataIndices = largePath.__largeDataIndices;
  489. var barWidthHalf = Math.abs(largePath.__barWidth / 2);
  490. var startValueVal = largePath.__startPoint[valueDimIdx];
  491. _eventPos[0] = x;
  492. _eventPos[1] = y;
  493. var pointerBaseVal = _eventPos[baseDimIdx];
  494. var pointerValueVal = _eventPos[1 - baseDimIdx];
  495. var baseLowerBound = pointerBaseVal - barWidthHalf;
  496. var baseUpperBound = pointerBaseVal + barWidthHalf;
  497. for (var i = 0, len = points.length / 2; i < len; i++) {
  498. var ii = i * 2;
  499. var barBaseVal = points[ii + baseDimIdx];
  500. var barValueVal = points[ii + valueDimIdx];
  501. if (barBaseVal >= baseLowerBound && barBaseVal <= baseUpperBound && (startValueVal <= barValueVal ? pointerValueVal >= startValueVal && pointerValueVal <= barValueVal : pointerValueVal >= barValueVal && pointerValueVal <= startValueVal)) {
  502. return largeDataIndices[i];
  503. }
  504. }
  505. return -1;
  506. }
  507. function setLargeStyle(el, seriesModel, data) {
  508. var borderColor = data.getVisual('borderColor') || data.getVisual('color');
  509. var itemStyle = seriesModel.getModel('itemStyle').getItemStyle(['color', 'borderColor']);
  510. el.useStyle(itemStyle);
  511. el.style.fill = null;
  512. el.style.stroke = borderColor;
  513. el.style.lineWidth = data.getLayout('barWidth');
  514. }
  515. function setLargeBackgroundStyle(el, backgroundModel, data) {
  516. var borderColor = backgroundModel.get('borderColor') || backgroundModel.get('color');
  517. var itemStyle = backgroundModel.getItemStyle(['color', 'borderColor']);
  518. el.useStyle(itemStyle);
  519. el.style.fill = null;
  520. el.style.stroke = borderColor;
  521. el.style.lineWidth = data.getLayout('barWidth');
  522. }
  523. function createBackgroundShape(isHorizontalOrRadial, layout, coord) {
  524. var coordLayout;
  525. var isPolar = coord.type === 'polar';
  526. if (isPolar) {
  527. coordLayout = coord.getArea();
  528. } else {
  529. coordLayout = coord.grid.getRect();
  530. }
  531. if (isPolar) {
  532. return {
  533. cx: coordLayout.cx,
  534. cy: coordLayout.cy,
  535. r0: isHorizontalOrRadial ? coordLayout.r0 : layout.r0,
  536. r: isHorizontalOrRadial ? coordLayout.r : layout.r,
  537. startAngle: isHorizontalOrRadial ? layout.startAngle : 0,
  538. endAngle: isHorizontalOrRadial ? layout.endAngle : Math.PI * 2
  539. };
  540. } else {
  541. return {
  542. x: isHorizontalOrRadial ? layout.x : coordLayout.x,
  543. y: isHorizontalOrRadial ? coordLayout.y : layout.y,
  544. width: isHorizontalOrRadial ? layout.width : coordLayout.width,
  545. height: isHorizontalOrRadial ? coordLayout.height : layout.height
  546. };
  547. }
  548. }
  549. function createBackgroundEl(coord, isHorizontalOrRadial, layout) {
  550. var ElementClz = coord.type === 'polar' ? graphic.Sector : graphic.Rect;
  551. return new ElementClz({
  552. shape: createBackgroundShape(isHorizontalOrRadial, layout, coord),
  553. silent: true,
  554. z2: 0
  555. });
  556. }
  557. module.exports = _default;