@@ -220,7 +220,7 @@ function getColor($regionID, $seasonID) {
220
220
<i class="fa fa-angle-right"></i> You can edit any part of your forecast by redrawing just that part.<br />
221
221
<i class="fa fa-angle-right"></i> You can adjust a single point by dragging it up or down.<br />
222
222
The animation below demonstrates these actions.
223
- (If you don't see the animation, click <a target="_blank" href="images/tutorial.gif">here</a>.)
223
+ (If you don't see the animation, click <a target="_blank" href="images/tutorial.gif">here</a>.)<!-- ' -->
224
224
</p>
225
225
<video width="1112" height="480" controls autoplay loop>
226
226
<source src="images/tutorial.mp4" type="video/mp4">
@@ -323,6 +323,7 @@ function getColor($regionID, $seasonID) {
323
323
</div></div><div id="box_canvas"><canvas id="canvas" width="800" height="400"></canvas></div>
324
324
</div>
325
325
<script>
326
+ <!-- was: forecast.js -->
326
327
var DRAW_POINTS = true;
327
328
var TICK_SIZE = 5;
328
329
var MONTHS = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
@@ -427,8 +428,9 @@ function min(x1,x2) { if (x1<x2) { return x1; } return x2; }
427
428
} // end $output['regions'] as $r
428
429
?>
429
430
var selectedSeasons = [];
430
- var showLastForecast = true;
431
- var lastForecast = [<?php foreach ($ lastForecast ['wili ' ] as $ v ){printf ('%.3f, ' , $ v );} ?> ];
431
+ var showLastForecast = <?= $ lastForecast ['wili ' ] ? "true " : "false " ?> ;
432
+ var lastForecast = [<?php foreach ($ lastForecast ['wili ' ] as $ v ){printf ('%.3f, ' , $ v );} ?> ];
433
+ var lastForecastEpiweek = <?= $ lastForecast ['date ' ] ? $ lastForecast ['date ' ][0 ] : $ currentWeek ?> ;
432
434
var timeoutID;
433
435
var lastDrag = null;
434
436
var tooltip = null;
@@ -535,7 +537,7 @@ function drawPoints(xs, ys, start, end, style, g) {
535
537
for(var i = start; i < end; i++) {
536
538
if(ys[i] >= 0) {
537
539
g.beginPath();
538
- var x = getX(xs[i]);
540
+ var x = getX(modulusEpiweek( xs[i]) );
539
541
var y = getY(ys[i]);
540
542
g.moveTo(x, y);
541
543
g.lineTo(x + 1, y);
@@ -544,14 +546,17 @@ function drawPoints(xs, ys, start, end, style, g) {
544
546
}
545
547
}
546
548
547
- function drawCurve(curve, start, end, epiweekOffset, style) {
549
+ function drawCurve(curve, start, end, epiweekStart, style, do_drawPoints) {
550
+ if (typeof do_drawPoints == "undefined") {
551
+ do_drawPoints = DRAW_POINTS;
552
+ }
548
553
var g = getGraphics();
549
554
g.strokeStyle = style.color;
550
555
g.lineWidth = style.size * uiScale;
551
556
g.setLineDash(style.dash);
552
557
g.beginPath();
553
558
var first = true;
554
- var epiweek = addEpiweeks(xRange[0], epiweekOffset);
559
+ var epiweek = epiweekStart; // addEpiweeks(xRange[0], epiweekOffset);
555
560
var xs = [];
556
561
for(var i = start; i < end; i++) {
557
562
if(curve[i] >= 0) {
@@ -569,10 +574,13 @@ function drawCurve(curve, start, end, epiweekOffset, style) {
569
574
}
570
575
g.stroke();
571
576
g.setLineDash([]);
572
- if(DRAW_POINTS )
577
+ if(do_drawPoints )
573
578
drawPoints(xs, curve, start, end, style, g);
574
579
}
575
- function drawCurveXY(xs, ys, start, end, style) {
580
+ function drawCurveXY(xs, ys, start, end, style, do_drawPoints) {
581
+ if (typeof do_drawPoints == "undefined") {
582
+ do_drawPoints = DRAW_POINTS;
583
+ }
576
584
var g = getGraphics();
577
585
g.strokeStyle = style.color;
578
586
g.lineWidth = style.size * uiScale;
@@ -593,26 +601,27 @@ function drawCurveXY(xs, ys, start, end, style) {
593
601
}
594
602
g.stroke();
595
603
g.setLineDash([]);
596
- if(DRAW_POINTS ) drawPoints(xs, ys, start, end, style, g);
604
+ if(do_drawPoints ) drawPoints(xs, ys, start, end, style, g);
597
605
}
598
606
function stitchCurves(regionID, style, y2, xoffset) {
599
- if(forecast[regionID][0] < 0) {
600
- return;
601
- }
607
+ if(forecast[regionID][0] < 0) {
608
+ return;
609
+ }
602
610
if (typeof y2 == "undefined") {
603
611
y2 = getY(forecast[regionID][0]);
604
612
}
605
613
if (typeof xoffset == "undefined") {
606
614
xoffset = 1;
607
-
608
615
}
609
616
610
- var seasonIndex = seasonIndices[<?= $ currentYear ?> ];
611
- var seasonLength = seasonOffsets[seasonIndex+1] - seasonOffsets[seasonIndex];
612
- var x1 = getX(addEpiweeks(xRange[0], seasonLength - 1));
613
- var y1 = getY(pastWili[regionID][seasonOffsets[seasonIndex + 1] - 1]);
614
- var x2 = getX(addEpiweeks(currentWeek, xoffset));
615
- drawLine(x1, y1, x2, y2, style);
617
+ var seasonIndex = seasonIndices[<?= $ currentYear ?> ];
618
+ var end = ((seasonIndex+1)<seasonOffsets.length) ? seasonOffsets[seasonIndex+1] : (pastWili[regionID].length-1);
619
+ var seasonLength = end - seasonOffsets[seasonIndex];
620
+ var x1 = (addEpiweeks(xRange[0], seasonLength));
621
+ var y1 = getY(pastWili[regionID][end]);
622
+ var x2 = (addEpiweeks(currentWeek, xoffset));
623
+ //console.log("stitch curve:",seasonIndex,end,seasonLength,x1,y1,x2,y2);
624
+ drawLine(getX(x1), y1, getX(x2), y2, style);
616
625
}
617
626
function drawTooltip(g, str) {
618
627
str = ' ' + str;
@@ -736,7 +745,7 @@ function repaint() {
736
745
g.fillStyle=oldFillStyle;
737
746
738
747
//other regions or past seasons
739
- function repaintSelection(r, s) {
748
+ function repaintSelection(r, s, withPoints ) {
740
749
if (typeof s == "undefined") {
741
750
i = r;
742
751
var r = selectedSeasons[i][0];
@@ -747,49 +756,29 @@ function repaintSelection(r, s) {
747
756
// var length = totalWeeks;
748
757
<?php if (!$ showPandemic ) { ?> if(s == 2008) { length -= 12; }<?php } ?>
749
758
750
-
751
- // re the below: nah, we stored the dates for a reason.
752
- //if(start == 0) {
753
- // var nextStart = seasonOffsets[seasonIndices[s + 1]];
754
- // length = nextStart - start;
755
- // //todo: that -1 at the end should only be there if current season has 53 weeks and past season has 52 weeks
756
- // epiweekOffset = Math.max(0, totalWeeks - length -1);
757
- //}
758
-
759
759
var end = seasonIndices[s]+1 < seasonOffsets.length ? seasonOffsets[seasonIndices[s]+1] : pastWili[r].length;
760
- drawCurveXY(pastEpiweek[r], pastWili[r], start, end, style);
761
-
762
- // forecast gets drawn later, no need to do it twice
763
- //if(s == <?= $ currentYear ?> ) {
764
- // style = {color: style.color, size: style.size, dash: DASH_STYLE};
765
- // drawCurve(forecast[r], 0, 52, numPastWeeks + 1, style);
766
- // stitchCurves(r, style);
767
- //}
760
+ drawCurveXY(pastEpiweek[r], pastWili[r], start, end, style, withPoints);
768
761
}
769
762
for(var i = 0; i < selectedSeasons.length; i++) {
770
763
var isCurrentSeason = (selectedSeasons[i][1] == <?= $ currentYear ?> );
771
764
if(selectedSeasons[i][0] == regionID && isCurrentSeason) {
772
765
//Skip the current region's latest season
773
766
continue;
774
767
}
775
- repaintSelection(i);
768
+ repaintSelection(i, undefined, false );
776
769
}
777
770
778
771
//last forecast
779
772
var lfStyle = {color: '#aaa', size: 2, dash: DASH_STYLE};
780
773
if(showLastForecast) {
781
- // shift x axis by 30 weeks.
782
- drawCurve(lastForecast, 0, lastForecast.length, totalWeeks - lastForecast.length, lfStyle);
774
+ drawCurve(lastForecast, 0, lastForecast.length, lastForecastEpiweek, lfStyle);
783
775
stitchCurves(regionID, lfStyle, getY(lastForecast[0]), 0);
784
776
}
785
777
786
778
//current region and latest season
787
- repaintSelection(regionID, <?= $ currentYear ?> );
779
+ repaintSelection(regionID, <?= $ currentYear ?> , true );
788
780
var style = {color: '#000', size: 2, dash: DASH_STYLE};
789
- //var start = seasonOffsets[seasonOffsets.length - 1];
790
- //var end = Math.min(pastWili[regionID].length, start + totalWeeks);
791
- //drawCurve(pastWili[regionID], start, end, 0, style);
792
- drawCurve(forecast[regionID], 0, 52, numPastWeeks + 1, style);
781
+ drawCurve(forecast[regionID], 0, 52, currentWeek+1, style);
793
782
stitchCurves(regionID, style);
794
783
795
784
//nowcast
0 commit comments