IndicatorRequired.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /**
  2. *
  3. * (c) 2010-2021 Daniel Studencki
  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 U from '../Core/Utilities.js';
  12. var error = U.error;
  13. /* eslint-disable no-invalid-this, valid-jsdoc */
  14. var requiredIndicatorMixin = {
  15. /**
  16. * Check whether given indicator is loaded, else throw error.
  17. * @private
  18. * @param {Highcharts.Indicator} indicator
  19. * Indicator constructor function.
  20. * @param {string} requiredIndicator
  21. * Required indicator type.
  22. * @param {string} type
  23. * Type of indicator where function was called (parent).
  24. * @param {Highcharts.IndicatorCallbackFunction} callback
  25. * Callback which is triggered if the given indicator is loaded.
  26. * Takes indicator as an argument.
  27. * @param {string} errMessage
  28. * Error message that will be logged in console.
  29. * @return {boolean}
  30. * Returns false when there is no required indicator loaded.
  31. */
  32. isParentLoaded: function (indicator, requiredIndicator, type, callback, errMessage) {
  33. if (indicator) {
  34. return callback ? callback(indicator) : true;
  35. }
  36. error(errMessage || this.generateMessage(type, requiredIndicator));
  37. return false;
  38. },
  39. /**
  40. * @private
  41. * @param {string} indicatorType
  42. * Indicator type
  43. * @param {string} required
  44. * Required indicator
  45. * @return {string}
  46. * Error message
  47. */
  48. generateMessage: function (indicatorType, required) {
  49. return 'Error: "' + indicatorType +
  50. '" indicator type requires "' + required +
  51. '" indicator loaded before. Please read docs: ' +
  52. 'https://api.highcharts.com/highstock/plotOptions.' +
  53. indicatorType;
  54. }
  55. };
  56. export default requiredIndicatorMixin;