Skip to content

Commit 61e8891

Browse files
committed
Handle showLabels(...) like showAggregates(...) like the documentation says.
1 parent 7ab9165 commit 61e8891

File tree

5 files changed

+148
-6
lines changed

5 files changed

+148
-6
lines changed

Source/Visualizations/AreaChart.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,9 @@ $jit.ST.Plot.NodeTypes.implement({
8989
if(aggValue !== false) {
9090
ctx.fillText(aggValue !== true? aggValue : valAcum, x, y - acumLeft - config.labelOffset - label.size/2, width);
9191
}
92-
if(showLabels(node.name, valLeft, valRight, node)) {
93-
ctx.fillText(node.name, x, y + label.size/2 + config.labelOffset);
92+
var labValue = showLabels(node.name, valLeft, valRight, node)
93+
if(labValue !== false) {
94+
ctx.fillText(labValue !== true? labValue : node.name, x, y + label.size/2 + config.labelOffset);
9495
}
9596
ctx.restore();
9697
}

Source/Visualizations/BarChart.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,15 +235,17 @@ $jit.ST.Plot.NodeTypes.implement({
235235
ctx.fillText(aggValue, x + width/2, y - Math.max.apply(null, dimArray) - label.size/2 - config.labelOffset);
236236
}
237237
}
238-
if(showLabels(node.name, valAcum, node)) {
238+
var labValue = showLabels(node.name, valAcum, node);
239+
if(labValue !== false) {
240+
labValue = labValue !== true? labValue : node.name;
239241
if(horz) {
240242
ctx.textAlign = 'center';
241243
ctx.translate(x - config.labelOffset - label.size/2, y + height/2);
242244
ctx.rotate(Math.PI / 2);
243-
ctx.fillText(node.name, 0, 0);
245+
ctx.fillText(labValue, 0, 0);
244246
} else {
245247
ctx.textAlign = 'center';
246-
ctx.fillText(node.name, x + width/2, y + label.size/2 + config.labelOffset);
248+
ctx.fillText(labValue, x + width/2, y + label.size/2 + config.labelOffset);
247249
}
248250
}
249251
ctx.restore();

Templates/AreaChart/test3.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
$def with (model)
2+
3+
<div id="inner-details"></div>

Tests/AreaChart/test3.js

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
function init(){
2+
//init data
3+
var json = {
4+
'label': ['label A', 'label B', 'label C', 'label D'],
5+
'values': [
6+
{
7+
'label': 'date A',
8+
'values': [20, 40, 15, 5]
9+
},
10+
{
11+
'label': 'date B',
12+
'values': [30, 10, 45, 10]
13+
},
14+
{
15+
'label': 'date E',
16+
'values': [38, 20, 35, 17]
17+
},
18+
{
19+
'label': 'date F',
20+
'values': [58, 10, 35, 32]
21+
},
22+
{
23+
'label': 'date D',
24+
'values': [55, 60, 34, 38]
25+
},
26+
{
27+
'label': 'date C',
28+
'values': [26, 40, 25, 40]
29+
}]
30+
31+
};
32+
var json2 = {
33+
'values': [
34+
{
35+
'label': 'date A',
36+
'values': [10, 40, 15, 7]
37+
},
38+
{
39+
'label': 'date B',
40+
'values': [30, 40, 45, 9]
41+
},
42+
{
43+
'label': 'date D',
44+
'values': [55, 30, 34, 26]
45+
},
46+
{
47+
'label': 'date C',
48+
'values': [26, 40, 85, 28]
49+
}]
50+
51+
};
52+
//end
53+
var infovis = document.getElementById('infovis');
54+
//init AreaChart
55+
var areaChart = new $jit.AreaChart({
56+
//id of the visualization container
57+
injectInto: 'infovis',
58+
//add animations
59+
animate: true,
60+
//separation offsets
61+
Margin: {
62+
top: 5,
63+
left: 5,
64+
right: 5,
65+
bottom: 5
66+
},
67+
labelOffset: 10,
68+
// function to modify sums
69+
showAggregates: function(name, left, right, node, acum) {
70+
if ( acum > 120 ) { return acum; }
71+
return false;
72+
},
73+
// function to modify labels
74+
showLabels: function(name, left, right, node) {
75+
if ( name.indexOf('B') != -1 ) { return name; }
76+
return false;
77+
},
78+
//could also be 'stacked'
79+
type: useGradients? 'stacked:gradient' : 'stacked',
80+
//label styling
81+
Label: {
82+
type: labelType, //can be 'Native' or 'HTML'
83+
size: 13,
84+
family: 'Arial',
85+
color: 'white'
86+
},
87+
//enable tips
88+
Tips: {
89+
enable: true,
90+
onShow: function(tip, elem) {
91+
tip.innerHTML = "<b>" + elem.name + "</b>: " + elem.value;
92+
}
93+
},
94+
//add left and right click handlers
95+
filterOnClick: true,
96+
restoreOnRightClick:true
97+
});
98+
//load JSON data.
99+
areaChart.loadJSON(json);
100+
//end
101+
var list = $jit.id('id-list'),
102+
button = $jit.id('update'),
103+
restoreButton = $jit.id('restore');
104+
//update json on click
105+
$jit.util.addEvent(button, 'click', function() {
106+
var util = $jit.util;
107+
if(util.hasClass(button, 'gray')) return;
108+
util.removeClass(button, 'white');
109+
util.addClass(button, 'gray');
110+
areaChart.updateJSON(json2);
111+
});
112+
//restore graph on click
113+
$jit.util.addEvent(restoreButton, 'click', function() {
114+
areaChart.restore();
115+
});
116+
//dynamically add legend to list
117+
var legend = areaChart.getLegend(),
118+
listItems = [];
119+
for(var name in legend) {
120+
listItems.push('<div class=\'query-color\' style=\'background-color:'
121+
+ legend[name] +'\'>&nbsp;</div>' + name);
122+
}
123+
list.innerHTML = '<li>' + listItems.join('</li><li>') + '</li>';
124+
}

tests.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,19 @@
741741
""",
742742
'Extras': ['excanvas.js'],
743743
'Example': False
744-
}
744+
},
745+
{
746+
'Title': 'Area Chart Example overridden aggregate values and labels',
747+
'Description':
748+
"""
749+
A static Area Chart example with gradients that displays tooltips when hovering the stacks.<br /><br />
750+
Left-click a Stack to apply a filter to it.<br /><br />
751+
Right-click to restore all stacks.<br /><br />
752+
Click the Update button to update the JSON data.
753+
""",
754+
'Extras': ['excanvas.js'],
755+
'Example': False
756+
},
745757
],
746758

747759
'BarChart': [

0 commit comments

Comments
 (0)