test
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

merging

12Me21 b6c9a0c2 746415b3

+40
+40
facet.js
··· 1 + function merge_features_to_facets(features) { 2 + // at begin, push its type to stack 3 + // at end, pop 4 + // make list of begins and ends 5 + // sort 6 + // iterate 7 + let edges = [] 8 + for (let x of features) { 9 + edges.push([x.start,'start',x]) 10 + edges.push([x.end,'end',x]) 11 + } 12 + edges.sort((a,b)=>{a[0]-b[0]}) 13 + let open = new Set() 14 + let facets = [] 15 + let last = 0 16 + for (let [index,type,feature] of edges) { 17 + facets.push({ 18 + range: [last, index], 19 + features: [...open], 20 + }) 21 + open.delete(feature) || open.add(feature) 22 + last = index 23 + } 24 + return facets 25 + } 26 + 27 + spans = [ 28 + {type:"abc", start: 1, end: 5}, 29 + {type:"def", start: 3, end: 5}, 30 + {type:"zzz", start: 6, end: 10}, 31 + ] 32 + 33 + .aaaa..... 34 + ...dd.zzzz 35 + 36 + output = [ 37 + {start: 1, end: 3, types: ["abc"]}, 38 + {start: 3, end: 5, types: ["abc","def"]}, 39 + {start: 6, end: 10, types: ["zzz"]}, 40 + ]