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

add ColorHeatmap spec #72

Merged
merged 2 commits into from
May 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/build/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@
</div>

<div class="container-fluid" id="container">Loading...</div>
<script type="text/javascript" src="bundle.4bf76ceec6eac992d822.js"></script></body>
<script type="text/javascript" src="bundle.9ad33569594b4bef01a9.js"></script></body>
</html>
2 changes: 1 addition & 1 deletion docs/src/docs/ColorHeatmap/propDocs.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
"name": "array"
},
"required": false,
"description": "...or else one will be constructed from colors, colorStops and interpolator"
"description": "...or else one will be constructed from colors, valueDomain and interpolator"
},
"valueDomain": {
"type": {
Expand Down
2 changes: 1 addition & 1 deletion src/ColorHeatmap.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export default class ColorHeatmap extends React.Component {
*/
colorScale: PropTypes.func,
/**
* ...or else one will be constructed from colors, colorStops and interpolator
* ...or else one will be constructed from colors, valueDomain and interpolator
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please run npm docs so the docs build also gets updated when we merge this in

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

*/
colors: PropTypes.array,
valueDomain: PropTypes.array,
Expand Down
4 changes: 1 addition & 3 deletions tests/jsdom/spec/AreaBarChart.spec.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import React from "react";
import * as d3 from "d3";
import _ from "lodash";
import { expect } from "chai";
import { mount, shallow } from "enzyme";
import { mount } from "enzyme";

import { testWithScales, expectProps } from "../utils";
import { XYPlot, AreaBarChart, RangeRect } from "../../../src/index.js";
import { getValue } from "../../../src/utils/Data.js";

Expand Down
70 changes: 70 additions & 0 deletions tests/jsdom/spec/ColorHeatmap.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import React from "react";
import * as d3 from "d3";
import _ from "lodash";
import { expect } from "chai";
import { mount } from "enzyme";

import { XYPlot, ColorHeatmap, RangeRect } from "../../../src/index.js";
import { getValue } from "../../../src/utils/Data.js";

describe("ColorHeatmap", () => {
const gridData = _.range(30).map(m => {
return _.range(30).map(n => {
return {
x: n,
xEnd: n + 1,
y: m,
yEnd: m + 1,
value: Math.sin(m * n * 0.01)
};
});
});
const data = _.flatten(gridData);
const props = {
data,
value: d => d.value,
x: d => d.x,
xEnd: d => d.xEnd,
y: d => d.y,
yEnd: d => d.yEnd,
xScale: d3
.scaleLinear()
.domain([-1, 0, 1])
.range([0, 30]),
yScale: d3
.scaleLinear()
.domain([0, 10])
.range([0, 30]),
colors: ['rebeccapurple', 'goldenrod'],
interpolator: 'lab',
rectClassName: 'rect-class',
};

it("renders a color heatmap", () => {
const chart = mount(<ColorHeatmap {...props} />);
const group = chart.find("g");
const rangeRects = chart.find(RangeRect);
expect(rangeRects).to.have.length(props.data.length);
});

it('passes props correctly', () => {
const chart = mount(<ColorHeatmap {...props} />);

expect(chart.find(RangeRect).first().props().x).to.equal(getValue(props.x, props.data[0]));
expect(chart.find(RangeRect).first().props().xEnd).to.equal(getValue(props.xEnd, props.data[0]));
expect(chart.find(RangeRect).first().props().y).to.equal(getValue(props.y, props.data[0]));
expect(chart.find(RangeRect).first().props().yEnd).to.equal(getValue(props.yEnd, props.data[0]));
expect(chart.find(RangeRect).first().props().xScale).to.equal(props.xScale);
expect(chart.find(RangeRect).first().props().yScale).to.equal(props.yScale);
expect(chart.find(RangeRect).first().props().className).to.equal(props.rectClassName);

describe('when colorScale prop is passed', () => {
it('sets the color scale to the prop value', () => {
const propsWithColorScale = {...props, colorScale: () => 'rgb'}
const chart = mount(<ColorHeatmap {...propsWithColorScale} />);

expect(chart.find(RangeRect).first().props().style).to.contain({ fill: 'rgb' })
});
});
});
});