Skip to content

Commit 01de8fd

Browse files
authored
[Feature] add new option node_overflow to allow to wrap the text in a node (#425)
* add new option node_overflow to allow to wrap the text in a node * add docs for the new option * update version
1 parent f18be10 commit 01de8fd

File tree

9 files changed

+46
-26
lines changed

9 files changed

+46
-26
lines changed

docs/en/2.options.md

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ options = {
3737
line_width:2, // thickness of the mindmap line
3838
line_color:'#555', // Thought mindmap line color
3939
draggable: false, // Drag the mind map with your mouse, when it's larger that the container
40-
hide_scrollbars_when_draggable: false // Hide container scrollbars, when mind map is larger than container and draggable option is true.
40+
hide_scrollbars_when_draggable: false, // Hide container scrollbars, when mind map is larger than container and draggable option is true.
41+
node_overflow: 'hidden' // Text overflow style in node
4142
},
4243
layout:{
4344
hspace:30, // horizontal spacing between nodes
@@ -89,15 +90,10 @@ These options are described in more detail below.
8990
9091
**mode** : (string) layout mode
9192

92-
> When adding a first-level child node to the mind map, jsMind will decide which side to place the node based on this option. 2 layout modes are currently supported::
93+
> When adding a first-level child node to the mind map, jsMind will decide which side to place the node based on this option. 2 layout modes are currently supported:
9394
94-
> * full - child nodes are dynamically distributed on both sides of the root node [default]
95-
> * side - child nodes are distributed only to the right of the root node
96-
97-
> 当往脑图里添加一级子节点时,jsMind 将根据此参数决定把节点放置在哪一侧。目前支持两种布局模式:
98-
99-
> * full - 子节点动态分布在根节点两侧 [默认值]
100-
> * side - 子节点只分布在根节点右侧
95+
> * `full` - child nodes are dynamically distributed on both sides of the root node [default]
96+
> * `side` - child nodes are distributed only to the right of the root node
10197
10298
> Note that this option only takes effect when adding nodes (`jsMind.add_node(...)`)
10399
@@ -118,8 +114,8 @@ These options are described in more detail below.
118114

119115
> jsMind now supports two line drawing engines:
120116
121-
> * CANVAS - Draw the lines on the canvas [default]
122-
> * SVG - Using SVG to draw lines, when there are a lot of nodes and a huge area in the mind map, using this mode can bring significant performance improvements
117+
> * `canvas` - Draw the lines on the canvas [default]
118+
> * `svg` - Using SVG to draw lines, when there are a lot of nodes and a huge area in the mind map, using this mode can bring significant performance improvements
123119
124120
**view.hmargin** : (number) Minimum horizontal distance (in pixels) of the mindmap from the container frame
125121
**view.vmargin** : (number) Minimum vertical distance (in pixels) of the mindmap from the outer container frame
@@ -141,6 +137,13 @@ These options are described in more detail below.
141137
> The default value of this parameter is false, as it keep the default behavior with vertical and horizontal scrollbars on the container when mind map is bigger than the container.
142138
> Otherwise, if true, there is no more scrollbars, and instead you can drag the mind map with your mouse, while button is down. It should be noted that in this case, the user will not be able to explore the mind map by rolling the mouse wheel.
143139
140+
**view.node_overflow** : (string) Text overflow style in node (since 0.5.3)
141+
142+
> 2 styles are currently supported when the node text is too long
143+
144+
> * `hidden` - Hide part of them to maintain the overall readability of the mind map [default]
145+
> * `wrap` - Wrap the text to display the entire content
146+
144147
**layout.hspace** : horizontal distance (pixels) between (number) nodes
145148
**layout.vspace** : vertical spacing (pixels) between (number) nodes
146149

docs/zh/2.options.md

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ options = {
3737
line_width:2, // 思维导图线条的粗细
3838
line_color:'#555', // 思维导图线条的颜色
3939
draggable: false, // 当容器不能完全容纳思维导图时,是否允许拖动画布代替鼠标滚动
40-
hide_scrollbars_when_draggable: false // 当设置 draggable = true 时,是否隐藏滚动条
40+
hide_scrollbars_when_draggable: false, // 当设置 draggable = true 时,是否隐藏滚动条
41+
node_overflow: 'hidden' // 节点文本过长时的样式
4142
},
4243
layout:{
4344
hspace:30, // 节点之间的水平间距
@@ -89,8 +90,8 @@ options = {
8990

9091
> 当往脑图里添加一级子节点时,jsMind 将根据此参数决定把节点放置在哪一侧。目前支持两种布局模式:
9192
92-
> * full - 子节点动态分布在根节点两侧 [默认值]
93-
> * side - 子节点只分布在根节点右侧
93+
> * `full` - 子节点动态分布在根节点两侧 [默认值]
94+
> * `side` - 子节点只分布在根节点右侧
9495
9596
> 需要注意的是,此参数只在添加节点时(`jsMind.add_node(...)`)生效。
9697
@@ -111,8 +112,8 @@ options = {
111112

112113
> jsMind 现支持两种线条的绘制引擎:
113114
114-
> * canvas - 把线条绘制在 canvas 上 [默认值]
115-
> * svg - 使用 svg 绘制线条,当思维导图的节点很多,面积巨大的时候,使用该模式能带来显著的性能提升
115+
> * `canvas` - 把线条绘制在 canvas 上 [默认值]
116+
> * `svg` - 使用 svg 绘制线条,当思维导图的节点很多,面积巨大的时候,使用该模式能带来显著的性能提升
116117
117118
**view.hmargin** : (number) 思维导图距容器外框的最小水平距离(像素)
118119
**view.vmargin** : (number) 思维导图距容器外框的最小垂直距离(像素)
@@ -133,6 +134,13 @@ options = {
133134
> 此参数仅当 `view.draggable` 为 true 时生效,其用于设置是否隐藏水平和垂直容器内的滚动条。
134135
> 此参数的默认值为 `false` (显示滚动条),当设置为 `true` 时,容器内的滚动条将会被隐藏,用户无法通过滚动鼠标滚轮的方式查看思维导图的不同部分。
135136
137+
**view.node_overflow** : (string) 节点文本过长时的样式 (0.5.3 及以上版本支持)
138+
139+
> 节点文本过长时,jsMind 支持两种样式:
140+
141+
> * `hidden` - 隐藏部分文本以保持脑图的整体易读性 [默认值]
142+
> * `wrap` - 对文本进行换行,以展示全部文本内容
143+
136144
**layout.hspace** : (number) 节点之间的水平间距(像素)
137145
**layout.vspace** : (number) 节点之间的垂直间距(像素)
138146

js/jsmind.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@
6262
line_width: 2,
6363
line_color: '#555',
6464
draggable: false, // drag the mind map with your mouse, when it's larger that the container
65-
hide_scrollbars_when_draggable: false // hide container scrollbars, when mind map is larger than container and draggable option is true.
65+
hide_scrollbars_when_draggable: false, // hide container scrollbars, when mind map is larger than container and draggable option is true.
66+
node_overflow: 'hidden' // hidden or wrap
6667
},
6768
layout: {
6869
hspace: 30,
@@ -1025,7 +1026,8 @@
10251026
line_width: opts.view.line_width,
10261027
line_color: opts.view.line_color,
10271028
draggable: opts.view.draggable,
1028-
hide_scrollbars_when_draggable: opts.view.hide_scrollbars_when_draggable
1029+
hide_scrollbars_when_draggable: opts.view.hide_scrollbars_when_draggable,
1030+
node_overflow: opts.view.node_overflow
10291031
};
10301032
// create instance of function provider
10311033
this.data = new jm.data_provider(this);
@@ -2293,8 +2295,7 @@
22932295
this.e_editor = $c('input');
22942296

22952297
this.graph = this.opts.engine.toLowerCase() === 'svg' ? new jm.graph_svg(this) : new jm.graph_canvas(this);
2296-
2297-
this.e_panel.className = 'jsmind-inner';
2298+
this.e_panel.className = 'jsmind-inner jmnode-overflow-' + this.opts.node_overflow;
22982299
this.e_panel.tabIndex = 1;
22992300
this.e_panel.appendChild(this.graph.element());
23002301
this.e_panel.appendChild(this.e_nodes);

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "jsmind",
3-
"version": "0.5.2",
3+
"version": "0.5.3",
44
"description": "jsMind is a pure javascript library for mindmap, it base on html5 canvas. jsMind was released under BSD license, you can embed it in any project, if only you observe the license.",
55
"main": "js/jsmind.js",
66
"directories": {

src/jsmind.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ export default class jsMind {
6161
line_color: this.options.view.line_color,
6262
draggable: this.options.view.draggable,
6363
hide_scrollbars_when_draggable: this.options.view.hide_scrollbars_when_draggable,
64+
node_overflow: this.options.view.node_overflow,
6465
};
6566
// create instance of function provider
6667
this.data = new DataProvider(this);

src/jsmind.option.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ const default_options = {
2424
line_color: '#555',
2525
draggable: false, // drag the mind map with your mouse, when it's larger that the container
2626
hide_scrollbars_when_draggable: false, // hide container scrollbars, when mind map is larger than container and draggable option is true.
27+
node_overflow: 'hidden', // hidden or wrap
2728
},
2829
layout: {
2930
hspace: 30,

src/jsmind.view_provider.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export class ViewProvider {
4141
this.e_panel = $.c('div');
4242
this.e_nodes = $.c('jmnodes');
4343
this.e_editor = $.c('input');
44-
this.e_panel.className = 'jsmind-inner';
44+
this.e_panel.className = 'jsmind-inner jmnode-overflow-' + this.opts.node_overflow;
4545
this.e_panel.tabIndex = 1;
4646
this.e_panel.appendChild(this.graph.element());
4747
this.e_panel.appendChild(this.e_nodes);

style/jsmind.css

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,6 @@ jmnode {
4848
position: absolute;
4949
cursor: default;
5050
max-width: 400px;
51-
white-space: nowrap;
52-
overflow: hidden;
53-
text-overflow: ellipsis;
5451
}
5552
jmexpander {
5653
position: absolute;
@@ -67,6 +64,15 @@ jmexpander {
6764
cursor: pointer;
6865
}
6966

67+
.jmnode-overflow-wrap jmnodes {
68+
min-width: 420px;
69+
}
70+
71+
.jmnode-overflow-hidden jmnode {
72+
white-space: nowrap;
73+
overflow: hidden;
74+
text-overflow: ellipsis;
75+
}
7076
/* default theme */
7177
jmnode {
7278
padding: 10px;

0 commit comments

Comments
 (0)