-
Notifications
You must be signed in to change notification settings - Fork 76
Support for a wickStrokeWidth style prop #330
Conversation
src/victory-primitives/candle.js
Outdated
const shapeRendering = props.shapeRendering || "auto"; | ||
const role = props.role || "presentation"; | ||
const wickStyle = assign({}, this.style, { strokeWidth: props.style.wickStrokeWidth || props.style.strokeWidth }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use lodash defaults
here.
@kale-stew can you figure out some logic within |
@kale-stew please remember to lint. You can run the lint command with |
…ory-core into feature/886-wickStrokeWidth
@boygirl here are those changes! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some small changes, but this is looking good overall.
src/victory-primitives/candle.js
Outdated
{ x1: x, x2: x, y1, y2, style: this.style, role, shapeRendering, className }, | ||
events | ||
); | ||
const wickStyle = assign( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be refactored to use defaults
rather than assign
with a conditional
src/victory-primitives/candle.js
Outdated
@@ -34,16 +36,16 @@ export default class Candle extends React.Component { | |||
} | |||
|
|||
shouldComponentUpdate(nextProps) { | |||
const { className, candleHeight, datum, x, y, y1, y2 } = this.props; | |||
const { className, candleHeight, datum, x, y, high, low } = this.props; | |||
const { style, candleWidth } = this.calculateAttributes(nextProps); | |||
|
|||
if (!Collection.allSetsEqual([ | |||
[className, nextProps.className], | |||
[candleHeight, nextProps.candleHeight], | |||
[x, nextProps.x], | |||
[y, nextProps.y], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no longer a y
prop. Should be comparing both open
and close
instead.
src/victory-primitives/candle.js
Outdated
); | ||
const lowWick = Math.min(close, open); | ||
const highWick = Math.max(close, open); | ||
const wickStyle = assign( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would be better written as:
const wickStyle = defaults({}, this.style, { strokeWidth: widthStrokeWidth })
the defaults
method doesn't overwrite values with undefined
expect(wick.prop("x2")).to.eql(5); | ||
expect(wick.prop("y1")).to.eql(50); | ||
expect(wick.prop("y2")).to.eql(5); | ||
expect(wrapper.find("line")).to.have.length(2); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can do something like
const wicks = wrapper.find("line");
wicks.forEach((wick, index) => {
expect(wick.prop("x1")).to.eql(5);
expect ...
});
@@ -39,7 +34,6 @@ describe("victory-primitives/candle", () => { | |||
expect(rect.prop("height")).to.eql(20); | |||
// x = x - width / 2 | |||
expect(rect.prop("x")).to.eql(4); | |||
expect(rect.prop("y")).to.eql(30); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't expect(rect.prop("y")).to.eql(30);
still be true?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would have thought so, but it returns undefined
when I run the test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tooling around with it more and I've graduated from undefined
to NaN
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like you need to add close
and open
to the props you're using to render the test component.
@boygirl fingers crossed but this should be it :) |
src/victory-primitives/candle.js
Outdated
); | ||
const lowWick = Math.min(close, open); | ||
const highWick = Math.max(close, open); | ||
const wickStyle = defaults({}, this.style, { strokeWidth: wickStrokeWidth }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one is my fault, but the ordering for defaults
is backwards. It should be defaults({ strokeWidth: wickStrokeWidth }, this.style)
. Otherwise, the style will always override the wickStrokeWidth
Approved! Good to merge once CI passes :) |
Overview
Supply a
wickStrokeWidth
value to see a difference between the candle's stroke width and the wick's stroke width.When supplied a
wickStrokeWidth
without a separatestrokeWidth
assignment, the candlestick will fallback to thewickStrokeWidth
for the candle'sstrokeWidth
.This PR is prerequisite to this PR in victory-chart.
Example
renders this chart:
Original Issue:
Victory Issue #886