コミットメタ情報

リビジョンd35581e3a4e9fb15e48d52c85b9df442da08e3d7 (tree)
日時2018-04-29 19:13:37
作者Kazuhiro Fujieda <fujieda@user...>
コミッターKazuhiro Fujieda

ログメッセージ

資材グラフの描画でデータの取得を必要な分だけにする

変更サマリ

差分

--- a/LogViewer/tags.tag
+++ b/LogViewer/tags.tag
@@ -300,21 +300,55 @@ this.resize = function() {
300300 };
301301
302302 this.drawChart = function(data) {
303+ range = this.calcRange(opts.chartSpec.seqRange);
304+ if (range.last === 0)
305+ return;
303306 if (!data) {
304307 $('#loading').show();
305308 $.ajax({
306- url: "./資材ログ.json?number=true",
309+ url: "./資材ログ.json?number=true" +
310+ "&from=" + range.first + "&to=" + range.last,
307311 success: function(d) { self.drawChart(d); },
308312 dataType: "json", cache: false
309313 });
310314 return;
311315 }
312316 var picked;
313- picked = this.pickChartData(data.data, opts.chartSpec.seqRange);
317+ picked = this.pickChartData(data.data, range);
314318 picked.data.unshift(self.header);
315319 this.drawSeqChart(picked);
316320 };
317321
322+this.calcRange = function(range) {
323+ var first = 0;
324+ var last = (new Date()).valueOf();
325+ switch (range) {
326+ case 0:
327+ first = moment(last).subtract(24, 'hours').valueOf();
328+ break;
329+ case 1:
330+ first = moment(last).subtract(7, 'days').valueOf();
331+ break;
332+ case 2:
333+ first = moment(last).subtract(1, 'months').valueOf();
334+ break;
335+ case 3:
336+ first = moment(last).subtract(3, 'months').valueOf();
337+ break;
338+ case 4:
339+ break;
340+ case 5:
341+ var fromDate = $('#chart_from').datepicker("getDate");
342+ var toDate = $('#chart_to').datepicker("getDate");
343+ if (fromDate === null || toDate === null)
344+ return {first: 0, last:0};
345+ first = fromDate.valueOf() + 3600 * 5000;
346+ last = toDate.valueOf() + this.oneDay + 3600 * 5000;
347+ break;
348+ }
349+ return {first: first, last: last};
350+}
351+
318352 this.unselected = {};
319353
320354 this.drawSeqChart = function(picked) {
@@ -386,35 +420,9 @@ this.pickChartData = function(data, range) {
386420 var newdata = [];
387421 var ticks = [];
388422 var grid = [];
389- var first = data[0][0];
390- var last = data[data.length - 1][0];
423+ var first = range.first;
424+ var last = range.last;
391425 var interval, tickInterval, lastTick;
392- switch (range) {
393- case 0:
394- first = moment(last).subtract(24, 'hours').valueOf();
395- break;
396- case 1:
397- first = moment(last).subtract(7, 'days').valueOf();
398- break;
399- case 2:
400- first = moment(last).subtract(1, 'months').valueOf();
401- break;
402- case 3:
403- first = moment(last).subtract(3, 'months').valueOf();
404- break;
405- case 4:
406- break;
407- case 5:
408- var fromDate = $('#chart_from').datepicker("getDate");
409- var toDate = $('#chart_to').datepicker("getDate");
410- if (fromDate === null || toDate === null)
411- return { data: [], tick: [], grid: [] };
412- var from = fromDate.valueOf() + 3600 * 5000;
413- var to = toDate.valueOf() + this.oneDay + 3600 * 5000;
414- first = Math.max(first, from);
415- last = Math.min(last, to);
416- break;
417- }
418426 if (last <= first + this.oneDay) {
419427 interval = 1000;
420428 tickInterval = 3600 * 1000;
@@ -498,21 +506,54 @@ this.resize = function() {
498506 };
499507
500508 this.drawChart = function(data) {
509+ range = this.calcRange(opts.chartSpec.diffRange);
510+ if (range.last === 0)
511+ return;
501512 if (!data) {
502513 $('#loading').show();
503514 $.ajax({
504- url: "./資材ログ.json?number=true",
515+ url: "./資材ログ.json?number=true" +
516+ "&from=" + range.first + "&to=" + range.last,
505517 success: function(d) { self.drawChart(d); },
506518 dataType: "json", cache: false
507519 });
508520 return;
509521 }
510522 var picked;
511- picked = this.pickChartData(data.data, opts.chartSpec.diffRange);
523+ picked = this.pickChartData(data.data, range);
512524 picked.data.unshift(self.header);
513525 this.drawDiffChart(picked);
514526 };
515527
528+this.calcRange = function(range) {
529+ var first = 0;
530+ var last = (new Date()).valueOf();
531+ switch (range) {
532+ case 0:
533+ first = moment(last).subtract(1, 'months').valueOf();
534+ break;
535+ case 1:
536+ first = moment(last).subtract(3, 'months').valueOf();
537+ break;
538+ case 2:
539+ first = moment(last).subtract(6, 'months').subtract(1, 'weeks').valueOf();
540+ break;
541+ case 3:
542+ break;
543+ case 4:
544+ var fromDate = $('#chart_from').datepicker("getDate");
545+ var toDate = $('#chart_to').datepicker("getDate");
546+ if (fromDate === null || toDate === null)
547+ return {first: 0, last: 0};
548+ var from = fromDate.valueOf() + 3600 * 5000;
549+ var to = toDate.valueOf() + this.oneDay + 3600 * 5000;
550+ first = Math.max(first, from);
551+ last = Math.min(last, to);
552+ break;
553+ }
554+ return {first: first, last: last};
555+}
556+
516557 this.unselected = {};
517558
518559 this.drawDiffChart = function(picked) {
@@ -585,33 +626,12 @@ this.pickChartData = function(data, range) {
585626 var newdata = [];
586627 var ticks = [];
587628 var grid = [];
588- var first = data[0][0];
589- var last = data[data.length - 1][0];
629+ var first = range.first;
630+ var last = range.last;
590631 var interval, tickInterval, lastTick;
591- switch (range) {
592- case 0:
593- first = moment(last).subtract(1, 'months').valueOf();
594- break;
595- case 1:
596- first = moment(last).subtract(3, 'months').valueOf();
597- break;
598- case 2:
599- first = moment(last).subtract(6, 'months').subtract(1, 'weeks').valueOf();
600- break;
601- case 3:
602- return this.pickMonthlyChartData(data);
603- case 4:
604- var fromDate = $('#chart_from').datepicker("getDate");
605- var toDate = $('#chart_to').datepicker("getDate");
606- if (fromDate === null || toDate === null)
607- return { data: [], tick: [], grid: [] };
608- var from = fromDate.valueOf() + 3600 * 5000;
609- var to = toDate.valueOf() + this.oneDay + 3600 * 5000;
610- first = Math.max(first, from);
611- last = Math.min(last, to);
612- break;
613- }
614632 var barWidth;
633+ if (first === 0)
634+ return this.pickMonthlyChartData(data);
615635 if (last <= first + this.oneDay * 2 * 31) {
616636 interval = this.oneDay;
617637 tickInterval = this.oneDay * 2;
旧リポジトリブラウザで表示