Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reproducible clouds #81

Merged
merged 10 commits into from
Jun 25, 2015
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"canvas": "^1.2.1"
},
"devDependencies": {
"jsdom": "^3.0.0"
"jsdom": "^3.0.0",
"mersenne-twister": "^1.0.1"
}
}
}
7 changes: 6 additions & 1 deletion src/d3.layout.cloud.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ else cloud(this.d3);
function cloud(d3) {
var random = Math.random;
d3.layout.cloud = function cloud() {
var size = [256, 256],
var DEFAULT_WIDTH = 256,
DEFAULT_HEIGHT = 256,
size = [DEFAULT_WIDTH, DEFAULT_HEIGHT],
startPoint = null,
text = cloudText,
font = cloudFont,
Expand Down Expand Up @@ -179,6 +181,9 @@ function cloud(d3) {
};

cloud.size = function(_) {
if (!arguments.length) return size;
if (!_[0] || _[0] < 0) _[0] = DEFAULT_WIDTH;
if (!_[1] || _[1] < 1) _[1] = DEFAULT_HEIGHT;
return arguments.length ? (size = [+_[0], +_[1]], cloud) : size;
};

Expand Down
3 changes: 3 additions & 0 deletions test/SpecRunner.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@
<script type="text/javascript" src="bower_components/jasmine/lib/jasmine-core/jasmine-html.js"></script>
<script type="text/javascript" src="bower_components/jasmine/lib/jasmine-core/boot.js"></script>

<script type="text/javascript" src="../node_modules/mersenne-twister/src/mersenne-twister.js"></script>

<script type="text/javascript" src="bower_components/d3/d3.js"></script>
<script type="text/javascript" src="../src/d3.layout.cloud.js"></script>

<!-- include spec files here... -->
<script type="text/javascript" src="d3.layout.cloud-spec.js"></script>
<script type="text/javascript" src="amd-spec.js"></script>
<script type="text/javascript" src="simple-cloud-spec.js"></script>
<script type="text/javascript" src="replicable-layout-spec.js"></script>

</body>
</html>
22 changes: 22 additions & 0 deletions test/d3.layout.cloud-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,28 @@

});

describe('size()', function() {

var mySizeCloud = cloud()
.size([300, 400]);

it('should have a size() function which sets and/or returns the size of the svg of the cloud', function() {
expect(mySizeCloud.size()).toEqual([300, 400]);
});

it('should survive an invalid a size()', function() {
expect(mySizeCloud.size([null, null]).size()).toEqual([256, 256]);
});

it('should survive a string size()', function() {
expect(mySizeCloud.size(['22', '505.4']).size()).toEqual([22, 505.4]);
});

it('should survive a negative size()', function() {
expect(mySizeCloud.size([-20, -30.5]).size()).toEqual([256, 256]);
});
});

describe('start()', function() {

var myStartedCloud = cloud()
Expand Down
File renamed without changes.
Loading