author | ymh <ymh.work@gmail.com> |
Fri, 09 Dec 2016 11:41:15 +0100 | |
changeset 467 | 762fc0eb4946 |
parent 424 | feb0d3e0fef9 |
child 532 | 1190ea937f2d |
permissions | -rw-r--r-- |
48
9ef0952033e0
add example of visualisation for "chonologie"
nowmad@nowmads-macbook-pro.local
parents:
diff
changeset
|
1 |
import Ember from 'ember'; |
392
4fbe94af93e8
Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents:
234
diff
changeset
|
2 |
import _ from 'lodash/lodash'; |
48
9ef0952033e0
add example of visualisation for "chonologie"
nowmad@nowmads-macbook-pro.local
parents:
diff
changeset
|
3 |
|
197 | 4 |
export default Ember.Component.extend({ |
120 | 5 |
|
424
feb0d3e0fef9
add dynamic date range calculation for dates, and add color gradient component, add color gradient for language and chrono
ymh <ymh.work@gmail.com>
parents:
393
diff
changeset
|
6 |
colors: Ember.inject.service(), |
feb0d3e0fef9
add dynamic date range calculation for dates, and add color gradient component, add color gradient for language and chrono
ymh <ymh.work@gmail.com>
parents:
393
diff
changeset
|
7 |
filter: Ember.inject.service(), |
feb0d3e0fef9
add dynamic date range calculation for dates, and add color gradient component, add color gradient for language and chrono
ymh <ymh.work@gmail.com>
parents:
393
diff
changeset
|
8 |
|
feb0d3e0fef9
add dynamic date range calculation for dates, and add color gradient component, add color gradient for language and chrono
ymh <ymh.work@gmail.com>
parents:
393
diff
changeset
|
9 |
range: null, |
393 | 10 |
rawdatestats: null, |
392
4fbe94af93e8
Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents:
234
diff
changeset
|
11 |
|
424
feb0d3e0fef9
add dynamic date range calculation for dates, and add color gradient component, add color gradient for language and chrono
ymh <ymh.work@gmail.com>
parents:
393
diff
changeset
|
12 |
rangeArray: Ember.computed('range', 'range.[]', function() { |
feb0d3e0fef9
add dynamic date range calculation for dates, and add color gradient component, add color gradient for language and chrono
ymh <ymh.work@gmail.com>
parents:
393
diff
changeset
|
13 |
let range = this.get('range'); |
feb0d3e0fef9
add dynamic date range calculation for dates, and add color gradient component, add color gradient for language and chrono
ymh <ymh.work@gmail.com>
parents:
393
diff
changeset
|
14 |
let resArray = []; |
feb0d3e0fef9
add dynamic date range calculation for dates, and add color gradient component, add color gradient for language and chrono
ymh <ymh.work@gmail.com>
parents:
393
diff
changeset
|
15 |
range.forEach(function(s) { resArray.push(parseInt(s.id)); }); |
feb0d3e0fef9
add dynamic date range calculation for dates, and add color gradient component, add color gradient for language and chrono
ymh <ymh.work@gmail.com>
parents:
393
diff
changeset
|
16 |
return resArray.sort(); |
feb0d3e0fef9
add dynamic date range calculation for dates, and add color gradient component, add color gradient for language and chrono
ymh <ymh.work@gmail.com>
parents:
393
diff
changeset
|
17 |
}), |
feb0d3e0fef9
add dynamic date range calculation for dates, and add color gradient component, add color gradient for language and chrono
ymh <ymh.work@gmail.com>
parents:
393
diff
changeset
|
18 |
|
feb0d3e0fef9
add dynamic date range calculation for dates, and add color gradient component, add color gradient for language and chrono
ymh <ymh.work@gmail.com>
parents:
393
diff
changeset
|
19 |
decades: Ember.computed('rangeArray', function() { |
feb0d3e0fef9
add dynamic date range calculation for dates, and add color gradient component, add color gradient for language and chrono
ymh <ymh.work@gmail.com>
parents:
393
diff
changeset
|
20 |
var range = this.get('rangeArray'); |
393 | 21 |
return _.range(Math.floor(range[0]/10)*10, (Math.floor(range[1]/10)+1)*10, 10); |
392
4fbe94af93e8
Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents:
234
diff
changeset
|
22 |
}), |
4fbe94af93e8
Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents:
234
diff
changeset
|
23 |
|
393 | 24 |
datestats: Ember.computed('rawdatestats.[]', function() { |
25 |
var res = {}; |
|
26 |
this.get('rawdatestats').forEach(function(s) { |
|
27 |
res[s.get('id')] = s.get('count'); |
|
28 |
}); |
|
29 |
return Ember.Object.create(res); |
|
30 |
}), |
|
31 |
||
32 |
counts: Ember.computed.mapBy('rawdatestats', 'count'), |
|
33 |
maxCount: Ember.computed.max('counts'), |
|
34 |
minCount: Ember.computed.min('counts'), |
|
424
feb0d3e0fef9
add dynamic date range calculation for dates, and add color gradient component, add color gradient for language and chrono
ymh <ymh.work@gmail.com>
parents:
393
diff
changeset
|
35 |
colorScale: Ember.computed('maxCount', 'minCount', function() { |
feb0d3e0fef9
add dynamic date range calculation for dates, and add color gradient component, add color gradient for language and chrono
ymh <ymh.work@gmail.com>
parents:
393
diff
changeset
|
36 |
return this.get('colors').getScaleLinear(this.get('minCount'), this.get('maxCount')); |
feb0d3e0fef9
add dynamic date range calculation for dates, and add color gradient component, add color gradient for language and chrono
ymh <ymh.work@gmail.com>
parents:
393
diff
changeset
|
37 |
}), |
189
21b30ee23191
/langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents:
120
diff
changeset
|
38 |
|
393 | 39 |
date: Ember.computed.alias('filter.dateList'), |
392
4fbe94af93e8
Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents:
234
diff
changeset
|
40 |
|
195
9d083636bd99
Layout and style of the /chronologie endpoint
Chloe Laisne <chloe.laisne@gmail.com>
parents:
189
diff
changeset
|
41 |
elementId: "chrono-table", |
9d083636bd99
Layout and style of the /chronologie endpoint
Chloe Laisne <chloe.laisne@gmail.com>
parents:
189
diff
changeset
|
42 |
|
189
21b30ee23191
/langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents:
120
diff
changeset
|
43 |
didInsertElement: function(){ |
393 | 44 |
|
189
21b30ee23191
/langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents:
120
diff
changeset
|
45 |
var self = this; |
21b30ee23191
/langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents:
120
diff
changeset
|
46 |
|
21b30ee23191
/langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents:
120
diff
changeset
|
47 |
var isMouseDown = false, |
233
0ff47a9c5da2
Keyboard events on chronology
Chloe Laisne <chloe.laisne@gmail.com>
parents:
202
diff
changeset
|
48 |
isHighlighted, |
0ff47a9c5da2
Keyboard events on chronology
Chloe Laisne <chloe.laisne@gmail.com>
parents:
202
diff
changeset
|
49 |
didHighlight, |
0ff47a9c5da2
Keyboard events on chronology
Chloe Laisne <chloe.laisne@gmail.com>
parents:
202
diff
changeset
|
50 |
previousElement; |
77
0889740f79c2
on page load, hilight the objects corresponding to the query params
nowmad@23.1.168.192.in-addr.arpa
parents:
72
diff
changeset
|
51 |
|
233
0ff47a9c5da2
Keyboard events on chronology
Chloe Laisne <chloe.laisne@gmail.com>
parents:
202
diff
changeset
|
52 |
Ember.$("#chrono-table li").mousedown(function (event) { |
0ff47a9c5da2
Keyboard events on chronology
Chloe Laisne <chloe.laisne@gmail.com>
parents:
202
diff
changeset
|
53 |
// Prevent right click selection. |
0ff47a9c5da2
Keyboard events on chronology
Chloe Laisne <chloe.laisne@gmail.com>
parents:
202
diff
changeset
|
54 |
if(event.button === 0) { |
392
4fbe94af93e8
Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents:
234
diff
changeset
|
55 |
|
233
0ff47a9c5da2
Keyboard events on chronology
Chloe Laisne <chloe.laisne@gmail.com>
parents:
202
diff
changeset
|
56 |
isMouseDown = true; |
424
feb0d3e0fef9
add dynamic date range calculation for dates, and add color gradient component, add color gradient for language and chrono
ymh <ymh.work@gmail.com>
parents:
393
diff
changeset
|
57 |
var $elem = Ember.$(this); |
feb0d3e0fef9
add dynamic date range calculation for dates, and add color gradient component, add color gradient for language and chrono
ymh <ymh.work@gmail.com>
parents:
393
diff
changeset
|
58 |
var element = parseInt($elem.attr('id')); |
feb0d3e0fef9
add dynamic date range calculation for dates, and add color gradient component, add color gradient for language and chrono
ymh <ymh.work@gmail.com>
parents:
393
diff
changeset
|
59 |
var range = self.get('rangeArray'); |
feb0d3e0fef9
add dynamic date range calculation for dates, and add color gradient component, add color gradient for language and chrono
ymh <ymh.work@gmail.com>
parents:
393
diff
changeset
|
60 |
if(!$elem.hasClass('highlighted') && !_.inRange(element, range[0], range[1]+1)) { |
393 | 61 |
return false; |
62 |
} |
|
233
0ff47a9c5da2
Keyboard events on chronology
Chloe Laisne <chloe.laisne@gmail.com>
parents:
202
diff
changeset
|
63 |
var elements = [element]; |
0ff47a9c5da2
Keyboard events on chronology
Chloe Laisne <chloe.laisne@gmail.com>
parents:
202
diff
changeset
|
64 |
if(event.shiftKey) { |
0ff47a9c5da2
Keyboard events on chronology
Chloe Laisne <chloe.laisne@gmail.com>
parents:
202
diff
changeset
|
65 |
while(previousElement !== element) { |
0ff47a9c5da2
Keyboard events on chronology
Chloe Laisne <chloe.laisne@gmail.com>
parents:
202
diff
changeset
|
66 |
elements.push(previousElement); |
0ff47a9c5da2
Keyboard events on chronology
Chloe Laisne <chloe.laisne@gmail.com>
parents:
202
diff
changeset
|
67 |
if(previousElement < element) { |
0ff47a9c5da2
Keyboard events on chronology
Chloe Laisne <chloe.laisne@gmail.com>
parents:
202
diff
changeset
|
68 |
previousElement = previousElement + 1; |
0ff47a9c5da2
Keyboard events on chronology
Chloe Laisne <chloe.laisne@gmail.com>
parents:
202
diff
changeset
|
69 |
} else if(previousElement > element) { |
0ff47a9c5da2
Keyboard events on chronology
Chloe Laisne <chloe.laisne@gmail.com>
parents:
202
diff
changeset
|
70 |
previousElement = previousElement - 1; |
0ff47a9c5da2
Keyboard events on chronology
Chloe Laisne <chloe.laisne@gmail.com>
parents:
202
diff
changeset
|
71 |
} else { |
0ff47a9c5da2
Keyboard events on chronology
Chloe Laisne <chloe.laisne@gmail.com>
parents:
202
diff
changeset
|
72 |
break; |
0ff47a9c5da2
Keyboard events on chronology
Chloe Laisne <chloe.laisne@gmail.com>
parents:
202
diff
changeset
|
73 |
} |
392
4fbe94af93e8
Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents:
234
diff
changeset
|
74 |
} |
233
0ff47a9c5da2
Keyboard events on chronology
Chloe Laisne <chloe.laisne@gmail.com>
parents:
202
diff
changeset
|
75 |
} |
392
4fbe94af93e8
Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents:
234
diff
changeset
|
76 |
var dates = self.get('date'); |
233
0ff47a9c5da2
Keyboard events on chronology
Chloe Laisne <chloe.laisne@gmail.com>
parents:
202
diff
changeset
|
77 |
var index = dates.indexOf(element); |
0ff47a9c5da2
Keyboard events on chronology
Chloe Laisne <chloe.laisne@gmail.com>
parents:
202
diff
changeset
|
78 |
if((!event.shiftKey && index === -1) || (event.shiftKey && didHighlight)) { |
0ff47a9c5da2
Keyboard events on chronology
Chloe Laisne <chloe.laisne@gmail.com>
parents:
202
diff
changeset
|
79 |
dates = dates.concat(elements); |
0ff47a9c5da2
Keyboard events on chronology
Chloe Laisne <chloe.laisne@gmail.com>
parents:
202
diff
changeset
|
80 |
isHighlighted = true; |
0ff47a9c5da2
Keyboard events on chronology
Chloe Laisne <chloe.laisne@gmail.com>
parents:
202
diff
changeset
|
81 |
} else { |
0ff47a9c5da2
Keyboard events on chronology
Chloe Laisne <chloe.laisne@gmail.com>
parents:
202
diff
changeset
|
82 |
elements.forEach(function(el) { |
0ff47a9c5da2
Keyboard events on chronology
Chloe Laisne <chloe.laisne@gmail.com>
parents:
202
diff
changeset
|
83 |
var id = dates.indexOf(el); |
0ff47a9c5da2
Keyboard events on chronology
Chloe Laisne <chloe.laisne@gmail.com>
parents:
202
diff
changeset
|
84 |
if((!event.shiftKey && index !== -1) || (event.shiftKey && id !== -1)) { |
392
4fbe94af93e8
Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents:
234
diff
changeset
|
85 |
dates.splice(id, 1); |
233
0ff47a9c5da2
Keyboard events on chronology
Chloe Laisne <chloe.laisne@gmail.com>
parents:
202
diff
changeset
|
86 |
} |
0ff47a9c5da2
Keyboard events on chronology
Chloe Laisne <chloe.laisne@gmail.com>
parents:
202
diff
changeset
|
87 |
}); |
0ff47a9c5da2
Keyboard events on chronology
Chloe Laisne <chloe.laisne@gmail.com>
parents:
202
diff
changeset
|
88 |
isHighlighted = false; |
0ff47a9c5da2
Keyboard events on chronology
Chloe Laisne <chloe.laisne@gmail.com>
parents:
202
diff
changeset
|
89 |
} |
392
4fbe94af93e8
Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents:
234
diff
changeset
|
90 |
self.set('date', dates); |
233
0ff47a9c5da2
Keyboard events on chronology
Chloe Laisne <chloe.laisne@gmail.com>
parents:
202
diff
changeset
|
91 |
didHighlight = isHighlighted; |
0ff47a9c5da2
Keyboard events on chronology
Chloe Laisne <chloe.laisne@gmail.com>
parents:
202
diff
changeset
|
92 |
previousElement = element; |
0ff47a9c5da2
Keyboard events on chronology
Chloe Laisne <chloe.laisne@gmail.com>
parents:
202
diff
changeset
|
93 |
// Prevent text selection. |
0ff47a9c5da2
Keyboard events on chronology
Chloe Laisne <chloe.laisne@gmail.com>
parents:
202
diff
changeset
|
94 |
return false; |
197 | 95 |
} |
189
21b30ee23191
/langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents:
120
diff
changeset
|
96 |
}).mouseover(function () { |
21b30ee23191
/langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents:
120
diff
changeset
|
97 |
if (isMouseDown) { |
233
0ff47a9c5da2
Keyboard events on chronology
Chloe Laisne <chloe.laisne@gmail.com>
parents:
202
diff
changeset
|
98 |
var element = parseInt(Ember.$(this).attr('id')); |
197 | 99 |
if(Ember.$(this).hasClass("highlighted") !== isHighlighted) { |
392
4fbe94af93e8
Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents:
234
diff
changeset
|
100 |
var dates = self.get('date'); |
233
0ff47a9c5da2
Keyboard events on chronology
Chloe Laisne <chloe.laisne@gmail.com>
parents:
202
diff
changeset
|
101 |
var index = dates.indexOf(element); |
197 | 102 |
if(index === -1) { |
233
0ff47a9c5da2
Keyboard events on chronology
Chloe Laisne <chloe.laisne@gmail.com>
parents:
202
diff
changeset
|
103 |
dates.push(element); |
197 | 104 |
} else { |
105 |
dates.splice(index, 1); |
|
106 |
} |
|
392
4fbe94af93e8
Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents:
234
diff
changeset
|
107 |
self.set('date', dates); |
197 | 108 |
} |
233
0ff47a9c5da2
Keyboard events on chronology
Chloe Laisne <chloe.laisne@gmail.com>
parents:
202
diff
changeset
|
109 |
previousElement = element; |
189
21b30ee23191
/langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents:
120
diff
changeset
|
110 |
} |
21b30ee23191
/langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents:
120
diff
changeset
|
111 |
}).bind("selectstart", function () { |
21b30ee23191
/langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents:
120
diff
changeset
|
112 |
return false; |
21b30ee23191
/langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents:
120
diff
changeset
|
113 |
}); |
21b30ee23191
/langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents:
120
diff
changeset
|
114 |
|
21b30ee23191
/langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents:
120
diff
changeset
|
115 |
Ember.$(document).mouseup(function () { |
21b30ee23191
/langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents:
120
diff
changeset
|
116 |
isMouseDown = false; |
21b30ee23191
/langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents:
120
diff
changeset
|
117 |
}); |
21b30ee23191
/langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents:
120
diff
changeset
|
118 |
}, |
21b30ee23191
/langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents:
120
diff
changeset
|
119 |
|
234
c928f6190771
Select row in chronology
Chloe Laisne <chloe.laisne@gmail.com>
parents:
233
diff
changeset
|
120 |
actions : { |
c928f6190771
Select row in chronology
Chloe Laisne <chloe.laisne@gmail.com>
parents:
233
diff
changeset
|
121 |
|
c928f6190771
Select row in chronology
Chloe Laisne <chloe.laisne@gmail.com>
parents:
233
diff
changeset
|
122 |
selectDecade: function(decade) { |
c928f6190771
Select row in chronology
Chloe Laisne <chloe.laisne@gmail.com>
parents:
233
diff
changeset
|
123 |
var array = []; |
c928f6190771
Select row in chronology
Chloe Laisne <chloe.laisne@gmail.com>
parents:
233
diff
changeset
|
124 |
var next = decade + 10; |
392
4fbe94af93e8
Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents:
234
diff
changeset
|
125 |
var dates = this.get('date'); |
234
c928f6190771
Select row in chronology
Chloe Laisne <chloe.laisne@gmail.com>
parents:
233
diff
changeset
|
126 |
while(decade < next) { |
c928f6190771
Select row in chronology
Chloe Laisne <chloe.laisne@gmail.com>
parents:
233
diff
changeset
|
127 |
array.push(decade); |
c928f6190771
Select row in chronology
Chloe Laisne <chloe.laisne@gmail.com>
parents:
233
diff
changeset
|
128 |
decade ++; |
c928f6190771
Select row in chronology
Chloe Laisne <chloe.laisne@gmail.com>
parents:
233
diff
changeset
|
129 |
} |
c928f6190771
Select row in chronology
Chloe Laisne <chloe.laisne@gmail.com>
parents:
233
diff
changeset
|
130 |
if(array.find(function(date){ return dates.indexOf(date) === -1; })) { |
c928f6190771
Select row in chronology
Chloe Laisne <chloe.laisne@gmail.com>
parents:
233
diff
changeset
|
131 |
array = array.filter(function(value) { |
c928f6190771
Select row in chronology
Chloe Laisne <chloe.laisne@gmail.com>
parents:
233
diff
changeset
|
132 |
return dates.indexOf(value) === -1; |
c928f6190771
Select row in chronology
Chloe Laisne <chloe.laisne@gmail.com>
parents:
233
diff
changeset
|
133 |
}); |
c928f6190771
Select row in chronology
Chloe Laisne <chloe.laisne@gmail.com>
parents:
233
diff
changeset
|
134 |
array = dates.concat(array); |
c928f6190771
Select row in chronology
Chloe Laisne <chloe.laisne@gmail.com>
parents:
233
diff
changeset
|
135 |
} else { |
c928f6190771
Select row in chronology
Chloe Laisne <chloe.laisne@gmail.com>
parents:
233
diff
changeset
|
136 |
array = dates.filter(function(value) { |
c928f6190771
Select row in chronology
Chloe Laisne <chloe.laisne@gmail.com>
parents:
233
diff
changeset
|
137 |
return array.indexOf(value) === -1; |
c928f6190771
Select row in chronology
Chloe Laisne <chloe.laisne@gmail.com>
parents:
233
diff
changeset
|
138 |
}); |
c928f6190771
Select row in chronology
Chloe Laisne <chloe.laisne@gmail.com>
parents:
233
diff
changeset
|
139 |
} |
392
4fbe94af93e8
Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents:
234
diff
changeset
|
140 |
this.set('date', array); |
234
c928f6190771
Select row in chronology
Chloe Laisne <chloe.laisne@gmail.com>
parents:
233
diff
changeset
|
141 |
} |
c928f6190771
Select row in chronology
Chloe Laisne <chloe.laisne@gmail.com>
parents:
233
diff
changeset
|
142 |
|
77
0889740f79c2
on page load, hilight the objects corresponding to the query params
nowmad@23.1.168.192.in-addr.arpa
parents:
72
diff
changeset
|
143 |
} |
0889740f79c2
on page load, hilight the objects corresponding to the query params
nowmad@23.1.168.192.in-addr.arpa
parents:
72
diff
changeset
|
144 |
|
48
9ef0952033e0
add example of visualisation for "chonologie"
nowmad@nowmads-macbook-pro.local
parents:
diff
changeset
|
145 |
}); |