155dca791f4133f50779bafbbf541dbef2bba60c184b60e9b0f818835cf1877a04fe073ca59698a9015b5f2406c5f1dce383aa60bdad378defeab191ae4c1c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. import ZRText, { TextStyleProps } from 'zrender/lib/graphic/Text.js';
  2. import Element, { ElementTextConfig } from 'zrender/lib/Element.js';
  3. import Model from '../model/Model.js';
  4. import { LabelOption, DisplayState, TextCommonOption, StatesOptionMixin, DisplayStateNonNormal, ColorString, ZRStyleProps, AnimationOptionMixin, InterpolatableValue } from '../util/types.js';
  5. import GlobalModel from '../model/Global.js';
  6. import SeriesData from '../data/SeriesData.js';
  7. declare type TextCommonParams = {
  8. /**
  9. * Whether disable drawing box of block (outer most).
  10. */
  11. disableBox?: boolean;
  12. /**
  13. * Specify a color when color is 'inherit',
  14. * If inheritColor specified, it is used as default textFill.
  15. */
  16. inheritColor?: ColorString;
  17. /**
  18. * Specify a opacity when opacity is not given.
  19. */
  20. defaultOpacity?: number;
  21. defaultOutsidePosition?: LabelOption['position'];
  22. /**
  23. * If support legacy 'auto' for 'inherit' usage.
  24. */
  25. textStyle?: ZRStyleProps;
  26. };
  27. interface SetLabelStyleOpt<TLabelDataIndex> extends TextCommonParams {
  28. defaultText?: string | ((labelDataIndex: TLabelDataIndex, opt: SetLabelStyleOpt<TLabelDataIndex>, interpolatedValue?: InterpolatableValue) => string);
  29. labelFetcher?: {
  30. getFormattedLabel: (labelDataIndex: TLabelDataIndex, status: DisplayState, dataType?: string, labelDimIndex?: number, formatter?: string | ((params: object) => string), extendParams?: {
  31. interpolatedValue: InterpolatableValue;
  32. }) => string;
  33. };
  34. labelDataIndex?: TLabelDataIndex;
  35. labelDimIndex?: number;
  36. /**
  37. * Inject a setter of text for the text animation case.
  38. */
  39. enableTextSetter?: boolean;
  40. }
  41. declare type LabelModel = Model<LabelOption & {
  42. formatter?: string | ((params: any) => string);
  43. showDuringLabel?: boolean;
  44. }>;
  45. declare type LabelModelForText = Model<Omit<LabelOption, 'position' | 'rotate'> & {
  46. formatter?: string | ((params: any) => string);
  47. }>;
  48. declare type LabelStatesModels<LabelModel> = Partial<Record<DisplayStateNonNormal, LabelModel>> & {
  49. normal: LabelModel;
  50. };
  51. export declare function setLabelText(label: ZRText, labelTexts: Record<DisplayState, string>): void;
  52. /**
  53. * Set normal styles and emphasis styles about text on target element
  54. * If target is a ZRText. It will create a new style object.
  55. * If target is other Element. It will create or reuse ZRText which is attached on the target.
  56. * And create a new style object.
  57. *
  58. * NOTICE: Because the style on ZRText will be replaced with new(only x, y are keeped).
  59. * So please update the style on ZRText after use this method.
  60. */
  61. declare function setLabelStyle<TLabelDataIndex>(targetEl: ZRText, labelStatesModels: LabelStatesModels<LabelModelForText>, opt?: SetLabelStyleOpt<TLabelDataIndex>, stateSpecified?: Partial<Record<DisplayState, TextStyleProps>>): void;
  62. declare function setLabelStyle<TLabelDataIndex>(targetEl: Element, labelStatesModels: LabelStatesModels<LabelModel>, opt?: SetLabelStyleOpt<TLabelDataIndex>, stateSpecified?: Partial<Record<DisplayState, TextStyleProps>>): void;
  63. export { setLabelStyle };
  64. export declare function getLabelStatesModels<LabelName extends string = 'label'>(itemModel: Model<StatesOptionMixin<any, any> & Partial<Record<LabelName, any>>>, labelName?: LabelName): Record<DisplayState, LabelModel>;
  65. /**
  66. * Set basic textStyle properties.
  67. */
  68. export declare function createTextStyle(textStyleModel: Model, specifiedTextStyle?: TextStyleProps, // Fixed style in the code. Can't be set by model.
  69. opt?: Pick<TextCommonParams, 'inheritColor' | 'disableBox'>, isNotNormal?: boolean, isAttached?: boolean): TextStyleProps;
  70. export declare function createTextConfig(textStyleModel: Model, opt?: Pick<TextCommonParams, 'defaultOutsidePosition' | 'inheritColor'>, isNotNormal?: boolean): ElementTextConfig;
  71. export declare function getFont(opt: Pick<TextCommonOption, 'fontStyle' | 'fontWeight' | 'fontSize' | 'fontFamily'>, ecModel: GlobalModel): string;
  72. export declare const labelInner: (hostObj: ZRText) => {
  73. /**
  74. * Previous target value stored used for label.
  75. * It's mainly for text animation
  76. */
  77. prevValue?: InterpolatableValue;
  78. /**
  79. * Target value stored used for label.
  80. */
  81. value?: InterpolatableValue;
  82. /**
  83. * Current value in text animation.
  84. */
  85. interpolatedValue?: InterpolatableValue;
  86. /**
  87. * If enable value animation
  88. */
  89. valueAnimation?: boolean;
  90. /**
  91. * Label value precision during animation.
  92. */
  93. precision?: number | 'auto';
  94. /**
  95. * If enable value animation
  96. */
  97. statesModels?: LabelStatesModels<LabelModelForText>;
  98. /**
  99. * Default text getter during interpolation
  100. */
  101. defaultInterpolatedText?: (value: InterpolatableValue) => string;
  102. /**
  103. * Change label text from interpolated text during animation
  104. */
  105. setLabelText?: (interpolatedValue?: InterpolatableValue) => void;
  106. };
  107. export declare function setLabelValueAnimation(label: ZRText, labelStatesModels: LabelStatesModels<LabelModelForText>, value: InterpolatableValue, getDefaultText: (value: InterpolatableValue) => string): void;
  108. export declare function animateLabelValue(textEl: ZRText, dataIndex: number, data: SeriesData, animatableModel: Model<AnimationOptionMixin>, labelFetcher: SetLabelStyleOpt<number>['labelFetcher']): void;