indicator-required.js 1.9 KB

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