Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chart Node click event support key-path value for function callback #1470

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/diagrams/class/classDb.js
Expand Up @@ -217,7 +217,7 @@ const setClickFunc = function(domId, functionName, tooltip) {
elem.addEventListener(
'click',
function() {
window[functionName](elemId);
utils.runFunc(functionName, elemId);
},
false
);
Expand Down
2 changes: 1 addition & 1 deletion src/diagrams/flowchart/flowDb.js
Expand Up @@ -232,7 +232,7 @@ const setClickFun = function(_id, functionName) {
elem.addEventListener(
'click',
function() {
window[functionName](id);
utils.runFunc(functionName, id);
},
false
);
Expand Down
3 changes: 2 additions & 1 deletion src/diagrams/gantt/ganttDb.js
Expand Up @@ -2,6 +2,7 @@ import moment from 'moment-mini';
import { sanitizeUrl } from '@braintree/sanitize-url';
import { logger } from '../../logger';
import { getConfig } from '../../config';
import utils from '../../utils';

const config = getConfig();
let dateFormat = '';
Expand Down Expand Up @@ -520,7 +521,7 @@ const setClickFun = function(id, functionName, functionArgs) {
let rawTask = findTaskById(id);
if (typeof rawTask !== 'undefined') {
pushFun(id, () => {
window[functionName](...argList);
utils.runFunc(functionName, ...argList);
});
}
};
Expand Down
18 changes: 17 additions & 1 deletion src/utils.js
Expand Up @@ -127,6 +127,21 @@ export const formatUrl = (linkStr, config) => {
}
};

export const runFunc = (functionName, ...params) => {
var arrPaths = functionName.split('.');

var len = arrPaths.length - 1;
var fnName = arrPaths[len];

var obj = window;
for (var i = 0; i < len; i++) {
obj = obj[arrPaths[i]];
if (!obj) return;
}

obj[fnName](...params);
};

const distance = (p1, p2) =>
p1 && p2 ? Math.sqrt(Math.pow(p2.x - p1.x, 2) + Math.pow(p2.y - p1.y, 2)) : 0;

Expand Down Expand Up @@ -262,5 +277,6 @@ export default {
calcCardinalityPosition,
formatUrl,
getStylesFromArray,
generateId
generateId,
runFunc
};