This is an automated email from the ASF dual-hosted git repository. ovilia pushed a commit to branch dvdkon-fix-13627 in repository https://gitbox.apache.org/repos/asf/echarts.git
commit 952fa45236e710fd55aa66cbb864716292bffd43 Merge: 75dd430d7 0c013fe71 Author: Ovilia <[email protected]> AuthorDate: Fri May 10 14:52:37 2024 +0800 chore: merge src/coord/axisCommonTypes.ts | 9 +- src/coord/axisTickLabelBuilder.ts | 42 ++++++++ test/axis-customTicks.html | 202 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 249 insertions(+), 4 deletions(-) diff --cc src/coord/axisCommonTypes.ts index fbfaf9cf4,4287256f0..0eb29b060 --- a/src/coord/axisCommonTypes.ts +++ b/src/coord/axisCommonTypes.ts @@@ -185,14 -143,20 +185,15 @@@ interface AxisTickOption inside?: boolean, // The length of axisTick. length?: number, -- lineStyle?: LineStyleOption - customValues?: (number | string | Date)[], - - // -------------------------------------------- - // [Properties below only for 'category' axis]: - - // If tick is align with label when boundaryGap is true - alignWithLabel?: boolean, - interval?: 'auto' | number | ((index: number, value: string) => boolean) ++ lineStyle?: LineStyleOption, ++ customValues?: (number | string | Date)[] } -export type AxisLabelFormatterOption = string | ((value: OrdinalRawValue | number, index: number) => string); +type AxisLabelValueFormatter = (value: number, index: number) => string; +type AxisLabelCategoryFormatter = (value: string, index: number) => string; -type TimeAxisLabelUnitFormatter = AxisLabelFormatterOption | string[]; +// export type AxisLabelFormatterOption = string | ((value: OrdinalRawValue | number, index: number) => string); +type TimeAxisLabelUnitFormatter = AxisLabelValueFormatter | string[] | string; export type TimeAxisLabelFormatterOption = string | ((value: number, index: number, extra: {level: number}) => string) @@@ -224,26 -181,20 +225,27 @@@ interface AxisLabelBaseOption extends O showMinLabel?: boolean, // true | false | null/undefined (auto) showMaxLabel?: boolean, + // 'left' | 'center' | 'right' | null/undefined (auto) + alignMinLabel?: TextAlign, + // 'left' | 'center' | 'right' | null/undefined (auto) + alignMaxLabel?: TextAlign, + // 'top' | 'middle' | 'bottom' | null/undefined (auto) + verticalAlignMinLabel?: TextVerticalAlign, + // 'top' | 'middle' | 'bottom' | null/undefined (auto) + verticalAlignMaxLabel?: TextVerticalAlign, margin?: number, - // value is supposed to be OptionDataPrimitive but for time axis, it is time stamp. - formatter?: AxisLabelFormatterOption | TimeAxisLabelFormatterOption, + rich?: Dictionary<TextCommonOption> + /** + * If hide overlapping labels. + */ - hideOverlap?: boolean; ++ hideOverlap?: boolean, + customValues?: (number | string | Date)[], - - // -------------------------------------------- - // [Properties below only for 'category' axis]: - - interval?: 'auto' | number | ((index: number, value: string) => boolean) - // Color can be callback -- color?: ColorString | ((value?: string | number, index?: number) => ColorString) - - rich?: Dictionary<TextCommonOption> ++ color?: ColorString | ((value?: string | number, index?: number) => ColorString), + overflow?: TextStyleProps['overflow'] +} +interface AxisLabelOption<TType extends OptionAxisType> extends AxisLabelBaseOption { + formatter?: LabelFormatters[TType] } interface MinorTickOption { @@@ -271,7 -222,3 +273,6 @@@ interface SplitAreaOption // colors will display in turn areaStyle?: AreaStyleOption<ZRColor[]> } + - +export type AxisBaseOption = ValueAxisBaseOption | LogAxisBaseOption + | CategoryAxisBaseOption | TimeAxisBaseOption | AxisBaseOptionCommon; diff --cc src/coord/axisTickLabelBuilder.ts index 6ac305f9b,8787207ca..dcd9febd7 --- a/src/coord/axisTickLabelBuilder.ts +++ b/src/coord/axisTickLabelBuilder.ts @@@ -60,9 -60,30 +60,31 @@@ type InnerStore = const inner = makeInner<InnerStore, any>(); + function tickValuesToNumbers(axis: Axis, values: (number | string | Date)[]) { + const nums = values.map(val => { + if (zrUtil.isString(val)) { + return axis.model.get('data').indexOf(val); + } + else if (val instanceof Date) { + return val.getTime(); + } + else { + return val; + } + }); + if (axis.type === 'time' && nums.length > 0) { + // Time axis needs duplicate first/last tick (see TimeScale.getTicks()) + // The first and last tick/label don't get drawn + nums.sort(); + nums.unshift(nums[0]); + nums.push(nums[nums.length - 1]); + } + return nums; + } + export function createAxisLabels(axis: Axis): { labels: { + level?: number, formattedLabel: string, rawLabel: string, tickValue: number --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
