@antv/component 2.1.8 → 2.1.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/dist/component.min.js +1 -1
  2. package/esm/animation/fadeIn.d.ts +1 -1
  3. package/esm/animation/fadeOut.d.ts +1 -1
  4. package/esm/animation/utils.d.ts +3 -3
  5. package/esm/ui/axis/axis.d.ts +1 -1
  6. package/esm/ui/axis/guides/grid.d.ts +1 -1
  7. package/esm/ui/axis/guides/labels.d.ts +1 -1
  8. package/esm/ui/axis/guides/ticks.d.ts +1 -1
  9. package/esm/ui/axis/guides/title.d.ts +1 -1
  10. package/esm/ui/grid/index.d.ts +1 -1
  11. package/esm/ui/legend/category/items.d.ts +1 -0
  12. package/esm/ui/legend/category/items.js.map +1 -1
  13. package/esm/ui/legend/category.d.ts +2 -1
  14. package/esm/ui/legend/category.js +35 -4
  15. package/esm/ui/legend/category.js.map +1 -1
  16. package/esm/ui/legend/constant.d.ts +5 -0
  17. package/esm/ui/legend/constant.js +1 -0
  18. package/esm/ui/legend/constant.js.map +1 -1
  19. package/esm/util/keyframe-interpolate.d.ts +1 -1
  20. package/lib/animation/fadeIn.d.ts +1 -1
  21. package/lib/animation/fadeOut.d.ts +1 -1
  22. package/lib/animation/utils.d.ts +3 -3
  23. package/lib/ui/axis/axis.d.ts +1 -1
  24. package/lib/ui/axis/guides/grid.d.ts +1 -1
  25. package/lib/ui/axis/guides/labels.d.ts +1 -1
  26. package/lib/ui/axis/guides/ticks.d.ts +1 -1
  27. package/lib/ui/axis/guides/title.d.ts +1 -1
  28. package/lib/ui/grid/index.d.ts +1 -1
  29. package/lib/ui/legend/category/items.d.ts +1 -0
  30. package/lib/ui/legend/category/items.js.map +1 -1
  31. package/lib/ui/legend/category.d.ts +2 -1
  32. package/lib/ui/legend/category.js +35 -4
  33. package/lib/ui/legend/category.js.map +1 -1
  34. package/lib/ui/legend/constant.d.ts +5 -0
  35. package/lib/ui/legend/constant.js +1 -0
  36. package/lib/ui/legend/constant.js.map +1 -1
  37. package/lib/util/keyframe-interpolate.d.ts +1 -1
  38. package/package.json +2 -1
  39. package/src/ui/legend/category/items.ts +1 -0
  40. package/src/ui/legend/category.ts +35 -5
  41. package/src/ui/legend/constant.ts +1 -0
@@ -1,4 +1,4 @@
1
1
  import type { GenericAnimation } from '../animation';
2
2
  import type { DisplayObject } from '../shapes';
3
3
  import type { Interpolatable } from './interpolate';
4
- export declare function keyframeInterpolate<T extends Interpolatable>(element: DisplayObject, from: T, to: T, options: GenericAnimation): import("@antv/g").IAnimation | null;
4
+ export declare function keyframeInterpolate<T extends Interpolatable>(element: DisplayObject, from: T, to: T, options: GenericAnimation): import("@antv/g-lite").IAnimation | null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antv/component",
3
- "version": "2.1.8",
3
+ "version": "2.1.9",
4
4
  "description": "Visualization components for AntV, based on G.",
5
5
  "license": "MIT",
6
6
  "main": "lib/index.js",
@@ -34,6 +34,7 @@
34
34
  "build:cjs": "tsc -p tsconfig.json --target ES5 --module commonjs --outDir lib",
35
35
  "build:esm": "tsc -p tsconfig.json --target ES5 --module ESNext --outDir esm",
36
36
  "ci": "run-s lint test build",
37
+ "prepublishOnly": "npm run ci",
37
38
  "prepare": "husky install"
