d3-context-menu
Advanced tools
Comparing version 0.1.3 to 0.2.1
{ | ||
"name": "d3-context-menu", | ||
"version": "0.1.3", | ||
"version": "0.2.1", | ||
"main": [ | ||
@@ -5,0 +5,0 @@ "js/d3-context-menu.js", |
@@ -26,3 +26,4 @@ (function(root, factory) { | ||
var openCallback, | ||
closeCallback; | ||
closeCallback, | ||
positionProvider; | ||
@@ -35,2 +36,3 @@ if (typeof opts === 'function') { | ||
closeCallback = opts.onClose; | ||
positionProvider = opts.position; | ||
} | ||
@@ -118,6 +120,12 @@ | ||
// get position | ||
var position = positionProvider; | ||
if (typeof positionProvider === 'function') { | ||
position = positionProvider(data, elm, index); | ||
} | ||
// display context menu | ||
d3.select('.d3-context-menu') | ||
.style('left', (d3.event.pageX - 2) + 'px') | ||
.style('top', (d3.event.pageY - 2) + 'px') | ||
.style('left', (position ? position.left : d3.event.pageX - 2) + 'px') | ||
.style('top', (position ? position.top : d3.event.pageY - 2) + 'px') | ||
.style('display', 'block'); | ||
@@ -124,0 +132,0 @@ |
{ | ||
"name": "d3-context-menu", | ||
"version": "0.1.3", | ||
"version": "0.2.1", | ||
"description": "A plugin for d3.js that allows you to easily use context menus in your visualizations.", | ||
@@ -10,3 +10,5 @@ "main": "js/d3-context-menu.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"test": "echo \"Error: no test specified\" && exit 1", | ||
"dist": "mkdirp dist && minify js/d3-context-menu.js > dist/d3-context-menu.min.js && minify css/d3-context-menu.css > dist/d3-context-menu.min.css", | ||
"prepublishOnly": "npm run dist" | ||
}, | ||
@@ -27,3 +29,7 @@ "repository": { | ||
}, | ||
"homepage": "https://github.com/patorjk/d3-context-menu" | ||
"homepage": "https://github.com/patorjk/d3-context-menu", | ||
"devDependencies": { | ||
"minify": "^3.0.2", | ||
"mkdirp": "^0.5.1" | ||
} | ||
} |
@@ -93,6 +93,6 @@ # d3-context-menu | ||
``` | ||
... | ||
.on('contextmenu', d3.contextMenu(menu, function() { | ||
console.log('Quick! Before the menu appears!'); | ||
})); // attach menu to element | ||
... | ||
.on('contextmenu', d3.contextMenu(menu, function() { | ||
console.log('Quick! Before the menu appears!'); | ||
})); // attach menu to element | ||
@@ -106,11 +106,11 @@ ``` | ||
``` | ||
... | ||
.on('contextmenu', d3.contextMenu(menu, { | ||
onOpen: function() { | ||
console.log('Quick! Before the menu appears!'); | ||
}, | ||
onClose: function() { | ||
console.log('Menu has been closed.'); | ||
} | ||
})); // attach menu to element | ||
... | ||
.on('contextmenu', d3.contextMenu(menu, { | ||
onOpen: function() { | ||
console.log('Quick! Before the menu appears!'); | ||
}, | ||
onClose: function() { | ||
console.log('Menu has been closed.'); | ||
} | ||
})); // attach menu to element | ||
@@ -190,2 +190,55 @@ ``` | ||
#### Explicitly set menu position | ||
Default position can be overwritten by providing a `position` option (either object or function returning an object): | ||
``` | ||
... | ||
.on('contextmenu', d3.contextMenu(menu, { | ||
onOpen: function() { | ||
... | ||
}, | ||
onClose: function() { | ||
... | ||
}, | ||
position: { | ||
top: 100, | ||
left: 200 | ||
} | ||
})); // attach menu to element | ||
``` | ||
or | ||
``` | ||
... | ||
.on('contextmenu', d3.contextMenu(menu, { | ||
onOpen: function() { | ||
... | ||
}, | ||
onClose: function() { | ||
... | ||
}, | ||
position: function(d, elm, i) { | ||
var bounds = elm.getBoundingClientRect(); | ||
// eg. align bottom-left | ||
return { | ||
top: bounds.top + bounds.height, | ||
left: bounds.left | ||
} | ||
} | ||
})); // attach menu to element | ||
``` | ||
The following example shows how to add a right click menu to a tree diagram: | ||
http://plnkr.co/edit/bDBe0xGX1mCLzqYGOqOS?p=info | ||
### What's new in version 0.2.1 | ||
* Ability to set menu position | ||
* Minified css and js versions | ||
### What's new in version 0.1.3 | ||
@@ -192,0 +245,0 @@ * Fixed issue where context menu element is never removed from DOM |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
15882
10
199
254
2