Polyline.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. var graphic = require("../../util/graphic");
  2. var zrUtil = require("zrender/lib/core/util");
  3. /**
  4. * @module echarts/chart/helper/Line
  5. */
  6. /**
  7. * @constructor
  8. * @extends {module:zrender/graphic/Group}
  9. * @alias {module:echarts/chart/helper/Polyline}
  10. */
  11. function Polyline(lineData, idx, seriesScope) {
  12. graphic.Group.call(this);
  13. this._createPolyline(lineData, idx, seriesScope);
  14. }
  15. var polylineProto = Polyline.prototype;
  16. polylineProto._createPolyline = function (lineData, idx, seriesScope) {
  17. // var seriesModel = lineData.hostModel;
  18. var points = lineData.getItemLayout(idx);
  19. var line = new graphic.Polyline({
  20. shape: {
  21. points: points
  22. }
  23. });
  24. this.add(line);
  25. this._updateCommonStl(lineData, idx, seriesScope);
  26. };
  27. polylineProto.updateData = function (lineData, idx, seriesScope) {
  28. var seriesModel = lineData.hostModel;
  29. var line = this.childAt(0);
  30. var target = {
  31. shape: {
  32. points: lineData.getItemLayout(idx)
  33. }
  34. };
  35. graphic.updateProps(line, target, seriesModel, idx);
  36. this._updateCommonStl(lineData, idx, seriesScope);
  37. };
  38. polylineProto._updateCommonStl = function (lineData, idx, seriesScope) {
  39. var line = this.childAt(0);
  40. var itemModel = lineData.getItemModel(idx);
  41. var visualColor = lineData.getItemVisual(idx, 'color');
  42. var lineStyle = seriesScope && seriesScope.lineStyle;
  43. var hoverLineStyle = seriesScope && seriesScope.hoverLineStyle;
  44. if (!seriesScope || lineData.hasItemOption) {
  45. lineStyle = itemModel.getModel('lineStyle.normal').getLineStyle();
  46. hoverLineStyle = itemModel.getModel('lineStyle.emphasis').getLineStyle();
  47. }
  48. line.useStyle(zrUtil.defaults({
  49. strokeNoScale: true,
  50. fill: 'none',
  51. stroke: visualColor
  52. }, lineStyle));
  53. line.hoverStyle = hoverLineStyle;
  54. graphic.setHoverStyle(this);
  55. };
  56. polylineProto.updateLayout = function (lineData, idx) {
  57. var polyline = this.childAt(0);
  58. polyline.setShape('points', lineData.getItemLayout(idx));
  59. };
  60. zrUtil.inherits(Polyline, graphic.Group);
  61. var _default = Polyline;
  62. module.exports = _default;