Skip to content

Commit 0ba027d

Browse files
committed
Graph mouse overs.
Signed-off-by: Grant Skinner <[email protected]>
1 parent 4d0cfbe commit 0ba027d

File tree

3 files changed

+29
-6
lines changed

3 files changed

+29
-6
lines changed

js/utils/Graph.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,22 @@ var ExpressionHighlighter = require('../ExpressionHighlighter');
2828

2929
var Graph = {};
3030

31-
Graph.forExpression = function(expr, token) {
31+
Graph.forExpression = function(expr, token, highlighter) {
3232
var groupClasses = ExpressionHighlighter.GROUP_CLASS_BY_TYPE, pre = "exp-";
3333
var result = $.div(null, "graph"), el = result;
34+
35+
var enterHandler = function(evt) {
36+
var o = evt.currentTarget;
37+
highlighter.selectToken(o.token);
38+
$.addClass(o, "selected");
39+
evt.stopPropagation();
40+
};
41+
var exitHandler = function(evt) {
42+
highlighter.selectToken(null);
43+
$.removeClass(evt.currentTarget, "selected");
44+
evt.stopPropagation();
45+
};
46+
3447
while ((token = token.next) && (token.type != "close")) {
3548
if (token.proxy) { continue; }
3649

@@ -68,6 +81,12 @@ Graph.forExpression = function(expr, token) {
6881
if (token.err) {
6982
$.addClass(div, "error");
7083
}
84+
85+
if (!token.open) {
86+
div.token = token;
87+
div.addEventListener("mouseover", enterHandler);
88+
div.addEventListener("mouseout", exitHandler);
89+
}
7190
}
7291

7392
return result;

js/views/DocView.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -628,7 +628,7 @@ p.updateTool = function (source, regex) {
628628
$.el(".content",this.toolsResults).innerHTML = "<code><pre>"+result+"</code></pre>";
629629
} else if (this.tool == "graph") {
630630
var token = this.exprLexer.token, expr = this.expressionCM.getValue();
631-
result = Graph.forExpression(expr, token);
631+
result = Graph.forExpression(expr, token, this.expressionHighlighter);
632632
$.empty($.el(".content",this.toolsResults)).appendChild(result);
633633
}
634634
};

scss/views/docView.scss

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,21 +138,25 @@
138138

139139
.tools .graph {
140140
div {
141-
padding: 0.5em;
141+
padding: calc(0.5em + 1px);
142142
margin-top: 0.75em;
143143
display: block;
144144
border: solid 1px rgba($title-bg,0.5);
145145
color: rgba(0,0,0,0.66);
146146
}
147147

148+
.selected {
149+
border: solid 2px $title-bg;
150+
padding: 0.5em;
151+
}
152+
148153
:first-child {
149154
margin-top: 0;
150155
}
151156

152-
.related {
153-
margin-top: 0;
157+
div.related {
158+
margin-top: -1px;
154159
background: rgba($title-bg,0.33);
155-
border-top: none;
156160
}
157161

158162
.error {

0 commit comments

Comments
 (0)