visadapter.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855
  1. /*
  2. IBM Confidential
  3. OCO Source Materials
  4. IBM Cognos Products: irot
  5. (C) Copyright IBM Corp. 2003, 2016
  6. The source code for this program is not published or otherwise divested of its trade secrets, irrespective of what has been deposited with the U.S. Copyright Office.
  7. */
  8. define([], function() {
  9. var G_Rave1Adapter = {};
  10. /*
  11. * Custom adapter settings
  12. * checkSupportedConfig
  13. *
  14. *
  15. * Init status codes
  16. * checkSupportedConfigErrorCode
  17. *
  18. */
  19. G_Rave1Adapter.Initialize = function(v_sAdapterId, v_sAdapterLocationFull, v_oAdapterSettings)
  20. {
  21. if (!this.m_oDeferredInitialize)
  22. {
  23. this.m_oDeferredInitialize = Q.defer();
  24. this.m_oBundleLibrary = {};
  25. this.m_oVisDataDefinition = {};
  26. var v_sAdapterLocation = v_sAdapterLocationFull.substr(0, v_sAdapterLocationFull.lastIndexOf("/"));
  27. // Included for the RAVE charting engine. If a RAVE chart is not used, the server will put empty files in the MHT
  28. // dojo is included first so that we can overwrite their definitions and not them overwriting ours
  29. // Need to define the configuration as a module
  30. define("dojo/_base/config", {
  31. async : true,
  32. afterOnLoad: true,
  33. locale : 'en-us',
  34. gfxRenderer : 'canvas,silverlight',
  35. blankGif : 'hal/imagesirot/blank.gif'
  36. });
  37. var v_oConfig =
  38. {
  39. waitSeconds : 60,
  40. paths :
  41. {
  42. "dojo" : v_sAdapterLocation + "/rave/dojo",
  43. "dojox" : v_sAdapterLocation + "/rave/dojox",
  44. "com" : v_sAdapterLocation + "/rave/com"
  45. }
  46. };
  47. this.M_bIsIE = ( ( ( navigator.userAgent.toLowerCase().search(/trident\/([0-9]+\.[0-9]+)/) != -1 ) ? parseFloat( RegExp.$1 ) : 0 ) >= 7.0 );
  48. var v_fnOnDojoLoaded = ( this.M_bIsIE ? this.f_onDojoLoadedIE : this.f_onDojoLoaded ).bind( this, v_sAdapterId, v_sAdapterLocation, v_oAdapterSettings );
  49. require( v_oConfig, ["dojo/dojo"], v_fnOnDojoLoaded );
  50. }
  51. return this.m_oDeferredInitialize.promise;
  52. };
  53. G_Rave1Adapter.f_onDojoLoadedIE = function(v_sAdapterId, v_sAdapterLocation, v_oAdapterSettings)
  54. {
  55. var fn = this.f_onDojoLoaded.bind( this, v_sAdapterId, v_sAdapterLocation, v_oAdapterSettings );
  56. // This block is required in IE to force dojo to the use the ActiveX XMLHttpRequest instead of the builtin XmlHttpRequest object.
  57. // The builtin XmlHttpRequest will return security errors for any files loaded from an MHT file when the MHT file is access through an HTTP url.
  58. require(["dojo/has", "dojo/sniff"], function(has) {
  59. has.add('activex', true, false, true);
  60. has.add('dojo-force-activex-xhr', true, false, true);
  61. has.add('native-xhr', false, false, true);
  62. has.add('native-xhr2', false, false, true);
  63. fn();
  64. });
  65. };
  66. G_Rave1Adapter.f_onDojoLoaded = function(v_sAdapterId, v_sAdapterLocation, v_oAdapterSettings)
  67. {
  68. // Load RAVE and it's dependencies using dojo
  69. require(["dojo/dojo-core-layer"], function() {
  70. require(["com/ibm/vis/main"], function() {
  71. //once we have the rave layer loaded, we can use all rave modules
  72. require(["com/ibm/init/ready", "com/ibm/vis/widget/VisControl", "com/ibm/vis/widget/Environment", "com/ibm/vis/interaction/HighlightRepresentation", "com/ibm/vis/interaction/ChangeEffect", "com/ibm/vis/template/Template", "com/ibm/vis/interaction/SceneItemTypes"], function(v_fnReady, v_fnVisControl, v_fnVisEnvironment, v_fnVisHighlightRepresentation, v_fnVisChangeEffect, v_fnVisTemplate, v_fnSceneItemTypes) {
  73. //ready function is needed to ensure the rave system is properly loaded
  74. v_fnReady(function() {
  75. this.m_oRaveEnv = {
  76. M_fnVisControl : v_fnVisControl,
  77. M_fnVisHighlightRepresentation : v_fnVisHighlightRepresentation,
  78. M_fnVisChangeEffect : v_fnVisChangeEffect,
  79. M_fnVisTemplate : v_fnVisTemplate,
  80. M_fnSceneItemTypes : v_fnSceneItemTypes
  81. };
  82. /*
  83. *
  84. * Environment.checkBrowserSupportedConfiguration()
  85. *
  86. * This is a browser sniffing API and checks if the current browser environment
  87. * is compatible with RAVE. It returns an Integer. The possible value of this
  88. * returned Integer is predefined and mapped to the specific environment setting.
  89. *
  90. * returnCode = 0 : Supported environment for RAVE
  91. *
  92. * All other return codes mean that the environment is not supported by RAVE.
  93. * [Requirement taken from the Acceptance Tests of the RTC Story #29082]
  94. * returnCode = 1 : Silverlight version 5 onwards not available on Internet Explorer
  95. * returnCode = 2 : Internet Explorer version prior to IE7 is found
  96. * returnCode = 3 : Firefox version prior to 3.6 is found
  97. * returnCode = 4 : Opera browser found
  98. * returnCode = 5 : Internet Explorer 9 in Quirks Mode without silverlight version >=5
  99. * returnCode = 6 : Internet Explorer 10 in IE5 Quirks mode
  100. */
  101. if (v_oAdapterSettings && v_oAdapterSettings.custom && v_oAdapterSettings.custom.checkSupportedConfig)
  102. {
  103. var v_iErrorCode = v_fnVisEnvironment.checkBrowserSupportedConfiguration();
  104. //Only look for SV errors. ARs need to work in IE5 Quirks mode in IE 10 in AR Preview
  105. if ( v_iErrorCode == 1 || v_iErrorCode == 5)
  106. {
  107. this.m_oDeferredInitialize.reject({checkSupportedConfigErrorCode : v_iErrorCode});
  108. return;
  109. }
  110. }
  111. this.m_oDeferredInitialize.resolve(true);
  112. }.bind(this));
  113. }.bind(this));
  114. }.bind(this));
  115. }.bind(this));
  116. };
  117. G_Rave1Adapter.Destroy = function()
  118. {
  119. };
  120. // cannot use the AMD text loader as it does not work on IE (access denied errors) when dealing with MHT files or file URL.
  121. G_Rave1Adapter.f_loadTextFile = function( v_sLocation )
  122. {
  123. var v_sAgent = navigator.userAgent.toLowerCase();
  124. var v_fIEVersion = ( v_sAgent.search(/trident\/([0-9]+\.[0-9]+)/) != -1 ) ? parseFloat( RegExp.$1 ) : 0;
  125. var v_bIsIE = (v_fIEVersion >= 7.0);
  126. var v_bIsFirefox = ( v_sAgent.match( /firefox|minefield|shiretoko|namoroka/ ) != null );
  127. var v_oRequest = v_bIsIE ? new ActiveXObject( "MSXML2.XMLHTTP.3.0" ) : new XMLHttpRequest();
  128. try
  129. {
  130. v_oRequest.open( "GET", v_sLocation, false );
  131. if ( v_bIsFirefox )
  132. {
  133. v_oRequest.overrideMimeType( "text/plain; charset=utf-8" );
  134. }
  135. v_oRequest.send( null );
  136. }
  137. catch ( e )
  138. {
  139. // can't localize this message because it may be string file we are loading.
  140. alert( "Failed to load file:" + v_sLocation );
  141. return "";
  142. }
  143. return ( v_oRequest.status == 404 ) ? "" : v_oRequest.responseText;
  144. };
  145. G_Rave1Adapter.LoadVisChartType = function(v_sBundleId, v_sBundleLocation, v_fnOnVisBundleLoaded)
  146. {
  147. if (this.m_oBundleLibrary[v_sBundleId])
  148. {
  149. v_fnOnVisBundleLoaded(v_sBundleId);
  150. return;
  151. }
  152. var v_sUrl = v_sBundleLocation;
  153. // cannot use the AMD text loader as it does not work on IE (access denied errors) when dealing with MHT files or file URL.
  154. var v_sVisJSON = this.f_loadTextFile(v_sUrl);
  155. var v_oVisJSON = dojo.fromJson(v_sVisJSON);
  156. var v_oBundle = this.m_oBundleLibrary[v_sBundleId] = {};
  157. v_oBundle.M_sBundleId = v_sBundleId;
  158. v_oBundle.M_oVisJSON = v_oVisJSON;
  159. v_oBundle.M_sVisJSON = v_sVisJSON;
  160. v_fnOnVisBundleLoaded(v_sBundleId);
  161. };
  162. G_Rave1Adapter.CreateVis = function(v_sBundleId)
  163. {
  164. return new C_Rave1Viz(this.m_oRaveEnv, this.m_oBundleLibrary[v_sBundleId]);
  165. };
  166. G_Rave1Adapter.GetVisDataDefinition = function(v_sBundleId)
  167. {
  168. var v_oVisJSON = this.m_oBundleLibrary[v_sBundleId].M_oVisJSON;
  169. if (!v_oVisJSON)
  170. {
  171. return null;
  172. }
  173. if (!v_oVisJSON.data)
  174. {
  175. return {};
  176. }
  177. var v_oDef = this.m_oVisDataDefinition[v_sBundleId];
  178. if (v_oDef)
  179. {
  180. return v_oDef;
  181. }
  182. // This should probably be generated from the chart type definition and not the visJSON
  183. v_oDef = {};
  184. v_oDef.dataSets = [];
  185. v_oDef.M_oSlotDataSet = {};
  186. for (var v_iData = 0; v_iData < v_oVisJSON.data.length; ++v_iData)
  187. {
  188. var v_oDataSet = v_oVisJSON.data[v_iData];
  189. var v_oDataDef = {};
  190. v_oDef.dataSets.push(v_oDataDef);
  191. v_oDataDef.id = v_oDataSet.id;
  192. v_oDataDef.slots = [];
  193. if ( v_oDataSet.fields )
  194. {
  195. for (var i = 0; i < v_oDataSet.fields.length; ++i)
  196. {
  197. var v_oField = v_oDataSet.fields[i];
  198. var v_oFieldDef = {};
  199. v_oDataDef.slots.push(v_oFieldDef);
  200. v_oFieldDef.id = v_oField.id;
  201. v_oFieldDef.type = v_oField.categories ? "category" : "value";
  202. v_oDef.M_oSlotDataSet[v_oField.id] = v_oDataSet.id;
  203. }
  204. }
  205. }
  206. this.m_oVisDataDefinition[v_sBundleId] = v_oDef;
  207. return v_oDef;
  208. };
  209. //=======================================
  210. var C_Rave1Viz = function(v_oRaveEnv, v_oBundle)
  211. {
  212. this.m_oRaveEnv = v_oRaveEnv;
  213. // Each instance of Viz should keep a local copy of JSON from boundle.
  214. // Otherwise, the later setData would polute the template which is shared by other instants.
  215. this.m_oVisJSONBundle = dojo.clone(v_oBundle.M_oVisJSON);
  216. this.m_oVisJSON = null;
  217. this.m_sErrorMessage = "";
  218. var v_oVisDef = G_Rave1Adapter.GetVisDataDefinition(v_oBundle.M_sBundleId);
  219. this.m_oSlotDataSet = v_oVisDef.M_oSlotDataSet;
  220. };
  221. /*
  222. * Custom vis settings
  223. * properties,
  224. * validateJSON
  225. *
  226. */
  227. C_Rave1Viz.prototype.Initialize = function(v_elContainerDiv, v_oVisSettings, v_fnOnInitializeComplete)
  228. {
  229. this.m_elContainerDiv = v_elContainerDiv;
  230. // RAVE is loaded, load the visualization
  231. this.m_oVisControl = new this.m_oRaveEnv.M_fnVisControl();
  232. v_elContainerDiv.appendChild( this.m_oVisControl.domNode );
  233. // hide the focus rect on IE
  234. if ( G_Rave1Adapter.M_bIsIE )
  235. {
  236. this.m_oVisControl.domNode.hideFocus = true;
  237. }
  238. this.m_oVisControl.startup().then(dojo.hitch(this, this.f_onRaveStartupAsync, v_oVisSettings, v_fnOnInitializeComplete));
  239. };
  240. C_Rave1Viz.prototype.Destroy = function()
  241. {
  242. if (this.m_oVisControl)
  243. {
  244. this.m_oVisControl.destroy();
  245. this.m_oVisControl = null;
  246. }
  247. };
  248. /*
  249. * v_fnOnDrawComplete(v_oDrawStatus)
  250. * v_oDrawStatus = {
  251. * error
  252. * }
  253. */
  254. C_Rave1Viz.prototype.Draw = function(v_fnOnDrawComplete)
  255. {
  256. if (this.m_sErrorMessage)
  257. {
  258. this.DrawBlank();
  259. v_fnOnDrawComplete({ error : this.m_sErrorMessage });
  260. return;
  261. }
  262. try
  263. {
  264. if ( this.m_bDrawWithTransition )
  265. {
  266. this.m_oVisControl.setSpecWithTransition(this.m_oVisJSON, 1);
  267. }
  268. else
  269. {
  270. this.m_oVisControl.setSpec(this.m_oVisJSON);
  271. }
  272. }
  273. catch( e )
  274. {
  275. this.DrawBlank();
  276. var v_sMessage = "";
  277. if (e.getMessage || e.getErrorDescription)
  278. {
  279. v_sMessage = (e.getMessage && e.getMessage()) ? e.getMessage() : "";
  280. if (v_sMessage == "")
  281. {
  282. v_sMessage = (e.getErrorDescription && e.getErrorDescription()) ? e.getErrorDescription() : "";
  283. }
  284. }
  285. v_fnOnDrawComplete({ error : v_sMessage });
  286. return;
  287. }
  288. if ( !this.m_bDrawWithTransition )
  289. {
  290. v_fnOnDrawComplete();
  291. }
  292. this.m_fnOnDrawComplete = v_fnOnDrawComplete;
  293. };
  294. C_Rave1Viz.prototype.DrawHighlights = function(v_aSelectionVisElements, v_aHoverVisElements)
  295. {
  296. var v_aSelections = (v_aSelectionVisElements && v_aSelectionVisElements.length) ? this.f_getSceneItemsFromVisElements(v_aSelectionVisElements) : null;
  297. var v_aHovers = (v_aHoverVisElements && v_aHoverVisElements.length) ? this.f_getSceneItemsFromVisElements(v_aHoverVisElements) : null;
  298. var o = this.m_oVisControl.interactivity().makeHighlightState();
  299. if (v_aSelections)
  300. {
  301. o.setMultiple( v_aSelections, this.k_iHighlight_Selection );
  302. }
  303. if (v_aHovers)
  304. {
  305. o.setMultiple( v_aHovers, this.k_iHighlight_Hover );
  306. }
  307. o.apply();
  308. };
  309. C_Rave1Viz.prototype.DrawBlank = function()
  310. {
  311. var v_oBlank = {
  312. "grammar": [
  313. ]
  314. };
  315. if (this.m_oVisSettings.properties.width && this.m_oVisSettings.properties.height)
  316. {
  317. v_oBlank.size = {
  318. width : this.m_oVisSettings.properties.width,
  319. height : this.m_oVisSettings.properties.height
  320. };
  321. }
  322. try
  323. {
  324. this.m_oVisControl.setSpec(v_oBlank);
  325. }
  326. catch(e)
  327. {
  328. }
  329. };
  330. C_Rave1Viz.prototype.SetData = function(v_idxDataSet, v_oDataSetChanges)
  331. {
  332. var v_oDataSet = this.m_oVisJSON.data[v_idxDataSet];
  333. v_oDataSet.rows = v_oDataSetChanges.rows || [];
  334. if (v_oDataSetChanges.fields)
  335. {
  336. for (var i = 0; i < v_oDataSetChanges.fields.length; ++i)
  337. {
  338. var v_oField = v_oDataSetChanges.fields[i];
  339. var v_oTargetField = v_oDataSet.fields[i];
  340. var v_aProps = ["label", "min", "max", "categories"];
  341. for (var ip = 0; ip < v_aProps.length; ++ip)
  342. {
  343. var s = v_aProps[ip];
  344. v_oTargetField[s] = v_oField[s];
  345. }
  346. }
  347. }
  348. };
  349. C_Rave1Viz.prototype.GetVisElementsAtPoint = function(v_iClientX, v_iClientY)
  350. {
  351. return this.f_createVisElementsForSceneItems(this.m_oVisControl.interactivity().getItemsAtPoint( v_iClientX, v_iClientY ));
  352. };
  353. C_Rave1Viz.prototype.GetVisElementsAtTouchPoint = function(v_iClientX, v_iClientY)
  354. {
  355. // I believe that the accounting for scroll position is because on an iPad sometimes the body can be scrolled, which does not happen on desktop
  356. var x = v_iClientX + document.body.scrollLeft;
  357. var y = v_iClientY + document.body.scrollTop;
  358. var v_oVisElement = this.GetVisElementsAtPoint( x, y );
  359. if ( v_oVisElement )
  360. {
  361. return v_oVisElement;
  362. }
  363. for ( var v_iRadius = 3; v_iRadius <= 12; v_iRadius += 3 )
  364. {
  365. var v_oVisElement = this.f_getVisElementInCircle( x, y, v_iRadius );
  366. if ( v_oVisElement )
  367. {
  368. //G_Debug.F_Print( "f_getVisElementInCircle(" + v_iRadius + ")" );
  369. return v_oVisElement;
  370. }
  371. }
  372. return [];
  373. };
  374. C_Rave1Viz.prototype.f_getVisElementInCircle = function( x, y, v_iRadius )
  375. {
  376. var v_aXs = [];
  377. var v_aYs= [];
  378. var v_aRadians = [0.0, 0.25 * Math.PI, 0.5 * Math.PI, 0.75 * Math.PI, Math.PI, 1.25 * Math.PI, 1.5 * Math.PI, 1.75 * Math.PI];
  379. for ( var i = 0; i < v_aRadians.length; i++ )
  380. {
  381. v_aXs.push( x + Math.round( v_iRadius * Math.cos( v_aRadians[i] ) ) );
  382. v_aYs.push( y + Math.round( v_iRadius * Math.sin( v_aRadians[i] ) ) );
  383. }
  384. return this.f_createVisElementsForSceneItems(this.m_oVisControl.interactivity().getItemsInPolygon(v_aXs, v_aYs));
  385. };
  386. C_Rave1Viz.prototype.GetVisElementsForRows = function(v_idxDataSet, v_aRows)
  387. {
  388. var v_aSceneItems = this.m_oVisControl.interactivity().getItemsMatchingAnyRows(v_aRows);
  389. var v_aFilteredSceneItems = [];
  390. for ( var v_iSi = 0; v_iSi < v_aSceneItems.length; v_iSi++ )
  391. {
  392. var v_oSceneItem = v_aSceneItems[v_iSi];
  393. if (v_oSceneItem.getDataIndex() == v_idxDataSet)
  394. {
  395. var v_aSceneItemRows = v_oSceneItem.getRows();
  396. var v_bAdd = true;
  397. for (var i = 0; i < v_aSceneItemRows.length; ++i)
  398. {
  399. if (v_aRows.indexOf(v_aSceneItemRows[i]) == -1)
  400. {
  401. v_bAdd = false;
  402. break;
  403. }
  404. }
  405. if (v_bAdd)
  406. {
  407. v_aFilteredSceneItems.push(v_oSceneItem);
  408. }
  409. }
  410. }
  411. return this.f_createVisElementsForSceneItems(v_aFilteredSceneItems);
  412. };
  413. C_Rave1Viz.prototype.SetValueSlotFormatter = function(v_fnNumberFormatter)
  414. {
  415. this.m_oVisControl.setNumberFormatter({ formatNumber : this.f_numberFormatterCallback.bind(this, v_fnNumberFormatter) });
  416. };
  417. C_Rave1Viz.prototype.f_numberFormatterCallback = function(v_fnNumberFormatter, value, rowIndex, fieldId, min, max, unit, visId)
  418. {
  419. return v_fnNumberFormatter(value, rowIndex, fieldId, this.m_oSlotDataSet[fieldId]);
  420. };
  421. C_Rave1Viz.prototype.GetCurrentVisualizationState = function()
  422. {
  423. return JSON.stringify(this.m_oVisJSON, null, "\t");
  424. };
  425. C_Rave1Viz.prototype.SetAccessibilityDescription = function(v_sDescription)
  426. {
  427. this.m_oVisJSON.description = v_sDescription;
  428. };
  429. C_Rave1Viz.prototype.ApplySettings = function(v_oVisSettings)
  430. {
  431. this.m_oVisSettings = v_oVisSettings;
  432. this.m_oVisControl.setSpecificationValidation(Boolean(this.m_oVisSettings.custom ? this.m_oVisSettings.custom.validateJSON : false));
  433. this.f_resolveParameters();
  434. if (v_oVisSettings.properties.width || v_oVisSettings.properties.height)
  435. {
  436. if (!this.m_oVisJSON.size)
  437. {
  438. this.m_oVisJSON.size = {};
  439. }
  440. this.m_oVisJSON.size.width = v_oVisSettings.properties.width;
  441. this.m_oVisJSON.size.height = v_oVisSettings.properties.height;
  442. // Explicitly setting the size avoids RAVE bugs with resizing in Silverlight
  443. this.m_oVisControl.domNode.style.width = this.m_oVisJSON.size.width;
  444. this.m_oVisControl.domNode.style.height = this.m_oVisJSON.size.height;
  445. }
  446. this.m_bDrawWithTransition = false;
  447. var v_sAnimationEffect = v_oVisSettings.properties.animationEffect;
  448. if (v_sAnimationEffect && v_sAnimationEffect != "none")
  449. {
  450. this.m_bDrawWithTransition = true;
  451. var v_oEffects = this.m_oVisControl.interactivity().getChangeEffects();
  452. var v_oEffect;
  453. switch (v_sAnimationEffect)
  454. {
  455. case "transition":
  456. v_oEffect = v_oEffects.makeTransitionEffect( 500 );
  457. v_oEffect.setFadeOutDuration(0.0, 1.0);
  458. v_oEffect.setMorphDuration(0.0, 1.0);
  459. v_oEffect.setFadeInDuration(0.0, 1.0);
  460. break;
  461. case "fadeIn":
  462. v_oEffect = v_oEffects.makeFadeInEffect( 500 );
  463. break;
  464. case "flyIn":
  465. v_oEffect = v_oEffects.makeFlyInEffect( 500 );
  466. break;
  467. case "grow":
  468. v_oEffect = v_oEffects.makeGrowEffect( 500 );
  469. break;
  470. case "reveal":
  471. v_oEffect = v_oEffects.makeRevealEffect( 500 );
  472. break;
  473. default:
  474. // unknow animation effect, ignore
  475. this.m_bDrawWithTransition = false;
  476. if (console && console.log) { console.log("Unknown animationEffect ignored: " + v_sAnimationEffect); }
  477. break;
  478. }
  479. v_oEffect.setTarget( this.m_oRaveEnv.M_fnVisChangeEffect.ELEMENT );
  480. v_oEffects.setChangeEffect( v_oEffect, 1 );
  481. // set up rave event handler so we can draw selections after animation effects
  482. this.update = dojo.hitch(this, this.f_onRaveEvent);
  483. this.m_oVisControl.addListener("EffectEndEvent", this);
  484. }
  485. // Setup highlights for selection and hovering
  486. var v_oSelectionHighlight =
  487. {
  488. fill : "rgba(242,188,102,0.4)",
  489. outline : "#F2BC66",
  490. stroke : { width : "1.75pt" }
  491. };
  492. /*
  493. var v_oSelectionHighlight =
  494. {
  495. fill : "rgba(255,255,255,0.6)",
  496. outline : "rgba(255,255,255,0.6)",
  497. stroke : { width : "1.75pt" }
  498. };
  499. */
  500. var v_oHoverHighlight =
  501. {
  502. fill : "rgba(247,225,188,0.4)",
  503. outline : "#F2BC66",
  504. stroke : { width : "1.75pt" }
  505. };
  506. var v_oInteractivity = this.m_oVisControl.interactivity();
  507. v_oInteractivity.setHighlightRepresentation(this.k_iHighlight_Selection, new this.m_oRaveEnv.M_fnVisHighlightRepresentation( v_oSelectionHighlight ));
  508. v_oInteractivity.setHighlightRepresentation(this.k_iHighlight_Hover, new this.m_oRaveEnv.M_fnVisHighlightRepresentation( v_oHoverHighlight ));
  509. };
  510. /**
  511. * @type Boolean Returns false if there was an error while applying the parameters
  512. */
  513. C_Rave1Viz.prototype.f_resolveParameters = function()
  514. {
  515. var v_sVersion = this.m_oVisJSONBundle.version;
  516. if (!v_sVersion || parseFloat(v_sVersion) < 5.0)
  517. {
  518. if (this.m_oVisJSON == null)
  519. {
  520. this.m_oVisJSON = dojo.clone(this.m_oVisJSONBundle);
  521. }
  522. return;
  523. }
  524. //Logged https://rtc-rave.ottawa.ibm.com:9451/ccm/resource/itemName/com.ibm.team.workitem.WorkItem/16859
  525. //Add JSON interface to template constructor and return value of resolve method
  526. var v_sOriginalJSON = this.m_sVisJSON;
  527. var v_bResolvedTemplate = false;
  528. var v_oResolvedJSON = "";
  529. try
  530. {
  531. //The object passed to createTemplateFromJSON will be modified
  532. var v_oClone = dojo.clone( this.m_oVisJSONBundle );
  533. var v_oTemplate = this.m_oRaveEnv.M_fnVisTemplate.createTemplateFromJSON( v_oClone );
  534. if (v_oTemplate.hasParameters())
  535. {
  536. //Logged https://rtc-rave.ottawa.ibm.com:9451/ccm/resource/itemName/com.ibm.team.workitem.WorkItem/16928
  537. //RAVE should return an object of type Array directly
  538. var v_aParams = v_oTemplate.getParameters().toArray();
  539. for (var i = 0; i < v_aParams.length; i++)
  540. {
  541. var v_oParam = v_aParams[i];
  542. var v_sParamId = v_oParam.getId();
  543. if (typeof this.m_oVisSettings.properties[v_sParamId] != "undefined")
  544. {
  545. v_oTemplate.setParameterValue(v_sParamId, this.m_oVisSettings.properties[v_sParamId]);
  546. }
  547. }
  548. if (v_oTemplate.canBeResolved())
  549. {
  550. v_oResolvedJSON = v_oTemplate.resolveToJSON();
  551. v_bResolvedTemplate = true;
  552. }
  553. }
  554. }
  555. catch(e)
  556. {
  557. var v_sMessage = "";
  558. if (e.getMessage || e.getErrorDescription)
  559. {
  560. v_sMessage = (e.getMessage && e.getMessage()) ? e.getMessage() : "";
  561. if (v_sMessage == "")
  562. {
  563. v_sMessage = (e.getErrorDescription && e.getErrorDescription()) ? e.getErrorDescription() : "";
  564. }
  565. }
  566. this.m_sErrorMessage = v_sMessage;
  567. }
  568. if (v_bResolvedTemplate)
  569. {
  570. try {
  571. // The new JSON is the one after resolved, here we need to keep the data.
  572. if (this.m_oVisJSON != null)
  573. {
  574. var v_oData = this.m_oVisJSON.data;
  575. this.m_oVisJSON = v_oResolvedJSON;
  576. this.m_oVisJSON.data = v_oData;
  577. }
  578. else
  579. {
  580. this.m_oVisJSON = v_oResolvedJSON;
  581. }
  582. }
  583. catch(e)
  584. {
  585. this.m_sErrorMessage = e.message ? e.message : " ";
  586. }
  587. }
  588. else if (this.m_oVisJSON == null)
  589. {
  590. this.m_oVisJSON = dojo.clone(this.m_oVisJSONBundle);
  591. }
  592. };
  593. C_Rave1Viz.prototype.f_onRaveStartupAsync = function(v_oVisSettings, v_fnOnInitializeComplete)
  594. {
  595. // The dojo 'then' introduces a try/catch block. This setTimeout prevent that block from interfering with subsequent exceptions.
  596. // The setTimeout should be removed if the defered dojo code is removed.
  597. setTimeout( dojo.hitch(this, this.f_onRaveStartup, v_oVisSettings, v_fnOnInitializeComplete), 0 );
  598. };
  599. C_Rave1Viz.prototype.k_iHighlight_Selection = 0;
  600. C_Rave1Viz.prototype.k_iHighlight_Hover = 1;
  601. C_Rave1Viz.prototype.f_onRaveStartup = function(v_oVisSettings, v_fnOnInitializeComplete)
  602. {
  603. this.ApplySettings(v_oVisSettings);
  604. v_fnOnInitializeComplete();
  605. };
  606. C_Rave1Viz.prototype.f_onRaveEvent = function(v_oEvent, v_oController)
  607. {
  608. if (this.m_fnOnDrawComplete && v_oEvent.getEventGroup() == "EffectEndEvent")
  609. {
  610. var v_fnOnDrawComplete = this.m_fnOnDrawComplete;
  611. this.m_fnOnDrawComplete = null;
  612. v_fnOnDrawComplete();
  613. }
  614. };
  615. C_Rave1Viz.prototype.f_getSceneItemsFromVisElements = function(v_aVisElements)
  616. {
  617. var a = [];
  618. for (var i = 0; i < v_aVisElements.length; ++i)
  619. {
  620. a.push(v_aVisElements[i].m_oSceneItem);
  621. }
  622. return a;
  623. };
  624. C_Rave1Viz.prototype.f_createVisElementsForSceneItems = function(v_aSceneItems)
  625. {
  626. var a = [];
  627. for (var i = 0; i < v_aSceneItems.length; ++i)
  628. {
  629. a.push(new C_Rave1VizElement(v_aSceneItems[i], this.m_oRaveEnv));
  630. }
  631. return a;
  632. };
  633. C_Rave1Viz.prototype.IsEqualVisElement = function(v_oVisElement1, v_oVisElement2)
  634. {
  635. if (v_oVisElement1 && v_oVisElement2)
  636. {
  637. return (v_oVisElement1.m_oSceneItem == v_oVisElement2.m_oSceneItem);
  638. }
  639. // return true if both are null
  640. return (v_oVisElement1 == v_oVisElement2);
  641. };
  642. //==================================================================================
  643. var C_Rave1VizElement = function(v_oSceneItem, v_oRaveEnv)
  644. {
  645. this.m_oSceneItem = v_oSceneItem;
  646. this.m_oRaveEnv = v_oRaveEnv;
  647. };
  648. C_Rave1VizElement.prototype.GetType = function()
  649. {
  650. if (!this.m_sType)
  651. {
  652. var v_sType = this.m_oSceneItem.getType();
  653. var v_sSubType = this.m_oSceneItem.subType();
  654. if (v_sType == this.m_oRaveEnv.M_fnSceneItemTypes.TYPE_ELEMENT && v_sSubType != this.m_oRaveEnv.M_fnSceneItemTypes.SUBTYPE_LABEL)
  655. {
  656. this.m_sType = "intersection";
  657. }
  658. else
  659. {
  660. this.m_sType = "category";
  661. }
  662. }
  663. return this.m_sType;
  664. };
  665. C_Rave1VizElement.prototype.GetDataSetIdx = function()
  666. {
  667. return this.m_oSceneItem.getDataIndex();
  668. };
  669. C_Rave1VizElement.prototype.GetRows = function()
  670. {
  671. return this.m_oSceneItem.getRowsWithoutAugmentedRows();
  672. };
  673. C_Rave1VizElement.prototype.GetFields = function()
  674. {
  675. // TBD
  676. };
  677. C_Rave1VizElement.prototype.GetColor = function()
  678. {
  679. var v_oColor = this.f_getColorFromSceneItem(this.m_oSceneItem);
  680. if (!v_oColor)
  681. {
  682. var v_aChildren = this.m_oSceneItem.getHitChildren();
  683. if (v_aChildren)
  684. {
  685. for (var i = 0; !v_oColor && (i < v_aChildren.length); ++i)
  686. {
  687. v_oColor = this.f_getColorFromSceneItem(v_aChildren[i]);
  688. }
  689. }
  690. }
  691. if (v_oColor != null)
  692. {
  693. var v_oJSColor = {};
  694. var v_aColors = v_oColor.getRGBA();
  695. if (v_aColors.length >= 3)
  696. {
  697. v_oJSColor.r = v_aColors[0];
  698. v_oJSColor.g = v_aColors[1];
  699. v_oJSColor.b = v_aColors[2];
  700. return v_oJSColor;
  701. }
  702. }
  703. return v_oColor;
  704. };
  705. C_Rave1VizElement.prototype.f_getColorFromSceneItem = function(v_oSceneItem)
  706. {
  707. var v_oStyle = v_oSceneItem.getSceneNode().getRenderStyleInfo();
  708. // get the fill; if non-null, try first the gradient, then the solid
  709. var v_oFill = v_oStyle.getFillProperty();
  710. if (v_oFill != null)
  711. {
  712. var v_aColors = v_oFill.getGradientColors(); // returns an array of colors
  713. if (v_aColors != null && v_aColors.length >= 1)
  714. {
  715. return v_aColors[0];
  716. }
  717. var v_oSolid = v_oFill.getSolid(); // returns a single color
  718. if (v_oSolid != null)
  719. {
  720. return v_oSolid;
  721. }
  722. }
  723. // fill didn't work, try the outline
  724. var v_oOutline = v_oStyle.getOutlineProperty();
  725. if (v_oOutline != null)
  726. {
  727. return v_oOutline;
  728. }
  729. return null;
  730. };
  731. return G_Rave1Adapter;
  732. });