Skip to content

Commit

Permalink
Merge branch 'gh-pages'
Browse files Browse the repository at this point in the history
  • Loading branch information
simonbrent committed Jan 10, 2017
2 parents b5aba09 + be09345 commit b46d566
Show file tree
Hide file tree
Showing 7 changed files with 397 additions and 131 deletions.
3 changes: 1 addition & 2 deletions css/trackControls.css
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

.gv-track-controls-plugin .gv-track-container div.gv-track-controls > * {
display: inline-block;
width: 20px;
min-width: 20px;
text-align: center;
}

Expand Down Expand Up @@ -57,6 +57,5 @@
}

.gv-track-controls-plugin .gv-track-container div.gv-track-controls select {
width: auto;
margin: 0 5px;
}
17 changes: 14 additions & 3 deletions js/Genoverse.js
Original file line number Diff line number Diff line change
Expand Up @@ -1415,7 +1415,7 @@ var Genoverse = Base.extend({
functionWrap: function (key, obj) {
obj.functions = obj.functions || {};

if (obj.functions[key] || key.match(/^(before|after)/)) {
if (obj.functions[key] || /^(before|after)/.test(key)) {
return;
}

Expand All @@ -1438,7 +1438,8 @@ var Genoverse = Base.extend({
obj.functions[key] = obj[key];

obj[key] = function () {
var args = [].slice.call(arguments);
var args = [].slice.call(arguments);
var currentConfig = (this._currentConfig || (this.track ? this.track._currentConfig : {}) || {}).func;
var rtn;

// Debugging functionality
Expand All @@ -1463,7 +1464,17 @@ var Genoverse = Base.extend({
}

trigger.call(this, 'before');
rtn = this.functions[key].apply(this, args);

if (currentConfig && currentConfig[key]) {
// override to add a value for this.base
rtn = function () {
this.base = this.functions[key] || function () {};
return currentConfig[key].apply(this, arguments);
}.apply(this, args);
} else {
rtn = this.functions[key].apply(this, args);
}

trigger.call(this, 'after');

if (mainObj.debug === 'time' || (typeof mainObj.debug === 'object' && mainObj.debug[key])) {
Expand Down
144 changes: 106 additions & 38 deletions js/Track.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ Genoverse.Track = Base.extend({
this.config[i] = this.defaultConfig[i];
}
}

this._setCurrentConfig();
},

setInterface: function () {
Expand Down Expand Up @@ -82,6 +84,7 @@ Genoverse.Track = Base.extend({
var settings = $.extend(true, {}, this.constructor.prototype, this.getSettingsForLength()[1]); // model, view, options
var controllerSettings = { prop: {}, func: {} };
var trackSettings = {};
var i;

settings.controller = settings.controller || this.controller || Genoverse.Track.Controller;

Expand All @@ -107,6 +110,32 @@ Genoverse.Track = Base.extend({
}
}

// If there are configSettings for the track, ensure that any properties in _currentConfig are set for the model/view/controller/track as appropriate.
// Functions in _currentConfig are accessed via Genoverse.functionWrap, so nothing needs to be done with them here.
if (!$.isEmptyObject(this._currentConfig)) {
var changed = {};
var type;

for (i in this._currentConfig.prop) {
type = this._interface[i];

if (/model|view/.test(type)) {
if (trackSettings[type][i] !== this._currentConfig.prop[i]) {
trackSettings[type][i] = this._currentConfig.prop[i];
changed[type] = true;
}
} else if (type === 'controller') {
controllerSettings.prop[i] = this._currentConfig.prop[i];
} else {
trackSettings[i] = this._currentConfig.prop[i];
}
}

for (type in changed) {
trackSettings[type].setDefaults(true);
}
}

/*
* Abandon all hope! If you've tracked a bug to this line of code, be afraid.
* It will almost certainly be due to the wonderful way the javascript objects work.
Expand Down Expand Up @@ -138,7 +167,8 @@ Genoverse.Track = Base.extend({
if (!this.controller || typeof this.controller === 'function') {
this.controller = this.newMVC(settings.controller, controllerSettings.func, $.extend(controllerSettings.prop, { model: this.model, view: this.view }));
} else {
$.extend(this.controller, { model: this.model, view: this.view, threshold: controllerSettings.prop.threshold || this.controller.constructor.prototype.threshold });
controllerSettings.prop.threshold = controllerSettings.prop.threshold || this.controller.constructor.prototype.threshold;
$.extend(this.controller, controllerSettings.prop, { model: this.model, view: this.view });
}

if (this.strand === -1 && this.orderReverse) {
Expand All @@ -161,18 +191,20 @@ Genoverse.Track = Base.extend({
},

setLengthMap: function () {
var mv = [ 'model', 'view' ];
var featureFilters = [];
var configSettings = [];
var lengthMap = [];
var models = {};
var views = {};
var mv = [ 'model', 'view' ];
var lengthMap = [];
var models = {};
var views = {};
var settings, value, deepCopy, prevLengthMap, mvSettings, type, prevType, i, j;

function compare(a, b) {
var checked = {};
var checked = { browser: true, width: true, track: true }; // Properties set in newMVC should be ignored, as they will be missing if comparing an object with a prototype

for (var key in a) {
if (checked[key]) {
continue;
}

checked[key] = true;

if (typeof a[key] !== typeof b[key]) {
Expand All @@ -181,7 +213,7 @@ Genoverse.Track = Base.extend({
if (a[key].toString() !== b[key].toString()) {
return false;
}
} else if (typeof a[key] === 'object' && !compare(a[key], b[key])) {
} else if (typeof a[key] === 'object' && !(a[key] instanceof $) && !compare(a[key], b[key])) {
return false;
} else if (a[key] !== b[key]) {
return false;
Expand All @@ -197,23 +229,6 @@ Genoverse.Track = Base.extend({
return true;
}

// Find configuration settings, force them into each lengthMap setting
for (i in this.configSettings) {
settings = this.getConfig(i);

if (settings) {
configSettings.push(settings);

if (settings.featureFilter) {
featureFilters.push(settings.featureFilter);
}
}
}

if (configSettings.length) {
configSettings = $.extend.apply($, [ true, {} ].concat(configSettings, { featureFilters: featureFilters }));
}

// Find all scale-map like keys
for (var key in this) {
if (!isNaN(key)) {
Expand All @@ -230,8 +245,6 @@ Genoverse.Track = Base.extend({
lengthMap = lengthMap.sort(function (a, b) { return b[0] - a[0]; });

for (i = 0; i < lengthMap.length; i++) {
$.extend(lengthMap[i][1], configSettings); // Add configSettings to the lengthMap entries

if (lengthMap[i][1].model && lengthMap[i][1].view) {
continue;
}
Expand Down Expand Up @@ -297,7 +310,7 @@ Genoverse.Track = Base.extend({
// If the track already has this.models/this.views and the prototype of the new model/view is the same as the value of this.models/this.views for the same length key, reuse that value.
// This can happen if the track has configSettings and the user changes config but that only affects one of the model and view.
// Again, reusing the old value stops the need to fetch identical data or draw identical images more than once.
if (prevType[lengthMap[i][0]] && compare(prevType[lengthMap[i][0]].constructor.prototype, settings[type].constructor.prototype)) {
if (prevType[lengthMap[i][0]] && compare(prevType[lengthMap[i][0]].constructor.prototype, $.extend({}, settings[type].constructor.prototype, mvSettings[type].prop))) {
settings[type] = prevType[lengthMap[i][0]];
}
}
Expand Down Expand Up @@ -379,19 +392,68 @@ Genoverse.Track = Base.extend({
}
},

setConfig: function (type, config) {
if (this.configSettings[type][config]) {
this.config[type] = config;
setConfig: function (config) {
if (typeof config === 'string' && arguments.length === 2) {
var _config = {};
_config[config] = arguments[1];
config = _config;
}

var configChanged = false;
var conf;

for (var type in config) {
conf = config[type];

if (typeof this.configSettings[type] === 'undefined' || typeof this.configSettings[type][conf] === 'undefined' || this.config[type] === conf) {
continue;
}

this.config[type] = conf;

configChanged = true;
}

if (configChanged) {
var features = this.prop('featuresById');

for (var i in features) {
delete features[i].menuEl;
}

this._setCurrentConfig();
this.reset();
this.browser.saveConfig();
}
},

this.reset();
this.browser.saveConfig();
_setCurrentConfig: function () {
var settings = [];
var featureFilters = [];
var conf;

this._currentConfig = { prop: {}, func: {} };

for (i in this.configSettings) {
conf = this.getConfig(i);

if (conf) {
settings.push(conf);

if (conf.featureFilter) {
featureFilters.push(conf.featureFilter);
}
}
}

if (settings.length) {
settings = $.extend.apply($, [ true, {} ].concat(settings, { featureFilters: featureFilters }));
delete settings.featureFilter;
}

for (i in settings) {
this._currentConfig[typeof settings[i] === 'function' && !/^(before|after)/.test(i) ? 'func' : 'prop'][i] = settings[i];
}
},

getConfig: function (type) {
Expand Down Expand Up @@ -427,12 +489,18 @@ Genoverse.Track = Base.extend({
},

reset: function () {
if (this.prop('url') !== false) {
this.model.init(true);
this.setLengthMap();

for (var i in this.models) {
if (this.models[i].url !== false) {
this.models[i].init(true);
}
}

for (i in this.views) {
this.views[i].init();
}

this.view.init();
this.setLengthMap();
this.controller.reset.apply(this.controller, arguments);
},

Expand Down
6 changes: 4 additions & 2 deletions js/Track/Model.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ Genoverse.Track.Model = Base.extend({
init: function (reset) {
this.setDefaults(reset);

if (reset && !this.data) {
if (reset) {
for (var i in this.featuresById) {
delete this.featuresById[i].position;
}
} else {
}

if (!reset || this.data) {
this.dataRanges = new RTree();
this.features = new RTree();
this.featuresById = {};
Expand Down
8 changes: 8 additions & 0 deletions js/Track/library/Legend.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,14 @@ Genoverse.Track.Legend = Genoverse.Track.Static.extend({
if (legend) {
legend.controller.makeImage({});
}
},

afterSetMVC: function () {
var legend = this.prop('legendTrack');

if (legend) {
legend[this.legend ? 'enable' : 'disable']();
}
}
}, this);
},
Expand Down
Loading

0 comments on commit b46d566

Please sign in to comment.