Skip to content

Commit 7f8c03e

Browse files
committed
Save bytes by aliasing d3.time.
1 parent e6551e5 commit 7f8c03e

16 files changed

Lines changed: 203 additions & 199 deletions

d3.js

Lines changed: 86 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -8310,8 +8310,7 @@ d3 = function() {
83108310
sw: "nesw-resize"
83118311
};
83128312
var d3_svg_brushResizes = [ [ "n", "e", "s", "w", "nw", "ne", "se", "sw" ], [ "e", "w" ], [ "n", "s" ], [] ];
8313-
d3.time = {};
8314-
var d3_time = Date, d3_time_daySymbols = [ "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" ];
8313+
var d3_time = d3.time = {}, d3_date = Date, d3_time_daySymbols = [ "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" ];
83158314
function d3_time_utc() {
83168315
this._ = new Date(arguments.length > 1 ? Date.UTC.apply(this, arguments) : arguments[0]);
83178316
}
@@ -8386,11 +8385,11 @@ d3 = function() {
83868385
return date - d0 < d1 - date ? d0 : d1;
83878386
}
83888387
function ceil(date) {
8389-
step(date = local(new d3_time(date - 1)), 1);
8388+
step(date = local(new d3_date(date - 1)), 1);
83908389
return date;
83918390
}
83928391
function offset(date, k) {
8393-
step(date = new d3_time(+date), k);
8392+
step(date = new d3_date(+date), k);
83948393
return date;
83958394
}
83968395
function range(t0, t1, dt) {
@@ -8407,12 +8406,12 @@ d3 = function() {
84078406
}
84088407
function range_utc(t0, t1, dt) {
84098408
try {
8410-
d3_time = d3_time_utc;
8409+
d3_date = d3_time_utc;
84118410
var utc = new d3_time_utc();
84128411
utc._ = t0;
84138412
return range(utc, t1, dt);
84148413
} finally {
8415-
d3_time = Date;
8414+
d3_date = Date;
84168415
}
84178416
}
84188417
local.floor = local;
@@ -8431,65 +8430,66 @@ d3 = function() {
84318430
function d3_time_interval_utc(method) {
84328431
return function(date, k) {
84338432
try {
8434-
d3_time = d3_time_utc;
8433+
d3_date = d3_time_utc;
84358434
var utc = new d3_time_utc();
84368435
utc._ = date;
84378436
return method(utc, k)._;
84388437
} finally {
8439-
d3_time = Date;
8438+
d3_date = Date;
84408439
}
84418440
};
84428441
}
8443-
d3.time.year = d3_time_interval(function(date) {
8444-
date = d3.time.day(date);
8442+
d3_time.year = d3_time_interval(function(date) {
8443+
date = d3_time.day(date);
84458444
date.setMonth(0, 1);
84468445
return date;
84478446
}, function(date, offset) {
84488447
date.setFullYear(date.getFullYear() + offset);
84498448
}, function(date) {
84508449
return date.getFullYear();
84518450
});
8452-
d3.time.years = d3.time.year.range;
8453-
d3.time.years.utc = d3.time.year.utc.range;
8454-
d3.time.day = d3_time_interval(function(date) {
8455-
var day = new d3_time(2e3, 0);
8451+
d3_time.years = d3_time.year.range;
8452+
d3_time.years.utc = d3_time.year.utc.range;
8453+
d3_time.day = d3_time_interval(function(date) {
8454+
var day = new d3_date(2e3, 0);
84568455
day.setFullYear(date.getFullYear(), date.getMonth(), date.getDate());
84578456
return day;
84588457
}, function(date, offset) {
84598458
date.setDate(date.getDate() + offset);
84608459
}, function(date) {
84618460
return date.getDate() - 1;
84628461
});
8463-
d3.time.days = d3.time.day.range;
8464-
d3.time.days.utc = d3.time.day.utc.range;
8465-
d3.time.dayOfYear = function(date) {
8466-
var year = d3.time.year(date);
8462+
d3_time.days = d3_time.day.range;
8463+
d3_time.days.utc = d3_time.day.utc.range;
8464+
d3_time.dayOfYear = function(date) {
8465+
var year = d3_time.year(date);
84678466
return Math.floor((date - year - (date.getTimezoneOffset() - year.getTimezoneOffset()) * 6e4) / 864e5);
84688467
};
84698468
d3_time_daySymbols.forEach(function(day, i) {
84708469
day = day.toLowerCase();
84718470
i = 7 - i;
8472-
var interval = d3.time[day] = d3_time_interval(function(date) {
8473-
(date = d3.time.day(date)).setDate(date.getDate() - (date.getDay() + i) % 7);
8471+
var interval = d3_time[day] = d3_time_interval(function(date) {
8472+
(date = d3_time.day(date)).setDate(date.getDate() - (date.getDay() + i) % 7);
84748473
return date;
84758474
}, function(date, offset) {
84768475
date.setDate(date.getDate() + Math.floor(offset) * 7);
84778476
}, function(date) {
8478-
var day = d3.time.year(date).getDay();
8479-
return Math.floor((d3.time.dayOfYear(date) + (day + i) % 7) / 7) - (day !== i);
8477+
var day = d3_time.year(date).getDay();
8478+
return Math.floor((d3_time.dayOfYear(date) + (day + i) % 7) / 7) - (day !== i);
84808479
});
8481-
d3.time[day + "s"] = interval.range;
8482-
d3.time[day + "s"].utc = interval.utc.range;
8483-
d3.time[day + "OfYear"] = function(date) {
8484-
var day = d3.time.year(date).getDay();
8485-
return Math.floor((d3.time.dayOfYear(date) + (day + i) % 7) / 7);
8480+
d3_time[day + "s"] = interval.range;
8481+
d3_time[day + "s"].utc = interval.utc.range;
8482+
d3_time[day + "OfYear"] = function(date) {
8483+
var day = d3_time.year(date).getDay();
8484+
return Math.floor((d3_time.dayOfYear(date) + (day + i) % 7) / 7);
84868485
};
84878486
});
8488-
d3.time.week = d3.time.sunday;
8489-
d3.time.weeks = d3.time.sunday.range;
8490-
d3.time.weeks.utc = d3.time.sunday.utc.range;
8491-
d3.time.weekOfYear = d3.time.sundayOfYear;
8492-
d3.time.format = function(template) {
8487+
d3_time.week = d3_time.sunday;
8488+
d3_time.weeks = d3_time.sunday.range;
8489+
d3_time.weeks.utc = d3_time.sunday.utc.range;
8490+
d3_time.weekOfYear = d3_time.sundayOfYear;
8491+
d3_time.format = d3_time_format;
8492+
function d3_time_format(template) {
84938493
var n = template.length;
84948494
function format(date) {
84958495
var string = [], i = -1, j = 0, c, p, f;
@@ -8517,7 +8517,7 @@ d3 = function() {
85178517
}, i = d3_time_parse(d, template, string, 0);
85188518
if (i != string.length) return null;
85198519
if ("p" in d) d.H = d.H % 12 + d.p * 12;
8520-
var date = new d3_time();
8520+
var date = new d3_date();
85218521
if ("j" in d) date.setFullYear(d.y, 0, d.j); else if ("w" in d && ("W" in d || "U" in d)) {
85228522
date.setFullYear(d.y, 0, 1);
85238523
date.setFullYear(d.y, 0, "W" in d ? (d.w + 6) % 7 + d.W * 7 - (date.getDay() + 5) % 7 : d.w + d.U * 7 - (date.getDay() + 6) % 7);
@@ -8529,7 +8529,7 @@ d3 = function() {
85298529
return template;
85308530
};
85318531
return format;
8532-
};
8532+
}
85338533
function d3_time_parse(date, template, string, j) {
85348534
var c, p, i = 0, n = template.length, m = string.length;
85358535
while (i < n) {
@@ -8575,7 +8575,7 @@ d3 = function() {
85758575
B: function(d) {
85768576
return d3_time_months[d.getMonth()];
85778577
},
8578-
c: d3.time.format(d3_time_formatDateTime),
8578+
c: d3_time_format(d3_time_formatDateTime),
85798579
d: function(d, p) {
85808580
return d3_time_formatPad(d.getDate(), p, 2);
85818581
},
@@ -8589,7 +8589,7 @@ d3 = function() {
85898589
return d3_time_formatPad(d.getHours() % 12 || 12, p, 2);
85908590
},
85918591
j: function(d, p) {
8592-
return d3_time_formatPad(1 + d3.time.dayOfYear(d), p, 3);
8592+
return d3_time_formatPad(1 + d3_time.dayOfYear(d), p, 3);
85938593
},
85948594
L: function(d, p) {
85958595
return d3_time_formatPad(d.getMilliseconds(), p, 3);
@@ -8607,16 +8607,16 @@ d3 = function() {
86078607
return d3_time_formatPad(d.getSeconds(), p, 2);
86088608
},
86098609
U: function(d, p) {
8610-
return d3_time_formatPad(d3.time.sundayOfYear(d), p, 2);
8610+
return d3_time_formatPad(d3_time.sundayOfYear(d), p, 2);
86118611
},
86128612
w: function(d) {
86138613
return d.getDay();
86148614
},
86158615
W: function(d, p) {
8616-
return d3_time_formatPad(d3.time.mondayOfYear(d), p, 2);
8616+
return d3_time_formatPad(d3_time.mondayOfYear(d), p, 2);
86178617
},
8618-
x: d3.time.format(d3_time_formatDate),
8619-
X: d3.time.format(d3_time_formatTime),
8618+
x: d3_time_format(d3_time_formatDate),
8619+
X: d3_time_format(d3_time_formatTime),
86208620
y: function(d, p) {
86218621
return d3_time_formatPad(d.getFullYear() % 100, p, 2);
86228622
},
@@ -8763,32 +8763,33 @@ d3 = function() {
87638763
var n = d3_time_percentRe.exec(string.substring(i, i + 1));
87648764
return n ? i + n[0].length : -1;
87658765
}
8766-
d3.time.format.utc = function(template) {
8767-
var local = d3.time.format(template);
8766+
d3_time_format.utc = d3_time_formatUtc;
8767+
function d3_time_formatUtc(template) {
8768+
var local = d3_time_format(template);
87688769
function format(date) {
87698770
try {
8770-
d3_time = d3_time_utc;
8771-
var utc = new d3_time();
8771+
d3_date = d3_time_utc;
8772+
var utc = new d3_date();
87728773
utc._ = date;
87738774
return local(utc);
87748775
} finally {
8775-
d3_time = Date;
8776+
d3_date = Date;
87768777
}
87778778
}
87788779
format.parse = function(string) {
87798780
try {
8780-
d3_time = d3_time_utc;
8781+
d3_date = d3_time_utc;
87818782
var date = local.parse(string);
87828783
return date && date._;
87838784
} finally {
8784-
d3_time = Date;
8785+
d3_date = Date;
87858786
}
87868787
};
87878788
format.toString = local.toString;
87888789
return format;
8789-
};
8790-
var d3_time_formatIso = d3.time.format.utc("%Y-%m-%dT%H:%M:%S.%LZ");
8791-
d3.time.format.iso = Date.prototype.toISOString && +new Date("2000-01-01T00:00:00.000Z") ? d3_time_formatIsoNative : d3_time_formatIso;
8790+
}
8791+
var d3_time_formatIso = d3_time_formatUtc("%Y-%m-%dT%H:%M:%S.%LZ");
8792+
d3_time_format.iso = Date.prototype.toISOString && +new Date("2000-01-01T00:00:00.000Z") ? d3_time_formatIsoNative : d3_time_formatIso;
87928793
function d3_time_formatIsoNative(date) {
87938794
return date.toISOString();
87948795
}
@@ -8797,45 +8798,45 @@ d3 = function() {
87978798
return isNaN(date) ? null : date;
87988799
};
87998800
d3_time_formatIsoNative.toString = d3_time_formatIso.toString;
8800-
d3.time.second = d3_time_interval(function(date) {
8801-
return new d3_time(Math.floor(date / 1e3) * 1e3);
8801+
d3_time.second = d3_time_interval(function(date) {
8802+
return new d3_date(Math.floor(date / 1e3) * 1e3);
88028803
}, function(date, offset) {
88038804
date.setTime(date.getTime() + Math.floor(offset) * 1e3);
88048805
}, function(date) {
88058806
return date.getSeconds();
88068807
});
8807-
d3.time.seconds = d3.time.second.range;
8808-
d3.time.seconds.utc = d3.time.second.utc.range;
8809-
d3.time.minute = d3_time_interval(function(date) {
8810-
return new d3_time(Math.floor(date / 6e4) * 6e4);
8808+
d3_time.seconds = d3_time.second.range;
8809+
d3_time.seconds.utc = d3_time.second.utc.range;
8810+
d3_time.minute = d3_time_interval(function(date) {
8811+
return new d3_date(Math.floor(date / 6e4) * 6e4);
88118812
}, function(date, offset) {
88128813
date.setTime(date.getTime() + Math.floor(offset) * 6e4);
88138814
}, function(date) {
88148815
return date.getMinutes();
88158816
});
8816-
d3.time.minutes = d3.time.minute.range;
8817-
d3.time.minutes.utc = d3.time.minute.utc.range;
8818-
d3.time.hour = d3_time_interval(function(date) {
8817+
d3_time.minutes = d3_time.minute.range;
8818+
d3_time.minutes.utc = d3_time.minute.utc.range;
8819+
d3_time.hour = d3_time_interval(function(date) {
88198820
var timezone = date.getTimezoneOffset() / 60;
8820-
return new d3_time((Math.floor(date / 36e5 - timezone) + timezone) * 36e5);
8821+
return new d3_date((Math.floor(date / 36e5 - timezone) + timezone) * 36e5);
88218822
}, function(date, offset) {
88228823
date.setTime(date.getTime() + Math.floor(offset) * 36e5);
88238824
}, function(date) {
88248825
return date.getHours();
88258826
});
8826-
d3.time.hours = d3.time.hour.range;
8827-
d3.time.hours.utc = d3.time.hour.utc.range;
8828-
d3.time.month = d3_time_interval(function(date) {
8829-
date = d3.time.day(date);
8827+
d3_time.hours = d3_time.hour.range;
8828+
d3_time.hours.utc = d3_time.hour.utc.range;
8829+
d3_time.month = d3_time_interval(function(date) {
8830+
date = d3_time.day(date);
88308831
date.setDate(1);
88318832
return date;
88328833
}, function(date, offset) {
88338834
date.setMonth(date.getMonth() + offset);
88348835
}, function(date) {
88358836
return date.getMonth();
88368837
});
8837-
d3.time.months = d3.time.month.range;
8838-
d3.time.months.utc = d3.time.month.utc.range;
8838+
d3_time.months = d3_time.month.range;
8839+
d3_time.months.utc = d3_time.month.utc.range;
88398840
function d3_time_scale(linear, methods, format) {
88408841
function scale(x) {
88418842
return linear(x);
@@ -8883,25 +8884,25 @@ d3 = function() {
88838884
};
88848885
}
88858886
var d3_time_scaleSteps = [ 1e3, 5e3, 15e3, 3e4, 6e4, 3e5, 9e5, 18e5, 36e5, 108e5, 216e5, 432e5, 864e5, 1728e5, 6048e5, 2592e6, 7776e6, 31536e6 ];
8886-
var d3_time_scaleLocalMethods = [ [ d3.time.second, 1 ], [ d3.time.second, 5 ], [ d3.time.second, 15 ], [ d3.time.second, 30 ], [ d3.time.minute, 1 ], [ d3.time.minute, 5 ], [ d3.time.minute, 15 ], [ d3.time.minute, 30 ], [ d3.time.hour, 1 ], [ d3.time.hour, 3 ], [ d3.time.hour, 6 ], [ d3.time.hour, 12 ], [ d3.time.day, 1 ], [ d3.time.day, 2 ], [ d3.time.week, 1 ], [ d3.time.month, 1 ], [ d3.time.month, 3 ], [ d3.time.year, 1 ] ];
8887-
var d3_time_scaleLocalFormats = [ [ d3.time.format("%Y"), d3_true ], [ d3.time.format("%B"), function(d) {
8887+
var d3_time_scaleLocalMethods = [ [ d3_time.second, 1 ], [ d3_time.second, 5 ], [ d3_time.second, 15 ], [ d3_time.second, 30 ], [ d3_time.minute, 1 ], [ d3_time.minute, 5 ], [ d3_time.minute, 15 ], [ d3_time.minute, 30 ], [ d3_time.hour, 1 ], [ d3_time.hour, 3 ], [ d3_time.hour, 6 ], [ d3_time.hour, 12 ], [ d3_time.day, 1 ], [ d3_time.day, 2 ], [ d3_time.week, 1 ], [ d3_time.month, 1 ], [ d3_time.month, 3 ], [ d3_time.year, 1 ] ];
8888+
var d3_time_scaleLocalFormats = [ [ d3_time_format("%Y"), d3_true ], [ d3_time_format("%B"), function(d) {
88888889
return d.getMonth();
8889-
} ], [ d3.time.format("%b %d"), function(d) {
8890+
} ], [ d3_time_format("%b %d"), function(d) {
88908891
return d.getDate() != 1;
8891-
} ], [ d3.time.format("%a %d"), function(d) {
8892+
} ], [ d3_time_format("%a %d"), function(d) {
88928893
return d.getDay() && d.getDate() != 1;
8893-
} ], [ d3.time.format("%I %p"), function(d) {
8894+
} ], [ d3_time_format("%I %p"), function(d) {
88948895
return d.getHours();
8895-
} ], [ d3.time.format("%I:%M"), function(d) {
8896+
} ], [ d3_time_format("%I:%M"), function(d) {
88968897
return d.getMinutes();
8897-
} ], [ d3.time.format(":%S"), function(d) {
8898+
} ], [ d3_time_format(":%S"), function(d) {
88988899
return d.getSeconds();
8899-
} ], [ d3.time.format(".%L"), function(d) {
8900+
} ], [ d3_time_format(".%L"), function(d) {
89008901
return d.getMilliseconds();
89018902
} ] ];
89028903
var d3_time_scaleLocalFormat = d3_time_scaleFormat(d3_time_scaleLocalFormats);
8903-
d3_time_scaleLocalMethods.year = d3.time.year;
8904-
d3.time.scale = function() {
8904+
d3_time_scaleLocalMethods.year = d3_time.year;
8905+
d3_time.scale = function() {
89058906
return d3_time_scale(d3.scale.linear(), d3_time_scaleLocalMethods, d3_time_scaleLocalFormat);
89068907
};
89078908
var d3_time_scaleMilliseconds = {
@@ -8912,24 +8913,24 @@ d3 = function() {
89128913
var d3_time_scaleUTCMethods = d3_time_scaleLocalMethods.map(function(m) {
89138914
return [ m[0].utc, m[1] ];
89148915
});
8915-
var d3_time_scaleUTCFormats = [ [ d3.time.format.utc("%Y"), d3_true ], [ d3.time.format.utc("%B"), function(d) {
8916+
var d3_time_scaleUTCFormats = [ [ d3_time_formatUtc("%Y"), d3_true ], [ d3_time_formatUtc("%B"), function(d) {
89168917
return d.getUTCMonth();
8917-
} ], [ d3.time.format.utc("%b %d"), function(d) {
8918+
} ], [ d3_time_formatUtc("%b %d"), function(d) {
89188919
return d.getUTCDate() != 1;
8919-
} ], [ d3.time.format.utc("%a %d"), function(d) {
8920+
} ], [ d3_time_formatUtc("%a %d"), function(d) {
89208921
return d.getUTCDay() && d.getUTCDate() != 1;
8921-
} ], [ d3.time.format.utc("%I %p"), function(d) {
8922+
} ], [ d3_time_formatUtc("%I %p"), function(d) {
89228923
return d.getUTCHours();
8923-
} ], [ d3.time.format.utc("%I:%M"), function(d) {
8924+
} ], [ d3_time_formatUtc("%I:%M"), function(d) {
89248925
return d.getUTCMinutes();
8925-
} ], [ d3.time.format.utc(":%S"), function(d) {
8926+
} ], [ d3_time_formatUtc(":%S"), function(d) {
89268927
return d.getUTCSeconds();
8927-
} ], [ d3.time.format.utc(".%L"), function(d) {
8928+
} ], [ d3_time_formatUtc(".%L"), function(d) {
89288929
return d.getUTCMilliseconds();
89298930
} ] ];
89308931
var d3_time_scaleUTCFormat = d3_time_scaleFormat(d3_time_scaleUTCFormats);
8931-
d3_time_scaleUTCMethods.year = d3.time.year.utc;
8932-
d3.time.scale.utc = function() {
8932+
d3_time_scaleUTCMethods.year = d3_time.year.utc;
8933+
d3_time.scale.utc = function() {
89338934
return d3_time_scale(d3.scale.linear(), d3_time_scaleUTCMethods, d3_time_scaleUTCFormat);
89348935
};
89358936
d3.text = d3_xhrType(function(request) {

d3.min.js

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/time/day.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import "interval";
22
import "time";
33
import "year";
44

5-
d3.time.day = d3_time_interval(function(date) {
6-
var day = new d3_time(2000, 0);
5+
d3_time.day = d3_time_interval(function(date) {
6+
var day = new d3_date(2000, 0);
77
day.setFullYear(date.getFullYear(), date.getMonth(), date.getDate());
88
return day;
99
}, function(date, offset) {
@@ -12,10 +12,10 @@ d3.time.day = d3_time_interval(function(date) {
1212
return date.getDate() - 1;
1313
});
1414

15-
d3.time.days = d3.time.day.range;
16-
d3.time.days.utc = d3.time.day.utc.range;
15+
d3_time.days = d3_time.day.range;
16+
d3_time.days.utc = d3_time.day.utc.range;
1717

18-
d3.time.dayOfYear = function(date) {
19-
var year = d3.time.year(date);
18+
d3_time.dayOfYear = function(date) {
19+
var year = d3_time.year(date);
2020
return Math.floor((date - year - (date.getTimezoneOffset() - year.getTimezoneOffset()) * 6e4) / 864e5);
2121
};

0 commit comments

Comments
 (0)