Skip to main content

subDomain

Specify all options related to the subDomain configuration

type subDomain: {
type: string,
gutter: number,
width: number,
height: number,
radius: number,
label:
| string
| null
| ((timestamp: number, value: number, element: SVGElement) => string);
color?:
| string
| ((timestamp: number, value: number, backgroundColor: string) => string);
}

type

SubDomain's type, representing a time unit.

This is the time unit represented by each cell in the calendar.

type: string,

The subDomain should always be smaller than the domain type.

Each subdomain type have their own layout (rows/columns count, etc ...)

month

Shows all the months within the domain type

Allowed domain type: year

http://localhost:3000
Live Editor
Result
Loading...

week

Shows all the weeks within the domain type

Allowed domain type: year, month

http://localhost:3000
Live Editor
Result
Loading...

day

Shows all the days within the domain type

Allowed domain type: year, month, week

http://localhost:3000
Live Editor
Result
Loading...

hour

Shows all the hours within the domain type

Allowed domain type: month, week, day

caution

year domain is not allowed for performance issues.

http://localhost:3000
Live Editor
Result
Loading...

minute

Shows all the minutes within the domain type

Allowed domain type: day, hour

caution

Other domains are not allowed for performance issues.

http://localhost:3000
Live Editor
Result
Loading...

There's 2 additional variants for the day type

xDay

Shows all the days within the domain type, but from left to right, and top to bottom

Allowed domain type: year, month, week

http://localhost:3000
Live Editor
Result
Loading...

ghDay

Shows all the days within the domain type, but domain start and end are rounded to the first and end of week of the month, so that each column has the same number of days.

This subDomain type ensure that there is no gap between domains, as opposed to just day

Allowed domain type: month

http://localhost:3000
Live Editor
Result
Loading...

Note in the above example that the domains does not start and end exactly on the first and last day of each month, each column represent a full week, to avoid partially populated column seen in xDay type.

caution

First week of the month is computed as the week having at least 4 days in the week.

tip

You can create and add your own custom subDomain type, see the Template section.

gutter

Space between each subDomain, in pixel

gutter: number,

Default: 2

http://localhost:3000
Live Editor
Result
Loading...

width

Width of each subDomain cell, in pixel

width: number,

Default: 10

http://localhost:3000
Live Editor
Result
Loading...

height

Height of each subDomain cell, in pixel

height: number,

Default: 10

http://localhost:3000
Live Editor
Result
Loading...

radius

Border radius of each subDomain cell, in pixel

radius: number,

Default: 0

http://localhost:3000
Live Editor
Result
Loading...

label

Label of the subDomain

label:
| string
| null
| ((timestamp: number, value: number, element: SVGElement) => string);

Default: null

This option accepts different value's type, see table below for usage.

Value TypeDescriptionExample ValueExample output
stringPass the string to dayjs format(), and display its result. (not value aware)MMMMMarch
nullDo not show any labelnull
functionDisplay the function's return value. The function takes the subDomain's timestamp, value and the label's SVG Element as argumentfunction (timestamp, value) { return `${value} items on ${new Date(date).toISOString()}`; }50 items on 2022-12-06T20:01:51.290Z
tip

dayjs format() is locale and timezone aware.

caution

Depending on your chosen cell size, subDomain label may overflow

tip

You can customize the style of the subDomain label text via css, or by manipulating the SVGElement given as argument when using a function.

http://localhost:3000
Live Editor
Result
Loading...

color

Color of the subDomain's label

color?:
| string
| ((timestamp: number, value: number, backgroundColor: string) => string);

Default:

d3.hcl(backgroundColor).l > 60 ? 'black' : 'white';

This option accepts different value's type, see table below for usage.

Value TypeDescriptionExample ValueExample Output
stringA hexadecimal color code#000#000
functionUse the hexadecimal color code returned by the function. The function takes the subDomain's timestamp, value and background color as argumentfunction (timestamp, value, backgroundColor) { return d3.hcl(backgroundColor).l > 60 ? 'black' : 'white' ; }#000

Using the string value, the same color will be applied to the whole calendar, regardless of the subDomain's background color. Depending on your color scale, the label color may not be readable.

Using a function will allow more fine-tuning of the label color, as you can use:

  • a d3-color scale
  • a range of static colors (i.e ['#fff', '#eee', '#000'], matching the scale's range)
  • a custom function returning a color, computed from the background color (like the default value)

sort

Sort order of the subDomains.

sort: 'asc' | 'desc';

Default: asc

http://localhost:3000
Live Editor
Result
Loading...
Option scope

This only affect the subDomain's order, not the Domain. See Domain.sort to also set the domains sort order.

You can achieve a RTL result by setting both values to desc