Browse Source

Changed the way the interval is calculated and displayed by default

This should fix some problems with funky date combos and also provide a
better default view
pull/23/merge
Zach Wise 13 years ago
parent
commit
023e55a453
  1. 4
      locale/de.js
  2. 4
      locale/en.js
  3. 4
      locale/es.js
  4. 4
      locale/fr.js
  5. 4
      locale/is.js
  6. 4
      locale/it.js
  7. 4
      locale/kr.js
  8. 4
      locale/nl.js
  9. 4
      locale/pt-br.js
  10. 4
      locale/zh-ch.js
  11. 4
      locale/zh-tw.js
  12. 170
      source/js/VMM.Timeline.TimeNav.js
  13. 13
      source/js/VMM.Util.js
  14. 4
      timeline-min.js
  15. 183
      timeline.js

4
locale/de.js

File diff suppressed because one or more lines are too long

4
locale/en.js

File diff suppressed because one or more lines are too long

4
locale/es.js

File diff suppressed because one or more lines are too long

4
locale/fr.js

File diff suppressed because one or more lines are too long

4
locale/is.js

File diff suppressed because one or more lines are too long

4
locale/it.js

File diff suppressed because one or more lines are too long

4
locale/kr.js

File diff suppressed because one or more lines are too long

4
locale/nl.js

File diff suppressed because one or more lines are too long

4
locale/pt-br.js

File diff suppressed because one or more lines are too long

4
locale/zh-ch.js

File diff suppressed because one or more lines are too long

4
locale/zh-tw.js

File diff suppressed because one or more lines are too long

170
source/js/VMM.Timeline.TimeNav.js

