simulator.js 65.4 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755
/*!
 * jQuery simulator plugin
 * version 2.4.2
 * Copyright 2014, IBISC University Evry Val d'Essonne, dev by Jean-Baptiste Munieres
 *
 */

//TOTEST :S => Success, B => Bug, N => Non tested, R => new version retry all test
/*

1er jet de test => trace only:

    Faire des successions d'etat : S
    Revenir dans la trace : S
    Ecraser la trace pour une nouvelle : S => probleme avec le off(click **)
    Revenir Init : S
    Revenir a la Fin : S
    Repartir de la fin pour continuer la trace : S
    Lancer le player : S
    Stoper le player en cours : S
    Stop et Play succesivement : S
    Accelerer la vitesse : S
    Baisser la vitesse : S
    Faire en play milieu de la trace : S
    Test l'aide : N
    Test Stop simulation : R
    Test Reset simulation : S
    
2eme jeu de test => graph & trace:
    
    A faire dans le graph :

        Faire des successions d'etat : S
        Revenir dans la trace : S
        Ecraser la trace pour une nouvelle : S
        Lancer le player : S
        Stoper le player en cours : S
        Stop et Play succesivement : S
        Accelerer la vitesse : S
        Baisser la vitesse : S
        Faire en play milieu de la trace : S
        Test Reset simulation : S
        
        Decocher la case pour afficher toutes les variables : S
        Decocher les variables une par une : S
        Cocher la case pour afficher toutes les variables : S
        Cocher les variables une par une : S
        
        Afficher les tooltips depuis l'axe des x : S
        Afficher un tooltip depuis un point : S
        
    A faire dans la trace avec nouvelle version :
        Tester tout dans 1er jeu
        
        Changer le debut de l'interval : S
        Avec un debut d'interval modifier :
            Faire des succesions d'etat : S
            Ecraser la trace pour une nouvelle : S
            Changer la fin de trace : S
            Impossibilite d'avoir fin < debut : S
            Revenir direct a la fin depuis le graphe : S
            Choisir le debut sur la trace & fin sur le graph : S
            
        Groups
            Decocher la case qui active toutes les transitions : S
            Decocher les transitions un par un : S
            Cocher la case qui active toutes les transitions : S
            Cocher les transitions une par une : S
            
            Refaire ce qu'il y a plus haut avec en plus :
                Changer l'interval : S S S S
*/

