Mercurial > hg > NetworkVis
comparison popoto/src/js/popoto.js @ 1:db013b2f3e10
added displayAttribute to show on individual nodes.
pull all labels and add getLabelFilter to ignore labels (currently with underscore).
added ismi-specific app-template and html file.
author | Robert Casties <casties@mpiwg-berlin.mpg.de> |
---|---|
date | Tue, 01 Sep 2015 16:56:31 +0200 |
parents | 3b8b5aa8ab65 |
children | aea1b2097f4f |
comparison
equal
deleted
inserted
replaced
0:3b8b5aa8ab65 | 1:db013b2f3e10 |
---|---|
2010 | 2010 |
2011 var nx = clickedNode.x + (100 * Math.cos((angleDeg * (Math.PI / 180)) - parentAngle)), | 2011 var nx = clickedNode.x + (100 * Math.cos((angleDeg * (Math.PI / 180)) - parentAngle)), |
2012 ny = clickedNode.y + (100 * Math.sin((angleDeg * (Math.PI / 180)) - parentAngle)); | 2012 ny = clickedNode.y + (100 * Math.sin((angleDeg * (Math.PI / 180)) - parentAngle)); |
2013 | 2013 |
2014 var isGroupNode = popoto.provider.getIsGroup(d); | 2014 var isGroupNode = popoto.provider.getIsGroup(d); |
2015 // filter multiple labels | |
2016 var nodeLabel = popoto.provider.getLabelFilter(d.label); | |
2017 | |
2015 var node = { | 2018 var node = { |
2016 "id": "" + (++popoto.graph.node.idgen), | 2019 "id": "" + (++popoto.graph.node.idgen), |
2017 "parent": clickedNode, | 2020 "parent": clickedNode, |
2018 "type": (isGroupNode) ? popoto.graph.node.NodeTypes.GROUP : popoto.graph.node.NodeTypes.CHOOSE, | 2021 "type": (isGroupNode) ? popoto.graph.node.NodeTypes.GROUP : popoto.graph.node.NodeTypes.CHOOSE, |
2019 "label": d.label, | 2022 "label": nodeLabel, |
2020 "fixed": false, | 2023 "fixed": false, |
2021 "internalLabel": popoto.graph.node.generateInternalLabel(d.label), | 2024 "internalLabel": popoto.graph.node.generateInternalLabel(nodeLabel), |
2022 "x": nx, | 2025 "x": nx, |
2023 "y": ny | 2026 "y": ny |
2024 }; | 2027 }; |
2025 | 2028 |
2026 popoto.graph.force.nodes().push(node); | 2029 popoto.graph.force.nodes().push(node); |
2649 matchElements.push("(" + targetNode.internalLabel + ":`" + targetNode.label + "`)-[r]" + rel + "(x)"); | 2652 matchElements.push("(" + targetNode.internalLabel + ":`" + targetNode.label + "`)-[r]" + rel + "(x)"); |
2650 returnElements.push("type(r) AS relationship"); | 2653 returnElements.push("type(r) AS relationship"); |
2651 if (popoto.query.USE_PARENT_RELATION) { | 2654 if (popoto.query.USE_PARENT_RELATION) { |
2652 returnElements.push("head(labels(x)) AS label"); | 2655 returnElements.push("head(labels(x)) AS label"); |
2653 } else { | 2656 } else { |
2654 returnElements.push("last(labels(x)) AS label"); | 2657 //returnElements.push("last(labels(x)) AS label"); |
2658 returnElements.push("labels(x) AS label"); | |
2655 } | 2659 } |
2656 returnElements.push("count(r) AS count"); | 2660 returnElements.push("count(r) AS count"); |
2657 endElements.push("ORDER BY count(r) DESC"); | 2661 endElements.push("ORDER BY count(r) DESC"); |
2658 | 2662 |
2659 return "MATCH " + matchElements.join(", ") + ((whereElements.length > 0) ? " WHERE " + whereElements.join(" AND ") : "") + " RETURN " + returnElements.join(", ") + " " + endElements.join(" "); | 2663 return "MATCH " + matchElements.join(", ") + ((whereElements.length > 0) ? " WHERE " + whereElements.join(" AND ") : "") + " RETURN " + returnElements.join(", ") + " " + endElements.join(" "); |
3436 popoto.provider.getDisplayResultFunction = function (label) { | 3440 popoto.provider.getDisplayResultFunction = function (label) { |
3437 return popoto.provider.getProperty(label, "displayResults"); | 3441 return popoto.provider.getProperty(label, "displayResults"); |
3438 }; | 3442 }; |
3439 | 3443 |
3440 /** | 3444 /** |
3445 * Select the label if there is more than one. | |
3446 * | |
3447 * Discards the label with an underscore. | |
3448 */ | |
3449 popoto.provider.getLabelFilter = function (nodeLabel) { | |
3450 if (Array.isArray(nodeLabel)) { | |
3451 // use last label | |
3452 var label = nodeLabel[nodeLabel.length - 1]; | |
3453 if (label.indexOf('_') == -1 && nodeLabel.length > 1) { | |
3454 // skip if wrong label | |
3455 label = nodeLabel[nodeLabel.length - 2]; | |
3456 } | |
3457 // replace array with string | |
3458 nodeLabel = label; | |
3459 } | |
3460 return nodeLabel; | |
3461 } | |
3462 | |
3463 /** | |
3441 * Label provider used by default if none have been defined for a label. | 3464 * Label provider used by default if none have been defined for a label. |
3442 * This provider can be changed if needed to customize default behavior. | 3465 * This provider can be changed if needed to customize default behavior. |
3443 * If some properties are not found in user customized providers, default values will be extracted from this provider. | 3466 * If some properties are not found in user customized providers, default values will be extracted from this provider. |
3444 */ | 3467 */ |
3445 popoto.provider.DEFAULT_PROVIDER = Object.freeze( | 3468 popoto.provider.DEFAULT_PROVIDER = Object.freeze( |
3504 * This id is used by default because it is a convenient way to identify a node when nothing is known about its attributes. | 3527 * This id is used by default because it is a convenient way to identify a node when nothing is known about its attributes. |
3505 * But you should really consider using your application attributes instead, it is a bad practice to rely on this attribute. | 3528 * But you should really consider using your application attributes instead, it is a bad practice to rely on this attribute. |
3506 */ | 3529 */ |
3507 "constraintAttribute": popoto.query.NEO4J_INTERNAL_ID, | 3530 "constraintAttribute": popoto.query.NEO4J_INTERNAL_ID, |
3508 | 3531 |
3532 /** | |
3533 * Defines the attribute of the node to display as a text identifying the node. | |
3534 * | |
3535 * The default value is the Neo4j internal id. | |
3536 */ | |
3537 "displayAttribute": popoto.query.NEO4J_INTERNAL_ID, | |
3538 | |
3509 /** | 3539 /** |
3510 * Return the list of predefined constraints to add for the given label. | 3540 * Return the list of predefined constraints to add for the given label. |
3511 * These constraints will be added in every generated Cypher query. | 3541 * These constraints will be added in every generated Cypher query. |
3512 * | 3542 * |
3513 * For example if the returned list contain ["$identifier.born > 1976"] for "Person" nodes everywhere in popoto.js the generated Cypher query will add the constraint | 3543 * For example if the returned list contain ["$identifier.born > 1976"] for "Person" nodes everywhere in popoto.js the generated Cypher query will add the constraint |
3589 * @param node the node to represent as text. | 3619 * @param node the node to represent as text. |
3590 * @returns {string} the text representation of the node. | 3620 * @returns {string} the text representation of the node. |
3591 */ | 3621 */ |
3592 "getTextValue": function (node) { | 3622 "getTextValue": function (node) { |
3593 var text; | 3623 var text; |
3594 var constraintAttr = popoto.provider.getProperty(node.label, "constraintAttribute"); | 3624 var textAttr = popoto.provider.getProperty(node.label, "displayAttribute"); |
3595 if (node.type === popoto.graph.node.NodeTypes.VALUE) { | 3625 if (node.type === popoto.graph.node.NodeTypes.VALUE) { |
3596 if (constraintAttr === popoto.query.NEO4J_INTERNAL_ID) { | 3626 if (textAttr === popoto.query.NEO4J_INTERNAL_ID) { |
3597 text = "" + node.internalID; | 3627 text = "" + node.internalID; |
3598 } else { | 3628 } else { |
3599 text = "" + node.attributes[constraintAttr]; | 3629 text = "" + node.attributes[textAttr]; |
3600 } | 3630 } |
3601 } else { | 3631 } else { |
3602 if (node.value === undefined) { | 3632 if (node.value === undefined) { |
3603 text = node.label; | 3633 text = node.label; |
3604 } else { | 3634 } else { |
3605 if (constraintAttr === popoto.query.NEO4J_INTERNAL_ID) { | 3635 if (textAttr === popoto.query.NEO4J_INTERNAL_ID) { |
3606 text = "" + node.value.internalID; | 3636 text = "" + node.value.internalID; |
3607 } else { | 3637 } else { |
3608 text = "" + node.value.attributes[constraintAttr]; | 3638 text = "" + node.value.attributes[textAttr]; |
3609 } | 3639 } |
3610 } | 3640 } |
3611 } | 3641 } |
3612 // Text is truncated to fill the ellipse | 3642 // Text is truncated to fill the ellipse |
3613 return text.substring(0, popoto.graph.node.NODE_MAX_CHARS); | 3643 return text.substring(0, popoto.graph.node.NODE_MAX_CHARS); |
3623 * @param node the node to represent as text. | 3653 * @param node the node to represent as text. |
3624 * @returns {string} the text semantic representation of the node. | 3654 * @returns {string} the text semantic representation of the node. |
3625 */ | 3655 */ |
3626 "getSemanticValue": function (node) { | 3656 "getSemanticValue": function (node) { |
3627 var text; | 3657 var text; |
3628 var constraintAttr = popoto.provider.getProperty(node.label, "constraintAttribute"); | 3658 var textAttr = popoto.provider.getProperty(node.label, "displayAttribute"); |
3629 if (node.type === popoto.graph.node.NodeTypes.VALUE) { | 3659 if (node.type === popoto.graph.node.NodeTypes.VALUE) { |
3630 if (constraintAttr === popoto.query.NEO4J_INTERNAL_ID) { | 3660 if (textAttr === popoto.query.NEO4J_INTERNAL_ID) { |
3631 text = "" + node.internalID; | 3661 text = "" + node.internalID; |
3632 } else { | 3662 } else { |
3633 text = "" + node.attributes[constraintAttr]; | 3663 text = "" + node.attributes[textAttr]; |
3634 } | 3664 } |
3635 } else { | 3665 } else { |
3636 if (node.value === undefined) { | 3666 if (node.value === undefined) { |
3637 text = node.label; | 3667 text = node.label; |
3638 } else { | 3668 } else { |
3639 if (constraintAttr === popoto.query.NEO4J_INTERNAL_ID) { | 3669 if (textAttr === popoto.query.NEO4J_INTERNAL_ID) { |
3640 text = "" + node.value.internalID; | 3670 text = "" + node.value.internalID; |
3641 } else { | 3671 } else { |
3642 text = "" + node.value.attributes[constraintAttr]; | 3672 text = "" + node.value.attributes[textAttr]; |
3643 } | 3673 } |
3644 } | 3674 } |
3645 } | 3675 } |
3646 return text; | 3676 return text; |
3647 }, | 3677 }, |