Commit 97cab5ea authored by Yannick Chudy's avatar Yannick Chudy

triggers on explore components

parent 5aa126a6
...@@ -29,7 +29,7 @@ jade: ...@@ -29,7 +29,7 @@ jade:
rundev: rundev:
. venv3/bin/activate; export APP_DEBUG=false; export FLASK_APP=botapadapp.py ;export FLASK_DEBUG=1; flask run . venv3/bin/activate; export APP_DEBUG=false; export FLASK_APP=botapadapp.py ;export FLASK_DEBUG=1; flask run --port 5002
docker-build: docker-build:
......
...@@ -144,30 +144,12 @@ def _weights(weightings): ...@@ -144,30 +144,12 @@ def _weights(weightings):
return _w return _w
def explore_engine(graphdb): def prox_subgraph(graph, uuids, cut=100, weighted=True, length=7, mode=ALL, add_loops=False, **kwargs ):
""" Prox engine """
# setup
engine = Engine("graph")
engine.graph.setup(in_name="request", out_name="graph")
## Search
@Composable
def get_graph(query, **kwargs):
return db_graph(graphdb, query)
@Composable
def subgraph(query, cut=100, weighted=True, length=7, mode=ALL, add_loops=False, **kwargs ):
graph = db_graph(graphdb, query)
uuids = { v['uuid'] : v.index for v in graph.vs }
pz = [ q for q in query.get('units', []) ]
pz = [ uuids[p] for p in pz ]
extract = ProxExtract() extract = ProxExtract()
vs = [] vs = []
if len(pz): if len(uuids):
for u in pz: for u in uuids:
s = extract(graph, pzeros=[u], weighted=weighted,mode=mode, cut=cut, length=length) s = extract(graph, pzeros=[u], weighted=weighted,mode=mode, cut=cut, length=length)
vs = vs + list(s.keys()) vs = vs + list(s.keys())
else : else :
...@@ -176,33 +158,6 @@ def explore_engine(graphdb): ...@@ -176,33 +158,6 @@ def explore_engine(graphdb):
return _prune(graph.subgraph(vs)) return _prune(graph.subgraph(vs))
from cello.graphs.transform import VtxAttr
searchs = []
for k,w,l,m,n in [
(u"Search", True, 6, ALL ,100 ), ]:
search = Optionable("GraphSearch")
search._func = subgraph
search.add_option("weighted", Boolean(default=w))
search.add_option("add_loops", Boolean(default=True, help="add loops on vertices"))
search.add_option("mode", Numeric(choices=[ OUT, IN, ALL], default=m, help="edge directions"))
search.add_option("length", Numeric( vtype=int, min=1, default=l))
search.add_option("cut", Numeric( vtype=int, min=2, default=n))
search |= VtxAttr(color=[(45, 200, 34), ])
search |= VtxAttr(type=1)
search.name = k
searchs.append(search)
sglobal = get_graph | ProxSubgraph()
sglobal.name = "Global"
sglobal.change_option_default("cut", 200);
searchs.append(sglobal)
engine.graph.set( *searchs )
return engine
def expand_subgraph(graph, expand, nodes,length=4, cut=100, weightings=None): def expand_subgraph(graph, expand, nodes,length=4, cut=100, weightings=None):
pz = {} pz = {}
...@@ -280,12 +235,99 @@ def starred(graph, limit=200, prune=True): ...@@ -280,12 +235,99 @@ def starred(graph, limit=200, prune=True):
return graph return graph
def starred_engine(graphdb):
""" Prox engine """
# setup
engine = Engine("graph")
engine.graph.setup(in_name="request", out_name="graph")
## Search
def subgraph(query, limit=200, prune=False):
"""
:param mode:
"""
graph = db_graph(graphdb, query)
return starred(graph, limit=100, prune=True)
graph_search = Optionable("GraphSearch")
graph_search._func = Composable(subgraph)
graph_search.add_option("limit", Numeric( vtype=int, default=200))
graph_search.add_option("prune", Boolean(default=True))
from cello.graphs.transform import VtxAttr
graph_search |= VtxAttr(color=[(45, 200, 34), ])
graph_search |= VtxAttr(type=1)
engine.graph.set(graph_search)
return engine
def explore_engine(graphdb):
""" Prox engine """
# setup
engine = Engine("graph")
engine.graph.setup(in_name="request", out_name="graph")
## Search
@Composable
def get_graph(query, **kwargs):
return db_graph(graphdb, query)
@Composable
def subgraph(query, cut=100, weighted=True, length=7, mode=ALL, add_loops=False, **kwargs ):
graph = db_graph(graphdb, query)
idx = { v['uuid'] : v.index for v in graph.vs }
uuids = [ q for q in query.get('units', []) ]
uuids = [ idx[p] for p in uuids ]
return prox_subgraph(graph, uuids, cut=cut, weighted=weighted, length=length, mode=mode, add_loops=add_loops, **kwargs )
from cello.graphs.transform import VtxAttr
searchs = []
for k,w,l,m,n in [
(u"Search", True, 6, ALL ,100 ), ]:
search = Optionable("GraphSearch")
search._func = subgraph
search.add_option("weighted", Boolean(default=w))
search.add_option("add_loops", Boolean(default=True, help="add loops on vertices"))
search.add_option("mode", Numeric(choices=[ OUT, IN, ALL], default=m, help="edge directions"))
search.add_option("length", Numeric( vtype=int, min=1, default=l))
search.add_option("cut", Numeric( vtype=int, min=2, default=n))
search |= VtxAttr(color=[(45, 200, 34), ])
search |= VtxAttr(type=1)
search.name = k
searchs.append(search)
sglobal = get_graph | ProxSubgraph()
sglobal.name = "Global"
sglobal.change_option_default("cut", 200);
searchs.append(sglobal)
engine.graph.set( *searchs )
return engine
def explore_api(engines, graphdb): def explore_api(engines, graphdb):
#explor_api = explor.explore_api("xplor", graphdb, engines) #explor_api = explor.explore_api("xplor", graphdb, engines)
api = ReliureAPI("xplor",expose_route=False) api = ReliureAPI("xplor",expose_route=False)
# starred
view = EngineView(starred_engine(graphdb))
view.set_input_type(ComplexQuery())
view.add_output("request", ComplexQuery())
view.add_output("graph", export_graph, id_attribute='uuid')
api.register_view(view, url_prefix="starred")
# prox search returns graph only # prox search returns graph only
view = EngineView(explore_engine(graphdb)) view = EngineView(explore_engine(graphdb))
view.set_input_type(ComplexQuery()) view.set_input_type(ComplexQuery())
...@@ -309,6 +351,15 @@ def explore_api(engines, graphdb): ...@@ -309,6 +351,15 @@ def explore_api(engines, graphdb):
api.register_view(view, url_prefix="additive_nodes") api.register_view(view, url_prefix="additive_nodes")
@api.route("/starred/<string:gid>.json", methods=['GET'])
def g_json_dump(gid):
graph = graphdb.get_graph(gid)
g = starred(graph, limit=100, prune=True)
g = export_graph( g, id_attribute='uuid')
return jsonify(g)
@api.route("/<string:gid>.json", methods=['GET']) @api.route("/<string:gid>.json", methods=['GET'])
def _json_dump(gid): def _json_dump(gid):
dumps = lambda g : json.dumps( export_graph(g, id_attribute='uuid') ) dumps = lambda g : json.dumps( export_graph(g, id_attribute='uuid') )
......
...@@ -39,7 +39,7 @@ RUN_GUNICORN = os.environ.get('RUN_GUNICORN', None) == "1" ...@@ -39,7 +39,7 @@ RUN_GUNICORN = os.environ.get('RUN_GUNICORN', None) == "1"
PATH = "./static/images" # images storage PATH = "./static/images" # images storage
STATIC_HOST = os.environ.get('STATIC_HOST', "") STATIC_HOST = os.environ.get('STATIC_HOST', "")
ENGINES_HOST = os.environ.get('ENGINES_HOST', "http://localhost:5000") ENGINES_HOST = os.environ.get('ENGINES_HOST', "http://localhost:5002")
PADAGRAPH_HOST = os.environ.get('PADAGRAPH_HOST', ENGINES_HOST) PADAGRAPH_HOST = os.environ.get('PADAGRAPH_HOST', ENGINES_HOST)
DELETE = os.environ.get('BOTAPAD_DELETE', "nope").lower() == "true" DELETE = os.environ.get('BOTAPAD_DELETE', "nope").lower() == "true"
...@@ -456,6 +456,7 @@ def botimport(repo, padurl, gid, content_type): ...@@ -456,6 +456,7 @@ def botimport(repo, padurl, gid, content_type):
'auto_rotate': int(args.get("auto_rotate", 0 )), 'auto_rotate': int(args.get("auto_rotate", 0 )),
'adaptive_zoom': int(args.get("adaptive_zoom", 1 )), 'adaptive_zoom': int(args.get("adaptive_zoom", 1 )),
'layout' : args.get("layout") if args.get("layout", "2D" ) in ("2D","3D") else "2D",
} }
...@@ -643,17 +644,8 @@ from pdglib.graphdb_ig import engines ...@@ -643,17 +644,8 @@ from pdglib.graphdb_ig import engines
from botapadapi import explore_api, starred from botapadapi import explore_api, starred
from pdgapi.explor import layout_api, clustering_api from pdgapi.explor import layout_api, clustering_api
api = explore_api(engines, graphdb)
@api.route("/starred/<string:gid>.json", methods=['GET'])
def g_json_dump(gid):
graph = graphdb.get_graph(gid)
g = starred(graph, limit=100, prune=True)
g = export_graph( g, id_attribute='uuid')
return jsonify(g)
api = explore_api(engines, graphdb)
api = layout_api(engines, api) api = layout_api(engines, api)
api = clustering_api(engines, api) api = clustering_api(engines, api)
......
...@@ -147,21 +147,21 @@ ...@@ -147,21 +147,21 @@
// panel tabs // panel tabs
setupUI(){ setupUI(){
var app = this.app;
// reset query button // reset query button
$('#btnreset').click( () => { $('#btnreset').click( () => {
this.app.models.clustering.reset({}) app.models.clustering.reset({})
this.app.models.userquery.reset(); app.models.userquery.reset();
this.app.models.graph.es.set_selected([]); app.models.graph.es.set_selected([]);
this.app.models.graph.vs.set_selected([]); app.models.graph.vs.set_selected([]);
this.app.models.graph.reset({vs:[], es:[]}); app.models.graph.reset({vs:[], es:[]});
}); });
$('#btn_plusdix').click(()=> { $('#btn_plusdix').click(()=> {
Backbone.trigger('engine:expand_prox', { expand: [], weights:[] }) Backbone.trigger('engine:expand_prox', { expand: [], weights:[] })
}); });
$('#btn_global').click(()=> { $('#btn_global').click(()=> {
this.app.trigger('engine:explore', 'Global') app.trigger('engine:explore', 'Global')
}); });
$('#btn_rotate').click(()=> { $('#btn_rotate').click(()=> {
var gviz = this.app.gviz var gviz = this.app.gviz
...@@ -176,13 +176,18 @@ ...@@ -176,13 +176,18 @@
$('#btn_2d3d').click(()=> { $('#btn_2d3d').click(()=> {
var t = $('#btn_2d3d span.active').text(); var t = $('#btn_2d3d span.active').text();
t = t == "2D" ? "3D" : "2D"; t = t == "2D" ? "3D" : "2D";
this.app.trigger('engine:layout', t + '_Force_directed') app.trigger('engine:layout', t + '_Force_directed')
$('#btn_2d3d span').toggleClass('active') $('#btn_2d3d span').toggleClass('active')
$('#btn_2d3d span').toggleClass('small') $('#btn_2d3d span').toggleClass('small')
}); });
}, if (this.options.layout == "3D")$('#btn_2d3d').click(); // force 3d with option 'layout':'3D'
attached() {
console.log('botapad-app attached') var _window_resized = function(){
if (app.gviz) app.gviz.resize_rendering();
}
$(window).on('resize', _window_resized );
_window_resized();
}, },
startapp(routes, data, sync, options) { startapp(routes, data, sync, options) {
...@@ -340,12 +345,6 @@ ...@@ -340,12 +345,6 @@
console.log("gviz_is now attached ") console.log("gviz_is now attached ")
}); });
var _window_resized = function(){
if (app.gviz) app.gviz.resize_rendering();
}
$(window).on('resize', _window_resized );
_window_resized();
} }
}); });
} // routes: } // routes:
......
This diff is collapsed.
...@@ -1104,10 +1104,22 @@ App.Base = Backbone.View.extend({ ...@@ -1104,10 +1104,22 @@ App.Base = Backbone.View.extend({
var explore = Engine({url: routes.explore.url}); var explore = Engine({url: routes.explore.url});
explore.register_input("request", app.models.query); explore.register_input("request", app.models.query);
app.listenTo( Backbone,"engine:explore", function(params){ app.listenTo( Backbone,"engine:explore", function(name, params){
if ( !explore.blocks.length) return;
console.log('engine:layout', name);
var comps = explore.blocks.at(0).components;
comps.each( function(e){ e.set('selected', false) } );
var comp = comps.get(name);
if (! comp) comp = comps.at(0);
comp.set('selected', true);
app.models.query.reset_from_models(params) app.models.query.reset_from_models(params)
explore.play(); explore.play();
}); });
app.listenTo(explore, 'play:success', app.explore_reset); app.listenTo(explore, 'play:success', app.explore_reset);
app.engines.explore = explore; app.engines.explore = explore;
......
This diff is collapsed.
...@@ -952,6 +952,7 @@ gviz.DEFAULTS = { ...@@ -952,6 +952,7 @@ gviz.DEFAULTS = {
debug : false debug : false
}; };
gviz.ThreeViz = Backbone.View.extend({ gviz.ThreeViz = Backbone.View.extend({
initialize: function(attributes){ initialize: function(attributes){
...@@ -1455,7 +1456,8 @@ gviz.ThreeViz = Backbone.View.extend({ ...@@ -1455,7 +1456,8 @@ gviz.ThreeViz = Backbone.View.extend({
if (obj.nodetype) if (obj.nodetype)
material.text_lines = get_text_lines( obj, material ); material.text_lines = get_text_lines( obj, material );
if (material.shape == null) material.shape='circle'; if (gviz.SHAPES.indexOf(material.shape) == -1 )
material.shape = 'circle';
material.id = obj.id; material.id = obj.id;
return material; return material;
...@@ -2029,6 +2031,8 @@ gviz.ThreeViz = Backbone.View.extend({ ...@@ -2029,6 +2031,8 @@ gviz.ThreeViz = Backbone.View.extend({
* *
*/ */
gviz.SHAPES = "circle square losange diamond triangle triangle-top triangle-bottom".split(' ')
gviz.ThreeVizHelpers = { gviz.ThreeVizHelpers = {
PI2: Math.PI * 2, PI2: Math.PI * 2,
...@@ -2135,7 +2139,6 @@ gviz.ThreeVizHelpers = { ...@@ -2135,7 +2139,6 @@ gviz.ThreeVizHelpers = {
context.scale(scale, scale); context.scale(scale, scale);
node._scale *= scale; node._scale *= scale;
//
if (material.shape == 'circle') // centered on 0.0 if (material.shape == 'circle') // centered on 0.0
{ {
......
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -630,7 +630,7 @@ require(['backbone', 'jquery', 'pdgconst'], function (Backbone, $, Const) { ...@@ -630,7 +630,7 @@ require(['backbone', 'jquery', 'pdgconst'], function (Backbone, $, Const) {
explore: function explore() { explore: function explore() {
var params = { graph: this.graph, query: this.model.id }; var params = { graph: this.graph, query: this.model.id };
Backbone.trigger('engine:explore', params); Backbone.trigger('engine:explore', "Search", params);
}, },
edit: function edit() { edit: function edit() {
...@@ -1342,7 +1342,7 @@ require(['backbone', 'pdgconst'], function (Backbone, Const) { ...@@ -1342,7 +1342,7 @@ require(['backbone', 'pdgconst'], function (Backbone, Const) {
} else if (action == 'explore') { } else if (action == 'explore') {
if (ismodel) { if (ismodel) {
var params = { graph: this.model.graph.id, query: this.model.id }; var params = { graph: this.model.graph.id, query: this.model.id };
Backbone.trigger('engine:explore', params); Backbone.trigger('engine:explore', 'Search', params);
} }
} else if (action == 'expand') { } else if (action == 'expand') {
var params = { graph: this.model.graph.id, expand: [this.model.id], weights: [] }; var params = { graph: this.model.graph.id, expand: [this.model.id], weights: [] };
...@@ -1702,7 +1702,7 @@ require(['backbone', 'cello', 'gviz', 'materials', 'pdgconst'], function (Backbo ...@@ -1702,7 +1702,7 @@ require(['backbone', 'cello', 'gviz', 'materials', 'pdgconst'], function (Backbo
explore: function explore() { explore: function explore() {
var graph = this.model.graph; var graph = this.model.graph;
var params = { graph: graph.id, query: this.model.id }; var params = { graph: graph.id, query: this.model.id };
Backbone.trigger('engine:explore', params); Backbone.trigger('engine:explore', "Search", params);
}, },
shortuuid: function shortuuid(model) { shortuuid: function shortuuid(model) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment