-
Notifications
You must be signed in to change notification settings - Fork 0
/
FundMgrPg
749 lines (624 loc) · 25.4 KB
/
FundMgrPg
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
<!DOCTYPE html>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<body>
<link rel="stylesheet" href="jquery-ui-1.11.4.custom/mfMgr.css">
<link rel="stylesheet" href="jquery-ui-1.11.4.custom/jquery-ui.css">
<script src="jquery-ui-1.11.4.custom/external/jquery/jquery.js"></script>
<script src="jquery-ui-1.11.4.custom/jquery-ui.js"></script>
<script src="jquery-ui-1.11.4.custom/jquery.ui.slider.js"></script>
<script src="jquery-ui-1.11.4.custom/d3.min.js"></script>
<script src="jquery-ui-1.11.4.custom/external/jquery/jquery-labrat-tip.js"></script>
<script src="jquery-ui-1.11.4.custom/external/jquery/d3-legend.js"></script>
<script src="jquery-ui-1.11.4.custom/dataManipulator.js"></script>
<script>
//global VARIABLES
window.master_array = new Array();
window.bm_array = new Array();
window.bm_Data_ = [];
//this will store the fund selected by the user
window.current_MF_Data_ = [];
window._BM_MF_FromDt_idx = -1;
window._BM_MF_ToDt_idx = -1;
var colors = d3.scale.category20();
//to be read from a static file
window.MFRiskReturnHeight = 400;
window.MFRiskReturnWidth = 500;
window.MFVsBMHeight = 400;
window.MFVsBMWidth = 700;
window.dispCircleRadius = 8;
window.dispBMName = '';
window.dispMFName = '';
window.isDragging = false;
//given that both BM and MF will have the same Date range
//we can read the current BM values itself
function findIndex(findDt){
for(ctr = 0 ;ctr < bm_Data_.length; ctr++){
if( (bm_Data_[ctr].Date).getTime() >= findDt.getTime() )
return ctr;
}
return -1;
}
// to be called initially
function initGlobalSetBM(){
//FOR NOW use 0 index .. but we need to have a map
// for MF data and bm index
window.bm_Data_ = retDefaultBMData();
dispBMName = retDefaultBMName();
window.bm_Data_.forEach(function(d) {
d.Date = new Date(d.Date);
d.closing = +d.closing;
});
console.log(' JUST FINISHED !!');
//first time user sees chart she should be able to see only 50% of the total time period
//then these 2 values are continually upDated in dragslider function
if(window._BM_MF_FromDt_idx == -1 && window._BM_MF_ToDt_idx == -1){
_BM_MF_FromDt_idx = Math.round( bm_Data_.length*(0.5) );
_BM_MF_ToDt_idx = bm_Data_.length-1;
}
//initialize the autocomplete list
}
function setBMDataBasedOnMF(_mf_name){
dispBMName = retBMName(_mf_name);
dispMFName = _mf_name;
bm_Data_ = retBMData(_mf_name);
current_MF_Data_ = retMFData (_mf_name);
//init
bm_Data_.forEach(function(d) {
d.Date = new Date(d.Date);
d.closing = +d.closing;
});
current_MF_Data_.forEach(function(d) {
d.Date = new Date(d.Date);
d.closing = +d.closing;
});
console.log("IN setBMDataBasedOnMF value of MF "+_mf_name+" and length "+ current_MF_Data_.length);
}
function _reScaleBM_MF_axes(init_Data_) {
console.log('RESCALING !!');
if (current_MF_Data_.length == 0)
current_MF_Data_ = bm_Data_;
//both slices will have window prefix since we intend to use them outside this function
//defensive coding
if(_BM_MF_FromDt_idx >= 0 && _BM_MF_ToDt_idx >= 0){
window.sliced_bm_Data_ = calcDailyCumuChanges( bm_Data_.slice(_BM_MF_FromDt_idx, _BM_MF_ToDt_idx) );
if(init_Data_ != null) //meaning its being called by click on mf circle ; else init
current_MF_Data_ = init_Data_;
window.current_Data_ = calcDailyCumuChanges( current_MF_Data_.slice(_BM_MF_FromDt_idx, _BM_MF_ToDt_idx) );
}
var minDate = new Date(); var maxDate = new Date(); var minClose = 0; var maxClose = 0;
// figure out the min and max shite
if( d3.max(sliced_bm_Data_, function(d) { return d.cumuChg; }) > d3.max(current_Data_, function(d) { return d.cumuChg; }) )
maxClose = d3.max(sliced_bm_Data_, function(d) { return d.cumuChg; });
else
maxClose = d3.max(current_Data_, function(d) { return d.cumuChg; });
if( d3.min(sliced_bm_Data_, function(d) { return d.cumuChg; }) < d3.min(current_Data_, function(d) { return d.cumuChg; }) )
minClose = d3.min(sliced_bm_Data_, function(d) { return d.cumuChg; });
else
minClose = d3.min(current_Data_, function(d) { return d.cumuChg; });
if( d3.max(sliced_bm_Data_, function(d) { return d.Date; }) > d3.max(current_Data_, function(d) { return d.Date; }) )
maxDate = d3.max(sliced_bm_Data_, function(d) { return d.Date; });
else
maxDate = d3.max(current_Data_, function(d) { return d.Date; });
if( d3.min(sliced_bm_Data_, function(d) { return d.Date; }) < d3.min(current_Data_, function(d) { return d.Date; }) )
minDate = d3.min(sliced_bm_Data_, function(d) { return d.Date; });
else
minDate = d3.min(current_Data_, function(d) { return d.Date; });
//
var line = d3.svg.line()
.x(function(d) { return xScaler(d.Date); })
.y(function(d) { return yScaler(d.cumuChg); });
var svg = d3.select(".chart2");
//clear existing
svg.selectAll("path")
.remove();
//rescale if necessary
xScaler.domain([minDate, maxDate]);
yScaler.domain([minClose, maxClose]);
//Date picker - set min and max Dates for the calendar to show
// also setup call back function for Date closing ..if that happens
// then you need call this _reScaleBM_MF_axes after resetting start and end index
if(bm_Data_ == current_MF_Data_){
$(function() {
$( "#FromDt" ).datepicker(
{ minDate: bm_Data_[0].Date,
maxDate: bm_Data_[bm_Data_.length-1].Date ,
beforeShowDay: $.datepicker.noWeekends ,
dateFormat: 'dd/mm/yy',
constrainInput: true,
onClose: function(selectedDate) {
//need to pass via Date class since the selectedDate comes in as string
//*** whenever comparing or working with DATES lets stick to conversion into Date object***
console.log('CHIKA CHAN '+new Date(selectedDate));
if( null !== selectedDate){
console.log('CON11 '+new Date(selectedDate).getMonth()+new Date(selectedDate).getDate());
var locStore = _BM_MF_FromDt_idx;
_BM_MF_FromDt_idx = findIndex( new Date(selectedDate) );
console.log('CON1 '+locStore+' '+_BM_MF_FromDt_idx+' '+_BM_MF_ToDt_idx);
//set the dragslider values to the ones selected by the Date
if ( _BM_MF_FromDt_idx < _BM_MF_ToDt_idx) {
$( "#dragslider-range" ).dragslider( "values" , [ _BM_MF_FromDt_idx , _BM_MF_ToDt_idx] )
//now call the rescale function
_reScaleBM_MF_axes(null);
}
else{
alert("sorry from's always going to be lesser than TO!!");
_BM_MF_FromDt_idx = locStore;
$( "#FromDt" ).datepicker( "setDate", bm_Data_[_BM_MF_FromDt_idx].Date );
}
}
}
}
);
});
$(function() {
$( "#ToDt" ).datepicker(
{ minDate: bm_Data_[0].Date,
maxDate: bm_Data_[bm_Data_.length-1].Date ,
beforeShowDay: $.datepicker.noWeekends ,
dateFormat: 'dd/mm/yy',
onClose: function(selectedDate) {
if( null !== selectedDate){
dateConst = (selectedDate.split("/"));
var locStore = _BM_MF_ToDt_idx;
_BM_MF_ToDt_idx = findIndex( new Date( dateConst[1]+'/'+dateConst[0]+'/'+dateConst[2] ) );
console.log('CON2 '+locStore+' '+_BM_MF_FromDt_idx+' '+_BM_MF_ToDt_idx+' '+new Date( dateConst[1]+'/'+dateConst[0]+'/'+dateConst[2] ) + bm_Data_[1982].Date);
//set the dragslider values to the ones selected by the Date
//but also check if the end dt > start ...
if ( _BM_MF_FromDt_idx < _BM_MF_ToDt_idx) {
$( "#dragslider-range" ).dragslider( "values" , [ _BM_MF_FromDt_idx , _BM_MF_ToDt_idx] )
//now call the rescale function
_reScaleBM_MF_axes(null);
}else{
alert("sorry from's always going to be lesser than TO!!");
_BM_MF_ToDt_idx = locStore;
$( "#ToDt" ).datepicker( "setDate", bm_Data_[_BM_MF_ToDt_idx].Date );
}
}
}
}
);
});
}
svg.select(".y.axis").transition().duration(500).ease("sin-in-out") // https://github.com/mbostock/d3/wiki/Transitions#wiki-d3_ease
.call(yAxis);
svg.select(".x.axis").transition().duration(500).ease("sin-in-out") // https://github.com/mbostock/d3/wiki/Transitions#wiki-d3_ease
.call(xAxis);
//add benchmark
window.benchMarkPath = svg.append("path")
.datum(sliced_bm_Data_)
.attr("class", "line")
.attr("d", line)
.attr("data-legend", dispBMName)
.attr("stroke","SpringGreen")
.attr("transform", "translate("+marOffsetX+","+marOffsetY+")")
//if the user hath selected some MF
if(bm_Data_ != current_MF_Data_){
window.MFPath = svg.append("path")
.datum(current_Data_)
.attr("class", "line")
.attr("d", line)
.attr("data-legend", dispMFName)
.attr("stroke","Turquoise")
.attr("transform", "translate("+marOffsetX+","+marOffsetY+")")
}
svg.selectAll(".legend").remove();
//now set to and from Date calendars and also dragslider positions
if ( _BM_MF_FromDt_idx < _BM_MF_ToDt_idx) {
$( "#FromDt" ).datepicker( "setDate", bm_Data_[_BM_MF_FromDt_idx].Date );
$( "#ToDt" ).datepicker( "setDate", bm_Data_[_BM_MF_ToDt_idx].Date );
$( "#dragslider-range" ).dragslider( "values" , [ _BM_MF_FromDt_idx , _BM_MF_ToDt_idx] )
}
else{
//better error handling ..for now just alert
alert("sorry from dt's always going to be earlier than To Date ..never went to school ..sucker ?");
}
legend = svg.append("g")
.attr("class","legend")
.attr("transform","translate(80,30)")
.style("font-size","15px")
.attr("data-style-padding",10)
.call(d3.legend);
//console();
}
</script>
<div id = "MENU" >
<div class="new">
<ul>
<li><a href="javascript:void(0);">Main</a></li>
<li><a href="javascript:void(0);">Sectoral</a></li>
<li><a class="current" href="javascript:void(0);">Risk</a></li>
<li><a href="javascript:void(0);">Perf Attribution</a></li>
</ul>
</div>
</div>
<div id="MFRiskReturn" >
<svg class="chart1" ></svg>
<script>
var margin = {top: 20, right: 20, bottom: 20, left: 20},
width = MFRiskReturnWidth - margin.left - margin.right,
height = MFRiskReturnHeight - margin.top - margin.bottom;
var xFun = d3.scale.linear().domain([-10,10])
.range([0,width]);
var yFun = d3.scale.linear().domain([10,-10])
.range([0,height]);
var xAxis = d3.svg.axis()
.scale(xFun)
.orient("bottom");
var yAxis = d3.svg.axis()
.scale(yFun)
.orient("left");
var tip = d3.tip()
.attr('class', 'd3-tip')
.offset([-10, 0])
.html(function(d) {
return "<strong>Risk:</strong> " + d.name +"<br><strong>Risk:</strong> " + d.x1 +"<br><strong>Return:</strong> " + d.x2 + "</span>";
})
var chart = d3.select(".chart1")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom);
//.append("g")
//.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
chart.call(tip);
//d3.csv("http://localhost:8080/test.csv", type, function(error, data) {
//below is the risk return metric we will be using for charts
var data_MF = retDataMFRiskReturn();
data_MF.forEach(function(d) {
d.x1 = +d.x1;
d.x2 = +d.x2;
d.name = d.name;
});
//below we need to push each mf's time series
//for now we will use random numbers
//**********below is where you should be placing MF data / arrays via static in django ********//
chart.append("g")
.attr("class", "x axis")
.attr("transform", "translate(0,"+height/2+")")
.call(xAxis)
.append("text")
.attr("transform", "translate("+(width-30)+",-10)")
.attr("y", 2)
.attr("dy", "1em")
.style("text-anchor", "begin")
.text("HIGH RETURN");
chart.append("g")
.attr("class", "y axis")
.attr("transform", "translate("+width/2+",0)")
.call(yAxis)
.append("text")
.attr("transform", "rotate(-90)")
.attr("y", 2)
.attr("dy", "1em")
.style("text-anchor", "end")
.text("HIGH RISK");
chart.selectAll(".bar")
.data(data_MF)
.enter()
.append("svg:circle")
.attr("fill", function(d, i) { return colors(i); })
.attr("r", function(d){ var store = 0;
if(d.x1 > d.x2)
store = Math.abs(d.x1)*10;
else
store = Math.abs(d.x2)*10;
return store
} )
.attr("cx", function(d){return xFun(d.x1) } )
.attr("cy", function(d){return yFun(d.x2)} )
.on('click', function(d,i){
setBMDataBasedOnMF( d.name ) ;
_reScaleBM_MF_axes( retMFData(d.name) ) ;
})
.on('mouseover', tip.show )
.on('mouseout', tip.hide );
//.append("svg:title")
//.text(function(d) { return d.x1; });;
</script>
</div>
<div id = "MFvsBM">
<label for="search">Choose Comparison: </label>
<input id="search">
<a href="#" onclick="hardCodedTimeFrame('YTD')" class="myButton">YTD</a> <a href="#" onclick="hardCodedTimeFrame('6M')" class="myButton">6M</a> <a href="#" onclick="hardCodedTimeFrame('1Y')" class="myButton">1Y</a> <a href="#" onclick="hardCodedTimeFrame('3Y')" class="myButton">3Y</a> <a href="#" onclick="hardCodedTimeFrame('5Y')" class="myButton">5Y</a>
<svg class="chart2" id="OK"></svg>
<script>
var margin = {top: 20, right: 30, bottom: 20, left: 30},
width = MFVsBMWidth - margin.left - margin.right,
height = MFVsBMHeight - margin.top - margin.bottom;
//width = 700 , height = 500 ;
var parseDate = d3.time.format("%d-%b-%y").parse;
//hopefully store dragslider values
window.marOffsetX = margin.right;
window.marOffsetY = margin.top;
var xScaler = d3.time.scale()
.range([0, width]);
var yScaler = d3.scale.linear()
.range([height, 0]);
var xAxis = d3.svg.axis()
.scale(xScaler)
.orient("bottom");
var yAxis = d3.svg.axis()
.scale(yScaler)
.orient("left");
var tipLineChart = d3.tip()
.attr('class', 'd3-tip')
//.offset([0, 0])
//.html(function(d) {
//return "<strong>Risk:</strong> " + d.x1 +"<br><strong>Return:</strong> " + d.x2 + "</span>";
//})
var svg = d3.select(".chart2")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.append("g")
.attr("transform", "translate(" + margin.left + "," + (margin.top) + ")");
//.attr("transform", "translate(0," + margin.top + ")");
svg.call( tipLineChart );
//d3.tsv("data.tsv", function(error, data) {
//**********below is where you should be placing Benchmark data / arrays via static in django ********//
//to init we call with 0 ..will need to change it after template mess
initGlobalSetBM();
//add hover line
// Hover line.
var hoverLineGroup = svg.append("g")
.attr("class", "hover-line");
var hoverLine = hoverLineGroup
.append("line")
.attr("x1", 10).attr("x2", 10)
.attr("y1", 0).attr("y2", height);
// Hide hover line by default.
hoverLine.style("opacity", 0.1);
//hoverLineGroup.call( tipLineChart );
circleBenchMark = svg.append("circle")
.attr("opacity", 0.00001)
.attr({ r: dispCircleRadius, fill: 'SpringGreen' });
circleMF = svg.append("circle")
.attr("opacity", 0.00001)
.attr({ r: dispCircleRadius, fill: 'Turquoise' });
d3.select(".chart2").on("mouseover", function() {
console.log('mouseover bugs');
}).on("mousemove", function() {
var xCoOrd = d3.mouse(this)[0];
var yCoOrd = d3.mouse(this)[1];
//console.log("x and y coordinate Function ENTRY: " + [xCoOrd , yCoOrd] );
hoverLine.attr("x1", xCoOrd - margin.left ).attr("x2", xCoOrd - margin.left ).style("opacity", 0.2);
var pathLength = benchMarkPath.node().getTotalLength();
//console.log("bm length " + pathLength );
//since our hover line has an offset from the xAxis our search
//needs to begin from there rather than plain xCoord
var x = xCoOrd - margin.left;
var beginning = x,
end = pathLength,
target;
while (true) {
target = Math.floor((beginning + end) / 2);
posBM = benchMarkPath.node().getPointAtLength(target);
if ((target === end || target === beginning) && posBM.x !== x) {
break;
}
if (posBM.x > x) end = target;
else if (posBM.x < x) beginning = target;
else break; //position found
}
//the code below is for the 2nd path i.e. MF line
//console.log("BEFORE : x and y coordinate where vertical line intersects graph: " + [posBM.x, posBM.y] );
//decorate the dialogue
locDt = xScaler.invert(posBM.x);
tipLineChart//.attr("transform","translate("+(width - posBM.x)+","+(height - posBM.y)+")")
.html(function(d) {
return "<strong>Date:</strong> " +locDt.getDate()+"-"+(parseInt(locDt.getMonth())+1)+"-"+locDt.getFullYear() +"<br><strong>"+ dispBMName +" % Chg:</strong> " + retDailyChange( sliced_bm_Data_ , ( xScaler.invert(posBM.x)) ).toFixed(2) + "</span>";
})
if(bm_Data_ != current_MF_Data_){
pathLength = MFPath.node().getTotalLength();
//console.log("MF length " + pathLength );
//since our hover line has an offset from the xAxis our search
//needs to begin from there rather than plain xCoord
x = xCoOrd - margin.left;
beginning = x,
end = pathLength,
target;
while (true) {
target = Math.floor((beginning + end) / 2);
posMF = MFPath.node().getPointAtLength(target);
if ((target === end || target === beginning) && posMF.x !== x) {
break;
}
if (posMF.x > x) end = target;
else if (posMF.x < x) beginning = target;
else break; //position found
}
//console.log("x and y coordinate where vertical line intersects graph: " + [posBM.x, posBM.y,posMF.x, posMF.y] );
circleMF.attr("opacity", 0.5)
.attr("cx", posMF.x )
.attr("cy", posMF.y)
//console.log("data where vertical line intersects graph: " + [ xScaler.invert(posBM.x), yScaler.invert(posBM.y) ,xScaler.invert(posMF.x), yScaler.invert(posMF.y)]);
locDt = xScaler.invert(posMF.x);
//html for hover box
tipLineChart.html(function(d) {
return "<strong>Date:</strong> " +locDt.getDate()+"-"+(parseInt(locDt.getMonth())+1)+"-"+locDt.getFullYear() +"<br><strong>"+ dispBMName + "% Chg:</strong> " + retDailyChange( sliced_bm_Data_ , ( xScaler.invert(posBM.x)) ).toFixed(2) + "</span><br><strong>"+dispMFName+ "% Change:</strong>" + retDailyChange( current_Data_ , ( xScaler.invert(posMF.x)) ).toFixed(2);
})
}
// end code for 2nd path
circleBenchMark.attr("opacity", 0.5)
.attr("cx", posBM.x )
.attr("cy", posBM.y)
//console.log("data where vertical line intersects graph: " + [xScaler.invert(posBM.x), yScaler.invert(posBM.y)]);
tipLineChart.show();
//console.log('mousemove x', ( d3.mouse(this)[0] ));
//console.log('mousemove y', ( d3.mouse(this)[1] ));
}) .on("mouseout", function() {
//console.log('mouseout');
hoverLine.style("opacity", 0.001);
circleBenchMark.attr("opacity", 0.001);
circleMF.attr("opacity", 0.001);
tipLineChart.hide();
});
// Hover line.
xScaler.domain(d3.extent(bm_Data_, function(d) { return d.Date; }));
yScaler.domain(d3.extent(bm_Data_, function(d) { return d.closing; }));
svg.append("g")
.attr("class", "x axis")
.attr("transform", "translate("+marOffsetX+"," + height + ")")
.call(xAxis);
svg.append("g")
.attr("class", "y axis")
.call(yAxis)
.append("text")
.attr("transform", "rotate(-90)")
.attr("y", 2)
.attr("dy", "1em")
.style("text-anchor", "end")
.text("% Daily Change (%)");
//call the final rendering
_reScaleBM_MF_axes(bm_Data_);
</script>
<script>
$(function() {
var begDate = new Date();
var endDate = new Date();
$( "#dragslider-range" ).dragslider({
range: true,
min: 0,
rangeDrag: true,
max: bm_Data_.length-1,
//values: [ 0 , bm_Data_.length-2 ],
//the below is the call back function when the dragslider's moved
slide: function( event, ui ) {
//if the below is true then this is called when we click on the range rather
//than drag the handle
if(!isDragging){
begDate = bm_Data_[ui.values[ 0 ]].Date;
endDate = bm_Data_[ui.values[ 1 ]-1].Date;
_BM_MF_FromDt_idx = ui.values[ 0 ];
_BM_MF_ToDt_idx = ui.values[ 1 ];
}
else
{
console.log('NOW GONE BUST!!!');
}
},
change : function ( event, ui ){
console.log('HMM MOVING VIA THIS !!'+_BM_MF_FromDt_idx+' '+ui.values[ 0 ]);
//over ride if isDragging true
},
stop: function( event, ui ) {
//rather than call it every movement in the above call it once after user lets go of handle
//if()
if(!isDragging)
_reScaleBM_MF_axes(null);
}
});
$( "#dragslider-range .ui-dragslider-range" ).unbind('mousedown');
// $( "#dragslider-range .ui-dragslider-range" ).mousedown(function( event ) {
// console.log('OK MAYBE THIS TIME');
// isDragging = true;
// });
//first time init of Dates and alider
$( "#FromDt" ).datepicker( "setDate", bm_Data_[_BM_MF_FromDt_idx].Date );
$( "#ToDt" ).datepicker( "setDate", bm_Data_[_BM_MF_ToDt_idx].Date );
$( "#dragslider-range" ).dragslider( "values" , [ _BM_MF_FromDt_idx , _BM_MF_ToDt_idx] );
});
function hardCodedTimeFrame(option){
switch(option) {
case 'YTD':
locArr = retDefaultBMData();
_BM_MF_ToDt_idx = locArr.length-1;
locEnd = new Date( locArr[_BM_MF_ToDt_idx].Date );
_BM_MF_FromDt_idx = findIndex ( new Date( '01/01/'+ locEnd.getFullYear() ) );
break;
case '6M':
locStart = new Date( sliced_bm_Data_[sliced_bm_Data_.length-1].Date );
var begD = locStart.getDate();
//returns the index from 0 to 11 hence need to add 1
var begM = parseInt(locStart.getMonth())+1;
var begY = 0;
if( begM <= 6){
begM = (12 + begM)-6;
begY = parseInt(locStart.getFullYear())-1;
}
else{
begM = (begM)-6;
begY = parseInt(locStart.getFullYear());
}
_BM_MF_FromDt_idx = findIndex ( new Date( begM+'/'+begD+'/'+ begY ) );
break;
case '1Y':
locStart = new Date( sliced_bm_Data_[sliced_bm_Data_.length-1].Date );
var begD = locStart.getDate();
//returns the index from 0 to 11 hence need to add 1
var begM = parseInt(locStart.getMonth())+1;
var begY = parseInt(locStart.getFullYear())-1;
console.log('1Y '+begD+'/'+begM+'/'+ begY);
//need to send it in MMDDYYYY ..a little screwed up
_BM_MF_FromDt_idx = findIndex ( new Date( begM+'/'+begD+'/'+ begY ) );
break;
case '3Y':
locStart = new Date( sliced_bm_Data_[sliced_bm_Data_.length-1].Date );
var begD = locStart.getDate();
//returns the index from 0 to 11 hence need to add 1
var begM = parseInt(locStart.getMonth())+1;
var begY = parseInt(locStart.getFullYear())-3;
console.log('3Y '+begD+'/'+begM+'/'+ begY);
//need to send it in MMDDYYYY ..a little screwed up
_BM_MF_FromDt_idx = findIndex ( new Date( begM+'/'+begD+'/'+ begY ) );
break;
case '5Y':
locStart = new Date( sliced_bm_Data_[sliced_bm_Data_.length-1].Date );
var begD = locStart.getDate();
//returns the index from 0 to 11 hence need to add 1
var begM = parseInt(locStart.getMonth())+1;
var begY = parseInt(locStart.getFullYear())-5;
console.log('5Y '+begD+'/'+begM+'/'+ begY);
//need to send it in MMDDYYYY ..a little screwed up
_BM_MF_FromDt_idx = findIndex ( new Date( begM+'/'+begD+'/'+ begY ) );
break;
}
if( _BM_MF_FromDt_idx>=0 && _BM_MF_ToDt_idx>=0 )
_reScaleBM_MF_axes(null);
else
console.log('SOMETHING GOTTA HURTA!!');
}
</script>
<script>
$.widget( "custom.catcomplete", $.ui.autocomplete, {
_create: function() {
this._super();
this.widget().menu( "option", "items", "> :not(.ui-autocomplete-category)" );
},
_renderMenu: function( ul, items ) {
var that = this,
currentCategory = "";
$.each( items, function( index, item ) {
var li;
if ( item.category != currentCategory ) {
ul.append( "<li class='ui-autocomplete-category'>" + item.category + "</li>" );
currentCategory = item.category;
}
li = that._renderItemData( ul, item );
if ( item.category ) {
li.attr( "aria-label", item.category + " : " + item.label );
}
});
}
});
</script>
<script>
$(function() {
var data = retSelectList();
$( "#search" ).catcomplete({
delay: 0,
source: data,
select: function(event, ui) {
//callback when option is selected
setBMDataBasedOnMF( ui.item.label ) ;
_reScaleBM_MF_axes( retMFData(ui.item.label) ) ;
}
});
});
</script>
</div>
<div id="dragslider-range-header">
<div id ="dragslider-text">
<p>From Date: <input type="text" readOnly='true' class="fromDate" id="FromDt" style="padding : 3px"> To Date: <input type="text" readOnly='true' id="ToDt" style="padding : 3px"> </p>
</div>
<div id="dragslider-range" class="vik"></div>
</div>
</body>