forked from LukeWoodward/SplitsBrowser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsplitsbrowser.min.js
26 lines (25 loc) · 131 KB
/
splitsbrowser.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
/*!
* SplitsBrowser - Orienteering results analysis.
*
* Copyright (C) 2000-2018 Dave Ryder, Reinhard Balling, Andris Strazdins,
* Ed Nash, Luke Woodward
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
var SplitsBrowser={Version:"3.4.4",Model:{},Input:{},Controls:{},Messages:{}};!function(){"use strict";var e=!1,s=function(t){window.alert(t)},n=null,i=null,r=SplitsBrowser.Messages;function o(t){e||(s(t),e=!0)}SplitsBrowser.setMessageAlerter=function(t){s=t},SplitsBrowser.tryGetMessage=function(t,e){return null!==n&&r[n].hasOwnProperty(t)?SplitsBrowser.getMessage(t):e},SplitsBrowser.getMessage=function(t){return null===i&&SplitsBrowser.initialiseMessages(),null!==n?r[n].hasOwnProperty(t)?r[n][t]:(o("Message not found for key '"+t+"' in language '"+n+"'"),"?????"):(o("No messages found. Has a language file been loaded?"),"?????")},SplitsBrowser.getMessageWithFormatting=function(t,e){var s=SplitsBrowser.getMessage(t);for(var n in e)if(e.hasOwnProperty(n)){var i=n.replace(/([.+*?|{}()^$\[\]\\])/g,"\\$1");s=s.replace(new RegExp(i,"g"),e[n])}return s},SplitsBrowser.getAllLanguages=function(){return i.slice(0)},SplitsBrowser.getLanguage=function(){return n},SplitsBrowser.getLanguageName=function(t){return r.hasOwnProperty(t)&&r[t].hasOwnProperty("Language")?r[t].Language:"?????"},SplitsBrowser.setLanguage=function(t){r.hasOwnProperty(t)&&(n=t)},SplitsBrowser.initialiseMessages=function(t){for(var e in i=[],r!==SplitsBrowser.Messages&&o("You appear to have loaded a messages file in the old format. This file, and all others loaded after it, will not work.\n\nPlease check the messages files."),r)r.hasOwnProperty(e)&&i.push(e);0===i.length?o("No messages files were found."):n=t&&r.hasOwnProperty(t)?t:i[0]}}(),function(){"use strict";function e(t){this.name="InvalidData",this.message=t}function s(t){this.name="WrongFileFormat",this.message=t}SplitsBrowser.isTrue=function(t){return t},SplitsBrowser.isNotNull=function(t){return null!==t},SplitsBrowser.isNaNStrict=function(t){return t!=t},SplitsBrowser.isNotNullNorNaN=function(t){return null!==t&&t==t},e.prototype.toString=function(){return this.name+": "+this.message},SplitsBrowser.throwInvalidData=function(t){throw new e(t)},s.prototype.toString=function(){return this.name+": "+this.message},SplitsBrowser.throwWrongFileFormat=function(t){throw new s(t)},SplitsBrowser.parseCourseLength=function(t){var e=parseFloat(t.replace(",","."));return isFinite(e)?(500<=e&&(e/=1e3),e):null},SplitsBrowser.parseCourseClimb=function(t){var e=parseInt(t,10);return SplitsBrowser.isNaNStrict(e)?null:e},SplitsBrowser.normaliseLineEndings=function(t){return t.replace(/\r\n/g,"\n").replace(/\r/g,"\n")}}(),function(){"use strict";SplitsBrowser.NULL_TIME_PLACEHOLDER="-----";var o=SplitsBrowser.isNaNStrict;SplitsBrowser.formatTime=function(t,e){if(null===t)return SplitsBrowser.NULL_TIME_PLACEHOLDER;if(o(t))return"???";var s="";t<0&&(s="-",t=-t);var n=Math.floor(t/3600),i=Math.floor(t/60)%60,r=t%60;return 0<n&&(s+=n.toString()+":"),i<10&&(s+="0"),s+=i+":",r<10&&(s+="0"),s+="number"==typeof e?r.toFixed(e):Math.round(100*r)/100},SplitsBrowser.parseTime=function(t){if(t=t.trim(),/^(\d+:)?\d+:\d\d([,.]\d+)?$/.test(t)){var e=t.replace(",",".").split(":"),s=0;return e.forEach(function(t){s=60*s+parseFloat(t)}),s}return null}}(),function(){"use strict";var t=SplitsBrowser.isNotNull,i=SplitsBrowser.isNaNStrict,o=SplitsBrowser.throwInvalidData;function n(t,e){return null===t||null===e?null:t-e}function r(t){if(!$.isArray(t))throw new TypeError("Cumulative times must be an array - got "+typeof t+" instead");0===t.length?o("Array of cumulative times must not be empty"):0!==t[0]?o("Array of cumulative times must have zero as its first item"):1===t.length&&o("Array of cumulative times must contain more than just a single zero");for(var e=[],s=0;s+1<t.length;s+=1)e.push(n(t[s+1],t[s]));return e}function a(t,e,s,n,i,r){"number"!=typeof t&&o("Competitor order must be a number, got "+typeof t+" '"+t+"' instead"),this.order=t,this.name=e,this.club=s,this.startTime=n,this.isNonCompetitive=!1,this.isNonStarter=!1,this.isNonFinisher=!1,this.isDisqualified=!1,this.isOverMaxTime=!1,this.className=null,this.yearOfBirth=null,this.gender=null,this.originalSplitTimes=i,this.originalCumTimes=r,this.splitTimes=null,this.cumTimes=null,this.splitRanks=null,this.cumRanks=null,this.timeLosses=null,this.totalTime=null===r||-1<r.indexOf(null)?null:r[r.length-1]}function e(t){for(var e=[],s=1;s+1<t.length;)if(i(t[s])){for(var n=s;n+1<t.length&&i(t[n+1]);)n+=1;n+1<t.length&&null!==t[s-1]&&null!==t[n+1]&&e.push({start:s-1,end:n+1}),s=n+1}else s+=1;return e}SplitsBrowser.Model.compareCompetitors=function(t,e){return t.isDisqualified!==e.isDisqualified?t.isDisqualified?1:-1:t.totalTime===e.totalTime?t.order-e.order:null===t.totalTime?null===e.totalTime?0:1:null===e.totalTime?-1:t.totalTime-e.totalTime},a.prototype.setNonCompetitive=function(){this.isNonCompetitive=!0},a.prototype.setNonStarter=function(){this.isNonStarter=!0},a.prototype.setNonFinisher=function(){this.isNonFinisher=!0},a.prototype.disqualify=function(){this.isDisqualified=!0},a.prototype.setOverMaxTime=function(){this.isOverMaxTime=!0},a.prototype.setClassName=function(t){this.className=t},a.prototype.setYearOfBirth=function(t){this.yearOfBirth=t},a.prototype.setGender=function(t){this.gender=t},a.fromOriginalCumTimes=function(t,e,s,n,i){return new a(t,e,s,n,r(i),i)},a.fromCumTimes=function(t,e,s,n,i){var r=a.fromOriginalCumTimes(t,e,s,n,i);return r.splitTimes=r.originalSplitTimes,r.cumTimes=r.originalCumTimes,r},a.prototype.setRepairedCumulativeTimes=function(t){this.cumTimes=t,this.splitTimes=r(t)},a.prototype.completed=function(){return null!==this.totalTime&&!this.isDisqualified&&!this.isOverMaxTime},a.prototype.hasAnyTimes=function(){return this.originalCumTimes.slice(1).some(t)},a.prototype.getSplitTimeTo=function(t){return 0===t?0:this.splitTimes[t-1]},a.prototype.getOriginalSplitTimeTo=function(t){return this.isNonStarter?null:0===t?0:this.originalSplitTimes[t-1]},a.prototype.isSplitTimeDubious=function(t){return 0<t&&this.originalSplitTimes[t-1]!==this.splitTimes[t-1]},a.prototype.getCumulativeTimeTo=function(t){return this.cumTimes[t]},a.prototype.getOriginalCumulativeTimeTo=function(t){return this.isNonStarter?null:this.originalCumTimes[t]},a.prototype.isCumulativeTimeDubious=function(t){return this.originalCumTimes[t]!==this.cumTimes[t]},a.prototype.getSplitRankTo=function(t){return null===this.splitRanks||0===t?null:this.splitRanks[t-1]},a.prototype.getCumulativeRankTo=function(t){return null===this.cumRanks||0===t?null:this.cumRanks[t-1]},a.prototype.getTimeLossAt=function(t){return 0===t||null===this.timeLosses?null:this.timeLosses[t-1]},a.prototype.getAllCumulativeTimes=function(){return this.cumTimes},a.prototype.getAllOriginalCumulativeTimes=function(){return this.originalCumTimes},a.prototype.lacksStartTime=function(){return null===this.startTime&&this.splitTimes.some(t)},a.prototype.setSplitAndCumulativeRanks=function(t,e){this.splitRanks=t,this.cumRanks=e},a.prototype.getCumTimesAdjustedToReference=function(s){return s.length!==this.cumTimes.length?o("Cannot adjust competitor times because the numbers of times are different ("+this.cumTimes.length+" and "+s.length+")"):-1<s.indexOf(null)&&o("Cannot adjust competitor times because a null value is in the reference data"),this.cumTimes.map(function(t,e){return n(t,s[e])})},a.prototype.getCumTimesAdjustedToReferenceWithStartAdded=function(t){var e=this.getCumTimesAdjustedToReference(t),s=this.startTime;return e.map(function(t){return function(t,e){return null===t||null===e?null:t+e}(t,s)})},a.prototype.getSplitPercentsBehindReferenceCumTimes=function(n){n.length!==this.cumTimes.length?o("Cannot determine percentages-behind because the numbers of times are different ("+this.cumTimes.length+" and "+n.length+")"):-1<n.indexOf(null)&&o("Cannot determine percentages-behind because a null value is in the reference data");var i=[0];return this.splitTimes.forEach(function(t,e){if(null===t)i.push(null);else{var s=n[e+1]-n[e];0<s?i.push(100*(t-s)/s):i.push(null)}}),i},a.prototype.determineTimeLosses=function(s){if(this.completed())if(s.length!==this.splitTimes.length?o("Cannot determine time loss of competitor with "+this.splitTimes.length+" split times using "+s.length+" fastest splits"):s.some(i)&&o("Cannot determine time loss of competitor when there is a NaN value in the fastest splits"),s.some(function(t){return 0===t}))this.timeLosses=this.splitTimes.map(function(){return NaN});else if(this.splitTimes.some(i))this.timeLosses=this.splitTimes.map(function(){return NaN});else{var n,t=this.splitTimes.map(function(t,e){return t/s[e]});if(t.sort(d3.ascending),t.length%2==1)n=t[(t.length-1)/2];else{var e=t.length/2;n=(t[e-1]+t[e])/2}this.timeLosses=this.splitTimes.map(function(t,e){return Math.round(t-s[e]*n)})}},a.prototype.crosses=function(t){t.cumTimes.length!==this.cumTimes.length&&o("Two competitors with different numbers of controls cannot cross");for(var e=!1,s=!1,n=0;n<this.cumTimes.length;n+=1)if(null!==this.cumTimes[n]&&null!==t.cumTimes[n]){var i=this.startTime+this.cumTimes[n],r=t.startTime+t.cumTimes[n];i<r?e=!0:r<i&&(s=!0)}return e&&s},a.prototype.getControlIndexesAroundDubiousCumulativeTimes=function(){return e(this.cumTimes)},a.prototype.getControlIndexesAroundDubiousSplitTimes=function(){return e([0].concat(this.splitTimes))},SplitsBrowser.Model.Competitor=a}(),function(){"use strict";var r=SplitsBrowser.isNotNullNorNaN,t=SplitsBrowser.throwInvalidData;function e(e,t,s){this.name=e,this.numControls=t,this.competitors=s,this.course=null,this.hasDubiousData=!1,this.competitors.forEach(function(t){t.setClassName(e)})}e.prototype.recordHasDubiousData=function(){this.hasDubiousData=!0},e.prototype.determineTimeLosses=function(){var e=d3.range(1,this.numControls+2).map(function(t){var e=this.getFastestSplitTo(t);return null===e?null:e.split},this);this.competitors.forEach(function(t){t.determineTimeLosses(e)})},e.prototype.isEmpty=function(){return 0===this.competitors.length},e.prototype.setCourse=function(t){this.course=t},e.prototype.getFastestSplitTo=function(s){("number"!=typeof s||s<1||s>this.numControls+1)&&t("Cannot return splits to leg '"+s+"' in a course with "+this.numControls+" control(s)");var n=null,i=null;return this.competitors.forEach(function(t){var e=t.getSplitTimeTo(s);r(e)&&(null===n||e<n)&&(n=e,i=t)}),null===n?null:{split:n,name:i.name}},e.prototype.getCompetitorsAtControlInTimeRange=function(n,i,r){("number"!=typeof n||isNaN(n)||n<0||n>this.numControls+1)&&t("Control number must be a number between 0 and "+this.numControls+" inclusive");var o=[];return this.competitors.forEach(function(t){var e=t.getCumulativeTimeTo(n);if(null!==e&&null!==t.startTime){var s=e+t.startTime;i<=s&&s<=r&&o.push({name:t.name,time:s})}}),o},SplitsBrowser.Model.CourseClass=e}(),function(){"use strict";var c=SplitsBrowser.isNotNull,u=SplitsBrowser.isNaNStrict,p=SplitsBrowser.isNotNullNorNaN,r=SplitsBrowser.throwInvalidData,n=SplitsBrowser.Model.compareCompetitors;function t(t){var e=t.filter(p);e.sort(d3.ascending);var s=new d3.map;return e.forEach(function(t,e){s.has(t)||s.set(t,e+1)}),t.map(function(t){return p(t)?s.get(t):t})}function e(t){this.allCompetitors=function(t){if(0===t.length)return[];var e=[],s=t[0].numControls;return t.forEach(function(t){t.numControls!==s&&r("Cannot merge classes with "+s+" and "+t.numControls+" controls"),t.competitors.forEach(function(t){t.isNonStarter||e.push(t)})}),e.sort(n),e}(t),this.classes=t,this.numControls=0<t.length?t[0].numControls:null,this.computeRanks()}function d(t,e){for(var s=[],n=1;n+1<t.length;)if(p(t[n]))n+=1;else{for(var i=n;i+1<t.length&&!p(t[i+1]);)i+=1;(i+1<t.length||e)&&s.push({start:n-1,end:i+1}),n=i+1}return s}function s(t){for(var e=d(t=t.slice(0),!1),s=0;s<e.length;s+=1)for(var n=e[s],i=t[n.start],r=(t[n.end]-i)/(n.end-n.start),o=n.start+1;o<n.end;o+=1)t[o]=i+(o-n.start)*r;for(var a=t.length;0<=a&&u(t[a-1]);)a-=1;if(0<a)for(var l=a;l<t.length;l+=1)t[l]=t[l-1]+(l===t.length-1?60:180);return t}e.prototype.isEmpty=function(){return 0===this.allCompetitors.length},e.prototype.getCourse=function(){return 0<this.classes.length?this.classes[0].course:null},e.prototype.getPrimaryClassName=function(){return 0<this.classes.length?this.classes[0].name:null},e.prototype.getNumClasses=function(){return this.classes.length},e.prototype.hasDubiousData=function(){return this.classes.some(function(t){return t.hasDubiousData})},e.prototype.getWinnerCumTimes=function(){if(0===this.allCompetitors.length)return null;var t=this.allCompetitors[0];return t.completed()?s(t.cumTimes):null},e.prototype.getFastestCumTimes=function(){return this.getFastestCumTimesPlusPercentage(0)},e.prototype.getFastestCumTimesPlusPercentage=function(t){if(null===this.numControls)return null;var s=1+t/100,r=new Array(this.numControls+1);r[0]=0;for(var e=1;e<=this.numControls+1;e+=1){for(var n=null,i=0;i<this.allCompetitors.length;i+=1){var o=this.allCompetitors[i].getSplitTimeTo(e);p(o)&&(null===n||o<n)&&(n=o)}r[e]=n}if(!r.every(c)){var a=d(r,!0),l=[];this.allCompetitors.forEach(function(e){d(e.getAllCumulativeTimes(),!1).forEach(function(t){l.push({start:t.start,end:t.end,size:t.end-t.start,overallSplit:e.getCumulativeTimeTo(t.end)-e.getCumulativeTimeTo(t.start)})})}),a.forEach(function(e){var t=l.filter(function(t){return t.start<=e.start&&e.end<=t.end+1}),s=null,n=null;if(t.forEach(function(t){(null===s||t.size<s)&&(s=t.size,n=null),(null===n||t.overallSplit<n)&&(n=t.overallSplit)}),null!==s&&null!==n)for(var i=e.start+1;i<e.end;i+=1)r[i]=n/s})}if(!r.every(c))for(var u=0;u<r.length;u+=1)null===r[u]&&(r[u]=u===r.length-1?60:180);var h=new Array(this.numControls+1);return r.forEach(function(t,e){h[e]=0===e?0:h[e-1]+t*s}),h},e.prototype.getCumulativeTimesForCompetitor=function(t){return s(this.allCompetitors[t].getAllCumulativeTimes())},e.prototype.computeRanks=function(){if(0!==this.allCompetitors.length){var n=[],i=[];this.allCompetitors.forEach(function(){n.push([]),i.push([])}),d3.range(1,this.numControls+2).forEach(function(e){var s=t(this.allCompetitors.map(function(t){return t.getSplitTimeTo(e)}));this.allCompetitors.forEach(function(t,e){n[e].push(s[e])})},this),d3.range(1,this.numControls+2).forEach(function(s){var n=t(this.allCompetitors.map(function(t,e){return 1<s&&null===i[e][s-1-1]?null:t.getCumulativeTimeTo(s)}));this.allCompetitors.forEach(function(t,e){i[e].push(n[e])})},this),this.allCompetitors.forEach(function(t,e){t.setSplitAndCumulativeRanks(n[e],i[e])})}},e.prototype.getFastestSplitsTo=function(t,i){if("number"!=typeof t||t<=0)r("The number of splits must be a positive integer");else{if(!("number"!=typeof i||i<=0||i>this.numControls+1)){var e=this.allCompetitors.filter(function(t){return t.completed()&&!u(t.getSplitTimeTo(i))});e.sort(function(t,e){var s=t.getSplitTimeTo(i),n=e.getSplitTimeTo(i);return s===n?d3.ascending(t.totalTime,e.totalTime):d3.ascending(s,n)});for(var s=[],n=0;n<e.length&&n<t;n+=1)s.push({name:e[n].name,split:e[n].getSplitTimeTo(i)});return s}r("Control "+i+" out of range")}},e.prototype.getChartData=function(e,t,s){if(void 0===e)throw new TypeError("referenceCumTimes undefined or missing");if(void 0===t)throw new TypeError("currentIndexes undefined or missing");if(void 0===s)throw new TypeError("chartType undefined or missing");var n,i,r=this.allCompetitors.map(function(t){return s.dataSelector(t,e)}),o=t.map(function(t){return r[t]}),a=d3.min(e),l=d3.max(e);if(0===t.length)if(this.isEmpty())n=0,i=60;else{var u=r[0];n=d3.min(u),i=d3.max(u)}else n=d3.min(o.map(function(t){return d3.min(t)})),i=d3.max(o.map(function(t){return d3.max(t)}));Math.abs(i-n)<1e-8&&(i=n+1);var h=s.skipStart?1:0,c=t.map(function(t){return s.indexesAroundDubiousTimesFunc(this.allCompetitors[t]).filter(function(t){return t.start>=h}).map(function(t){return{start:t.start-h,end:t.end-h}})},this),p=d3.transpose(o),d=s.skipStart?e.slice(1):e,m=d3.zip(d,p),f=t.map(function(t){return this.allCompetitors[t].name},this);return{dataColumns:m.map(function(t){return{x:t[0],ys:t[1]}}),competitorNames:f,numControls:this.numControls,xExtent:[a,l],yExtent:[n,i],dubiousTimesInfo:c}},SplitsBrowser.Model.CourseClassSet=e}(),function(){"use strict";var r=SplitsBrowser.throwInvalidData;function t(t,e,s,n,i){this.name=t,this.classes=e,this.length=s,this.climb=n,this.controls=i}var a=t.START="__START__",l=t.FINISH="__FINISH__";t.prototype.getOtherClasses=function(e){var t=this.classes.filter(function(t){return t!==e});if(t.length!==this.classes.length)return t;r("Course.getOtherClasses: given class is not in this course")},t.prototype.getNumClasses=function(){return this.classes.length},t.prototype.hasControls=function(){return null!==this.controls},t.prototype.getControlCode=function(t){return 0===t?a:1<=t&&t<=this.controls.length?this.controls[t-1]:t===this.controls.length+1?l:void r("Cannot get control code of control "+t+" because it is out of range")},t.prototype.usesLeg=function(t,e){return 0<=this.getLegNumber(t,e)},t.prototype.getLegNumber=function(t,e){if(null===this.controls)return-1;if(t===a&&e===l)return 0===this.controls.length?1:-1;if(t===a)return 0<this.controls.length&&this.controls[0]===e?1:-1;if(e===l)return 0<this.controls.length&&this.controls[this.controls.length-1]===t?this.controls.length+1:-1;for(var s=1;s<this.controls.length;s+=1)if(this.controls[s-1]===t&&this.controls[s]===e)return s+1;return-1},t.prototype.getFastestSplitsForLeg=function(t,e){null===this.legs&&r("Cannot determine fastest splits for a leg because leg information is not available");var s=this.getLegNumber(t,e);s<0&&r("Leg from "+((t===a?"start":t)+" to "+(e===l?"end":e))+" not found in course "+this.name);var n=s,i=[];return this.classes.forEach(function(t){var e=t.getFastestSplitTo(n);null!==e&&i.push({name:e.name,className:t.name,split:e.split})}),i},t.prototype.getCompetitorsAtControlInTimeRange=function(t,e,s){if(null===this.controls)return[];if(t===a)return this.getCompetitorsAtControlNumInTimeRange(0,e,s);if(t===l)return this.getCompetitorsAtControlNumInTimeRange(this.controls.length+1,e,s);for(var n=-1,i=[],r=function(t){i.push(t)};;){var o=this.controls.indexOf(t,n+1);if(o<0)return i;this.getCompetitorsAtControlNumInTimeRange(o+1,e,s).forEach(r),n=o}},t.prototype.getCompetitorsAtControlNumInTimeRange=function(t,s,n){var i=[];return this.classes.forEach(function(e){e.getCompetitorsAtControlInTimeRange(t,s,n).forEach(function(t){i.push({name:t.name,time:t.time,className:e.name})})}),i},t.prototype.hasControl=function(t){return null!==this.controls&&-1<this.controls.indexOf(t)},t.prototype.getNextControls=function(t){if(null===this.controls)r("Course has no controls");else if(t===l)r("Cannot fetch next control after the finish");else{if(t===a)return[0===this.controls.length?l:this.controls[0]];for(var e=-1,s=[];;){var n=this.controls.indexOf(t,e+1);if(-1===n)break;n===this.controls.length-1?s.push(l):s.push(this.controls[n+1]),e=n}if(0!==s.length)return s;r("Control '"+t+"' not found on course "+this.name)}},SplitsBrowser.Model.Course=t}(),function(){"use strict";var s=SplitsBrowser.Model.Course;function t(t,e,s){this.classes=t,this.courses=e,this.warnings=s}t.prototype.determineTimeLosses=function(){this.classes.forEach(function(t){t.determineTimeLosses()})},t.prototype.needsRepair=function(){return this.classes.some(function(t){return t.competitors.some(function(t){return null===t.getAllCumulativeTimes()})})},t.prototype.getFastestSplitsForLeg=function(e,s){var n=[];return this.courses.forEach(function(t){t.usesLeg(e,s)&&(n=n.concat(t.getFastestSplitsForLeg(e,s)))}),n.sort(function(t,e){return d3.ascending(t.split,e.split)}),n},t.prototype.getCompetitorsAtControlInTimeRange=function(e,s,n){var i=[];return this.courses.forEach(function(t){t.getCompetitorsAtControlInTimeRange(e,s,n).forEach(function(t){i.push(t)})}),i.sort(function(t,e){return d3.ascending(t.time,e.time)}),i},t.prototype.getNextControlsAfter=function(e){var t=this.courses;return e!==s.START&&(t=t.filter(function(t){return t.hasControl(e)})),t.map(function(t){return{course:t,nextControls:t.getNextControls(e)}})},SplitsBrowser.Model.Event=t}(),function(){function s(t){return null===t?null:t/60}function t(t){return t.getControlIndexesAroundDubiousCumulativeTimes()}function e(t){return t.getControlIndexesAroundDubiousSplitTimes()}SplitsBrowser.Model.ChartTypes={SplitsGraph:{nameKey:"SplitsGraphChartType",dataSelector:function(t,e){return t.getCumTimesAdjustedToReference(e).map(s)},skipStart:!1,yAxisLabelKey:"SplitsGraphYAxisLabel",isRaceGraph:!1,isResultsTable:!1,minViewableControl:1,indexesAroundDubiousTimesFunc:t},RaceGraph:{nameKey:"RaceGraphChartType",dataSelector:function(t,e){return t.getCumTimesAdjustedToReferenceWithStartAdded(e).map(s)},skipStart:!1,yAxisLabelKey:"RaceGraphYAxisLabel",isRaceGraph:!0,isResultsTable:!1,minViewableControl:0,indexesAroundDubiousTimesFunc:t},PositionAfterLeg:{nameKey:"PositionAfterLegChartType",dataSelector:function(t){return t.cumRanks},skipStart:!0,yAxisLabelKey:"PositionYAxisLabel",isRaceGraph:!1,isResultsTable:!1,minViewableControl:1,indexesAroundDubiousTimesFunc:t},SplitPosition:{nameKey:"SplitPositionChartType",dataSelector:function(t){return t.splitRanks},skipStart:!0,yAxisLabelKey:"PositionYAxisLabel",isRaceGraph:!1,isResultsTable:!1,minViewableControl:1,indexesAroundDubiousTimesFunc:e},PercentBehind:{nameKey:"PercentBehindChartType",dataSelector:function(t,e){return t.getSplitPercentsBehindReferenceCumTimes(e)},skipStart:!1,yAxisLabelKey:"PercentBehindYAxisLabel",isRaceGraph:!1,isResultsTable:!1,minViewableControl:1,indexesAroundDubiousTimesFunc:e},ResultsTable:{nameKey:"ResultsTableChartType",dataSelector:null,skipStart:!1,yAxisLabelKey:null,isRaceGraph:!1,isResultsTable:!0,minViewableControl:1,indexesAroundDubiousTimesFunc:null}}}(),function(){"use strict";var i="number",r=SplitsBrowser.throwInvalidData;function t(t){typeof t!=i?r("Competitor count must be a number"):t<0&&r("Competitor count must be a non-negative number"),this.count=t,this.currentIndexes=[],this.changeHandlers=[]}t.prototype.isSelected=function(t){return-1<this.currentIndexes.indexOf(t)},t.prototype.isSingleRunnerSelected=function(){return 1===this.currentIndexes.length},t.prototype.getSingleRunnerIndex=function(){return this.isSingleRunnerSelected()?this.currentIndexes[0]:null},t.prototype.selectCrossingRunners=function(t){if(this.isSingleRunnerSelected()){var s=t[this.currentIndexes[0]].competitor;t.forEach(function(t,e){t.visible&&t.competitor.crosses(s)&&this.currentIndexes.push(e)},this),this.currentIndexes.sort(d3.ascending),this.fireChangeHandlers()}},t.prototype.fireChangeHandlers=function(){this.changeHandlers.forEach(function(t){t(this.currentIndexes.slice(0))},this)},t.prototype.selectAll=function(){this.currentIndexes=d3.range(this.count),this.fireChangeHandlers()},t.prototype.selectNone=function(){this.currentIndexes=[],this.fireChangeHandlers()},t.prototype.getSelectedIndexes=function(){return this.currentIndexes.slice(0)},t.prototype.setSelectedIndexes=function(t){t.every(function(t){return 0<=t&&t<this.count},this)&&(this.currentIndexes=t,this.fireChangeHandlers())},t.prototype.registerChangeHandler=function(t){-1===this.changeHandlers.indexOf(t)&&this.changeHandlers.push(t)},t.prototype.deregisterChangeHandler=function(t){var e=this.changeHandlers.indexOf(t);-1<e&&this.changeHandlers.splice(e,1)},t.prototype.toggle=function(t){if(typeof t==i)if(0<=t&&t<this.count){var e=this.currentIndexes.indexOf(t);-1===e?(this.currentIndexes.push(t),this.currentIndexes.sort(d3.ascending)):this.currentIndexes.splice(e,1),this.fireChangeHandlers()}else r("Index '"+t+"' is out of range");else r("Index is not a number")},t.prototype.bulkSelect=function(t){t.some(function(t){return typeof t!=i||t<0||t>=this.count},this)&&r("Indexes not all numeric and in range");var e=d3.set(this.currentIndexes);0<(t=t.filter(function(t){return!e.has(t)})).length&&(this.currentIndexes=this.currentIndexes.concat(t),this.currentIndexes.sort(d3.ascending),this.fireChangeHandlers())},t.prototype.bulkDeselect=function(t){t.some(function(t){return typeof t!=i||t<0||t>=this.count},this)&&r("Indexes not all numeric and in range");for(var e=d3.set(this.currentIndexes),s=!1,n=0;n<t.length;n+=1)e.has(t[n])&&(e.remove(t[n]),s=!0);s&&(this.currentIndexes=e.values().map(function(t){return parseInt(t,10)}),this.currentIndexes.sort(d3.ascending),this.fireChangeHandlers())},t.prototype.migrate=function(e,t){$.isArray(e)?$.isArray(t)?e.length!==this.count?r("CompetitorSelection.migrate: oldCompetitors list must have the same length as the current count"):0===t.length&&0<this.currentIndexes.length&&r("CompetitorSelection.migrate: newCompetitors list must not be empty if current list has competitors selected"):r("CompetitorSelection.migrate: newCompetitors not an array"):r("CompetitorSelection.migrate: oldCompetitors not an array");var s=this.currentIndexes.map(function(t){return e[t]});this.count=t.length,this.currentIndexes=[],t.forEach(function(t,e){0<=s.indexOf(t)&&this.currentIndexes.push(e)},this)},SplitsBrowser.Model.CompetitorSelection=t}(),function(){"use strict";function e(){this.madeAnyChanges=!1}var l=SplitsBrowser.isNotNullNorNaN,i=SplitsBrowser.throwInvalidData;function u(t){0!==t.length&&0===t[0]||i("cumulative times array does not start with a zero cumulative time");for(var e=0,s=1;s<t.length;s+=1){var n=t[s];if(l(n)){if(n<=t[e])return{first:e,second:s};e=s}}return null}e.prototype.removeCumulativeTimesEqualToPrevious=function(t){for(var e=t[0],s=1;s+1<t.length;s+=1)null!==t[s]&&(t[s]===e?(t[s]=NaN,this.madeAnyChanges=!0):e=t[s])},e.prototype.removeCumulativeTimesCausingNegativeSplits=function(t){for(var e=u(t);null!==e&&e.second+1<t.length;){for(var s=e.first,n=e.second,i=!1,r=1;r<=3;r+=1){var o=t.slice();if(3!==r||1!==s&&l(t[s-1])){1===r?o[n]=NaN:2===r?o[s]=NaN:3===r&&(o[s]=NaN,o[s-1]=NaN);var a=u(o);if(null===a||a.first>n){i=!0,t=o,this.madeAnyChanges=!0,e=a;break}}else;}if(!i)break}return t},e.prototype.removeFinishTimeIfAbsurd=function(t){var e=t[t.length-1],s=t[t.length-2];l(e)&&l(s)&&e<=s-300&&(t[t.length-1]=NaN,this.madeAnyChanges=!0)},e.prototype.repairCompetitor=function(t){var e=t.originalCumTimes.slice(0);this.removeCumulativeTimesEqualToPrevious(e),e=this.removeCumulativeTimesCausingNegativeSplits(e),t.completed()||this.removeFinishTimeIfAbsurd(e),t.setRepairedCumulativeTimes(e)},e.prototype.repairCourseClass=function(t){this.madeAnyChanges=!1,t.competitors.forEach(function(t){this.repairCompetitor(t)},this),this.madeAnyChanges&&t.recordHasDubiousData()},e.prototype.repairEventData=function(t){t.classes.forEach(function(t){this.repairCourseClass(t)},this)},SplitsBrowser.DataRepair={repairEventData:function(t){(new e).repairEventData(t)},transferCompetitorData:function(t){t.classes.forEach(function(t){t.competitors.forEach(function(t){t.setRepairedCumulativeTimes(t.getAllOriginalCumulativeTimes())})})}}}(),function(){"use strict";var l=SplitsBrowser.isTrue,u=SplitsBrowser.isNotNull,h=SplitsBrowser.throwInvalidData,c=SplitsBrowser.throwWrongFileFormat,o=SplitsBrowser.normaliseLineEndings,g=SplitsBrowser.parseTime,C=SplitsBrowser.Model.Competitor,p=SplitsBrowser.Model.compareCompetitors,d=SplitsBrowser.Model.CourseClass,a=SplitsBrowser.Model.Course,m=SplitsBrowser.Model.Event;function f(t,s){var e=t.split(/\r?\n/).filter(l);0===e.length&&h("parseCourseClass got an empty list of lines");var n=e.shift().split(",");if(2===n.length){var i=n.shift(),r=n.shift(),o=parseInt(r,10);if(isNaN(o))h("Could not read control count: '"+r+"'");else{if(!(o<0&&0<e.length)){var a=e.map(function(t,e){return function(t,e,s,n,i){for(var r=e.split(",");r.length>s+5&&r[3].match(/[^0-9.,:-]/);)r[2]+=","+r[3],r.splice(3,1);var o=r.length,a=((r.shift()||"")+" "+(r.shift()||"")).trim()||"<name unknown>";if(o===s+5){var l=r.shift(),u=r.shift(),h=g(u);0===h?h=null:u.match(/^\d+:\d\d:\d\d$/)||(h*=60);var c=[0],p=0;r.map(function(t){var e=g(t);null!==e&&0<e?(p+=e,c.push(p)):c.push(null)});var d=C.fromCumTimes(t+1,a,l,h,c);return 0===p&&d.setNonStarter(),d}var m=o-(s+5),f=m<0?-m+" too few":m+" too many";return i.push("Competitor '"+a+"' appears to have the wrong number of split times - "+f+" (row "+(t+1)+" of class '"+n+"')"),null}(e,t,o,i,s)}).filter(u);return a.sort(p),new d(i,o,a)}h("Expected a non-negative control count, got "+o+" instead")}}else c("Expected first line to have two parts (class name and number of controls), got "+n.length+" part(s) instead")}SplitsBrowser.Input.CSV={parseEventData:function(t){/<html/i.test(t)&&c("Cannot parse this file as CSV as it appears to be HTML");var e=(t=(t=o(t)).replace(/,+\n/g,"\n").replace(/,+$/,"")).split(/\n\n/).map(function(t){return t.trim()}).filter(l),s=[],n=e.map(function(t){return f(t,s)});0===(n=n.filter(function(t){return!t.isEmpty()})).length&&h("No competitor data was found");for(var i=n.map(function(t){return new a(t.name,[t],null,null,null)}),r=0;r<n.length;r+=1)n[r].setCourse(i[r]);return new m(n,i,s)}}}(),function(){"use strict";var o=SplitsBrowser.throwInvalidData,i=SplitsBrowser.throwWrongFileFormat,m=SplitsBrowser.isNaNStrict,r=SplitsBrowser.parseCourseLength,a=SplitsBrowser.parseCourseClimb,e=SplitsBrowser.normaliseLineEndings,c=SplitsBrowser.parseTime,f=SplitsBrowser.Model.Competitor.fromOriginalCumTimes,s=SplitsBrowser.Model.CourseClass,C=SplitsBrowser.Model.Course,n=SplitsBrowser.Model.Event,l=[";",",","\t","\\"],u={};[44,46,60].forEach(function(t){u[t]={course:t-7,distance:t-6,climb:t-5,controlCount:t-4,placing:t-3,startPunch:t-2,finish:t-1,control1:t}}),[44,46].forEach(function(t){u[t].nonCompetitive=t-38,u[t].startTime=t-37,u[t].time=t-35,u[t].classifier=t-34,u[t].club=t-31,u[t].className=t-28}),u[44].combinedName=3,u[44].yearOfBirth=4,u[46].forename=4,u[46].surname=3,u[46].yearOfBirth=5,u[46].gender=6,u[60].forename=6,u[60].surname=5,u[60].yearOfBirth=7,u[60].gender=8,u[60].combinedName=3,u[60].nonCompetitive=10,u[60].startTime=11,u[60].time=13,u[60].classifier=14,u[60].club=20,u[60].className=26,u[60].classNameFallback=u[60].course,u[60].clubFallback=18;function h(t){return'"'===t[0]&&'"'===t[t.length-1]&&(t=t.substring(1,t.length-1).replace(/""/g,'"').trim()),t}function p(t){this.data=e(t),this.classes=d3.map(),this.courseDetails=d3.map(),this.classCoursePairs=[],this.columnIndexes=null,this.warnings=[]}p.prototype.identifyDelimiter=function(){this.lines.length<=1&&i("No data found to read");for(var t=this.lines[1],e=0;e<l.length;e+=1){var s=l[e];if(37<t.split(s).length)return s}i("Data appears not to be in the OE CSV format")},p.prototype.identifyFormatVariation=function(t){var e=this.lines[1].split(t),s=/^[A-Za-z0-9]+$/;for(var n in u){if(u.hasOwnProperty(n))if((n=parseInt(n,10))<e.length&&s.test(e[n])&&(""===e[n-2].trim()||null!==c(e[n-2]))&&(""===e[n-1].trim()||null!==c(e[n-1])))if(""!==e[u[n].controlCount].trim())return void(this.columnIndexes=u[n])}i("Did not find control 1 at any of the supported indexes")},p.prototype.getClassName=function(t){var e=t[this.columnIndexes.className];return""===e&&this.columnIndexes.hasOwnProperty("classNameFallback")&&(e=t[this.columnIndexes.classNameFallback]),e},p.prototype.getStartTime=function(t){var e=t[this.columnIndexes.startPunch];return""===e&&(e=t[this.columnIndexes.startTime]),c(e)},p.prototype.getNumControls=function(t,e){var s,n=this.getClassName(t);if(""===n.trim())return s=this.getName(t)||"<name unknown>",this.warnings.push("Could not find a class for competitor '"+s+"' (line "+e+")"),null;if(this.classes.has(n))return this.classes.get(n).numControls;var i=parseInt(t[this.columnIndexes.controlCount],10);return isFinite(i)?i:(s=this.getName(t)||"<name unknown>",this.warnings.push("Could not read the control count '"+t[this.columnIndexes.controlCount]+"' for competitor '"+s+"' from line "+e),null)},p.prototype.readCumulativeTimes=function(t,e,s){for(var n=[0],i=0;i<s;i+=1){var r=this.columnIndexes.control1+1+2*i,o=r<t.length?t[r]:null,a=null===o?null:c(o);n.push(a)}var l=c(t[this.columnIndexes.time]);if(null===l){var u=this.getStartTime(t),h=c(t[this.columnIndexes.finish]);null!==u&&null!==h&&(l=h-u)}return n.push(l),n},p.prototype.createClassIfNecessary=function(t,e){var s=this.getClassName(t);this.classes.has(s)||this.classes.set(s,{numControls:e,competitors:[]})},p.prototype.createCourseIfNecessary=function(e,t){var s=e[this.columnIndexes.course];if(!this.courseDetails.has(s)){var n=d3.range(0,t).map(function(t){return e[this.columnIndexes.control1+2*t]},this);this.courseDetails.set(s,{length:r(e[this.columnIndexes.distance]),climb:a(e[this.columnIndexes.climb]),controls:n})}},p.prototype.createClassCoursePairIfNecessary=function(t){var e=this.getClassName(t),s=t[this.columnIndexes.course];this.classCoursePairs.some(function(t){return t[0]===e&&t[1]===s})||this.classCoursePairs.push([e,s])},p.prototype.getName=function(t){var e=""
;this.columnIndexes.hasOwnProperty("forename")&&this.columnIndexes.hasOwnProperty("surname")&&(e=(t[this.columnIndexes.forename]+" "+t[this.columnIndexes.surname]).trim());return""===e&&this.columnIndexes.hasOwnProperty("combinedName")&&(e=t[this.columnIndexes.combinedName]),e},p.prototype.addCompetitor=function(t,e){var s=this.getClassName(t),n=t[this.columnIndexes.placing],i=t[this.columnIndexes.club];""===i&&this.columnIndexes.hasOwnProperty("clubFallback")&&(i=t[this.columnIndexes.clubFallback]);var r=this.getStartTime(t),o=this.getName(t),a=""!==n&&m(parseInt(n,10));a&&o.substring(o.length-n.length)===n&&(o=o.substring(0,o.length-n.length).trim());var l=this.classes.get(s).competitors.length+1,u=f(l,o,i,r,e);("1"===t[this.columnIndexes.nonCompetitive]||a)&&u.completed()&&u.setNonCompetitive();var h=t[this.columnIndexes.classifier];""!==h&&"0"!==h?"1"===h?u.setNonStarter():"2"===h?u.setNonFinisher():"4"===h?u.disqualify():"5"===h&&u.setOverMaxTime():u.hasAnyTimes()||u.setNonStarter();var c=t[this.columnIndexes.yearOfBirth];if(""!==c){var p=parseInt(c,10);m(p)||u.setYearOfBirth(p)}if(this.columnIndexes.hasOwnProperty("gender")){var d=t[this.columnIndexes.gender];"M"!==d&&"F"!==d||u.setGender(d)}this.classes.get(s).competitors.push(u)},p.prototype.readLine=function(t,e,s){if(""!==t.trim()){var n=t.split(s).map(function(t){return t.trim()}).map(h);n.length<37&&o("Too few items on line "+e+" of the input file: expected at least 37, got "+n.length);var i=this.getNumControls(n,e);if(null!==i){var r=this.readCumulativeTimes(n,e,i);this.createClassIfNecessary(n,i),this.createCourseIfNecessary(n,i),this.createClassCoursePairIfNecessary(n),this.addCompetitor(n,r)}}},p.prototype.getMapsBetweenClassesAndCourses=function(){var n=d3.map(),i=d3.map();return this.classCoursePairs.forEach(function(t){var e=t[0],s=t[1];n.has(e)?n.get(e).push(s):n.set(e,[s]),i.has(s)?i.get(s).push(e):i.set(s,[e])}),{classesToCourses:n,coursesToClasses:i}},p.prototype.createClasses=function(){var t=this.classes.keys();return t.sort(),t.map(function(t){var e=this.classes.get(t);return new s(t,e.numControls,e.competitors)},this)},p.prototype.createCourseFromLinkedClassesAndCourses=function(t,e,s,n){for(var i,r,o=[t],a=[],l=[],u=[];0<o.length||0<a.length;){for(;0<o.length;){i=o.shift();for(var h=e.coursesToClasses.get(i),c=0;c<h.length;c+=1)r=h[c],a.indexOf(r)<0&&u.indexOf(r)<0&&a.push(r);l.push(i)}for(;0<a.length;){r=a.shift();for(var p=e.classesToCourses.get(r),d=0;d<p.length;d+=1)i=p[d],o.indexOf(i)<0&&l.indexOf(i)<0&&o.push(i);u.push(r)}}l.forEach(function(t){s.add(t)});var m=u.map(function(t){return n.get(t)}),f=this.courseDetails.get(t),g=new C(t,m,f.length,f.climb,f.controls);return m.forEach(function(t){t.setCourse(g)}),g},p.prototype.determineCourses=function(t){var s=this.getMapsBetweenClassesAndCourses(),n=d3.set(),i=d3.map();t.forEach(function(t){i.set(t.name,t)});var r=[];return s.coursesToClasses.keys().forEach(function(t){if(!n.has(t)){var e=this.createCourseFromLinkedClassesAndCourses(t,s,n,i);r.push(e)}},this),r},p.prototype.parseEventData=function(){this.warnings=[],this.lines=this.data.split(/\n/);var s=this.identifyDelimiter();this.identifyFormatVariation(s),this.lines.shift(),this.lines.forEach(function(t,e){this.readLine(t,e+1,s)},this);var t=this.createClasses();0===t.length&&0<this.warnings.length&&i("This file may have looked vaguely like an OE CSV file but no data could be read out of it");var e=this.determineCourses(t);return new n(t,e,this.warnings)},SplitsBrowser.Input.OE={},SplitsBrowser.Input.OE.parseEventData=function(t){return new p(t).parseEventData()}}(),function(){"use strict";var d=SplitsBrowser.isNotNull,m=SplitsBrowser.throwInvalidData,n=SplitsBrowser.throwWrongFileFormat,s=SplitsBrowser.parseCourseLength,i=SplitsBrowser.normaliseLineEndings,f=SplitsBrowser.parseTime,r=SplitsBrowser.Model.Competitor.fromOriginalCumTimes,l=SplitsBrowser.Model.CourseClass,u=SplitsBrowser.Model.Course,e=SplitsBrowser.Model.Event,o=/<[^>]+>/g,a=/([0-9.,]+)\s*(?:Km|km)/,h=/(\d+)\s*(?:Cm|Hm|hm|m)/;function c(t){return null!==t&&""!==t}function g(t){return""!==(t=t.trim())&&isFinite(t)}function C(t){return t.split(/\s+/g).filter(c)}function p(t){return t.replace(o,"")}function v(t,e){for(var s,n=[];null!==(s=t.exec(e));)n.push(p(s[1]));return n}function S(t){return v(/<font[^>]*>(.*?)<\/font>/g,t)}function y(t){return v(/<td[^>]*>(.*?)<\/td>/g,t).map(function(t){return t.trim()})}function x(t){return y(t).filter(function(t){return""!==t})}function T(t){var e=a.exec(t);return null===e?null:s(e[1])}function w(t){var e=h.exec(t);return null===e?null:parseInt(e[1],10)}function b(t){for(var e=[],s=0;s<t.length;s+=1){var n=t[s],i=n.indexOf("(");if(-1<i&&")"===n[n.length-1]){var r=n.substring(i+1,n.length-1);e.push(r)}else s+1===t.length?e.push(null):m("Unrecognised control header label: '"+n+"'")}return e}function D(t,e){for(;0<e.length&&"*"===e[e.length-1][0];)e.splice(e.length-1,1),t.splice(t.length-1,1)}function L(t,e,s,n,i,r){this.name=t,this.club=e,this.className=s,this.totalTime=n,this.cumTimes=i,this.competitive=r}L.prototype.isContinuation=function(){return""===this.name&&""===this.club&&null===this.className&&""===this.totalTime&&!this.competitive},L.prototype.append=function(t){if(!t.isContinuation())throw new Error("Can only append a continuation CompetitorParseRecord");this.cumTimes=this.cumTimes.concat(t.cumTimes)},L.prototype.toCompetitor=function(t){var e=[0].concat(this.cumTimes),s=r(t,this.name,this.club,null,e);return s.completed()&&!this.competitive&&s.setNonCompetitive(),s.hasAnyTimes()||s.setNonStarter(),s};function t(){this.precedingColumnCount=null}t.prototype.isTextOfThisFormat=function(t){return 0<=t.indexOf("<pre>")&&0<=t.indexOf("<font")},t.prototype.preprocess=function(t){var e=t.indexOf("<pre>");if(-1===e)throw new Error("Cannot find opening pre tag");var s=t.indexOf("\n",e),n=(t=(t=t.substring(s+1)).replace(/\n{2,}/g,"\n")).lastIndexOf("</pre>");return-1===n&&m("Found opening <pre> but no closing </pre>"),s=t.lastIndexOf("\n",n),(t=t.substring(0,s)).trim()},t.prototype.canIgnoreThisLine=function(t){return""===t},t.prototype.isCourseHeaderLine=function(t){return 2===S(t).length},t.prototype.parseCourseHeaderLine=function(t){var e=S(t);if(2!==e.length)throw new Error("Course header line should have two parts");var s=e[0],n=e[1],i=s.indexOf("("),r=-1<i?s.substring(0,i):s,o=T(n),a=w(n);return{name:r.trim(),distance:o,climb:a}},t.prototype.parseControlsLine=function(t){var e=t.lastIndexOf("</font>");return b(C((-1===e?t:t.substring(e+"</font>".length)).trim()))},t.prototype.readCompetitorSplitDataLine=function(t){for(var e=0;e<this.precedingColumnCount;e+=1){var s=t.indexOf("</font>");t=t.substring(s+"</font>".length)}return C(p(t))},t.prototype.parseCompetitor=function(t,e){var s=S(t),n=S(e);if(null===this.precedingColumnCount){var i=s[1].trim();this.precedingColumnCount=i.match(/^\d*$/)?4:3}var r=g(s[0]),o=s[this.precedingColumnCount-2].trim(),a=s[this.precedingColumnCount-1].trim(),l=n[this.precedingColumnCount-2].trim(),u=this.readCompetitorSplitDataLine(t),h=this.readCompetitorSplitDataLine(e);D(u=u.map(f),h);var c=null;if(null!==o&&""!==o){for(var p=-1,d=0;d<this.precedingColumnCount;d+=1)p=t.indexOf("</font>",p+1);var m=C(t.substring(0,p+"</font>".length).replace(/<font[^>]*>(.*?)<\/font>/g,""));0<m.length&&(c=m[0])}return new L(o,l,c,a,u,r)};function I(){this.timesOffset=null}I.prototype.isTextOfThisFormat=function(t){for(var e=-1,s=0;s<5;s+=1)if(-1===(e=t.indexOf("<table",e+1)))return!1;return!0},I.prototype.preprocess=function(t){var e=t.indexOf("</table>");-1===e&&m("Could not find any closing </table> tags");var s=(t=t.substring(e+"</table>".length)).indexOf("</div>"),n=t.indexOf("<table");return-1<s&&s<n&&(t=t.substring(s+"</div>".length)),(t=(t=(t=(t=(t=(t=t.replace(/>\n+</g,"><").replace(/><tr>/g,">\n<tr>").replace(/<\/tr></g,"</tr>\n<").replace(/><table/g,">\n<table").replace(/<\/table></g,"</table>\n<")).replace(/<\/col[^>]*>/g,"")).replace(/<tr[^>]*><td[^>]*>(?:<nobr>)? ?(?:<\/nobr>)?<\/td><\/tr>/g,"")).replace(/<a id="[^"]*"><\/a>/g,"")).replace(/<div id="navigation">[\s\S]*?<\/div>/g,"")).replace("</body></html>","")).trim()},I.prototype.canIgnoreThisLine=function(t){if(-1<t.indexOf("<th>")){var e=function(t){return v(/<th[^>]*>(.*?)<\/th>/g,t).filter(function(t){return""!==t})}(t);return this.timesOffset=e.length,!0}return""===t||-1<t.indexOf("<table")||-1<t.indexOf("</table>")},I.prototype.isCourseHeaderLine=function(t){return-1<t.indexOf('<td id="header"')},I.prototype.parseCourseHeaderLine=function(t){var e=x(t);0===e.length&&m("No parts found in course header line");var s=e[0],n=s.indexOf("(");-1<n&&(s=s.substring(0,n)),s=s.trim();for(var i=null,r=null,o=1;o<e.length;o+=1)null===i&&(i=T(e[o])),null===r&&(r=w(e[o]));return{name:s,distance:i,climb:r}},I.prototype.parseControlsLine=function(t){return b(x(t))},I.prototype.readCompetitorSplitDataLine=function(t){for(var e=y(t),s=this.timesOffset,n=e.length;0<n&&""===e[n-1];)n-=1;return e.slice(s,n).filter(c)},I.prototype.parseCompetitor=function(t,e){var s=y(t),n=y(e),i=g(s[0]),r=3===this.timesOffset?1:2,o=s[r],a=s[this.timesOffset-1],l=n[r],u=5===this.timesOffset&&""!==o?s[3]:null,h=this.readCompetitorSplitDataLine(t),c=this.readCompetitorSplitDataLine(e);D(h=h.map(f),c);var p=h.filter(d).length;return p!==c.length&&m("Cumulative and split times do not have the same length: "+p+" cumulative times, "+c.length+" split times"),new L(o,l,u,a,h,i)};function N(){this.usesClasses=!1}function O(t,e,s){this.name=t,this.distance=e,this.climb=s,this.controls=[],this.competitors=[]}function B(t){this.recognizer=t,this.courses=[],this.currentCourse=null,this.lines=null,this.linePos=-1,this.currentCompetitor=null}N.prototype.isTextOfThisFormat=function(t){var e=t.indexOf("<table");if(0<=e){var s=t.indexOf("<table",e+1);if(0<=s)if(t.indexOf("<table",s+1)<0)return!0}return!1},N.prototype.preprocess=function(t){var e=t.indexOf("</table>");return-1===e&&m("Could not find any closing </table> tags"),0<=t.indexOf('<td colspan="25">')&&(this.usesClasses=!0),(t=(t=(t=(t=t.substring(e+"</table>".length)).replace(/<tr[^>]*><td colspan=[^>]*> <\/td><\/tr>/g,"")).replace(/\n{2,}/g,"\n")).replace("</body>","").replace("</html>","")).trim()},N.prototype.canIgnoreThisLine=function(t){return""===t||-1<t.indexOf("<table")||-1<t.indexOf("</table>")||-1<t.indexOf("<hr>")},N.prototype.isCourseHeaderLine=function(t){return-1<t.indexOf('<tr class="clubName"')},N.prototype.parseCourseHeaderLine=function(t){var e=x(t);0===e.length&&m("No parts found in course header line");var s,n,i,r=e[0],o=/^(.*?)\s+\((\d+)m,\s*(\d+)m\)$/.exec(r);return i=null===o?(s=r,n=null):(s=o[1],n=parseInt(o[2],10)/1e3,parseInt(o[3],10)),{name:s.trim(),distance:n,climb:i}},N.prototype.parseControlsLine=function(t){return x(t).map(function(t){var e=t.indexOf("-");return-1===e?null:t.substring(e+1)})},N.prototype.readCompetitorSplitDataLine=function(t){for(var e=this.usesClasses?5:4,s=t.length;0<s&&""===t[s-1];)s-=1;for(var n=[],i=e;i<s;i+=2){var r=t[i];c(r)&&n.push(r)}return n},N.prototype.parseCompetitor=function(t,e){for(var s=y(t),n=y(e),i=g(s[0]),r=s[2],o=s[this.usesClasses?4:3],a=this.usesClasses&&""!==r?s[3]:null,l=n[2],u=this.usesClasses?5:4;u<s.length&&u<n.length;u+=2)""!==s[u]&&""===n[u]&&(n[u]="----");var h=this.readCompetitorSplitDataLine(s),c=this.readCompetitorSplitDataLine(n);return D(h=h.map(f),c),h.length!==c.length&&m("Cumulative and split times do not have the same length: "+h.length+" cumulative times, "+c.length+" split times"),new L(r,l,a,o,h,i)},O.prototype.addControls=function(t){this.controls=this.controls.concat(t)},O.prototype.hasAllControls=function(){return 0<this.controls.length&&null===this.controls[this.controls.length-1]},O.prototype.addCompetitor=function(t){if(t.competitive||t.cumTimes.length!==this.controls.length-1||t.cumTimes.push(null),null===f(t.totalTime)&&0===t.cumTimes.length)for(;t.cumTimes.length<this.controls.length;)t.cumTimes.push(null);t.cumTimes.length===this.controls.length?this.competitors.push(t):m("Competitor '"+t.name+"' should have "+this.controls.length+" cumulative times, but has "+t.cumTimes.length+" times")},B.prototype.tryGetLine=function(){return this.linePos+1<this.lines.length?(this.linePos+=1,this.lines[this.linePos]):null},B.prototype.addCurrentCompetitorIfNecessary=function(){null!==this.currentCompetitor&&(this.currentCourse.addCompetitor(this.currentCompetitor),this.currentCompetitor=null)},B.prototype.addCurrentCompetitorAndCourseIfNecessary=function(){this.addCurrentCompetitorIfNecessary(),null!==this.currentCourse&&this.courses.push(this.currentCourse)},B.prototype.readCompetitorLines=function(t){var e=this.tryGetLine();null===e&&m("Hit end of input data unexpectedly while parsing competitor: first line was '"+t+"'");var s=this.recognizer.parseCompetitor(t,e);s.isContinuation()?null===this.currentCompetitor?m("First row of competitor data has no name nor time"):this.currentCompetitor.append(s):(this.addCurrentCompetitorIfNecessary(),this.currentCompetitor=s)},B.prototype.areClassesUniqueWithinCourses=function(){for(var t=d3.map(),e=0;e<this.courses.length;e+=1)for(var s=this.courses[e],n=0;n<s.competitors.length;n+=1){var i=s.competitors[n];if(t.has(i.className)){if(t.get(i.className)!==s.name)return!1}else t.set(i.className,s.name)}return!0},B.prototype.createOverallEventObject=function(){var s=this.areClassesUniqueWithinCourses(),t=[],a=[],n=this.courses.every(function(t){return t.competitors.every(function(t){return d(t.className)})});return this.courses.forEach(function(i){var r=d3.map();i.competitors.forEach(function(t){var e=n&&s?t.className:i.name;r.has(e)?r.get(e).push(t):r.set(e,[t])});var o=[];r.keys().forEach(function(t){var e=i.controls.length-1,s=r.get(t).map(function(t,e){return t.toCompetitor(e+1)}),n=new l(t,e,s);o.push(n),a.push(n)},this);var e=new u(i.name,o,i.distance,i.climb,i.controls.slice(0,i.controls.length-1));t.push(e),o.forEach(function(t){t.setCourse(e)})},this),new e(a,t,[])},B.prototype.parse=function(t){for(this.lines=t.split("\n");;){var e=this.tryGetLine();if(null===e)break;if(this.recognizer.canIgnoreThisLine(e));else if(this.recognizer.isCourseHeaderLine(e)){this.addCurrentCompetitorAndCourseIfNecessary();var s=this.recognizer.parseCourseHeaderLine(e);this.currentCourse=new O(s.name,s.distance,s.climb)}else if(null===this.currentCourse);else if(this.currentCourse.hasAllControls())this.readCompetitorLines(e);else{var n=this.recognizer.parseControlsLine(e);this.currentCourse.addControls(n)}}return this.addCurrentCompetitorAndCourseIfNecessary(),0===this.courses.length&&m("No competitor data was found"),this.createOverallEventObject()};var M=[t,I,N];SplitsBrowser.Input.Html={},SplitsBrowser.Input.Html.parseEventData=function(t){t=i(t);for(var e=0;e<M.length;e+=1){var s=new M[e];if(s.isTextOfThisFormat(t))return t=s.preprocess(t),new B(s).parse(t)}n("No HTML recognizers recognised this as HTML they could parse")}}(),function(){"use strict";var r=SplitsBrowser.throwWrongFileFormat,o=SplitsBrowser.normaliseLineEndings,p=SplitsBrowser.parseTime,u=SplitsBrowser.parseCourseLength,h=SplitsBrowser.parseCourseClimb,d=SplitsBrowser.Model.Competitor.fromOriginalCumTimes,a=SplitsBrowser.Model.CourseClass,n=SplitsBrowser.Model.Course,l=SplitsBrowser.Model.Event,e={controlsOffset:38,step:3,name:3,club:5,courseName:7,startTime:8,length:null,climb:null,placing:null,finishTime:null,allowMultipleCompetitorNames:!0},i=[",",";"],c=/^[A-Za-z0-9]+$/;function m(t){for(var e=t.length-1;0<=e&&""===t[e];)e-=1;t.splice(e+1,t.length-e-1)}function s(t){this.format=t,this.classes=d3.map(),this.delimiter=null,this.hasAnyStarters=!1,this.warnings=[],this.controlsTerminationOffset=null===t.finishTime?t.step:0}s.prototype.determineDelimiter=function(t){for(var e=0;e<i.length;e+=1){var s=i[e],n=t.split(s);if(m(n),n.length>this.format.controlsOffset)return s}return null},s.prototype.adjustLinePartsForMultipleCompetitors=function(t){if(this.format.allowMultipleCompetitorNames)for(;t.length>this.format.name+1&&t[this.format.name+1].match(/^\s\S/);)t[this.format.name]+=","+t[this.format.name+1],t.splice(this.format.name+1,1)},s.prototype.checkControlCodesAlphaNumeric=function(t){var e=t.split(this.delimiter);m(e),this.adjustLinePartsForMultipleCompetitors(e,this.format);for(var s=this.format.controlsOffset;s+this.controlsTerminationOffset<e.length;s+=this.format.step)c.test(e[s])||r("Data appears not to be in an alternative CSV format - data in cell "+s+" of the first row ('"+e[s]+"') is not an number")},s.prototype.addCompetitorToCourse=function(t,e,s){if(this.classes.has(e)){var n=this.classes.get(e),i=t.getAllOriginalCumulativeTimes();i.length-1!==n.controls.length+1?this.warnings.push("Competitor '"+t.name+"' has the wrong number of splits for course '"+e+"': expected "+(n.controls.length+1)+", actual "+(i.length-1)):n.competitors.push(t)}else{for(var r=[],o=this.format.controlsOffset;o+this.controlsTerminationOffset<s.length;o+=this.format.step)r.push(s[o]);var a=null===this.format.length?null:u(s[this.format.length]),l=null===this.format.climb?null:h(s[this.format.climb]);this.classes.set(e,{length:a,climb:l,controls:r,competitors:[t]})}},s.prototype.readDataRow=function(t){var e=t.split(this.delimiter);if(m(e),this.adjustLinePartsForMultipleCompetitors(e),!(e.length<this.format.controlsOffset)){for(;(e.length-this.format.controlsOffset)%this.format.step!=0;)e.push("");for(var s=e[this.format.name],n=e[this.format.club],i=e[this.format.courseName],r=p(e[this.format.startTime]),o=[0],a=this.format.controlsOffset+1;a<e.length;a+=this.format.step)o.push(p(e[a]));if(null!==this.format.finishTime){var l=p(e[this.format.finishTime]),u=null===r||null===l?null:l-r;o.push(u)}if(1!==o.length){var h=this.classes.has(i)?this.classes.get(i).competitors.length+1:1,c=d(h,s,n,r,o);if(null!==this.format.placing&&c.completed())e[this.format.placing].match(/^\d*$/)||c.setNonCompetitive();c.hasAnyTimes()?this.hasAnyStarters=!0:c.setNonStarter(),this.addCompetitorToCourse(c,i,e)}else""!==s&&this.warnings.push("Competitor '"+s+"' on course '"+(""===i?"(unnamed)":i)+"' has no times recorded")}},s.prototype.createClassesAndCourses=function(){var r=[],o=d3.map();this.classes.entries().forEach(function(t){var e=t.key,s=t.value,n=new a(e,s.controls.length,s.competitors);r.push(n);var i=s.controls.join(",");o.has(i)?o.get(i).classes.push(n):o.set(i,{name:e,classes:[n],length:s.length,climb:s.climb,controls:s.controls})});var s=[];return o.values().forEach(function(t){var e=new n(t.name,t.classes,t.length,t.climb,t.controls);t.classes.forEach(function(t){t.setCourse(e)}),s.push(e)}),{classes:r,courses:s}},s.prototype.parseEventData=function(t){this.warnings=[];var e=(t=o(t)).split(/\n/);e.length<2&&r("Data appears not to be in an alternative CSV format - too few lines");var s=e[1];this.delimiter=this.determineDelimiter(s),null===this.delimiter&&r("Data appears not to be in an alternative CSV format - first data line has fewer than "+this.format.controlsOffset+" parts when separated by any recognised delimiter"),this.checkControlCodesAlphaNumeric(s);for(var n=1;n<e.length;n+=1)this.readDataRow(e[n]);var i=this.createClassesAndCourses();return this.hasAnyStarters||r("Data appears not to be in an alternative CSV format - data apparently could be read but everyone was a non-starter"),new l(i.classes,i.courses,this.warnings)},SplitsBrowser.Input.AlternativeCSV={parseTripleColumnEventData:function(t){return new s(e).parseEventData(t)}}}(),function(){"use strict";var i=SplitsBrowser.throwInvalidData,h=SplitsBrowser.throwWrongFileFormat,c=SplitsBrowser.isNaNStrict,n=SplitsBrowser.parseTime,S=SplitsBrowser.Model.Competitor.fromOriginalCumTimes,p=SplitsBrowser.Model.CourseClass,d=SplitsBrowser.Model.Course,m=SplitsBrowser.Model.Event;function l(t){return void 0===t}var y=/^\d{4}/,t={isOfThisVersion:function(t){return 0<=t.indexOf("IOFdata.dtd")},checkVersion:function(t){var e=$("> IOFVersion",t);if(0===e.length)h("Could not find IOFVersion element");else{var s=e.attr("version");l(s)?h("Version attribute missing from IOFVersion element"):"2.0.3"!==s&&h("Found unrecognised IOF XML data format '"+s+"'")}var n=t.attr("status");l(n)||"complete"===n.toLowerCase()||i("Only complete IOF data supported; snapshot and delta are not supported")},readClassName:function(t){return $("> ClassShortName",t).text()},readCourseFromClass:function(t,e){var s=$("> ClassShortName",t).text(),n=$("> PersonResult > Result",t).first(),i=null;if(0<n.length){var r=$("> CourseLength",n),o=r.text();if(0<o.length)if(i=parseFloat(o),isFinite(i)){var a=r.attr("unit");l(a)||"m"===a?i/=1e3:"km"===a||("ft"===a?i/=3280:(e.push("Course '"+s+"' gives its length in a unit '"+a+"', but this unit was not recognised"),i=null))}else e.push("Course '"+s+"' specifies a course length that was not understood: '"+o+"'"),i=null}return{id:null,name:s,length:i,climb:null,numberOfControls:null}},getCompetitorNameElement:function(t){return $("> Person > PersonName",t)},readClubName:function(t){return $("> Club > ShortName",t).text()},readDateOfBirth:function(t){return $("> Person > BirthDate > Date",t).text()},readStartTime:function(t){var e=$("> StartTime > Clock",t).text();return""===e?null:n(e)},readTotalTime:function(t){var e=$("> Time",t).text();return""===e?null:n(e)},getStatus:function(t){var e=$("> CompetitorStatus",t);return 1===e.length?e.attr("value"):""},StatusNonCompetitive:"NotCompeting",StatusNonStarter:"DidNotStart",StatusNonFinisher:"DidNotFinish",StatusDisqualified:"Disqualified",StatusOverMaxTime:"OverTime",isAdditional:function(){return!1},readSplitTime:function(t){var e=$("> ControlCode",t).text();""===e&&(e=$("> Control > ControlCode",t).text()),""===e&&i("Control code missing for control");var s=$("> Time",t).text();return{code:e,time:""===s?null:n(s)}}},r=/^\d\d\d\d-?\d\d-?\d\dT?(\d\d):?(\d\d)(?::?(\d\d))?/,o={isOfThisVersion:function(t){return 0<=t.indexOf("http://www.orienteering.org/datastandard/3.0")},checkVersion:function(t){var e=t.attr("iofVersion");l(e)?h("Could not find IOF version number"):"3.0"!==e&&h("Found unrecognised IOF XML data format '"+e+"'");var s=t.attr("status");l(s)||"complete"===s.toLowerCase()||i("Only complete IOF data supported; snapshot and delta are not supported")},readClassName:function(t){return $("> Class > Name",t).text()},readCourseFromClass:function(t,e){var s,n=$("> Course",t),i=$("> Id",n).text()||null,r=$("> Name",n).text(),o=$("> Length",n).text();""===o?s=null:(s=parseInt(o,10),c(s)?(e.push("Course '"+r+"' specifies a course length that was not understood: '"+o+"'"),s=null):s/=1e3);var a=$("> NumberOfControls",n).text(),l=parseInt(a,10);c(l)&&(l=null);var u=$("> Climb",n).text(),h=parseInt(u,10);return c(h)&&(h=null),{id:i,name:r,length:s,climb:h,numberOfControls:l}},getCompetitorNameElement:function(t){return $("> Person > Name",t)},readClubName:function(t){return $("> Organisation > ShortName",t).text()},readDateOfBirth:function(t){var e=$("> Person > BirthDate",t).text(),s=y.exec(e);return null===s?null:parseInt(s[0],10)},readStartTime:function(t){var e=$("> StartTime",t).text(),s=r.exec(e);return null===s?null:60*parseInt(s[1],10)*60+60*parseInt(s[2],10)+(l(s[3])?0:parseInt(s[3],10))},readTime:function(t){var e=parseFloat(t);return isFinite(e)?e:null},readTotalTime:function(t){var e=$("> Time",t).text();return o.readTime(e)},getStatus:function(t){return $("> Status",t).text()},StatusNonCompetitive:"NotCompeting",StatusNonStarter:"DidNotStart",StatusNonFinisher:"DidNotFinish",StatusDisqualified:"Disqualified",StatusOverMaxTime:"OverTime",isAdditional:function(t){return"Additional"===t.attr("status")},readSplitTime:function(t){var e,s=$("> ControlCode",t).text();if(""===s&&i("Control code missing for control"),"Missing"===t.attr("status"))e=null;else{var n=$("> Time",t).text();e=""===n?null:o.readTime(n)}return{code:s,time:e}}},f=[t,o];function g(t,e,s,n){var i=$(t),r=function(t){var e=$("> Given",t).text(),s=$("> Family",t).text();return""===e?s:""===s?e:e+" "+s}(s.getCompetitorNameElement(i));if(""===r)return n.push("Could not find a name for a competitor"),null;var o=s.readClubName(i),a=s.readDateOfBirth(i),l=y.exec(a),u=null===l?null:parseInt(l[0],10),h=$("> Person",i).attr("sex"),c=$("Result",i);if(0===c.length)return n.push("Could not find any result information for competitor '"+r+"'"),null;var p=s.readStartTime(c),d=s.readTotalTime(c),m=$("> SplitTime",c).toArray().filter(function(t){return!s.isAdditional($(t))}).map(function(t){return s.readSplitTime($(t))}),f=m.map(function(t){return t.code}),g=m.map(function(t){return t.time});g.unshift(0),g.push(d);var C=S(e,r,o,p,g);null!==u&&C.setYearOfBirth(u),"M"!==h&&"F"!==h||C.setGender(h);var v=s.getStatus(c);return v===s.StatusNonCompetitive?C.setNonCompetitive():v===s.StatusNonStarter?C.setNonStarter():v===s.StatusNonFinisher?C.setNonFinisher():v===s.StatusDisqualified?C.disqualify():v===s.StatusOverMaxTime&&C.setOverMaxTime(),{competitor:C,controls:f}}SplitsBrowser.Input.IOFXml={parseEventData:function(t){var r=function(t){for(var e=0;e<f.length;e+=1){var s=f[e];if(s.isOfThisVersion(t))return s}h("Data apparently not of any recognised IOF XML format")}(t),e=function(t){var e;try{e=$.parseXML(t)}catch(t){i("XML data not well-formed")}return 0===$("> *",$(e)).length&&i("XML data not well-formed: "+t),e}(t);!function(t,e){var s=$("> *",t),n=s.prop("tagName");"ResultList"!==n&&h("Root element of XML document does not have expected name 'ResultList', got '"+n+"'"),e.checkVersion(s)}(e,r);var s=$("> ResultList > ClassResult",$(e)).toArray();0===s.length&&i("No class result elements found");var o=[],a=[],l=d3.map(),u=[];s.forEach(function(t){var e=function(t,e,s){var n=$(t),i={name:null,competitors:[],controls:[],course:null};i.course=e.readCourseFromClass(n,s);var r=e.readClassName(n);""===r&&(r="<unnamed class>"),i.name=r;var o=$("> PersonResult",n);if(0===o.length)return s.push("Class '"+r+"' has no competitors"),null;for(var a=0;a<o.length;a+=1){var l=g(o[a],a+1,e,s);if(null!==l){var u=l.competitor,h=l.controls;0!==i.competitors.length||u.isNonStarter&&0===h.length||(i.controls=h,null===i.course.numberOfControls&&(i.course.numberOfControls=i.controls.length));var c=u.getAllOriginalCumulativeTimes().length-2,p=null;if(u.isNonStarter&&0==c);else if(c!==i.course.numberOfControls)p="Competitor '"+u.name+"' in class '"+r+"' has an unexpected number of controls: expected "+i.course.numberOfControls+", actual "+c;else for(var d=0;d<c;d+=1)if(i.controls[d]!==h[d]){p="Competitor '"+u.name+"' has an unexpected control code at control "+(d+1)+": expected '"+i.controls[d]+"', actual '"+h[d]+"'";break}null===p?i.competitors.push(u):s.push(p)}}return null===i.course.id&&0<i.controls.length&&(i.course.id=i.controls.join(",")),i}(t,r,u);if(null!==e){var s=new p(e.name,e.controls.length,e.competitors);o.push(s);var n=e.course,i=n.id+","+e.controls.join(",");null!==n.id&&l.has(i)?l.get(i).classes.push(s):(n.classes=[s],n.controls=e.controls,a.push(n),null!==n.id&&l.set(i,n))}});var n=a.map(function(t){var e=new d(t.name,t.classes,t.length,t.climb,t.controls);return t.classes.forEach(function(t){t.setCourse(e)}),e});return new m(o,n,u)}}}(),function(){"use strict";var n=[SplitsBrowser.Input.CSV.parseEventData,SplitsBrowser.Input.OE.parseEventData,SplitsBrowser.Input.Html.parseEventData,SplitsBrowser.Input.AlternativeCSV.parseTripleColumnEventData,SplitsBrowser.Input.IOFXml.parseEventData];SplitsBrowser.Input.parseEventData=function(t){for(var e=0;e<n.length;e+=1){var s=n[e];try{return s(t)}catch(t){if("WrongFileFormat"!==t.name)throw t}}return null}}(),function(){"use strict";function t(t,e){this.parent=t,this.alerter=e,this.handler=null,this.competitorSelection=null,this.lastFilterString="",this.allCompetitors=[],this.allCompetitorDetails=[],this.dragging=!1,this.dragStartCompetitorIndex=null,this.currentDragCompetitorIndex=null,this.allCompetitorDivs=[],this.inverted=!1,this.placeholderDiv=null,this.changeHandlers=[],this.containerDiv=d3.select(t).append("div").attr("id","competitorListContainer"),this.buttonsPanel=this.containerDiv.append("div");var s=this;this.allButton=this.buttonsPanel.append("button").attr("id","selectAllCompetitors").style("width","50%").on("click",function(){s.selectAllFiltered()}),this.noneButton=this.buttonsPanel.append("button").attr("id","selectNoCompetitors").style("width","50%").on("click",function(){s.selectNoneFiltered()}),$(this.noneButton.node()).dblclick(function(){s.selectNone()}),this.buttonsPanel.append("br"),this.crossingRunnersButton=this.buttonsPanel.append("button").attr("id","selectCrossingRunners").style("width","100%").on("click",function(){s.selectCrossingRunners()}).style("display","none"),this.filter=this.buttonsPanel.append("input").attr("type","text"),this.filter.on("input",function(){s.updateFilterIfChanged()}).on("keyup",function(){s.updateFilterIfChangedDelayed()}).on("mouseup",function(){s.updateFilterIfChangedDelayed()}),this.listDiv=this.containerDiv.append("div").attr("id","competitorList"),this.listDiv.on("mousedown",function(){s.startDrag(-1)}).on("mousemove",function(){s.mouseMove(-1)}).on("mouseup",function(){s.stopDrag()}),d3.select(document.body).on("mouseup",function(){s.stopDrag()}),this.setMessages()}var i=SplitsBrowser.getMessage,s=SplitsBrowser.getMessageWithFormatting;function r(t){return t.toLowerCase().replace(/\W/g,"")}function o(t){return t.completed()?""===t.name?"\xa0":t.name:"* "+t.name}t.prototype.setMessages=function(){this.allButton.text(i("SelectAllCompetitors")),this.noneButton.text(i("SelectNoCompetitors")),this.crossingRunnersButton.text(i("SelectCrossingRunners")),this.filter.attr("placeholder",i("CompetitorListFilter"))},t.prototype.retranslate=function(){this.setMessages(),null!==this.placeholderDiv&&(this.placeholderDiv.text(i("NoCompetitorsStarted")),this.fireChangeHandlers())},t.prototype.registerChangeHandler=function(t){-1===this.changeHandlers.indexOf(t)&&this.changeHandlers.push(t)},t.prototype.deregisterChangeHandler=function(t){var e=this.changeHandlers.indexOf(t);-1<e&&this.changeHandlers.splice(e,1)},t.prototype.fireChangeHandlers=function(){this.changeHandlers.forEach(function(t){t()},this)},t.prototype.isMouseOffBottomOfCompetitorList=function(){return null===this.lastVisibleDiv||d3.mouse(this.lastVisibleDiv)[1]>=$(this.lastVisibleDiv).height()},t.prototype.getDragClassName=function(){return this.inverted?"dragDeselected":"dragSelected"},t.prototype.startDrag=function(t){if(1===d3.event.which){this.dragStartCompetitorIndex=t,this.currentDragCompetitorIndex=t,this.allCompetitorDivs=$("div.competitor");var e=this.allCompetitorDivs.filter(":visible");if(this.lastVisibleDiv=0===e.length?null:e[e.length-1],this.inverted=d3.event.shiftKey,-1===t){if(!this.isMouseOffBottomOfCompetitorList())return}else d3.select(this.allCompetitorDivs[t]).classed(this.getDragClassName(),!0);d3.event.stopPropagation(),this.dragging=!0}},t.prototype.mouseMove=function(t){if(this.dragging&&(d3.event.stopPropagation(),t!==this.currentDragCompetitorIndex)){var e,s,n=this.getDragClassName();if(d3.selectAll("div.competitor."+n).classed(n,!1),-1===this.dragStartCompetitorIndex&&-1===t)return;if(-1===t&&!this.isMouseOffBottomOfCompetitorList())return;s=-1===this.dragStartCompetitorIndex||-1===t?(e=this.dragStartCompetitorIndex+t- -1,this.allCompetitorDivs.length-1):(e=Math.min(this.dragStartCompetitorIndex,t),Math.max(this.dragStartCompetitorIndex,t));for(var i=[],r=e;r<=s;r+=1)this.allCompetitorDetails[r].visible&&i.push(this.allCompetitorDivs[r]);d3.selectAll(i).classed(n,!0),this.currentDragCompetitorIndex=t}},t.prototype.stopDrag=function(){if(this.dragging){this.dragging=!1;for(var t=[],e=this.getDragClassName(),s=0;s<this.allCompetitorDivs.length;s+=1)$(this.allCompetitorDivs[s]).hasClass(e)&&t.push(s);d3.selectAll("div.competitor."+e).classed(e,!1),d3.event.currentTarget===document||-1===this.currentDragCompetitorIndex&&!this.isMouseOffBottomOfCompetitorList()||(1===t.length?this.toggleCompetitor(t[0]):this.inverted?this.competitorSelection.bulkDeselect(t):this.competitorSelection.bulkSelect(t)),this.dragStartCompetitorIndex=null,this.currentDragCompetitorIndex=null,d3.event.stopPropagation()}},t.prototype.width=function(){return $(this.containerDiv.node()).width()},t.prototype.setHeight=function(t){$(this.listDiv.node()).height(t-$(this.buttonsPanel.node()).height())},t.prototype.getAllVisibleIndexes=function(){return d3.range(this.allCompetitorDetails.length).filter(function(t){return this.allCompetitorDetails[t].visible},this)},t.prototype.selectAllFiltered=function(){this.competitorSelection.bulkSelect(this.getAllVisibleIndexes())},
t.prototype.selectNoneFiltered=function(){this.competitorSelection.bulkDeselect(this.getAllVisibleIndexes())},t.prototype.selectNone=function(){this.competitorSelection.selectNone()},t.prototype.isSelected=function(t){return null!==this.competitorSelection&&this.competitorSelection.isSelected(t)},t.prototype.selectCrossingRunners=function(){if(this.competitorSelection.selectCrossingRunners(this.allCompetitorDetails),this.competitorSelection.isSingleRunnerSelected()){var t=this.allCompetitors[this.competitorSelection.getSingleRunnerIndex()].name,e=0<this.lastFilterString.length?"RaceGraphNoCrossingRunnersFiltered":"RaceGraphNoCrossingRunners";this.alerter(s(e,{$$NAME$$:t}))}},t.prototype.enableOrDisableCrossingRunnersButton=function(){this.crossingRunnersButton.node().disabled=!this.competitorSelection.isSingleRunnerSelected()},t.prototype.setChartType=function(t){this.crossingRunnersButton.style("display",t.isRaceGraph?"block":"none")},t.prototype.selectionChanged=function(){var s=this;this.listDiv.selectAll("div.competitor").data(d3.range(this.competitorSelection.count)).classed("selected",function(t,e){return s.isSelected(e)})},t.prototype.toggleCompetitor=function(t){this.competitorSelection.toggle(t)},t.prototype.setCompetitorList=function(t,e){this.allCompetitors=t,this.allCompetitorDetails=this.allCompetitors.map(function(t){return{competitor:t,normedName:r(t.name),visible:!0}}),null!==this.placeholderDiv&&(this.placeholderDiv.remove(),this.placeholderDiv=null);var s=this.listDiv.selectAll("div.competitor").data(this.allCompetitors),n=this;s.enter().append("div").classed("competitor",!0).classed("selected",function(t,e){return n.isSelected(e)}),s.selectAll("span").remove(),s=this.listDiv.selectAll("div.competitor").data(this.allCompetitors),e&&s.append("span").classed("competitorClassLabel",!0).text(function(t){return t.className}),s.append("span").classed("nonfinisher",function(t){return!t.completed()}).text(o),s.exit().remove(),0===this.allCompetitors.length&&(this.placeholderDiv=this.listDiv.append("div").classed("competitorListPlaceholder",!0).text(i("NoCompetitorsStarted"))),this.allButton.property("disabled",0===this.allCompetitors.length),this.noneButton.property("disabled",0===this.allCompetitors.length),this.filter.property("disabled",0===this.allCompetitors.length),s.on("mousedown",function(t,e){n.startDrag(e)}).on("mousemove",function(t,e){n.mouseMove(e)}).on("mouseup",function(){n.stopDrag()}),this.updateFilter()},t.prototype.setSelection=function(t){null!==this.competitorSelection&&this.competitorSelection.deregisterChangeHandler(this.handler);var e=this;this.competitorSelection=t,this.handler=function(){e.selectionChanged()},this.competitorSelection.registerChangeHandler(this.handler),this.selectionChanged()},t.prototype.getFilterText=function(){return this.filter.node().value},t.prototype.setFilterText=function(t){this.filter.node().value=t,this.updateFilterIfChanged()},t.prototype.updateFilter=function(){var e=r(this.filter.node().value);this.allCompetitorDetails.forEach(function(t){t.visible=0<=t.normedName.indexOf(e)});var s=this;this.listDiv.selectAll("div.competitor").style("display",function(t,e){return s.allCompetitorDetails[e].visible?null:"none"})},t.prototype.updateFilterIfChanged=function(){var t=this.getFilterText();t!==this.lastFilterString&&(this.updateFilter(),this.lastFilterString=t,this.fireChangeHandlers())},t.prototype.updateFilterIfChangedDelayed=function(){var t=this;setTimeout(function(){t.updateFilterIfChanged()},1)},SplitsBrowser.Controls.CompetitorList=t}(),function(){"use strict";var t=SplitsBrowser.getMessage,i=SplitsBrowser.getAllLanguages,r=SplitsBrowser.getLanguage,o=SplitsBrowser.getLanguageName,e=SplitsBrowser.setLanguage;function s(t){if(this.changeHandlers=[],this.label=null,this.dropDown=null,this.allLanguages=i(),!(this.allLanguages.length<2)){d3.select(t).append("div").classed("topRowStartSpacer",!0);var e=d3.select(t).append("div").classed("topRowStart",!0);this.label=e.append("span");var s=this;this.dropDown=e.append("select").node(),$(this.dropDown).bind("change",function(){s.onLanguageChanged()});var n=d3.select(this.dropDown).selectAll("option").data(this.allLanguages);n.enter().append("option"),(n=d3.select(this.dropDown).selectAll("option").data(this.allLanguages)).attr("value",function(t){return t}).text(function(t){return o(t)}),n.exit().remove(),this.setLanguage(r()),this.setMessages()}}s.prototype.setMessages=function(){this.label.text(t("LanguageSelectorLabel"))},s.prototype.registerChangeHandler=function(t){-1===this.changeHandlers.indexOf(t)&&this.changeHandlers.push(t)},s.prototype.setLanguage=function(t){var e=this.allLanguages.indexOf(t);0<=e&&(this.dropDown.selectedIndex=e,this.onLanguageChanged())},s.prototype.onLanguageChanged=function(){e(this.dropDown.options[this.dropDown.selectedIndex].value),this.changeHandlers.forEach(function(t){t()})},SplitsBrowser.Controls.LanguageSelector=s}(),function(){"use strict";var n=SplitsBrowser.throwInvalidData,i=SplitsBrowser.getMessage;function t(t){this.changeHandlers=[],this.otherClassesEnabled=!0;var e=d3.select(t).append("div").classed("topRowStart",!0);this.labelSpan=e.append("span");var n=this;this.dropDown=e.append("select").node(),$(this.dropDown).bind("change",function(){n.updateOtherClasses(d3.set()),n.onSelectionChanged()}),this.otherClassesContainer=d3.select(t).append("div").attr("id","otherClassesContainer").classed("topRowStart",!0).style("display","none"),this.otherClassesCombiningLabel=this.otherClassesContainer.append("span").classed("otherClassCombining",!0),this.otherClassesSelector=this.otherClassesContainer.append("div").classed("otherClassSelector",!0).style("display","inline-block"),this.otherClassesSpan=this.otherClassesSelector.append("span"),this.otherClassesList=d3.select(t).append("div").classed("otherClassList",!0).classed("transient",!0).style("position","absolute").style("display","none"),this.otherClassesSelector.on("click",function(){n.showHideClassSelector()}),this.setClasses([]),this.selectedOtherClassIndexes=d3.set(),$(document).click(function(t){var e=n.otherClassesList.node();if("none"!==e.style.display){var s=$("div.otherClassList,div.otherClassSelector");s.is(t.target)||0!==s.has(t.target).length||(e.style.display="none")}}),this.setMessages()}t.prototype.setMessages=function(){this.labelSpan.text(i("ClassSelectorLabel")),this.otherClassesCombiningLabel.text(i("AdditionalClassSelectorLabel"))},t.prototype.setOtherClassesEnabled=function(t){this.otherClassesCombiningLabel.classed("disabled",!t),this.otherClassesSelector.classed("disabled",!t),this.otherClassesEnabled=t},t.prototype.setClasses=function(t){if($.isArray(t)){var e;e=0===(this.classes=t).length?(this.dropDown.disabled=!0,[i("NoClassesLoadedPlaceholder")]):(this.dropDown.disabled=!1,t.map(function(t){return t.name}));var s=d3.select(this.dropDown).selectAll("option").data(e);s.enter().append("option"),(s=d3.select(this.dropDown).selectAll("option").data(e)).attr("value",function(t,e){return e.toString()}).text(function(t){return t}),s.exit().remove(),this.updateOtherClasses(d3.set())}else n("ClassSelector.setClasses: classes is not an array")},t.prototype.registerChangeHandler=function(t){-1===this.changeHandlers.indexOf(t)&&this.changeHandlers.push(t)},t.prototype.selectClasses=function(t){0<t.length&&t.every(function(t){return 0<=t&&t<this.dropDown.options.length},this)&&(this.dropDown.selectedIndex=t[0],this.updateOtherClasses(d3.set(t.slice(1))),this.onSelectionChanged())},t.prototype.getSelectedClasses=function(){if(this.dropDown.disabled)return[];var e=[this.dropDown.selectedIndex];return this.selectedOtherClassIndexes.each(function(t){e.push(parseInt(t,10))}),e},t.prototype.onSelectionChanged=function(){var e=this.getSelectedClasses();this.changeHandlers.forEach(function(t){t(e)})},t.prototype.updateOtherClassText=function(){var t,e=this.selectedOtherClassIndexes.values();e.sort(d3.ascending),t=0===e.length?i("NoAdditionalClassesSelectedPlaceholder"):e.map(function(t){return this.classes[t].name},this).join(", "),this.otherClassesSpan.text(t)},t.prototype.updateOtherClasses=function(e){this.otherClassesList.style("display","none"),this.selectedOtherClassIndexes=e,this.updateOtherClassText(),$("div.otherClassItem").off("click");var t,s=this;if(0<this.classes.length){var n=this.classes[this.dropDown.selectedIndex];t=n.course.getOtherClasses(n)}else t=[];var i=t.map(function(t){return this.classes.indexOf(t)},this),r=this.otherClassesList.selectAll("div").data(i);r.enter().append("div").classed("otherClassItem",!0),(r=this.otherClassesList.selectAll("div").data(i)).attr("id",function(t){return"courseClassIdx_"+t}).classed("selected",function(t){return e.has(t)}).text(function(t){return s.classes[t].name}),r.exit().remove(),0<i.length?this.otherClassesContainer.style("display",null):this.otherClassesContainer.style("display","none");var o=$(this.otherClassesSelector.node()).offset(),a=$(this.otherClassesSelector.node()).outerHeight();this.otherClassesList.style("left",o.left+"px").style("top",o.top+a+"px"),$("div.otherClassItem").each(function(t,e){$(e).on("click",function(){s.toggleOtherClass(i[t])})})},t.prototype.showHideClassSelector=function(){this.otherClassesEnabled&&this.otherClassesList.style("display","none"===this.otherClassesList.style("display")?null:"none")},t.prototype.toggleOtherClass=function(t){this.selectedOtherClassIndexes.has(t)?this.selectedOtherClassIndexes.remove(t):this.selectedOtherClassIndexes.add(t),d3.select("div#courseClassIdx_"+t).classed("selected",this.selectedOtherClassIndexes.has(t)),this.updateOtherClassText(),this.onSelectionChanged()},t.prototype.retranslate=function(){this.setMessages(),0===this.classes.length&&d3.select(this.dropDown.options[0]).text(i("NoClassesLoadedPlaceholder")),0===this.selectedOtherClassIndexes.values().length&&this.otherClassesSpan.text(i("NoAdditionalClassesSelectedPlaceholder"))},SplitsBrowser.Controls.ClassSelector=t}(),function(){"use strict";var s=SplitsBrowser.getMessage,n=SplitsBrowser.getMessageWithFormatting,o=[{nameKey:"CompareWithWinner",selector:function(t){return t.getWinnerCumTimes()},requiresWinner:!0,percentage:""},{nameKey:"CompareWithFastestTime",selector:function(t){return t.getFastestCumTimes()},requiresWinner:!1,percentage:""}];[5,25,50,100].forEach(function(e){o.push({nameKey:"CompareWithFastestTimePlusPercentage",selector:function(t){return t.getFastestCumTimesPlusPercentage(e)},requiresWinner:!1,percentage:e})}),o.push({nameKey:"CompareWithAnyRunner",selector:null,requiresWinner:!0,percentage:""});function t(t,e){this.changeHandlers=[],this.classes=null,this.currentRunnerIndex=null,this.previousCompetitorList=null,this.parent=t,this.alerter=e,this.hasWinner=!1,this.previousSelectedIndex=-1;var s=d3.select(t).append("div").classed("topRowStart",!0);this.comparisonSelectorLabel=s.append("span").classed("comparisonSelectorLabel",!0);var n=this;this.dropDown=s.append("select").attr("id","comparisonSelector").node(),$(this.dropDown).bind("change",function(){n.onSelectionChanged()}),this.optionsList=d3.select(this.dropDown).selectAll("option").data(o),this.optionsList.enter().append("option"),this.optionsList=d3.select(this.dropDown).selectAll("option").data(o),this.optionsList.attr("value",function(t,e){return e.toString()}),this.optionsList.exit().remove(),this.runnerDiv=d3.select(t).append("div").classed("topRowStart",!0).style("display","none").style("padding-left","20px"),this.runnerSpan=this.runnerDiv.append("span").classed("comparisonSelectorLabel",!0),this.runnerDropDown=this.runnerDiv.append("select").attr("id","runnerSelector").node(),$(this.runnerDropDown).bind("change",function(){n.onSelectionChanged()}),this.dropDown.selectedIndex=1,this.previousSelectedIndex=1,this.setMessages()}t.prototype.setMessages=function(){this.comparisonSelectorLabel.text(s("ComparisonSelectorLabel")),this.runnerSpan.text(s("CompareWithAnyRunnerLabel")),this.optionsList.text(function(t){return n(t.nameKey,{$$PERCENT$$:t.percentage})})},t.prototype.registerChangeHandler=function(t){-1===this.changeHandlers.indexOf(t)&&this.changeHandlers.push(t)},t.prototype.isAnyRunnerSelected=function(){return this.dropDown.selectedIndex===o.length-1},t.prototype.setCourseClassSet=function(t){this.courseClassSet=t,this.setRunners()},t.prototype.setRunners=function(){var e=this.courseClassSet.allCompetitors,s=d3.range(e.length).filter(function(t){return e[t].completed()}),t=e.filter(function(t){return t.completed()});this.hasWinner=0<t.length;var n=d3.select(this.runnerDropDown).selectAll("option").data(t);if(n.enter().append("option"),(n=d3.select(this.runnerDropDown).selectAll("option").data(t)).attr("value",function(t,e){return s[e].toString()}).text(function(t){return t.name}),n.exit().remove(),null===this.previousCompetitorList)this.currentRunnerIndex=0;else if(this.hasWinner){var i=this.previousCompetitorList[this.currentRunnerIndex],r=this.courseClassSet.allCompetitors.indexOf(i);this.currentRunnerIndex=Math.max(r,0)}else o[this.dropDown.selectedIndex].requiresWinner&&this.setComparisonType(1,null);this.runnerDropDown.selectedIndex=this.currentRunnerIndex,this.previousCompetitorList=this.courseClassSet.allCompetitors},t.prototype.setEnabled=function(t){d3.select(this.parent).selectAll("span.comparisonSelectorLabel").classed("disabled",!t),this.dropDown.disabled=!t,this.runnerDropDown.disabled=!t},t.prototype.getComparisonFunction=function(){if(this.isAnyRunnerSelected()){var e=this;return function(t){return t.getCumulativeTimesForCompetitor(e.currentRunnerIndex)}}return o[this.dropDown.selectedIndex].selector},t.prototype.getComparisonType=function(){var t=this.dropDown.selectedIndex;return{index:t,runner:t===o.length-1?(this.runnerDropDown.selectedIndex<0&&(this.runnerDropDown.selectedIndex=0),this.courseClassSet.allCompetitors[this.runnerDropDown.selectedIndex]):null}},t.prototype.setComparisonType=function(t,e){if(0<=t&&t<o.length)if(t===o.length-1){var s=this.courseClassSet.allCompetitors.indexOf(e);0<=s&&(this.dropDown.selectedIndex=t,this.runnerDropDown.selectedIndex=s,this.onSelectionChanged())}else this.dropDown.selectedIndex=t,this.onSelectionChanged()},t.prototype.onSelectionChanged=function(){var t=Math.max(this.runnerDropDown.selectedIndex,0),e=o[this.dropDown.selectedIndex];!this.hasWinner&&e.requiresWinner?(this.alerter(n("CannotCompareAsNoWinner",{$$OPTION$$:s(e.nameKey)})),this.dropDown.selectedIndex=this.previousSelectedIndex):(this.runnerDiv.style("display",this.isAnyRunnerSelected()?null:"none"),this.currentRunnerIndex=0===this.runnerDropDown.options.length?0:parseInt(this.runnerDropDown.options[t].value,10),this.previousSelectedIndex=this.dropDown.selectedIndex,this.changeHandlers.forEach(function(t){t(this.getComparisonFunction())},this))},SplitsBrowser.Controls.ComparisonSelector=t}(),function(){"use strict";var s=SplitsBrowser.getMessage,n="statisticCheckbox",i=["TotalTime","SplitTime","BehindFastest","TimeLoss"],r=["StatisticsTotalTime","StatisticsSplitTime","StatisticsBehindFastest","StatisticsTimeLoss"],o=["SplitTime","TimeLoss"];function t(t){this.div=d3.select(t).append("div").classed("topRowEnd",!0).attr("id","statisticSelector");var e=this.div.selectAll("div").data(i).enter().append("div").style("display","inline-block");e.append("input").attr("id",function(t){return n+t}).attr("type","checkbox").attr("checked",function(t){return 0<=o.indexOf(t)?"checked":null}),this.statisticLabels=e.append("label").attr("for",function(t){return n+t}).classed("statisticsSelectorLabel",!0);var s=this;$("input",this.div.node()).bind("change",function(){return s.onCheckboxChanged()}),this.handlers=[],this.setMessages()}t.prototype.setMessages=function(){this.statisticLabels.text(function(t,e){return s(r[e])})},t.prototype.clearAll=function(){this.div.selectAll("input").attr("checked",null)},t.prototype.setEnabled=function(t){this.div.selectAll("label.statisticsSelectorLabel").classed("disabled",!t),this.div.selectAll("input").attr("disabled",t?null:"disabled")},t.prototype.registerChangeHandler=function(t){-1===this.handlers.indexOf(t)&&this.handlers.push(t)},t.prototype.deregisterChangeHandler=function(t){var e=this.handlers.indexOf(t);-1!==e&&this.handlers.splice(e,1)},t.prototype.getVisibleStatistics=function(){var s={};return this.div.selectAll("input").nodes().forEach(function(t,e){s[i[e]]=t.checked}),s},t.prototype.setVisibleStatistics=function(s){this.div.selectAll("input").nodes().forEach(function(t,e){t.checked=s[i[e]]||!1}),this.onCheckboxChanged()},t.prototype.onCheckboxChanged=function(){var e=this.getVisibleStatistics();this.handlers.forEach(function(t){t(e)})},SplitsBrowser.Controls.StatisticsSelector=t}(),function(){"use strict";var e=SplitsBrowser.getMessage;function t(t,e){this.changeHandlers=[],this.chartTypes=e,this.raceGraphDisabledNotifier=null,this.lastSelectedIndex=0;var s=d3.select(t).append("div").classed("topRowStart",!0);this.labelSpan=s.append("span");var n=this;this.dropDown=s.append("select").node(),$(this.dropDown).bind("change",function(){n.onSelectionChanged()}),this.optionsList=d3.select(this.dropDown).selectAll("option").data(e),this.optionsList.enter().append("option"),this.optionsList=d3.select(this.dropDown).selectAll("option").data(e),this.optionsList.attr("value",function(t,e){return e.toString()}),this.optionsList.exit().remove(),this.setMessages()}t.prototype.setMessages=function(){this.labelSpan.text(e("ChartTypeSelectorLabel")),this.optionsList.text(function(t){return e(t.nameKey)})},t.prototype.setRaceGraphDisabledNotifier=function(t){this.raceGraphDisabledNotifier=t,null!==this.raceGraphDisabledNotifier&&this.chartTypes[this.dropDown.selectedIndex].isRaceGraph&&(this.raceGraphDisabledNotifier(),this.dropDown.selectedIndex=0,this.onSelectionChanged())},t.prototype.registerChangeHandler=function(t){-1===this.changeHandlers.indexOf(t)&&this.changeHandlers.push(t)},t.prototype.getChartType=function(){return this.chartTypes[Math.max(this.dropDown.selectedIndex,0)]},t.prototype.setChartType=function(t){var e=this.chartTypes.indexOf(t);0<=e&&(this.dropDown.selectedIndex=e,this.onSelectionChanged())},t.prototype.onSelectionChanged=function(){null!==this.raceGraphDisabledNotifier&&this.chartTypes[this.dropDown.selectedIndex].isRaceGraph&&(this.raceGraphDisabledNotifier(),this.dropDown.selectedIndex=Math.max(this.lastSelectedIndex,0)),this.changeHandlers.forEach(function(t){t(this.chartTypes[this.dropDown.selectedIndex])},this),this.lastSelectedIndex=this.dropDown.selectedIndex},SplitsBrowser.Controls.ChartTypeSelector=t}(),function(){"use strict";var t=SplitsBrowser.getMessage;function e(t){this.parent=t;var e="originalDataCheckbox";this.containerDiv=t.append("div").classed("topRowStart",!0).attr("id","originalDataSelectorContainer"),this.containerDiv.append("div").classed("topRowStartSpacer",!0);var s=this.containerDiv.append("span"),n=this;this.checkbox=s.append("input").attr("type","checkbox").attr("id",e).on("click",function(){n.fireChangeHandlers()}).node(),this.label=s.append("label").attr("for",e).classed("originalDataSelectorLabel",!0),this.handlers=[],this.setMessages()}e.prototype.setMessages=function(){this.label.text(t("ShowOriginalData")),this.containerDiv.attr("title",t("ShowOriginalDataTooltip"))},e.prototype.registerChangeHandler=function(t){-1===this.handlers.indexOf(t)&&this.handlers.push(t)},e.prototype.deregisterChangeHandler=function(t){var e=this.handlers.indexOf(t);-1!==e&&this.handlers.splice(e,1)},e.prototype.fireChangeHandlers=function(){this.handlers.forEach(function(t){t(this.checkbox.checked)},this)},e.prototype.isOriginalDataSelected=function(){return this.checkbox.checked},e.prototype.selectOriginalData=function(){this.checkbox.checked=!0,this.fireChangeHandlers()},e.prototype.setVisible=function(t){this.containerDiv.style("display",t?null:"none")},e.prototype.setEnabled=function(t){this.parent.selectAll("label.originalDataSelectorLabel").classed("disabled",!t),this.checkbox.disabled=!t},SplitsBrowser.Controls.OriginalDataSelector=e}(),function(){"use strict";var c=SplitsBrowser.formatTime,p=SplitsBrowser.getMessage,d=SplitsBrowser.getMessageWithFormatting,m=SplitsBrowser.Model.Course,t={};t.getFastestSplitsPopupData=function(t,e){var s=t.getFastestSplitsTo(10,e);return s=s.map(function(t){return{time:t.split,name:t.name,highlight:!1}}),{title:p("SelectedClassesPopupHeader"),data:s,placeholder:p("SelectedClassesPopupPlaceholder")}},t.getFastestSplitsForLegPopupData=function(t,e,s){var n=t.getCourse(),i=n.getControlCode(s-1),r=n.getControlCode(s),o=i===m.START?p("StartName"):i,a=r===m.FINISH?p("FinishName"):r,l=d("FastestLegTimePopupHeader",{$$START$$:o,$$END$$:a}),u=t.getPrimaryClassName();return{title:l,data:e.getFastestSplitsForLeg(i,r).map(function(t){return{name:t.name,className:t.className,time:t.split,highlight:t.className===u}}),placeholder:null}},t.getCompetitorsVisitingCurrentControlPopupData=function(t,e,s,n){var i,r=t.getCourse().getControlCode(s),o=Math.round(n)-120,a=Math.round(n)+120,l=e.getCompetitorsAtControlInTimeRange(r,o,a),u=t.getPrimaryClassName(),h=l.map(function(t){return{name:t.name,className:t.className,time:t.time,highlight:t.className===u}});return i=r===m.START?p("StartName"):r===m.FINISH?p("FinishName"):d("ControlName",{$$CODE$$:r}),{title:d("NearbyCompetitorsPopupHeader",{$$START$$:c(o),$$END$$:c(a),$$CONTROL$$:i}),data:h,placeholder:p("NoNearbyCompetitors")}},t.getNextControlData=function(t,e,s){var n=Math.min(s,t.controls.length),i=t.getControlCode(n),r=e.getNextControlsAfter(i);return r.sort(function(t,e){return function(t,e){if(t===e)return 0;if(""===t||""===e||t[0]!==e[0])return t<e?-1:1;var s=/^[^0-9]+/.exec(t);if(null!==s&&0<s.length){var n=s[0];if(0<n.length&&n.length<t.length&&e.substring(0,n.length)===n){var i=parseInt(t.substring(n.length),10),r=parseInt(e.substring(n.length),10);if(!isNaN(i)&&!isNaN(r))return i-r}}return t<e?-1:1}(t.course.name,e.course.name)}),{thisControl:i===m.START?p("StartName"):d("ControlName",{$$CODE$$:i}),nextControls:function(t){return t.map(function(t){var e=t.nextControls.slice(0);return e[e.length-1]===m.FINISH&&(e[e.length-1]=p("FinishName")),{course:t.course,nextControls:e.join(", ")}})}(r)}},SplitsBrowser.Model.ChartPopupData=t}(),function(){"use strict";var n=SplitsBrowser.formatTime;function t(t,e){this.shown=!1,this.mouseIn=!1,this.popupDiv=d3.select(t).append("div"),this.popupDiv.classed("chartPopup",!0).style("display","none").style("position","absolute"),this.dataHeader=this.popupDiv.append("div").classed("chartPopupHeader",!0).append("span");var s=this.popupDiv.append("div").classed("chartPopupTableContainer",!0);for(var n in this.dataTable=s.append("table"),this.popupDiv.selectAll(".nextControls").style("display","none"),e)e.hasOwnProperty(n)&&$(this.popupDiv.node()).on(n,e[n]);var i=this;$(this.popupDiv.node()).mouseenter(function(){i.mouseIn=!0}),$(this.popupDiv.node()).mouseleave(function(){i.mouseIn=!1})}t.prototype.isShown=function(){return this.shown},t.prototype.isMouseIn=function(){return this.mouseIn},t.prototype.setData=function(t,e){this.dataHeader.text(t.title);var s=this.dataTable.selectAll("tr").data(t.data);s.enter().append("tr"),(s=this.dataTable.selectAll("tr").data(t.data)).classed("highlighted",function(t){return t.highlight}),s.selectAll("td").remove(),s.append("td").text(function(t){return n(t.time)}),e&&s.append("td").text(function(t){return t.className}),s.append("td").text(function(t){return t.name}),s.exit().remove(),0===t.data.length&&null!==t.placeholder&&this.dataTable.append("tr").append("td").text(t.placeholder)},t.prototype.setNextControlData=function(t){this.dataHeader.text(t.thisControl);var e=this.dataTable.selectAll("tr").data(t.nextControls);e.enter().append("tr"),e.selectAll("td").remove(),e.classed("highlighted",!1),e.append("td").text(function(t){return t.course.name}),e.append("td").text("--\x3e"),e.append("td").text(function(t){return t.nextControls}),e.exit().remove()},t.prototype.setLocation=function(t){this.popupDiv.style("left",t.x+"px").style("top",t.y+"px")},t.prototype.show=function(t){this.popupDiv.style("display",null),this.shown=!0,this.setLocation(t)},t.prototype.hide=function(){this.popupDiv.style("display","none"),this.shown=!1},t.prototype.height=function(){return $(this.popupDiv.node()).height()},SplitsBrowser.Controls.ChartPopup=t}(),function(){"use strict";var s=18,h=0,c=18,o=53,l="\xa0\xa0\xa0\xa0",u=["#FF0000","#4444FF","#00FF00","#000000","#CC0066","#000099","#FFCC00","#884400","#9900FF","#CCCC00","#888800","#CC6699","#00DD00","#3399FF","#BB00BB","#00DDDD","#FF00FF","#0088BB","#888888","#FF99FF","#55BB33"],p=SplitsBrowser.formatTime,a=SplitsBrowser.getMessage,d=SplitsBrowser.isNotNullNorNaN,n=SplitsBrowser.isNaNStrict,t=SplitsBrowser.Model.ChartPopupData,m=SplitsBrowser.Controls.ChartPopup;function f(t,e){var s;return s=null===e?"-":n(e)?"?":e.toString(),l+p(t)+" ("+s+")"}function g(t,e){return""===e?t:t+" ("+e+")"}function C(t){return t.completed()&&t.isNonCompetitive?a("NonCompetitiveShort"):t.isNonFinisher?a("DidNotFinishShort"):t.isDisqualified?a("DisqualifiedShort"):t.isOverMaxTime?a("OverMaxTimeShort"):t.completed()?"":a("MispunchedShort")}function e(t){this.parent=t,this.xScale=null,this.yScale=null,this.hasData=!1,this.overallWidth=-1,this.overallHeight=-1,this.contentWidth=-1,this.contentHeight=-1,this.numControls=-1,this.selectedIndexes=[],this.currentCompetitorData=null,this.isPopupOpen=!1,this.popupUpdateFunc=null,this.maxStartTimeLabelWidth=0,this.mouseOutTimeout=null,this.selectedIndexesOrderedByLastYValue=[],this.referenceCumTimes=[],this.referenceCumTimesSorted=[],this.referenceCumTimeIndexes=[],this.fastestCumTimes=[],this.isMouseIn=!1,this.currentControlIndex=null,this.actualControlIndex=null,this.controlLine=null,this.svg=d3.select(this.parent).append("svg").attr("id","chart"),this.svgGroup=this.svg.append("g"),this.setLeftMargin(o);function e(t){i.onMouseMove(t)}function s(t){i.onMouseUp(t)}function n(t){i.onMouseDown(t)}var i=this;$(this.svg.node()).mouseenter(function(t){i.onMouseEnter(t)}).mousemove(e).mouseleave(function(t){i.onMouseLeave(t)}).mousedown(n).mouseup(s),$(this.svg.node()).contextmenu(function(t){t.preventDefault()}),this.textSizeElement=this.svg.append("text").attr("fill","transparent").attr("id","sb-text-size-element");var r={mousemove:e,mousedown:n,mouseup:s};this.popup=new m(t,r),$(document).mouseup(function(){i.popup.hide()})}function v(t){var e=t.filter(d);return 0<e.length?d3.max(e):0}e.prototype.setLeftMargin=function(t){this.currentLeftMargin=t,this.svgGroup.attr("transform","translate("+this.currentLeftMargin+","+s+")")},e.prototype.getPopupLocation=function(t){return{x:t.pageX+10,y:Math.max(t.pageY-this.popup.height()/2,0)}},e.prototype.getFastestSplitsPopupData=function(){return t.getFastestSplitsPopupData(this.courseClassSet,this.currentControlIndex)},e.prototype.getFastestSplitsForCurrentLegPopupData=function(){return t.getFastestSplitsForLegPopupData(this.courseClassSet,this.eventData,this.currentControlIndex)},e.prototype.setCurrentChartTime=function(t){var e=t.pageY-$(this.svg.node()).offset().top-s;this.currentChartTime=Math.round(60*this.yScale.invert(e))+this.referenceCumTimes[this.currentControlIndex]},e.prototype.getCompetitorsVisitingCurrentControlPopupData=function(){return t.getCompetitorsVisitingCurrentControlPopupData(this.courseClassSet,this.eventData,this.currentControlIndex,this.currentChartTime)},e.prototype.getNextControlData=function(){return t.getNextControlData(this.courseClassSet.getCourse(),this.eventData,this.actualControlIndex)},e.prototype.onMouseEnter=function(t){null!==this.mouseOutTimeout&&(clearTimeout(this.mouseOutTimeout),this.mouseOutTimeout=null),this.isMouseIn=!0,this.hasData&&this.updateControlLineLocation(t)},e.prototype.onMouseMove=function(t){this.hasData&&this.isMouseIn&&null!==this.xScale&&this.updateControlLineLocation(t)},e.prototype.onMouseLeave=function(){var t=this;this.mouseOutTimeout=setTimeout(function(){t.popup.isMouseIn()||(t.isMouseIn=!1,t.removeControlLine())},1)},e.prototype.onMouseDown=function(t){var e=this;setTimeout(function(){e.showPopupDialog(t)},1)},e.prototype.onMouseUp=function(t){this.popup.hide(),t.preventDefault()},e.prototype.showPopupDialog=function(t){if(this.isMouseIn&&null!==this.currentControlIndex){var e=!1,s=this;!this.isRaceGraph||1!==t.which&&3!==t.which?1===t.which?(this.popupUpdateFunc=function(){s.popup.setData(s.getFastestSplitsPopupData(),!1)},e=!0):3===t.which&&this.hasControls&&(this.popupUpdateFunc=function(){s.popup.setData(s.getFastestSplitsForCurrentLegPopupData(),!0)},e=!0):this.hasControls&&(this.setCurrentChartTime(t),this.popupUpdateFunc=function(){s.popup.setData(s.getCompetitorsVisitingCurrentControlPopupData(),!0)},e=!0),e&&(this.updatePopupContents(t),this.popup.show(this.getPopupLocation(t)))}},e.prototype.updatePopupContents=function(t){var e=t.pageY-$(this.svg.node()).offset().top;this.hasControls&&e<s?this.updateNextControlInformation():this.popupUpdateFunc()},e.prototype.updateNextControlInformation=function(){this.hasControls&&this.popup.setNextControlData(this.getNextControlData())},e.prototype.drawControlLine=function(t){this.currentControlIndex=t,this.updateCompetitorStatistics();var e=this.xScale(this.referenceCumTimes[t]);this.controlLine=this.svgGroup.append("line").attr("x1",e).attr("y1",0).attr("x2",e).attr("y2",this.contentHeight).attr("class","controlLine").node()},e.prototype.updateControlLineLocation=function(t){var e=$(this.svg.node()),s=e.offset(),n=t.pageX-s.left,i=t.pageY-s.top;if(this.currentLeftMargin<=n&&n<e.width()-h&&i<e.height()-c){var r,o=this.xScale.invert(n-this.currentLeftMargin),a=d3.bisect(this.referenceCumTimesSorted,o);if(a>=this.referenceCumTimesSorted.length)r=this.referenceCumTimesSorted.length-1;else{var l=Math.abs(this.referenceCumTimesSorted[a]-o);r=Math.abs(o-this.referenceCumTimesSorted[a-1])<l?a-1:a}var u=this.referenceCumTimeIndexes[r];null!==this.actualControlIndex&&this.actualControlIndex===u||(this.removeControlLine(),this.actualControlIndex=u,this.drawControlLine(Math.max(this.minViewableControl,u))),this.popup.isShown()&&null!==this.currentControlIndex&&(this.isRaceGraph&&this.setCurrentChartTime(t),this.updatePopupContents(t),this.popup.setLocation(this.getPopupLocation(t)))}else this.removeControlLine(),this.popup.hide()},e.prototype.removeControlLine=function(){this.currentControlIndex=null,this.actualControlIndex=null,this.updateCompetitorStatistics(),null!==this.controlLine&&(d3.select(this.controlLine).remove(),this.controlLine=null)},e.prototype.getTimesBehindFastest=function(s,t){var e=t.map(function(t){return this.courseClassSet.allCompetitors[t]},this),n=this.fastestCumTimes[s]-this.fastestCumTimes[s-1];return e.map(function(t){var e=t.getSplitTimeTo(s);return null===e?null:e-n})},e.prototype.getTimeLosses=function(e,t){return t.map(function(t){return this.courseClassSet.allCompetitors[t]},this).map(function(t){return t.getTimeLossAt(e)})},e.prototype.updateCompetitorStatistics=function(){var t=this.selectedIndexesOrderedByLastYValue.map(function(t){return this.courseClassSet.allCompetitors[t]},this),s=t.map(function(t){return g(t.name,C(t))});if(null!==this.currentControlIndex&&0<this.currentControlIndex){if(this.visibleStatistics.TotalTime){var e=t.map(function(t){return t.getCumulativeTimeTo(this.currentControlIndex)},this),n=t.map(function(t){return t.getCumulativeRankTo(this.currentControlIndex)},this);s=d3.zip(s,e,n).map(function(t){return t[0]+f(t[1],t[2])})}if(this.visibleStatistics.SplitTime){var i=t.map(function(t){return t.getSplitTimeTo(this.currentControlIndex)},this),r=t.map(function(t){return t.getSplitRankTo(this.currentControlIndex)},this);s=d3.zip(s,i,r).map(function(t){return t[0]+f(t[1],t[2])})}if(this.visibleStatistics.BehindFastest){var o=this.getTimesBehindFastest(this.currentControlIndex,this.selectedIndexesOrderedByLastYValue);s=d3.zip(s,o).map(function(t){return t[0]+l+p(t[1])})}if(this.visibleStatistics.TimeLoss){var a=this.getTimeLosses(this.currentControlIndex,this.selectedIndexesOrderedByLastYValue);s=d3.zip(s,a).map(function(t){return t[0]+l+p(t[1])})}}this.hasData&&this.currentCompetitorData.forEach(function(t,e){t.label=s[e]}),d3.selectAll("text.competitorLabel").text(function(t){return t.label})},e.prototype.getTickFormatter=function(){var s=this;return function(t,e){return 0===e?a("StartNameShort"):e===s.numControls+1?a("FinishNameShort"):e.toString()}},e.prototype.getTextWidth=function(t){return this.textSizeElement.text(t).node().getBBox().width},e.prototype.getTextHeight=function(t){return this.textSizeElement.text(t).node().getBBox().height},e.prototype.getMaxGraphEndTextWidth=function(){if(
0===this.selectedIndexes.length)return 0;var t=this.selectedIndexes.map(function(t){var e=this.courseClassSet.allCompetitors[t];return this.getTextWidth(g(e.name,C(e)))},this);return d3.max(t)+this.determineMaxStatisticTextWidth()},e.prototype.getMaxTimeAndRankTextWidth=function(n,i){var r=0,o=0,a=this.selectedIndexes.map(function(t){return this.courseClassSet.allCompetitors[t]},this);d3.range(1,this.numControls+2).forEach(function(e){var t=a.map(function(t){return t[n](e)});r=Math.max(r,v(t));var s=a.map(function(t){return t[i](e)});o=Math.max(o,v(s))});var t=f(r,o);return this.getTextWidth(t)},e.prototype.getMaxSplitTimeAndRankTextWidth=function(){return this.getMaxTimeAndRankTextWidth("getSplitTimeTo","getSplitRankTo")},e.prototype.getMaxCumulativeTimeAndRankTextWidth=function(){return this.getMaxTimeAndRankTextWidth("getCumulativeTimeTo","getCumulativeRankTo")},e.prototype.getMaxTimeBehindFastestWidth=function(){for(var t=0,e=1;e<=this.numControls+1;e+=1){var s=this.getTimesBehindFastest(e,this.selectedIndexes);t=Math.max(t,v(s))}return this.getTextWidth(l+p(t))},e.prototype.getMaxTimeLossWidth=function(){for(var t=0,e=0,s=1;s<=this.numControls+1;s+=1){var n=this.getTimeLosses(s,this.selectedIndexes).filter(d);0<n.length&&(t=Math.max(t,d3.max(n)),e=Math.min(e,d3.min(n)))}return Math.max(this.getTextWidth(l+p(t)),this.getTextWidth(l+p(e)))},e.prototype.determineMaxStatisticTextWidth=function(){var t=0;return this.visibleStatistics.TotalTime&&(t+=this.getMaxCumulativeTimeAndRankTextWidth()),this.visibleStatistics.SplitTime&&(t+=this.getMaxSplitTimeAndRankTextWidth()),this.visibleStatistics.BehindFastest&&(t+=this.getMaxTimeBehindFastestWidth()),this.visibleStatistics.TimeLoss&&(t+=this.getMaxTimeLossWidth()),t},e.prototype.determineMaxStartTimeLabelWidth=function(t){return 0<t.competitorNames.length?d3.max(t.competitorNames.map(function(t){return this.getTextWidth("00:00:00 "+t)},this)):0},e.prototype.createScales=function(t){this.xScale=d3.scaleLinear().domain(t.xExtent).range([0,this.contentWidth]),this.yScale=d3.scaleLinear().domain(t.yExtent).range([0,this.contentHeight]),this.xScaleMinutes=d3.scaleLinear().domain([t.xExtent[0]/60,t.xExtent[1]/60]).range([0,this.contentWidth])},e.prototype.drawBackgroundRectangles=function(){var e=this.referenceCumTimes.slice(0);e.sort(d3.ascending);for(var t=1;t<e.length;)e[t]===e[t-1]?e.splice(t,1):t+=1;var s=this,n=this.svgGroup.selectAll("rect").data(d3.range(e.length-1));n.enter().append("rect"),(n=this.svgGroup.selectAll("rect").data(d3.range(e.length-1))).attr("x",function(t){return s.xScale(e[t])}).attr("y",0).attr("width",function(t){return s.xScale(e[t+1])-s.xScale(e[t])}).attr("height",this.contentHeight).attr("class",function(t){return t%2==0?"background1":"background2"}),n.exit().remove()},e.prototype.determineYAxisTickFormatter=function(t){if(this.isRaceGraph){var s=0===t.dataColumns.length?[]:t.dataColumns[0].ys;if(0===s.length)return function(t){return p(60*t)};var n=this.yScale;return function(e){return 10<=d3.min(s.map(function(t){return Math.abs(n(t)-n(e))}))?p(Math.round(60*e)):""}}return null},e.prototype.drawAxes=function(t,e){var s=this.determineYAxisTickFormatter(e),n=d3.axisTop().scale(this.xScale).tickFormat(this.getTickFormatter()).tickValues(this.referenceCumTimes),i=d3.axisLeft().scale(this.yScale).tickFormat(s),r=d3.axisBottom().scale(this.xScaleMinutes);this.svgGroup.selectAll("g.axis").remove(),this.svgGroup.append("g").attr("class","x axis").call(n),this.svgGroup.append("g").attr("class","y axis").call(i).append("text").attr("transform","rotate(-90)").attr("x",-(this.contentHeight-6)).attr("y",6).attr("dy",".71em").style("text-anchor","start").style("fill","black").text(t),this.svgGroup.append("g").attr("class","x axis").attr("transform","translate(0,"+this.contentHeight+")").call(r).append("text").attr("x",60).attr("y",-5).style("text-anchor","start").style("fill","black").text(a("LowerXAxisChartLabel"))},e.prototype.drawChartLines=function(r){var o=this;this.svgGroup.selectAll("path.graphLine").remove(),this.svgGroup.selectAll("line.aroundDubiousTimes").remove(),d3.range(this.numLines).forEach(function(e){function s(){o.highlight(o.selectedIndexes[e])}function n(){o.unhighlight()}var i=u[this.selectedIndexes[e]%u.length];this.svgGroup.append("path").attr("d",function(e){return r.dataColumns.some(function(t){return d(t.ys[e])})?d3.line().x(function(t){return o.xScale(t.x)}).y(function(t){return o.yScale(t.ys[e])}).defined(function(t){return d(t.ys[e])}):d3.line().x(0).y(0).defined(function(t,e){return 0===e})}(e)(r.dataColumns)).attr("stroke",i).attr("class","graphLine competitor"+this.selectedIndexes[e]).on("mouseenter",s).on("mouseleave",n).append("title").text(r.competitorNames[e]),r.dubiousTimesInfo[e].forEach(function(t){this.svgGroup.append("line").attr("x1",this.xScale(r.dataColumns[t.start].x)).attr("y1",this.yScale(r.dataColumns[t.start].ys[e])).attr("x2",this.xScale(r.dataColumns[t.end].x)).attr("y2",this.yScale(r.dataColumns[t.end].ys[e])).attr("stroke",i).attr("class","aroundDubiousTimes competitor"+this.selectedIndexes[e]).on("mouseenter",s).on("mouseleave",n).append("title").text(r.competitorNames[e])},this)},this)},e.prototype.highlight=function(t){this.svg.selectAll("path.graphLine.competitor"+t).classed("selected",!0),this.svg.selectAll("line.competitorLegendLine.competitor"+t).classed("selected",!0),this.svg.selectAll("text.competitorLabel.competitor"+t).classed("selected",!0),this.svg.selectAll("text.startLabel.competitor"+t).classed("selected",!0),this.svg.selectAll("line.aroundDubiousTimes.competitor"+t).classed("selected",!0)},e.prototype.unhighlight=function(){this.svg.selectAll("path.graphLine.selected").classed("selected",!1),this.svg.selectAll("line.competitorLegendLine.selected").classed("selected",!1),this.svg.selectAll("text.competitorLabel.selected").classed("selected",!1),this.svg.selectAll("text.startLabel.selected").classed("selected",!1),this.svg.selectAll("line.aroundDubiousTimes.selected").classed("selected",!1)},e.prototype.drawCompetitorStartTimeLabels=function(s){var n=s.dataColumns[0],i=this,t=this.svgGroup.selectAll("text.startLabel").data(this.selectedIndexes);t.enter().append("text").classed("startLabel",!0),(t=this.svgGroup.selectAll("text.startLabel").data(this.selectedIndexes)).attr("x",-7).attr("y",function(t,e){return i.yScale(n.ys[e])+i.getTextHeight(s.competitorNames[e])/4}).attr("class",function(t){return"startLabel competitor"+t}).on("mouseenter",function(t){i.highlight(t)}).on("mouseleave",function(){i.unhighlight()}).text(function(t,e){return p(Math.round(60*n.ys[e]))+" "+s.competitorNames[e]}),t.exit().remove()},e.prototype.removeCompetitorStartTimeLabels=function(){this.svgGroup.selectAll("text.startLabel").remove()},e.prototype.adjustCompetitorLegendLabelsDownwardsIfNecessary=function(){for(var t=1;t<this.numLines;t+=1){var e=this.currentCompetitorData[t-1],s=this.currentCompetitorData[t];s.y<e.y+e.textHeight&&(s.y=e.y+e.textHeight)}},e.prototype.adjustCompetitorLegendLabelsUpwardsIfNecessary=function(t){if(0<this.numLines&&this.currentCompetitorData[this.numLines-1].y>this.contentHeight){this.currentCompetitorData[this.numLines-1].y=Math.max(t,this.contentHeight);for(var e=this.numLines-2;0<=e;e-=1){var s=this.currentCompetitorData[e+1],n=this.currentCompetitorData[e];if(!(n.y+n.textHeight>s.y))break;n.y=s.y-n.textHeight}}},e.prototype.drawCompetitorLegendLabels=function(t){var i=0;if(0===t.dataColumns.length)this.currentCompetitorData=[];else{var r=t.dataColumns[t.dataColumns.length-1];this.currentCompetitorData=d3.range(this.numLines).map(function(t){var e=this.selectedIndexes[t],s=this.courseClassSet.allCompetitors[e].name,n=this.getTextHeight(s);return i+=n,{label:g(s,C(this.courseClassSet.allCompetitors[e])),textHeight:n,y:d(r.ys[t])?this.yScale(r.ys[t]):null,colour:u[e%u.length],index:e}},this),i-=this.currentCompetitorData[this.numLines-1].textHeight;for(var e=null,s=this.numLines-1;0<=s;s-=1)null===this.currentCompetitorData[s].y&&(this.currentCompetitorData[s].y=null===e?this.contentHeight:e-this.currentCompetitorData[s].textHeight,e=this.currentCompetitorData[s].y)}this.currentCompetitorData.sort(function(t,e){return t.y-e.y}),this.selectedIndexesOrderedByLastYValue=this.currentCompetitorData.map(function(t){return t.index}),this.adjustCompetitorLegendLabelsDownwardsIfNecessary(),this.adjustCompetitorLegendLabelsUpwardsIfNecessary(i);var n=this.svgGroup.selectAll("line.competitorLegendLine").data(this.currentCompetitorData);n.enter().append("line").classed("competitorLegendLine",!0);var o=this;(n=this.svgGroup.selectAll("line.competitorLegendLine").data(this.currentCompetitorData)).attr("x1",this.contentWidth+1).attr("y1",function(t){return t.y}).attr("x2",this.contentWidth+10+1).attr("y2",function(t){return t.y}).attr("stroke",function(t){return t.colour}).attr("class",function(t){return"competitorLegendLine competitor"+t.index}).on("mouseenter",function(t){o.highlight(t.index)}).on("mouseleave",function(){o.unhighlight()}),n.exit().remove();var a=this.svgGroup.selectAll("text.competitorLabel").data(this.currentCompetitorData);a.enter().append("text").classed("competitorLabel",!0),(a=this.svgGroup.selectAll("text.competitorLabel").data(this.currentCompetitorData)).attr("x",this.contentWidth+10+2).attr("y",function(t){return t.y+t.textHeight/4}).attr("class",function(t){return"competitorLabel competitor"+t.index}).on("mouseenter",function(t){o.highlight(t.index)}).on("mouseleave",function(){o.unhighlight()}).text(function(t){return t.label}),a.exit().remove()},e.prototype.adjustContentSize=function(){var t=this.getMaxGraphEndTextWidth();this.setLeftMargin(Math.max(this.maxStartTimeLabelWidth+8,o)),this.contentWidth=Math.max(this.overallWidth-this.currentLeftMargin-h-t-12,100),this.contentHeight=Math.max(this.overallHeight-s-c,100)},e.prototype.setSize=function(t,e){this.overallWidth=t,this.overallHeight=e,$(this.svg.node()).width(t).height(e),this.adjustContentSize()},e.prototype.clearGraph=function(){this.svgGroup.selectAll("*").remove()},e.prototype.sortReferenceCumTimes=function(){var s=d3.map();this.referenceCumTimes.forEach(function(t,e){s.has(t)||s.set(t,e)}),this.referenceCumTimesSorted=this.referenceCumTimes.slice(0),this.referenceCumTimesSorted.sort(d3.ascending);for(var t=this.referenceCumTimesSorted.length-1;0<t;t-=1)this.referenceCumTimesSorted[t]===this.referenceCumTimesSorted[t-1]&&this.referenceCumTimesSorted.splice(t,1);this.referenceCumTimeIndexes=this.referenceCumTimesSorted.map(function(t){return s.get(t)})},e.prototype.drawChart=function(t,e,s,n){var i=t.chartData;this.numControls=i.numControls,this.numLines=i.competitorNames.length,this.selectedIndexes=e,this.referenceCumTimes=t.referenceCumTimes,this.fastestCumTimes=t.fastestCumTimes,this.eventData=t.eventData,this.courseClassSet=t.courseClassSet,this.hasControls=t.courseClassSet.getCourse().hasControls(),this.isRaceGraph=n.isRaceGraph,this.minViewableControl=n.minViewableControl,this.visibleStatistics=s,this.hasData=!0,this.maxStatisticTextWidth=this.determineMaxStatisticTextWidth(),this.maxStartTimeLabelWidth=this.isRaceGraph?this.determineMaxStartTimeLabelWidth(i):0,this.sortReferenceCumTimes(),this.adjustContentSize(),this.createScales(i),this.drawBackgroundRectangles(),this.drawAxes(a(n.yAxisLabelKey),i),this.drawChartLines(i),this.drawCompetitorLegendLabels(i),this.removeControlLine(),this.isRaceGraph?this.drawCompetitorStartTimeLabels(i):this.removeCompetitorStartTimeLabels()},SplitsBrowser.Controls.Chart=e}(),function(){"use strict";var c=SplitsBrowser.formatTime,p=SplitsBrowser.Model.compareCompetitors,d=SplitsBrowser.getMessage,m=SplitsBrowser.getMessageWithFormatting,f=SplitsBrowser.isNotNullNorNaN;function t(t){this.parent=t,this.courseClass=null,this.div=null,this.headerSpan=null,this.table=null,this.buildTable()}function g(t){return t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}t.prototype.buildTable=function(){this.div=d3.select(this.parent).append("div").attr("id","resultsTableContainer"),this.headerSpan=this.div.append("div").append("span").classed("resultsTableHeader",!0),this.table=this.div.append("table").classed("resultsTable",!0),this.table.append("thead").append("tr"),this.table.append("tbody")},t.prototype.populateTable=function(){var t=this.courseClass.name+", ";1===this.courseClass.numControls?t+=d("ResultsTableHeaderSingleControl"):t+=m("ResultsTableHeaderMultipleControls",{$$NUM$$:this.courseClass.numControls});var e=this.courseClass.course;null!==e.length&&(t+=", "+m("ResultsTableHeaderCourseLength",{$$DISTANCE$$:e.length.toFixed(1)})),null!==e.climb&&(t+=", "+m("ResultsTableHeaderClimb",{$$CLIMB$$:e.climb})),this.headerSpan.text(t);var s=[d("ResultsTableHeaderControlNumber"),d("ResultsTableHeaderName"),d("ResultsTableHeaderTime")],n=this.courseClass.course.controls;(s=null===n?s.concat(d3.range(1,this.courseClass.numControls+1)):s.concat(n.map(function(t,e){return e+1+"\xa0("+t+")"}))).push(d("FinishName"));var i=this.table.select("thead tr").selectAll("th").data(s);i.enter().append("th"),i.exit().remove(),(i=this.table.select("thead tr").selectAll("th").data(s)).text(function(t){return t});var l=[];function r(t,e,s,n,i,r,o){l.push("<td"),s&&l.push(' class="'+s+'"'),l.push("><span");var a=((n?"fastest":"")+" "+(r?"dubious":"")).trim();""!==a&&l.push(' class="'+a+'"'),l.push(">"),l.push(g(t)),l.push("</span><br><span"),""!==(a=((i?"fastest":"")+" "+(o?"dubious":"")).trim())&&l.push(' class="'+a+'"'),l.push(">"),l.push(g(e)),l.push("</span></td>\n")}var o=this.courseClass.competitors.slice(0);o.sort(p);var a=0,u=0,h=function(t){var e=0,s=1;return t.forEach(function(t){t.getAllOriginalCumulativeTimes().forEach(function(t){if(f(t))for(;e<2&&Math.abs(t-Math.round(t*s)/s)>1e-7*t;)e+=1,s*=10})}),e}(o);o.forEach(function(e,t){l.push("<tr><td>"),e.isNonCompetitive?(l.push(g(d("NonCompetitiveShort"))),a+=1):e.completed()&&(0!==t&&o[t-1].totalTime===e.totalTime||(u=t+1-a),l.push(""+u)),l.push("</td>"),r(e.name,e.club,!1,!1,!1,!1),r(function(t){return t.isNonStarter?d("DidNotStartShort"):t.isNonFinisher?d("DidNotFinishShort"):t.isDisqualified?d("DisqualifiedShort"):t.isOverMaxTime?d("OverMaxTimeShort"):t.completed()?c(t.totalTime):d("MispunchedShort")}(e),"\xa0","time",!1,!1,!1,!1),d3.range(1,this.courseClass.numControls+2).forEach(function(t){r(c(e.getOriginalCumulativeTimeTo(t),h),c(e.getOriginalSplitTimeTo(t),h),"time",1===e.getCumulativeRankTo(t),1===e.getSplitRankTo(t),e.isCumulativeTimeDubious(t),e.isSplitTimeDubious(t))}),l.push("</tr>\n")},this),this.table.select("tbody").node().innerHTML=l.join("")},t.prototype.setClass=function(t){this.courseClass=t,null!==this.courseClass&&this.populateTable()},t.prototype.show=function(){this.div.style("display",null)},t.prototype.hide=function(){this.div.style("display","none")},t.prototype.retranslate=function(){this.populateTable()},SplitsBrowser.Controls.ResultsTable=t}(),function(){"use strict";var i=SplitsBrowser.Model.ChartTypes,l=SplitsBrowser.Model.CourseClassSet;function r(t,e){return t.replace(new RegExp(e.source,"g"),"")}var u=/(?:^|&|\?)class=([^&]+)/;var o=/(?:^|&|\?)chartType=([^&]+)/;var a=/(?:^|&|\?)compareWith=([^&]+)/,h=["Winner","FastestTime","FastestTimePlus5","FastestTimePlus25","FastestTimePlus50","FastestTimePlus100"];var c=/(?:^|&|\?)selected=([^&]+)/;var p=/(?:^|&|\?)stats=([^&]*)/,d=["TotalTime","SplitTime","BehindFastest","TimeLoss"];var m=/(?:^|&|\?)showOriginal=([^&]*)/;var f=/(?:^|&|\?)filterText=([^&]*)/;SplitsBrowser.parseQueryString=function(t,e){var s=function(t,e){var s=u.exec(t);if(null===s)return null;for(var n=d3.map(),i=0;i<e.classes.length;i+=1)n.set(e.classes[i].name,e.classes[i]);var r=decodeURIComponent(s[1]).split(";"),o=(r=d3.set(r).values()).filter(function(t){return n.has(t)}).map(function(t){return n.get(t)});if(0===o.length)return null;var a=o[0].course;return o=o.filter(function(t){return t.course===a}),new l(o)}(t,e);return{classes:null===s?null:s.classes.map(function(t){return e.classes.indexOf(t)}),chartType:function(t){var e=o.exec(t);if(null===e)return null;var s=e[1];return i.hasOwnProperty(s)?i[s]:null}(t),compareWith:function(t,e){var s=a.exec(t);if(null===s)return null;var n=decodeURIComponent(s[1]),i=h.indexOf(n);if(1<=i)return{index:i,runner:null};if(0===i&&null!==e)return e.allCompetitors.some(function(t){return t.completed()})?{index:0,runner:null}:null;if(null===e)return null;for(var r=0;r<e.allCompetitors.length;r+=1){var o=e.allCompetitors[r];if(o.name===n&&o.completed())return{index:h.length,runner:o}}return null}(t,s),selected:function(t,e){if(null===e)return null;var s=c.exec(t);if(null===s)return null;var n=decodeURIComponent(s[1]).split(";");if(0<=n.indexOf("*"))return d3.range(0,e.allCompetitors.length);n=d3.set(n).values();var i=e.allCompetitors.map(function(t){return t.name}),r=[];return n.forEach(function(t){var e=i.indexOf(t);0<=e&&r.push(e)}),r.sort(d3.ascending),0===r.length?null:r}(t,s),stats:function(t){var e=p.exec(t);if(null===e)return null;var s=decodeURIComponent(e[1]).split(";"),n={};d.forEach(function(t){n[t]=!1});for(var i=0;i<s.length;i+=1){var r=s[i];if(n.hasOwnProperty(r))n[r]=!0;else if(""!==r)return null}return n}(t),showOriginal:function(t){var e=m.exec(t);return null!==e&&"1"===e[1]}(t),filterText:function(t){var e=f.exec(t);return null===e?"":decodeURIComponent(e[1])}(t)}},SplitsBrowser.formatQueryString=function(t,e,s,n){return t=(t=function(t,e){return t=r(t,f),""===e?t:t+"&filterText="+encodeURIComponent(e)}(t=function(t,e){return t=r(t,m),e?t+"&showOriginal=1":t}(t=function(t,e){t=r(t,p);var s=d.filter(function(t){return e.hasOwnProperty(t)&&e[t]});return t+"&stats="+encodeURIComponent(s.join(";"))}(t=function(t,e,s){t=r(t,c);var n=s.map(function(t){return e.allCompetitors[t]});if(0===n.length)return t;if(n.length===e.allCompetitors.length)return t+"&selected=*";var i=n.map(function(t){return t.name}).join(";");return t+"&selected="+encodeURIComponent(i)}(t=function(t,e,s){t=r(t,a);var n=null;return"number"==typeof e&&0<=e&&e<h.length?n=h[e]:null!==s&&(n=s.name),null===n?t:t+"&compareWith="+encodeURIComponent(n)}(t=function(t,e){for(var s in t=r(t,o),i)if(i.hasOwnProperty(s)&&i[s]===e)return t+"&chartType="+encodeURIComponent(s);return t}(t=function(t,e,s){t=r(t,u);var n=s.map(function(t){return e.classes[t].name});return t+"&class="+encodeURIComponent(n.join(";"))}(t,e,n.classes),n.chartType),n.compareWith.index,n.compareWith.runner),s,n.selected),n.stats),n.showOriginal),n.filterText)).replace(/^\??&/,"")}}(),function(){"use strict";var t=SplitsBrowser.getMessage;function e(t){this.parent=t,this.warnings=[],this.containerDiv=t.append("div").classed("topRowStart",!0).attr("id","warningViewerContainer").style("display","none"),this.containerDiv.append("div").classed("topRowStartSpacer",!0),this.warningTriangle=this.createWarningTriangle(this.containerDiv),this.warningList=t.append("div").classed("warningList",!0).classed("transient",!0).style("position","absolute").style("display","none");var s=this;$(document).click(function(t){if("none"!==s.warningList.style("display")){var e=$("div#warningTriangleContainer,div.warningList");e.is(t.target)||0!==e.has(t.target).length||s.warningList.style("display","none")}}),this.setMessages()}e.prototype.setMessages=function(){this.containerDiv.attr("title",t("WarningsTooltip"))},e.prototype.createWarningTriangle=function(){var t=this.containerDiv.append("div").attr("id","warningTriangleContainer"),e=t.append("svg");e.style("width","21px").style("height","19px").style("margin-bottom","-3px"),e.append("polygon").attr("points","1,18 10,0 19,18").style("stroke","black").style("stroke-width","1.5px").style("fill","#ffd426"),e.append("text").attr("x",10).attr("y",16).attr("text-anchor","middle").style("font-size","14px").text("!");var s=this;return t.on("click",function(){s.showHideErrorList()}),e},e.prototype.setWarnings=function(t){var e=this.warningList.selectAll("div").data(t);e.enter().append("div").classed("warning",!0),(e=this.warningList.selectAll("div").data(t)).text(function(t){return t}),e.exit().remove(),this.containerDiv.style("display",t&&0<t.length?"block":"none")},e.prototype.showHideErrorList=function(){if("none"===this.warningList.style("display")){var t=$(this.warningTriangle.node()).offset(),e=$(this.warningTriangle.node()).outerHeight(),s=$(this.warningList.node()).outerWidth();this.warningList.style("left",Math.max(t.left-s/2,0)+"px").style("top",t.top+e+5+"px").style("display","block")}else this.warningList.style("display","none")},SplitsBrowser.Controls.WarningViewer=e}(),function(){"use strict";var t=SplitsBrowser.Version,n=SplitsBrowser.getMessage,e=SplitsBrowser.tryGetMessage,i=SplitsBrowser.getMessageWithFormatting,o=SplitsBrowser.initialiseMessages,s=SplitsBrowser.Model,r=s.CompetitorSelection,a=s.CourseClassSet,l=s.ChartTypes,u=SplitsBrowser.Input.parseEventData,h=SplitsBrowser.DataRepair.repairEventData,c=SplitsBrowser.DataRepair.transferCompetitorData,p=SplitsBrowser.parseQueryString,d=SplitsBrowser.formatQueryString,m=SplitsBrowser.Controls,f=m.LanguageSelector,g=m.ClassSelector,C=m.ChartTypeSelector,v=m.ComparisonSelector,S=m.OriginalDataSelector,y=m.StatisticsSelector,x=m.WarningViewer,T=m.CompetitorList,w=m.Chart,b=m.ResultsTable;function D(){return window.d3?!(parseFloat(d3.version)<4)||(alert("D3 version "+d3.version+" was found. SplitsBrowser requires D3 version 4 or later."),!1):(alert("D3 was not found. SplitsBrowser requires D3 version 4 or later."),!1)}function L(t){this.options=t,this.eventData=null,this.classes=null,this.currentClasses=[],this.chartData=null,this.referenceCumTimes=null,this.fastestCumTimes=null,this.previousCompetitorList=[],this.topBarHeight=t&&t.topBar&&0<$(t.topBar).length?$(t.topBar).outerHeight(!0):0,this.selection=null,this.courseClassSet=null,this.languageSelector=null,this.classSelector=null,this.comparisonSelector=null,this.originalDataSelector=null,this.statisticsSelector=null,this.competitorList=null,this.warningViewer=null,this.chart=null,this.topPanel=null,this.mainPanel=null,this.buttonsPanel=null,this.competitorListContainer=null,this.container=null,this.currentResizeTimeout=null}function I(t){alert(t)}function N(){alert(n("RaceGraphDisabledAsStartTimesMissing"))}function O(t,e){var s=d3.select("body").append("div").classed("sbErrors",!0);s.append("h1").text(n("LoadFailedHeader")),s.append("p").text(i(t,e))}function B(t,e,s){O("LoadFailedReadError",{$$ERROR$$:s})}L.prototype.enableOrDisableRaceGraph=function(){var t=this.courseClassSet.allCompetitors.some(function(t){return t.lacksStartTime()});this.chartTypeSelector.setRaceGraphDisabledNotifier(t?N:null)},L.prototype.setEvent=function(t){this.eventData=t,this.classes=t.classes,null!==this.classSelector&&this.classSelector.setClasses(this.classes),this.warningViewer.setWarnings(t.warnings)},L.prototype.drawLogo=function(){this.logoSvg=this.topPanel.append("svg").classed("topRowStart",!0),this.logoSvg.style("width","19px").style("height","19px").style("margin-bottom","-3px"),this.logoSvg.append("rect").attr("x","0").attr("y","0").attr("width","19").attr("height","19").attr("fill","white"),this.logoSvg.append("polygon").attr("points","0,19 19,0 19,19").attr("fill","red"),this.logoSvg.append("polyline").attr("points","0.5,0.5 0.5,18.5 18.5,18.5 18.5,0.5 0.5,0.5 0.5,18.5").attr("stroke","black").attr("fill","none"),this.logoSvg.append("polyline").attr("points","1,12 5,8 8,14 17,11").attr("fill","none").attr("stroke","blue").attr("stroke-width","2"),this.logoSvg.selectAll("*").append("title"),this.setLogoMessages()},L.prototype.setLogoMessages=function(){this.logoSvg.selectAll("title").text(i("ApplicationVersion",{$$VERSION$$:t}))},L.prototype.addSpacer=function(){this.topPanel.append("div").classed("topRowStartSpacer",!0)},L.prototype.addLanguageSelector=function(){this.languageSelector=new f(this.topPanel.node())},L.prototype.addClassSelector=function(){this.classSelector=new g(this.topPanel.node()),null!==this.classes&&this.classSelector.setClasses(this.classes)},L.prototype.addChartTypeSelector=function(){var t=[l.SplitsGraph,l.RaceGraph,l.PositionAfterLeg,l.SplitPosition,l.PercentBehind,l.ResultsTable];this.chartTypeSelector=new C(this.topPanel.node(),t)},L.prototype.addComparisonSelector=function(){this.comparisonSelector=new v(this.topPanel.node(),I),null!==this.classes&&this.comparisonSelector.setClasses(this.classes)},L.prototype.addOriginalDataSelector=function(){this.originalDataSelector=new S(this.topPanel)},L.prototype.addDirectLink=function(){this.directLink=this.topPanel.append("a").classed("topRowStart",!0).attr("id","directLinkAnchor").attr("href",document.location.href),this.setDirectLinkMessages()},L.prototype.addWarningViewer=function(){this.warningViewer=new x(this.topPanel)},L.prototype.setDirectLinkMessages=function(){this.directLink.attr("title",e("DirectLinkToolTip","")).text(n("DirectLink"))},L.prototype.updateDirectLink=function(){var t={classes:this.classSelector.getSelectedClasses(),chartType:this.chartTypeSelector.getChartType(),compareWith:this.comparisonSelector.getComparisonType(),selected:this.selection.getSelectedIndexes(),stats:this.statisticsSelector.getVisibleStatistics(),showOriginal:this.courseClassSet.hasDubiousData()&&this.originalDataSelector.isOriginalDataSelected(),filterText:this.competitorList.getFilterText()},e=document.location.search,s=d(e,this.eventData,this.courseClassSet,t),n=document.location.href;this.directLink.attr("href",n.substring(0,n.length-e.length)+"?"+s.replace(/^\?+/,""))},L.prototype.addCompetitorList=function(){this.competitorList=new T(this.mainPanel.node(),I)},L.prototype.buildUi=function(){var t=d3.select("body");t.style("overflow","hidden"),this.container=t.append("div").attr("id","sbContainer"),this.topPanel=this.container.append("div"),this.drawLogo(),this.addLanguageSelector(),this.addSpacer(),this.addClassSelector(),this.addSpacer(),this.addChartTypeSelector(),this.addSpacer(),this.addComparisonSelector(),this.addOriginalDataSelector(),this.addSpacer(),this.addDirectLink(),this.addWarningViewer(),this.statisticsSelector=new y(this.topPanel.node()),this.topPanel.append("div").style("clear","both"),this.mainPanel=this.container.append("div"),this.addCompetitorList(),this.chart=new w(this.mainPanel.node()),this.resultsTable=new b(this.container.node()),this.resultsTable.hide();var e=this;$(window).resize(function(){e.handleWindowResize()}),$("input:text").bind("selectstart",function(t){t.stopPropagation()}),$(this.container.node()).bind("selectstart",function(){return!1}),$(document).keydown(function(t){27===t.which&&e.hideTransientElements()})},L.prototype.registerChangeHandlers=function(){var e=this;this.languageSelector.registerChangeHandler(function(){e.retranslate()}),this.classSelector.registerChangeHandler(function(t){e.selectClasses(t)}),this.chartTypeSelector.registerChangeHandler(function(t){e.selectChartTypeAndRedraw(t)}),this.comparisonSelector.registerChangeHandler(function(t){e.selectComparison(t)}),this.originalDataSelector.registerChangeHandler(function(t){e.showOriginalOrRepairedData(t)}),this.competitorList.registerChangeHandler(function(){e.handleFilterTextChanged()})},L.prototype.handleWindowResize=function(){null!==this.currentResizeTimeout&&clearTimeout(this.currentResizeTimeout);var t=this;this.currentResizeTimeout=setTimeout(function(){t.postResizeHook()},100)},L.prototype.postResizeHook=function(){this.currentResizeTimeout=null,this.setCompetitorListHeight(),this.setChartSize(),this.hideTransientElements(),this.redraw()},L.prototype.hideTransientElements=function(){d3.selectAll(".transient").style("display","none")},L.prototype.getHorizontalMargin=function(){var t=$("body"),e=$(this.container.node());return t.outerWidth(!0)-t.width()+(e.outerWidth()-e.width())},L.prototype.getVerticalMargin=function(){var t=$("body"),e=$(this.container.node());return t.outerHeight(!0)-t.height()+(e.outerHeight()-e.height())},L.prototype.getUsableHeight=function(){return $(window).outerHeight()-this.getVerticalMargin()-this.topBarHeight-$(this.topPanel.node()).height()},L.prototype.setCompetitorListHeight=function(){this.competitorList.setHeight(this.getUsableHeight())},L.prototype.setChartSize=function(){var t=this.getHorizontalMargin(),e=this.getVerticalMargin(),s=$(window).width()-t,n=$(window).height()-e-this.topBarHeight;$(this.container.node()).width(s).height(n);var i=s-this.competitorList.width()-2,r=this.getUsableHeight();this.chart.setSize(i,r)},L.prototype.drawChart=function(){if(!this.chartTypeSelector.getChartType().isResultsTable){this.currentVisibleStatistics=this.statisticsSelector.getVisibleStatistics(),null!==this.selectionChangeHandler&&this.selection.deregisterChangeHandler(this.selectionChangeHandler),null!==this.statisticsChangeHandler&&this.statisticsSelector.deregisterChangeHandler(this.statisticsChangeHandler);var e=this;if(this.selectionChangeHandler=function(){e.competitorList.enableOrDisableCrossingRunnersButton(),e.redraw(),e.updateDirectLink()},this.selection.registerChangeHandler(this.selectionChangeHandler),this.statisticsChangeHandler=function(t){e.currentVisibleStatistics=t,e.redraw(),e.updateDirectLink()},this.statisticsSelector.registerChangeHandler(this.statisticsChangeHandler),this.updateControlEnabledness(),0<this.classes.length){var t=this.comparisonSelector.getComparisonFunction();this.referenceCumTimes=t(this.courseClassSet),this.fastestCumTimes=this.courseClassSet.getFastestCumTimes(),this.chartData=this.courseClassSet.getChartData(this.referenceCumTimes,this.selection.getSelectedIndexes(),this.chartTypeSelector.getChartType()),this.redrawChart()}}},L.prototype.redrawChart=function(){var t={chartData:this.chartData,eventData:this.eventData,courseClassSet:this.courseClassSet,referenceCumTimes:this.referenceCumTimes,fastestCumTimes:this.fastestCumTimes};this.chart.drawChart(t,this.selection.getSelectedIndexes(),this.currentVisibleStatistics,this.chartTypeSelector.getChartType())},L.prototype.redraw=function(){var t=this.chartTypeSelector.getChartType();t.isResultsTable||(this.chartData=this.courseClassSet.getChartData(this.referenceCumTimes,this.selection.getSelectedIndexes(),t),this.redrawChart())},L.prototype.retranslate=function(){this.setLogoMessages(),this.languageSelector.setMessages(),this.classSelector.retranslate(),this.chartTypeSelector.setMessages(),this.comparisonSelector.setMessages(),this.originalDataSelector.setMessages(),this.setDirectLinkMessages(),this.statisticsSelector.setMessages(),this.warningViewer.setMessages(),this.competitorList.retranslate(),this.resultsTable.retranslate(),this.chartTypeSelector.getChartType().isResultsTable||this.redrawChart()},L.prototype.setClasses=function(t){this.currentClasses=t.map(function(t){return this.classes[t]},this),this.courseClassSet=new a(this.currentClasses),this.comparisonSelector.setCourseClassSet(this.courseClassSet),this.resultsTable.setClass(0<this.currentClasses.length?this.currentClasses[0]:null),this.enableOrDisableRaceGraph(),this.originalDataSelector.setVisible(this.courseClassSet.hasDubiousData())},L.prototype.initClasses=function(t){this.classSelector.selectClasses(t),this.setClasses(t),this.competitorList.setCompetitorList(this.courseClassSet.allCompetitors,1<this.currentClasses.length),this.selection=new r(this.courseClassSet.allCompetitors.length),this.competitorList.setSelection(this.selection),this.previousCompetitorList=this.courseClassSet.allCompetitors},L.prototype.selectClasses=function(t){0<t.length&&0<this.currentClasses.length&&this.classes[t[0]]===this.currentClasses[0]||this.selection.selectNone(),this.setClasses(t),this.competitorList.setCompetitorList(this.courseClassSet.allCompetitors,1<this.currentClasses.length),this.selection.migrate(this.previousCompetitorList,this.courseClassSet.allCompetitors),this.competitorList.selectionChanged(),this.chartTypeSelector.getChartType().isResultsTable||(this.setChartSize(),this.drawChart()),this.previousCompetitorList=this.courseClassSet.allCompetitors,this.updateDirectLink()},L.prototype.selectComparison=function(){this.drawChart(),this.updateDirectLink()},L.prototype.selectChartType=function(t){t.isResultsTable?(this.mainPanel.style("display","none"),this.container.style("width",null).style("height",null),d3.select("body").style("overflow",null),this.resultsTable.show()):(this.resultsTable.hide(),d3.select("body").style("overflow","hidden"),this.mainPanel.style("display",null),this.setChartSize()),this.updateControlEnabledness(),this.competitorList.setChartType(t)},L.prototype.selectChartTypeAndRedraw=function(t){this.selectChartType(t),t.isResultsTable||(this.setCompetitorListHeight(),
this.drawChart()),this.updateDirectLink()},L.prototype.selectOriginalOrRepairedData=function(t){t?c(this.eventData):h(this.eventData),this.eventData.determineTimeLosses()},L.prototype.showOriginalOrRepairedData=function(t){this.selectOriginalOrRepairedData(t),this.drawChart(),this.updateDirectLink()},L.prototype.handleFilterTextChanged=function(){this.setChartSize(),this.redraw(),this.updateDirectLink()},L.prototype.updateControlEnabledness=function(){var t=this.chartTypeSelector.getChartType();this.classSelector.setOtherClassesEnabled(!t.isResultsTable),this.comparisonSelector.setEnabled(!t.isResultsTable),this.statisticsSelector.setEnabled(!t.isResultsTable),this.originalDataSelector.setEnabled(!t.isResultsTable),this.competitorList.enableOrDisableCrossingRunnersButton()},L.prototype.updateFromQueryString=function(t){null===t.classes?this.setDefaultSelectedClass():this.initClasses(t.classes),null!==t.chartType&&(this.chartTypeSelector.setChartType(t.chartType),this.selectChartType(t.chartType)),null!==t.compareWith&&this.comparisonSelector.setComparisonType(t.compareWith.index,t.compareWith.runner),null!==t.selected&&this.selection.setSelectedIndexes(t.selected),null!==t.stats&&this.statisticsSelector.setVisibleStatistics(t.stats),t.showOriginal&&this.courseClassSet.hasDubiousData()&&(this.originalDataSelector.selectOriginalData(),this.selectOriginalOrRepairedData(!0)),""!==t.filterText&&this.competitorList.setFilterText(t.filterText)},L.prototype.setDefaultSelectedClass=function(){this.initClasses(0<this.classes.length?[0]:[])},SplitsBrowser.Viewer=L,SplitsBrowser.readEvent=function(t,e){if(D()){var s;try{s=u(t)}catch(t){if("InvalidData"===t.name)return void O("LoadFailedInvalidData",{$$MESSAGE$$:t.message});throw t}if(null===s)O("LoadFailedUnrecognisedData",{});else{s.needsRepair()&&h(s),"string"==typeof e&&(e={topBar:e}),s.determineTimeLosses(),e&&e.defaultLanguage&&o(e.defaultLanguage);var n=new L(e);n.buildUi(),n.setEvent(s);var i=document.location.search;if(null!==i&&0<i.length){var r=p(i,s);n.updateFromQueryString(r)}else n.setDefaultSelectedClass();n.setCompetitorListHeight(),n.setChartSize(),n.drawChart(),n.registerChangeHandlers()}}},SplitsBrowser.loadEvent=function(t,s){D()&&$.ajax({url:t,data:"",success:function(t,e){!function(t,e,s){"success"===e?SplitsBrowser.readEvent(t,s):O("LoadFailedStatusNotSuccess",{$$STATUS$$:e})}(t,e,s)},dataType:"text",error:B})}}();