How to wrap the text inside a shape using Cytoscape?
Asked Answered
A

1

7

I'm trying to build tiles using Cytoscape. Basically, each rectangle (tile) has a title and I want it to be written within the limits of that rectangle.

My code is:

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

  style: [
    {
      selector: 'node',
      css: {
        'shape': 'rectangle',
        'width': '200',
        'height': '150',
        'content': 'data(name)',
        'text-wrap': 'wrap',
        'text-valign': 'center',
        'text-halign': 'center',
        'text-transform': 'uppercase'
      }
    }, ///

And:

elements: {
    nodes: [
      { data: { id: 'F1', name: 'This is my very long text long text long text long text long text long text long text'} },
      { data: { id: 'F2' } },
      { data: { id: 'c', parent: 'b' } },
      { data: { id: 'd' } },
      { data: { id: 'e' } },
      { data: { id: 'f', parent: 'e' } }
    ],///

But it seems the text-wrap value isn't being read. I get:

Can anyone help with this?

Thanks in advance!

Page

Adulterine answered 23/7, 2015 at 17:18 Comment(0)
R
6

You've set text-wrap: wrap so text wrapping is enabled. You haven't specified any rules for how you want the text wrapped. Options:

(1) Use manual newlines (i.e. '\n')

(2) Set text-max-width to the maximum line length, as desired

Rahmann answered 29/7, 2015 at 18:40 Comment(4)
Can we set dynamic values? Node sizes might change. I don't want to put hardcoded values like 100pxDiastole
Every property is mappable.Rahmann
How can I map from text length? I tried "text-max-width": "mapData(title.length, 0, 100, 0px, 100px)" it seems like not workingDiastole
@Rahmann What if I want to wrap a text that does not have any newlines? I am trying to use "'text-max-width': 1, 'text-overflow-wrap': 'anywhere',", but failing miserably for hours.Sporophyll

© 2022 - 2024 — McMap. All rights reserved.