@ -67,6 +67,14 @@ if(typeof VMM.Timeline != 'undefined' && typeof VMM.Timeline.TimeNav == 'undefin
multiplier: 100
};
var interval_macro = {
type: "year",
number: 10,
first: 1970,
last: 2011,
multiplier: 100
};
var interval_calc = {
day: {} ,
month: {},
@ -89,13 +97,13 @@ if(typeof VMM.Timeline != 'undefined' && typeof VMM.Timeline.TimeNav == 'undefin
config.timeline = false;
config.marker_width = 150;
config.marker_height = 48;
config.density = 2;
config.density = 1;
config.timeline_width = 900;
config.interval_width = 200;
config.rows = [1, 1, 1];
config.multiplier = 6;
config.max_multiplier = 16;
config.min_multiplier = 1;
config.min_multiplier = .1;
config.has_start_page = false;
config.rows = [config.marker_height, config.marker_height*2, 1];
@ -206,21 +214,21 @@ if(typeof VMM.Timeline != 'undefined' && typeof VMM.Timeline.TimeNav == 'undefin
}
function onZoomIn() {
trace("CLICK");
VMM.DragSlider.cancelSlide();
if (config.multiplier > config.min_multiplier) {
if (config.multiplier <= 1) {
config.multiplier = config.multiplier - .25;
} else {
config.multiplier = config.multiplier - 1;
if (config.multiplier < 0) {
}
if (config.multiplier <= 0) {
config.multiplier = config.min_multiplier;
}
refreshTimeline();
}
}
function onZoomOut() {
trace("CLICK");
VMM.DragSlider.cancelSlide();
if (config.multiplier < config.max_multiplier) {
config.multiplier = config.multiplier + 1;
@ -363,7 +371,8 @@ if(typeof VMM.Timeline != 'undefined' && typeof VMM.Timeline.TimeNav == 'undefin
era_markers.push(era);
}
positionMarkers();
}
@ -417,6 +426,66 @@ if(typeof VMM.Timeline != 'undefined' && typeof VMM.Timeline.TimeNav == 'undefin
}
var averageMarkerPositionDistance = function() {
var last_pos = 0;
var pos = 0;
var pos_dif = 0;
var mp_diff = [];
for(var i = 0; i < markers.length; i++) {
if (data[i].type == "start") {
} else {
var _pos = positionOnTimeline(interval, data[i].startdate, data[i].enddate);
last_pos = pos;
pos = _pos.begin;
pos_dif = pos - last_pos;
mp_diff.push(pos_dif);
}
}
return VMM.Util.average(mp_diff).mean;
}
var averageDateDistance = function() {
var last_dd = 0;
var dd = 0;
var date_dif = 0;
var date_diffs = [];
var is_first_date = true;
for(var i = 0; i < data.length; i++) {
if (data[i].type == "start") {
trace("DATA DATE IS START")
} else {
var _dd = data[i].startdate;
last_dd = dd;
dd = _dd;
date_dif = dd - last_dd;
date_diffs.push(date_dif);
}
}
return VMM.Util.average(date_diffs);
}
var calculateMultiplier = function() {
var temp_multiplier = config.multiplier;
for(var i = 0; i < temp_multiplier; i++) {
if (averageMarkerPositionDistance() < 75) {
if (config.multiplier > 1) {
config.multiplier = config.multiplier - 1;
}
}
}
}
var positionMarkers = function(is_animated) {
var _type = interval.type;
@ -694,7 +763,7 @@ if(typeof VMM.Timeline != 'undefined' && typeof VMM.Timeline.TimeNav == 'undefin
interval.date = new Date(data[0].startdate.getFullYear(), 0, 1, 0,0,0);
interval_major.date = new Date(data[0].startdate.getFullYear(), 0, 1, 0,0,0);
interval_macro.date = new Date(data[0].startdate.getFullYear(), 0, 1, 0,0,0);
//interval.date_major_start = new Date(data[0].startdate.getFullYear(), 0, 1, 0,0,0);
//interval.date_major_end = new Date(data[0].startdate.getFullYear(), 0, 1, 0,0,0);
@ -948,7 +1017,7 @@ if(typeof VMM.Timeline != 'undefined' && typeof VMM.Timeline.TimeNav == 'undefin
}
VMM.Element.css($timeintervalminor_minor, "left", _major_first_pos - _minor_pos_offset);
//VMM.Element.css($timeintervalminor_minor, "left", _major_first_pos - _minor_pos_offset);
config.timeline_width = VMM.Element.width($timeinterval);
@ -960,6 +1029,8 @@ if(typeof VMM.Timeline != 'undefined' && typeof VMM.Timeline.TimeNav == 'undefin
/* CALCULATE INTERVAL
================================================== */
timespan = getDateFractions((data[data.length - 1].enddate) - (data[0].startdate), true);
//timespan = getDateFractions( averageDateDistance().mean );
trace(timespan);
calculateInterval();
/* DETERMINE DEFAULT INTERVAL TYPE
@ -967,73 +1038,53 @@ if(typeof VMM.Timeline != 'undefined' && typeof VMM.Timeline.TimeNav == 'undefin
if (timespan.milleniums > data.length / config.density) {
interval = interval_calc.millenium;
//interval_major = interval_calc.millenium;
interval_major = interval_calc.millenium;
interval_macro = interval_calc.millenium;
} else if (timespan.centuries > data.length / config.density) {
interval = Math.ceil(interval_calc.century);
//interval_major = interval_calc.millenium;
interval_major = interval_calc.millenium;
interval_macro = interval_calc.decade;
} else if (timespan.decades > data.length / config.density) {
interval = interval_calc.decade;
//interval_major = Math.ceil(interval_calc.century);
interval_major = Math.ceil(interval_calc.century);
interval_macro = interval_calc.year;
} else if (timespan.years > data.length / config.density) {
interval = interval_calc.year;
//interval_major = interval_calc.decade;
interval_major = interval_calc.decade;
interval_macro = interval_calc.month;
} else if (timespan.months > data.length / config.density) {
interval = interval_calc.month;
//interval_major = interval_calc.year;
//} else if (timespan.weeks > data.length / config.density) {
//interval = interval_calc.week;
//interval = interval_calc.month;
//interval_major = interval_calc.month;
interval_major = interval_calc.year;
interval_macro = interval_calc.day;
} else if (timespan.days > data.length / config.density) {
interval = interval_calc.day;
//interval_major = interval_calc.month;
interval_major = interval_calc.month;
interval_macro = interval_calc.hour;
} else if (timespan.hours > data.length / config.density) {
interval = interval_calc.hour;
//interval_major = interval_calc.day;
interval_major = interval_calc.day;
interval_macro = interval_calc.minute;
} else if (timespan.minutes > data.length / config.density) {
interval = interval_calc.minute;
//interval_major = interval_calc.hour;
interval_major = interval_calc.hour;
interval_macro = interval_calc.second;
} else if (timespan.seconds > data.length / config.density) {
interval = interval_calc.second;
//interval_major = interval_calc.minute;
} else {
trace("NO IDEA WHAT THE TYPE SHOULD BE");
interval.type = "unknown";
}
/* DETERMINE MAJOR TYPE
================================================== */
if (timespan.milleniums >= 1) {
interval_major = interval_calc.millenium;
} else if (timespan.centuries >= 1) {
interval_major = interval_calc.century;
} else if (timespan.decades >= 1) {
interval_major = interval_calc.decade;
} else if (timespan.years >= 1) {
interval_major = interval_calc.year;
} else if (timespan.months > 1) {
interval_major = interval_calc.month;
} else if (timespan.weeks > 1) {
interval_major = interval_calc.month;
} else if (timespan.days > 1) {
interval_major = interval_calc.day;
} else if (timespan.hours > 1) {
interval_major = interval_calc.hour;
} else if (timespan.minutes > 1) {
interval_major = interval_calc.minute;
} else if (timespan.seconds > 1) {
interval_major = interval_calc.minute;
interval_macro = interval_calc.second;
} else {
trace("NO IDEA WHAT THE TYPE SHOULD BE");
interval_major.type = "unknown";
//interval.type = "unknown";
//interval_major.type = "unknown";
interval = interval_calc.day;
interval_major = interval_calc.month;
interval_macro = interval_calc.hour;
}
//trace(interval_major.type);
trace(interval.type)
trace(interval_major.type)
trace()
$timeintervalminor_minor = VMM.appendAndGetElement($timeintervalminor, "<div>", "minor");
positionInterval();
}
@ -1118,6 +1169,12 @@ if(typeof VMM.Timeline != 'undefined' && typeof VMM.Timeline.TimeNav == 'undefin
buildInterval();
buildMarkers();
calculateMultiplier();
positionMarkers();
positionInterval();
reSize(true);
VMM.fireEvent(layout, "LOADED");
@ -1167,8 +1224,9 @@ if(typeof VMM.Timeline != 'undefined' && typeof VMM.Timeline.TimeNav == 'undefin
};
var refreshTimeline = function() {
positionInterval();
positionMarkers(true);
positionInterval();
//positionMarkers(true);
//reSize();
};

13
source/js/VMM.Util.js

@ -14,6 +14,19 @@ if(typeof VMM != 'undefined' && typeof VMM.Util == 'undefined') {
randomBetween: function(min, max) {
return Math.floor(Math.random() * (max - min + 1) + min);
},
/* AVERAGE
http://jsfromhell.com/array/average
var x = VMM.Util.average([2, 3, 4]);
VMM.Util.average([2, 3, 4]).mean
================================================== */
average: function(a) {
var r = {mean: 0, variance: 0, deviation: 0}, t = a.length;
for(var m, s = 0, l = t; l--; s += a[l]);
for(m = r.mean = s / t, l = t, s = 0; l--; s += Math.pow(a[l] - m, 2));
return r.deviation = Math.sqrt(r.variance = s / t), r;
},
/* CUSTOM SORT
================================================== */

4
timeline-min.js vendored

File diff suppressed because one or more lines are too long

183
timeline.js

@ -3023,6 +3023,19 @@ if(typeof VMM != 'undefined' && typeof VMM.Util == 'undefined') {
randomBetween: function(min, max) {
return Math.floor(Math.random() * (max - min + 1) + min);
},
/* AVERAGE
http://jsfromhell.com/array/average
var x = VMM.Util.average([2, 3, 4]);
VMM.Util.average([2, 3, 4]).mean
================================================== */
average: function(a) {
var r = {mean: 0, variance: 0, deviation: 0}, t = a.length;
for(var m, s = 0, l = t; l--; s += a[l]);
for(m = r.mean = s / t, l = t, s = 0; l--; s += Math.pow(a[l] - m, 2));
return r.deviation = Math.sqrt(r.variance = s / t), r;
},
/* CUSTOM SORT
================================================== */
@ -5380,6 +5393,14 @@ if(typeof VMM.Timeline != 'undefined' && typeof VMM.Timeline.TimeNav == 'undefin
multiplier: 100
};
var interval_macro = {
type: "year",
number: 10,
first: 1970,
last: 2011,
multiplier: 100
};
var interval_calc = {
day: {} ,
month: {},
@ -5402,13 +5423,13 @@ if(typeof VMM.Timeline != 'undefined' && typeof VMM.Timeline.TimeNav == 'undefin
config.timeline = false;
config.marker_width = 150;
config.marker_height = 48;
config.density = 2;
config.density = 1;
config.timeline_width = 900;
config.interval_width = 200;
config.rows = [1, 1, 1];
config.multiplier = 6;
config.max_multiplier = 16;
config.min_multiplier = 1;
config.min_multiplier = .1;
config.has_start_page = false;
config.rows = [config.marker_height, config.marker_height*2, 1];
@ -5519,21 +5540,21 @@ if(typeof VMM.Timeline != 'undefined' && typeof VMM.Timeline.TimeNav == 'undefin
}
function onZoomIn() {
trace("CLICK");
VMM.DragSlider.cancelSlide();
if (config.multiplier > config.min_multiplier) {
if (config.multiplier <= 1) {
config.multiplier = config.multiplier - .25;
} else {
config.multiplier = config.multiplier - 1;
if (config.multiplier < 0) {
}
if (config.multiplier <= 0) {
config.multiplier = config.min_multiplier;
}
refreshTimeline();
}
}
function onZoomOut() {
trace("CLICK");
VMM.DragSlider.cancelSlide();
if (config.multiplier < config.max_multiplier) {
config.multiplier = config.multiplier + 1;
@ -5676,7 +5697,8 @@ if(typeof VMM.Timeline != 'undefined' && typeof VMM.Timeline.TimeNav == 'undefin
era_markers.push(era);
}
positionMarkers();
}
@ -5730,6 +5752,66 @@ if(typeof VMM.Timeline != 'undefined' && typeof VMM.Timeline.TimeNav == 'undefin
}
var averageMarkerPositionDistance = function() {
var last_pos = 0;
var pos = 0;
var pos_dif = 0;
var mp_diff = [];
for(var i = 0; i < markers.length; i++) {
if (data[i].type == "start") {
} else {
var _pos = positionOnTimeline(interval, data[i].startdate, data[i].enddate);
last_pos = pos;
pos = _pos.begin;
pos_dif = pos - last_pos;
mp_diff.push(pos_dif);
}
}
return VMM.Util.average(mp_diff).mean;
}
var averageDateDistance = function() {
var last_dd = 0;
var dd = 0;
var date_dif = 0;
var date_diffs = [];
var is_first_date = true;
for(var i = 0; i < data.length; i++) {
if (data[i].type == "start") {
trace("DATA DATE IS START")
} else {
var _dd = data[i].startdate;
last_dd = dd;
dd = _dd;
date_dif = dd - last_dd;
date_diffs.push(date_dif);
}
}
return VMM.Util.average(date_diffs);
}
var calculateMultiplier = function() {
var temp_multiplier = config.multiplier;
for(var i = 0; i < temp_multiplier; i++) {
if (averageMarkerPositionDistance() < 75) {
if (config.multiplier > 1) {
config.multiplier = config.multiplier - 1;
}
}
}
}
var positionMarkers = function(is_animated) {
var _type = interval.type;
@ -6007,7 +6089,7 @@ if(typeof VMM.Timeline != 'undefined' && typeof VMM.Timeline.TimeNav == 'undefin
interval.date = new Date(data[0].startdate.getFullYear(), 0, 1, 0,0,0);
interval_major.date = new Date(data[0].startdate.getFullYear(), 0, 1, 0,0,0);
interval_macro.date = new Date(data[0].startdate.getFullYear(), 0, 1, 0,0,0);
//interval.date_major_start = new Date(data[0].startdate.getFullYear(), 0, 1, 0,0,0);
//interval.date_major_end = new Date(data[0].startdate.getFullYear(), 0, 1, 0,0,0);
@ -6261,7 +6343,7 @@ if(typeof VMM.Timeline != 'undefined' && typeof VMM.Timeline.TimeNav == 'undefin
}
VMM.Element.css($timeintervalminor_minor, "left", _major_first_pos - _minor_pos_offset);
//VMM.Element.css($timeintervalminor_minor, "left", _major_first_pos - _minor_pos_offset);
config.timeline_width = VMM.Element.width($timeinterval);
@ -6273,6 +6355,8 @@ if(typeof VMM.Timeline != 'undefined' && typeof VMM.Timeline.TimeNav == 'undefin
/* CALCULATE INTERVAL
================================================== */
timespan = getDateFractions((data[data.length - 1].enddate) - (data[0].startdate), true);
//timespan = getDateFractions( averageDateDistance().mean );
trace(timespan);
calculateInterval();
/* DETERMINE DEFAULT INTERVAL TYPE
@ -6280,73 +6364,53 @@ if(typeof VMM.Timeline != 'undefined' && typeof VMM.Timeline.TimeNav == 'undefin
if (timespan.milleniums > data.length / config.density) {
interval = interval_calc.millenium;
//interval_major = interval_calc.millenium;
interval_major = interval_calc.millenium;
interval_macro = interval_calc.millenium;
} else if (timespan.centuries > data.length / config.density) {
interval = Math.ceil(interval_calc.century);
//interval_major = interval_calc.millenium;
interval_major = interval_calc.millenium;
interval_macro = interval_calc.decade;
} else if (timespan.decades > data.length / config.density) {
interval = interval_calc.decade;
//interval_major = Math.ceil(interval_calc.century);
interval_major = Math.ceil(interval_calc.century);
interval_macro = interval_calc.year;
} else if (timespan.years > data.length / config.density) {
interval = interval_calc.year;
//interval_major = interval_calc.decade;
interval_major = interval_calc.decade;
interval_macro = interval_calc.month;
} else if (timespan.months > data.length / config.density) {
interval = interval_calc.month;
//interval_major = interval_calc.year;
//} else if (timespan.weeks > data.length / config.density) {
//interval = interval_calc.week;
//interval = interval_calc.month;
//interval_major = interval_calc.month;
interval_major = interval_calc.year;
interval_macro = interval_calc.day;
} else if (timespan.days > data.length / config.density) {
interval = interval_calc.day;
//interval_major = interval_calc.month;
interval_major = interval_calc.month;
interval_macro = interval_calc.hour;
} else if (timespan.hours > data.length / config.density) {
interval = interval_calc.hour;
//interval_major = interval_calc.day;
interval_major = interval_calc.day;
interval_macro = interval_calc.minute;
} else if (timespan.minutes > data.length / config.density) {
interval = interval_calc.minute;
//interval_major = interval_calc.hour;
interval_major = interval_calc.hour;
interval_macro = interval_calc.second;
} else if (timespan.seconds > data.length / config.density) {
interval = interval_calc.second;
//interval_major = interval_calc.minute;
} else {
trace("NO IDEA WHAT THE TYPE SHOULD BE");
interval.type = "unknown";
}
/* DETERMINE MAJOR TYPE
================================================== */
if (timespan.milleniums >= 1) {
interval_major = interval_calc.millenium;
} else if (timespan.centuries >= 1) {
interval_major = interval_calc.century;
} else if (timespan.decades >= 1) {
interval_major = interval_calc.decade;
} else if (timespan.years >= 1) {
interval_major = interval_calc.year;
} else if (timespan.months > 1) {
interval_major = interval_calc.month;
} else if (timespan.weeks > 1) {
interval_major = interval_calc.month;
} else if (timespan.days > 1) {
interval_major = interval_calc.day;
} else if (timespan.hours > 1) {
interval_major = interval_calc.hour;
} else if (timespan.minutes > 1) {
interval_major = interval_calc.minute;
} else if (timespan.seconds > 1) {
interval_major = interval_calc.minute;
interval_macro = interval_calc.second;
} else {
trace("NO IDEA WHAT THE TYPE SHOULD BE");
interval_major.type = "unknown";
//interval.type = "unknown";
//interval_major.type = "unknown";
interval = interval_calc.day;
interval_major = interval_calc.month;
interval_macro = interval_calc.hour;
}
//trace(interval_major.type);
trace(interval.type)
trace(interval_major.type)
trace()
$timeintervalminor_minor = VMM.appendAndGetElement($timeintervalminor, "<div>", "minor");
positionInterval();
}
@ -6431,6 +6495,12 @@ if(typeof VMM.Timeline != 'undefined' && typeof VMM.Timeline.TimeNav == 'undefin
buildInterval();
buildMarkers();
calculateMultiplier();
positionMarkers();
positionInterval();
reSize(true);
VMM.fireEvent(layout, "LOADED");
@ -6480,8 +6550,9 @@ if(typeof VMM.Timeline != 'undefined' && typeof VMM.Timeline.TimeNav == 'undefin
};
var refreshTimeline = function() {
positionInterval();
positionMarkers(true);
positionInterval();
//positionMarkers(true);
//reSize();
};

Loading…
Cancel
Save