Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
andig committed Jul 16, 2017
1 parent 785c016 commit 1a0e661
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 5 deletions.
8 changes: 4 additions & 4 deletions docs/axes/cartesian/category.md
@@ -1,12 +1,12 @@
# Category Cartesian Axis

The category scale will be familiar to those who have used v1.0. Labels are drawn from one of the label arrays included in the chart data. If only `data.labels` is defined, this will be used. If `data.xLabels` is defined and the axis is horizontal, this will be used. Similarly, if `data.yLabels` is defined and the axis is vertical, this property will be used. Using both `xLabels` and `yLabels` together can create a chart that uses strings for both the X and Y axes.
The category scale will be familiar to those who have used v1.0. If global configuration is used, labels are drawn from one of the label arrays included in the chart data. If only `data.labels` is defined, this will be used. If `data.xLabels` is defined and the axis is horizontal, this will be used. Similarly, if `data.yLabels` is defined and the axis is vertical, this property will be used. Using both `xLabels` and `yLabels` together can create a chart that uses strings for both the X and Y axes.

Specifying any of the settings above implicitly defines the x axis as `type: category`if not defined otherwise. For more fine-grained control of category labels, it is (as of 2.7) also possible to add `labels` as part of the explicit category axis definition.
Specifying any of the settings above implicitly defines the x axis as `type: category`if not defined otherwise. For more fine-grained control of category labels it is also possible to add `labels` as part of the category axis definition. Doing so does not apply the global defaults for bar charts.

## Category Axis Definition

Implicit:
Globally:

```javascript
let chart = new Chart(ctx, {
Expand All @@ -17,7 +17,7 @@ let chart = new Chart(ctx, {
},
});
```
Explicit:
As part of axis definition:

```javascript
let chart = new Chart(ctx, {
Expand Down
33 changes: 32 additions & 1 deletion test/specs/scale.category.tests.js
Expand Up @@ -108,7 +108,7 @@ describe('Category scale tests', function() {
expect(scale.ticks).toEqual(mockData.xLabels);
});

it('Should generate ticks from the data xLabels', function() {
it('Should generate ticks from the data yLabels', function() {
var scaleID = 'myScale';

var mockData = {
Expand Down Expand Up @@ -136,6 +136,37 @@ describe('Category scale tests', function() {
expect(scale.ticks).toEqual(mockData.yLabels);
});

it('Should generate ticks from the axis labels', function() {
var scaleID = 'myScale';

var mockData = {
datasets: [{
xAxisID: scaleID,
data: [10, 5, 0, 25, 78]
}],
xAxes: [{
id: scaleID,
labels: ['tick1', 'tick2', 'tick3', 'tick4', 'tick5']
}]
};

var config = Chart.helpers.clone(Chart.scaleService.getScaleDefaults('category'));
config.position = 'left'; // y axis
var Constructor = Chart.scaleService.getScaleConstructor('category');
var scale = new Constructor({
ctx: {},
options: config,
chart: {
data: mockData
},
id: scaleID
});

scale.determineDataLimits();
scale.buildTicks();
expect(scale.ticks).toEqual(mockData.xaxes[0].labels);
});

it ('should get the correct label for the index', function() {
var scaleID = 'myScale';

Expand Down

0 comments on commit 1a0e661

Please sign in to comment.