This repository has been archived by the owner on Jan 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
8,451 additions
and
5,233 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
'use strict'; | ||
|
||
import mlTreeFacet from './ml-tree-facet.vue'; | ||
import mlSubTree from './ml-sub-tree.vue'; | ||
|
||
export default { | ||
mlTreeFacet, | ||
mlSubTree | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
<template> | ||
<ul class="ml-sub-tree"> | ||
<li v-for="(id, $index) in nonEmptystartIds" :key="$index" :id="id"> | ||
<div :class="nodes[id].highlight ? 'ml-tree-highlight' : ''"> | ||
<a | ||
href | ||
v-if=" | ||
nodes[id].children.length && | ||
(showEmpty || nodes[id].sum > (nodes[id].value || 0)) | ||
" | ||
v-on:click.prevent="toggle(id)" | ||
> | ||
<i class="fa fa-chevron-right" v-show="collapsed[id]"></i> | ||
<i class="fa fa-chevron-down" v-show="!collapsed[id]"></i> | ||
</a> | ||
<a href v-on:click.prevent="onClick(nodes[id])">{{ | ||
nodes[id].label | ||
}}</a> | ||
<a href v-on:click.prevent="onClick(nodes[id], true)" | ||
><i class="fa fa-remove"></i | ||
></a> | ||
<span v-show="nodes[id].value"> ({{ nodes[id].value }})</span> | ||
<span v-show="nodes[id].sum > (nodes[id].value || 0)"> | ||
[{{ nodes[id].sum }}]</span | ||
> | ||
</div> | ||
<div v-if="!collapsed[id] && nodes[id].children.length"> | ||
<ml-sub-tree | ||
:nodes="nodes" | ||
:start-ids="nodes[id].children" | ||
:on-click="onClick" | ||
:show-empty="showEmpty" | ||
></ml-sub-tree> | ||
</div> | ||
</li> | ||
</ul> | ||
</template> | ||
|
||
<script> | ||
export default { | ||
name: 'ml-sub-tree', | ||
components: {}, | ||
data() { | ||
return { | ||
collapsed: {}, | ||
console: console | ||
}; | ||
}, | ||
props: { | ||
nodes: { | ||
type: Object, | ||
required: true | ||
}, | ||
startIds: { | ||
type: Array, | ||
required: true | ||
}, | ||
onClick: { | ||
type: Function, | ||
default: function() {} | ||
}, | ||
showEmpty: { | ||
type: Boolean, | ||
default: false | ||
} | ||
}, | ||
computed: { | ||
nonEmptystartIds() { | ||
if (this.showEmpty) { | ||
return this.startIds.filter(id => { | ||
const node = this.nodes[id]; | ||
return node !== undefined; | ||
}); | ||
} else { | ||
return this.startIds.filter(id => { | ||
const node = this.nodes[id]; | ||
return node && node.sum > 0; | ||
}); | ||
} | ||
} | ||
}, | ||
methods: { | ||
toggle(id) { | ||
this.$set(this.collapsed, id, !this.collapsed[id]); | ||
} | ||
} | ||
}; | ||
</script> | ||
|
||
<style lang="less" scoped> | ||
ul.ml-sub-tree { | ||
list-style: none; | ||
.ml-tree-highlight { | ||
background-color: lightyellow; | ||
} | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,229 @@ | ||
<template> | ||
<div | ||
class="ml-facet ml-tree-facet" | ||
v-if="startIds.length" | ||
v-show="!facet.hide" | ||
> | ||
<h3 v-on:click.prevent="showHideFacet()"> | ||
{{ facet.name | capitalize }} | ||
<div class="pull-right"> | ||
<i class="fa fa-caret-right" v-if="!facetOpen"></i> | ||
<i class="fa fa-caret-down" v-if="!!facetOpen"></i> | ||
</div> | ||
</h3> | ||
<div v-if="facetOpen"> | ||
<form v-if="showSearch" v-on:submit.prevent="highlightNodes()"> | ||
<span> | ||
Search: | ||
<!--input v-model="searchNode" autocomplete="off" uib-typeahead="suggestion for suggestion in suggestionsList | filter:$viewValue | limitTo:20" placeholder="in the tree below"--> | ||
<multiselect | ||
:value="searchNode" | ||
:options="suggestionsList" | ||
:multiple="false" | ||
:searchable="true" | ||
:clear-on-select="false" | ||
placeholder="in the tree below" | ||
open-direction="bottom" | ||
v-on:select="highlightNodes" | ||
> | ||
</multiselect> | ||
</span> | ||
<div> | ||
Show empty nodes | ||
<input type="checkbox" v-model="showEmpty_" /> | ||
</div> | ||
</form> | ||
|
||
<ml-sub-tree | ||
:nodes="nodes_" | ||
:start-ids="startIds" | ||
:on-click="onClick" | ||
:show-empty="showEmpty_" | ||
></ml-sub-tree> | ||
</div> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
import Multiselect from 'vue-multiselect'; | ||
import mlSubTree from './ml-sub-tree.vue'; | ||
import 'vue-multiselect/dist/vue-multiselect.min.css'; | ||
export default { | ||
name: 'ml-tree-facet', | ||
components: { | ||
Multiselect, | ||
mlSubTree | ||
}, | ||
props: { | ||
facet: { | ||
type: Object, | ||
required: true | ||
}, | ||
nodes: { | ||
type: Object, | ||
required: true | ||
}, | ||
startIds: { | ||
type: Array, | ||
required: true | ||
}, | ||
toggle: { | ||
type: Function, | ||
default: function() {} | ||
}, | ||
negate: { | ||
type: Function, | ||
default: function() {} | ||
}, | ||
showSearch: { | ||
type: Boolean, | ||
default: true | ||
}, | ||
showEmpty: { | ||
type: Boolean, | ||
default: false | ||
} | ||
}, | ||
data() { | ||
return { | ||
searchNode: '', | ||
suggestionsList: [], | ||
showEmpty_: false, | ||
nodes_: {}, | ||
facetOpen: true | ||
}; | ||
}, | ||
methods: { | ||
showHideFacet() { | ||
this.facetOpen = !this.facetOpen; | ||
}, | ||
onClick(node, negate) { | ||
if (negate) { | ||
this.negate(this.facet.name, this.facet.type, node.id, node.label); | ||
} else { | ||
this.toggle(this.facet.name, this.facet.type, node.id, node.label); | ||
} | ||
}, | ||
calculateSums(nodes, startIds) { | ||
var self = this; | ||
var totalSum = 0; | ||
startIds.forEach(function(id) { | ||
var node = nodes[id]; | ||
var sum = node.children ? self.calculateSums(nodes, node.children) : 0; | ||
sum = sum + (node.value || 0); | ||
node.sum = sum; | ||
totalSum += sum; | ||
}); | ||
return totalSum; | ||
}, | ||
updateSuggestions(nodes) { | ||
var self = this; | ||
self.suggestionsList = []; | ||
Object.keys(nodes).forEach(id => { | ||
const node = nodes[id]; | ||
if (node.sum > 0) { | ||
if (node.label) { | ||
self.suggestionsList.push(node.label); | ||
} | ||
if (node.altLabels) { | ||
node.altLabels.forEach(function(label) { | ||
self.suggestionsList.push(label); | ||
}); | ||
} | ||
} | ||
}); | ||
self.suggestionsList.sort(); | ||
}, | ||
highlightNodes(selected) { | ||
var self = this; | ||
this.searchNode = selected !== undefined ? selected : this.searchNode; | ||
var noMatch = { | ||
test: function() { | ||
return false; | ||
} | ||
}; | ||
var _highlightNodes = function(match, startIds) { | ||
var totalHit = false; | ||
startIds.forEach(function(id) { | ||
var node = self.nodes_[id]; | ||
var hit = node.children | ||
? _highlightNodes(match, node.children) | ||
: false; | ||
if (!hit) { | ||
hit = node.label && match.test(node.label); | ||
} | ||
if (!hit) { | ||
hit = | ||
node.altLabels && | ||
node.altLabels.filter(function(label) { | ||
return match.test(label); | ||
}).length; | ||
} | ||
if (hit) { | ||
self.$set(node, 'highlight', true); | ||
totalHit = true; | ||
} else { | ||
self.$set(node, 'highlight', false); | ||
} | ||
}); | ||
return totalHit; | ||
}; | ||
if (this.searchNode) { | ||
var match = new RegExp('' + this.searchNode, 'i'); | ||
_highlightNodes(match, this.startIds); | ||
} else { | ||
_highlightNodes(noMatch, this.startIds); | ||
} | ||
}, | ||
init() { | ||
if (this.facet !== undefined && Object.keys(this.nodes).length) { | ||
var nodes = JSON.parse(JSON.stringify(this.nodes)); | ||
this.facet.facetValues.forEach(facetValue => { | ||
nodes[facetValue.value].value = facetValue.count; | ||
}); | ||
this.calculateSums(nodes, this.startIds); | ||
this.updateSuggestions(nodes); | ||
this.nodes_ = nodes; | ||
} | ||
} | ||
}, | ||
created() { | ||
this.init(); | ||
}, | ||
watch: { | ||
showEmpty(newEmpty) { | ||
if (newEmpty !== undefined) { | ||
this.showEmpty_ = newEmpty; | ||
} | ||
}, | ||
facet() { | ||
this.init(); | ||
}, | ||
nodes() { | ||
this.init(); | ||
} | ||
} | ||
}; | ||
</script> | ||
|
||
<style lang="less" scoped> | ||
.ml-facet { | ||
.facet-add-pos, | ||
.facet-add-neg { | ||
visibility: hidden; | ||
} | ||
span:hover > .facet-add-pos, | ||
div:hover > .facet-add-neg { | ||
visibility: visible !important; | ||
} | ||
form { | ||
padding-bottom: 0; | ||
} | ||
} | ||
</style> |
Oops, something went wrong.