38
39
  },
39
40
  "keywords": [
@@ -65,6 +65,7 @@ export type CategoryItemsStyleProps = GroupStyleProps &
65
65
  focus?: boolean;
66
66
  focusMarkerSize?: number;
67
67
  classNamePrefix?: string;
68
+ render?: (data: CategoryItemsDatum[]) => string | HTMLElement;
68
69
  };
69
70
 
70
71
  export type CategoryItemsOptions = ComponentOptions<CategoryItemsStyleProps>;
@@ -1,5 +1,5 @@
1
1
  import { Component } from '../../core';
2
- import type { Group } from '../../shapes';
2
+ import { HTML, type Group } from '../../shapes';
3
3
  import { BBox, select, Selection, splitStyle, subStyleProps } from '../../util';
4
4
  import type { TitleStyleProps } from './title';
5
5
  import { getBBox, Title } from './title';
@@ -9,6 +9,12 @@ import type { CategoryOptions, CategoryStyleProps } from './types';
9
9
 
10
10
  export type { CategoryOptions, CategoryStyleProps };
11
11
 
12
+ class HtmlLegend extends HTML {
13
+ update(options: any) {
14
+ this.attr(options);
15
+ }
16
+ }
17
+
12
18
  export class Category extends Component<CategoryStyleProps> {
13
19
  constructor(options: CategoryOptions) {
14
20
  super(options, CATEGORY_DEFAULT_OPTIONS);
@@ -35,6 +41,26 @@ export class Category extends Component<CategoryStyleProps> {
35
41
  .update(finalTitleStyle) as Selection<Title>;
36
42
  }
37
43
 
44
+ private renderCustom(container: Selection) {
45
+ const { data } = this.attributes;
46
+
47
+ const style = {
48
+ innerHTML: this.attributes.render(data),
49
+ pointerEvents: 'auto' as const,
50
+ };
51
+
52
+ container
53
+ .maybeAppendByClassName(
54
+ CLASS_NAMES.html,
55
+ () =>
56
+ new HtmlLegend({
57
+ className: CLASS_NAMES.html.name,
58
+ style,
59
+ })
60
+ )
61
+ .update(style);
62
+ }
63
+
38
64
  private renderItems(container: Selection, bbox: DOMRect) {
39
65
  const { x, y, width, height } = bbox;
40
66
  const style = subStyleProps(this.attributes, 'title', true);
@@ -84,7 +110,7 @@ export class Category extends Component<CategoryStyleProps> {
84
110
  }
85
111
 
86
112
  render(attributes: Required<CategoryStyleProps>, container: Group) {
87
- const { width, height, x = 0, y = 0, classNamePrefix } = this.attributes;
113
+ const { width, height, x = 0, y = 0, classNamePrefix, render } = this.attributes;
88
114
  const ctn = select(container);
89
115
 
90
116
  // Set root container className
@@ -97,10 +123,14 @@ export class Category extends Component<CategoryStyleProps> {
97
123
 
98
124
  container.style.transform = `translate(${x}, ${y})`;
99
125
 
100
- this.renderTitle(ctn, width!, height!);
126
+ if (render as CategoryStyleProps['render']) {
127
+ this.renderCustom(ctn);
128
+ } else {
129
+ this.renderTitle(ctn, width!, height!);
101
130
 
102
- this.renderItems(ctn, this.availableSpace);
131
+ this.renderItems(ctn, this.availableSpace);
103
132
 
104
- this.adjustLayout();
133
+ this.adjustLayout();
134
+ }
105
135
  }
106
136
  }
@@ -62,6 +62,7 @@ export const NAME_VALUE_RATIO = 0.5;
62
62
  export const CLASS_NAMES = classNames(
63
63
  {
64
64
  title: 'title',
65
+ html: 'html',
65
66
  titleGroup: 'title-group',
66
67
  items: 'items',
67
68
  itemsGroup: 'items-group',