Polyline.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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 graphic = require("../../util/graphic");
  20. var zrUtil = require("zrender/lib/core/util");
  21. /*
  22. * Licensed to the Apache Software Foundation (ASF) under one
  23. * or more contributor license agreements. See the NOTICE file
  24. * distributed with this work for additional information
  25. * regarding copyright ownership. The ASF licenses this file
  26. * to you under the Apache License, Version 2.0 (the
  27. * "License"); you may not use this file except in compliance
  28. * with the License. You may obtain a copy of the License at
  29. *
  30. * http://www.apache.org/licenses/LICENSE-2.0
  31. *
  32. * Unless required by applicable law or agreed to in writing,
  33. * software distributed under the License is distributed on an
  34. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  35. * KIND, either express or implied. See the License for the
  36. * specific language governing permissions and limitations
  37. * under the License.
  38. */
  39. /**
  40. * @module echarts/chart/helper/Line
  41. */
  42. /**
  43. * @constructor
  44. * @extends {module:zrender/graphic/Group}
  45. * @alias {module:echarts/chart/helper/Polyline}
  46. */
  47. function Polyline(lineData, idx, seriesScope) {
  48. graphic.Group.call(this);
  49. this._createPolyline(lineData, idx, seriesScope);
  50. }
  51. var polylineProto = Polyline.prototype;
  52. polylineProto._createPolyline = function (lineData, idx, seriesScope) {
  53. // var seriesModel = lineData.hostModel;
  54. var points = lineData.getItemLayout(idx);
  55. var line = new graphic.Polyline({
  56. shape: {
  57. points: points
  58. }
  59. });
  60. this.add(line);
  61. this._updateCommonStl(lineData, idx, seriesScope);
  62. };
  63. polylineProto.updateData = function (lineData, idx, seriesScope) {
  64. var seriesModel = lineData.hostModel;
  65. var line = this.childAt(0);
  66. var target = {
  67. shape: {
  68. points: lineData.getItemLayout(idx)
  69. }
  70. };
  71. graphic.updateProps(line, target, seriesModel, idx);
  72. this._updateCommonStl(lineData, idx, seriesScope);
  73. };
  74. polylineProto._updateCommonStl = function (lineData, idx, seriesScope) {
  75. var line = this.childAt(0);
  76. var itemModel = lineData.getItemModel(idx);
  77. var visualColor = lineData.getItemVisual(idx, 'color');
  78. var lineStyle = seriesScope && seriesScope.lineStyle;
  79. var hoverLineStyle = seriesScope && seriesScope.hoverLineStyle;
  80. if (!seriesScope || lineData.hasItemOption) {
  81. lineStyle = itemModel.getModel('lineStyle').getLineStyle();
  82. hoverLineStyle = itemModel.getModel('emphasis.lineStyle').getLineStyle();
  83. }
  84. line.useStyle(zrUtil.defaults({
  85. strokeNoScale: true,
  86. fill: 'none',
  87. stroke: visualColor
  88. }, lineStyle));
  89. line.hoverStyle = hoverLineStyle;
  90. graphic.setHoverStyle(this);
  91. };
  92. polylineProto.updateLayout = function (lineData, idx) {
  93. var polyline = this.childAt(0);
  94. polyline.setShape('points', lineData.getItemLayout(idx));
  95. };
  96. zrUtil.inherits(Polyline, graphic.Group);
  97. var _default = Polyline;
  98. module.exports = _default;