client/js/renderer/shapebuilder.js
author ymh <ymh.work@gmail.com>
Tue, 10 Jan 2017 17:36:30 +0100
changeset 649 2b9c120dba55
parent 467 fd2b5a7ec356
permissions -rw-r--r--
first implementation of node title size and color
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
326
e4afd8643576 shape builder for node
cavaliet
parents:
diff changeset
     1
e4afd8643576 shape builder for node
cavaliet
parents:
diff changeset
     2
define([], function () {
e4afd8643576 shape builder for node
cavaliet
parents:
diff changeset
     3
    'use strict';
e4afd8643576 shape builder for node
cavaliet
parents:
diff changeset
     4
441
4732f078d0fe add cloud form
ymh <ymh.work@gmail.com>
parents: 435
diff changeset
     5
    var cloud_path = "M0,0c-0.1218516546,-0.0336420601 -0.2451649928,0.0048580836 -0.3302944641,0.0884969975c-0.0444763883,-0.0550844815 -0.1047003238,-0.0975985034 -0.1769360893,-0.1175406746c-0.1859066673,-0.0513257002 -0.3774236254,0.0626045858 -0.4272374613,0.2541588105c-0.0036603877,0.0140753132 -0.0046241235,0.028229722 -0.0065872453,0.042307536c-0.1674179627,-0.0179317735 -0.3276106855,0.0900599386 -0.3725537463,0.2628868425c-0.0445325077,0.1712456429 0.0395025693,0.3463497959 0.1905420475,0.4183458793c-0.0082101538,0.0183442886 -0.0158652506,0.0372432828 -0.0211098452,0.0574080693c-0.0498130336,0.1915540431 0.0608692569,0.3884647499 0.2467762814,0.4397904033c0.0910577256,0.0251434257 0.1830791813,0.0103792696 0.2594677475,-0.0334472349c0.042100113,0.0928009202 0.1205930075,0.1674914182 0.2240666796,0.1960572479c0.1476344161,0.0407610407 0.297446165,-0.0238077445 0.3783262342,-0.1475652419c0.0327623278,0.0238981846 0.0691792333,0.0436665447 0.1102008706,0.0549940004c0.1859065794,0.0513256592 0.3770116432,-0.0627203154 0.4268255671,-0.2542745401c0.0250490557,-0.0963230532 0.0095494076,-0.1938010889 -0.0356681889,-0.2736906101c0.0447507424,-0.0439678867 0.0797796014,-0.0996624318 0.0969425462,-0.1656617192c0.0498137481,-0.1915564561 -0.0608688118,-0.3884669813 -0.2467755669,-0.4397928163c-0.0195699622,-0.0054005426 -0.0391731675,-0.0084429542 -0.0586916488,-0.0102888295c0.0115683912,-0.1682147574 -0.0933564223,-0.3269222408 -0.2572937178,-0.3721841203z";
326
e4afd8643576 shape builder for node
cavaliet
parents:
diff changeset
     6
    /* ShapeBuilder Begin */
e4afd8643576 shape builder for node
cavaliet
parents:
diff changeset
     7
e4afd8643576 shape builder for node
cavaliet
parents:
diff changeset
     8
    var builders = {
e4afd8643576 shape builder for node
cavaliet
parents:
diff changeset
     9
        "circle":{
e4afd8643576 shape builder for node
cavaliet
parents:
diff changeset
    10
            getShape: function() {
e4afd8643576 shape builder for node
cavaliet
parents:
diff changeset
    11
                return new paper.Path.Circle([0, 0], 1);
e4afd8643576 shape builder for node
cavaliet
parents:
diff changeset
    12
            },
e4afd8643576 shape builder for node
cavaliet
parents:
diff changeset
    13
            getImageShape: function(center, radius) {
e4afd8643576 shape builder for node
cavaliet
parents:
diff changeset
    14
                return new paper.Path.Circle(center, radius);
e4afd8643576 shape builder for node
cavaliet
parents:
diff changeset
    15
            }
e4afd8643576 shape builder for node
cavaliet
parents:
diff changeset
    16
        },
e4afd8643576 shape builder for node
cavaliet
parents:
diff changeset
    17
        "rectangle":{
e4afd8643576 shape builder for node
cavaliet
parents:
diff changeset
    18
            getShape: function() {
e4afd8643576 shape builder for node
cavaliet
parents:
diff changeset
    19
                return new paper.Path.Rectangle([-2, -2], [2, 2]);
e4afd8643576 shape builder for node
cavaliet
parents:
diff changeset
    20
            },
e4afd8643576 shape builder for node
cavaliet
parents:
diff changeset
    21
            getImageShape: function(center, radius) {
e4afd8643576 shape builder for node
cavaliet
parents:
diff changeset
    22
                return new paper.Path.Rectangle([-radius, -radius], [radius*2, radius*2]);
e4afd8643576 shape builder for node
cavaliet
parents:
diff changeset
    23
            }
e4afd8643576 shape builder for node
cavaliet
parents:
diff changeset
    24
        },
e4afd8643576 shape builder for node
cavaliet
parents:
diff changeset
    25
        "ellipse":{
e4afd8643576 shape builder for node
cavaliet
parents:
diff changeset
    26
            getShape: function() {
e4afd8643576 shape builder for node
cavaliet
parents:
diff changeset
    27
                return new paper.Path.Ellipse(new paper.Rectangle([-2, -1], [2, 1]));
e4afd8643576 shape builder for node
cavaliet
parents:
diff changeset
    28
            },
e4afd8643576 shape builder for node
cavaliet
parents:
diff changeset
    29
            getImageShape: function(center, radius) {
e4afd8643576 shape builder for node
cavaliet
parents:
diff changeset
    30
                return new paper.Path.Ellipse(new paper.Rectangle([-radius, -radius/2], [radius*2, radius]));
e4afd8643576 shape builder for node
cavaliet
parents:
diff changeset
    31
            }
e4afd8643576 shape builder for node
cavaliet
parents:
diff changeset
    32
        },
e4afd8643576 shape builder for node
cavaliet
parents:
diff changeset
    33
        "polygon":{
e4afd8643576 shape builder for node
cavaliet
parents:
diff changeset
    34
            getShape: function() {
e4afd8643576 shape builder for node
cavaliet
parents:
diff changeset
    35
                return new paper.Path.RegularPolygon([0, 0], 6, 1);
e4afd8643576 shape builder for node
cavaliet
parents:
diff changeset
    36
            },
e4afd8643576 shape builder for node
cavaliet
parents:
diff changeset
    37
            getImageShape: function(center, radius) {
458
423bdf56d103 migrated to style, added dash style to client + small refactoring for shapes + triangle
ymh <ymh.work@gmail.com>
parents: 441
diff changeset
    38
                return new paper.Path.RegularPolygon(center, 6, radius);
326
e4afd8643576 shape builder for node
cavaliet
parents:
diff changeset
    39
            }
e4afd8643576 shape builder for node
cavaliet
parents:
diff changeset
    40
        },
e4afd8643576 shape builder for node
cavaliet
parents:
diff changeset
    41
        "diamond":{
e4afd8643576 shape builder for node
cavaliet
parents:
diff changeset
    42
            getShape: function() {
435
e529b633c339 Add shape management, correction on shape manip[ulation on the client, correct 404 error on space creation, increment version
ymh <ymh.work@gmail.com>
parents: 328
diff changeset
    43
                var d = new paper.Path.Rectangle([-Math.SQRT2, -Math.SQRT2], [Math.SQRT2, Math.SQRT2]);
326
e4afd8643576 shape builder for node
cavaliet
parents:
diff changeset
    44
                d.rotate(45);
e4afd8643576 shape builder for node
cavaliet
parents:
diff changeset
    45
                return d;
e4afd8643576 shape builder for node
cavaliet
parents:
diff changeset
    46
            },
e4afd8643576 shape builder for node
cavaliet
parents:
diff changeset
    47
            getImageShape: function(center, radius) {
435
e529b633c339 Add shape management, correction on shape manip[ulation on the client, correct 404 error on space creation, increment version
ymh <ymh.work@gmail.com>
parents: 328
diff changeset
    48
                var d = new paper.Path.Rectangle([-radius*Math.SQRT2/2, -radius*Math.SQRT2/2], [radius*Math.SQRT2, radius*Math.SQRT2]);
326
e4afd8643576 shape builder for node
cavaliet
parents:
diff changeset
    49
                d.rotate(45);
e4afd8643576 shape builder for node
cavaliet
parents:
diff changeset
    50
                return d;
e4afd8643576 shape builder for node
cavaliet
parents:
diff changeset
    51
            }
e4afd8643576 shape builder for node
cavaliet
parents:
diff changeset
    52
        },
e4afd8643576 shape builder for node
cavaliet
parents:
diff changeset
    53
        "star":{
e4afd8643576 shape builder for node
cavaliet
parents:
diff changeset
    54
            getShape: function() {
e4afd8643576 shape builder for node
cavaliet
parents:
diff changeset
    55
                return new paper.Path.Star([0, 0], 8, 1, 0.7);
e4afd8643576 shape builder for node
cavaliet
parents:
diff changeset
    56
            },
e4afd8643576 shape builder for node
cavaliet
parents:
diff changeset
    57
            getImageShape: function(center, radius) {
458
423bdf56d103 migrated to style, added dash style to client + small refactoring for shapes + triangle
ymh <ymh.work@gmail.com>
parents: 441
diff changeset
    58
                return new paper.Path.Star(center, 8, radius*1, radius*0.7);
326
e4afd8643576 shape builder for node
cavaliet
parents:
diff changeset
    59
            }
e4afd8643576 shape builder for node
cavaliet
parents:
diff changeset
    60
        },
441
4732f078d0fe add cloud form
ymh <ymh.work@gmail.com>
parents: 435
diff changeset
    61
        "cloud": {
4732f078d0fe add cloud form
ymh <ymh.work@gmail.com>
parents: 435
diff changeset
    62
            getShape: function() {
4732f078d0fe add cloud form
ymh <ymh.work@gmail.com>
parents: 435
diff changeset
    63
                var path = new paper.Path(cloud_path);
4732f078d0fe add cloud form
ymh <ymh.work@gmail.com>
parents: 435
diff changeset
    64
                return path;
4732f078d0fe add cloud form
ymh <ymh.work@gmail.com>
parents: 435
diff changeset
    65
4732f078d0fe add cloud form
ymh <ymh.work@gmail.com>
parents: 435
diff changeset
    66
            },
4732f078d0fe add cloud form
ymh <ymh.work@gmail.com>
parents: 435
diff changeset
    67
            getImageShape: function(center, radius) {
4732f078d0fe add cloud form
ymh <ymh.work@gmail.com>
parents: 435
diff changeset
    68
                var path = new paper.Path(cloud_path);
4732f078d0fe add cloud form
ymh <ymh.work@gmail.com>
parents: 435
diff changeset
    69
                path.scale(radius);
4732f078d0fe add cloud form
ymh <ymh.work@gmail.com>
parents: 435
diff changeset
    70
                path.translate(center);
4732f078d0fe add cloud form
ymh <ymh.work@gmail.com>
parents: 435
diff changeset
    71
                return path;
4732f078d0fe add cloud form
ymh <ymh.work@gmail.com>
parents: 435
diff changeset
    72
            }
4732f078d0fe add cloud form
ymh <ymh.work@gmail.com>
parents: 435
diff changeset
    73
        },
458
423bdf56d103 migrated to style, added dash style to client + small refactoring for shapes + triangle
ymh <ymh.work@gmail.com>
parents: 441
diff changeset
    74
        "triangle": {
423bdf56d103 migrated to style, added dash style to client + small refactoring for shapes + triangle
ymh <ymh.work@gmail.com>
parents: 441
diff changeset
    75
            getShape: function() {
423bdf56d103 migrated to style, added dash style to client + small refactoring for shapes + triangle
ymh <ymh.work@gmail.com>
parents: 441
diff changeset
    76
                return new paper.Path.RegularPolygon([0,0], 3, 1);
423bdf56d103 migrated to style, added dash style to client + small refactoring for shapes + triangle
ymh <ymh.work@gmail.com>
parents: 441
diff changeset
    77
            },
423bdf56d103 migrated to style, added dash style to client + small refactoring for shapes + triangle
ymh <ymh.work@gmail.com>
parents: 441
diff changeset
    78
            getImageShape: function(center, radius) {
467
fd2b5a7ec356 Correct triangle display with images
ymh <ymh.work@gmail.com>
parents: 458
diff changeset
    79
                var shape = new paper.Path.RegularPolygon([0,0], 3, 1);
fd2b5a7ec356 Correct triangle display with images
ymh <ymh.work@gmail.com>
parents: 458
diff changeset
    80
                shape.scale(radius);
fd2b5a7ec356 Correct triangle display with images
ymh <ymh.work@gmail.com>
parents: 458
diff changeset
    81
                shape.translate(center);
fd2b5a7ec356 Correct triangle display with images
ymh <ymh.work@gmail.com>
parents: 458
diff changeset
    82
                return shape;
458
423bdf56d103 migrated to style, added dash style to client + small refactoring for shapes + triangle
ymh <ymh.work@gmail.com>
parents: 441
diff changeset
    83
            }
423bdf56d103 migrated to style, added dash style to client + small refactoring for shapes + triangle
ymh <ymh.work@gmail.com>
parents: 441
diff changeset
    84
        },
327
239d372644a0 svg path possibilites and update paper
cavaliet
parents: 326
diff changeset
    85
        "svg": function(path){
239d372644a0 svg path possibilites and update paper
cavaliet
parents: 326
diff changeset
    86
            return {
239d372644a0 svg path possibilites and update paper
cavaliet
parents: 326
diff changeset
    87
                getShape: function() {
239d372644a0 svg path possibilites and update paper
cavaliet
parents: 326
diff changeset
    88
                    return new paper.Path(path);
239d372644a0 svg path possibilites and update paper
cavaliet
parents: 326
diff changeset
    89
                },
239d372644a0 svg path possibilites and update paper
cavaliet
parents: 326
diff changeset
    90
                getImageShape: function(center, radius) {
435
e529b633c339 Add shape management, correction on shape manip[ulation on the client, correct 404 error on space creation, increment version
ymh <ymh.work@gmail.com>
parents: 328
diff changeset
    91
                    // No calcul for the moment
327
239d372644a0 svg path possibilites and update paper
cavaliet
parents: 326
diff changeset
    92
                    return new paper.Path();
239d372644a0 svg path possibilites and update paper
cavaliet
parents: 326
diff changeset
    93
                }
328
3e69a85d73e9 jshint corrections
cavaliet
parents: 327
diff changeset
    94
            };
327
239d372644a0 svg path possibilites and update paper
cavaliet
parents: 326
diff changeset
    95
        }
326
e4afd8643576 shape builder for node
cavaliet
parents:
diff changeset
    96
    };
435
e529b633c339 Add shape management, correction on shape manip[ulation on the client, correct 404 error on space creation, increment version
ymh <ymh.work@gmail.com>
parents: 328
diff changeset
    97
326
e4afd8643576 shape builder for node
cavaliet
parents:
diff changeset
    98
    var ShapeBuilder = function (shape){
435
e529b633c339 Add shape management, correction on shape manip[ulation on the client, correct 404 error on space creation, increment version
ymh <ymh.work@gmail.com>
parents: 328
diff changeset
    99
        if(shape === null || typeof shape === "undefined"){
327
239d372644a0 svg path possibilites and update paper
cavaliet
parents: 326
diff changeset
   100
            shape = "circle";
239d372644a0 svg path possibilites and update paper
cavaliet
parents: 326
diff changeset
   101
        }
328
3e69a85d73e9 jshint corrections
cavaliet
parents: 327
diff changeset
   102
        if(shape.substr(0,4)==="svg:"){
3e69a85d73e9 jshint corrections
cavaliet
parents: 327
diff changeset
   103
            return builders.svg(shape.substr(4));
327
239d372644a0 svg path possibilites and update paper
cavaliet
parents: 326
diff changeset
   104
        }
326
e4afd8643576 shape builder for node
cavaliet
parents:
diff changeset
   105
        if(!(shape in builders)){
e4afd8643576 shape builder for node
cavaliet
parents:
diff changeset
   106
            shape = "circle";
e4afd8643576 shape builder for node
cavaliet
parents:
diff changeset
   107
        }
e4afd8643576 shape builder for node
cavaliet
parents:
diff changeset
   108
        return builders[shape];
e4afd8643576 shape builder for node
cavaliet
parents:
diff changeset
   109
    };
435
e529b633c339 Add shape management, correction on shape manip[ulation on the client, correct 404 error on space creation, increment version
ymh <ymh.work@gmail.com>
parents: 328
diff changeset
   110
458
423bdf56d103 migrated to style, added dash style to client + small refactoring for shapes + triangle
ymh <ymh.work@gmail.com>
parents: 441
diff changeset
   111
    ShapeBuilder.builders = builders;
423bdf56d103 migrated to style, added dash style to client + small refactoring for shapes + triangle
ymh <ymh.work@gmail.com>
parents: 441
diff changeset
   112
326
e4afd8643576 shape builder for node
cavaliet
parents:
diff changeset
   113
    return ShapeBuilder;
e4afd8643576 shape builder for node
cavaliet
parents:
diff changeset
   114
e4afd8643576 shape builder for node
cavaliet
parents:
diff changeset
   115
});