@antv/g2 5.0.17 → 5.0.18

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 (73) hide show
  1. package/dist/g2-lite.min.js +3 -3
  2. package/dist/g2.min.js +3 -3
  3. package/esm/component/legendContinuous.js +6 -5
  4. package/esm/component/legendContinuous.js.map +1 -1
  5. package/esm/interaction/legendFilter.d.ts +2 -0
  6. package/esm/interaction/legendFilter.js +66 -37
  7. package/esm/interaction/legendFilter.js.map +1 -1
  8. package/esm/mark/lineX.js +5 -3
  9. package/esm/mark/lineX.js.map +1 -1
  10. package/esm/mark/lineY.js +5 -3
  11. package/esm/mark/lineY.js.map +1 -1
  12. package/esm/runtime/plot.js +3 -3
  13. package/esm/runtime/plot.js.map +1 -1
  14. package/esm/runtime/types/theme.d.ts +1 -0
  15. package/esm/shape/label/label.d.ts +7 -1
  16. package/esm/shape/label/label.js +11 -2
  17. package/esm/shape/label/label.js.map +1 -1
  18. package/esm/shape/text/advance.js +24 -11
  19. package/esm/shape/text/advance.js.map +1 -1
  20. package/esm/theme/academy.js +6 -0
  21. package/esm/theme/academy.js.map +1 -1
  22. package/esm/theme/classic.js +6 -0
  23. package/esm/theme/classic.js.map +1 -1
  24. package/esm/theme/classicDark.js +6 -0
  25. package/esm/theme/classicDark.js.map +1 -1
  26. package/esm/transform/filter.js +19 -6
  27. package/esm/transform/filter.js.map +1 -1
  28. package/esm/utils/selection.d.ts +1 -1
  29. package/esm/utils/selection.js +3 -1
  30. package/esm/utils/selection.js.map +1 -1
  31. package/lib/component/legendContinuous.js +5 -4
  32. package/lib/component/legendContinuous.js.map +1 -1
  33. package/lib/interaction/legendFilter.d.ts +2 -0
  34. package/lib/interaction/legendFilter.js +67 -37
  35. package/lib/interaction/legendFilter.js.map +1 -1
  36. package/lib/mark/lineX.js +4 -2
  37. package/lib/mark/lineX.js.map +1 -1
  38. package/lib/mark/lineY.js +4 -2
  39. package/lib/mark/lineY.js.map +1 -1
  40. package/lib/runtime/plot.js +3 -3
  41. package/lib/runtime/plot.js.map +1 -1
  42. package/lib/runtime/types/theme.d.ts +1 -0
  43. package/lib/shape/label/label.d.ts +7 -1
  44. package/lib/shape/label/label.js +11 -2
  45. package/lib/shape/label/label.js.map +1 -1
  46. package/lib/shape/text/advance.js +24 -11
  47. package/lib/shape/text/advance.js.map +1 -1
  48. package/lib/theme/academy.js +6 -0
  49. package/lib/theme/academy.js.map +1 -1
  50. package/lib/theme/classic.js +6 -0
  51. package/lib/theme/classic.js.map +1 -1
  52. package/lib/theme/classicDark.js +6 -0
  53. package/lib/theme/classicDark.js.map +1 -1
  54. package/lib/transform/filter.js +19 -6
  55. package/lib/transform/filter.js.map +1 -1
  56. package/lib/utils/selection.d.ts +1 -1
  57. package/lib/utils/selection.js +3 -1
  58. package/lib/utils/selection.js.map +1 -1
  59. package/package.json +4 -4
  60. package/src/component/legendContinuous.ts +9 -5
  61. package/src/interaction/legendFilter.ts +96 -49
  62. package/src/mark/lineX.ts +11 -5
  63. package/src/mark/lineY.ts +11 -5
  64. package/src/runtime/plot.ts +7 -2
  65. package/src/runtime/types/theme.ts +1 -0
  66. package/src/shape/label/label.ts +21 -2
  67. package/src/shape/text/advance.ts +39 -14
  68. package/src/theme/academy.ts +6 -0
  69. package/src/theme/classic.ts +6 -0
  70. package/src/theme/classicDark.ts +6 -0
  71. package/src/transform/filter.ts +16 -5
  72. package/src/utils/selection.ts +6 -1
  73. package/CHANGELOG.md +0 -251
