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
week
Shows all the weeks within the domain type
Allowed domain type: year
, month
day
Shows all the days within the domain type
Allowed domain type: year
, month
, week
hour
Shows all the hours within the domain type
Allowed domain type: month
, week
, day
year
domain is not allowed for performance issues.
minute
Shows all the minutes within the domain type
Allowed domain type: day
, hour
Other domains are not allowed for performance issues.
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
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
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.
First week of the month is computed as the week having at least 4 days in the week.
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
width
Width of each subDomain cell, in pixel
width: number,
Default: 10
height
Height of each subDomain cell, in pixel
height: number,
Default: 10
radius
Border radius of each subDomain cell, in pixel
radius: number,
Default: 0
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 Type | Description | Example Value | Example output |
---|---|---|---|
string | Pass the string to dayjs format() , and display its result. (not value aware) | MMMM | March |
null | Do not show any label | null | |
function | Display the function's return value. The function takes the subDomain's timestamp, value and the label's SVG Element as argument | function (timestamp, value) { return `${value} items on ${new Date(date).toISOString()}`; } | 50 items on 2022-12-06T20:01:51.290Z |
Depending on your chosen cell size, subDomain label may overflow
You can customize the style of the subDomain label text via css, or by
manipulating the SVGElement
given as argument when using a function
.
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 Type | Description | Example Value | Example Output |
---|---|---|---|
string | A hexadecimal color code | #000 | #000 |
function | Use the hexadecimal color code returned by the function. The function takes the subDomain's timestamp, value and background color as argument | function (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 thescale'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
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