zebradog / radial-menu

Snap.svg radial menu
http://code.zebradog.com/radial-menu/
MIT License
4 stars 3 forks source link

create initial library #1

Closed matt-cook closed 8 years ago

matt-cook commented 8 years ago

Radial Menu Library

This will be a general-purpose radial menu for use with Javascript, generated as SVG using the Snap.svg library (http://snapsvg.io/).

General Requirements

//creating a new RadialMenu
var myMenu = new RadialMenu({
    stroke: 1, //stroke width around every menu item, in pixels
    spacing: 10 //amount of space between menu items
    x: 0, //location of the center of the menu
    y: 0,
    opacity: 1.0

    ... //any child item configuration option can be specified here to set the default for the entire menu. the above options are only available on the RadialMenu 
});

//calling .add() with optional configuration will add a new RadialMenuItem and return it
var myMenuItem = myMenu.add('menu-item-label',{
    size: null, //if set to a float value 0-1, attempt to allow the section to take that percent of the circle. if null, size is automatically calculated by
    font-size: 14, //font size of this item, in pixels
    font-family: 'Verdana',
    font-color: '#000000',
    active-font-color: '#000000',
    active-stroke-color: '#000000',
    active-stroke-opacity: 1.0,
    active-fill: '#ffffff',
    active-fill-opacity: 1.0,
    stroke-color: '#000000',
    stroke-opacity: 1.0,
    text-color: '#000000',
    fill: '#ffffff',
    fill-opacity: 0.5,
    data: null, //optionally additional object can be provided that will be sent to the callback, this could include an ID or URL to load on click
    onclick: null, //callback, none by default
});
myMenu.
myMenu.add(label,config); //add and return a top-level menu item
myMenu.children(); //return all child menu items as array
myMenu.close(); //will animate the entire menu to closed/hidden position
myMenuItem.close(); //if this menu item is open, it will animate to closed
myMenuItem.open(); //if this menu item is not open, it (and any parents if they are not open) will be marked as selected
myMenuItem.add(label,config); //add and return a child menu item
myMenuItem.children(); //return all child menu items as array

Example:

radial-menu

var myMenu = new RadialMenu({
    opacity: 0.0,
    fill-opacity: 1.0,
    active-fill: '#cbcccb',
    onclick: function(e){
        //need to be able to reference source RadialMenuItem
        //and optional .data attribute in here
        //possibly through 'this.data' or 'e.target.data'
        console.log('menu item clicked',this,e);
        this.open();
    }
});

var m1 = myMenu.add('RESIDENTIAL EXPERIENCE',{size:0.5});
var m2 = myMenu.add('HALL ARTS LEASING');
var m3 = myMenu.add('HALL GROUP');

m1.add('DESIGN TEAM');
m1.add('THE ARTS DISTRICT');
m1.add('AMENITIES');
m1.add('MORE');
m1.add('LIFESTYLE');

m2.add('HALL STRUCTURED FINANCE');
m2.add('ANGEL INVESTING');
m2.add('PHILANTHROPY');
m2.add('MORE');
m2.add('HALL OFFICE PARK');

/* ... add m3 children, other sub-sub children ...*/

var menuOpen = false;
$("body").on('click',function(e){
    if(menuOpen) {
        myMenu.opacity = 0;
    }else {
        myMenu.x = e.pageX;
        myMenu.y = e.pageY;
        myMenu.opacity = 1.0;
        myMenu.open();
    }
    menuOpen = !menuOpen;
});
matt-cook commented 8 years ago

bcb2e791631372ce02625559d081f007f9d99d0d