0

With cytoscape.js I want to get two effects at the same time:

  1. to show directed arrows for the arcs between nodes AND
  2. to show custom-made labels for the arcs between nodes.

With the code available below I can only get arc labels shown but not arrows.

If I remove from the code the segment

style: {'label': 'data(label)'},

then I can get arrows to be shown but the arc labels disappear.

I am planning to use my code in a relatively complex system of various separate js libraries etc. and thus I would like to hear a solution that can be flexibly used in various conditions. Thanks for your kind help.

<!DOCTYPE>

<html>

<head>
    <title>cytoscape-springy.js demo</title>
    <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1, maximum-scale=1">

    <script src="jquery.min.js"></script>
    <script src="cytoscape.min.js"></script>
    <script src="springy.js"></script>
    <script src="./cytoscape-springy.js"></script>

    <style>

        #cy {
            width: 100%;
            height: 100%;
            position: absolute;
        //  left: 0;
        //  top: 0;
            z-index: 999;
        }


    </style>

    <script>
        $(function(){

            var cy = window.cy = cytoscape({
                container: document.getElementById('cy'),

                layout: {
                    name: 'springy',
                    directed: true
                },

                style: [

                    {
                        selector: 'node',
                        css: {
                            'content': 'data(name)'
                        }
                    },

                    {
                        selector: 'edge',

                        // to get a custom label shown for each arc
                        style: {
                        'label': 'data(label)'
                        },

                        // to get an arrowhead shown for each arc
                        css: {
                            'curve-style': 'bezier',
                            'target-arrow-shape': 'triangle',
                            'target-arrow-color': 'black',
                            'line-color': 'black',
                            'width': 3
                        }

                    }
                ],

                elements: {
                    nodes: [
                        { data: { id: 'a', name: 'a' } },
                        { data: { id: 'b', name: 'b' } },
                        { data: { id: 'c', name: 'c' } }
                    ],
                    edges: [
                        { data: { source: 'a', target: 'b', label: 'a_to_b' } },
                        { data: { source: 'b', target: 'c', label: 'b_to_c' } },
                        { data: { source: 'c', target: 'a', label: 'c_to_a' } }
                    ]
                },
            });

        });
    </script>
</head>

<body>
    <h1>cytoscape-springy demo</h1>

    <div id="cy"></div>

</body>

</html>

1 Answers1

0

Specify one key -- a style or css key -- but not both.

                    style: {
                        'label': 'data(label)',
                        'curve-style': 'bezier',
                        'target-arrow-shape': 'triangle',
                        'target-arrow-color': 'black',
                        'line-color': 'black',
                        'width': 3
                    }
maxkfranz
  • 11,896
  • 1
  • 27
  • 36