f5abf33ca258ee88e297ed780fadf3c9300c1eda7a534bfef5df781b8a739beda5f78eb4b2e1b633aeb0a6b7144887bb5f5cec177931bb40623d39f4b9d585 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. import VisualMapping, { VisualMappingOption } from '../../visual/VisualMapping.js';
  2. import { ComponentOption, BoxLayoutOptionMixin, LabelOption, ColorString, ZRColor, BorderOptionMixin, OptionDataValue, BuiltinVisualProperty, DimensionIndex } from '../../util/types.js';
  3. import ComponentModel from '../../model/Component.js';
  4. import Model from '../../model/Model.js';
  5. import GlobalModel from '../../model/Global.js';
  6. import SeriesModel from '../../model/Series.js';
  7. import SeriesData from '../../data/SeriesData.js';
  8. declare type VisualOptionBase = {
  9. [key in BuiltinVisualProperty]?: any;
  10. };
  11. declare type LabelFormatter = (min: OptionDataValue, max?: OptionDataValue) => string;
  12. declare type VisualState = VisualMapModel['stateList'][number];
  13. export interface VisualMapOption<T extends VisualOptionBase = VisualOptionBase> extends ComponentOption, BoxLayoutOptionMixin, BorderOptionMixin {
  14. mainType?: 'visualMap';
  15. show?: boolean;
  16. align?: string;
  17. realtime?: boolean;
  18. /**
  19. * 'all' or null/undefined: all series.
  20. * A number or an array of number: the specified series.
  21. * set min: 0, max: 200, only for campatible with ec2.
  22. * In fact min max should not have default value.
  23. */
  24. seriesIndex?: 'all' | number[] | number;
  25. /**
  26. * min value, must specified if pieces is not specified.
  27. */
  28. min?: number;
  29. /**
  30. * max value, must specified if pieces is not specified.
  31. */
  32. max?: number;
  33. /**
  34. * Dimension to be encoded
  35. */
  36. dimension?: number;
  37. /**
  38. * Visual configuration for the data in selection
  39. */
  40. inRange?: T;
  41. /**
  42. * Visual configuration for the out of selection
  43. */
  44. outOfRange?: T;
  45. controller?: {
  46. inRange?: T;
  47. outOfRange?: T;
  48. };
  49. target?: {
  50. inRange?: T;
  51. outOfRange?: T;
  52. };
  53. /**
  54. * Width of the display item
  55. */
  56. itemWidth?: number;
  57. /**
  58. * Height of the display item
  59. */
  60. itemHeight?: number;
  61. inverse?: boolean;
  62. orient?: 'horizontal' | 'vertical';
  63. backgroundColor?: ZRColor;
  64. contentColor?: ZRColor;
  65. inactiveColor?: ZRColor;
  66. /**
  67. * Padding of the component. Can be an array similar to CSS
  68. */
  69. padding?: number[] | number;
  70. /**
  71. * Gap between text and item
  72. */
  73. textGap?: number;
  74. precision?: number;
  75. /**
  76. * @deprecated
  77. * Option from version 2
  78. */
  79. color?: ColorString[];
  80. formatter?: string | LabelFormatter;
  81. /**
  82. * Text on the both end. Such as ['High', 'Low']
  83. */
  84. text?: string[];
  85. textStyle?: LabelOption;
  86. categories?: unknown;
  87. }
  88. export interface VisualMeta {
  89. stops: {
  90. value: number;
  91. color: ColorString;
  92. }[];
  93. outerColors: ColorString[];
  94. dimension?: DimensionIndex;
  95. }
  96. declare class VisualMapModel<Opts extends VisualMapOption = VisualMapOption> extends ComponentModel<Opts> {
  97. static type: string;
  98. type: string;
  99. static readonly dependencies: string[];
  100. readonly stateList: readonly ["inRange", "outOfRange"];
  101. readonly replacableOptionKeys: readonly ["inRange", "outOfRange", "target", "controller", "color"];
  102. readonly layoutMode: {
  103. readonly type: "box";
  104. readonly ignoreSize: true;
  105. };
  106. /**
  107. * [lowerBound, upperBound]
  108. */
  109. dataBound: number[];
  110. protected _dataExtent: [number, number];
  111. targetVisuals: {
  112. [x: string]: {
  113. symbol?: VisualMapping;
  114. color?: VisualMapping;
  115. opacity?: VisualMapping;
  116. decal?: VisualMapping;
  117. symbolSize?: VisualMapping;
  118. liftZ?: VisualMapping;
  119. colorAlpha?: VisualMapping;
  120. colorLightness?: VisualMapping;
  121. colorSaturation?: VisualMapping;
  122. colorHue?: VisualMapping;
  123. } & {
  124. __alphaForOpacity?: VisualMapping;
  125. };
  126. };
  127. controllerVisuals: {
  128. [x: string]: {
  129. symbol?: VisualMapping;
  130. color?: VisualMapping;
  131. opacity?: VisualMapping;
  132. decal?: VisualMapping;
  133. symbolSize?: VisualMapping;
  134. liftZ?: VisualMapping;
  135. colorAlpha?: VisualMapping;
  136. colorLightness?: VisualMapping;
  137. colorSaturation?: VisualMapping;
  138. colorHue?: VisualMapping;
  139. } & {
  140. __alphaForOpacity?: VisualMapping;
  141. };
  142. };
  143. textStyleModel: Model<LabelOption>;
  144. itemSize: number[];
  145. init(option: Opts, parentModel: Model, ecModel: GlobalModel): void;
  146. /**
  147. * @protected
  148. */
  149. optionUpdated(newOption: Opts, isInit?: boolean): void;
  150. /**
  151. * @protected
  152. */
  153. resetVisual(supplementVisualOption: (this: this, mappingOption: VisualMappingOption, state: string) => void): void;
  154. /**
  155. * @public
  156. */
  157. getItemSymbol(): string;
  158. /**
  159. * @protected
  160. * @return {Array.<number>} An array of series indices.
  161. */
  162. getTargetSeriesIndices(): number[];
  163. /**
  164. * @public
  165. */
  166. eachTargetSeries<Ctx>(callback: (this: Ctx, series: SeriesModel) => void, context?: Ctx): void;
  167. /**
  168. * @pubilc
  169. */
  170. isTargetSeries(seriesModel: SeriesModel): boolean;
  171. /**
  172. * @example
  173. * this.formatValueText(someVal); // format single numeric value to text.
  174. * this.formatValueText(someVal, true); // format single category value to text.
  175. * this.formatValueText([min, max]); // format numeric min-max to text.
  176. * this.formatValueText([this.dataBound[0], max]); // using data lower bound.
  177. * this.formatValueText([min, this.dataBound[1]]); // using data upper bound.
  178. *
  179. * @param value Real value, or this.dataBound[0 or 1].
  180. * @param isCategory Only available when value is number.
  181. * @param edgeSymbols Open-close symbol when value is interval.
  182. * @protected
  183. */
  184. formatValueText(value: number | string | number[], isCategory?: boolean, edgeSymbols?: string[]): string;
  185. /**
  186. * @protected
  187. */
  188. resetExtent(): void;
  189. /**
  190. * PENDING:
  191. * delete this method if no outer usage.
  192. *
  193. * Return Concrete dimention. If return null/undefined, no dimension used.
  194. */
  195. getDataDimensionIndex(data: SeriesData): DimensionIndex;
  196. getExtent(): [number, number];
  197. completeVisualOption(): void;
  198. resetItemSize(): void;
  199. isCategory(): boolean;
  200. /**
  201. * @public
  202. * @abstract
  203. */
  204. setSelected(selected?: any): void;
  205. getSelected(): any;
  206. /**
  207. * @public
  208. * @abstract
  209. */
  210. getValueState(value: any): VisualMapModel['stateList'][number];
  211. /**
  212. * FIXME
  213. * Do not publish to thirt-part-dev temporarily
  214. * util the interface is stable. (Should it return
  215. * a function but not visual meta?)
  216. *
  217. * @pubilc
  218. * @abstract
  219. * @param getColorVisual
  220. * params: value, valueState
  221. * return: color
  222. * @return {Object} visualMeta
  223. * should includes {stops, outerColors}
  224. * outerColor means [colorBeyondMinValue, colorBeyondMaxValue]
  225. */
  226. getVisualMeta(getColorVisual: (value: number, valueState: VisualState) => string): VisualMeta;
  227. static defaultOption: VisualMapOption;
  228. }
  229. export default VisualMapModel;