LegendSymbol.js 3.5 KB

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