UNPKG

17.8 kBTypeScriptView Raw
1/**
2 * Category axis module
3 */
4/**
5 * ============================================================================
6 * IMPORTS
7 * ============================================================================
8 * @hidden
9 */
10import { Axis, AxisItemLocation, AxisDataItem, IAxisProperties, IAxisDataFields, IAxisAdapters, IAxisEvents, IAxisDataItemAdapters } from "./Axis";
11import { IPoint, IOrientationPoint } from "../../core/defs/IPoint";
12import { Animation } from "../../core/utils/Animation";
13import { AxisRenderer } from "./AxisRenderer";
14import { SerialChart } from "../types/SerialChart";
15import { Dictionary } from "../../core/utils/Dictionary";
16import { XYSeries, XYSeriesDataItem } from "../series/XYSeries";
17import { ColumnSeries } from "../series/ColumnSeries";
18import { CategoryAxisBreak } from "./CategoryAxisBreak";
19import { IRange } from "../../core/defs/IRange";
20/**
21 * ============================================================================
22 * DATA ITEM
23 * ============================================================================
24 * @hidden
25 */
26/**
27 * Defines a [[DataItem]] for [[CategoryAxis]].
28 *
29 * @see {@link DataItem}
30 */
31export declare class CategoryAxisDataItem extends AxisDataItem {
32 /**
33 * Defines a type of [[Component]] this data item is used for.
34 */
35 _component: CategoryAxis;
36 seriesDataItems: {
37 [index: string]: XYSeriesDataItem[];
38 };
39 deltaAnimation: Animation;
40 /**
41 * Defines available adapters.
42 */
43 _adapter: ICategoryAxisDataItemAdapters;
44 /**
45 * Constructor
46 */
47 constructor();
48 /**
49 * Category.
50 *
51 * @param value Category
52 */
53 /**
54 * @return Category
55 */
56 category: string;
57 /**
58 * End category.
59 *
60 * Used for items that span several categories, like [[CategoryAxisBreak]].
61 *
62 * @param value End category
63 */
64 /**
65 * @return End category
66 */
67 endCategory: string;
68 deltaPosition: number;
69}
70/**
71 * Defines adapters for [[DataItem]]
72 * Includes both the [[Adapter]] definitions and properties
73 * @see {@link Adapter}
74 */
75export interface ICategoryAxisDataItemAdapters extends IAxisDataItemAdapters {
76 category: string;
77}
78/**
79 * ============================================================================
80 * REQUISITES
81 * ============================================================================
82 * @hidden
83 */
84/**
85 * Defines data fields for [[CategoryAxis]].
86 */
87export interface ICategoryAxisDataFields extends IAxisDataFields {
88 /**
89 * A field that holds category information.
90 */
91 category?: string;
92}
93/**
94 * Defines properties for [[CategoryAxis]].
95 */
96export interface ICategoryAxisProperties extends IAxisProperties {
97 sortBySeries?: ColumnSeries;
98}
99/**
100 * Defines events for [[CategoryAxis]].
101 */
102export interface ICategoryAxisEvents extends IAxisEvents {
103}
104/**
105 * Defines adapter for [[CategoryAxis]].
106 *
107 * @see {@link Adapter}
108 */
109export interface ICategoryAxisAdapters extends IAxisAdapters, ICategoryAxisProperties {
110}
111/**
112 * ============================================================================
113 * MAIN CLASS
114 * ============================================================================
115 * @hidden
116 */
117/**
118 * Used to create a category-based axis for the chart.
119 *
120 * ```TypeScript
121 * // Create the axis
122 * let xAxis = chart.xAxes.push(new am4charts.CategoryAxis());
123 *
124 * // Set settings
125 * xAxis.title.text = "Clients";
126 * ```
127 * ```JavaScript
128 * // Create the axis
129 * var valueAxis = chart.xAxes.push(new am4charts.CategoryAxis());
130 *
131 * // Set settings
132 * valueAxis.title.text = "Clients";
133 * ```
134 * ```JSON
135 * "xAxes": [{
136 * "type": "CategoryAxis",
137 * "title": {
138 * "text": "Clients"
139 * }
140 * }]
141 * ```
142 *
143 * @see {@link ICategoryAxisEvents} for a list of available Events
144 * @see {@link ICategoryAxisAdapters} for a list of available Adapters
145 * @important
146 */
147export declare class CategoryAxis<T extends AxisRenderer = AxisRenderer> extends Axis<T> {
148 /**
149 * Defines data fields.
150 */
151 _dataFields: ICategoryAxisDataFields;
152 /**
153 * Defines available properties.
154 */
155 _properties: ICategoryAxisProperties;
156 /**
157 * Defines available adapters.
158 */
159 _adapter: ICategoryAxisAdapters;
160 /**
161 * Defines available events.
162 */
163 _events: ICategoryAxisEvents;
164 /**
165 * Defines the type of the Date Items.
166 */
167 _dataItem: CategoryAxisDataItem;
168 /**
169 * Defines the type of the axis breaks.
170 */
171 _axisBreak: CategoryAxisBreak;
172 /**
173 * A reference to chart the axis is for.
174 */
175 chart: SerialChart;
176 /**
177 * Frequency of the labels on axis.
178 */
179 protected _frequency: number;
180 /**
181 * A collection that holds Axis' data items sorted by each category.
182 */
183 dataItemsByCategory: Dictionary<string, this["_dataItem"]>;
184 /**
185 * last data item is used for the closing grid
186 */
187 protected _lastDataItem: CategoryAxisDataItem;
188 /**
189 * Constructor
190 */
191 constructor();
192 /**
193 * Returns a new/empty [[DataItem]] of the type appropriate for this object.
194 *
195 * @see {@link DataItem}
196 * @return Data Item
197 */
198 protected createDataItem(): this["_dataItem"];
199 /**
200 * Returns a new/empty [[AxisBreak]] of the appropriate type.
201 *
202 * @return Axis break
203 */
204 protected createAxisBreak(): this["_axisBreak"];
205 /**
206 * Processes a related series' data item.
207 *
208 * @ignore Exclude from docs
209 * @todo Description
210 * @param dataItem Data item
211 */
212 processSeriesDataItem(dataItem: XYSeriesDataItem, axisLetter?: string): void;
213 /**
214 * Validates the data range.
215 *
216 * @ignore Exclude from docs
217 * @todo Description (review)
218 */
219 validateDataRange(): void;
220 /**
221 * Validates the whole axis. Causes it to redraw.
222 *
223 * @ignore Exclude from docs
224 * @todo Description (review)
225 */
226 validate(): void;
227 /**
228 * [validateDataElement description]
229 *
230 * @ignore Exclude from docs
231 * @todo Description
232 * @param dataItem [description]
233 * @param itemIndex [description]
234 */
235 validateDataElement(dataItem: this["_dataItem"], itemIndex?: number, index?: number): void;
236 /**
237 * @ignore
238 */
239 disposeData(): void;
240 /**
241 * Processes the axis data item.
242 *
243 * @ignore Exclude from docs
244 * @param dataItem Data item
245 * @param dataContext The raw data that corresponds to this data item
246 */
247 processDataItem(dataItem: this["_dataItem"], dataContext: Object): void;
248 protected getDataItem(dataContext?: any): this["_dataItem"];
249 /**
250 * Converts a category index to an actual screen coordinate on the axis.
251 *
252 * `location` identifies relative location within category. 0 - beginning,
253 * 0.5 - middle, 1 - end, and anything inbetween.
254 *
255 * @param index Index
256 * @param location Location (0-1)
257 * @return Position (px)
258 */
259 indexToPosition(index: number, location?: AxisItemLocation | number): number;
260 /**
261 * Converts a string category name to relative position on axis.
262 *
263 * `location` identifies relative location within category. 0 - beginning,
264 * 0.5 - middle, 1 - end, and anything inbetween.
265 *
266 * @param category Category name
267 * @param location Location (0-1)
268 * @return Position
269 */
270 categoryToPosition(category: string, location?: AxisItemLocation): number;
271 /**
272 * Converts a string category name to a orientation point (x, y, angle) on axis
273 *
274 * `location` identifies relative location within category. 0 - beginning,
275 * 0.5 - middle, 1 - end, and anything inbetween.
276 * @param category Category name
277 * @param location Location (0-1)
278 * @return Orientation point
279 */
280 categoryToPoint(category: string, location?: AxisItemLocation): IOrientationPoint;
281 /**
282 * Converts a string category name to a orientation point (x, y, angle) on axis
283 *
284 * `location` identifies relative location within category. 0 - beginning,
285 * 0.5 - middle, 1 - end, and anything inbetween.
286 * @param category Category name
287 * @param location Location (0-1)
288 * @return Orientation point
289 */
290 anyToPoint(category: string, location?: AxisItemLocation): IOrientationPoint;
291 /**
292 * Converts a string category name to relative position on axis.
293 *
294 * An alias to `categoryToPosition()`.
295 *
296 * @param category Category name
297 * @param location Location (0-1)
298 * @return Relative position
299 */
300 anyToPosition(category: string, location?: AxisItemLocation): number;
301 /**
302 * Converts named category to an index of data item it corresponds to.
303 *
304 * @param category Category
305 * @return Data item index
306 */
307 categoryToIndex(category: string): number;
308 /**
309 * Zooms the axis to specific named ctaegories.
310 *
311 * @param startCategory Start category
312 * @param endCategory End category
313 */
314 zoomToCategories(startCategory: string, endCategory: string): void;
315 /**
316 * [getAnyRangePath description]
317 *
318 * @ignore Exclude from docs
319 * @todo Description
320 * @param start [description]
321 * @param end [description]
322 * @param startLocation [description]
323 * @param endLocation [description]
324 * @return [description]
325 */
326 getAnyRangePath(start: string, end: string, startLocation?: AxisItemLocation, endLocation?: AxisItemLocation): string;
327 /**
328 * Takes an absolute position (px) within axis and adjust it to a specific
329 * `location` within category it corresponds to.
330 *
331 * @param position Source position (px)
332 * @param location Location within category (0-1)
333 * @return Adjusted position (px)
334 */
335 roundPosition(position: number, location?: AxisItemLocation): number;
336 /**
337 * Finds and returns first series data item with specific category
338 * @param series Target series
339 * @param category Category
340 * @return XYSeriesDataItem data item
341 */
342 getFirstSeriesDataItem(series: XYSeries, category: string): XYSeriesDataItem;
343 /**
344 * Finds and returns last series data item with specific category.
345 * @param series Target series
346 * @param category Category
347 * @return XYSeriesDataItem data item
348 */
349 getLastSeriesDataItem(series: XYSeries, category: string): XYSeriesDataItem;
350 getSeriesDataItemByCategory(category: string, series: XYSeries): XYSeriesDataItem;
351 /**
352 * Returns a data item from Series that corresponds to a specific absolute
353 * position on the Axis.
354 *
355 * @param series Target series
356 * @param position Position (px)
357 * @return XYSeriesDataItem data item
358 */
359 getSeriesDataItem(series: XYSeries, position: number, findNearest?: boolean): XYSeriesDataItem;
360 /**
361 * Returns the X coordinate for series' data item.
362 *
363 * @ignore Exclude from docs
364 * @todo Description (review)
365 * @param dataItem Data item
366 * @param key Category
367 * @param location Location (0-1)
368 * @return X coordinate (px)
369 */
370 getX(dataItem: XYSeriesDataItem, key?: string, location?: number, stackKey?: string, range?: IRange): number;
371 /**
372 * Returns relative position on axis for series' data item.
373 *
374 * @since 4.5.14
375 * @param dataItem Data item
376 * @param key Category
377 * @param location Location (0-1)
378 * @return Relative position
379 */
380 getPositionX(dataItem: XYSeriesDataItem, key?: string, location?: number, stackKey?: string, range?: IRange): number;
381 /**
382 * Returns the Y coordinate for series' data item.
383 *
384 * @ignore Exclude from docs
385 * @todo Description (review)
386 * @param dataItem Data item
387 * @param key Category
388 * @param location Location (0-1)
389 * @return Y coordinate (px)
390 */
391 getY(dataItem: XYSeriesDataItem, key?: string, location?: number, stackKey?: string, range?: IRange): number;
392 /**
393 * Returns relative position on axis for series' data item.
394 *
395 * @since 4.5.14
396 * @param dataItem Data item
397 * @param key Category
398 * @param location Location (0-1)
399 * @return Relative position
400 */
401 getPositionY(dataItem: XYSeriesDataItem, key?: string, location?: number, stackKey?: string, range?: IRange): number;
402 /**
403 * Returns an angle for series data item.
404 *
405 * @ignore Exclude from docs
406 * @todo Description (review)
407 * @param dataItem Data item
408 * @param key Category
409 * @param location Location (0-1)
410 * @param stackKey Stack key (?)
411 * @param range Range to fit in
412 * @return Angle
413 */
414 getAngle(dataItem: XYSeriesDataItem, key: string, location?: number, stackKey?: string, range?: IRange): number;
415 /**
416 * Returns an absolute pixel coordinate of the start of the cell (category),
417 * that specific position value falls into.
418 *
419 * @ignore Exclude from docs
420 * @todo Description (review)
421 * @param position Position (px)
422 * @return Cell start position (px)
423 */
424 getCellStartPosition(position: number): number;
425 /**
426 * Returns an absolute pixel coordinate of the end of the cell (category),
427 * that specific position value falls into.
428 *
429 * @ignore Exclude from docs
430 * @todo Description (review)
431 * @param position Position (px)
432 * @return Cell end position (px)
433 */
434 getCellEndPosition(position: number): number;
435 /**
436 * Returns text to show in a category tooltip, based on specific position
437 * within axis.
438 *
439 * @ignore Exclude from docs
440 * @param position Position (px)
441 * @return Label (category)
442 */
443 getTooltipText(position: number): string;
444 /**
445 * Returns an index of the category that corresponds to specific pixel
446 * position within axis.
447 *
448 * @param position Position (px)
449 * @return Category index
450 */
451 positionToIndex(position: number): number;
452 /**
453 * Returns category based on position.
454 *
455 * Please note that `position` represents position within axis which may be
456 * zoomed and not correspond to Cursor's `position`.
457 *
458 * To convert Cursor's `position` to Axis' `position` use `toAxisPosition()` method.
459 *
460 * This is a synonim of `getPositionLabel()` implemented here for consistentcy.
461 *
462 * @since 4.3.8
463 * @see {@link https://www.amcharts.com/docs/v4/tutorials/tracking-cursors-position-via-api/#Tracking_Cursor_s_position} For more information about cursor tracking.
464 * @param position Relative position on axis (0-1)
465 * @return Position label
466 */
467 positionToCategory(position: number): string;
468 /**
469 * Returns category based on position.
470 *
471 * Please note that `position` represents position within axis which may be
472 * zoomed and not correspond to Cursor's `position`.
473 *
474 * To convert Cursor's `position` to Axis' `position` use `toAxisPosition()` method.
475 *
476 * @see {@link https://www.amcharts.com/docs/v4/tutorials/tracking-cursors-position-via-api/#Tracking_Cursor_s_position} For more information about cursor tracking.
477 * @param position Relative position on axis (0-1)
478 * @return Position label
479 */
480 getPositionLabel(position: number): string;
481 /**
482 * Coordinates of the actual axis start.
483 *
484 * @ignore Exclude from docs
485 * @return Base point
486 */
487 readonly basePoint: IPoint;
488 /**
489 * Initializes Axis' renderer.
490 *
491 * @ignore Exclude from docs
492 */
493 initRenderer(): void;
494 /**
495 * Current frequency of labels of the axis.
496 *
497 * Normally it would be 1, but when labels start to be hidden due
498 * to `minGridDistance` this read-only property will increase.
499 *
500 * @readonly
501 * @since 4.2.0
502 * @return Label frequency
503 */
504 readonly frequency: number;
505 /**
506 * If set to a reference of [[ColumnSeries]] the categories will be sorted
507 * by actual values.
508 *
509 * The categories are ordered in descending order (from highest values to
510 * lowest). To reverse the order, use axis renderer's `inversed` setting.
511 * E.g.:
512 *
513 * ```TypeScript
514 * categoryAxis.sortBySeries = series;
515 * categoryAxis.renderer.inversed = true;
516 * ```
517 * ```JavaScript
518 * categoryAxis.sortBySeries = series;
519 * categoryAxis.renderer.inversed = true;
520 * ```
521 * ```JSON
522 * {
523 * // ...
524 * "xAxes": [{
525 * // ...
526 * "sortBySeries": "s1",
527 * "renderer": {
528 * // ...
529 * "inversed": true
530 * }
531 * }]
532 * }
533 * ```
534 *
535 * @since 4.8.7
536 * @param value Sort categories?
537 */
538 /**
539 * @return Sort categories?
540 */
541 sortBySeries: ColumnSeries;
542 /**
543 * Processes JSON-based config before it is applied to the object.
544 *
545 * @ignore Exclude from docs
546 * @param config Config
547 */
548 processConfig(config?: {
549 [index: string]: any;
550 }): void;
551}