Commit db2c864f authored by Themousaillon's avatar Themousaillon

filter refactor & small tweaks

parent 38374c74
......@@ -408,7 +408,8 @@
],
"filterable": {
"date": ["regest"]
"date": ["regest"],
"keywords": ["regest"]
},
"source": {
......
......@@ -105,6 +105,58 @@ class QueryEngine {
}
class NodeFilters {
constructor(settings){
this._settings = settings
}
ifTrue = node => {
node.hide = false
node.excluded = false
}
ifFalse = node => {
node.hide = true
node.excluded = true
}
/**
* @param startDate sould be a @Date object
* @param endDate sould be a @Date object
*/
filterByDate = (startDate, endDate) => node => {
const filterable = this._settings.filterable["date"]
if (node.collapsed)
return false
if (filterable.includes(node.type) && node.data["startDate"] && node.data["endDate"])
return node.data.startDate >= startDate && node.data.endDate <= endDate
else
return true
}
filterByKeywords = keywords => node => {
const filterable = this._settings.filterable["keywords"]
if (node.collapsed)
return false
if (keywords.length === 0)
return true
else if (filterable.includes(node.type))
return keywords.every(keyword => node.label.includes(keyword))
else
return true
}
filterAll = (keywords, startDate, endDate) => nodes => {
const keywordsFilter = this.filterByKeywords(keywords)
const dateFilter = this.filterByDate(startDate, endDate)
nodes.filterApply(
(node) => dateFilter(node) && keywordsFilter(node),
this.ifTrue,
this.ifFalse
)
}
}
/**
* This class handles all the data for the 2D multimodal graph.
* The data is handle unsynchronously, so you must use @function mutate to apply structure modification
......@@ -115,12 +167,12 @@ export class Graph2d {
constructor(dbConnector, idList, cullList){
// curentNodes contains the current nodes ids at expention n, in order to differentiate with n+1 expention
this._currentNodes = new Set(idList)
this._currentExpantion = new Set(idList)
this._nodes = new IdSet()
this._edges = new IdSet()
this._cullList = cullList
this._queryEngine = new QueryEngine(dbConnector)
this._pending = []
this._filters = new NodeFilters(dbConnector.settings)
this.fetchFromIds(idList)(x => x)
}
......@@ -146,7 +198,6 @@ export class Graph2d {
const idList = ids.filter(id => !this._currentNodes.has(id))
ids.forEach(id => {
this._currentNodes.add(id)
this._currentExpantion.add(id)
})
const params = {
queryName: "getComponentsAutoExpend",
......@@ -274,7 +325,6 @@ export class Graph2d {
this._edges.removeByIds(edgesIds)
idList.forEach(id => {
this._currentNodes.delete(id)
this._currentExpantion.delete(id)
f("node", id)
})
edgesIds.forEach(id => f("edge", id))
......@@ -282,58 +332,7 @@ export class Graph2d {
})
)
/**
* @param startDate sould be a @Date object
* @param endDate sould be a @Date object
*/
filterByDate = (startDate, endDate) => {
const filterable = this._queryEngine._dbConnector.settings.filterable["date"]
const condFn = node => {
if (node.collapsed)
return true
if (filterable.includes(node.type) && node.data["startDate"] && node.data["endDate"])
return node.data.startDate < startDate || node.data.endDate > endDate
else
return false
}
const f1 = node => {
node.hide = true
node.excluded = true
}
const f2 = node => {
if (this._currentNodes.has(node.id)){
node.hide = false
}
node.excluded = false
}
this._nodes.filterApply(condFn, f1, f2)
}
filterKeyword = (keyword) => {
const condFn = node => {
if (node.collapsed || keyword === "")
return true
else
return node.label.include(keyword)
}
const f1 = node => {
node.hide = true
node.excluded = true
}
const f2 = node => {
if (this._currentNodes.has(node.id)){
node.hide = false
}
node.excluded = false
}
this._nodes.filterApply(condFn, f1, f2)
}
filter = (keywords, startDate, endDate) => this._filters.filterAll(keywords, startDate, endDate)(this._nodes)
notNeighbors = ids => {
const related = new Set(
......
......@@ -88,8 +88,7 @@ function start(settings, login, password) {
let app = new App(dbConnector);
const graph2D = new Graph2D(dbConnector, [], []);
//testGraph2d(dbConnector)
testGraph2d(dbConnector)
// Setup interface
$('#db_name').html(settings.database.name);
$('#keyword').focus();
......@@ -398,6 +397,11 @@ function start(settings, login, password) {
}
requestAnimationFrame(animate);
$("#filter-content").on("input", () => {
const keywords = $("#filter-content").val().split(" ")
graph2D.graph2d.filterByKeywords(keywords)
graph2D.applyFilterToGraph()
})
return app;
}
......
......@@ -74,7 +74,7 @@ module.exports = class Queries{
let types = this.settings.keywordSearch.selection.map((e) => e.layer);
let i = types.indexOf(type);
let query = this.settings.keywordSearch.selection[i].query;
keyword = keyword.replace("(", "\\\\(").replace(")", "\\\\)").replace(".", "\\\\.")
keyword = keyword.replace("(", "\\\\(").replace(")", "\\\\)").replace(".", "\\\\.").replace("]", "\\\\]").replace("[", "\\\\[")
query = query.replace(/%KEYWORD%/g, keyword);
query = query.replace(/%CULLS%/g, culls);
return query;
......
......@@ -33,6 +33,9 @@ export default class IdSet {
collectFromKeys = idList => idList.map(id => this._entries[id])
/**
* if condFn is true, call f1 else call f2
*/
filterApply = (condFn, f1, f2) => {
for (let id in this._entries){
if (condFn(this._entries[id]))
......
......@@ -32,7 +32,7 @@ export class EntrySearch {
getNodeName = (node, type) => node.properties[this._dbConnector.settings.nodeTypes2[type].labelField]
searchEntry = (searchString, type) => {
if (this._entries[type])
if (this._entries[type] && searchString.length > 2)
return this._entries[type].filter(x => x && x.toLowerCase().includes(searchString.toLowerCase()))
else
return []
......
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