skill_wheel.js.tpl 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713
  1. {# topbar #}
  2. {% include 'layout/topbar.tpl'|get_template %}
  3. <script>
  4. var SkillWheel = {
  5. currentSkill: null,
  6. getSkillInfo: function(skillId) {
  7. return $.getJSON(
  8. '{{ url }}',
  9. {
  10. a: 'get_skill_info',
  11. id: parseInt(skillId)
  12. }
  13. );
  14. },
  15. showFormSkill: function(skillId) {
  16. skillId = parseInt(skillId);
  17. var formSkill = $('form[name="form"]');
  18. var getSkillInfo = SkillWheel.getSkillInfo(skillId);
  19. $.when(getSkillInfo).done(function(skillInfo) {
  20. SkillWheel.currentSkill = skillInfo;
  21. var getSkillParentInfo = SkillWheel.getSkillInfo(skillInfo.extra.parent_id);
  22. $.when(getSkillParentInfo).done(function(skillParentInfo) {
  23. formSkill.find('p#parent').text(skillParentInfo.name);
  24. });
  25. formSkill.find('p#name').text(skillInfo.name);
  26. if (skillInfo.short_code.length > 0) {
  27. formSkill.find('p#short_code').text(skillInfo.short_code).parent().parent().show();
  28. } else {
  29. formSkill.find('p#short_code').parent().parent().hide();
  30. }
  31. if (skillInfo.description.length > 0) {
  32. formSkill.find('p#description').text(skillInfo.description).parent().parent().show();
  33. } else {
  34. formSkill.find('p#description').parent().parent().hide();
  35. }
  36. if (skillInfo.gradebooks.length > 0) {
  37. formSkill.find('ul#gradebook').empty().parent().parent().show();
  38. $.each(skillInfo.gradebooks, function(index, gradebook) {
  39. $('<li>').text(gradebook.name).appendTo(formSkill.find('ul#gradebook'));
  40. });
  41. } else {
  42. formSkill.find('ul#gradebook').parent().parent().hide();
  43. }
  44. $('#frm-skill').modal('show');
  45. });
  46. }
  47. };
  48. /* Skill wheel settings */
  49. var debug = true;
  50. var url = '{{ url }}';
  51. var skill_to_load_from_get = '{{ skill_id_to_load }}';
  52. //Just in case we want to use it
  53. var main_depth = 4;
  54. var main_parent_id = 0;
  55. // Used to split in two word or not
  56. var max_size_text_length = 20;
  57. /* ColorBrewer settings */
  58. var my_domain = [1,2,3,4,5,6,7,8,9];
  59. var col = 9;
  60. var color_patterns = [];
  61. /*
  62. See colorbrewer documentation
  63. color_patterns[1] = d3.scale.ordinal().domain(my_domain).range(colorbrewer.Blues[col]);
  64. color_patterns[2] = d3.scale.ordinal().domain(my_domain).range(colorbrewer.Purples[col]);
  65. color_patterns[2] = d3.scale.ordinal().domain(my_domain).range(colorbrewer.Blues[6]);
  66. color_patterns[3] = d3.scale.ordinal().domain(my_domain).range(colorbrewer.Greens[col]);
  67. color_patterns[4] = d3.scale.ordinal().domain(my_domain).range(colorbrewer.Reds[col]);
  68. color_patterns[5] = d3.scale.ordinal().domain(my_domain).range(colorbrewer.Oranges[col]);
  69. color_patterns[6] = d3.scale.ordinal().domain(my_domain).range(colorbrewer.YlOrBr[col]);
  70. color_patterns[7] = d3.scale.ordinal().domain(my_domain).range(colorbrewer.YlGn[col]);
  71. color_patterns[8] = d3.scale.ordinal().domain(my_domain).range(colorbrewer.YlGnBu[col]);
  72. color_patterns[9] = d3.scale.ordinal().domain(my_domain).range(colorbrewer.GnBu[col]);
  73. color_patterns[10] = d3.scale.ordinal().domain(my_domain).range(colorbrewer.BuGn[col]);
  74. color_patterns[11] = d3.scale.ordinal().domain(my_domain).range(colorbrewer.PuBuGn[col]);
  75. color_patterns[12] = d3.scale.ordinal().domain(my_domain).range(colorbrewer.PuBu[col]);
  76. color_patterns[13] = d3.scale.ordinal().domain(my_domain).range(colorbrewer.BuPu[col]);
  77. color_patterns[14] = d3.scale.ordinal().domain(my_domain).range(colorbrewer.RdPu[col]);
  78. color_patterns[15] = d3.scale.ordinal().domain(my_domain).range(colorbrewer.PuRd[col]);
  79. color_patterns[16] = d3.scale.ordinal().domain(my_domain).range(colorbrewer.OrRd[col]);
  80. color_patterns[17] = d3.scale.ordinal().domain(my_domain).range(colorbrewer.YlOrRd[col]);*/
  81. //Too make the gray tones lighter
  82. col = 3;
  83. color_patterns[18] = d3.scale.ordinal().domain(my_domain).range(colorbrewer.Blues[col]);
  84. //If you want to use the category10()
  85. //var normal_fill = d3.scale.category10().domain(my_domain);
  86. //First 8 colors
  87. var colors = $.xcolor.analogous('#da0'); //8 colors
  88. //How long will be the array of colors?
  89. var color_loops = 4;
  90. // Generating array of colors thanks to the "$.xcolor.analogous" function we can create a rainbow style!
  91. for (i= 0; i < color_loops; i++) {
  92. //Getting the latest color hex of the 8 colors loaded
  93. last_color = colors[colors.length-1].getHex();
  94. //Getting the complementary
  95. glue_color = $.xcolor.complementary(last_color);
  96. //Generating 8 more colors
  97. temp_color_array = $.xcolor.analogous(glue_color);
  98. //Adding the color to the main array
  99. colors = $.merge(colors, temp_color_array);
  100. }
  101. /* The partiton name will have 1 or 2 lines? */
  102. function is_multiline(word) {
  103. if (word) {
  104. if (word.length > max_size_text_length) {
  105. return (word).split(" ").length > 1;
  106. }
  107. }
  108. return false;
  109. }
  110. /* Interpolate the scales! */
  111. function arcTween(d, arc, x, y, r) {
  112. var my = maxY(d),
  113. xd = d3.interpolate(x.domain(), [d.x, d.x + d.dx]),
  114. yd = d3.interpolate(y.domain(), [d.y, my]),
  115. yr = d3.interpolate(y.range(), [d.y ? 20 : 0, r]);
  116. return function(d) {
  117. return function(t) {
  118. x.domain(xd(t));
  119. y.domain(yd(t)).range(yr(t));
  120. return arc(d);
  121. };
  122. };
  123. }
  124. /* Calculate maxY */
  125. function maxY(d) {
  126. return d.children ? Math.max.apply(Math, d.children.map(maxY)) : d.y + d.dy;
  127. }
  128. /* Use a formula for contrasting colour
  129. http://www.w3.org/WAI/ER/WD-AERT/#color-contrast
  130. */
  131. function brightness(rgb) {
  132. return rgb.r * .299 + rgb.g * .587 + rgb.b * .114;
  133. }
  134. /* Returns whether p is parent of c */
  135. function isParentOf(p, c) {
  136. if (p === c) return true;
  137. if (p.children) {
  138. return p.children.some(function(d) {
  139. return isParentOf(d, c);
  140. });
  141. }
  142. return false;
  143. }
  144. function get_color(d) {
  145. depth = d.depth;
  146. if (d.family_id) {
  147. /*var p = color_patterns[d.family_id];
  148. color = p(depth -1 + d.counter);
  149. d.color = color;*/
  150. if (depth > 1) {
  151. family1 = colors[d.family_id];
  152. family2 = colors[d.family_id + 2];
  153. position = d.depth*d.counter;
  154. //part_color = $.xcolor.gradientlevel(family1, family2, position, 100);
  155. part_color = $.xcolor.lighten(family1, position, 15);
  156. color = part_color.getHex();
  157. //console.log(d.depth + " - " + d.name + " + "+ color+ "+ " +d.counter);
  158. } else {
  159. color = colors[d.family_id];
  160. }
  161. return color;
  162. }
  163. color = '#fefefe';
  164. return color; //missing colors
  165. }
  166. /*
  167. gray tones for all skills that have no particular property ("Basic skills wheel" view)
  168. yellow tones for skills that are provided by courses in Chamilo ("Teachable skills" view)
  169. bright blue tones for personal skills already acquired by the student currently looking at the weel ("My skills" view)
  170. dark blue tones for skills already acquired by a series of students, when looking at the will in the "Owned skills" view.
  171. bright green for skills looked for by a HR director ("Profile search" view)
  172. dark green for skills most searched for, summed up from the different saved searches from HR directors ("Most wanted skills")
  173. bright red for missing skills, in the "Required skills" view for a student when looking at the "Most wanted skills" (or later, when we will have developed that, for the "Matching position" view)
  174. */
  175. var userSkills;
  176. /**
  177. Manage the partition background colors
  178. **/
  179. function set_skill_style(d, attribute, searched_skill_id) {
  180. //Default border color (stroke)
  181. return_stroke = '#000';
  182. //0. Nice rainbow colors (Comment 1.0 to see the rainbow!)
  183. return_fill = get_color(d);
  184. //1. Grey colors using colorbrewer
  185. var p = color_patterns[18];
  186. color = p(depth -1 + d.counter);
  187. return_fill = color;
  188. //2. Yellow - If the skill has a gradebook attached
  189. if (d.skill_has_gradebook) {
  190. return_fill = '#F89406';
  191. //return_stroke = 'grey';
  192. }
  193. //3. Red - if you search that skill
  194. if (d.isSearched) {
  195. return_fill = '#B94A48';
  196. }
  197. if (!userSkills) {
  198. $.ajax({
  199. url: url + '&a=get_all_user_skills',
  200. async: false,
  201. success: function (skills) {
  202. userSkills = jQuery.parseJSON(skills);
  203. }
  204. });
  205. }
  206. // Old way (it makes a lot of ajax calls)
  207. //4. Blue - if user achieved that skill
  208. //var skill = false;
  209. /*$.ajax({
  210. url: url+'&a=get_user_skill&profile_id='+d.id,
  211. async: false,
  212. success: function(skill) {
  213. if (skill == 1) {
  214. return_fill = '#3A87AD';
  215. }
  216. }
  217. });*/
  218. // New way (Only 1 ajax call)
  219. // 4. Blue - if user achieved that skill
  220. if (userSkills[d.id]) {
  221. return_fill = '#A1D99B';
  222. }
  223. // 5. Grey / Black if the skill is disabled
  224. if (d.status < 1) {
  225. return_fill = '#48616C';
  226. }
  227. switch (attribute) {
  228. case 'fill':
  229. //In order to identify the color of the text (white, black) used in other function
  230. d.color = return_fill;
  231. return return_fill;
  232. break;
  233. case 'stroke':
  234. return return_stroke;
  235. break;
  236. }
  237. }
  238. /* When you click a skill partition */
  239. function click_partition(d, path, text, icon, arc, x, y, r, p, vis) {
  240. if (debug) {
  241. console.log('Clicking a partition skill id: '+d.id);
  242. console.log(d);
  243. console.log('real parent_id: '+d.real_parent_id + ' parent_id: ' +d.parent_id);
  244. console.log('depth ' + d.depth);
  245. console.log('main_depth ' + main_depth);
  246. console.log('main_parent_id: ' + main_parent_id);
  247. }
  248. if (d.depth >= main_depth) {
  249. //main_depth += main_depth;
  250. if (main_parent_id) {
  251. load_nodes(main_parent_id, main_depth);
  252. } else {
  253. load_nodes(d.id, main_depth);
  254. }
  255. }
  256. if (d.id) {
  257. console.log('Getting skill info');
  258. skill_info = get_skill_info(d.parent_id);
  259. main_parent_id = skill_info.extra.parent_id;
  260. main_parent_id = d.parent_id;
  261. console.log('Setting main_parent_id: ' + main_parent_id);
  262. }
  263. //console.log(main_parent_id);
  264. /* "No id" means that we reach the center of the wheel go to the root*/
  265. if (!d.id) {
  266. load_nodes(main_parent_id, main_depth);
  267. }
  268. if (debug) console.log('Continue to click_partition');
  269. //console.log(main_parent_id);
  270. //Duration of the transition
  271. var duration = 1000;
  272. path.transition()
  273. .duration(duration)
  274. .attrTween("d", arcTween(d, arc, x, y, r));
  275. /* Updating text position */
  276. // Somewhat of a hack as we rely on arcTween updating the scales.
  277. text.style("visibility", function(e) {
  278. return isParentOf(d, e) ? null : d3.select(this).style("visibility");
  279. })
  280. .transition().duration(duration)
  281. .attrTween("text-anchor", function(d) {
  282. return function() {
  283. return x(d.x + d.dx / 2) > Math.PI ? "end" : "start";
  284. };
  285. })
  286. .attrTween("transform", function(d) {
  287. var multiline = is_multiline(d.name); //(d.name || "").split(" ").length > 1;
  288. return function() {
  289. var angle = x(d.x + d.dx / 2) * 180 / Math.PI - 90,
  290. rotate = angle + (multiline ? -.5 : 0);
  291. return "rotate(" + rotate + ")translate(" + (y(d.y) + p) + ")rotate(" + (angle > 90 ? -180 : 0) + ")";
  292. };
  293. })
  294. .style("fill-opacity", function(e) {
  295. return isParentOf(d, e) ? 1 : 1e-6;
  296. })
  297. .each("end", function(e) {
  298. d3.select(this).style("visibility", isParentOf(d, e) ? null : "hidden");
  299. });
  300. //Add an icon in the partition
  301. /* Updating icon position */
  302. /*
  303. icon.transition().duration(duration)
  304. .attrTween("text-anchor", function(d) {
  305. return function() {
  306. return x(d.x + d.dx / 2) > Math.PI ? "end" : "start";
  307. };
  308. })
  309. .attrTween("transform", function(d) {
  310. return function() {
  311. var angle = x(d.x + d.dx / 2) * 180 / Math.PI - 90,
  312. rotate = angle;
  313. return "rotate(" + rotate + ")translate(" + (y(d.y) + p) + ")rotate(" + (angle > 90 ? -180 : 0) + ")";
  314. };
  315. })
  316. .style("fill-opacity", function(e) {
  317. //return isParentOf(d, e) ? 1 : 1e-6;
  318. })
  319. .each("end", function(e) {
  320. //d3.select(this).style("visibility", isParentOf(d, e) ? null : "hidden");
  321. });*/
  322. }
  323. /* Handles mouse clicks */
  324. function handle_mousedown_event(d, path, text, icon, arc, x, y, r, padding, vis) {
  325. switch (d3.event.which) {
  326. case 1:
  327. //alert('Left mouse button pressed');
  328. click_partition(d, path, text, icon, arc, x, y, r, padding, vis);
  329. break;
  330. case 2:
  331. //alert('Middle mouse button pressed');
  332. break;
  333. case 3:
  334. if (typeof d.id === 'undefined') {
  335. break;
  336. }
  337. SkillWheel.showFormSkill(d.id);
  338. //alert('Right mouse button pressed');
  339. break;
  340. default:
  341. //alert('You have a strange mouse :D '); //
  342. }
  343. }
  344. /*
  345. Loads the skills partitions thanks to a json call
  346. */
  347. function load_nodes(load_skill_id, main_depth, extra_parent_id) {
  348. if (debug) {
  349. console.log('Load nodes ----->');
  350. console.log('Loading skill id: '+load_skill_id+' with depth ' + main_depth);
  351. console.log('main_parent_id before: ' + main_parent_id);
  352. }
  353. // "Root partition" on click switch
  354. if (main_parent_id && load_skill_id) {
  355. skill_info = get_skill_info(load_skill_id);
  356. if (skill_info && skill_info.extra) {
  357. main_parent_id = skill_info.extra.parent_id;
  358. } else {
  359. main_parent_id = 0;
  360. }
  361. console.log('main_parent_id after: ' + main_parent_id);
  362. }
  363. if (load_skill_id && load_skill_id == 1) {
  364. main_parent_id = 0;
  365. }
  366. /** Define constants and size of the wheel */
  367. /** Total width of the wheel (also counts for the height) */
  368. var w = 900,
  369. h = w,
  370. r = w / 2,
  371. /** x/y positionning of the center of the wheel */
  372. x = d3.scale.linear().range([0, 2 * Math.PI]),
  373. y = d3.scale.pow().exponent(1.1).domain([0, 1]).range([0, r]),
  374. /** Padding in pixels before the string starts */
  375. padding = 3,
  376. /** Levels to show */
  377. levels_to_show = 3;
  378. reduce_top = 1;
  379. /* Locate the #div id element */
  380. $("#skill_wheel").remove();
  381. $("#wheel_container").html('');
  382. $("#wheel_container").append('<div id="skill_wheel"></div>');
  383. var div = d3.select("#skill_wheel");
  384. /* Remove the image (make way for the dynamic stuff */
  385. div.select("img").remove();
  386. /* Append an element "svg" to the #vis section */
  387. var vis = div.append("svg")
  388. //.attr("class", "Blues")
  389. .attr("width", w + padding * 2)
  390. .attr("height", h + padding * 2)
  391. .append("g")
  392. .attr("transform", "translate(" + (r + padding) + "," + (r/reduce_top + padding) + ")");
  393. /* ...update translate variables to change coordinates of wheel's center */
  394. /* Add a small label to help the user */
  395. div.append("p")
  396. .attr("id", "intro")
  397. .text("{{ "ClickToZoom"|get_lang }}");
  398. /* Generate the partition layout */
  399. var partition = d3.layout.partition()
  400. .sort(null)
  401. /** Value here seems to be a calculation of the size of the elements
  402. depending on the level of depth they're at. Changing it makes
  403. elements pass over the limits of others... */
  404. //.size([1, 2])
  405. .value(function(d) {
  406. //return 5.8 - d.depth;
  407. //When having more than 4 children seems that the code above does not work
  408. return 1;
  409. });
  410. /* Generate an arc which will define the whole wheel context */
  411. var arc = d3.svg.arc()
  412. .startAngle(function(d) {
  413. return Math.max(0, Math.min(2 * Math.PI, x(d.x)));
  414. })
  415. .endAngle(function(d) {
  416. return Math.max(0, Math.min(2 * Math.PI, x(d.x + d.dx)));
  417. })
  418. .innerRadius(function(d) {
  419. return Math.max(0, d.y ? y(d.y) : d.y);
  420. })
  421. .outerRadius(function(d) {
  422. return Math.max(0, y(d.y + d.dy));
  423. });
  424. load_skill_condition = '';
  425. //First the $_GET value
  426. if (skill_to_load_from_get != 0) {
  427. load_skill_condition = 'skill_id=' + skill_to_load_from_get;
  428. }
  429. //The JS load
  430. if (load_skill_id != 0) {
  431. load_skill_condition = 'skill_id=' + load_skill_id;
  432. }
  433. d3.json("{{ wheel_url }}&main_depth="+main_depth+"&"+load_skill_condition, function(json) {
  434. /** Define the list of nodes based on the JSON */
  435. var nodes = partition.nodes({
  436. children: json
  437. });
  438. /* Setting all skills */
  439. var path = vis.selectAll("path").data(nodes);
  440. /* Setting all texts */
  441. var text = vis.selectAll("text").data(nodes);
  442. /* Setting icons */
  443. var icon = vis.selectAll("icon").data(nodes);
  444. /* Path settings */
  445. path.enter().append("path")
  446. .attr("id", function(d, i) {
  447. return "path-" + i;
  448. })
  449. .attr("d", arc)
  450. .attr("fill-rule", "evenodd")
  451. .attr("class", "skill_partition skill_background")
  452. // .style("fill", colour)
  453. .style("fill", function(d) {
  454. return set_skill_style(d, 'fill', load_skill_id);
  455. })
  456. .style("stroke", function(d) {
  457. return set_skill_style(d, 'stroke');
  458. })
  459. .on("mouseover", function(d, i) {
  460. //$("#icon-" + i).show();
  461. })
  462. .on("mouseout", function(d, i) {
  463. //$("#icon-" + i).hide();
  464. })
  465. .on("contextmenu", function(d, i) {
  466. //Handles mouse clicks
  467. handle_mousedown_event(d, path, text, icon, arc, x, y, r, padding, vis);
  468. //Blocks "right click menu"
  469. d3.event.preventDefault();
  470. return false;
  471. })
  472. .on("mousedown", function(d, i) {
  473. })
  474. .on("click", function(d) {
  475. //Simple click
  476. handle_mousedown_event(d, path, text, icon, arc, x, y, r, padding, vis);
  477. });
  478. /*//Redefine the root
  479. path_zero = vis.selectAll("#path-0").on("mousedown", function(d){
  480. d = get_skill_info(extra_parent_id);
  481. d.parent_id = d.extra.parent_id;
  482. click_partition(d, path, text, icon, arc, x, y, r, padding, vis);
  483. });*/
  484. /* End setting skills */
  485. /* Text settings */
  486. var textEnter = text.enter().append("text")
  487. .style("fill-opacity", 1)
  488. .style("fill", function(d) {
  489. return brightness(d3.rgb(d.color)) < 125 ? "#eee" : "#000";
  490. })
  491. .attr("text-anchor", function(d) {
  492. return x(d.x + d.dx / 2) > Math.PI ? "end" : "start";
  493. })
  494. .attr("rel", "tooltip_skill")
  495. .attr("title", function(d) {
  496. return d.name;
  497. })
  498. .attr("dy", ".2em")
  499. .attr("transform", function(d) {
  500. /** Get the text details and define the rotation and general position */
  501. var multiline = is_multiline(d.name); //(d.name || "").split(" ").length > 1,
  502. angle = x(d.x + d.dx / 2) * 180 / Math.PI - 90,
  503. rotate = angle + (multiline ? -.5 : 0);
  504. return "rotate(" + rotate + ")translate(" + (y(d.y) + padding) + ")rotate(" + (angle > 90 ? -180 : 0) + ")";
  505. })
  506. .on("mouseover", function(d, i) {
  507. //$("#icon-" + i).show();
  508. })
  509. .on("mouseout", function(d, i) {
  510. //$("#icon-" + i).hide();
  511. })
  512. .on("contextmenu", function(d, i) {
  513. handle_mousedown_event(d, path, text, icon, arc, x, y, r, padding, vis);
  514. d3.event.preventDefault();
  515. })
  516. .on("mousedown", function(d, i) {
  517. })
  518. .on("click", function(d) {
  519. handle_mousedown_event(d, path, text, icon, arc, x, y, r, padding, vis);
  520. });
  521. /** Managing text - maximum two words */
  522. textEnter.append("tspan")
  523. .attr("x", 0)
  524. .text(function(d) {
  525. if (d.short_code) {
  526. return d.short_code;
  527. }
  528. if (d.depth && d.name) {
  529. var nameParts = d.name.split(' ');
  530. if (nameParts[0].length > max_size_text_length) {
  531. return nameParts[0].substring(0, max_size_text_length - 3) + '...';
  532. }
  533. return nameParts[0];
  534. }
  535. return d.depth ? d.name : '';
  536. });
  537. textEnter.append("tspan")
  538. .attr("x", 0)
  539. .attr("dy", "1em")
  540. .text(function(d) {
  541. if (d.short_code) {
  542. return null;
  543. }
  544. if (d.depth && d.name) {
  545. var nameParts = d.name.split(' ');
  546. if (nameParts.length >= 2) {
  547. if (nameParts[1].length > max_size_text_length) {
  548. return nameParts[1].substring(0, max_size_text_length - 3) + '...';
  549. }
  550. return nameParts[1];
  551. }
  552. return '';
  553. }
  554. return d.depth ? d.name : '';
  555. });
  556. /* Icon settings */
  557. /*
  558. var icon_click = icon.enter().append("text")
  559. .style("fill-opacity", 1)
  560. .style("fill", function(d) {
  561. //return "#000";
  562. })
  563. .attr("text-anchor", function(d) {
  564. return x(d.x + d.dx / 2) > Math.PI ? "end" : "start";
  565. })
  566. .attr("dy", ".2em")
  567. .attr("transform", function(d) {
  568. ///Get the text details and define the rotation and general position
  569. angle = x(d.x + d.dx / 2) * 180 / Math.PI - 90,
  570. rotate = angle;
  571. return "rotate(" + rotate + ")translate(" + (y(d.y) + padding +80) + ")rotate(" + (angle > 90 ? -180 : 0) + ")";
  572. })
  573. .on("click", function(d){
  574. SkillWheel.showFormSkill(d.id);
  575. });
  576. icon_click.append("tspan")
  577. .attr("id", function(d, i) {
  578. return "icon-" + i;
  579. })
  580. .attr("x", 0)
  581. .attr("display", 'none')
  582. .text(function(d) {
  583. //return "Click";
  584. });*/
  585. });
  586. if (debug) {
  587. console.log('<------ End load nodes ----->');
  588. }
  589. }
  590. /* Skill AJAX calls */
  591. function get_skill_info(my_id) {
  592. var skill = false;
  593. $.ajax({
  594. url: url+'&a=get_skill_info&id='+my_id,
  595. async: false,
  596. success: function(json) {
  597. skill = jQuery.parseJSON(json);
  598. return skill;
  599. }
  600. });
  601. return skill;
  602. }
  603. function get_gradebook_info(id) {
  604. var item = false;
  605. $.ajax({
  606. url: url+'&a=get_gradebook_info&id='+id,
  607. async: false,
  608. success: function(json) {
  609. item = jQuery.parseJSON(json);
  610. return item;
  611. }
  612. });
  613. return item;
  614. }
  615. </script>