Skip to content

@eightkk/vue-weave / core / createWorkingTimeScale

Function: createWorkingTimeScale() ​

createWorkingTimeScale(range, periods, pixelsPerUnit, nonWorkingRatio?): TimeScale

Defined in: src/core/workingTimeScale.ts:27

A piecewise-linear TimeScale that gives working time pixelsPerUnit pixels per time unit and non-working time pixelsPerUnit * nonWorkingRatio. Use it as the scale prop of GanttChart so working hours get more room.

  • periods are half-open [start, end) working periods, as buildWorkPeriods returns them. They are clipped to range, and they may be unsorted, overlapping or touching: they are sorted and united. Periods outside the range are ignored. Endpoints must be finite with positive length (RangeError otherwise).
  • nonWorkingRatio is a fraction in (0, 1], default 0.1. It cannot be 0: a collapsed interval would map many times to one pixel, so toTime could not invert toX. A ratio of 1 gives a plain linear scale.
  • With no working period inside the range the whole range is non-working, so the scale is linear at pixelsPerUnit * nonWorkingRatio.
  • Outside range the scale extrapolates linearly with the slope of the nearest edge segment, so toX and toTime stay strictly increasing and mutually inverse for drags past either edge. toX(range.start) is 0 and toX(range.end) is width.

Both mappings binary-search precomputed breakpoints, so a call costs O(log n) for n periods. The round trip is exact at segment boundaries and within floating-point rounding elsewhere. Changing the ratio or pixelsPerUnit changes only x positions, never times. The scale does not depend on text direction; GanttChart positions from the inline start edge in right-to-left charts.

Parameters ​

range ​

TimeRange

periods ​

readonly TimeRange[]

pixelsPerUnit ​

number

nonWorkingRatio? ​

number = defaultNonWorkingRatio

Returns ​

TimeScale

Released under the MIT License.