Skip to content

Commit

Permalink
Fix #147. Add minSegmentWidth method
Browse files Browse the repository at this point in the history
  • Loading branch information
vasturiano committed Oct 18, 2024
1 parent 7f1fc94 commit 76292cd
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ myChart
| <b>xTickFormat</b>([<i>function</i>]) | X axis tick label formatter function, as pass-through to [d3-axis](https://github.com/d3/d3-axis#axis_tickFormat). By default, it uses a [multi-scale time format](https://bl.ocks.org/mbostock/4149176). | |
| <b>dateMarker</b>([<i>date object</i>]) | Getter/setter for the date marker to show as a vertical line. If a falsy value is used, no marker is shown. | `null` |
| <b>minSegmentDuration</b>([<i>number</i>]) | Getter/setter for the minimum time duration (in msecs) of a segment in order for it to be shown. | 0 |
| <b>minSegmentWidth</b>([<i>number</i>]) | Getter/setter for the minimum displayed px width of a segment. | 1 |
| <b>getNLines</b>() | Returns number of timelines currently visible in the chart. | - |
| <b>getTotalNLines</b>() | Returns total number of timelines in the chart. | - |
| <b>zQualitative</b>([<i>boolean</i>]) | Getter/setter for whether the segment data color values are categorical (true) or quantitative (false). This will affect how the color legend is presented, and changing it will automatically toggle the `zColorScale` between defaults. | false |
Expand Down
2 changes: 2 additions & 0 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ export interface TimelinesChartGenericInstance<ChainableInstance> {
dateMarker(date: TS | null | boolean): ChainableInstance;
minSegmentDuration(): number;
minSegmentDuration(duration: number): ChainableInstance;
minSegmentWidth(): number;
minSegmentWidth(width: number): ChainableInstance;

getNLines(): number;
getTotalNLines(): number;
Expand Down
7 changes: 4 additions & 3 deletions src/timelines.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ export default Kapsule({
}
},
minSegmentDuration: {},
minSegmentWidth: { default: 1 },
zColorScale: { default: d3ScaleSequential(interpolateRdYlBu) },
zQualitative: { default: false, onChange(discrete, state) {
state.zColorScale = discrete
Expand Down Expand Up @@ -1003,7 +1004,7 @@ export default Kapsule({
return state.xScale(d.timeRange[0])-hoverEnlarge/2;
})
.attr('width', function (d) {
return d3Max([1, state.xScale(d.timeRange[1])-state.xScale(d.timeRange[0])])+hoverEnlarge;
return d3Max([state.minSegmentWidth, state.xScale(d.timeRange[1])-state.xScale(d.timeRange[0])])+hoverEnlarge;
})
.attr('y', function (d) {
return state.yScale(d.group+'+&+'+d.label)-(state.lineHeight+hoverEnlarge)/2;
Expand All @@ -1018,7 +1019,7 @@ export default Kapsule({
return state.xScale(d.timeRange[0]);
})
.attr('width', function (d) {
return d3Max([1, state.xScale(d.timeRange[1])-state.xScale(d.timeRange[0])]);
return d3Max([state.minSegmentWidth, state.xScale(d.timeRange[1])-state.xScale(d.timeRange[0])]);
})
.attr('y', function (d) {
return state.yScale(d.group+'+&+'+d.label)-state.lineHeight/2;
Expand All @@ -1038,7 +1039,7 @@ export default Kapsule({
return state.xScale(d.timeRange[0]);
})
.attr('width', function (d) {
return d3Max([1, state.xScale(d.timeRange[1])-state.xScale(d.timeRange[0])]);
return d3Max([state.minSegmentWidth, state.xScale(d.timeRange[1])-state.xScale(d.timeRange[0])]);
})
.attr('y', function (d) {
return state.yScale(d.group+'+&+'+d.label)-state.lineHeight/2;
Expand Down

0 comments on commit 76292cd

Please sign in to comment.