@@ -1,10 +1,12 @@
1
1
  import { DisplayObject } from '@antv/g';
2
- import { deepMix } from '@antv/util';
2
+ import { deepMix, throttle } from '@antv/util';
3
3
  import { subObject } from '../utils/helper';
4
4
  import { useState, setCursor, restoreCursor } from './utils';
5
5
 
6
6
  export const CATEGORY_LEGEND_CLASS_NAME = 'legend-category';
7
7
 
8
+ export const CONTINUOUS_LEGEND_CLASS_NAME = 'legend-continuous';
9
+
8
10
  export const LEGEND_ITEMS_CLASS_NAME = 'items-item';
9
11
 
10
12
  export const LEGEND_MAKER_CLASS_NAME = 'legend-category-item-marker';
@@ -27,6 +29,10 @@ export function legendsOf(root) {
27
29
  return root.getElementsByClassName(CATEGORY_LEGEND_CLASS_NAME);
28
30
  }
29
31
 
32
+ export function legendsContinuousOf(root) {
33
+ return root.getElementsByClassName(CONTINUOUS_LEGEND_CLASS_NAME);
34
+ }
35
+
30
36
  export function dataOf(root) {
31
37
  // legend -> layout -> container
32
38
  let parent = root.parentNode;
@@ -44,7 +50,7 @@ export function attributesOf(root) {
44
50
  return child.attributes;
45
51
  }
46
52
 
47
- function legendFilter(
53
+ function legendFilterOrdinal(
48
54
  root: DisplayObject,
49
55
  {
50
56
  legends, // given the root of chart returns legends to be manipulated
@@ -175,61 +181,102 @@ function legendFilter(
175
181
  };
176
182
  }
177
183
 
184
+ function legendFilterContinuous(_, { legend, filter, emitter, channel }) {
185
+ const onValueChange = ({ detail: { value } }) => {
186
+ filter(value);
187
+ emitter.emit({
188
+ nativeEvent: true,
189
+ data: {
190
+ channel,
191
+ values: value,
192
+ },
193
+ });
194
+ };
195
+ legend.addEventListener('valuechange', onValueChange);
196
+ return () => {
197
+ legend.removeEventListener('valuechange', onValueChange);
198
+ };
199
+ }
200
+
178
201
  export function LegendFilter() {
179
202
  return (context, _, emitter) => {
180
203
  const { container, view, options: viewOptions, update } = context;
181
204
 
182
- const legends = legendsOf(container);
183
-
184
- const filter = async (channel, value) => {
185
- const { scale } = view;
186
- const { [channel]: scaleOrdinal } = scale;
187
- const { marks } = viewOptions;
188
- // Add filter transform for every marks,
189
- // which will skip for mark without color channel.
190
- const newMarks = marks.map((mark) => {
191
- if (mark.type === 'legends') return mark;
192
- const { transform = [] } = mark;
193
- const newTransform = [
194
- { type: 'filter', [channel]: value },
195
- ...transform,
196
- ];
197
- return deepMix({}, mark, {
198
- transform: newTransform,
199
- //Set domain of scale to preserve legends.
200
- scale: {
201
- [channel]: {
202
- domain: scaleOrdinal.getOptions().domain,
203
- },
204
- },
205
- legend: {
206
- [channel]: { preserve: true },
207
- },
205
+ const legends = [
206
+ ...legendsOf(container),
207
+ ...legendsContinuousOf(container),
208
+ ];
209
+
210
+ const filter = throttle(
211
+ async (channel, value, ordinal: boolean, channels) => {
212
+ const { marks } = viewOptions;
213
+ // Add filter transform for every marks,
214
+ // which will skip for mark without color channel.
215
+ const newMarks = marks.map((mark) => {
216
+ if (mark.type === 'legends') return mark;
217
+
218
+ // Inset after aggregate transform, such as group, and bin.
219
+ const { transform = [] } = mark;
220
+ const index = transform.findIndex(
221
+ ({ type }) => type.startsWith('group') || type.startsWith('bin'),
222
+ );
223
+ const newTransform = [...transform];
224
+ newTransform.splice(index + 1, 0, {
225
+ type: 'filter',
226
+ [channel]: { value, ordinal },
227
+ });
228
+
229
+ // Set domain of scale to preserve encoding.
230
+ const newScale = Object.fromEntries(
231
+ channels.map((channel) => [
232
+ channel,
233
+ { domain: view.scale[channel].getOptions().domain },
234
+ ]),
235
+ );
236
+
237
+ return deepMix({}, mark, {
238
+ transform: newTransform,
239
+ scale: newScale,
240
+ ...(!ordinal && { animate: false }),
241
+ legend: { [channel]: { preserve: true } },
242
+ });
208
243
  });
209
- });
210
- const newOptions = {
211
- ...viewOptions,
212
- marks: newMarks,
213
- };
214
- return update(newOptions);
215
- };
244
+ const newOptions = {
245
+ ...viewOptions,
246
+ marks: newMarks,
247
+ };
248
+ await update(newOptions);
249
+ },
250
+ 50,
251
+ { trailing: true },
252
+ );
216
253
 
217
254
  const removes = legends.map((legend) => {
218
255
  const { name: channel, domain } = dataOf(legend).scales[0];
219
- return legendFilter(container, {
220
- legends: itemsOf,
221
- marker: markerOf,
222
- label: labelOf,
223
- datum: (d) => {
224
- const { __data__: datum } = d;
225
- const { index } = datum;
226
- return domain[index];
227
- },
228
- filter: (value) => filter(channel, value),
229
- state: legend.attributes.state,
230
- channel,
231
- emitter,
232
- });
256
+ const channels = dataOf(legend).scales.map((d) => d.name);
257
+ if (legend.className === CATEGORY_LEGEND_CLASS_NAME) {
258
+ return legendFilterOrdinal(container, {
259
+ legends: itemsOf,
260
+ marker: markerOf,
261
+ label: labelOf,
262
+ datum: (d) => {
263
+ const { __data__: datum } = d;
264
+ const { index } = datum;
265
+ return domain[index];
266
+ },
267
+ filter: (value) => filter(channel, value, true, channels),
268
+ state: legend.attributes.state,
269
+ channel,
270
+ emitter,
271
+ });
272
+ } else {
273
+ return legendFilterContinuous(container, {
274
+ legend,
275
+ filter: (value) => filter(channel, value, false, channels),
276
+ emitter,
277
+ channel,
278
+ });
279
+ }
233
280
  });
234
281
  return () => {
235
282
  removes.forEach((remove) => remove());
package/src/mark/lineX.ts CHANGED
@@ -1,21 +1,27 @@
1
- import { Vector } from '@antv/coord';
1
+ import { deepMix } from '@antv/util';
2
2
  import { MarkComponent as MC, Vector2 } from '../runtime';
3
3
  import { LineXMark } from '../spec';
4
4
  import {
5
5
  basePostInference,
6
6
  baseAnnotationChannels,
7
7
  basePreInference,
8
+ createBandOffset,
8
9
  } from './utils';
9
10
 
10
11
  export type LineXOptions = Omit<LineXMark, 'type'>;
11
12
 
12
- export const LineX: MC<LineXOptions> = () => {
13
+ export const LineX: MC<LineXOptions> = (options) => {
13
14
  return (index, scale, value, coordinate) => {
14
15
  const { x: X } = value;
16
+ const offset = createBandOffset(
17
+ scale,
18
+ value,
19
+ deepMix({ style: { bandOffset: 0 } }, options),
20
+ );
15
21
  const P = Array.from(index, (i) => {
16
- const p1 = [X[i], 1] as Vector;
17
- const p2 = [X[i], 0] as Vector;
18
- return [p1, p2].map((d) => coordinate.map(d)) as Vector2[];
22
+ const p1 = [X[i], 1] as Vector2;
23
+ const p2 = [X[i], 0] as Vector2;
24
+ return [p1, p2].map((d) => coordinate.map(offset(d, i))) as Vector2[];
19
25
  });
20
26
  return [index, P];
21
27
  };
package/src/mark/lineY.ts CHANGED
@@ -1,21 +1,27 @@
1
- import { Vector } from '@antv/coord';
1
+ import { deepMix } from '@antv/util';
2
2
  import { MarkComponent as MC, Vector2 } from '../runtime';
3
3
  import { LineYMark } from '../spec';
4
4
  import {
5
5
  baseAnnotationChannels,
6
6
  basePreInference,
7
7
  basePostInference,
8
+ createBandOffset,
8
9
  } from './utils';
9
10
 
10
11
  export type LineYOptions = Omit<LineYMark, 'type'>;
11
12
 
12
- export const LineY: MC<LineYOptions> = () => {
13
+ export const LineY: MC<LineYOptions> = (options) => {
13
14
  return (index, scale, value, coordinate) => {
14
15
  const { y: Y } = value;
16
+ const offset = createBandOffset(
17
+ scale,
18
+ value,
19
+ deepMix({ style: { bandOffset: 0 } }, options),
20
+ );
15
21
  const P = Array.from(index, (i) => {
16
- const p1 = [0, Y[i]] as Vector;
17
- const p2 = [1, Y[i]] as Vector;
18
- return [p1, p2].map((d) => coordinate.map(d)) as Vector2[];
22
+ const p1 = [0, Y[i]] as Vector2;
23
+ const p2 = [1, Y[i]] as Vector2;
24
+ return [p1, p2].map((d) => coordinate.map(offset(d, i))) as Vector2[];
19
25
  });
20
26
  return [index, P];
21
27
  };
@@ -1189,6 +1189,7 @@ function createLabelShapeFunction(
1189
1189
  formatter = (d) => `${d}`,
1190
1190
  transform,
1191
1191
  style: abstractStyle,
1192
+ render,
1192
1193
  ...abstractOptions
1193
1194
  } = options;
1194
1195
  const visualOptions = mapObject(
@@ -1197,10 +1198,14 @@ function createLabelShapeFunction(
1197
1198
  );
1198
1199
  const { shape = defaultLabelShape, text, ...style } = visualOptions;
1199
1200
  const f = typeof formatter === 'string' ? format(formatter) : formatter;
1200
- const value = { ...style, text: f(text, datum, index, abstractData) };
1201
+ const value = {
1202
+ ...style,
1203
+ text: f(text, datum, index, abstractData),
1204
+ datum,
1205
+ };
1201
1206
 
1202
1207
  // Params for create shape.
1203
- const shapeOptions = { type: `label.${shape}`, ...style };
1208
+ const shapeOptions = { type: `label.${shape}`, render, ...style };
1204
1209
  const shapeFunction = useShape(shapeOptions, shapeContext);
1205
1210
  const defaults = getDefaultsStyle(theme, 'label', shape, 'label');
1206
1211
 
@@ -79,6 +79,7 @@ type ComponentTheme = {
79
79
  legendContinuous?: any;
80
80
  label?: LabelStyleProps;
81
81
  innerLabel?: LabelStyleProps;
82
+ htmlLabel?: any;
82
83
  slider?: any;
83
84
  scrollbar?: any;
84
85
  title?: any; // @todo
@@ -8,7 +8,13 @@ import { Advance } from '../text/advance';
8
8
  import { LabelPosition } from './position/default';
9
9
  import * as PositionProcessor from './position';
10
10
 
11
- export type LabelOptions = Record<string, any>;
11
+ export type LabelOptions = {
12
+ /**
13
+ * Customize label with html string or element.
14
+ */
15
+ render: (text: string, datum: any, index: number) => string | HTMLElement;
16
+ [key: string]: any;
17
+ };
12
18
 
13
19
  function inferPosition(position: LabelPosition, coordinate: Coordinate) {
14
20
  if (position !== undefined) return position;
@@ -27,8 +33,14 @@ function getDefaultStyle(
27
33
  // For non-series mark, calc position for label based on
28
34
  // position and the bounds of shape.
29
35
  const { position } = value;
36
+ const { render } = options;
30
37
  const p = inferPosition(position, coordinate);
31
- const t = theme[p === 'inside' ? 'innerLabel' : 'label'];
38
+ const labelType = render
39
+ ? 'htmlLabel'
40
+ : p === 'inside'
41
+ ? 'innerLabel'
42
+ : 'label';
43
+ const t = theme[labelType];
32
44
  const v = Object.assign({}, t, value);
33
45
  const processor = PositionProcessor[camelCase(p)];
34
46
  if (!processor) {
@@ -46,6 +58,7 @@ function getDefaultStyle(
46
58
  */
47
59
  export const Label: SC<LabelOptions> = (options, context) => {
48
60
  const { coordinate, theme } = context;
61
+ const { render } = options;
49
62
  return (points, value) => {
50
63
  const {
51
64
  text,
@@ -53,6 +66,7 @@ export const Label: SC<LabelOptions> = (options, context) => {
53
66
  y,
54
67
  transform: specifiedTS = '',
55
68
  transformOrigin,
69
+ className = '',
56
70
  ...overrideStyle
57
71
  } = value;
58
72
  const {
@@ -64,6 +78,11 @@ export const Label: SC<LabelOptions> = (options, context) => {
64
78
  return select(new Advance())
65
79
  .call(applyStyle, defaultStyle)
66
80
  .style('text', `${text}`)
81
+ .style('className', `${className} g2-label`)
82
+ .style(
83
+ 'innerHTML',
84
+ render ? render(text, value.datum, value.index) : undefined,
85
+ )
67
86
  .style(
68
87
  'labelTransform',
69
88
  `${transform} rotate(${+rotate}) ${specifiedTS}`.trim(),
@@ -34,6 +34,8 @@ type TextShapeStyleProps = Omit<TextStyleProps, 'text'> &
34
34
  BackgroundStyleProps &
35
35
  MarkerStyleProps<'startMarker'> &
36
36
  MarkerStyleProps<'endMarker'> & {
37
+ id: string;
38
+ className?: string;
37
39
  x0?: number; // x0 represents the x position of relative point, default is equal to x
38
40
  y0?: number;
39
41
  coordCenter?: Vector2; // center of coordinate
@@ -44,6 +46,8 @@ type TextShapeStyleProps = Omit<TextStyleProps, 'text'> &
44
46
  labelTransform?: string;
45
47
  labelTransformOrigin?: string;
46
48
  rotate?: number;
49
+ innerHTML?: string | HTMLElement;
50
+ text?: string;
47
51
  };
48
52
 
49
53
  function getConnectorPoint(shape: GText | Rect) {
@@ -126,8 +130,10 @@ function inferConnectorPath(
126
130
 
127
131
  export const Advance = createElement((g) => {
128
132
  const {
133
+ id,
134
+ className,
129
135
  // Do not pass className
130
- class: className,
136
+ class: _c,
131
137
  transform,
132
138
  rotate,
133
139
  labelTransform,
@@ -136,11 +142,13 @@ export const Advance = createElement((g) => {
136
142
  y,
137
143
  x0 = x,
138
144
  y0 = y,
145
+ text,
139
146
  background,
140
147
  connector,
141
148
  startMarker,
142
149
  endMarker,
143
150
  coordCenter,
151
+ innerHTML,
144
152
  ...rest
145
153
  } = g.attributes as TextShapeStyleProps;
146
154
 
@@ -157,26 +165,43 @@ export const Advance = createElement((g) => {
157
165
  [+x0, +y0],
158
166
  [+x, +y],
159
167
  ];
160
- const shape1 = select(g)
161
- .maybeAppend('text', 'text')
162
- .style('zIndex', 0)
163
- .call(applyStyle, {
164
- textBaseline: 'middle',
165
- transform: labelTransform,
166
- transformOrigin: labelTransformOrigin,
167
- ...rest,
168
- })
169
- .node();
170
168
 
171
- const shape2 = select(g)
169
+ let textShape;
170
+ // Use html to customize advance text.
171
+ if (innerHTML) {
172
+ textShape = select(g)
173
+ .maybeAppend(id, 'html', className)
174
+ .style('zIndex', 0)
175
+ .style('innerHTML', innerHTML)
176
+ .call(applyStyle, {
177
+ transform: labelTransform,
178
+ transformOrigin: labelTransformOrigin,
179
+ ...rest,
180
+ })
181
+ .node();
182
+ } else {
183
+ textShape = select(g)
184
+ .maybeAppend('text', 'text')
185
+ .style('zIndex', 0)
186
+ .style('text', text)
187
+ .call(applyStyle, {
188
+ textBaseline: 'middle',
189
+ transform: labelTransform,
190
+ transformOrigin: labelTransformOrigin,
191
+ ...rest,
192
+ })
193
+ .node();
194
+ }
195
+
196
+ const rect = select(g)
172
197
  .maybeAppend('background', 'rect')
173
198
  .style('zIndex', -1)
174
- .call(applyStyle, inferBackgroundBounds(shape1, padding))
199
+ .call(applyStyle, inferBackgroundBounds(textShape, padding))
175
200
  .call(applyStyle, background ? backgroundStyle : {})
176
201
  .node();
177
202
 
178
203
  const connectorPath = inferConnectorPath(
179
- shape2,
204
+ rect,
180
205
  endPoints,
181
206
  points,
182
207
  coordCenter,
@@ -370,6 +370,12 @@ export const Academy: TC<AcademyOptions> = (options) => {
370
370
  stroke: undefined,
371
371
  offset: 0,
372
372
  },
373
+ htmlLabel: {
374
+ fontSize: 12,
375
+ opacity: 0.65,
376
+ color: COLORS.BLACK,
377
+ fontWeight: 'normal',
378
+ },
373
379
  slider: {
374
380
  trackSize: 16,
375
381
  trackFill: COLORS.STROKE,
@@ -377,6 +377,12 @@ export const Classic: TC<ClassicOptions> = (options) => {
377
377
  stroke: undefined,
378
378
  offset: 0,
379
379
  },
380
+ htmlLabel: {
381
+ fontSize: 12,
382
+ opacity: 0.65,
383
+ color: COLORS.BLACK,
384
+ fontWeight: 'normal',
385
+ },
380
386
  slider: {
381
387
  trackSize: 16,
382
388
  trackFill: COLORS.STROKE,
@@ -376,6 +376,12 @@ export const ClassicDark: TC<ClassicDarkOptions> = (options) => {
376
376
  stroke: undefined,
377
377
  offset: 0,
378
378
  },
379
+ htmlLabel: {
380
+ fontSize: 12,
381
+ opacity: 0.65,
382
+ color: COLORS.BLACK,
383
+ fontWeight: 'normal',
384
+ },
379
385
  slider: {
380
386
  trackSize: 16,
381
387
  trackFill: COLORS.STROKE,
@@ -6,6 +6,11 @@ import { columnOf } from './utils/helper';
6
6
 
7
7
  export type FilterOptions = Omit<FilterTransform, 'type'>;
8
8
 
9
+ function normalizeValue(value) {
10
+ if (typeof value === 'object') return [value.value, value.ordinal];
11
+ else return [value, true];
12
+ }
13
+
9
14
  /**
10
15
  * The Filter transform filter channels.
11
16
  */
@@ -13,15 +18,21 @@ export const Filter: TC<FilterOptions> = (options = {}) => {
13
18
  return (I, mark) => {
14
19
  const { encode, data } = mark;
15
20
  const filters = Object.entries(options)
16
- .map(([key, value]) => {
21
+ .map(([key, v]) => {
17
22
  const [V] = columnOf(encode, key);
18
23
  // Skip empty channel.
19
24
  if (!V) return null;
25
+ const [value, ordinal = true] = normalizeValue(v);
20
26
  if (typeof value === 'function') return (i) => value(V[i]);
21
- const expectedValues = Array.isArray(value) ? value : [value];
22
- // Skip empty expected values.
23
- if (expectedValues.length === 0) return null;
24
- return (i) => expectedValues.includes(V[i]);
27
+ if (ordinal) {
28
+ const expectedValues = Array.isArray(value) ? value : [value];
29
+ // Skip empty expected values.
30
+ if (expectedValues.length === 0) return null;
31
+ return (i) => expectedValues.includes(V[i]);
32
+ } else {
33
+ const [start, end] = value;
34
+ return (i) => V[i] >= start && V[i] <= end;
35
+ }
25
36
  })
26
37
  .filter(defined);
27
38
 
@@ -166,7 +166,11 @@ export class Selection<T = any> {
166
166
  }
167
167
  }
168
168
 
169
- maybeAppend(id: string, node: string | (() => G2Element)) {
169
+ maybeAppend(
170
+ id: string,
171
+ node: string | (() => G2Element),
172
+ className?: string,
173
+ ) {
170
174
  const element = this._elements[0];
171
175
  const child = element.getElementById(id) as G2Element;
172
176
  if (child) {
@@ -175,6 +179,7 @@ export class Selection<T = any> {
175
179
  const newChild =
176
180
  typeof node === 'string' ? this.createElement(node) : node();
177
181
  newChild.id = id;
182
+ if (className) newChild.className = className;
178
183
  element.appendChild(newChild);
179
184
  return new Selection([newChild], null, this._parent, this._document);
180
185
  }