feat(chart): support configurable plot margins
All checks were successful
Package component / package (push) Successful in 7m2s
All checks were successful
Package component / package (push) Successful in 7m2s
This commit is contained in:
@@ -7,6 +7,9 @@
|
||||
/** 图表边距 */
|
||||
export const margin = { top: 18, right: 24, bottom: 52, left: 64 }
|
||||
|
||||
/** Distance from the drawing SVG bottom edge to the X-axis title baseline. */
|
||||
export const X_AXIS_TITLE_BOTTOM_OFFSET = 12
|
||||
|
||||
/**
|
||||
* 图表最小高度(像素)
|
||||
*/
|
||||
|
||||
@@ -24,7 +24,6 @@ import {
|
||||
normalizeGridOptions,
|
||||
paginateSeries,
|
||||
resolveGridCellGeometry,
|
||||
X_AXIS_BAND,
|
||||
} from './grid'
|
||||
import {
|
||||
buildTrackLayouts,
|
||||
@@ -316,7 +315,6 @@ export function useWaveformLayout(context: LayoutContext) {
|
||||
)
|
||||
: [],
|
||||
)
|
||||
const xAxisTitleY = computed(() => innerHeight.value + X_AXIS_BAND + 10)
|
||||
const editorSeries = computed<AnnotationSeriesInfo | undefined>(() => {
|
||||
const seriesId = annotationInteraction.editorDraft.value?.annotation.seriesId
|
||||
const series = chartSeries.value.find((item) => item.id === seriesId)
|
||||
@@ -360,7 +358,6 @@ export function useWaveformLayout(context: LayoutContext) {
|
||||
resolveSeriesYScale,
|
||||
annotationTrackLayouts,
|
||||
renderedAnnotations,
|
||||
xAxisTitleY,
|
||||
editorSeries,
|
||||
resolveFrameNumber,
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import {
|
||||
TITLE_CHAR_WIDTH_RATIO,
|
||||
TITLE_DEFAULT_FONT_SIZE,
|
||||
TITLE_LINE_HEIGHT,
|
||||
X_AXIS_TITLE_BOTTOM_OFFSET,
|
||||
ZERO_LINE_DEFAULTS,
|
||||
} from './constants'
|
||||
import { calculateRotatedTitleLayout, TITLE_AREA_HORIZONTAL_PADDING } from './title'
|
||||
@@ -144,11 +145,23 @@ export function useWaveformPresentation(context: PresentationContext) {
|
||||
const titleAreaHeight = computed(() =>
|
||||
titleAreaReserved.value ? titleLayout.value.areaHeight : 0,
|
||||
)
|
||||
const chartTopMargin = computed(() => margin.top)
|
||||
const resolvePlotMargin = (value: number | undefined, fallback: number) =>
|
||||
typeof value === 'number' && Number.isFinite(value) && value >= 0 ? value : fallback
|
||||
const resolvedPlotMargin = computed(() => ({
|
||||
top: resolvePlotMargin(props.plotMargin.top, margin.top),
|
||||
bottom: resolvePlotMargin(props.plotMargin.bottom, margin.bottom),
|
||||
}))
|
||||
const chartTopMargin = computed(() => resolvedPlotMargin.value.top)
|
||||
const drawingHeight = computed(() =>
|
||||
Math.max(0, chartHeight.value - titleAreaHeight.value - paginationBandHeight.value),
|
||||
)
|
||||
const innerHeight = computed(() => Math.max(0, drawingHeight.value - margin.top - margin.bottom))
|
||||
const xAxisTitleY = computed(() => Math.max(0, drawingHeight.value - X_AXIS_TITLE_BOTTOM_OFFSET))
|
||||
const innerHeight = computed(() =>
|
||||
Math.max(
|
||||
0,
|
||||
drawingHeight.value - resolvedPlotMargin.value.top - resolvedPlotMargin.value.bottom,
|
||||
),
|
||||
)
|
||||
const titleAreaStyle = computed<CSSProperties>(() => ({
|
||||
height: `${titleAreaHeight.value}px`,
|
||||
justifyContent:
|
||||
@@ -193,8 +206,10 @@ export function useWaveformPresentation(context: PresentationContext) {
|
||||
titleMeasureStyle,
|
||||
titleLayout,
|
||||
titleAreaHeight,
|
||||
resolvedPlotMargin,
|
||||
chartTopMargin,
|
||||
drawingHeight,
|
||||
xAxisTitleY,
|
||||
innerHeight,
|
||||
titleAreaStyle,
|
||||
titleVisualStyle,
|
||||
|
||||
@@ -7,6 +7,7 @@ import type {
|
||||
WaveformInteractionMode,
|
||||
WaveformLegendOptions,
|
||||
WaveformOverlayMode,
|
||||
WaveformPlotMargin,
|
||||
WaveformPoint,
|
||||
WaveformRenderingOptions,
|
||||
WaveformTitleOptions,
|
||||
@@ -42,6 +43,7 @@ export interface WaveformChartProps {
|
||||
interactionMode?: WaveformInteractionMode
|
||||
grid?: WaveformGridOptions
|
||||
rendering?: WaveformRenderingOptions
|
||||
plotMargin?: WaveformPlotMargin
|
||||
title?: WaveformTitleOptions
|
||||
legend?: WaveformLegendOptions
|
||||
hiddenSeriesIds?: string[]
|
||||
@@ -65,6 +67,7 @@ type DefaultedProp =
|
||||
| 'annotationsVisible'
|
||||
| 'grid'
|
||||
| 'rendering'
|
||||
| 'plotMargin'
|
||||
| 'legend'
|
||||
| 'defaultHiddenSeriesIds'
|
||||
| 'cleanView'
|
||||
|
||||
Reference in New Issue
Block a user