KPIDOMProvider.js 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. 'use strict';
  2. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  3. /*
  4. * Licensed Materials - Property of IBM
  5. * IBM Business Analytics (C) Copyright IBM Corp. 2020
  6. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  7. */
  8. /**
  9. * @class KPIDOMProvider
  10. * @hideconstructor
  11. * @classdesc Implements DOMProviderAPI
  12. */
  13. define(['jquery', './api/DOMProviderAPI', '../../../../lib/@waca/dashboard-common/dist/core/APIFactory'], function ($, DomProviderAPI, APIFactory) {
  14. var KPIDOMProvider = function () {
  15. function KPIDOMProvider(options) {
  16. _classCallCheck(this, KPIDOMProvider);
  17. this._domNode = options.features.ContentViewDOM.getNode();
  18. this.liveWidgetDOM = options.features.LiveWidgetDOM;
  19. this.visualization = options.features.Visualization;
  20. var type = this.visualization.getType();
  21. if (type === 'KPI') {
  22. this.liveWidgetDOM.registerProvider(this.getAPI());
  23. }
  24. }
  25. KPIDOMProvider.prototype.getAPI = function getAPI() {
  26. if (!this._api) {
  27. this._api = APIFactory.createAPI(this, [DomProviderAPI]);
  28. }
  29. return this._api;
  30. };
  31. /**
  32. * @implements DomProviderAPI.getUIJSON
  33. */
  34. KPIDOMProvider.prototype.getUIJSON = function getUIJSON() {
  35. return {
  36. base: this._retrieve('base'),
  37. target: this._retrieve('target'),
  38. time: this._retrieveTime()
  39. };
  40. };
  41. KPIDOMProvider.prototype._retrieveTime = function _retrieveTime() {
  42. var $timeChart = $(this._domNode).find('div.dataview.kpi-widget > div.kpi-widget-content > div.kpi-widget-sparkline.widget svg.Rave2LineRenderer g.element-shape > path.line');
  43. if ($timeChart.length > 0) {
  44. return {
  45. color: $timeChart.css('stroke')
  46. };
  47. }
  48. };
  49. KPIDOMProvider.prototype._retrieve = function _retrieve(slot) {
  50. var selectorRoot = 'div.dataview > div.kpi-widget-content > div.kpi-widget-value.kpi-widget-' + slot + '-value.labeled-value > div.labeled-value';
  51. var $label = $(this._domNode).find(selectorRoot + '-label > span');
  52. if ($label.length > 0) {
  53. var $value = $(this._domNode).find(selectorRoot + '-value > span');
  54. var $shape = $(this._domNode).find(selectorRoot + '-value > svg > use');
  55. return {
  56. label: {
  57. text: $label.text(),
  58. color: $label.css('color')
  59. },
  60. value: {
  61. text: $value.text(),
  62. color: $value.css('color'),
  63. shape: $shape.attr('xlink:href')
  64. }
  65. };
  66. }
  67. };
  68. return KPIDOMProvider;
  69. }();
  70. return KPIDOMProvider;
  71. });
  72. //# sourceMappingURL=KPIDOMProvider.js.map