Skip to content

Commit ac216bd

Browse files
sartaj10pjm17971
authored andcommitted
Fix issues (#166)
* Added an option to overlay or underlay the Grid * Make requested changes * Fix Issue #141 : Brush gets stuck * Fix Issue #150 : Control tick count * Add link to source code Issue #133
1 parent acac053 commit ac216bd

File tree

5 files changed

+56
-20
lines changed

5 files changed

+56
-20
lines changed

lib/components/YAxis.js

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -198,12 +198,21 @@ var YAxis = function (_React$Component) {
198198
var axis = align === "left" ? _d3Axis.axisLeft : _d3Axis.axisRight;
199199
if (this.props.type === "linear" || this.props.type === "power") {
200200
if (this.props.height <= 200) {
201-
axisGenerator = axis(scale).ticks(5).tickFormat(function (d) {
202-
if (absolute) {
203-
return yformat(Math.abs(d));
204-
}
205-
return yformat(d);
206-
}).tickSizeOuter(0);
201+
if (this.props.tickCount > 0) {
202+
axisGenerator = axis(scale).ticks(this.props.tickCount).tickFormat(d => {
203+
if (absolute) {
204+
return yformat(Math.abs(d));
205+
}
206+
return yformat(d);
207+
}).tickSizeOuter(0);
208+
} else {
209+
axisGenerator = axis(scale).ticks(5).tickFormat(function (d) {
210+
if (absolute) {
211+
return yformat(Math.abs(d));
212+
}
213+
return yformat(d);
214+
}).tickSizeOuter(0);
215+
}
207216
} else {
208217
axisGenerator = axis(scale).tickFormat(function (d) {
209218
if (absolute) {
@@ -349,5 +358,9 @@ YAxis.propTypes = {
349358
/**
350359
* [Internal] The height supplied by the surrounding ChartContainer
351360
*/
352-
height: _propTypes2.default.number
361+
height: _propTypes2.default.number,
362+
/**
363+
* The number of ticks
364+
*/
365+
tickCount: _propTypes2.default.number
353366
};

src/components/Brush.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,20 +157,22 @@ export default class Brush extends React.Component {
157157
this.props.timeScale.invert(xy[0]).getTime();
158158

159159
// Constrain
160+
let startOffsetConstraint = timeOffset;
161+
let endOffsetConstrain = timeOffset;
160162
if (tb - timeOffset < viewport.begin()) {
161-
timeOffset = tb - viewport.begin().getTime();
163+
startOffsetConstraint = tb - viewport.begin().getTime();
162164
}
163165
if (te - timeOffset > viewport.end()) {
164-
timeOffset = te - viewport.end().getTime();
166+
endOffsetConstrain = te - viewport.end().getTime();
165167
}
166168

167169
newBegin = this.state.brushingInitializationSite === "brush" ||
168170
this.state.brushingInitializationSite === "handle-left"
169-
? parseInt(tb - timeOffset, 10)
171+
? parseInt(tb - startOffsetConstraint, 10)
170172
: tb;
171173
newEnd = this.state.brushingInitializationSite === "brush" ||
172174
this.state.brushingInitializationSite === "handle-right"
173-
? parseInt(te - timeOffset, 10)
175+
? parseInt(te - endOffsetConstrain, 10)
174176
: te;
175177

176178
// Swap if needed

src/components/YAxis.js

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -174,12 +174,21 @@ export default class YAxis extends React.Component {
174174
const axis = align === "left" ? axisLeft : axisRight;
175175
if (this.props.type === "linear" || this.props.type === "power") {
176176
if (this.props.height <= 200) {
177-
axisGenerator = axis(scale).ticks(5).tickFormat(d => {
178-
if (absolute) {
179-
return yformat(Math.abs(d));
180-
}
181-
return yformat(d);
182-
}).tickSizeOuter(0);
177+
if (this.props.tickCount > 0) {
178+
axisGenerator = axis(scale).ticks(this.props.tickCount).tickFormat(d => {
179+
if (absolute) {
180+
return yformat(Math.abs(d));
181+
}
182+
return yformat(d);
183+
}).tickSizeOuter(0);
184+
} else {
185+
axisGenerator = axis(scale).ticks(5).tickFormat(d => {
186+
if (absolute) {
187+
return yformat(Math.abs(d));
188+
}
189+
return yformat(d);
190+
}).tickSizeOuter(0);
191+
}
183192
} else {
184193
axisGenerator = axis(scale).tickFormat(d => {
185194
if (absolute) {
@@ -279,7 +288,7 @@ YAxis.defaultProps = {
279288
labelOffset: 0, // Offset the label position
280289
transition: 100, // Axis transition time
281290
width: 80,
282-
style: defaultStyle
291+
style: defaultStyle,
283292
};
284293

285294
YAxis.propTypes = {
@@ -360,5 +369,9 @@ YAxis.propTypes = {
360369
/**
361370
* [Internal] The height supplied by the surrounding ChartContainer
362371
*/
363-
height: PropTypes.number
372+
height: PropTypes.number,
373+
/**
374+
* The number of ticks
375+
*/
376+
tickCount: PropTypes.number
364377
};

src/website/api/docs.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4132,6 +4132,13 @@
41324132
},
41334133
"required": false,
41344134
"description": "[Internal] The height supplied by the surrounding ChartContainer"
4135+
},
4136+
"tickCount": {
4137+
"type": {
4138+
"name": "number"
4139+
},
4140+
"required": false,
4141+
"description": "The number of ticks"
41354142
}
41364143
}
41374144
}

src/website/examples/Example.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,15 @@ export default React.createClass({
2929
const ExampleMetaData = Meta[exampleName];
3030
const Component = Examples[exampleName];
3131
const docs = Examples[`${exampleName}_docs`];
32-
32+
const sourceCode = "https://github.com/esnet/react-timeseries-charts/tree/master/src/website/examples/" + exampleName;
3333
return (
3434
<div>
3535
<div className="row">
3636
<div className="col-md-12">
3737
<div className="row">
3838
<div className="col-md-12">
3939
<h3>{ExampleMetaData.title}</h3>
40+
<a href={sourceCode} target="_blank">Source Code</a>
4041
<p>
4142
{ExampleMetaData.description}
4243
</p>

0 commit comments

Comments
 (0)