Skip to content

Commit c71f892

Browse files
committed
have one highcharts-based chart nearly working
1 parent 1d388f0 commit c71f892

File tree

4 files changed

+42
-104
lines changed

4 files changed

+42
-104
lines changed

app/assets/javascripts/angular/controllers/scout.js

Lines changed: 0 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -33,92 +33,5 @@ gg.controller('ScoutController', ['$scope', '$element', '$urlFilter',
3333
renderAll();
3434
}
3535
});
36-
37-
$scope.render = function() {
38-
var grp = asGrp.all();
39-
if (typeof grp !== 'undefined') {
40-
xyValues = _.map(grp, function (g) { return [g.key, g.value.value]; })
41-
$scope.chart.series[0].setData(xyValues);
42-
}
43-
}
44-
45-
options = {
46-
chart: {
47-
type: "column",
48-
renderTo: $element.find('.canvas')[0],
49-
backgroundColor: "#F7F4EF",
50-
color: "#00f",
51-
animation: false,
52-
zoomType: 'x',
53-
width: 170,
54-
height: 130,
55-
events: {
56-
selection: function(event) {
57-
console.log("Selected", event.xAxis[0].min, event.xAxis[0].max, event);
58-
59-
// TODO bind dimension to chart properly
60-
if (typeof asDim !== 'undefined') {
61-
asDim.filterRange([event.xAxis[0].min, event.xAxis[0].max]);
62-
renderAll();
63-
}
64-
65-
// TODO show current filter as text
66-
// TODO when filter is active, show a RESET link
67-
// TODO show filter as highlighted region on chart
68-
// TODO switch all charts over to highcharts
69-
// TODO if not too hard, make selection area draggable
70-
71-
event.preventDefault();
72-
}
73-
}
74-
},
75-
title: {text: ""},
76-
legend: {enabled: false},
77-
xAxis: {
78-
labels: {
79-
enabled: true,
80-
style: {"fontFamily":"'Open Sans', verdana, arial, helvetica, sans-serif"},
81-
formatter: function () { return this.value; }
82-
}
83-
},
84-
yAxis: {
85-
lineWidth: 0,
86-
minorGridLineWidth: 0,
87-
lineColor: 'transparent',
88-
labels: { enabled: false },
89-
minorTickLength: 0,
90-
tickLength: 0,
91-
title: '',
92-
endOnTick: false
93-
},
94-
credits: {enabled:false},
95-
plotOptions: {
96-
column:{
97-
animation:false,
98-
color:'steelblue',
99-
groupPadding: 0,
100-
pointPadding: 0,
101-
borderWidth: 0,
102-
pointPlacement: 'on',
103-
marker: {
104-
enabled:true,
105-
radius:4,
106-
symbol: "circle",
107-
lineColor: "#111",
108-
lineWidth:1,
109-
fillColor:"#222",
110-
states: {hover:{enabled:true}}
111-
},
112-
shadow:false,
113-
threshold:0
114-
}
115-
},
116-
subtitle: {}
117-
};
118-
options.series = [];
119-
$scope.chart = new Highcharts.Chart(options);
120-
$scope.chart.addSeries({
121-
data: [1]
122-
});
12336
}
12437
]);

app/assets/javascripts/scout.js

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ function render(method) {
7575
}
7676

7777
function renderAll() {
78-
$('#static').scope().render();
79-
// $('.filterchart').each(function() { this.render() });
78+
// $('#static').scope().render();
79+
$('.filterchart').each(function() { this.render() });
8080
chart.each(render);
8181
list.each(render);
8282
d3.select("#active").text(formatNumber(gr_all.value()));
@@ -368,8 +368,8 @@ function entities_url() {
368368
return data_host() + "/ents" + debug_suffix() + ".csv";
369369
}
370370

371-
function filter_chart(element, dimension, group, domain, title) {
372-
options = {
371+
function filter_chart(element, dimension, group, domain) {
372+
var options = {
373373
chart: {
374374
type: "column",
375375
renderTo: element,
@@ -383,13 +383,27 @@ function filter_chart(element, dimension, group, domain, title) {
383383
selection: function(event) {
384384
console.log("Selected", event.xAxis[0].min, event.xAxis[0].max, event);
385385

386+
event.xAxis[0].axis.removePlotBand('plot-band-1');
387+
388+
event.xAxis[0].axis.addPlotBand({
389+
from: event.xAxis[0].min,
390+
to: event.xAxis[0].max,
391+
color: 'rgba(150, 50, 50, 0.1)',
392+
zIndex: 5,
393+
id: 'plot-band-1'
394+
});
395+
396+
filterchart = event.currentTarget.container.parentElement.parentElement
397+
$(filterchart).children(".filtered").show();
398+
$(filterchart).find(".lower").text(Math.floor(event.xAxis[0].min));
399+
$(filterchart).find(".upper").text(Math.floor(event.xAxis[0].max));
400+
386401
dimension.filterRange([event.xAxis[0].min, event.xAxis[0].max]);
387402
renderAll();
388403

389-
// TODO show current filter as text
390-
// TODO when filter is active, show a RESET link
391-
// TODO show filter as highlighted region on chart
392-
// TODO switch all charts over to highcharts
404+
// TODO make the RESET link actually work
405+
// TODO when filter is cleared, hide the filter text and RESET link
406+
// TODO switch all charts over to highcharts, in a nice DRY way
393407
// TODO if not too hard, make selection area draggable
394408

395409
event.preventDefault();
@@ -635,10 +649,25 @@ function scout_init() {
635649
})
636650
});
637651

638-
652+
653+
chartContainer = $(document.createElement('div')).addClass('djchart');
654+
655+
chartTitle = $('<div class="title">Player\'s Army Strength @ X minutes</div>');
656+
657+
chartFilterText = $('<div class="filtered title" style="display:none">from <span class="lower">-</span> to <span class="upper">-</span></div>');
658+
filterResetLink = $('<a href="#" class="reset">reset</a>');
659+
filterResetLink.click(function(e) { e.preventDefault(); console.log('reset!'); });
660+
chartFilterText.append(filterResetLink);
661+
662+
chartContainer.append(chartTitle);
663+
chartContainer.append(chartFilterText);
664+
665+
639666
asChart = $(document.createElement('div')).addClass('filterchart');
640-
// filter_chart(asChart, asDim, asGrp, [0, 2500], 'FOOBABY');
641-
// $('#filtercharts').append(asChart);
667+
chartContainer.append(asChart);
668+
669+
filter_chart(asChart[0], asDim, asGrp, [0, 2500]);
670+
$('#filtercharts').append(chartContainer);
642671

643672
renderAll();
644673

app/assets/stylesheets/scout.css.scss

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
}
1616

1717
.reset {
18-
padding-left: 1em;
18+
padding-left: 2em;
1919
font-size: smaller;
20-
color: #ccc;
20+
text-decoration: none !important;
2121
}
2222

2323
.background.bar {

app/views/home/scout.html

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,6 @@
2121
<div><span>Player id:</span><input type="text" id="player_id"></input></div>
2222
<div><span id="winrate">-</span>% matches won.</div>
2323
<div><span id="active">-</span> of <span id="total">-</span> matches selected.</div>
24-
<div class="djchart">
25-
<div class="title">Player's Army Strength @ X minutes</div>
26-
<div class="canvas"></div>
27-
</div>
2824
<div id="filtercharts"></div>
2925
<div id="charts">
3026
<div id="league-chart" class="chart">

0 commit comments

Comments
 (0)