skill_wheel.js.tpl 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709
  1. {# topbar #}
  2. {% include template ~ "/layout/topbar.tpl" %}
  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.Greens[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 = '#3A87AD';
  222. }
  223. switch (attribute) {
  224. case 'fill':
  225. //In order to identify the color of the text (white, black) used in other function
  226. d.color = return_fill;
  227. return return_fill;
  228. break;
  229. case 'stroke':
  230. return return_stroke;
  231. break;
  232. }
  233. }
  234. /* When you click a skill partition */
  235. function click_partition(d, path, text, icon, arc, x, y, r, p, vis) {
  236. //console.log(d.depth);
  237. if (debug) {
  238. console.log('Clicking a partition skill id: '+d.id);
  239. console.log(d);
  240. console.log('real parent_id: '+d.real_parent_id + ' parent_id: ' +d.parent_id);
  241. console.log('depth ' + d.depth);
  242. console.log('main_depth ' + main_depth);
  243. console.log('main_parent_id: ' + main_parent_id);
  244. }
  245. if (d.depth >= main_depth) {
  246. //main_depth += main_depth;
  247. if (main_parent_id) {
  248. load_nodes(main_parent_id, main_depth);
  249. } else {
  250. load_nodes(d.id, main_depth);
  251. }
  252. }
  253. if (d.id) {
  254. console.log('Getting skill info');
  255. skill_info = get_skill_info(d.parent_id);
  256. main_parent_id = skill_info.extra.parent_id;
  257. main_parent_id = d.parent_id;
  258. console.log('Setting main_parent_id: ' + main_parent_id);
  259. }
  260. //console.log(main_parent_id);
  261. /* "No id" means that we reach the center of the wheel go to the root*/
  262. if (!d.id) {
  263. load_nodes(main_parent_id, main_depth);
  264. }
  265. if (debug) console.log('Continue to click_partition');
  266. //console.log(main_parent_id);
  267. //Duration of the transition
  268. var duration = 1000;
  269. path.transition()
  270. .duration(duration)
  271. .attrTween("d", arcTween(d, arc, x, y, r));
  272. /* Updating text position */
  273. // Somewhat of a hack as we rely on arcTween updating the scales.
  274. text.style("visibility", function(e) {
  275. return isParentOf(d, e) ? null : d3.select(this).style("visibility");
  276. })
  277. .transition().duration(duration)
  278. .attrTween("text-anchor", function(d) {
  279. return function() {
  280. return x(d.x + d.dx / 2) > Math.PI ? "end" : "start";
  281. };
  282. })
  283. .attrTween("transform", function(d) {
  284. var multiline = is_multiline(d.name); //(d.name || "").split(" ").length > 1;
  285. return function() {
  286. var angle = x(d.x + d.dx / 2) * 180 / Math.PI - 90,
  287. rotate = angle + (multiline ? -.5 : 0);
  288. return "rotate(" + rotate + ")translate(" + (y(d.y) + p) + ")rotate(" + (angle > 90 ? -180 : 0) + ")";
  289. };
  290. })
  291. .style("fill-opacity", function(e) {
  292. return isParentOf(d, e) ? 1 : 1e-6;
  293. })
  294. .each("end", function(e) {
  295. d3.select(this).style("visibility", isParentOf(d, e) ? null : "hidden");
  296. });
  297. //Add an icon in the partition
  298. /* Updating icon position */
  299. /*
  300. icon.transition().duration(duration)
  301. .attrTween("text-anchor", function(d) {
  302. return function() {
  303. return x(d.x + d.dx / 2) > Math.PI ? "end" : "start";
  304. };
  305. })
  306. .attrTween("transform", function(d) {
  307. return function() {
  308. var angle = x(d.x + d.dx / 2) * 180 / Math.PI - 90,
  309. rotate = angle;
  310. return "rotate(" + rotate + ")translate(" + (y(d.y) + p) + ")rotate(" + (angle > 90 ? -180 : 0) + ")";
  311. };
  312. })
  313. .style("fill-opacity", function(e) {
  314. //return isParentOf(d, e) ? 1 : 1e-6;
  315. })
  316. .each("end", function(e) {
  317. //d3.select(this).style("visibility", isParentOf(d, e) ? null : "hidden");
  318. });*/
  319. }
  320. /* Handles mouse clicks */
  321. function handle_mousedown_event(d, path, text, icon, arc, x, y, r, padding, vis) {
  322. switch (d3.event.which) {
  323. case 1:
  324. //alert('Left mouse button pressed');
  325. click_partition(d, path, text, icon, arc, x, y, r, padding, vis);
  326. break;
  327. case 2:
  328. //alert('Middle mouse button pressed');
  329. break;
  330. case 3:
  331. if (typeof d.id === 'undefined') {
  332. break;
  333. }
  334. SkillWheel.showFormSkill(d.id);
  335. //alert('Right mouse button pressed');
  336. break;
  337. default:
  338. //alert('You have a strange mouse :D '); //
  339. }
  340. }
  341. /*
  342. Loads the skills partitions thanks to a json call
  343. */
  344. function load_nodes(load_skill_id, main_depth, extra_parent_id) {
  345. if (debug) {
  346. console.log('Load nodes ----->');
  347. console.log('Loading skill id: '+load_skill_id+' with depth ' + main_depth);
  348. console.log('main_parent_id before: ' + main_parent_id);
  349. }
  350. // "Root partition" on click switch
  351. if (main_parent_id && load_skill_id) {
  352. skill_info = get_skill_info(load_skill_id);
  353. if (skill_info && skill_info.extra) {
  354. main_parent_id = skill_info.extra.parent_id;
  355. } else {
  356. main_parent_id = 0;
  357. }
  358. console.log('main_parent_id after: ' + main_parent_id);
  359. }
  360. if (load_skill_id && load_skill_id == 1) {
  361. main_parent_id = 0;
  362. }
  363. /** Define constants and size of the wheel */
  364. /** Total width of the wheel (also counts for the height) */
  365. var w = 900,
  366. h = w,
  367. r = w / 2,
  368. /** x/y positionning of the center of the wheel */
  369. x = d3.scale.linear().range([0, 2 * Math.PI]),
  370. y = d3.scale.pow().exponent(1.1).domain([0, 1]).range([0, r]),
  371. /** Padding in pixels before the string starts */
  372. padding = 3,
  373. /** Levels to show */
  374. levels_to_show = 3;
  375. reduce_top = 1;
  376. /* Locate the #div id element */
  377. $("#skill_wheel").remove();
  378. $("#wheel_container").html('');
  379. $("#wheel_container").append('<div id="skill_wheel"></div>');
  380. var div = d3.select("#skill_wheel");
  381. /* Remove the image (make way for the dynamic stuff */
  382. div.select("img").remove();
  383. /* Append an element "svg" to the #vis section */
  384. var vis = div.append("svg")
  385. //.attr("class", "Blues")
  386. .attr("width", w + padding * 2)
  387. .attr("height", h + padding * 2)
  388. .append("g")
  389. .attr("transform", "translate(" + (r + padding) + "," + (r/reduce_top + padding) + ")");
  390. /* ...update translate variables to change coordinates of wheel's center */
  391. /* Add a small label to help the user */
  392. div.append("p")
  393. .attr("id", "intro")
  394. .text("{{ "ClickToZoom"|get_lang }}");
  395. /* Generate the partition layout */
  396. var partition = d3.layout.partition()
  397. .sort(null)
  398. /** Value here seems to be a calculation of the size of the elements
  399. depending on the level of depth they're at. Changing it makes
  400. elements pass over the limits of others... */
  401. //.size([1, 2])
  402. .value(function(d) {
  403. //return 5.8 - d.depth;
  404. //When having more than 4 children seems that the code above does not work
  405. return 1;
  406. });
  407. /* Generate an arc which will define the whole wheel context */
  408. var arc = d3.svg.arc()
  409. .startAngle(function(d) {
  410. return Math.max(0, Math.min(2 * Math.PI, x(d.x)));
  411. })
  412. .endAngle(function(d) {
  413. return Math.max(0, Math.min(2 * Math.PI, x(d.x + d.dx)));
  414. })
  415. .innerRadius(function(d) {
  416. return Math.max(0, d.y ? y(d.y) : d.y);
  417. })
  418. .outerRadius(function(d) {
  419. return Math.max(0, y(d.y + d.dy));
  420. });
  421. load_skill_condition = '';
  422. //First the $_GET value
  423. if (skill_to_load_from_get != 0) {
  424. load_skill_condition = 'skill_id=' + skill_to_load_from_get;
  425. }
  426. //The JS load
  427. if (load_skill_id != 0) {
  428. load_skill_condition = 'skill_id=' + load_skill_id;
  429. }
  430. d3.json("{{ wheel_url }}&main_depth="+main_depth+"&"+load_skill_condition, function(json) {
  431. /** Define the list of nodes based on the JSON */
  432. var nodes = partition.nodes({
  433. children: json
  434. });
  435. /* Setting all skills */
  436. var path = vis.selectAll("path").data(nodes);
  437. /* Setting all texts */
  438. var text = vis.selectAll("text").data(nodes);
  439. /* Setting icons */
  440. var icon = vis.selectAll("icon").data(nodes);
  441. /* Path settings */
  442. path.enter().append("path")
  443. .attr("id", function(d, i) {
  444. return "path-" + i;
  445. })
  446. .attr("d", arc)
  447. .attr("fill-rule", "evenodd")
  448. .attr("class", "skill_partition skill_background")
  449. // .style("fill", colour)
  450. .style("fill", function(d) {
  451. return set_skill_style(d, 'fill', load_skill_id);
  452. })
  453. .style("stroke", function(d) {
  454. return set_skill_style(d, 'stroke');
  455. })
  456. .on("mouseover", function(d, i) {
  457. //$("#icon-" + i).show();
  458. })
  459. .on("mouseout", function(d, i) {
  460. //$("#icon-" + i).hide();
  461. })
  462. .on("contextmenu", function(d, i) {
  463. //Handles mouse clicks
  464. handle_mousedown_event(d, path, text, icon, arc, x, y, r, padding, vis);
  465. //Blocks "right click menu"
  466. d3.event.preventDefault();
  467. return false;
  468. })
  469. .on("mousedown", function(d, i) {
  470. })
  471. .on("click", function(d) {
  472. //Simple click
  473. handle_mousedown_event(d, path, text, icon, arc, x, y, r, padding, vis);
  474. });
  475. /*//Redefine the root
  476. path_zero = vis.selectAll("#path-0").on("mousedown", function(d){
  477. d = get_skill_info(extra_parent_id);
  478. d.parent_id = d.extra.parent_id;
  479. click_partition(d, path, text, icon, arc, x, y, r, padding, vis);
  480. });*/
  481. /* End setting skills */
  482. /* Text settings */
  483. var textEnter = text.enter().append("text")
  484. .style("fill-opacity", 1)
  485. .style("fill", function(d) {
  486. return brightness(d3.rgb(d.color)) < 125 ? "#eee" : "#000";
  487. })
  488. .attr("text-anchor", function(d) {
  489. return x(d.x + d.dx / 2) > Math.PI ? "end" : "start";
  490. })
  491. .attr("rel", "tooltip_skill")
  492. .attr("title", function(d) {
  493. return d.name;
  494. })
  495. .attr("dy", ".2em")
  496. .attr("transform", function(d) {
  497. /** Get the text details and define the rotation and general position */
  498. var multiline = is_multiline(d.name); //(d.name || "").split(" ").length > 1,
  499. angle = x(d.x + d.dx / 2) * 180 / Math.PI - 90,
  500. rotate = angle + (multiline ? -.5 : 0);
  501. return "rotate(" + rotate + ")translate(" + (y(d.y) + padding) + ")rotate(" + (angle > 90 ? -180 : 0) + ")";
  502. })
  503. .on("mouseover", function(d, i) {
  504. //$("#icon-" + i).show();
  505. })
  506. .on("mouseout", function(d, i) {
  507. //$("#icon-" + i).hide();
  508. })
  509. .on("contextmenu", function(d, i) {
  510. handle_mousedown_event(d, path, text, icon, arc, x, y, r, padding, vis);
  511. d3.event.preventDefault();
  512. })
  513. .on("mousedown", function(d, i) {
  514. })
  515. .on("click", function(d) {
  516. handle_mousedown_event(d, path, text, icon, arc, x, y, r, padding, vis);
  517. });
  518. /** Managing text - maximum two words */
  519. textEnter.append("tspan")
  520. .attr("x", 0)
  521. .text(function(d) {
  522. if (d.short_code) {
  523. return d.short_code;
  524. }
  525. if (d.depth && d.name) {
  526. var nameParts = d.name.split(' ');
  527. if (nameParts[0].length > max_size_text_length) {
  528. return nameParts[0].substring(0, max_size_text_length - 3) + '...';
  529. }
  530. return nameParts[0];
  531. }
  532. return d.depth ? d.name : '';
  533. });
  534. textEnter.append("tspan")
  535. .attr("x", 0)
  536. .attr("dy", "1em")
  537. .text(function(d) {
  538. if (d.short_code) {
  539. return null;
  540. }
  541. if (d.depth && d.name) {
  542. var nameParts = d.name.split(' ');
  543. if (nameParts.length >= 2) {
  544. if (nameParts[1].length > max_size_text_length) {
  545. return nameParts[1].substring(0, max_size_text_length - 3) + '...';
  546. }
  547. return nameParts[1];
  548. }
  549. return '';
  550. }
  551. return d.depth ? d.name : '';
  552. });
  553. /* Icon settings */
  554. /*
  555. var icon_click = icon.enter().append("text")
  556. .style("fill-opacity", 1)
  557. .style("fill", function(d) {
  558. //return "#000";
  559. })
  560. .attr("text-anchor", function(d) {
  561. return x(d.x + d.dx / 2) > Math.PI ? "end" : "start";
  562. })
  563. .attr("dy", ".2em")
  564. .attr("transform", function(d) {
  565. ///Get the text details and define the rotation and general position
  566. angle = x(d.x + d.dx / 2) * 180 / Math.PI - 90,
  567. rotate = angle;
  568. return "rotate(" + rotate + ")translate(" + (y(d.y) + padding +80) + ")rotate(" + (angle > 90 ? -180 : 0) + ")";
  569. })
  570. .on("click", function(d){
  571. SkillWheel.showFormSkill(d.id);
  572. });
  573. icon_click.append("tspan")
  574. .attr("id", function(d, i) {
  575. return "icon-" + i;
  576. })
  577. .attr("x", 0)
  578. .attr("display", 'none')
  579. .text(function(d) {
  580. //return "Click";
  581. });*/
  582. });
  583. if (debug) {
  584. console.log('<------ End load nodes ----->');
  585. }
  586. }
  587. /* Skill AJAX calls */
  588. function get_skill_info(my_id) {
  589. var skill = false;
  590. $.ajax({
  591. url: url+'&a=get_skill_info&id='+my_id,
  592. async: false,
  593. success: function(json) {
  594. skill = jQuery.parseJSON(json);
  595. return skill;
  596. }
  597. });
  598. return skill;
  599. }
  600. function get_gradebook_info(id) {
  601. var item = false;
  602. $.ajax({
  603. url: url+'&a=get_gradebook_info&id='+id,
  604. async: false,
  605. success: function(json) {
  606. item = jQuery.parseJSON(json);
  607. return item;
  608. }
  609. });
  610. return item;
  611. }
  612. </script>