Skip to content
This repository has been archived by the owner on Feb 19, 2022. It is now read-only.

Support for a wickStrokeWidth style prop #330

Merged
merged 16 commits into from
Jan 29, 2018
Merged

Conversation

kale-stew
Copy link

@kale-stew kale-stew commented Jan 19, 2018

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 separate strokeWidth assignment, the candlestick will fallback to the wickStrokeWidth for the candle's strokeWidth.

This PR is prerequisite to this PR in victory-chart.

Example

<VictoryCandlestick
  wickStrokeWidth={12}
  style={{ data: { 
    fill: "#c43a31", 
    fillOpacity: 0.7, 
    stroke: "#c43a31", 
    strokeWidth: 3 
  }, parent: style.parent }}
  data={data}
/>

renders this chart:

screen shot 2018-01-25 at 1 17 56 pm

Original Issue:

Victory Issue #886

const shapeRendering = props.shapeRendering || "auto";
const role = props.role || "presentation";
const wickStyle = assign({}, this.style, { strokeWidth: props.style.wickStrokeWidth || props.style.strokeWidth });
Copy link
Contributor

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.

@boygirl
Copy link
Contributor

boygirl commented Jan 19, 2018

@kale-stew can you figure out some logic within Candle so that the wick never intersects the candle? Swapping open and close isn't an option, as the order of those values is meaningful to the chart.

@boygirl
Copy link
Contributor

boygirl commented Jan 19, 2018

@kale-stew please remember to lint. You can run the lint command with npm run check (to run both linting and testing) or builder run lint to run only linting.

@kale-stew
Copy link
Author

@boygirl here are those changes!

Copy link
Contributor

@boygirl boygirl left a 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.

{ x1: x, x2: x, y1, y2, style: this.style, role, shapeRendering, className },
events
);
const wickStyle = assign(
Copy link
Contributor

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

@@ -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],
Copy link
Contributor

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.

);
const lowWick = Math.min(close, open);
const highWick = Math.max(close, open);
const wickStyle = assign(
Copy link
Contributor

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);
Copy link
Contributor

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);
Copy link
Contributor

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?

Copy link
Author

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

Copy link
Author

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.

Copy link
Contributor

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.

@kale-stew
Copy link
Author

@boygirl fingers crossed but this should be it :)

);
const lowWick = Math.min(close, open);
const highWick = Math.max(close, open);
const wickStyle = defaults({}, this.style, { strokeWidth: wickStrokeWidth });
Copy link
Contributor

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

@boygirl
Copy link
Contributor

boygirl commented Jan 29, 2018

Approved! Good to merge once CI passes :)

@kale-stew kale-stew merged commit 9648031 into master Jan 29, 2018
@kale-stew kale-stew deleted the feature/886-wickStrokeWidth branch January 29, 2018 20:04
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants