Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
CodeMirror
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Moritz Aurel Pascal Schubotz
CodeMirror
Commits
075c33bb
Commit
075c33bb
authored
12 years ago
by
Marijn Haverbeke
Browse files
Options
Downloads
Patches
Plain Diff
Add internal document tree visualization demo
As shown at GOTO Aarhus this month
parent
d3e3d07f
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
demo/btree.html
+87
-0
87 additions, 0 deletions
demo/btree.html
index.html
+1
-0
1 addition, 0 deletions
index.html
with
88 additions
and
0 deletions
demo/btree.html
0 → 100644
+
87
−
0
View file @
075c33bb
<!doctype html>
<html>
<head>
<meta
charset=
"utf-8"
>
<title>
CodeMirror: B-Tree visualization
</title>
<link
rel=
"stylesheet"
href=
"../lib/codemirror.css"
>
<script
src=
"../lib/codemirror.js"
></script>
<link
rel=
"stylesheet"
href=
"../doc/docs.css"
>
<style
type=
"text/css"
>
.lineblock
{
display
:
inline-block
;
margin
:
1px
;
height
:
5px
;
}
.CodeMirror
{
border
:
1px
solid
#aaa
;
height
:
400px
}
</style>
</head>
<body>
<h1>
CodeMirror: B-Tree visualization
</h1>
<p>
Shows a visual representation of the b-tree that CodeMirror
uses to store its document. See
the
<a
href=
"http://marijnhaverbeke.nl/blog/codemirror-line-tree.html"
>
corresponding
blog post
</a>
for a description of this format. The gray blocks
under each leaf show the lines it holds (with their width
representing the line height). Add and remove content to see how
the nodes are split and merged to keep the tree balanced.
</p>
<div
style=
"position: relative"
>
<div
style=
"width: 60%; display: inline-block; vertical-align: top"
>
<form><textarea
id=
"code"
name=
"code"
>
type here, see a summary of the document b-tree to the right
</textarea></form>
</div>
<div
style=
"display: inline-block; height: 402px; overflow-y: auto"
id=
"output"
></div>
</div>
<script
id=
"me"
>
var
editor
=
CodeMirror
.
fromTextArea
(
document
.
getElementById
(
"
code
"
),
{
lineNumbers
:
true
,
lineWrapping
:
true
});
var
updateTimeout
;
editor
.
on
(
"
change
"
,
function
(
cm
)
{
clearTimeout
(
updateTimeout
);
updateTimeout
=
setTimeout
(
updateVisual
,
200
);
});
updateVisual
();
function
updateVisual
()
{
var
out
=
document
.
getElementById
(
"
output
"
);
out
.
innerHTML
=
""
;
function
drawTree
(
out
,
node
)
{
if
(
node
.
lines
)
{
out
.
appendChild
(
document
.
createElement
(
"
div
"
)).
innerHTML
=
"
<b>leaf</b>:
"
+
node
.
lines
.
length
+
"
lines,
"
+
Math
.
round
(
node
.
height
)
+
"
px
"
;
var
lines
=
out
.
appendChild
(
document
.
createElement
(
"
div
"
));
lines
.
style
.
lineHeight
=
"
6px
"
;
lines
.
style
.
marginLeft
=
"
10px
"
;
for
(
var
i
=
0
;
i
<
node
.
lines
.
length
;
++
i
)
{
var
line
=
node
.
lines
[
i
],
lineElt
=
lines
.
appendChild
(
document
.
createElement
(
"
div
"
));
lineElt
.
className
=
"
lineblock
"
;
var
gray
=
Math
.
min
(
line
.
text
.
length
*
3
,
230
),
col
=
gray
.
toString
(
16
);
if
(
col
.
length
==
1
)
col
=
"
0
"
+
col
;
lineElt
.
style
.
background
=
"
#
"
+
col
+
col
+
col
;
console
.
log
(
line
.
height
,
line
);
lineElt
.
style
.
width
=
Math
.
max
(
Math
.
round
(
line
.
height
/
3
),
1
)
+
"
px
"
;
}
}
else
{
out
.
appendChild
(
document
.
createElement
(
"
div
"
)).
innerHTML
=
"
<b>node</b>:
"
+
node
.
size
+
"
lines,
"
+
Math
.
round
(
node
.
height
)
+
"
px
"
;
var
sub
=
out
.
appendChild
(
document
.
createElement
(
"
div
"
));
sub
.
style
.
paddingLeft
=
"
20px
"
;
for
(
var
i
=
0
;
i
<
node
.
children
.
length
;
++
i
)
drawTree
(
sub
,
node
.
children
[
i
]);
}
}
drawTree
(
out
,
editor
.
view
.
doc
);
}
function
fillEditor
()
{
var
sc
=
document
.
getElementById
(
"
me
"
);
var
doc
=
(
sc
.
textContent
||
sc
.
innerText
||
sc
.
innerHTML
).
replace
(
/^
\s
*/
,
""
)
+
"
\n
"
;
doc
+=
doc
;
doc
+=
doc
;
doc
+=
doc
;
doc
+=
doc
;
doc
+=
doc
;
doc
+=
doc
;
editor
.
setValue
(
doc
);
}
</script>
<p><button
onclick=
"fillEditor()"
>
Add a lot of content
</button></p>
</body>
</html>
This diff is collapsed.
Click to expand it.
index.html
+
1
−
0
View file @
075c33bb
...
...
@@ -116,6 +116,7 @@
<li><a
href=
"demo/vim.html"
>
Vim keybindings
</a></li>
<li><a
href=
"demo/closetag.html"
>
Automatic xml tag closing
</a></li>
<li><a
href=
"demo/loadmode.html"
>
Lazy mode loading
</a></li>
<li><a
href=
"demo/btree.html"
>
Document tree visualization
</a></li>
</ul>
<h2>
Real-world uses:
</h2>
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment