mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-07 09:36:41 +02:00
Chart Node click event support key-path value for function callback
This commit is contained in:
@@ -217,7 +217,7 @@ const setClickFunc = function(domId, functionName, tooltip) {
|
|||||||
elem.addEventListener(
|
elem.addEventListener(
|
||||||
'click',
|
'click',
|
||||||
function() {
|
function() {
|
||||||
window[functionName](elemId);
|
utils.runFunc(functionName, elemId);
|
||||||
},
|
},
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
|
@@ -232,7 +232,7 @@ const setClickFun = function(_id, functionName) {
|
|||||||
elem.addEventListener(
|
elem.addEventListener(
|
||||||
'click',
|
'click',
|
||||||
function() {
|
function() {
|
||||||
window[functionName](id);
|
utils.runFunc(functionName, id);
|
||||||
},
|
},
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
|
@@ -2,6 +2,7 @@ import moment from 'moment-mini';
|
|||||||
import { sanitizeUrl } from '@braintree/sanitize-url';
|
import { sanitizeUrl } from '@braintree/sanitize-url';
|
||||||
import { logger } from '../../logger';
|
import { logger } from '../../logger';
|
||||||
import { getConfig } from '../../config';
|
import { getConfig } from '../../config';
|
||||||
|
import utils from '../../utils';
|
||||||
|
|
||||||
const config = getConfig();
|
const config = getConfig();
|
||||||
let dateFormat = '';
|
let dateFormat = '';
|
||||||
@@ -520,7 +521,7 @@ const setClickFun = function(id, functionName, functionArgs) {
|
|||||||
let rawTask = findTaskById(id);
|
let rawTask = findTaskById(id);
|
||||||
if (typeof rawTask !== 'undefined') {
|
if (typeof rawTask !== 'undefined') {
|
||||||
pushFun(id, () => {
|
pushFun(id, () => {
|
||||||
window[functionName](...argList);
|
utils.runFunc(functionName, ...argList);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
18
src/utils.js
18
src/utils.js
@@ -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) =>
|
const distance = (p1, p2) =>
|
||||||
p1 && p2 ? Math.sqrt(Math.pow(p2.x - p1.x, 2) + Math.pow(p2.y - p1.y, 2)) : 0;
|
p1 && p2 ? Math.sqrt(Math.pow(p2.x - p1.x, 2) + Math.pow(p2.y - p1.y, 2)) : 0;
|
||||||
|
|
||||||
@@ -262,5 +277,6 @@ export default {
|
|||||||
calcCardinalityPosition,
|
calcCardinalityPosition,
|
||||||
formatUrl,
|
formatUrl,
|
||||||
getStylesFromArray,
|
getStylesFromArray,
|
||||||
generateId
|
generateId,
|
||||||
|
runFunc
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user