Skip to content

Commit 2ab6861

Browse files
committed
add test and remove helper
1 parent 26c5117 commit 2ab6861

38 files changed

+91
-16
lines changed

dc.js

+14-5
Original file line numberDiff line numberDiff line change
@@ -1545,6 +1545,19 @@ dc.baseMixin = function (_chart) {
15451545
return _chart;
15461546
};
15471547

1548+
1549+
/**
1550+
#### .legendLabelAccessor([legendLabelAccessorFunction])
1551+
Set or get the legend label accessor function. The legend label accessor function is used to retrieve the
1552+
value from the legend label for the crossfilter group.
1553+
```js
1554+
// default legenLabel accessor
1555+
chart.legendLabelAccessor(function(d) { return d.key; });
1556+
// custom legen label accessor for a multi-value crossfilter reduction
1557+
chart.legendLabelAccessor(function(p) { return "Custom Legend:" + p.key; });
1558+
```
1559+
1560+
**/
15481561
_chart.legendLabelAccessor = function (_) {
15491562
if (!arguments.length) {
15501563
return _legendLabelAccessor;
@@ -1576,10 +1589,6 @@ dc.baseMixin = function (_chart) {
15761589
return _chart;
15771590
};
15781591

1579-
_chart.getLegendLabel = function (d, i) {
1580-
return _legendLabelAccessor.call(this, d, i);
1581-
};
1582-
15831592
/**
15841593
#### .renderLabel(boolean)
15851594
Turn on/off label rendering
@@ -4137,7 +4146,7 @@ dc.pieChart = function (parent, chartGroup) {
41374146

41384147
_chart.legendables = function () {
41394148
return _chart.data().map(function (d, i) {
4140-
var legendable = {name: _chart.getLegendLabel(d, i), data: d.value, others: d.others, chart:_chart};
4149+
var legendable = {name: _chart.legendLabelAccessor(d, i), data: d.value, others: d.others, chart:_chart};
41414150
legendable.color = _chart.getColor(d, i);
41424151
return legendable;
41434152
});

dc.min.js

+3-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dc.min.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+33-1
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,40 @@
2525
"url": "https://github.com/dc-js/dc.js.git"
2626
},
2727
"dependencies": {
28+
"browser-resolve": "^1.8.2",
29+
"browserify-zlib": "^0.1.4",
30+
"concat-stream": "^1.4.8",
2831
"crossfilter": "1.x",
29-
"d3": "3.x"
32+
"crypto-browserify": "^3.9.14",
33+
"d3": "3.x",
34+
"defined": "^1.0.0",
35+
"domain-browser": "^1.1.4",
36+
"duplexer2": "0.0.2",
37+
"events": "^1.0.2",
38+
"has": "^1.0.0",
39+
"http-browserify": "^1.7.0",
40+
"https-browserify": "0.0.0",
41+
"isarray": "0.0.1",
42+
"labeled-stream-splicer": "^1.0.2",
43+
"marked": "^0.3.3",
44+
"os-browserify": "^0.1.2",
45+
"path-browserify": "0.0.0",
46+
"phantomjs": "^1.9.16",
47+
"process": "^0.10.1",
48+
"punycode": "^1.3.2",
49+
"querystring-es3": "^0.2.1",
50+
"read-only-stream": "^1.1.1",
51+
"readable-stream": "^1.0.33",
52+
"shallow-copy": "0.0.1",
53+
"stream-browserify": "^1.0.0",
54+
"string_decoder": "^0.10.31",
55+
"through2": "^0.6.5",
56+
"timers-browserify": "^1.4.0",
57+
"tty-browserify": "0.0.0",
58+
"url": "^0.10.3",
59+
"util": "^0.10.3",
60+
"vm-browserify": "0.0.4",
61+
"xtend": "^4.0.0"
3062
},
3163
"devDependencies": {
3264
"emu": "~0.0.2",

spec/bar-chart-spec.js

100644100755
File mode changed.

spec/base-mixin-spec.js

100644100755
File mode changed.

spec/biggish-data-spec.js

100644100755
File mode changed.

spec/box-plot-spec.js

100644100755
File mode changed.

spec/bubble-chart-spec.js

100644100755
File mode changed.

spec/bubble-overlay-spec.js

100644100755
File mode changed.

spec/color-spec.js

100644100755
File mode changed.

spec/composite-chart-spec.js

100644100755
File mode changed.

spec/coordinate-grid-chart-spec.js

100644100755
File mode changed.

spec/core-spec.js

100644100755
File mode changed.

spec/data-addition-spec.js

100644100755
File mode changed.

spec/data-count-spec.js

100644100755
File mode changed.

spec/data-grid-spec.js

100644100755
File mode changed.

spec/data-table-spec.js

100644100755
File mode changed.

spec/event-spec.js

100644100755
File mode changed.

spec/filter-dates-spec.js

100644100755
File mode changed.

spec/filters-spec.js

100644100755
File mode changed.

spec/geo-choropleth-chart-spec.js

100644100755
File mode changed.

spec/heatmap-spec.js

100644100755
File mode changed.

spec/helpers/custom_matchers.js

100644100755
File mode changed.

spec/helpers/fixtures.js

100644100755
File mode changed.

spec/helpers/geoFixtures.js

100644100755
File mode changed.

spec/helpers/spec-helper.js

100644100755
File mode changed.

spec/legend-spec.js

100644100755
File mode changed.

spec/line-chart-spec.js

100644100755
File mode changed.

spec/logger-spec.js

100644100755
File mode changed.

spec/number-display-spec.js

100644100755
File mode changed.

spec/pie-chart-spec.js

100644100755
+26
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,32 @@ describe('dc.pieChart', function() {
658658
valueDimension.filterAll();
659659
});
660660
});
661+
662+
663+
describe('legends with label', function() {
664+
var chart;
665+
beforeEach(function() {
666+
chart = buildChart("pie-chart-legend")
667+
.cap(3)
668+
.legend(dc.legend())
669+
.legendLabelAccessor(function(d){
670+
return d.key + " labeled";
671+
})
672+
.render();
673+
});
674+
it('should generate items for each slice', function() {
675+
expect(chart.selectAll('g.dc-legend g.dc-legend-item').size()).toEqual(chart.data().length);
676+
});
677+
it('should include "others" item labeled', function() {
678+
var numOthersGroups = chart.selectAll('g.dc-legend g.dc-legend-item text').filter(function(d, i) {
679+
return d.name == "Others labeled";
680+
}).size();
681+
expect(numOthersGroups).toEqual(1);
682+
});
683+
afterEach(function() {
684+
valueDimension.filterAll();
685+
});
686+
});
661687
});
662688

663689

spec/row-chart-spec.js

100644100755
File mode changed.

spec/scatter-plot-spec.js

100644100755
File mode changed.

spec/series-chart-spec.js

100644100755
File mode changed.

spec/utils-spec.js

100644100755
File mode changed.

src/base-mixin.js

+13-4
Original file line numberDiff line numberDiff line change
@@ -895,6 +895,19 @@ dc.baseMixin = function (_chart) {
895895
return _chart;
896896
};
897897

898+
899+
/**
900+
#### .legendLabelAccessor([legendLabelAccessorFunction])
901+
Set or get the legend label accessor function. The legend label accessor function is used to retrieve the
902+
value from the legend label for the crossfilter group.
903+
```js
904+
// default legenLabel accessor
905+
chart.legendLabelAccessor(function(d) { return d.key; });
906+
// custom legen label accessor for a multi-value crossfilter reduction
907+
chart.legendLabelAccessor(function(p) { return "Custom Legend:" + p.key; });
908+
```
909+
910+
**/
898911
_chart.legendLabelAccessor = function (_) {
899912
if (!arguments.length) {
900913
return _legendLabelAccessor;
@@ -926,10 +939,6 @@ dc.baseMixin = function (_chart) {
926939
return _chart;
927940
};
928941

929-
_chart.getLegendLabel = function (d, i) {
930-
return _legendLabelAccessor.call(this, d, i);
931-
};
932-
933942
/**
934943
#### .renderLabel(boolean)
935944
Turn on/off label rendering

src/pie-chart.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ dc.pieChart = function (parent, chartGroup) {
429429

430430
_chart.legendables = function () {
431431
return _chart.data().map(function (d, i) {
432-
var legendable = {name: _chart.getLegendLabel(d, i), data: d.value, others: d.others, chart:_chart};
432+
var legendable = {name: _chart.legendLabelAccessor(d, i), data: d.value, others: d.others, chart:_chart};
433433
legendable.color = _chart.getColor(d, i);
434434
return legendable;
435435
});

0 commit comments

Comments
 (0)