LegendSymbol.js 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /* *
  2. *
  3. * (c) 2010-2020 Torstein Honsi
  4. *
  5. * License: www.highcharts.com/license
  6. *
  7. * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
  8. *
  9. * */
  10. import H from '../Core/Globals.js';
  11. import U from '../Core/Utilities.js';
  12. var merge = U.merge, pick = U.pick;
  13. /* eslint-disable valid-jsdoc */
  14. /**
  15. * Legend symbol mixin.
  16. *
  17. * @private
  18. * @mixin Highcharts.LegendSymbolMixin
  19. */
  20. var LegendSymbolMixin = H.LegendSymbolMixin = {
  21. /**
  22. * Get the series' symbol in the legend
  23. *
  24. * @private
  25. * @function Highcharts.LegendSymbolMixin.drawRectangle
  26. *
  27. * @param {Highcharts.Legend} legend
  28. * The legend object
  29. *
  30. * @param {Highcharts.Point|Highcharts.Series} item
  31. * The series (this) or point
  32. */
  33. drawRectangle: function (legend, item) {
  34. var options = legend.options, symbolHeight = legend.symbolHeight, square = options.squareSymbol, symbolWidth = square ? symbolHeight : legend.symbolWidth;
  35. item.legendSymbol = this.chart.renderer.rect(square ? (legend.symbolWidth - symbolHeight) / 2 : 0, legend.baseline - symbolHeight + 1, // #3988
  36. symbolWidth, symbolHeight, pick(legend.options.symbolRadius, symbolHeight / 2))
  37. .addClass('highcharts-point')
  38. .attr({
  39. zIndex: 3
  40. }).add(item.legendGroup);
  41. },
  42. /**
  43. * Get the series' symbol in the legend. This method should be overridable
  44. * to create custom symbols through
  45. * Highcharts.seriesTypes[type].prototype.drawLegendSymbols.
  46. *
  47. * @private
  48. * @function Highcharts.LegendSymbolMixin.drawLineMarker
  49. *
  50. * @param {Highcharts.Legend} legend
  51. * The legend object.
  52. */
  53. drawLineMarker: function (legend) {
  54. var options = this.options, markerOptions = options.marker, radius, legendSymbol, symbolWidth = legend.symbolWidth, symbolHeight = legend.symbolHeight, generalRadius = symbolHeight / 2, renderer = this.chart.renderer, legendItemGroup = this.legendGroup, verticalCenter = legend.baseline -
  55. Math.round(legend.fontMetrics.b * 0.3), attr = {};
  56. // Draw the line
  57. if (!this.chart.styledMode) {
  58. attr = {
  59. 'stroke-width': options.lineWidth || 0
  60. };
  61. if (options.dashStyle) {
  62. attr.dashstyle = options.dashStyle;
  63. }
  64. }
  65. this.legendLine = renderer
  66. .path([
  67. ['M', 0, verticalCenter],
  68. ['L', symbolWidth, verticalCenter]
  69. ])
  70. .addClass('highcharts-graph')
  71. .attr(attr)
  72. .add(legendItemGroup);
  73. // Draw the marker
  74. if (markerOptions && markerOptions.enabled !== false && symbolWidth) {
  75. // Do not allow the marker to be larger than the symbolHeight
  76. radius = Math.min(pick(markerOptions.radius, generalRadius), generalRadius);
  77. // Restrict symbol markers size
  78. if (this.symbol.indexOf('url') === 0) {
  79. markerOptions = merge(markerOptions, {
  80. width: symbolHeight,
  81. height: symbolHeight
  82. });
  83. radius = 0;
  84. }
  85. this.legendSymbol = legendSymbol = renderer.symbol(this.symbol, (symbolWidth / 2) - radius, verticalCenter - radius, 2 * radius, 2 * radius, markerOptions)
  86. .addClass('highcharts-point')
  87. .add(legendItemGroup);
  88. legendSymbol.isMarker = true;
  89. }
  90. }
  91. };
  92. export default LegendSymbolMixin;