Skip to content

Commit 084b5bd

Browse files
authored
Merge pull request #7 from daveseah/dev-bl/edge-entry
Edge Entry Prototype
2 parents 9c0075b + fc45322 commit 084b5bd

14 files changed

+5098
-226
lines changed

build/app/assets/htmldemos/d3forcedemo/data.reducedlinks.json

Lines changed: 2500 additions & 0 deletions
Large diffs are not rendered by default.

build/app/view/autocompletedemo/AutoCompleteDemo.jsx

Lines changed: 501 additions & 12 deletions
Large diffs are not rendered by default.

build/app/view/autocompletedemo/components/AutoComplete.css

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,17 @@ svg {
7575
flex-basis: 100%;
7676
min-width: 200px;
7777
}
78+
/* D3SimpleNetGraph redo removes links group...
7879
svg .links line {
7980
stroke: #aaa;
81+
}
82+
... and replaces with .edge */
83+
svg .edge {
84+
stroke: #aaa;
85+
}
86+
svg .edge.selected {
87+
stroke: #f00;
88+
stroke-width: 5px;
8089
}
8190
svg .nodes circle {
8291
pointer-events: all;
@@ -86,3 +95,6 @@ svg .nodes text {
8695
stroke: #666;
8796
stroke-width: 0px;
8897
}
98+
.noselect {
99+
user-select: none;
100+
}

build/app/view/autocompletedemo/components/AutoComplete.jsx

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,40 @@ const Autosuggest = require('react-autosuggest');
66
/******************************************************************************/
77
/*/
88
9+
AutoComplete is the text input field for entering node labels to:
10+
* search for nodes,
11+
* edit existing nodes,
12+
* and add new nodes.
13+
14+
Main features:
15+
16+
* It interactively provides a list of suggestions that match the current
17+
input, e.g. typing "ah" will display a list of suggestions including "Ah
18+
Long", "Ah Seung", and "Oahu Railroad Station".
19+
20+
* Users can highlight suggestions (via mouseover or with keyboard arrows)
21+
22+
* Users can select a suggestion (via clicking or hitting return)
23+
24+
AutoComplete is a wrapper class for the open source AutoSuggest component,
25+
which handles the actual rendering of the suggestions list. AutoComplete
26+
provides an interface to NodeSelector and EdgeEntry. AutoComplete also
27+
provides the handler routines for generating the suggestions list and
28+
handling highlights and selections.
29+
30+
31+
932
This relies on the react-autosuggest component.
1033
See documentation: https://github.com/moroshko/react-autosuggest
1134
1235
1336
To Use:
1437
<AutoComplete
38+
1539
data={this.state.data}
40+
value={label}
1641
disableSuggestions={this.state.canEdit}
42+
1743
onInputChange={this.handleInputChange}
1844
onSelection={this.handleNodeSelection}
1945
onHighlight={this.handleSuggestionHighlight}
@@ -26,8 +52,8 @@ const Autosuggest = require('react-autosuggest');
2652
data is mapped to this.props.data
2753
This is how graph data is passed to the AutoComplete component.
2854
29-
requestClearValue is mapped to this.props.clearValue
30-
Parent component can call this to clear the input field.
55+
value is mapped to this.props.setValue
56+
Use this to set the autocomplete value externally.
3157
3258
disableSuggesions is mapped to this.props.disabled
3359
Set to true to stop making suggestions
@@ -171,7 +197,7 @@ class AutoComplete extends React.Component {
171197
onSuggestionSelected (event, { suggestion }) {
172198
// call parent handler
173199
if (suggestion.isAddNew) {
174-
console.log('Add new:', this.state.value, 'suggestion',suggestion);
200+
// console.log('Add new:', this.state.value, 'suggestion',suggestion);
175201
this.props.onSelection( this.state.value )
176202
} else {
177203
this.props.onSelection( suggestion )
@@ -186,13 +212,17 @@ class AutoComplete extends React.Component {
186212
return this.props.disableSuggestions
187213
}
188214

215+
setValue ( value ) {
216+
// console.log('...AutoComplete.setValue to',value)
217+
this.setState({value: value})
218+
}
189219
clearValue () {
190220
this.setState({value:''})
191221
}
192222

193223
componentWillReceiveProps (nextProps) {
194224
// console.log('AutoComplete: componentWillReceiveProps',nextProps)
195-
if (nextProps.requestClearValue) this.clearValue()
225+
if (nextProps.value!==undefined) this.setValue( nextProps.value )
196226
}
197227

198228
render() {

build/app/view/autocompletedemo/components/D3NetGraph.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@
88
NetGraph calls SetData whenever it receives an updated data object.
99
This triggers D3NetGraph to redraw itself.
1010
11+
DEPRECATED
12+
This implementation was problematic because newly-added links would not be
13+
properly updated. The problem likely had to do with:
14+
* Not using a proper link id based on source.id + target.id
15+
* Using saved references to objects that could get outdated with
16+
data joins/merges/updates.
17+
Use `D3SimpleNetGraph.js` instead.
18+
1119
\*\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ * //////////////////////////////////////*/
1220

1321

@@ -152,12 +160,13 @@ class D3NetGraph {
152160
.on("end", (d) => { this._Dragended(d, this) }))
153161

154162
// UPDATE SELECTION
163+
// If a node is not selected, its d.selected value is ''.
155164
this.node.merge(nodeRoot).selectAll("circle")
156-
.attr("stroke", function(d) { if (d.selected) return '#000'; })
165+
.attr("stroke", function(d) { if (d.selected) return d.selected; })
157166
.attr("stroke-width", function(d) { if (d.selected) return '5px'; })
158167
this.node.merge(nodeRoot).selectAll("text")
168+
.attr("color", function(d) { if (d.selected) return d.selected; })
159169
.attr("font-weight", function(d) { if (d.selected) return 'bold'; })
160-
.attr("color", function(d) { if (d.selected) return '#000'; })
161170

162171
// ENTER Add Group Items
163172
this.node.append("circle")

0 commit comments

Comments
 (0)