From dabcc61c4f67dcf431bc2730acd64de32eb36b5b Mon Sep 17 00:00:00 2001 From: Tanay Vardhan Date: Mon, 10 Jun 2019 13:37:01 +0530 Subject: [PATCH 1/3] implement xy limit props --- src/XLine.js | 24 ++++++++++++++++++++++-- src/YLine.js | 11 ++++++++++- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/src/XLine.js b/src/XLine.js index aa9396c5..71f6421a 100644 --- a/src/XLine.js +++ b/src/XLine.js @@ -11,6 +11,15 @@ export default class XLine extends React.Component { */ xScale: PropTypes.func, value: PropTypes.any.isRequired, + /** + * D3 scale for Y axis - provided by XYPlot + */ + yScale: PropTypes.func, + yLimit: PropTypes.any, + /** + * The Y domain of the data as an array - provided by XYPlot + */ + yDomain: PropTypes.array, /** * Spacing top - provided by XYPlot */ @@ -39,6 +48,9 @@ export default class XLine extends React.Component { const { xScale, value, + yScale, + yLimit, + yDomain, height, style, spacingTop, @@ -47,13 +59,21 @@ export default class XLine extends React.Component { const className = `rct-chart-line-x ${this.props.className}`; const lineX = xScale(value); + let y1 = -spacingTop; + let y2 = height + spacingBottom; + + if (yLimit) { + y1 = yScale(yDomain[0]); + y2 = yScale(yLimit); + } + return ( Date: Mon, 10 Jun 2019 13:42:21 +0530 Subject: [PATCH 2/3] update documentation --- docs/src/docs/XLine/propDocs.json | 21 +++++++++++++++++++++ docs/src/docs/YLine/propDocs.json | 14 ++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/docs/src/docs/XLine/propDocs.json b/docs/src/docs/XLine/propDocs.json index 375b58b3..3d1b9cf4 100644 --- a/docs/src/docs/XLine/propDocs.json +++ b/docs/src/docs/XLine/propDocs.json @@ -16,6 +16,27 @@ "required": true, "description": "" }, + "yScale": { + "type": { + "name": "func" + }, + "required": false, + "description": "D3 scale for Y axis - provided by XYPlot" + }, + "yLimit": { + "type": { + "name": "any" + }, + "required": false, + "description": "Limit on the height of the line" + }, + "yDomain": { + "type": { + "name": "array" + }, + "required": false, + "description": "Y domain of the data as an array - provided by XYPlot" + }, "spacingTop": { "type": { "name": "number" diff --git a/docs/src/docs/YLine/propDocs.json b/docs/src/docs/YLine/propDocs.json index 6b7d5e49..cf270778 100644 --- a/docs/src/docs/YLine/propDocs.json +++ b/docs/src/docs/YLine/propDocs.json @@ -16,6 +16,20 @@ "required": true, "description": "" }, + "xScale": { + "type": { + "name": "func" + }, + "required": false, + "description": "D3 scale for X axis - provided by XYPlot" + }, + "xLimit": { + "type": { + "name": "any" + }, + "required": false, + "description": "Limit on the width of the line" + }, "spacingLeft": { "type": { "name": "number" From d089a0f66fcb54b2fecf9bc4acdcba0441860108 Mon Sep 17 00:00:00 2001 From: Tanay Vardhan Date: Sat, 29 Jun 2019 23:23:37 +0530 Subject: [PATCH 3/3] add test cases, better undefined check for XLine --- src/XLine.js | 4 ++-- tests/jsdom/spec/XLine.spec.js | 16 ++++++++++++++++ tests/jsdom/spec/YLine.spec.js | 15 +++++++++++++++ 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/src/XLine.js b/src/XLine.js index 71f6421a..2ac4c890 100644 --- a/src/XLine.js +++ b/src/XLine.js @@ -62,8 +62,8 @@ export default class XLine extends React.Component { let y1 = -spacingTop; let y2 = height + spacingBottom; - if (yLimit) { - y1 = yScale(yDomain[0]); + if (typeof yLimit !== "undefined") { + y1 = yScale(yDomain[0]) + spacingBottom; y2 = yScale(yLimit); } diff --git a/tests/jsdom/spec/XLine.spec.js b/tests/jsdom/spec/XLine.spec.js index d47aaf63..eb8db0a7 100644 --- a/tests/jsdom/spec/XLine.spec.js +++ b/tests/jsdom/spec/XLine.spec.js @@ -110,4 +110,20 @@ describe("XLine", () => { ); expect(findLine(wrapper).prop("style")).to.deep.equal(style); }); + + it("limits the line's height using yLimit", () => { + const limit = 2; + let wrapper = shallow( + + ); + expect(getLineHeight(findLine(wrapper))).to.equal(linearScale(limit)); + }); + }); diff --git a/tests/jsdom/spec/YLine.spec.js b/tests/jsdom/spec/YLine.spec.js index 78f21e51..ebcf37f2 100644 --- a/tests/jsdom/spec/YLine.spec.js +++ b/tests/jsdom/spec/YLine.spec.js @@ -110,4 +110,19 @@ describe("YLine", () => { ); expect(findLine(wrapper).prop("style")).to.deep.equal(style); }); + + it("limits the line's width using xLimit", () => { + const limit = 2; + let wrapper = shallow( + + ); + expect(getLineWidth(findLine(wrapper))).to.equal(linearScale(limit)); + }); + });