Mercurial > code > home > repos > light9
annotate light9/web/graph.coffee @ 1789:d8ae388a8076
autodeps: try pruning some unrelated patches
Ignore-this: 5382b18ab437706b00ecc9dad6c08f0
author | Drew Perttula <drewp@bigasterisk.com> |
---|---|
date | Thu, 07 Jun 2018 17:42:36 +0000 |
parents | 11affc6d6045 |
children | a07bfbe1e9de |
rev | line source |
---|---|
1346
2809a8b732f6
optimize graph lookup calls during zoom steps
Drew Perttula <drewp@bigasterisk.com>
parents:
1334
diff
changeset
|
1 log = console.log |
2809a8b732f6
optimize graph lookup calls during zoom steps
Drew Perttula <drewp@bigasterisk.com>
parents:
1334
diff
changeset
|
2 |
1317
4c6d88aa9e26
enough element and rdf support to drag one adjuster and see its value change
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
3 # Patch is {addQuads: <quads>, delQuads: <quads>} |
1708
8d3569829198
more upgrades for n3 api. not quite passing
drewp@bigasterisk.com
parents:
1707
diff
changeset
|
4 # <quads> are made with Quad(s,p,o,g) |
1317
4c6d88aa9e26
enough element and rdf support to drag one adjuster and see its value change
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
5 |
1362
168262618f2d
new test_js target for testing SyncedGraph
Drew Perttula <drewp@bigasterisk.com>
parents:
1361
diff
changeset
|
6 # for mocha |
168262618f2d
new test_js target for testing SyncedGraph
Drew Perttula <drewp@bigasterisk.com>
parents:
1361
diff
changeset
|
7 if require? |
168262618f2d
new test_js target for testing SyncedGraph
Drew Perttula <drewp@bigasterisk.com>
parents:
1361
diff
changeset
|
8 `window = {}` |
1707 | 9 `_ = require('./lib/underscore/underscore-min.js')` |
1706
e30493d458f9
more npm setup. n3 upgraded but code is not, yet
drewp@bigasterisk.com
parents:
1651
diff
changeset
|
10 `N3 = require('../../node_modules/n3/n3-browser.js')` |
e30493d458f9
more npm setup. n3 upgraded but code is not, yet
drewp@bigasterisk.com
parents:
1651
diff
changeset
|
11 `d3 = require('../../node_modules/d3/dist/d3.min.js')` |
1362
168262618f2d
new test_js target for testing SyncedGraph
Drew Perttula <drewp@bigasterisk.com>
parents:
1361
diff
changeset
|
12 `RdfDbClient = require('./rdfdbclient.js').RdfDbClient` |
168262618f2d
new test_js target for testing SyncedGraph
Drew Perttula <drewp@bigasterisk.com>
parents:
1361
diff
changeset
|
13 module.exports = window |
168262618f2d
new test_js target for testing SyncedGraph
Drew Perttula <drewp@bigasterisk.com>
parents:
1361
diff
changeset
|
14 |
1363
233b81d9bd9d
simple first version of SyncedGraph.runHandler
Drew Perttula <drewp@bigasterisk.com>
parents:
1362
diff
changeset
|
15 RDF = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#' |
233b81d9bd9d
simple first version of SyncedGraph.runHandler
Drew Perttula <drewp@bigasterisk.com>
parents:
1362
diff
changeset
|
16 |
233b81d9bd9d
simple first version of SyncedGraph.runHandler
Drew Perttula <drewp@bigasterisk.com>
parents:
1362
diff
changeset
|
17 patchSizeSummary = (patch) -> |
1350
36f58b2aa8ef
browser syncedgraph sends patches back to server
Drew Perttula <drewp@bigasterisk.com>
parents:
1347
diff
changeset
|
18 '-' + patch.delQuads.length + ' +' + patch.addQuads.length |
36f58b2aa8ef
browser syncedgraph sends patches back to server
Drew Perttula <drewp@bigasterisk.com>
parents:
1347
diff
changeset
|
19 |
1363
233b81d9bd9d
simple first version of SyncedGraph.runHandler
Drew Perttula <drewp@bigasterisk.com>
parents:
1362
diff
changeset
|
20 # (sloppily shared to rdfdbclient.coffee too) |
233b81d9bd9d
simple first version of SyncedGraph.runHandler
Drew Perttula <drewp@bigasterisk.com>
parents:
1362
diff
changeset
|
21 window.patchSizeSummary = patchSizeSummary |
233b81d9bd9d
simple first version of SyncedGraph.runHandler
Drew Perttula <drewp@bigasterisk.com>
parents:
1362
diff
changeset
|
22 |
1786
11affc6d6045
more graph methods. some cleanup of the code that runs only required handlers, but it's not turned on yet
Drew Perttula <drewp@bigasterisk.com>
parents:
1783
diff
changeset
|
23 patchContainsPreds = (patch, preds) -> |
11affc6d6045
more graph methods. some cleanup of the code that runs only required handlers, but it's not turned on yet
Drew Perttula <drewp@bigasterisk.com>
parents:
1783
diff
changeset
|
24 if patch._allPreds == undefined |
11affc6d6045
more graph methods. some cleanup of the code that runs only required handlers, but it's not turned on yet
Drew Perttula <drewp@bigasterisk.com>
parents:
1783
diff
changeset
|
25 patch._allPreds = new Set() |
11affc6d6045
more graph methods. some cleanup of the code that runs only required handlers, but it's not turned on yet
Drew Perttula <drewp@bigasterisk.com>
parents:
1783
diff
changeset
|
26 for qq in [patch.addQuads, patch.delQuads] |
11affc6d6045
more graph methods. some cleanup of the code that runs only required handlers, but it's not turned on yet
Drew Perttula <drewp@bigasterisk.com>
parents:
1783
diff
changeset
|
27 for q in qq |
11affc6d6045
more graph methods. some cleanup of the code that runs only required handlers, but it's not turned on yet
Drew Perttula <drewp@bigasterisk.com>
parents:
1783
diff
changeset
|
28 patch._allPreds.add(q.predicate.value) |
11affc6d6045
more graph methods. some cleanup of the code that runs only required handlers, but it's not turned on yet
Drew Perttula <drewp@bigasterisk.com>
parents:
1783
diff
changeset
|
29 |
11affc6d6045
more graph methods. some cleanup of the code that runs only required handlers, but it's not turned on yet
Drew Perttula <drewp@bigasterisk.com>
parents:
1783
diff
changeset
|
30 for p in preds |
11affc6d6045
more graph methods. some cleanup of the code that runs only required handlers, but it's not turned on yet
Drew Perttula <drewp@bigasterisk.com>
parents:
1783
diff
changeset
|
31 if patch._allPreds.has(p.value) |
11affc6d6045
more graph methods. some cleanup of the code that runs only required handlers, but it's not turned on yet
Drew Perttula <drewp@bigasterisk.com>
parents:
1783
diff
changeset
|
32 return true |
11affc6d6045
more graph methods. some cleanup of the code that runs only required handlers, but it's not turned on yet
Drew Perttula <drewp@bigasterisk.com>
parents:
1783
diff
changeset
|
33 return false |
11affc6d6045
more graph methods. some cleanup of the code that runs only required handlers, but it's not turned on yet
Drew Perttula <drewp@bigasterisk.com>
parents:
1783
diff
changeset
|
34 |
11affc6d6045
more graph methods. some cleanup of the code that runs only required handlers, but it's not turned on yet
Drew Perttula <drewp@bigasterisk.com>
parents:
1783
diff
changeset
|
35 allPatchSubjs = (patch) -> # returns subjs as Set of strings |
11affc6d6045
more graph methods. some cleanup of the code that runs only required handlers, but it's not turned on yet
Drew Perttula <drewp@bigasterisk.com>
parents:
1783
diff
changeset
|
36 out = new Set() |
11affc6d6045
more graph methods. some cleanup of the code that runs only required handlers, but it's not turned on yet
Drew Perttula <drewp@bigasterisk.com>
parents:
1783
diff
changeset
|
37 if patch._allSubjs == undefined |
11affc6d6045
more graph methods. some cleanup of the code that runs only required handlers, but it's not turned on yet
Drew Perttula <drewp@bigasterisk.com>
parents:
1783
diff
changeset
|
38 patch._allSubjs = new Set() |
11affc6d6045
more graph methods. some cleanup of the code that runs only required handlers, but it's not turned on yet
Drew Perttula <drewp@bigasterisk.com>
parents:
1783
diff
changeset
|
39 for qq in [patch.addQuads, patch.delQuads] |
11affc6d6045
more graph methods. some cleanup of the code that runs only required handlers, but it's not turned on yet
Drew Perttula <drewp@bigasterisk.com>
parents:
1783
diff
changeset
|
40 for q in qq |
11affc6d6045
more graph methods. some cleanup of the code that runs only required handlers, but it's not turned on yet
Drew Perttula <drewp@bigasterisk.com>
parents:
1783
diff
changeset
|
41 patch._allSubjs.add(q.subject.value) |
11affc6d6045
more graph methods. some cleanup of the code that runs only required handlers, but it's not turned on yet
Drew Perttula <drewp@bigasterisk.com>
parents:
1783
diff
changeset
|
42 |
11affc6d6045
more graph methods. some cleanup of the code that runs only required handlers, but it's not turned on yet
Drew Perttula <drewp@bigasterisk.com>
parents:
1783
diff
changeset
|
43 return patch._allSubjs |
11affc6d6045
more graph methods. some cleanup of the code that runs only required handlers, but it's not turned on yet
Drew Perttula <drewp@bigasterisk.com>
parents:
1783
diff
changeset
|
44 |
1363
233b81d9bd9d
simple first version of SyncedGraph.runHandler
Drew Perttula <drewp@bigasterisk.com>
parents:
1362
diff
changeset
|
45 class Handler |
233b81d9bd9d
simple first version of SyncedGraph.runHandler
Drew Perttula <drewp@bigasterisk.com>
parents:
1362
diff
changeset
|
46 # a function and the quad patterns it cared about |
1386
29a1382de5c8
introduce autodep handler tree; only rerun highest-level affected handler and let it rerun its children
Drew Perttula <drewp@bigasterisk.com>
parents:
1383
diff
changeset
|
47 constructor: (@func, @label) -> |
29a1382de5c8
introduce autodep handler tree; only rerun highest-level affected handler and let it rerun its children
Drew Perttula <drewp@bigasterisk.com>
parents:
1383
diff
changeset
|
48 @patterns = [] # s,p,o,g quads that should trigger the next run |
29a1382de5c8
introduce autodep handler tree; only rerun highest-level affected handler and let it rerun its children
Drew Perttula <drewp@bigasterisk.com>
parents:
1383
diff
changeset
|
49 @innerHandlers = [] # Handlers requested while this one was running |
1363
233b81d9bd9d
simple first version of SyncedGraph.runHandler
Drew Perttula <drewp@bigasterisk.com>
parents:
1362
diff
changeset
|
50 |
233b81d9bd9d
simple first version of SyncedGraph.runHandler
Drew Perttula <drewp@bigasterisk.com>
parents:
1362
diff
changeset
|
51 class AutoDependencies |
233b81d9bd9d
simple first version of SyncedGraph.runHandler
Drew Perttula <drewp@bigasterisk.com>
parents:
1362
diff
changeset
|
52 constructor: () -> |
1753
3c997bc6d380
fix some coffee lint
Drew Perttula <drewp@bigasterisk.com>
parents:
1751
diff
changeset
|
53 # tree of all known Handlers (at least those with non-empty |
3c997bc6d380
fix some coffee lint
Drew Perttula <drewp@bigasterisk.com>
parents:
1751
diff
changeset
|
54 # patterns). Top node is not a handler. |
3c997bc6d380
fix some coffee lint
Drew Perttula <drewp@bigasterisk.com>
parents:
1751
diff
changeset
|
55 @handlers = new Handler(null) |
1386
29a1382de5c8
introduce autodep handler tree; only rerun highest-level affected handler and let it rerun its children
Drew Perttula <drewp@bigasterisk.com>
parents:
1383
diff
changeset
|
56 @handlerStack = [@handlers] # currently running |
1363
233b81d9bd9d
simple first version of SyncedGraph.runHandler
Drew Perttula <drewp@bigasterisk.com>
parents:
1362
diff
changeset
|
57 |
1386
29a1382de5c8
introduce autodep handler tree; only rerun highest-level affected handler and let it rerun its children
Drew Perttula <drewp@bigasterisk.com>
parents:
1383
diff
changeset
|
58 runHandler: (func, label) -> |
1363
233b81d9bd9d
simple first version of SyncedGraph.runHandler
Drew Perttula <drewp@bigasterisk.com>
parents:
1362
diff
changeset
|
59 # what if we have this func already? duplicate is safe? |
1386
29a1382de5c8
introduce autodep handler tree; only rerun highest-level affected handler and let it rerun its children
Drew Perttula <drewp@bigasterisk.com>
parents:
1383
diff
changeset
|
60 |
1643
77eaccba654e
try to fix timeline sending empty ctx to rdfdb
Drew Perttula <drewp@bigasterisk.com>
parents:
1624
diff
changeset
|
61 if not label? |
77eaccba654e
try to fix timeline sending empty ctx to rdfdb
Drew Perttula <drewp@bigasterisk.com>
parents:
1624
diff
changeset
|
62 throw new Error("missing label") |
77eaccba654e
try to fix timeline sending empty ctx to rdfdb
Drew Perttula <drewp@bigasterisk.com>
parents:
1624
diff
changeset
|
63 |
1386
29a1382de5c8
introduce autodep handler tree; only rerun highest-level affected handler and let it rerun its children
Drew Perttula <drewp@bigasterisk.com>
parents:
1383
diff
changeset
|
64 h = new Handler(func, label) |
1645
9c5e62615a63
don't let handlers pile up (workaround)
Drew Perttula <drewp@bigasterisk.com>
parents:
1643
diff
changeset
|
65 tailChildren = @handlerStack[@handlerStack.length - 1].innerHandlers |
9c5e62615a63
don't let handlers pile up (workaround)
Drew Perttula <drewp@bigasterisk.com>
parents:
1643
diff
changeset
|
66 matchingLabel = _.filter(tailChildren, ((c) -> c.label == label)).length |
9c5e62615a63
don't let handlers pile up (workaround)
Drew Perttula <drewp@bigasterisk.com>
parents:
1643
diff
changeset
|
67 # ohno, something depends on some handlers getting run twice :( |
9c5e62615a63
don't let handlers pile up (workaround)
Drew Perttula <drewp@bigasterisk.com>
parents:
1643
diff
changeset
|
68 if matchingLabel < 2 |
9c5e62615a63
don't let handlers pile up (workaround)
Drew Perttula <drewp@bigasterisk.com>
parents:
1643
diff
changeset
|
69 tailChildren.push(h) |
1537 | 70 console.time("handler #{label}") |
1494
ea9e8f581eea
WIP optimization for note point dragging
Drew Perttula <drewp@bigasterisk.com>
parents:
1415
diff
changeset
|
71 @_rerunHandler(h, null) |
1537 | 72 console.timeEnd("handler #{label}") |
1651
e00492e1c0b1
include some of the handler tree optimization code, turned off
Drew Perttula <drewp@bigasterisk.com>
parents:
1648
diff
changeset
|
73 #@_logHandlerTree() |
1363
233b81d9bd9d
simple first version of SyncedGraph.runHandler
Drew Perttula <drewp@bigasterisk.com>
parents:
1362
diff
changeset
|
74 |
1494
ea9e8f581eea
WIP optimization for note point dragging
Drew Perttula <drewp@bigasterisk.com>
parents:
1415
diff
changeset
|
75 _rerunHandler: (handler, patch) -> |
1363
233b81d9bd9d
simple first version of SyncedGraph.runHandler
Drew Perttula <drewp@bigasterisk.com>
parents:
1362
diff
changeset
|
76 handler.patterns = [] |
233b81d9bd9d
simple first version of SyncedGraph.runHandler
Drew Perttula <drewp@bigasterisk.com>
parents:
1362
diff
changeset
|
77 @handlerStack.push(handler) |
233b81d9bd9d
simple first version of SyncedGraph.runHandler
Drew Perttula <drewp@bigasterisk.com>
parents:
1362
diff
changeset
|
78 try |
1494
ea9e8f581eea
WIP optimization for note point dragging
Drew Perttula <drewp@bigasterisk.com>
parents:
1415
diff
changeset
|
79 handler.func(patch) |
1363
233b81d9bd9d
simple first version of SyncedGraph.runHandler
Drew Perttula <drewp@bigasterisk.com>
parents:
1362
diff
changeset
|
80 catch e |
233b81d9bd9d
simple first version of SyncedGraph.runHandler
Drew Perttula <drewp@bigasterisk.com>
parents:
1362
diff
changeset
|
81 log('error running handler: ', e) |
233b81d9bd9d
simple first version of SyncedGraph.runHandler
Drew Perttula <drewp@bigasterisk.com>
parents:
1362
diff
changeset
|
82 # assuming here it didn't get to do all its queries, we could |
233b81d9bd9d
simple first version of SyncedGraph.runHandler
Drew Perttula <drewp@bigasterisk.com>
parents:
1362
diff
changeset
|
83 # add a *,*,*,* handler to call for sure the next time? |
233b81d9bd9d
simple first version of SyncedGraph.runHandler
Drew Perttula <drewp@bigasterisk.com>
parents:
1362
diff
changeset
|
84 finally |
233b81d9bd9d
simple first version of SyncedGraph.runHandler
Drew Perttula <drewp@bigasterisk.com>
parents:
1362
diff
changeset
|
85 #log('done. got: ', handler.patterns) |
233b81d9bd9d
simple first version of SyncedGraph.runHandler
Drew Perttula <drewp@bigasterisk.com>
parents:
1362
diff
changeset
|
86 @handlerStack.pop() |
233b81d9bd9d
simple first version of SyncedGraph.runHandler
Drew Perttula <drewp@bigasterisk.com>
parents:
1362
diff
changeset
|
87 # handler might have no watches, in which case we could forget about it |
1645
9c5e62615a63
don't let handlers pile up (workaround)
Drew Perttula <drewp@bigasterisk.com>
parents:
1643
diff
changeset
|
88 |
9c5e62615a63
don't let handlers pile up (workaround)
Drew Perttula <drewp@bigasterisk.com>
parents:
1643
diff
changeset
|
89 _logHandlerTree: -> |
9c5e62615a63
don't let handlers pile up (workaround)
Drew Perttula <drewp@bigasterisk.com>
parents:
1643
diff
changeset
|
90 log('handler tree:') |
9c5e62615a63
don't let handlers pile up (workaround)
Drew Perttula <drewp@bigasterisk.com>
parents:
1643
diff
changeset
|
91 prn = (h, depth) -> |
9c5e62615a63
don't let handlers pile up (workaround)
Drew Perttula <drewp@bigasterisk.com>
parents:
1643
diff
changeset
|
92 indent = '' |
9c5e62615a63
don't let handlers pile up (workaround)
Drew Perttula <drewp@bigasterisk.com>
parents:
1643
diff
changeset
|
93 for i in [0...depth] |
9c5e62615a63
don't let handlers pile up (workaround)
Drew Perttula <drewp@bigasterisk.com>
parents:
1643
diff
changeset
|
94 indent += ' ' |
1647
67347c027b2a
hopefully harmmless steps towards making the handler tree right
Drew Perttula <drewp@bigasterisk.com>
parents:
1646
diff
changeset
|
95 log("#{indent} \"#{h.label}\" #{h.patterns.length} pats") |
1645
9c5e62615a63
don't let handlers pile up (workaround)
Drew Perttula <drewp@bigasterisk.com>
parents:
1643
diff
changeset
|
96 for c in h.innerHandlers |
9c5e62615a63
don't let handlers pile up (workaround)
Drew Perttula <drewp@bigasterisk.com>
parents:
1643
diff
changeset
|
97 prn(c, depth + 1) |
9c5e62615a63
don't let handlers pile up (workaround)
Drew Perttula <drewp@bigasterisk.com>
parents:
1643
diff
changeset
|
98 prn(@handlers, 0) |
1363
233b81d9bd9d
simple first version of SyncedGraph.runHandler
Drew Perttula <drewp@bigasterisk.com>
parents:
1362
diff
changeset
|
99 |
1786
11affc6d6045
more graph methods. some cleanup of the code that runs only required handlers, but it's not turned on yet
Drew Perttula <drewp@bigasterisk.com>
parents:
1783
diff
changeset
|
100 _handlerIsAffected: (child, patchSubjs) -> |
1647
67347c027b2a
hopefully harmmless steps towards making the handler tree right
Drew Perttula <drewp@bigasterisk.com>
parents:
1646
diff
changeset
|
101 if allPatchSubjs == null |
67347c027b2a
hopefully harmmless steps towards making the handler tree right
Drew Perttula <drewp@bigasterisk.com>
parents:
1646
diff
changeset
|
102 return true |
67347c027b2a
hopefully harmmless steps towards making the handler tree right
Drew Perttula <drewp@bigasterisk.com>
parents:
1646
diff
changeset
|
103 if not child.patterns.length |
67347c027b2a
hopefully harmmless steps towards making the handler tree right
Drew Perttula <drewp@bigasterisk.com>
parents:
1646
diff
changeset
|
104 return false |
67347c027b2a
hopefully harmmless steps towards making the handler tree right
Drew Perttula <drewp@bigasterisk.com>
parents:
1646
diff
changeset
|
105 |
67347c027b2a
hopefully harmmless steps towards making the handler tree right
Drew Perttula <drewp@bigasterisk.com>
parents:
1646
diff
changeset
|
106 for stmt in child.patterns |
1786
11affc6d6045
more graph methods. some cleanup of the code that runs only required handlers, but it's not turned on yet
Drew Perttula <drewp@bigasterisk.com>
parents:
1783
diff
changeset
|
107 if stmt[0] == null # wildcard on subject |
11affc6d6045
more graph methods. some cleanup of the code that runs only required handlers, but it's not turned on yet
Drew Perttula <drewp@bigasterisk.com>
parents:
1783
diff
changeset
|
108 return true |
11affc6d6045
more graph methods. some cleanup of the code that runs only required handlers, but it's not turned on yet
Drew Perttula <drewp@bigasterisk.com>
parents:
1783
diff
changeset
|
109 if patchSubjs.has(stmt[0].value) |
1647
67347c027b2a
hopefully harmmless steps towards making the handler tree right
Drew Perttula <drewp@bigasterisk.com>
parents:
1646
diff
changeset
|
110 return true |
67347c027b2a
hopefully harmmless steps towards making the handler tree right
Drew Perttula <drewp@bigasterisk.com>
parents:
1646
diff
changeset
|
111 |
67347c027b2a
hopefully harmmless steps towards making the handler tree right
Drew Perttula <drewp@bigasterisk.com>
parents:
1646
diff
changeset
|
112 return false |
67347c027b2a
hopefully harmmless steps towards making the handler tree right
Drew Perttula <drewp@bigasterisk.com>
parents:
1646
diff
changeset
|
113 |
1363
233b81d9bd9d
simple first version of SyncedGraph.runHandler
Drew Perttula <drewp@bigasterisk.com>
parents:
1362
diff
changeset
|
114 graphChanged: (patch) -> |
233b81d9bd9d
simple first version of SyncedGraph.runHandler
Drew Perttula <drewp@bigasterisk.com>
parents:
1362
diff
changeset
|
115 # SyncedGraph is telling us this patch just got applied to the graph. |
1647
67347c027b2a
hopefully harmmless steps towards making the handler tree right
Drew Perttula <drewp@bigasterisk.com>
parents:
1646
diff
changeset
|
116 |
1786
11affc6d6045
more graph methods. some cleanup of the code that runs only required handlers, but it's not turned on yet
Drew Perttula <drewp@bigasterisk.com>
parents:
1783
diff
changeset
|
117 subjs = allPatchSubjs(patch) |
1647
67347c027b2a
hopefully harmmless steps towards making the handler tree right
Drew Perttula <drewp@bigasterisk.com>
parents:
1646
diff
changeset
|
118 |
1386
29a1382de5c8
introduce autodep handler tree; only rerun highest-level affected handler and let it rerun its children
Drew Perttula <drewp@bigasterisk.com>
parents:
1383
diff
changeset
|
119 rerunInners = (cur) => |
29a1382de5c8
introduce autodep handler tree; only rerun highest-level affected handler and let it rerun its children
Drew Perttula <drewp@bigasterisk.com>
parents:
1383
diff
changeset
|
120 toRun = cur.innerHandlers.slice() |
29a1382de5c8
introduce autodep handler tree; only rerun highest-level affected handler and let it rerun its children
Drew Perttula <drewp@bigasterisk.com>
parents:
1383
diff
changeset
|
121 for child in toRun |
1789
d8ae388a8076
autodeps: try pruning some unrelated patches
Drew Perttula <drewp@bigasterisk.com>
parents:
1786
diff
changeset
|
122 match = @_handlerIsAffected(child, subjs) |
d8ae388a8076
autodeps: try pruning some unrelated patches
Drew Perttula <drewp@bigasterisk.com>
parents:
1786
diff
changeset
|
123 continue if not match |
1651
e00492e1c0b1
include some of the handler tree optimization code, turned off
Drew Perttula <drewp@bigasterisk.com>
parents:
1648
diff
changeset
|
124 #log('match', child.label, match) |
1789
d8ae388a8076
autodeps: try pruning some unrelated patches
Drew Perttula <drewp@bigasterisk.com>
parents:
1786
diff
changeset
|
125 child.innerHandlers = [] # let all children get called again |
1647
67347c027b2a
hopefully harmmless steps towards making the handler tree right
Drew Perttula <drewp@bigasterisk.com>
parents:
1646
diff
changeset
|
126 |
1494
ea9e8f581eea
WIP optimization for note point dragging
Drew Perttula <drewp@bigasterisk.com>
parents:
1415
diff
changeset
|
127 @_rerunHandler(child, patch) |
1415
edc17fdcaaf1
big rewrite of adjuster update code. origin & p3 adjusters kind of work. adj layout slightly works
Drew Perttula <drewp@bigasterisk.com>
parents:
1387
diff
changeset
|
128 rerunInners(child) |
1386
29a1382de5c8
introduce autodep handler tree; only rerun highest-level affected handler and let it rerun its children
Drew Perttula <drewp@bigasterisk.com>
parents:
1383
diff
changeset
|
129 rerunInners(@handlers) |
1363
233b81d9bd9d
simple first version of SyncedGraph.runHandler
Drew Perttula <drewp@bigasterisk.com>
parents:
1362
diff
changeset
|
130 |
233b81d9bd9d
simple first version of SyncedGraph.runHandler
Drew Perttula <drewp@bigasterisk.com>
parents:
1362
diff
changeset
|
131 askedFor: (s, p, o, g) -> |
233b81d9bd9d
simple first version of SyncedGraph.runHandler
Drew Perttula <drewp@bigasterisk.com>
parents:
1362
diff
changeset
|
132 # SyncedGraph is telling us someone did a query that depended on |
233b81d9bd9d
simple first version of SyncedGraph.runHandler
Drew Perttula <drewp@bigasterisk.com>
parents:
1362
diff
changeset
|
133 # quads in the given pattern. |
233b81d9bd9d
simple first version of SyncedGraph.runHandler
Drew Perttula <drewp@bigasterisk.com>
parents:
1362
diff
changeset
|
134 current = @handlerStack[@handlerStack.length - 1] |
1386
29a1382de5c8
introduce autodep handler tree; only rerun highest-level affected handler and let it rerun its children
Drew Perttula <drewp@bigasterisk.com>
parents:
1383
diff
changeset
|
135 if current? and current != @handlers |
1363
233b81d9bd9d
simple first version of SyncedGraph.runHandler
Drew Perttula <drewp@bigasterisk.com>
parents:
1362
diff
changeset
|
136 current.patterns.push([s, p, o, g]) |
233b81d9bd9d
simple first version of SyncedGraph.runHandler
Drew Perttula <drewp@bigasterisk.com>
parents:
1362
diff
changeset
|
137 #log('push', s,p,o,g) |
1651
e00492e1c0b1
include some of the handler tree optimization code, turned off
Drew Perttula <drewp@bigasterisk.com>
parents:
1648
diff
changeset
|
138 #else |
e00492e1c0b1
include some of the handler tree optimization code, turned off
Drew Perttula <drewp@bigasterisk.com>
parents:
1648
diff
changeset
|
139 # console.trace('read outside runHandler') |
1317
4c6d88aa9e26
enough element and rdf support to drag one adjuster and see its value change
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
140 |
1354
59eab70254fa
refactor the rdfdb networking out of (js) SyncedGraph
Drew Perttula <drewp@bigasterisk.com>
parents:
1352
diff
changeset
|
141 class window.SyncedGraph |
59eab70254fa
refactor the rdfdb networking out of (js) SyncedGraph
Drew Perttula <drewp@bigasterisk.com>
parents:
1352
diff
changeset
|
142 # Main graph object for a browser to use. Syncs both ways with |
59eab70254fa
refactor the rdfdb networking out of (js) SyncedGraph
Drew Perttula <drewp@bigasterisk.com>
parents:
1352
diff
changeset
|
143 # rdfdb. Meant to hide the choice of RDF lib, so we can change it |
59eab70254fa
refactor the rdfdb networking out of (js) SyncedGraph
Drew Perttula <drewp@bigasterisk.com>
parents:
1352
diff
changeset
|
144 # later. |
1753
3c997bc6d380
fix some coffee lint
Drew Perttula <drewp@bigasterisk.com>
parents:
1751
diff
changeset
|
145 # |
1354
59eab70254fa
refactor the rdfdb networking out of (js) SyncedGraph
Drew Perttula <drewp@bigasterisk.com>
parents:
1352
diff
changeset
|
146 # Note that _applyPatch is the only method to write to the graph, so |
59eab70254fa
refactor the rdfdb networking out of (js) SyncedGraph
Drew Perttula <drewp@bigasterisk.com>
parents:
1352
diff
changeset
|
147 # it can fire subscriptions. |
59eab70254fa
refactor the rdfdb networking out of (js) SyncedGraph
Drew Perttula <drewp@bigasterisk.com>
parents:
1352
diff
changeset
|
148 |
1355
9476e97b57fb
status widget for rdfdb-synced-graph
Drew Perttula <drewp@bigasterisk.com>
parents:
1354
diff
changeset
|
149 constructor: (@patchSenderUrl, @prefixes, @setStatus) -> |
1354
59eab70254fa
refactor the rdfdb networking out of (js) SyncedGraph
Drew Perttula <drewp@bigasterisk.com>
parents:
1352
diff
changeset
|
150 # patchSenderUrl is the /syncedGraph path of an rdfdb server. |
59eab70254fa
refactor the rdfdb networking out of (js) SyncedGraph
Drew Perttula <drewp@bigasterisk.com>
parents:
1352
diff
changeset
|
151 # prefixes can be used in Uri(curie) calls. |
1363
233b81d9bd9d
simple first version of SyncedGraph.runHandler
Drew Perttula <drewp@bigasterisk.com>
parents:
1362
diff
changeset
|
152 @_autoDeps = new AutoDependencies() # replaces GraphWatchers |
1354
59eab70254fa
refactor the rdfdb networking out of (js) SyncedGraph
Drew Perttula <drewp@bigasterisk.com>
parents:
1352
diff
changeset
|
153 @clearGraph() |
59eab70254fa
refactor the rdfdb networking out of (js) SyncedGraph
Drew Perttula <drewp@bigasterisk.com>
parents:
1352
diff
changeset
|
154 |
1362
168262618f2d
new test_js target for testing SyncedGraph
Drew Perttula <drewp@bigasterisk.com>
parents:
1361
diff
changeset
|
155 if @patchSenderUrl |
1714
f2265601ead6
edit-choice/etc fixes and tests
Drew Perttula <drewp@bigasterisk.com>
parents:
1708
diff
changeset
|
156 @_client = new RdfDbClient(@patchSenderUrl, |
f2265601ead6
edit-choice/etc fixes and tests
Drew Perttula <drewp@bigasterisk.com>
parents:
1708
diff
changeset
|
157 @_clearGraphOnNewConnection.bind(@), |
f2265601ead6
edit-choice/etc fixes and tests
Drew Perttula <drewp@bigasterisk.com>
parents:
1708
diff
changeset
|
158 @_applyPatch.bind(@), |
f2265601ead6
edit-choice/etc fixes and tests
Drew Perttula <drewp@bigasterisk.com>
parents:
1708
diff
changeset
|
159 @setStatus) |
1354
59eab70254fa
refactor the rdfdb networking out of (js) SyncedGraph
Drew Perttula <drewp@bigasterisk.com>
parents:
1352
diff
changeset
|
160 |
1643
77eaccba654e
try to fix timeline sending empty ctx to rdfdb
Drew Perttula <drewp@bigasterisk.com>
parents:
1624
diff
changeset
|
161 clearGraph: -> |
1363
233b81d9bd9d
simple first version of SyncedGraph.runHandler
Drew Perttula <drewp@bigasterisk.com>
parents:
1362
diff
changeset
|
162 # just deletes the statements; watchers are unaffected. |
1354
59eab70254fa
refactor the rdfdb networking out of (js) SyncedGraph
Drew Perttula <drewp@bigasterisk.com>
parents:
1352
diff
changeset
|
163 if @graph? |
1707 | 164 @_applyPatch({addQuads: [], delQuads: @graph.getQuads()}) |
1354
59eab70254fa
refactor the rdfdb networking out of (js) SyncedGraph
Drew Perttula <drewp@bigasterisk.com>
parents:
1352
diff
changeset
|
165 |
59eab70254fa
refactor the rdfdb networking out of (js) SyncedGraph
Drew Perttula <drewp@bigasterisk.com>
parents:
1352
diff
changeset
|
166 # if we had a Store already, this lets N3.Store free all its indices/etc |
59eab70254fa
refactor the rdfdb networking out of (js) SyncedGraph
Drew Perttula <drewp@bigasterisk.com>
parents:
1352
diff
changeset
|
167 @graph = N3.Store() |
59eab70254fa
refactor the rdfdb networking out of (js) SyncedGraph
Drew Perttula <drewp@bigasterisk.com>
parents:
1352
diff
changeset
|
168 @_addPrefixes(@prefixes) |
1759
72380e12d86c
performance: add @cachedUriValues
Drew Perttula <drewp@bigasterisk.com>
parents:
1753
diff
changeset
|
169 @cachedFloatValues = new Map() # s + '|' + p -> number |
72380e12d86c
performance: add @cachedUriValues
Drew Perttula <drewp@bigasterisk.com>
parents:
1753
diff
changeset
|
170 @cachedUriValues = new Map() # s + '|' + p -> Uri |
1643
77eaccba654e
try to fix timeline sending empty ctx to rdfdb
Drew Perttula <drewp@bigasterisk.com>
parents:
1624
diff
changeset
|
171 |
77eaccba654e
try to fix timeline sending empty ctx to rdfdb
Drew Perttula <drewp@bigasterisk.com>
parents:
1624
diff
changeset
|
172 _clearGraphOnNewConnection: -> # must not send a patch to the server! |
77eaccba654e
try to fix timeline sending empty ctx to rdfdb
Drew Perttula <drewp@bigasterisk.com>
parents:
1624
diff
changeset
|
173 log('graph: clearGraphOnNewConnection') |
77eaccba654e
try to fix timeline sending empty ctx to rdfdb
Drew Perttula <drewp@bigasterisk.com>
parents:
1624
diff
changeset
|
174 @clearGraph() |
77eaccba654e
try to fix timeline sending empty ctx to rdfdb
Drew Perttula <drewp@bigasterisk.com>
parents:
1624
diff
changeset
|
175 log('graph: clearGraphOnNewConnection done') |
1347
5c54a1f94050
browser SyncedGraph client connects and receives patches
Drew Perttula <drewp@bigasterisk.com>
parents:
1346
diff
changeset
|
176 |
1317
4c6d88aa9e26
enough element and rdf support to drag one adjuster and see its value change
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
177 _addPrefixes: (prefixes) -> |
1707 | 178 for k in (prefixes or {}) |
179 @prefixes[k] = prefixes[k] | |
180 @prefixFuncs = N3.Util.prefixes(@prefixes) | |
1317
4c6d88aa9e26
enough element and rdf support to drag one adjuster and see its value change
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
181 |
4c6d88aa9e26
enough element and rdf support to drag one adjuster and see its value change
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
182 Uri: (curie) -> |
1741
17f56584e253
fix types so graph writing works again.
Drew Perttula <drewp@bigasterisk.com>
parents:
1739
diff
changeset
|
183 if not curie? |
17f56584e253
fix types so graph writing works again.
Drew Perttula <drewp@bigasterisk.com>
parents:
1739
diff
changeset
|
184 throw new Error("no uri") |
1707 | 185 if curie.match(/^http/) |
186 return N3.DataFactory.namedNode(curie) | |
187 part = curie.split(':') | |
188 return @prefixFuncs(part[0])(part[1]) | |
1317
4c6d88aa9e26
enough element and rdf support to drag one adjuster and see its value change
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
189 |
4c6d88aa9e26
enough element and rdf support to drag one adjuster and see its value change
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
190 Literal: (jsValue) -> |
1707 | 191 N3.DataFactory.literal(jsValue) |
1317
4c6d88aa9e26
enough element and rdf support to drag one adjuster and see its value change
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
192 |
1350
36f58b2aa8ef
browser syncedgraph sends patches back to server
Drew Perttula <drewp@bigasterisk.com>
parents:
1347
diff
changeset
|
193 LiteralRoundedFloat: (f) -> |
1707 | 194 N3.DataFactory.literal(d3.format(".3f")(f), |
1741
17f56584e253
fix types so graph writing works again.
Drew Perttula <drewp@bigasterisk.com>
parents:
1739
diff
changeset
|
195 @Uri("http://www.w3.org/2001/XMLSchema#double")) |
1708
8d3569829198
more upgrades for n3 api. not quite passing
drewp@bigasterisk.com
parents:
1707
diff
changeset
|
196 |
8d3569829198
more upgrades for n3 api. not quite passing
drewp@bigasterisk.com
parents:
1707
diff
changeset
|
197 Quad: (s, p, o, g) -> N3.DataFactory.quad(s, p, o, g) |
1350
36f58b2aa8ef
browser syncedgraph sends patches back to server
Drew Perttula <drewp@bigasterisk.com>
parents:
1347
diff
changeset
|
198 |
1317
4c6d88aa9e26
enough element and rdf support to drag one adjuster and see its value change
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
199 toJs: (literal) -> |
4c6d88aa9e26
enough element and rdf support to drag one adjuster and see its value change
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
200 # incomplete |
1708
8d3569829198
more upgrades for n3 api. not quite passing
drewp@bigasterisk.com
parents:
1707
diff
changeset
|
201 parseFloat(literal.value) |
1317
4c6d88aa9e26
enough element and rdf support to drag one adjuster and see its value change
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
202 |
4c6d88aa9e26
enough element and rdf support to drag one adjuster and see its value change
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
203 loadTrig: (trig, cb) -> # for debugging |
4c6d88aa9e26
enough element and rdf support to drag one adjuster and see its value change
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
204 patch = {delQuads: [], addQuads: []} |
4c6d88aa9e26
enough element and rdf support to drag one adjuster and see its value change
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
205 parser = N3.Parser() |
4c6d88aa9e26
enough element and rdf support to drag one adjuster and see its value change
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
206 parser.parse trig, (error, quad, prefixes) => |
1753
3c997bc6d380
fix some coffee lint
Drew Perttula <drewp@bigasterisk.com>
parents:
1751
diff
changeset
|
207 if error |
3c997bc6d380
fix some coffee lint
Drew Perttula <drewp@bigasterisk.com>
parents:
1751
diff
changeset
|
208 throw new Error(error) |
3c997bc6d380
fix some coffee lint
Drew Perttula <drewp@bigasterisk.com>
parents:
1751
diff
changeset
|
209 if (quad) |
3c997bc6d380
fix some coffee lint
Drew Perttula <drewp@bigasterisk.com>
parents:
1751
diff
changeset
|
210 patch.addQuads.push(quad) |
3c997bc6d380
fix some coffee lint
Drew Perttula <drewp@bigasterisk.com>
parents:
1751
diff
changeset
|
211 else |
3c997bc6d380
fix some coffee lint
Drew Perttula <drewp@bigasterisk.com>
parents:
1751
diff
changeset
|
212 @_applyPatch(patch) |
3c997bc6d380
fix some coffee lint
Drew Perttula <drewp@bigasterisk.com>
parents:
1751
diff
changeset
|
213 @_addPrefixes(prefixes) |
3c997bc6d380
fix some coffee lint
Drew Perttula <drewp@bigasterisk.com>
parents:
1751
diff
changeset
|
214 cb() if cb |
1317
4c6d88aa9e26
enough element and rdf support to drag one adjuster and see its value change
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
215 |
4c6d88aa9e26
enough element and rdf support to drag one adjuster and see its value change
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
216 quads: () -> # for debugging |
1707 | 217 [q.subject, q.predicate, q.object, q.graph] for q in @graph.getQuads() |
1317
4c6d88aa9e26
enough element and rdf support to drag one adjuster and see its value change
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
218 |
1363
233b81d9bd9d
simple first version of SyncedGraph.runHandler
Drew Perttula <drewp@bigasterisk.com>
parents:
1362
diff
changeset
|
219 applyAndSendPatch: (patch) -> |
1647
67347c027b2a
hopefully harmmless steps towards making the handler tree right
Drew Perttula <drewp@bigasterisk.com>
parents:
1646
diff
changeset
|
220 console.time('applyAndSendPatch') |
1383
73762e14ee98
typecheck on applyPatch
Drew Perttula <drewp@bigasterisk.com>
parents:
1375
diff
changeset
|
221 if !Array.isArray(patch.addQuads) || !Array.isArray(patch.delQuads) |
1750 | 222 console.timeEnd('applyAndSendPatch') |
223 log('corrupt patch') | |
1647
67347c027b2a
hopefully harmmless steps towards making the handler tree right
Drew Perttula <drewp@bigasterisk.com>
parents:
1646
diff
changeset
|
224 throw new Error("corrupt patch: #{JSON.stringify(patch)}") |
1643
77eaccba654e
try to fix timeline sending empty ctx to rdfdb
Drew Perttula <drewp@bigasterisk.com>
parents:
1624
diff
changeset
|
225 |
1651
e00492e1c0b1
include some of the handler tree optimization code, turned off
Drew Perttula <drewp@bigasterisk.com>
parents:
1648
diff
changeset
|
226 @_validatePatch(patch) |
e00492e1c0b1
include some of the handler tree optimization code, turned off
Drew Perttula <drewp@bigasterisk.com>
parents:
1648
diff
changeset
|
227 |
e00492e1c0b1
include some of the handler tree optimization code, turned off
Drew Perttula <drewp@bigasterisk.com>
parents:
1648
diff
changeset
|
228 @_applyPatch(patch) |
e00492e1c0b1
include some of the handler tree optimization code, turned off
Drew Perttula <drewp@bigasterisk.com>
parents:
1648
diff
changeset
|
229 @_client.sendPatch(patch) if @_client |
e00492e1c0b1
include some of the handler tree optimization code, turned off
Drew Perttula <drewp@bigasterisk.com>
parents:
1648
diff
changeset
|
230 console.timeEnd('applyAndSendPatch') |
e00492e1c0b1
include some of the handler tree optimization code, turned off
Drew Perttula <drewp@bigasterisk.com>
parents:
1648
diff
changeset
|
231 |
e00492e1c0b1
include some of the handler tree optimization code, turned off
Drew Perttula <drewp@bigasterisk.com>
parents:
1648
diff
changeset
|
232 _validatePatch: (patch) -> |
1643
77eaccba654e
try to fix timeline sending empty ctx to rdfdb
Drew Perttula <drewp@bigasterisk.com>
parents:
1624
diff
changeset
|
233 for qs in [patch.addQuads, patch.delQuads] |
77eaccba654e
try to fix timeline sending empty ctx to rdfdb
Drew Perttula <drewp@bigasterisk.com>
parents:
1624
diff
changeset
|
234 for q in qs |
1708
8d3569829198
more upgrades for n3 api. not quite passing
drewp@bigasterisk.com
parents:
1707
diff
changeset
|
235 if not q.equals |
8d3569829198
more upgrades for n3 api. not quite passing
drewp@bigasterisk.com
parents:
1707
diff
changeset
|
236 throw new Error("doesn't look like a proper Quad") |
1749
468a13c4b910
fix dropping effect into timeline
Drew Perttula <drewp@bigasterisk.com>
parents:
1741
diff
changeset
|
237 if not q.subject.id or not q.graph.id? or not q.predicate.id? |
1647
67347c027b2a
hopefully harmmless steps towards making the handler tree right
Drew Perttula <drewp@bigasterisk.com>
parents:
1646
diff
changeset
|
238 throw new Error("corrupt patch: #{JSON.stringify(q)}") |
67347c027b2a
hopefully harmmless steps towards making the handler tree right
Drew Perttula <drewp@bigasterisk.com>
parents:
1646
diff
changeset
|
239 |
1354
59eab70254fa
refactor the rdfdb networking out of (js) SyncedGraph
Drew Perttula <drewp@bigasterisk.com>
parents:
1352
diff
changeset
|
240 _applyPatch: (patch) -> |
1317
4c6d88aa9e26
enough element and rdf support to drag one adjuster and see its value change
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
241 # In most cases you want applyAndSendPatch. |
1753
3c997bc6d380
fix some coffee lint
Drew Perttula <drewp@bigasterisk.com>
parents:
1751
diff
changeset
|
242 # |
1354
59eab70254fa
refactor the rdfdb networking out of (js) SyncedGraph
Drew Perttula <drewp@bigasterisk.com>
parents:
1352
diff
changeset
|
243 # This is the only method that writes to @graph! |
1517
3bb58b74c9c1
timeline: add cache of floats between graph updates for smoother redraws
Drew Perttula <drewp@bigasterisk.com>
parents:
1494
diff
changeset
|
244 @cachedFloatValues.clear() |
1759
72380e12d86c
performance: add @cachedUriValues
Drew Perttula <drewp@bigasterisk.com>
parents:
1753
diff
changeset
|
245 @cachedUriValues.clear() |
1317
4c6d88aa9e26
enough element and rdf support to drag one adjuster and see its value change
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
246 for quad in patch.delQuads |
1753
3c997bc6d380
fix some coffee lint
Drew Perttula <drewp@bigasterisk.com>
parents:
1751
diff
changeset
|
247 #log("remove #{JSON.stringify(quad)}") |
1708
8d3569829198
more upgrades for n3 api. not quite passing
drewp@bigasterisk.com
parents:
1707
diff
changeset
|
248 did = @graph.removeQuad(quad) |
1739 | 249 #log("removed: #{did}") |
1317
4c6d88aa9e26
enough element and rdf support to drag one adjuster and see its value change
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
250 for quad in patch.addQuads |
1707 | 251 @graph.addQuad(quad) |
1363
233b81d9bd9d
simple first version of SyncedGraph.runHandler
Drew Perttula <drewp@bigasterisk.com>
parents:
1362
diff
changeset
|
252 #log('applied patch locally', patchSizeSummary(patch)) |
233b81d9bd9d
simple first version of SyncedGraph.runHandler
Drew Perttula <drewp@bigasterisk.com>
parents:
1362
diff
changeset
|
253 @_autoDeps.graphChanged(patch) |
1317
4c6d88aa9e26
enough element and rdf support to drag one adjuster and see its value change
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
254 |
4c6d88aa9e26
enough element and rdf support to drag one adjuster and see its value change
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
255 getObjectPatch: (s, p, newObject, g) -> |
1591
2713d2f7a0fc
resource-display can have a rename button for editing rdfs:label
Drew Perttula <drewp@bigasterisk.com>
parents:
1537
diff
changeset
|
256 # make a patch which removes existing values for (s,p,*,c) and |
1317
4c6d88aa9e26
enough element and rdf support to drag one adjuster and see its value change
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
257 # adds (s,p,newObject,c). Values in other graphs are not affected. |
1707 | 258 existing = @graph.getQuads(s, p, null, g) |
1317
4c6d88aa9e26
enough element and rdf support to drag one adjuster and see its value change
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
259 return { |
4c6d88aa9e26
enough element and rdf support to drag one adjuster and see its value change
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
260 delQuads: existing, |
1708
8d3569829198
more upgrades for n3 api. not quite passing
drewp@bigasterisk.com
parents:
1707
diff
changeset
|
261 addQuads: [@Quad(s, p, newObject, g)] |
1317
4c6d88aa9e26
enough element and rdf support to drag one adjuster and see its value change
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
262 } |
4c6d88aa9e26
enough element and rdf support to drag one adjuster and see its value change
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
263 |
4c6d88aa9e26
enough element and rdf support to drag one adjuster and see its value change
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
264 patchObject: (s, p, newObject, g) -> |
4c6d88aa9e26
enough element and rdf support to drag one adjuster and see its value change
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
265 @applyAndSendPatch(@getObjectPatch(s, p, newObject, g)) |
1786
11affc6d6045
more graph methods. some cleanup of the code that runs only required handlers, but it's not turned on yet
Drew Perttula <drewp@bigasterisk.com>
parents:
1783
diff
changeset
|
266 |
11affc6d6045
more graph methods. some cleanup of the code that runs only required handlers, but it's not turned on yet
Drew Perttula <drewp@bigasterisk.com>
parents:
1783
diff
changeset
|
267 clearObjects: (s, p, g) -> |
11affc6d6045
more graph methods. some cleanup of the code that runs only required handlers, but it's not turned on yet
Drew Perttula <drewp@bigasterisk.com>
parents:
1783
diff
changeset
|
268 @applyAndSendPatch({ |
11affc6d6045
more graph methods. some cleanup of the code that runs only required handlers, but it's not turned on yet
Drew Perttula <drewp@bigasterisk.com>
parents:
1783
diff
changeset
|
269 delQuads: @graph.getQuads(s, p, null, g), |
11affc6d6045
more graph methods. some cleanup of the code that runs only required handlers, but it's not turned on yet
Drew Perttula <drewp@bigasterisk.com>
parents:
1783
diff
changeset
|
270 addQuads: [] |
11affc6d6045
more graph methods. some cleanup of the code that runs only required handlers, but it's not turned on yet
Drew Perttula <drewp@bigasterisk.com>
parents:
1783
diff
changeset
|
271 }) |
1317
4c6d88aa9e26
enough element and rdf support to drag one adjuster and see its value change
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
272 |
1386
29a1382de5c8
introduce autodep handler tree; only rerun highest-level affected handler and let it rerun its children
Drew Perttula <drewp@bigasterisk.com>
parents:
1383
diff
changeset
|
273 runHandler: (func, label) -> |
1363
233b81d9bd9d
simple first version of SyncedGraph.runHandler
Drew Perttula <drewp@bigasterisk.com>
parents:
1362
diff
changeset
|
274 # runs your func once, tracking graph calls. if a future patch |
233b81d9bd9d
simple first version of SyncedGraph.runHandler
Drew Perttula <drewp@bigasterisk.com>
parents:
1362
diff
changeset
|
275 # matches what you queried, we runHandler your func again (and |
233b81d9bd9d
simple first version of SyncedGraph.runHandler
Drew Perttula <drewp@bigasterisk.com>
parents:
1362
diff
changeset
|
276 # forget your queries from the first time). |
1624
4a751aaaee52
big timeline rewrites. hopefully it's faster and less leaky
Drew Perttula <drewp@bigasterisk.com>
parents:
1595
diff
changeset
|
277 |
4a751aaaee52
big timeline rewrites. hopefully it's faster and less leaky
Drew Perttula <drewp@bigasterisk.com>
parents:
1595
diff
changeset
|
278 # helps with memleak? not sure yet. The point was if two matching |
4a751aaaee52
big timeline rewrites. hopefully it's faster and less leaky
Drew Perttula <drewp@bigasterisk.com>
parents:
1595
diff
changeset
|
279 # labels get puushed on, we should run only one. So maybe |
4a751aaaee52
big timeline rewrites. hopefully it's faster and less leaky
Drew Perttula <drewp@bigasterisk.com>
parents:
1595
diff
changeset
|
280 # appending a serial number is backwards. |
4a751aaaee52
big timeline rewrites. hopefully it's faster and less leaky
Drew Perttula <drewp@bigasterisk.com>
parents:
1595
diff
changeset
|
281 @serial = 1 if not @serial |
4a751aaaee52
big timeline rewrites. hopefully it's faster and less leaky
Drew Perttula <drewp@bigasterisk.com>
parents:
1595
diff
changeset
|
282 @serial += 1 |
4a751aaaee52
big timeline rewrites. hopefully it's faster and less leaky
Drew Perttula <drewp@bigasterisk.com>
parents:
1595
diff
changeset
|
283 #label = label + @serial |
4a751aaaee52
big timeline rewrites. hopefully it's faster and less leaky
Drew Perttula <drewp@bigasterisk.com>
parents:
1595
diff
changeset
|
284 |
1386
29a1382de5c8
introduce autodep handler tree; only rerun highest-level affected handler and let it rerun its children
Drew Perttula <drewp@bigasterisk.com>
parents:
1383
diff
changeset
|
285 @_autoDeps.runHandler(func, label) |
1363
233b81d9bd9d
simple first version of SyncedGraph.runHandler
Drew Perttula <drewp@bigasterisk.com>
parents:
1362
diff
changeset
|
286 |
1356
16aa26b7d685
timeline audio loads the current song img
Drew Perttula <drewp@bigasterisk.com>
parents:
1355
diff
changeset
|
287 _singleValue: (s, p) -> |
1363
233b81d9bd9d
simple first version of SyncedGraph.runHandler
Drew Perttula <drewp@bigasterisk.com>
parents:
1362
diff
changeset
|
288 @_autoDeps.askedFor(s, p, null, null) |
1707 | 289 quads = @graph.getQuads(s, p) |
1534
d4de13e83b7f
graph.js don't error if a statement is in multiple graphs
Drew Perttula <drewp@bigasterisk.com>
parents:
1517
diff
changeset
|
290 objs = new Set(q.object for q in quads) |
d4de13e83b7f
graph.js don't error if a statement is in multiple graphs
Drew Perttula <drewp@bigasterisk.com>
parents:
1517
diff
changeset
|
291 |
d4de13e83b7f
graph.js don't error if a statement is in multiple graphs
Drew Perttula <drewp@bigasterisk.com>
parents:
1517
diff
changeset
|
292 switch objs.size |
1356
16aa26b7d685
timeline audio loads the current song img
Drew Perttula <drewp@bigasterisk.com>
parents:
1355
diff
changeset
|
293 when 0 |
1725 | 294 throw new Error("no value for "+s.value+" "+p.value) |
1317
4c6d88aa9e26
enough element and rdf support to drag one adjuster and see its value change
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
295 when 1 |
1534
d4de13e83b7f
graph.js don't error if a statement is in multiple graphs
Drew Perttula <drewp@bigasterisk.com>
parents:
1517
diff
changeset
|
296 obj = objs.values().next().value |
1358 | 297 return obj |
1317
4c6d88aa9e26
enough element and rdf support to drag one adjuster and see its value change
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
298 else |
1534
d4de13e83b7f
graph.js don't error if a statement is in multiple graphs
Drew Perttula <drewp@bigasterisk.com>
parents:
1517
diff
changeset
|
299 throw new Error("too many different values: " + JSON.stringify(quads)) |
1356
16aa26b7d685
timeline audio loads the current song img
Drew Perttula <drewp@bigasterisk.com>
parents:
1355
diff
changeset
|
300 |
16aa26b7d685
timeline audio loads the current song img
Drew Perttula <drewp@bigasterisk.com>
parents:
1355
diff
changeset
|
301 floatValue: (s, p) -> |
1725 | 302 key = s.value + '|' + p.value |
1517
3bb58b74c9c1
timeline: add cache of floats between graph updates for smoother redraws
Drew Perttula <drewp@bigasterisk.com>
parents:
1494
diff
changeset
|
303 hit = @cachedFloatValues.get(key) |
3bb58b74c9c1
timeline: add cache of floats between graph updates for smoother redraws
Drew Perttula <drewp@bigasterisk.com>
parents:
1494
diff
changeset
|
304 return hit if hit != undefined |
1624
4a751aaaee52
big timeline rewrites. hopefully it's faster and less leaky
Drew Perttula <drewp@bigasterisk.com>
parents:
1595
diff
changeset
|
305 #log('float miss', s, p) |
1517
3bb58b74c9c1
timeline: add cache of floats between graph updates for smoother redraws
Drew Perttula <drewp@bigasterisk.com>
parents:
1494
diff
changeset
|
306 |
1783
717a971132eb
float vs str values on live
Drew Perttula <drewp@bigasterisk.com>
parents:
1781
diff
changeset
|
307 v = @_singleValue(s, p).value |
717a971132eb
float vs str values on live
Drew Perttula <drewp@bigasterisk.com>
parents:
1781
diff
changeset
|
308 ret = parseFloat(v) |
717a971132eb
float vs str values on live
Drew Perttula <drewp@bigasterisk.com>
parents:
1781
diff
changeset
|
309 if isNaN(ret) |
717a971132eb
float vs str values on live
Drew Perttula <drewp@bigasterisk.com>
parents:
1781
diff
changeset
|
310 throw new Error("#{s.value} #{p.value} -> #{v} not a float") |
1517
3bb58b74c9c1
timeline: add cache of floats between graph updates for smoother redraws
Drew Perttula <drewp@bigasterisk.com>
parents:
1494
diff
changeset
|
311 @cachedFloatValues.set(key, ret) |
3bb58b74c9c1
timeline: add cache of floats between graph updates for smoother redraws
Drew Perttula <drewp@bigasterisk.com>
parents:
1494
diff
changeset
|
312 return ret |
1317
4c6d88aa9e26
enough element and rdf support to drag one adjuster and see its value change
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
313 |
4c6d88aa9e26
enough element and rdf support to drag one adjuster and see its value change
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
314 stringValue: (s, p) -> |
1708
8d3569829198
more upgrades for n3 api. not quite passing
drewp@bigasterisk.com
parents:
1707
diff
changeset
|
315 @_singleValue(s, p).value |
1356
16aa26b7d685
timeline audio loads the current song img
Drew Perttula <drewp@bigasterisk.com>
parents:
1355
diff
changeset
|
316 |
1317
4c6d88aa9e26
enough element and rdf support to drag one adjuster and see its value change
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
317 uriValue: (s, p) -> |
1759
72380e12d86c
performance: add @cachedUriValues
Drew Perttula <drewp@bigasterisk.com>
parents:
1753
diff
changeset
|
318 key = s.value + '|' + p.value |
72380e12d86c
performance: add @cachedUriValues
Drew Perttula <drewp@bigasterisk.com>
parents:
1753
diff
changeset
|
319 hit = @cachedUriValues.get(key) |
72380e12d86c
performance: add @cachedUriValues
Drew Perttula <drewp@bigasterisk.com>
parents:
1753
diff
changeset
|
320 return hit if hit != undefined |
72380e12d86c
performance: add @cachedUriValues
Drew Perttula <drewp@bigasterisk.com>
parents:
1753
diff
changeset
|
321 |
72380e12d86c
performance: add @cachedUriValues
Drew Perttula <drewp@bigasterisk.com>
parents:
1753
diff
changeset
|
322 ret = @_singleValue(s, p) |
72380e12d86c
performance: add @cachedUriValues
Drew Perttula <drewp@bigasterisk.com>
parents:
1753
diff
changeset
|
323 @cachedUriValues.set(key, ret) |
72380e12d86c
performance: add @cachedUriValues
Drew Perttula <drewp@bigasterisk.com>
parents:
1753
diff
changeset
|
324 return ret |
1317
4c6d88aa9e26
enough element and rdf support to drag one adjuster and see its value change
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
325 |
1595
013cbd7a0f08
choice-type attrs in live
Drew Perttula <drewp@bigasterisk.com>
parents:
1591
diff
changeset
|
326 labelOrTail: (uri) -> |
013cbd7a0f08
choice-type attrs in live
Drew Perttula <drewp@bigasterisk.com>
parents:
1591
diff
changeset
|
327 try |
1714
f2265601ead6
edit-choice/etc fixes and tests
Drew Perttula <drewp@bigasterisk.com>
parents:
1708
diff
changeset
|
328 ret = @stringValue(uri, @Uri('rdfs:label')) |
1595
013cbd7a0f08
choice-type attrs in live
Drew Perttula <drewp@bigasterisk.com>
parents:
1591
diff
changeset
|
329 catch |
1714
f2265601ead6
edit-choice/etc fixes and tests
Drew Perttula <drewp@bigasterisk.com>
parents:
1708
diff
changeset
|
330 words = uri.value.split('/') |
f2265601ead6
edit-choice/etc fixes and tests
Drew Perttula <drewp@bigasterisk.com>
parents:
1708
diff
changeset
|
331 ret = words[words.length-1] |
f2265601ead6
edit-choice/etc fixes and tests
Drew Perttula <drewp@bigasterisk.com>
parents:
1708
diff
changeset
|
332 if not ret |
f2265601ead6
edit-choice/etc fixes and tests
Drew Perttula <drewp@bigasterisk.com>
parents:
1708
diff
changeset
|
333 ret = uri.value |
f2265601ead6
edit-choice/etc fixes and tests
Drew Perttula <drewp@bigasterisk.com>
parents:
1708
diff
changeset
|
334 return ret |
1595
013cbd7a0f08
choice-type attrs in live
Drew Perttula <drewp@bigasterisk.com>
parents:
1591
diff
changeset
|
335 |
1317
4c6d88aa9e26
enough element and rdf support to drag one adjuster and see its value change
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
336 objects: (s, p) -> |
1363
233b81d9bd9d
simple first version of SyncedGraph.runHandler
Drew Perttula <drewp@bigasterisk.com>
parents:
1362
diff
changeset
|
337 @_autoDeps.askedFor(s, p, null, null) |
1707 | 338 quads = @graph.getQuads(s, p) |
1358 | 339 return (q.object for q in quads) |
1317
4c6d88aa9e26
enough element and rdf support to drag one adjuster and see its value change
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
340 |
4c6d88aa9e26
enough element and rdf support to drag one adjuster and see its value change
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
341 subjects: (p, o) -> |
1363
233b81d9bd9d
simple first version of SyncedGraph.runHandler
Drew Perttula <drewp@bigasterisk.com>
parents:
1362
diff
changeset
|
342 @_autoDeps.askedFor(null, p, o, null) |
1707 | 343 quads = @graph.getQuads(null, p, o) |
1363
233b81d9bd9d
simple first version of SyncedGraph.runHandler
Drew Perttula <drewp@bigasterisk.com>
parents:
1362
diff
changeset
|
344 return (q.subject for q in quads) |
1317
4c6d88aa9e26
enough element and rdf support to drag one adjuster and see its value change
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
345 |
4c6d88aa9e26
enough element and rdf support to drag one adjuster and see its value change
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
346 items: (list) -> |
1363
233b81d9bd9d
simple first version of SyncedGraph.runHandler
Drew Perttula <drewp@bigasterisk.com>
parents:
1362
diff
changeset
|
347 out = [] |
233b81d9bd9d
simple first version of SyncedGraph.runHandler
Drew Perttula <drewp@bigasterisk.com>
parents:
1362
diff
changeset
|
348 current = list |
233b81d9bd9d
simple first version of SyncedGraph.runHandler
Drew Perttula <drewp@bigasterisk.com>
parents:
1362
diff
changeset
|
349 while true |
233b81d9bd9d
simple first version of SyncedGraph.runHandler
Drew Perttula <drewp@bigasterisk.com>
parents:
1362
diff
changeset
|
350 if current == RDF + 'nil' |
233b81d9bd9d
simple first version of SyncedGraph.runHandler
Drew Perttula <drewp@bigasterisk.com>
parents:
1362
diff
changeset
|
351 break |
233b81d9bd9d
simple first version of SyncedGraph.runHandler
Drew Perttula <drewp@bigasterisk.com>
parents:
1362
diff
changeset
|
352 |
1648
ffa3b81c6d95
some missing askedFor auditing
Drew Perttula <drewp@bigasterisk.com>
parents:
1647
diff
changeset
|
353 @_autoDeps.askedFor(current, null, null, null) # a little loose |
ffa3b81c6d95
some missing askedFor auditing
Drew Perttula <drewp@bigasterisk.com>
parents:
1647
diff
changeset
|
354 |
1707 | 355 firsts = @graph.getQuads(current, RDF + 'first', null) |
356 rests = @graph.getQuads(current, RDF + 'rest', null) | |
1363
233b81d9bd9d
simple first version of SyncedGraph.runHandler
Drew Perttula <drewp@bigasterisk.com>
parents:
1362
diff
changeset
|
357 if firsts.length != 1 |
1753
3c997bc6d380
fix some coffee lint
Drew Perttula <drewp@bigasterisk.com>
parents:
1751
diff
changeset
|
358 throw new Error( |
3c997bc6d380
fix some coffee lint
Drew Perttula <drewp@bigasterisk.com>
parents:
1751
diff
changeset
|
359 "list node #{current} has #{firsts.length} rdf:first edges") |
1363
233b81d9bd9d
simple first version of SyncedGraph.runHandler
Drew Perttula <drewp@bigasterisk.com>
parents:
1362
diff
changeset
|
360 out.push(firsts[0].object) |
233b81d9bd9d
simple first version of SyncedGraph.runHandler
Drew Perttula <drewp@bigasterisk.com>
parents:
1362
diff
changeset
|
361 |
233b81d9bd9d
simple first version of SyncedGraph.runHandler
Drew Perttula <drewp@bigasterisk.com>
parents:
1362
diff
changeset
|
362 if rests.length != 1 |
1753
3c997bc6d380
fix some coffee lint
Drew Perttula <drewp@bigasterisk.com>
parents:
1751
diff
changeset
|
363 throw new Error( |
3c997bc6d380
fix some coffee lint
Drew Perttula <drewp@bigasterisk.com>
parents:
1751
diff
changeset
|
364 "list node #{current} has #{rests.length} rdf:rest edges") |
1363
233b81d9bd9d
simple first version of SyncedGraph.runHandler
Drew Perttula <drewp@bigasterisk.com>
parents:
1362
diff
changeset
|
365 current = rests[0].object |
233b81d9bd9d
simple first version of SyncedGraph.runHandler
Drew Perttula <drewp@bigasterisk.com>
parents:
1362
diff
changeset
|
366 |
233b81d9bd9d
simple first version of SyncedGraph.runHandler
Drew Perttula <drewp@bigasterisk.com>
parents:
1362
diff
changeset
|
367 return out |
1317
4c6d88aa9e26
enough element and rdf support to drag one adjuster and see its value change
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
368 |
4c6d88aa9e26
enough element and rdf support to drag one adjuster and see its value change
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
369 contains: (s, p, o) -> |
1363
233b81d9bd9d
simple first version of SyncedGraph.runHandler
Drew Perttula <drewp@bigasterisk.com>
parents:
1362
diff
changeset
|
370 @_autoDeps.askedFor(s, p, o, null) |
1707 | 371 return @graph.getQuads(s, p, o).length > 0 |
1317
4c6d88aa9e26
enough element and rdf support to drag one adjuster and see its value change
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
372 |
1387
26fabcf3a0a8
relocate nextNumberedResource to SyncedGraph
Drew Perttula <drewp@bigasterisk.com>
parents:
1386
diff
changeset
|
373 nextNumberedResources: (base, howMany) -> |
1741
17f56584e253
fix types so graph writing works again.
Drew Perttula <drewp@bigasterisk.com>
parents:
1739
diff
changeset
|
374 # base is NamedNode or string |
17f56584e253
fix types so graph writing works again.
Drew Perttula <drewp@bigasterisk.com>
parents:
1739
diff
changeset
|
375 base = base.id if base.id |
1387
26fabcf3a0a8
relocate nextNumberedResource to SyncedGraph
Drew Perttula <drewp@bigasterisk.com>
parents:
1386
diff
changeset
|
376 results = [] |
1786
11affc6d6045
more graph methods. some cleanup of the code that runs only required handlers, but it's not turned on yet
Drew Perttula <drewp@bigasterisk.com>
parents:
1783
diff
changeset
|
377 |
11affc6d6045
more graph methods. some cleanup of the code that runs only required handlers, but it's not turned on yet
Drew Perttula <drewp@bigasterisk.com>
parents:
1783
diff
changeset
|
378 # @contains is really slow. |
11affc6d6045
more graph methods. some cleanup of the code that runs only required handlers, but it's not turned on yet
Drew Perttula <drewp@bigasterisk.com>
parents:
1783
diff
changeset
|
379 @_nextNumber = new Map() unless @_nextNumber? |
11affc6d6045
more graph methods. some cleanup of the code that runs only required handlers, but it's not turned on yet
Drew Perttula <drewp@bigasterisk.com>
parents:
1783
diff
changeset
|
380 start = @_nextNumber.get(base) |
11affc6d6045
more graph methods. some cleanup of the code that runs only required handlers, but it's not turned on yet
Drew Perttula <drewp@bigasterisk.com>
parents:
1783
diff
changeset
|
381 if start == undefined |
11affc6d6045
more graph methods. some cleanup of the code that runs only required handlers, but it's not turned on yet
Drew Perttula <drewp@bigasterisk.com>
parents:
1783
diff
changeset
|
382 start = 0 |
11affc6d6045
more graph methods. some cleanup of the code that runs only required handlers, but it's not turned on yet
Drew Perttula <drewp@bigasterisk.com>
parents:
1783
diff
changeset
|
383 |
11affc6d6045
more graph methods. some cleanup of the code that runs only required handlers, but it's not turned on yet
Drew Perttula <drewp@bigasterisk.com>
parents:
1783
diff
changeset
|
384 for serial in [start..1000] |
1387
26fabcf3a0a8
relocate nextNumberedResource to SyncedGraph
Drew Perttula <drewp@bigasterisk.com>
parents:
1386
diff
changeset
|
385 uri = @Uri("#{base}#{serial}") |
26fabcf3a0a8
relocate nextNumberedResource to SyncedGraph
Drew Perttula <drewp@bigasterisk.com>
parents:
1386
diff
changeset
|
386 if not @contains(uri, null, null) |
26fabcf3a0a8
relocate nextNumberedResource to SyncedGraph
Drew Perttula <drewp@bigasterisk.com>
parents:
1386
diff
changeset
|
387 results.push(uri) |
1786
11affc6d6045
more graph methods. some cleanup of the code that runs only required handlers, but it's not turned on yet
Drew Perttula <drewp@bigasterisk.com>
parents:
1783
diff
changeset
|
388 @_nextNumber.set(base, serial + 1) |
1387
26fabcf3a0a8
relocate nextNumberedResource to SyncedGraph
Drew Perttula <drewp@bigasterisk.com>
parents:
1386
diff
changeset
|
389 if results.length >= howMany |
26fabcf3a0a8
relocate nextNumberedResource to SyncedGraph
Drew Perttula <drewp@bigasterisk.com>
parents:
1386
diff
changeset
|
390 return results |
26fabcf3a0a8
relocate nextNumberedResource to SyncedGraph
Drew Perttula <drewp@bigasterisk.com>
parents:
1386
diff
changeset
|
391 throw new Error("can't make sequential uri with base #{base}") |
1363
233b81d9bd9d
simple first version of SyncedGraph.runHandler
Drew Perttula <drewp@bigasterisk.com>
parents:
1362
diff
changeset
|
392 |
1387
26fabcf3a0a8
relocate nextNumberedResource to SyncedGraph
Drew Perttula <drewp@bigasterisk.com>
parents:
1386
diff
changeset
|
393 nextNumberedResource: (base) -> |
1753
3c997bc6d380
fix some coffee lint
Drew Perttula <drewp@bigasterisk.com>
parents:
1751
diff
changeset
|
394 @nextNumberedResources(base, 1)[0] |
1387
26fabcf3a0a8
relocate nextNumberedResource to SyncedGraph
Drew Perttula <drewp@bigasterisk.com>
parents:
1386
diff
changeset
|
395 |
1591
2713d2f7a0fc
resource-display can have a rename button for editing rdfs:label
Drew Perttula <drewp@bigasterisk.com>
parents:
1537
diff
changeset
|
396 contextsWithPattern: (s, p, o) -> |
1648
ffa3b81c6d95
some missing askedFor auditing
Drew Perttula <drewp@bigasterisk.com>
parents:
1647
diff
changeset
|
397 @_autoDeps.askedFor(s, p, o, null) |
1591
2713d2f7a0fc
resource-display can have a rename button for editing rdfs:label
Drew Perttula <drewp@bigasterisk.com>
parents:
1537
diff
changeset
|
398 ctxs = [] |
1707 | 399 for q in @graph.getQuads(s, p, o) |
1591
2713d2f7a0fc
resource-display can have a rename button for editing rdfs:label
Drew Perttula <drewp@bigasterisk.com>
parents:
1537
diff
changeset
|
400 ctxs.push(q.graph) |
2713d2f7a0fc
resource-display can have a rename button for editing rdfs:label
Drew Perttula <drewp@bigasterisk.com>
parents:
1537
diff
changeset
|
401 return _.unique(ctxs) |
2713d2f7a0fc
resource-display can have a rename button for editing rdfs:label
Drew Perttula <drewp@bigasterisk.com>
parents:
1537
diff
changeset
|
402 |
1781
e46907e9e053
sort numbers within uris numerically
Drew Perttula <drewp@bigasterisk.com>
parents:
1759
diff
changeset
|
403 sortedUris: (uris) -> |
e46907e9e053
sort numbers within uris numerically
Drew Perttula <drewp@bigasterisk.com>
parents:
1759
diff
changeset
|
404 _.sortBy uris, (u) -> |
e46907e9e053
sort numbers within uris numerically
Drew Perttula <drewp@bigasterisk.com>
parents:
1759
diff
changeset
|
405 parts = u.value.split(/([0-9]+)/) |
e46907e9e053
sort numbers within uris numerically
Drew Perttula <drewp@bigasterisk.com>
parents:
1759
diff
changeset
|
406 expanded = parts.map (p) -> |
e46907e9e053
sort numbers within uris numerically
Drew Perttula <drewp@bigasterisk.com>
parents:
1759
diff
changeset
|
407 f = parseInt(p) |
e46907e9e053
sort numbers within uris numerically
Drew Perttula <drewp@bigasterisk.com>
parents:
1759
diff
changeset
|
408 return p if isNaN(f) |
e46907e9e053
sort numbers within uris numerically
Drew Perttula <drewp@bigasterisk.com>
parents:
1759
diff
changeset
|
409 return p.padStart(8, '0') |
e46907e9e053
sort numbers within uris numerically
Drew Perttula <drewp@bigasterisk.com>
parents:
1759
diff
changeset
|
410 return expanded.join('') |
1786
11affc6d6045
more graph methods. some cleanup of the code that runs only required handlers, but it's not turned on yet
Drew Perttula <drewp@bigasterisk.com>
parents:
1783
diff
changeset
|
411 |
11affc6d6045
more graph methods. some cleanup of the code that runs only required handlers, but it's not turned on yet
Drew Perttula <drewp@bigasterisk.com>
parents:
1783
diff
changeset
|
412 # temporary optimization since autodeps calls too often |
11affc6d6045
more graph methods. some cleanup of the code that runs only required handlers, but it's not turned on yet
Drew Perttula <drewp@bigasterisk.com>
parents:
1783
diff
changeset
|
413 @patchContainsPreds: (patch, preds) -> |
11affc6d6045
more graph methods. some cleanup of the code that runs only required handlers, but it's not turned on yet
Drew Perttula <drewp@bigasterisk.com>
parents:
1783
diff
changeset
|
414 patchContainsPreds(patch, preds) |
11affc6d6045
more graph methods. some cleanup of the code that runs only required handlers, but it's not turned on yet
Drew Perttula <drewp@bigasterisk.com>
parents:
1783
diff
changeset
|
415 |
11affc6d6045
more graph methods. some cleanup of the code that runs only required handlers, but it's not turned on yet
Drew Perttula <drewp@bigasterisk.com>
parents:
1783
diff
changeset
|
416 prettyLiteral: (x) -> |
11affc6d6045
more graph methods. some cleanup of the code that runs only required handlers, but it's not turned on yet
Drew Perttula <drewp@bigasterisk.com>
parents:
1783
diff
changeset
|
417 if typeof(x) == 'number' |
11affc6d6045
more graph methods. some cleanup of the code that runs only required handlers, but it's not turned on yet
Drew Perttula <drewp@bigasterisk.com>
parents:
1783
diff
changeset
|
418 @LiteralRoundedFloat(x) |
11affc6d6045
more graph methods. some cleanup of the code that runs only required handlers, but it's not turned on yet
Drew Perttula <drewp@bigasterisk.com>
parents:
1783
diff
changeset
|
419 else |
11affc6d6045
more graph methods. some cleanup of the code that runs only required handlers, but it's not turned on yet
Drew Perttula <drewp@bigasterisk.com>
parents:
1783
diff
changeset
|
420 @Literal(x) |