/** * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * http://www.apache.org/licenses/LICENSE-2.0 * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import type Bounding from '../common/Bounding'; import { type AxisStyle, type Styles } from '../common/Styles'; import { type LineAttrs } from '../extension/figure/line'; import { type TextAttrs } from '../extension/figure/text'; import { type AxisTick } from '../component/Axis'; import type XAxis from '../component/XAxis'; import AxisView from './AxisView'; export default class XAxisView extends AxisView { override getAxisStyles(styles: Styles): AxisStyle { return styles.xAxis; } override createAxisLine(bounding: Bounding): LineAttrs { return { coordinates: [ { x: 0, y: 0 }, { x: bounding.width, y: 0 }, ], }; } override createTictViews( ticks: AxisTick[], _bounding: Bounding, styles: AxisStyle, ): LineAttrs[] { const tictViewStyles = styles.tictView; const axisLineSize = styles.axisLine.size; return ticks.map((tick) => ({ coordinates: [ { x: tick.coord, y: 0 }, { x: tick.coord, y: axisLineSize + tictViewStyles.length }, ], })); } override createTickTexts( ticks: AxisTick[], _bounding: Bounding, styles: AxisStyle, ): TextAttrs[] { const tickTickStyles = styles.tickText; const axisLineSize = styles.axisLine.size; const tictViewLength = styles.tictView.length; return ticks.map((tick) => ({ x: tick.coord, y: axisLineSize + tictViewLength + tickTickStyles.marginStart, text: tick.text, align: 'center', baseline: 'top', })); } }