(function($) {
    
    //Plugin for function who need object
    //Ne pas rebind plusieur fois sur le meme objet sous peine de gros lag
    jQuery.fn.simisc = function(option, callback){
        
        /**
         *  @description Add attribute and click handler for get_state
         *  @param {Integer} key  The state number to get
         *  @param {Integer} instance_key The key for get the data (only for next version (3.0))
         */
        $.fn.get_attr_link = function(key, instance_key) {
            console.log("get_attr_link")
            $(this).attr({"data-num": key})
            $(this).on("click",get_trace)
        }
        
        /**
         *  @description Add attributes and click handler for set_state
         *  @param {Integer} value  Dictionnary for set a new state : { action : String, state : Integer, mode : Integer  }
         *  @param {Integer} instance_key The key for get the data (only for next version (3.0))
         */
        $.fn.set_attr_link = function(value, instance_key){
            console.log("set_attr_link")
            $(this).attr({"data-action": value.action , "data-state" : value.state, "data-mode" : value.mode, "data-groups" : value.groups})
            $(this).on("click",set_trace)
        }
        
        /**
         * @description @see $.fn.set_attr_link
         */
        function set_trace(object, instance_key) {
            $.simisc.set_trace(this, instance_key );
        }
        
        /**
         * @description @see $.fn.get_attr_link
         */
        function get_trace(object, instance_key) {
            $.simisc.get_trace(this, instance_key );
        }
        
        //Remove all handler on object (optimise for just delete the handler of click)
        $(this).off()
            
        //Reset the attributes for object
        $(this).removeAttr("data-num data-action data-mode data-state")
        
        return $(this)
    }
    
    //Plugin principal
    jQuery.simisc = function (options, callback) {
    
        // if the first argument is a function then assume the options aren't being passed
        if (jQuery.isFunction(options)) {
            callback = options;
            options = {};
        }
        else{
        
            // Merge passed settings with default values
            $.simisc.instance.push($.extend(true, {}, $.simisc.defaults, options));
        
            //For version 3.0 with multiple simulator in same page
            var instance_key = $.simisc.instance.length-1,
            settings = $.extend(true, {}, $.simisc.defaults, options),
            //Contains all the history
            _history,
            _data,
            //Contains the current state num for user
            _clk_end,
            //Contains the begin state
            _clk_begin,
            //Current trace
            _trace,
            //Current modes
            _modes,
            //Current variables
            _variables,
            //Current groups to see
            _groups,
            //True if we look into the history
            _isHistory,
            //Contain all variables for graph
            _graph = {},
            //variables for player
            _record = {
                "speed":1,
                "max_speed":16,
                "play": false
            },
            //Function can be call by simulator
            update = {
                settext : function (action) {
                    $(action.select).text(action.text);
                },
                sethtml : function (action) {
                    $(action.select).html(action.html);
                },
                clear : function (action) {
                    $(action.select).html("");
                },
                setlist : function (action) {
                    ul = $(action.select);
                    ul.html("");
                    $.each(action.items, function (num, item) {
                        ul.append("<li>" + item + "</li>");
                    });
                },
                dropclass : function (action) {
                    $(action.select).removeClass(action.class);
                },
                addclass : function (action) {
                    $(action.select).addClass(action.class);
                }
            };
            //Init all the simulator
            init();
        }
        
        /**
         *  @description Function for create/add the player to the view
         */
        function init_player() {
            console.log("init player")
            div = document.createElement("div")
            
            div_gauche = document.createElement("div")
            div_bouton = document.createElement("div")
            
            span = document.createElement("span")
            input = document.createElement("input")
            
            div_droite = document.createElement("div")
            span = document.createElement("span")
            
            $(div).attr({
                "class": "input-group col-md-12",
                "id": "frames"
            });
            
            $(div_bouton).attr({
                "class": "btn-group"
            })
            
            //Left part of player
            span = document.createElement("span")
            $(span).addClass("glyphicon glyphicon-play")
            
            bouton_play = document.createElement("div")
            $(bouton_play).attr({
                    "id": "simisc_play",
                    "type": "button",
                    "class": "btn btn-default",
                })
                .tooltip({
                    title: "Launch the player",
                    trigger: "hover",
                    placement: "top",
                    delay: { show: 500, hide: 100 }
                })
                .append(span)
                .click(function(){
                    play(this)
                })
                
            
            span = document.createElement("span")
            $(span).addClass("glyphicon glyphicon-stop")
            
            bouton_stop = document.createElement("div")
            $(bouton_stop).attr({
                    "id": "simisc_stop",
                    "type": "button",
                    "class": "btn btn-default",
                    "style": "display:none;"
                })
                .tooltip({
                    title: "Stop the player",
                    trigger: "hover",
                    placement: "top",
                    delay: { show: 500, hide: 100 }
                })
                .append(span)
                .click(function(){
                    stop(this)
                })
            
            $(div_gauche).attr({
                "class": "input-group-btn",
                "id": "simisc_left_player"
                })
                .append([bouton_play, bouton_stop])
            
            //Input in middle
            $(input).attr({
                "value": 10,
                "type": "text",
                "class": "form-control"
            });
            
            
            //Right part of player
            span = document.createElement("span")
            $(span).addClass("glyphicon glyphicon-minus-sign")
            
            bouton_moins = document.createElement("div")
            $(bouton_moins).attr({
                "id": "simisc_down",
                "type": "button",
                "class": "btn btn-default"
                })
                .tooltip({
                    title: "Click for down the speed per tick",
                    trigger: "hover",
                    placement: "top",
                    delay: { show: 500, hide: 100 }
                })
                .append(span)
                .click(function(){
                    down_speed()
                })
                
            
            span = document.createElement("span")
            $(span).addClass("glyphicon glyphicon-plus-sign")
            
            bouton_plus = document.createElement("div")
            $(bouton_plus).attr({
                "id": "simisc_up",
                "type": "button",
                "class": "btn btn-default"
                })
                .tooltip({
                    title: "Click for up the speed per tick",
                    trigger: "hover",
                    placement: "top",
                    delay: { show: 500, hide: 100 }
                })
                .append(span)
                .click(function(){
                    up_speed()
                })
            
            $(div_droite).attr({
                "class": "input-group-btn"
                })
                .append([bouton_moins, bouton_plus])
            
            span = document.createElement("span")
            $(span).attr({
                "class": "input-group-addon",
                "style": "width:56px;text-align:left"
            })
            
            
            $(div).append([div_gauche, input, span, div_droite])
            
            $(settings.player.id).append(div);
            set_speed();
            
            create_modal(settings.player.modal)
                        
            $(settings.player.modal.id + " .btn-primary").on("click",function(){
                    play(this, true)
            })
        }
        
        /**
         *  @description Launch the player
         */
        function play(object, force){
            console.log("play");
            
            //If we are in history, we ask the conform to delete trace
            if(force != true && _clk_end < _history.trace.length-1){
                $(settings.player.modal.id).modal();
            }
            else{
                _record.play = true;
                
                _record.begin_frame = _clk_end
                _record.end_frame = _clk_end + parseInt($("#frames input").val(),10);
                
                //Hide all and show stop
                $(settings.player.id + " #simisc_play").hide().appendTo("#simisc_left_player");
                $(settings.player.id + " #simisc_stop").show();
                
                //Disabled up & down
                $(settings.player.id + " #simisc_up").attr("disabled","");
                $(settings.player.id + " #simisc_down").attr("disabled","");
                if (_clk_end < _history.trace.length-1) {
                    cut_trace(0,_clk_end+1)
                }
                _isHistory = false;
                
                $.periodic({period: _record.speed * 1000, decay:1, max_period: _record.speed * 1000}, function() {
                    this.cur_period = _record.speed * 1000;
                    this.max_period = _record.speed * 1000;
        
                    //If there is no more modes to run we stop the player
                    if (!_history.modes[_clk_end] || _history.modes[_clk_end].length == 0){
                        stop(object);
                        this.cancel();
                    }
                    else{
                        _record.begin_frame++;
            
                        rdn = Math.floor((Math.random()*_history.modes[_clk_end].length));
                        
                        //Create the fake object a for force an set_trace with rdn mode
                        a = document.createElement("a");
                        
                        $(a).simisc().set_attr_link(_history.modes[_clk_end][rdn], instance_key);
                        $(a).html($(a).attr("data-action"))
                        
                        //If stop is push we stop
                        if (_record.play == false || _record.begin_frame == _record.end_frame){
                            stop(object);
                            this.cancel();
                        }
                        
                        //GO to the new state
                        $.simisc.set_trace($(a));                        
                    }
                });
            }
        }

        /**
         *  @description Stop the player
         */
        function stop(object){
            console.log("stop");
            _record.play = false;
            //Hide all and show stop
            $(settings.player.id + " #simisc_play").show();
            $(settings.player.id + " #simisc_stop").hide().appendTo("#simisc_left_player");
            
            //Disabled up & down
            $(settings.player.id + " #simisc_up").removeAttr("disabled");
            $(settings.player.id + " #simisc_down").removeAttr("disabled");
        }
        
        /**
         *  @description Down the speed between each ticks
         */
        function down_speed(){
            console.log("down speed");
            _record.speed = Math.min(_record.max_speed,_record.speed * 2);
            set_speed();
        }
        
        /**
         *  @description Up the speed between each ticks
         */
        function up_speed(){
            console.log("up_speed");
            _record.speed = Math.max(1/_record.max_speed,_record.speed / 2);
            set_speed();
        }

        //TODO : afficher le speed avec une fraction => moins rapide = 1/16 plus rapide 16
        /**
         *  @description Set the speed in variable and in view
         */
        function set_speed(){
            console.log("set_speed")
            
            text = "16"
            
            switch (_record.speed) {
                case 8 : ;
                case 4 : ;
                case 2 : ;
                case 1 : text = _record.speed; break;
                case 0.5 : text = "<sup>1</sup>/<sub>2</sub>"; break;
                case 0.25 : text = "<sup>1</sup>/<sub>4</sub>"; break;
                case 0.125 : text = "<sup>1</sup>/<sub>8</sub>"; break;
                case 0.0625 : text = "<sup>1</sup>/<sub>16</sub>"; break;
            }
            
            $("#frames .input-group-addon").html("&times;" + text)
        }
      
        /**
         *  @description Init the trace, by creating the table, who will contain all history
         */
        function init_trace(){
            table = document.createElement("table")
            thead = document.createElement("thead")
            tbody = document.createElement("tbody")
            tr = document.createElement("tr")
            
            $(table).addClass("table table-hover")
            
            th = document.createElement("th")
            $(th).addClass("col-md-1")
                .html("#")
            $(tr).append(th)
            
            th = document.createElement("th")
            $(th).html("Action")
            $(tr).append(th)
            
            th = document.createElement("th")
            $(th).html("Modes")
            $(tr).append(th)
            
            th = document.createElement("th")
            $(th).html("States")
            $(tr).append(th)
            
            if (settings.graph.groups === true) {
                th = document.createElement("th")
                $(th).html("Groups")
                $(tr).append(th)
            }
            
            
            th = document.createElement("th")
            $(th).addClass("col-md-1")
            $(tr).append(th)
            
            if (settings.graph.interval) {
                th = document.createElement("th")
                $(th).addClass("col-md-1")
                $(tr).append(th)
            }
            
            $(tbody).attr("id","simisc_trace")
            
            $(thead).append(tr)
            $(table).append(thead,tbody)
            
            $(settings.trace.id).append(table)
        }
        
        /**
         *  @description Init all variables
         */
        function init_vars(){
            //Load initial state
            _trace = {
                "action": settings.init.action,
                "mode": settings.init.mode,
                "state": settings.init.state,
            }
            _isHistory = false
            _history = {
                "trace": new Array(_trace),
                "modes": new Array(),
                "variables": new Array(),
                "data": new Array()
            }
            _clk_end = 0;
            _clk_begin = 0;
            _variables = {}
        }
        
        /**
         *  @description Init the helper
         *  @param {Dict} helper Contain a dictionnary with all content for help, cf bootstrap / popover for the dictionary syntaxe
         */
        function init_help(helper){
            console.log("init_help")
            //console.log(helper)
            $.each(helper, function(key, value){
                value = $.extend({
                    "placement":"auto",
                    "trigger": "manual"
            
                }, value);
                //console.log(value);
                $(key).popover(value);
                $(key).addClass("help-ui");
                $(key).click(function(event){
                    event.stopImmediatePropagation();
                });
            });
        }
        
        /**
         *  @description Init the graph using D3.js
         *  @param {Dict<String:Integer>} variables Contains a dictionnary with couples name value
         */
        function init_graph(variables,groups) {
            console.log("init graph variables")
            _graph.variables = new Array();
            _graph.groups = new Array();
        
            if(!settings.graph.color)
                settings.graph.color = {}
        
            for(key in groups){
                _graph.groups.push(groups[key])
            }
            
            _groups = _graph.groups
            _groups.push("others")
        
            for(key in variables){
                _graph.variables.push(key)
        
                if(!(key in settings.graph.color))
                    settings.graph.color[key] = "pink"
            }
            
            console.log(_graph.groups)
            console.log("init graph")
            
            $.extend(true, variables, {"transition": settings.init.action, "groups": settings.init.groups})
            
            set_history(_clk_end, {"variables":variables})
            
            var max = [0]
            _data = _history.variables
            
            if (_clk_end == _clk_begin) {
                _data.push(_data[0])
            }
            
            //Init the marge & width of graph
            _graph.margin = {top: 30, right: 20, bottom: 200, left: 40},
            _graph.width = $(settings.graph.id).width() - _graph.margin.left - _graph.margin.right,
            _graph.height = 150 - _graph.margin.top + _graph.margin.bottom;
        
            
            _graph.x = d3.scale.linear().range([0, _graph.width]);
        
            _graph.y = d3.scale.linear().range([_graph.height, 0]);
            
            //We create the x axis
            _graph.xAxis = d3.svg.axis().scale(_graph.x)
                .orient("bottom")
                .tickFormat(function(d,i){
                    //We take only the integer part & return the transition cross
                    if(parseFloat(d,10) == parseInt(d,10)){
                        if (_clk_end == _clk_begin && d == 1) {
                            return ""
                        }
                        return _data[d]['transition']
                    }
                    return ''
                });
        
            //We create the y axis
            _graph.yAxis = d3.svg.axis().scale(_graph.y)
                .orient("left").ticks(5);
        
            //Reset the zone if user write element on it (dumbproof)
            $(settings.graph.id).html("")
        
            //Add the table with variable
            init_control_command()
                
            //Add the graph
            _graph.svg = d3.select(settings.graph.id)
                .append("svg")
                .attr("width", _graph.width + _graph.margin.left + _graph.margin.right)
                .attr("height", _graph.height + _graph.margin.top + _graph.margin.bottom)
                .append("g")
                .attr("transform", "translate(" + _graph.margin.left + "," + _graph.margin.top + ")");
        
            //Contains the lines for each variable
            _graph.line = []
        
            _graph.x.domain([0,1]);
            
            //Create the x axis in view
            _graph.svg.append("g")
                .attr("class", "x axis")
                .attr("transform", "translate(0," + _graph.height + ")")
                .call(_graph.xAxis);
            
            //Create the y axis in view
            _graph.svg.append("g")
                .attr("class", "y axis")
                .call(_graph.yAxis);
        
            _graph.variables.forEach(function(v){
                _graph.line[v] = d3.svg.line()
                    .interpolate("step-after")
                    .x(function(d,i) {
                        return _graph.x(i);
                    })
                    .y(function(d) {
                        return _graph.y(d[v]);
                    })
        
                max.push(d3.max(_data, function(d) { return d[v]; }));
        
                _graph.svg.append("path")
                    .attr("class", "line line-" + v)
                    .attr("var",v)
                    .attr("d", _graph.line[v](_data))
                    .attr("style","cursor:pointer;")
                    .style("stroke", settings.graph.color[v])
        
            });
            //TODO : quand on clique trop vite dans le tableau : les points apparaissent
        
            _graph.y.domain([0, d3.max(max, function(d) { return d; })])
        }
        
        //TOREDO parce que D3 pour du tableau c'est moyen
        /**
         *  @description Init the control command for variable, with the tab pannel for (un)select variables and change the interval of visualisation
         */
        function init_control_command() {
            console.log("init_control_command")
            //We add the table on the zone for graph (it's better when call first)
            _graph.table = d3.select(settings.graph.control_panel)
                .append("table")
                .attr("class","table table-bordered table_var")
        
            //ADD variable
            _graph.thead = _graph.table.append("thead")
            
            _graph.tbody = _graph.table.append("tbody")
            
            // append the header row
            _graph.thead.append("tr")
                .selectAll("th")
                //Tab for thead
                .data(["vars","<input class='check_all_vars' type='checkbox' checked />"])
                .enter()
                .append("th")
                .attr("class","active")
                .html(function(column) {
                    console.log(column)
                    return column;
            });
        
            var tab_var = []
         
            _graph.variables.forEach(function(d){
                tab_var.push([d, "<input class='check_var' type='checkbox' checked var='" + d + "' />"])
            })
            
            // create a row for each object in the data
            _graph.rows = _graph.tbody.selectAll("tr")
                .data(tab_var)
                .enter()
                .append("tr");
        
            // create a cell in each row for each column
            _graph.cells = _graph.rows.selectAll("td")
                .data(function(row) {
                    return ([0,1]).map(function(column) {
                        console.log(column)
                        return {column: column, value: row[column]};
                    });
                })
                .enter()
                .append("td")
                .attr("style", "font-family: Courier")
                .html(function(d) { return d.value; });
                
            if (settings.graph.groups) {
                _graph.thead_groups = _graph.table.append("thead")
            
                _graph.tbody_groups = _graph.table.append("tbody")
                
                // append the header row
                _graph.thead_groups.append("tr")
                    .selectAll("th")
                    //Tab for thead
                    .data(["groups","<input class='check_all_groups' type='checkbox' checked />"])
                    .enter()
                    .append("th")
                    .attr("class","active")
                    .html(function(column) {
                        return column;
                });
                    
                var tab_groups = []
         
                _graph.groups.forEach(function(d){
                    tab_groups.push([d, "<input class='check_group' type='checkbox' checked group='" + d + "' />"])
                });
                
                // create a row for each object in the data
                _graph.rows_groups = _graph.tbody_groups.selectAll("tr")
                    .data(tab_groups)
                    .enter()
                    .append("tr");
            
                // create a cell in each row for each column
                _graph.cells_groups = _graph.rows_groups.selectAll("td")
                    .data(function(row) {
                        return ([0,1]).map(function(column) {
                            return {column: column, value: row[column]};
                        });
                    })
                    .enter()
                    .append("td")
                    .attr("style", "font-family: Courier")
                    .html(function(d) { return d.value; });
                    
                 $('.check_all_groups').click(function(){
                    if ($(this).is(":checked")) {
                        $('.check_group').prop("checked", true);
                        _groups = _graph.groups
                        toggle_path("",true)
                    }
                    else{
                        $('.check_group').prop("checked", false);
                        _groups = Array()
                        fade_path("",true)
                    }
                })
                 
                $('.check_group').click(function(){
                    var _group = $(this).attr("group")
                    if ($(this).is(":checked")) {
                        if ( $(".check_group:checked").length == $(".check_group").length){
                            $('.check_all_groups').prop("checked", true);
                        }
                        _groups.push(_group)
                        toggle_path("",true)
                        
                    }
                    else{
                        $('.check_all_groups').prop("checked", false);
                        _groups = Array()
                        
                        $(".check_group:checked").each(function(){
                            _groups.push($(this).attr("group"))
                        })
                        
                        if ( $(".check_group:checked").length == 0){
                            fade_path("",true)
                        }
                        else{
                            print_option();
                        }                        
                    }
                    
                })
            }
            
            if (settings.graph.interval) {
                _graph.thead_interval = _graph.table.append("thead")
                _graph.tbody_interval = _graph.table.append("tbody")
                
                _graph.thead_interval.append("tr")
                    .selectAll("th")
                    .data(["Interval","<a id='reset_interval'> Reset</a>"])
                    .enter()
                    .append("th")
                    .attr("class","active")
                    .html(function(column) {
                        console.log(column)
                        return column;
                    })
                    
                _graph.rows_interval = _graph.tbody_interval.selectAll("tr")
                    .data([["Begin","<input id='begin_interval' class='form-control  col-md-3' type='number' value='0' />"],["End","<input id='end_interval' class='form-control col-md-3' type='number' value='0' />"]])
                    .enter()
                    .append("tr");
                    
                _graph.cells_interval = _graph.rows_interval.selectAll("td")
                .data(function(row) {
                    return ([0,1]).map(function(column) {
                        console.log(column)
                        return {column: column, value: row[column]};
                    });
                })
                .enter()
                .append("td")
                .attr("style", "font-family: Courier")
                .html(function(d) { return d.value; });
                
                $("#reset_interval").on("click", function(){
                    change_begin(0)
                }).get_attr_link(0, instance_key)
                
               
                $("#begin_interval").on("change",function(){
                    val = parseInt($(this).val(),10)
                    if (val != _clk_begin) {
                        if (val > _clk_end) {
                            val = _clk_end
                        }
                        else if(val < 0){
                            val = 0
                        }
                        change_begin(val)
                    }
                })
                
                $("#end_interval").get_attr_link(0, instance_key)
                
                $("#end_interval").on("change",function(){
                    val = parseInt($(this).val(),10)
                    if(val != _clk_end){
                        if (val < _clk_begin) {
                            val = _clk_begin
                        }
                        else if (val >= _history.trace.length) {
                            val = _history.trace.length-1
                        }
                        $(this).attr("data-num",val)
                        $.simisc.get_trace($(this));                   
                    }
                })
                
            }
            
             
            //Check all is the checkbox on thead, you can affich/desable all variables
            $('.check_all_vars').click(function(){
                if ($(this).is(":checked")) {
                    $('.check_var').prop("checked", true);
                    toggle_path("",true)
                }
                else{
                    $('.check_var').prop("checked", false);
                    fade_path("",true)
                }
            })
            
           
                
            //For fade or toggle variable one per one
            $('.check_var').click(function(){
                var _var = $(this).attr("var")
                if ($(this).is(":checked")) {
                    if ( $(".check_var:checked").length == $(".check_var").length){
                        $('.check_all_vars').prop("checked", true);
                    }
                    toggle_path($(this).attr("var"),false)
                }
                else{
                    $('.check_all_vars').prop("checked", false);
                    fade_path($(this).attr("var"),false)
                }
            })
        }
      
        /**
         *  @description Change the begin in graph visualisation
         */
        function change_begin(num) {
            _clk_begin = num
            print_option()
            update_command_center()
        }
        
        /**
         * @description Create a Bootstrap modal with custom id, title, text & button primary text
         * @param {Dict} modal Dict with id, title, text, button_text for modal
         */
        function create_modal(modal){            
            $("body").append('<div class="modal fade" id="' + modal.id.substring(1) + '"><div class="modal-dialog"><div class="modal-content"><div class="modal-header"><button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times</button><h4 class="modal-title">' + modal.title + '</h4></div><div class="modal-body"><p>' + modal.text + '</p></div><div class="modal-footer"><button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button> <button type="button" class="btn btn-primary" data-dismiss="modal">' + modal.button + '</button></div></div>')
        }

        function get_server(action){
            if(settings.api.server == ""){
                return action
            }
            else{
                return settings.api.server
            }
        }
        
        function get_param_server(func, dict){
            if(settings.api.server == ""){
                return [func, dict]
            }
            else{
                $.extend(dict, {token: settings.api.token, method : "POST", function : action})
                return [settings.api.server, dict]
            }
        }
        
        /**
         *  @description Init the simulator
         */
        function init(){
            console.log("init simulator")
            
            init_vars();
            init_player();
            
            create_modal(settings.api.modal)
            
            if (settings.trace.activate) {
                init_trace();
            }

            
            params = get_param_server(settings.init.action, {state: settings.init.state})
            $.get(params[0], params[1],function(data){
                console.log(typeof(data))
                if (data.help)
                    init_help(data.help)

                console.log(_variables)
        
                set_modes(data.state);
                
                apply_trace(data.state);
                
                if (settings.graph.activate && data.state.variables && typeof(settings.graph) == typeof({}))
                    init_graph(data.state.variables, data.state.groups)
                
                print_option();
            });
            
            //add click event
            $(settings.api.quit).click(function() {
                console.log("quit");
                params = get_param_server("quit", {})
                $.get(params[0], params[1],function(data){
                    $("#alive .ui").html("").text(data);
                    window.location.reload();
                });
            });
            
            //add reset event
            $(settings.api.reset).click(function() {
                reset(instance_key)
            });
            
            $(settings.api.help).click(function(){
                console.log("change trigger");
                //We disabled the help
                if($(".help-ui").hasClass("help-activate")){
                    $(this).parent().removeClass("active");
                    $(".help-ui").removeClass("help-activate");
                    $(".help-ui").off( "mouseenter mouseleave" );
                }
                else{
                    $(this).parent().addClass("active");
                    $(".help-ui").addClass("help-activate");
                    $(".help-activate").hover(function(){
                        $(this).popover("show"); 
                        $(this).addClass("highlight_help")
                        event.stopImmediatePropagation();
                    },function(){
                        $(this).popover("hide"); 
                        $(this).removeClass("highlight_help")
                        event.stopImmediatePropagation();
                    });
                }
            });
            
            //add ping
            if (settings.api.token == ""){
                
                $("#alive .ping").text("Stayin alive!");
                $.periodic({period: 10000, decay:1, max_period: 10000}, function() {
                    params = get_param_server("ping", {})
                    $.get(params[0], params[1],function(data){
                        $(".ping").text(data);
                    });
                });
            }
            
            ul = $(settings.api.nav)
            
            $.each(settings.nav, function(key, value){
                li = document.createElement("li");
                a = document.createElement("a");                
        
                $(a).html(value.text);
                $(a).attr("href","#");
        
                $.each(value.attr, function(key, value){
                   $(a).attr(key,value);
                });
        
                $(li).append(a);
                $(ul).append(li);
            });
        }
        
        /**
         *  @description Add a trace to the history
         *  @param {Integer} key Contains the id where the trace will be set in history
         *  @param {Dict} trace  Contains all part to add at history, at max we use { trace: , modes: , variables: , data:}
         */
        function set_history(key, trace) {
            console.log("set_history")
            console.log(key)
            console.log(trace)
            $.each(trace, function(k,v){
                _history[k][key] = v
            })
            
        }
        
        /**
         *  @description Set modes to the history and to the view, like get_modes with update modes in history
         *  @param {Dict} data Contains all data for get states & modes
         */
        function set_modes(data){
            console.log("set_modes")
            
            //We have possibilité to do function in each state
            $.each(data.states, function (num, item) {
                update[item.do](item);
            });
            
            //New modes
            _modes = new Array();
        
            //For each modes & action, we create a list of modes
            $.each(data.modes, function(num, action){
                div = $(action.select);
                div.html("");
                
                div_group = document.createElement("div")
                
                $(div_group).addClass("btn-group-vertical")
        
        
                $.each(action.items, function (pos, item) {
                    button = document.createElement("button");
                    
                    newtrace = {
                        action : item.html,
                        mode : item.mode,
                        state : item.state,
                        groups : item.groups
                    };
                    
                    //We create the link for get the succ of this state
                    $(button).html(item.html)
                        .attr({
                            type: "button",
                            class: "btn btn-default"
                        })
                        
                    $(button).simisc().set_attr_link(newtrace, instance_key)
        
                    _modes.push(newtrace)
        
                    $(div_group).append(button);
                });
                
                $(div).append(div_group)
            });
        }
        
        /**
         *  @description Set modes to the history and to the view, like set_modes without update modes in history
         *  @param {Dict} data Contains all data for get states & modes
         */
        function get_modes(data) {
            console.log("get_modes")
            set_modes(data)
        }
        
        /**
         *  @description Reset the player to initial state, without call init
         */
        function reset(key){
            console.log("reset")
            _isHistory = false
            _clk_end = 0;
            _clk_begin = 0;
            cut_trace(0,1);
            
            //We get the data without pass by get_trace
            _trace = _history.trace[0]
            _variables = _history.variables[0]
            _modes = _history.modes[0]
            
            get_modes(_history.data[0])
            apply_trace(_history.data[0])
            print_option()
            console.log(_history)
        }
        
        /**
         *  @description Add a new trace to the history, call function @see set_modes, @see apply_trace and @see print_option
         *  @param {HTML Object} object Contain the object to calll the data from server
         *  @param {Integer} key Contain the key for settings (only use for 3.0)
         */
        $.simisc.set_trace = function(object, key){
            console.log("set_trace")
            _clk_end++;
            console.log(_clk_end)

            //TOBETTER
            tmp = document.createElement("a")
            
            $(tmp).html($(object).attr("data-action"))
            
            _trace = {
                "action": $(tmp).text(),
                "state": $(object).attr("data-state"),
                "mode": $(object).attr("data-mode")
            }
            
            console.log(_trace)
            
            params = get_param_server("succ", {state: _trace.state, mode: _trace.mode})
            $.get(params[0], params[1],function(data){
                if (settings.graph.activate && data.variables) {
                    _variables = data.variables
                    _variables.transition = _trace.action

                    if($(object).attr("data-groups"))
                        _variables.groups = $(object).attr("data-groups").split(",")
                }
                
                console.log(_history.variables)
                
                set_modes(data);
        
                apply_trace(data);
                
                print_option();
                
            });
        }
        
        /**
         *  @description Get a trace from the history, call function @see get_modes, @see apply_trace and @see print_option
         *  @param {HTML Object} object Contain the object to calll the data from server
         *  @param {Integer} key Contain the key for settings (only use for 3.0)
         */
        $.simisc.get_trace = function(object, key) {
            console.log("get_trace")
            console.log(_history)
            
            _clk_end = parseInt($(object).attr("data-num"),10);
            _isHistory = true;
            console.log(_clk_end)
            
            _trace = _history.trace[_clk_end]
            _variables = _history.variables[_clk_end]
            _modes = _history.modes[_clk_end]
            
            if (_clk_end == _history.trace.length-1) {
                _isHistory = false
            }
            
            get_modes(_history.data[_clk_end])
            apply_trace(_history.data[_clk_end]);
            print_option();
        }
        
        /**
         *  @description Apply the trace of current state, and check if we need to cut or juste set a new history
         *  @param {Dict} data Contain the data for the current state
         */
        function apply_trace(data) {
            console.log("apply_trace")
            console.log(_history)
            if (_isHistory) {
                if (!compare_trace(_history.trace[_clk_end], _trace)){
                    console.log("destroy jenkins");
                    console.log(_history)
                    console.log(_clk_end)
                    cut_trace(0,_clk_end)
                    console.log(_history)
                    _isHistory = false;
                }
                else{
                    console.log("get the old trace")
                    $.each(data.modes, function(num, action){
                        $(action.select + " button").each(function(){
                            console.log(this)
                            
                            if(compare_trace({"state":$(this).attr("data-state"), "mode":$(this).attr("data-mode")},_history.trace[_clk_end+1]))
                            {
                                console.log($(this))
                                $(this).addClass("btn-primary")
                                //We switch to get, because we know the content
                                $(this).simisc().get_attr_link(_clk_end+1, instance_key)
                                
                            }
                            else{
                                trace = {
                                    "action": $(this).attr("data-action"),
                                    "state": $(this).attr("data-state"),
                                    "mode": $(this).attr("data-mode"),
                                    "groups": $(this).attr("data-groups")
                                }
                                
                                $(this).simisc()
                                .addClass("btn-warning")
                                .on("click",function(){
                                    $(settings.api.modal.id + ' .btn-primary').simisc().set_attr_link(trace, instance_key)
                                    $(settings.api.modal.id).modal('show')
                                });
                            }
                        });
                    });
                }
            }
            console.log("set_history ici")
            console.log(_variables)
            
            set_history(_clk_end, {
                "trace": _trace,
                "variables": _variables,
                "modes": _modes,
                "data": data
            })
            
            update_command_center()
        }
        
        /**
         *  @description print on the view all option activated in the settings
         */
        function print_option() {
            console.log(_groups)
            if(settings.trace.activate && ('id' in settings.trace)){
                print_trace();
            }
            
            if(settings.graph.activate && ('id' in settings.graph)){
                print_graph();
            }
        }
            
        /**
         *  @description Delete from data all transition, where transition hasn't a group in activate groups.
         *  @param Array data All data to process in graph
         */
        function extract_groups(data) {
            console.log("extract_groups")
            data = jQuery.grep(data, function(v, i){                
                return (process_group(v.groups));
            })
            
            return data
        }
        
        /**
         *  @description Take an Array of groups and return true if one or more of this group are activate in control panel, false else.
         *  @param Array groups contains groups of current data to process
         */
        function process_group(groups) {
            console.log("process group")
            if (groups.length == 0) {
                console.log("length 0")
                return (_groups.indexOf("others") > -1)
            }
            else{
                ok = false
                
                for (g in groups) {
                    console.log(g)
                    if ( (g == "" && _groups.indexOf("others") > -1) || _groups.indexOf(groups[g]) > -1) {
                        ok = true
                    }
                }
                return ok
            }
        }
        
        /**
         * @description print the graph with the new data, use D3.js
         */
        function print_graph(){
            console.log("print_graph")
            $(settings.graph.id + " .tooltip").hide();
            
            _data = _history.variables
            _data = _data.slice(_clk_begin,_clk_end+1);
            
            _data = extract_groups(_data)
            
            if (_data.length == 1) {
                _data.push(_data[0])
            }
            
            taille = _data.length
            
            console.log("lance graphe avec")
            console.log(_history.variables);
            console.log(_data);
            console.log(_clk_end);
            
            //Update the x length
            _graph.x.domain([0, _data.length-1]);
        
            //Var for get the max for all variable
            var max = [0]
        
            //We destroy all point & text for var
            _graph.svg.selectAll(".text-var").remove();
            _graph.svg.selectAll("circle").remove();
        
            //We get the max only for actif variables
            _graph.variables.forEach(function(v){
                if ($(".check_var[var='" + v + "']").prop("checked") && taille > 0) {
                    max.push(d3.max(_data, function(d) { return d[v]; }));
                }
            });
            
            //Update the y axis
            _graph.y.domain([0, d3.max(max, function(d) { return d; })]);
        
            //Create the transition
            _graph.transition = d3.select(settings.graph.id).transition();
        
            //Update the number of tick on x axis
            _graph.xAxis.ticks(d3.min([_data.length, settings.graph.max_it]));
        
            //DO the translation for the axis object
            _graph.transition.select(".x.axis") 
                .duration(750)
                .call(_graph.xAxis)
                .selectAll("text")
                    .style("text-anchor", "end")
                    .style("cursor", "pointer")
                    .attr("dx", "-.8em")
                    .attr("dy", ".15em")
                    .attr("transform", function(d) {
                        return "rotate(-65)"
                    });
        
            //We update each actif variable, the text & circles too 
            _graph.variables.forEach(function(v){
                if ($(".check_var[var='" + v + "']").prop("checked") && taille > 0) {
                    console.log("variables")
                    console.log(v)
                    _graph.transition.select(".line-" + v)
                        .duration(750)
                        .attr("d", _graph.line[v](_data))
                        //Call back
                        .each("end",function(){
                            _graph.svg.selectAll("dot")
                                .data(_data)
                                .enter().append("circle")
                                .attr("r", 3.5)
                                .attr("cx", function(d, i) { return _graph.x(i); })
                                .attr("cy", function(d) { return _graph.y(d[v]); })
                                //We give the attr data-num for toggle the tooltip on this transition when axis x is hover
                                .attr("data-num", function(d,i) {
                                    //We create all tooltip 
                                    $(this).tooltip({
                                        'title': "transition " + d['transition'] + " : " + v + " = " + d[v],
                                        'trigger': 'manual',
                                        'container':"body"
                                    });
                                    
                                    return i;
                                })
                                .attr("style","cursor:pointer;fill:" + settings.graph.color[v])
                                .attr("class","dot dot-"+v)
                                .on("mouseover", function(d) {
                                    $(this).tooltip('show')
                                })
                                .on("mouseout", function(d){
                                    $(this).tooltip('hide')
                                })
                        });
                    
                    _graph.svg.append("text")
                        .attr("transform", "translate("+(_graph.width+10)+","+_graph.y(_data[taille-1][v])+")")
                        .attr("dy", ".35em")
                        .attr("text-anchor", "start")
                        .attr("class", "text-var text-"+v)
                        .style("fill", settings.graph.color[v])
                        .text(v);
                }
            });
        
                    
            //TODO : permet de faire la trace dans le graph : à améliorer pour direct le mettre dans le x axis, un peu brouillon a mon gout (c'est le compteur qui me gene)
            cmp = 0
        
            $(".x.axis text").each(function(){
                //text is empty when there isn't not enought transition pass
                if ($(this).html() != "") {
                    var tmp_clk = cmp;
                    
                    $(this).unbind("mouseover")
                        .mouseover(function(){
                            $(".dot[data-num=" + tmp_clk + "]").each(function(){
                                console.log($(this).css('opacity'))
                                if ( $(this).css('opacity') == 1 ) {
                                    $(this).tooltip('show')
                                }
                            });
                        })
                        .mouseout(function(){
                            $(".dot[data-num=" + tmp_clk + "]").each(function(){                    
                                $(this).tooltip('hide')
                            });
                        })            
                    cmp++
                }
            });
                    
            _graph.transition.select(".y.axis") // change the y axis
                .duration(750)
                .call(_graph.yAxis);
            
        }
        
        /**
         *  @description print the trace for see history
         */
        function print_trace(){
            console.log("print_trace")
        
            //At each state we rewrite the trace, can be optimised with prepend when just add, and add style when cross the path
            $("#simisc_trace").html("");
        
            $.each(_history.trace, function(key,value){
                a = document.createElement("a");
                td = document.createElement("td");
                tr = document.createElement("tr");
                title = ""
                span = document.createElement("span")
                
                $(span).addClass("glyphicon")
                $(tr).html("<td>" + key + "</td><td>" + value.action + "</td><td>" + value.mode + "</td><td>" + value.state + "</td>");
                
                if (settings.graph.interval && settings.graph.activate) {
                    //When interval we have a second part, for begin
                    tdb = document.createElement("td")
                    ab = document.createElement("a")
                    spanb = document.createElement("span")
                    titleb = ""
                    
                    $(spanb).addClass("glyphicon")
                    
                    if (key == _clk_end) {
                        $(tr).addClass("info")
                        $(span).addClass("glyphicon-arrow-left")
                        title = "current ending state"
                        
                        $(ab).click(function(){
                            change_begin(key)
                        })
                        $(spanb).addClass("glyphicon-indent-left")
                        titleb = "Set the new end interval"
                    }
                    //Part we can change the end interval
                    else if (key > _clk_begin) {
                        $(tr).addClass("warning")
                        $(a).simisc().get_attr_link(key,instance_key)
                        $(span).addClass("glyphicon-indent-right")
                        title = "Set the new end interval"
                        
                    }
                    
                    if (key == _clk_begin) {
                        $(tr).addClass("info")
                        $(spanb).addClass("glyphicon-arrow-right")
                        titleb = "current ending state"
                        
                        $(a).simisc().get_attr_link(key,instance_key)
                        $(span).addClass("glyphicon-indent-right")
                        title = "Set the new end interval"
                    }
                    //Part we can change the begin interval
                    else if (key < _clk_end) {
                        $(tr).addClass("warning")
                        $(ab).click(function(){
                            change_begin(key)
                        })
                        $(spanb).addClass("glyphicon-indent-left")
                        titleb = "Set the new end interval"
                    }
                    
                    if (key < _clk_end && key > _clk_begin) {
                        $(tr).removeClass("warning danger")
                        
                        if (settings.graph.groups && !process_group(_history.variables[key].groups)) {
                            $(tr).addClass("danger")
                        }
                        else{
                            $(tr).addClass("success")
                        }
                    }
                    
                    if (settings.graph.groups) {
                        $(tr).append("<td>" + _history.variables[key].groups.join(',') + "</td>")
                    }
                    
                    
                    $(ab).append(spanb)
                    $(tdb).append(ab)
                    
                    $(a).append(span)
                    $(td).append(a)
                    
                    $(tr).append(tdb,td)
                }
                //Normal mode without interval choice
                else{
                    if(key === _clk_end){
                        $(tr).addClass("info");
                        title = "current state"
                        $(span).addClass("glyphicon-arrow-left")
                    }
                    else{
                        $(tr).addClass("success");
                        $(span).addClass("glyphicon-share-alt")
                        $(a).simisc().get_attr_link(key, instance_key);
                    }
                    
                    if (key > _clk_end) {
                        $(tr).addClass("warning");
                    }
                    
                    
                    $(a).append(span)
                    $(td).append(a)
                    $(tr).append(td)
                }
                
                $("#simisc_trace").append(tr);
                
            });
        }    
        
        /**
         *  @description Compare a couple of 'state'/'mode'
         *  @returns {Boolean} True if the couple have same state & mode, false else
         */
        function compare_trace(t1,t2){
            if(t1.mode === t2.mode && t1.state === t2.state)
                return true;
            return false;
        }
        
        /**
         * @description Cut for trace all between the two param given
         * @param {Integer} begin The id where the cut is begin
         * @param {Integer} end The id where the cut is stop
         */
        function cut_trace(begin, end){
            console.log("cut_trace")
            
            $.each(_history, function(k,v){
                _history[k] = _history[k].slice(begin,end)
            })
        }
        
        /**
         *  @description Update value in interval of command center
         */
        function update_command_center(){
            console.log("update command center")
            $("#end_interval").val(_clk_end)
            $("#begin_interval").val(_clk_begin)
            $("#reset_interval").attr("data-num",_history.trace.length-1)  
        }
        
        /**
         *  @description Set the opacity to 1 to path with var : variable, if "not" is true is all path except this one will be toggle
         *  @param {String} variable Variable to show
         *  @param {Boolean} not If not is true all variables will be show except @see variable
         */
        function toggle_path(variable, not) {
            console.log("toogle_path")
            //Not mean : if you want toggle other than the path for the variable
            print_option()
            if (not) {
                $(".line:not(.line-"+ variable + ")").fadeTo("slow",1)
                $(".dot:not(.dot-"+ variable + ")").fadeTo("slow",1)
                $(".text-var:not(.text-"+ variable + ")").fadeTo("slow",1)
            }
            else{
                $(".line-" + variable).fadeTo("slow",1)
                $(".dot-" + variable).fadeTo("slow",1)
                $(".text-" + variable).fadeTo("slow",1)
            }
        }
        
        /**
         *  @description Set the opacity to 0 to path with var : variable, if "not" is true is all path except this one will be fade
         *  @param {String} variable Variable to hide
         *  @param {Boolean} not If not is true all variables will be hide except @see variable
         */
        function fade_path(variable, not){
            print_option()
            if (not) {
                $(".line:not(.line-"+ variable + ")").fadeTo("slow",0)
                $(".dot:not(.dot-"+ variable + ")").fadeTo("slow",0)
                $(".text-var:not(.text-"+ variable + ")").fadeTo("slow",0)
            }
            else{
                $(".line-" + variable).fadeTo("slow",0)
                $(".dot-" + variable).fadeTo("slow",0)
                $(".text-" + variable).fadeTo("slow",0)
            }
        }
        
    };
    
    //For the 3.0 version : multiple simulators in same time
    $.simisc.instance = new Array()
    
    //The default value for simulator
    $.simisc.defaults = {
        "api":{
            //Id for reset button
            "reset": "#ui-reset",
            //If localhost let him empty
            "token": "",
            //Server for call function, if you are in localhost let him empty
            "server":"",
            //Id for stop button
            "quit": "#ui-quit",
            //Id for help button
            "help":"#ui-help",
            //Where model is stock
            "model": "#model",
            //Where nav will be added
            "nav": "#nav_sim",
            "modal":{
                "id":"#simisc_trace_alert",
                "text":"The trace isn't same as history, will you change this trace ?",
                "title":"Warning : new trace detected",
                "button": "Go new trace"
            },
        },
        //Where is the player & if he is activate
        "player":{
            //Where the player is added
            "id":"#player",
            "modal":{
                "id":"#simisc_player_alert",
                "text":"The trace isn't same as history, will you change this trace ?",
                "title":"Warning : new trace detected",
                "button": "Go new trace"
            },
            //When true the player will be add
            "activate": true
        },
        //Nav optionnal content, add to reset/quit & help button
        "nav": {
            //Sample of new content to nav
            "about": {
                "script": "",
                "text": "About",
                "attr": {
                    "data-toggle": "modal",
                    "data-target": "#ui-about"
                }
            }
        },
        //Init state
        "init": {
            "state": 0,
            "mode": 0,
            //How we call the init state
            "action": "init",
            "groups": Array()
        },
        //Option for trace
        "trace": {
            //Where the trace will be added
            "id": "#trace_zone",
            //If the trace is activated
            "activate": true
        },
        //Option for graph
        "graph": {
            //Where the graph will be added
            'id' : '#graph',
            'control_panel': '#Command_center',
            //The number max of tick with label in x axis
            "max_iteration" : 50,
            //If we can change the begin & the end for zoom in graph
            "interval": true,
            //Where the command pannel will be add
            "command_bord": "#graph_bord",
            //If the graph is activated
            "activate": true,
            //If typed transition are active
            "groups": true
        }
    };

})(jQuery)