Skip to content

Commit 810ebd0

Browse files
committed
docs(Docs): update API method
1 parent 162972e commit 810ebd0

File tree

5 files changed

+51
-23
lines changed

5 files changed

+51
-23
lines changed

docs/Axes.md

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,6 @@ const timeline = new Timeline({
148148
},
149149
viewConfiguration: {
150150
axes: {
151-
trackHeight: 30,
152151
lineWidth: 1,
153152
color: {
154153
line: '#e0e0e0'
@@ -188,8 +187,6 @@ const timeline = new Timeline({
188187
},
189188
viewConfiguration: {
190189
axes: {
191-
// Customize axis appearance
192-
trackHeight: 40,
193190
lineWidth: 2,
194191
color: {
195192
line: '#b0b0b0'
@@ -220,17 +217,16 @@ constructor(api: CanvasApi) {
220217

221218
### Track Position Calculation
222219

223-
Track positions are calculated based on the axis configuration and visual settings:
220+
Track positions are calculated based on the axis configuration (each axis has its own `height` per track):
224221

225222
```typescript
226223
public getAxisTrackPosition(axis: Axis, trackIndex: number): number {
227224
if (!axis || axis.tracksCount < 0) {
228225
throw new Error("Invalid axis configuration");
229226
}
230227

231-
const { axes } = this.api.getVisualConfiguration();
232228
const index = clamp(trackIndex, 0, axis.tracksCount - 1);
233-
return axis.top + axes.trackHeight * index + axes.trackHeight / 2;
229+
return axis.top + axis.height * index + axis.height / 2;
234230
}
235231
```
236232

@@ -240,7 +236,7 @@ The rendering process handles both straight and dashed line modes:
240236

241237
```typescript
242238
public render() {
243-
const { ruler, axes } = this.api.getVisualConfiguration();
239+
const { axes } = this.api.getViewConfiguration();
244240
const { ctx } = this.api;
245241

246242
// Set line style based on mode
@@ -250,7 +246,7 @@ public render() {
250246

251247
// Apply scroll transform and ruler offset
252248
this.api.useScrollTransform();
253-
ctx.translate(0, ruler.height);
249+
ctx.translate(0, this.api.getRulerHeight());
254250

255251
// Render tracks for each axis
256252
ctx.strokeStyle = axes.color.line;
@@ -279,7 +275,7 @@ public render() {
279275

280276
2. **Visual Customization**
281277
- Choose appropriate line styles (straight/dashed)
282-
- Set track heights based on content
278+
- Set `height` per axis (height of each track in that axis)
283279
- Use consistent colors across related axes
284280

285281
3. **Performance**

docs/CanvasApi.md

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,8 @@ api.setMarkers([
166166
{
167167
time: Date.now() + 1800000,
168168
color: '#ff0000',
169+
activeColor: '#ff5252',
170+
hoverColor: '#ff1744',
169171
label: 'Important Point'
170172
}
171173
]);
@@ -185,6 +187,37 @@ api.setSelectedEvents(['event1', 'event2']);
185187
**Parameters:**
186188
- `ids`: Array of event IDs to select
187189

190+
#### `setSections(sections: TimelineSection[])`
191+
192+
Updates the timeline sections.
193+
194+
```typescript
195+
api.setSections([
196+
{
197+
id: 'section1',
198+
from: Date.now(),
199+
to: Date.now() + 1800000,
200+
color: 'rgba(255, 193, 7, 0.2)',
201+
hoverColor: 'rgba(255, 193, 7, 0.3)'
202+
}
203+
]);
204+
```
205+
206+
**Parameters:**
207+
- `sections`: Array of section configurations
208+
209+
#### `setViewConfiguration(viewConfiguration: ViewConfiguration)`
210+
211+
Updates the view configuration. **Merges with the current configuration** (does not replace it entirely).
212+
213+
```typescript
214+
api.setViewConfiguration({ hideRuler: true });
215+
api.setViewConfiguration({ axes: { lineWidth: 2 } });
216+
```
217+
218+
**Parameters:**
219+
- `viewConfiguration`: Partial view configuration to merge in
220+
188221
### Utility Methods
189222

190223
#### `timeToPosition(t: number): number`
@@ -240,7 +273,7 @@ const duration = api.widthToTime(200);
240273
| `currentTime` | `number` | Current timestamp (aligned to seconds) |
241274
| `emit` | `Function` | Event emitter function |
242275
| `getInterval()` | `{ start: number; end: number }` | Current timeline range |
243-
| `getVisualConfiguration()` | `ViewConfigurationDefault` | Current view configuration |
276+
| `getViewConfiguration()` | `ViewConfigurationDefault` | Current view configuration |
244277
| `getTimelineSettings()` | `TimelineSettings` | Current timeline settings |
245278

246279
## Examples
@@ -327,7 +360,7 @@ api.setSelectedEvents(['event1']);
327360
// Get current timeline state
328361
const { start, end } = api.getInterval();
329362
const settings = api.getTimelineSettings();
330-
const config = api.getVisualConfiguration();
363+
const config = api.getViewConfiguration();
331364
```
332365

333366
## Implementation Details

docs/Grid.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ private selectGridLevel(domainSize: number, canvasWidth: number): TGridLevel | n
172172

173173
// Check if marks fit within visible area
174174
if (this.calculateMarksWidth(level, domainSize) >
175-
canvasWidth + this.api.getVisualConfiguration().grid.widthBuffer) {
175+
canvasWidth + this.api.getViewConfiguration().grid.widthBuffer) {
176176
continue;
177177
}
178178

@@ -190,7 +190,7 @@ Grid lines are rendered using the canvas 2D context:
190190

191191
```typescript
192192
private renderLevel(top: number, left: number, width: number, height: number, level: TGridLevel) {
193-
const { grid } = this.api.getVisualConfiguration();
193+
const { grid } = this.api.getViewConfiguration();
194194
const { start, end } = this.api.getInterval();
195195
const { ctx } = this.api;
196196

docs/Ruler.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ private renderLevel(
336336
y: number,
337337
color: string,
338338
) {
339-
const { ruler } = this.api.getVisualConfiguration();
339+
const { ruler } = this.api.getViewConfiguration();
340340
const { start, end } = this.api.getInterval();
341341
const { ctx, width } = this.api;
342342

docs/docs.md

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,14 @@ const timeline = new Timeline({
3535
Manages and renders timeline events with support for selection, interaction, and custom rendering.
3636

3737
```typescript
38-
// Events are managed through the Timeline instance
39-
timeline.settings.events = [{
38+
// Events are managed through the Timeline API
39+
timeline.api.setEvents([{
4040
id: '1',
4141
axisId: 'axis1',
4242
trackIndex: 0,
4343
from: Date.now(),
4444
to: Date.now() + 1800000
45-
}];
45+
}]);
4646
```
4747

4848
### [Ruler](./Ruler.md)
@@ -176,12 +176,11 @@ const event = {
176176

177177
Visit our [Storybook](https://preview.gravity-ui.com/timeline/) to explore interactive examples:
178178

179-
- [Basic Timeline](https://preview.gravity-ui.com/timeline/?path=/story/basic-timeline--default)
180-
- [Multiple Axes](https://preview.gravity-ui.com/timeline/?path=/story/multiple-axes--default)
181-
- [Custom Events](https://preview.gravity-ui.com/timeline/?path=/story/custom-events--default)
182-
- [Markers](https://preview.gravity-ui.com/timeline/?path=/story/markers--default)
183-
- [Grid Customization](https://preview.gravity-ui.com/timeline/?path=/story/grid-customization--default)
184-
- [Ruler Customization](https://preview.gravity-ui.com/timeline/?path=/story/ruler-customization--default)
179+
- [Basic Timeline](https://preview.gravity-ui.com/timeline/?path=/story/timeline-events--basic) — Simple timeline with events and axes
180+
- [Endless Timeline](https://preview.gravity-ui.com/timeline/?path=/story/timeline-events--endless-timelines) — Endless timeline with events and axes
181+
- [Markers](https://preview.gravity-ui.com/timeline/?path=/story/timeline-markers--basic) — Timeline with vertical markers and labels
182+
- [Custom Events](https://preview.gravity-ui.com/timeline/?path=/story/timeline-events--custom-renderer) — Timeline with custom event rendering
183+
- [Integrations](https://preview.gravity-ui.com/timeline/?path=/story/integrations-gravity-ui--timeline-ruler) — RangeDateSelection, DragHandler, NestedEvents, Popup, List
185184

186185
## Best Practices
187186

0 commit comments

Comments
 (0)