| Name | Type | Default | Description
| ---- | ---- | ------- | -----------
-| `align` | `string` | `'center'` | The tick alignment along the axis. Can be `'start'`, `'center'`, or `'end'`.
+| `align` | `string` | `'center'` | The tick alignment along the axis. Can be `'start'`, `'center'`, `'end'`, or `'inner'`. `inner` alignment means align `start` for first tick and `end` for the last tick of horizontal axis
| `crossAlign` | `string` | `'near'` | The tick alignment perpendicular to the axis. Can be `'near'`, `'center'`, or `'far'`. See [Tick Alignment](/axes/cartesian/#tick-alignment)
| `sampleSize` | `number` | `ticks.length` | The number of ticks to examine when deciding how many labels will fit. Setting a smaller value will be faster, but may be less accurate when there is large variability in label length.
| `autoSkip` | `boolean` | `true` | If true, automatically calculates how many labels can be shown and hides labels accordingly. Labels will be rotated up to `maxRotation` before skipping any. Turn `autoSkip` off to show all labels no matter what.
paddingRight = last.width;
} else if (align === 'end') {
paddingLeft = first.width;
- } else {
+ } else if (align !== 'inner') {
paddingLeft = first.width / 2;
paddingRight = last.width / 2;
}
const color = optsAtIndex.color;
const strokeColor = optsAtIndex.textStrokeColor;
const strokeWidth = optsAtIndex.textStrokeWidth;
+ let tickTextAlign = textAlign;
if (isHorizontal) {
x = pixel;
+
+ if (textAlign === 'inner') {
+ if (i === ilen - 1) {
+ tickTextAlign = !this.options.reverse ? 'right' : 'left';
+ } else if (i === 0) {
+ tickTextAlign = !this.options.reverse ? 'left' : 'right';
+ } else {
+ tickTextAlign = 'center';
+ }
+ }
+
if (position === 'top') {
if (crossAlign === 'near' || rotation !== 0) {
textOffset = -lineCount * lineHeight + lineHeight / 2;
strokeColor,
strokeWidth,
textOffset,
- textAlign,
+ textAlign: tickTextAlign,
textBaseline,
translation: [x, y],
backdrop,
align = 'left';
} else if (ticks.align === 'end') {
align = 'right';
+ } else if (ticks.align === 'inner') {
+ align = 'inner';
}
return align;
--- /dev/null
+module.exports = {
+ config: {
+ type: 'line',
+ data: {
+ datasets: [{
+ data: [1, 2, 3],
+ }],
+ labels: ['Label1_long', 'Label2_long', 'Label3_long']
+ },
+ options: {
+ scales: {
+ x: {
+ ticks: {
+ align: 'inner',
+ },
+ },
+ y: {
+ display: false
+ }
+ }
+ }
+ },
+ options: {
+ spriteText: true,
+ canvas: {
+ height: 256,
+ width: 512
+ }
+ }
+};
--- /dev/null
+module.exports = {
+ config: {
+ type: 'line',
+ data: {
+ datasets: [{
+ data: [1, 2, 3],
+ }],
+ labels: ['Label1', 'Label2', 'Label3']
+ },
+ options: {
+ scales: {
+ x: {
+ ticks: {
+ align: 'inner'
+ },
+ reverse: true
+ }
+ }
+ }
+ },
+ options: {
+ spriteText: true,
+ canvas: {
+ height: 256,
+ width: 512
+ }
+ }
+};
--- /dev/null
+module.exports = {
+ config: {
+ type: 'line',
+ data: {
+ datasets: [{
+ data: [1, 2, 3],
+ }],
+ labels: ['Label1', 'Label2', 'Label3']
+ },
+ options: {
+ scales: {
+ x: {
+ ticks: {
+ align: 'inner',
+ maxRotation: 45,
+ minRotation: 45
+ },
+ }
+ }
+ }
+ },
+ options: {
+ spriteText: true,
+ canvas: {
+ height: 256,
+ width: 512
+ }
+ }
+};
--- /dev/null
+module.exports = {
+ config: {
+ type: 'line',
+ data: {
+ datasets: [{
+ data: [1, 2, 3],
+ }],
+ labels: ['Label1', 'Label2', 'Label3']
+ },
+ options: {
+ scales: {
+ x: {
+ ticks: {
+ align: 'inner',
+ },
+ }
+ }
+ }
+ },
+ options: {
+ spriteText: true,
+ canvas: {
+ height: 256,
+ width: 512
+ }
+ }
+};
* The label alignment
* @default 'center'
*/
- align: Align;
+ align: Align | 'inner';
/**
* If true, automatically calculates how many labels can be shown and hides labels accordingly. Labels will be rotated up to maxRotation before skipping any. Turn autoSkip off to show all labels no matter what.
* @default true