@visactor/vrender-components 1.1.4-alpha.0 → 1.1.4-alpha.2
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.
- package/cjs/animation/animate-component.js +1 -1
- package/cjs/animation/axis-animate.js +1 -1
- package/cjs/animation/exit-release.js +1 -1
- package/cjs/animation/label-animate.js +1 -1
- package/cjs/animation/static-truth.js +1 -1
- package/cjs/axis/util.js +1 -2
- package/cjs/brush/type.js +2 -1
- package/cjs/checkbox/register.js +2 -1
- package/cjs/crosshair/polygon-sector.js +1 -2
- package/cjs/data-zoom/interaction.js +2 -1
- package/cjs/empty-tip/register.js +1 -2
- package/cjs/index.d.ts +1 -1
- package/cjs/index.js +1 -1
- package/cjs/index.js.map +1 -1
- package/cjs/jsx/index.js +1 -1
- package/cjs/label/arc.js +1 -1
- package/cjs/label/base.js +1 -1
- package/cjs/label/data-label-register.js +1 -1
- package/cjs/label/dataLabel.js +1 -1
- package/cjs/legend/discrete/discrete.d.ts +1 -0
- package/cjs/legend/discrete/discrete.js +54 -27
- package/cjs/legend/discrete/discrete.js.map +1 -1
- package/cjs/legend/discrete/type.d.ts +1 -0
- package/cjs/legend/discrete/type.js.map +1 -1
- package/dist/index.es.js +172 -58
- package/es/animation/animate-component.js +1 -1
- package/es/animation/axis-animate.js +1 -1
- package/es/animation/exit-release.js +1 -1
- package/es/animation/label-animate.js +1 -1
- package/es/animation/static-truth.js +1 -1
- package/es/axis/util.js +1 -2
- package/es/brush/type.js +2 -1
- package/es/checkbox/register.js +2 -1
- package/es/crosshair/polygon-sector.js +1 -2
- package/es/data-zoom/interaction.js +2 -1
- package/es/empty-tip/register.js +1 -2
- package/es/index.d.ts +1 -1
- package/es/index.js +1 -1
- package/es/index.js.map +1 -1
- package/es/jsx/index.js +1 -1
- package/es/label/arc.js +1 -1
- package/es/label/base.js +1 -1
- package/es/label/data-label-register.js +1 -1
- package/es/label/dataLabel.js +1 -1
- package/es/legend/discrete/discrete.d.ts +1 -0
- package/es/legend/discrete/discrete.js +51 -25
- package/es/legend/discrete/discrete.js.map +1 -1
- package/es/legend/discrete/type.d.ts +1 -0
- package/es/legend/discrete/type.js.map +1 -1
- package/package.json +6 -6
package/es/jsx/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export * from "./component-type";
|
|
2
|
-
//# sourceMappingURL=index.js.map
|
|
2
|
+
//# sourceMappingURL=index.js.map
|
package/es/label/arc.js
CHANGED
package/es/label/base.js
CHANGED
package/es/label/dataLabel.js
CHANGED
|
@@ -15,6 +15,7 @@ export declare class DiscreteLegend extends LegendBase<DiscreteLegendAttrs> {
|
|
|
15
15
|
private _itemContext;
|
|
16
16
|
private _scrollMask;
|
|
17
17
|
private _scrollMaskContext;
|
|
18
|
+
private _stateDefinitionsCache;
|
|
18
19
|
static defaultAttributes: Partial<DiscreteLegendAttrs>;
|
|
19
20
|
constructor(attributes: DiscreteLegendAttrs, options?: ComponentOptions);
|
|
20
21
|
render(): void;
|
|
@@ -10,6 +10,8 @@ var __rest = this && this.__rest || function(s, e) {
|
|
|
10
10
|
|
|
11
11
|
import { merge, isEmpty, normalizePadding, get, isValid, isNil, isFunction, isArray, minInArray, throttle, isNumberClose, clamp, isObject } from "@visactor/vutils";
|
|
12
12
|
|
|
13
|
+
import { StateDefinitionCompiler } from "@visactor/vrender-core";
|
|
14
|
+
|
|
13
15
|
import { graphicCreator } from "../../util/graphic-creator";
|
|
14
16
|
|
|
15
17
|
import { LegendBase } from "../base";
|
|
@@ -40,7 +42,8 @@ export class DiscreteLegend extends LegendBase {
|
|
|
40
42
|
constructor(attributes, options) {
|
|
41
43
|
super((null == options ? void 0 : options.skipDefault) ? attributes : merge({}, DiscreteLegend.defaultAttributes, attributes)),
|
|
42
44
|
this.name = "discreteLegend", this._itemsContainer = null, this._itemHeightByUser = void 0,
|
|
43
|
-
this._itemHeight = 0, this._itemMaxWidth = 0, this._contentMaxHeight = 0, this.
|
|
45
|
+
this._itemHeight = 0, this._itemMaxWidth = 0, this._contentMaxHeight = 0, this._stateDefinitionsCache = new WeakMap,
|
|
46
|
+
this._onHover = e => {
|
|
44
47
|
const target = e.target;
|
|
45
48
|
if (target && target.name && target.name.startsWith(LEGEND_ELEMENT_NAME.item)) {
|
|
46
49
|
const legendItem = target.delegate;
|
|
@@ -88,7 +91,7 @@ export class DiscreteLegend extends LegendBase {
|
|
|
88
91
|
};
|
|
89
92
|
}
|
|
90
93
|
render() {
|
|
91
|
-
super.render(), this._lastActiveItem = null;
|
|
94
|
+
this._stateDefinitionsCache = new WeakMap, super.render(), this._lastActiveItem = null;
|
|
92
95
|
}
|
|
93
96
|
setSelected(selectedData) {
|
|
94
97
|
var _a;
|
|
@@ -206,7 +209,7 @@ export class DiscreteLegend extends LegendBase {
|
|
|
206
209
|
}), this._appendDataToShape(itemGroup, LEGEND_ELEMENT_NAME.item, item, itemGroup)) : (itemGroup = graphicCreator.group(Object.assign({
|
|
207
210
|
x: 0,
|
|
208
211
|
y: 0
|
|
209
|
-
}, backgroundStyle.style)), this._appendDataToShape(itemGroup, LEGEND_ELEMENT_NAME.item, item, itemGroup, backgroundStyle.state)),
|
|
212
|
+
}, backgroundStyle.style)), this._appendDataToShape(itemGroup, LEGEND_ELEMENT_NAME.item, item, itemGroup, backgroundStyle.state, backgroundStyle.reuseStateDefinitions)),
|
|
210
213
|
itemGroup.id = `${null != id ? id : label}-${index}`, itemGroup.addState(isSelected ? LegendStateValue.selected : LegendStateValue.unSelected);
|
|
211
214
|
const innerGroup = graphicCreator.group({
|
|
212
215
|
x: 0,
|
|
@@ -223,12 +226,14 @@ export class DiscreteLegend extends LegendBase {
|
|
|
223
226
|
y: 0,
|
|
224
227
|
symbolType: "circle",
|
|
225
228
|
strokeBoundsBuffer: 0
|
|
226
|
-
}, shape), shapeStyle.style))
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
229
|
+
}, shape), shapeStyle.style)), shapeStateNeedsItemColor = Object.keys(shapeStyle.state || {}).some((key => {
|
|
230
|
+
const state = shapeStyle.state[key];
|
|
231
|
+
return !!(state.fill || state.stroke) && (!!shape.fill && isNil(state.fill) || !!shape.stroke && isNil(state.stroke));
|
|
232
|
+
})), shapeStates = shapeStateNeedsItemColor ? merge({}, shapeStyle.state) : shapeStyle.state;
|
|
233
|
+
Object.keys(shapeStates || {}).forEach((key => {
|
|
234
|
+
const state = shapeStates[key], color = state.fill || state.stroke;
|
|
235
|
+
shape.fill && isNil(state.fill) && color && (state.fill = color), shape.stroke && isNil(state.stroke) && color && (state.stroke = color);
|
|
236
|
+
})), this._appendDataToShape(itemShape, LEGEND_ELEMENT_NAME.itemShape, item, itemGroup, shapeStates, !shapeStateNeedsItemColor && !1 !== shapeStyle.reuseStateDefinitions),
|
|
232
237
|
itemShape.addState(isSelected ? LegendStateValue.selected : LegendStateValue.unSelected),
|
|
233
238
|
innerGroup.add(itemShape);
|
|
234
239
|
}
|
|
@@ -256,7 +261,7 @@ export class DiscreteLegend extends LegendBase {
|
|
|
256
261
|
text: text,
|
|
257
262
|
_originText: labelAttr.formatMethod ? label : void 0
|
|
258
263
|
}), labelShape = createTextGraphicByType(labelAttributes);
|
|
259
|
-
this._appendDataToShape(labelShape, LEGEND_ELEMENT_NAME.itemLabel, item, itemGroup, labelStyle.state),
|
|
264
|
+
this._appendDataToShape(labelShape, LEGEND_ELEMENT_NAME.itemLabel, item, itemGroup, labelStyle.state, labelStyle.reuseStateDefinitions),
|
|
260
265
|
labelShape.addState(isSelected ? LegendStateValue.selected : LegendStateValue.unSelected),
|
|
261
266
|
innerGroup.add(labelShape);
|
|
262
267
|
const labelSpace = get(labelAttr, "space", DEFAULT_LABEL_SPACE);
|
|
@@ -271,7 +276,7 @@ export class DiscreteLegend extends LegendBase {
|
|
|
271
276
|
text: valueText,
|
|
272
277
|
_originText: valueAttr.formatMethod ? value : void 0
|
|
273
278
|
}), valueShape = createTextGraphicByType(valueAttributes);
|
|
274
|
-
if (this._appendDataToShape(valueShape, LEGEND_ELEMENT_NAME.itemValue, item, itemGroup, valueStyle.state),
|
|
279
|
+
if (this._appendDataToShape(valueShape, LEGEND_ELEMENT_NAME.itemValue, item, itemGroup, valueStyle.state, valueStyle.reuseStateDefinitions),
|
|
275
280
|
valueShape.addState(isSelected ? LegendStateValue.selected : LegendStateValue.unSelected),
|
|
276
281
|
this._itemWidthByUser) {
|
|
277
282
|
const layoutWidth = this._itemWidthByUser - parsedPadding[1] - parsedPadding[3] - shapeSize - shapeSpace - labelSpace - focusSpace - valueSpace;
|
|
@@ -342,20 +347,25 @@ export class DiscreteLegend extends LegendBase {
|
|
|
342
347
|
}));
|
|
343
348
|
}
|
|
344
349
|
_updatePositionOfPager(renderStartY, compWidth, compHeight) {
|
|
345
|
-
|
|
350
|
+
var _a;
|
|
351
|
+
const {pager: pager} = this.attribute, {totalPage: totalPage, isHorizontal: isHorizontal} = this._itemContext, position = pager && pager.position || "middle", hugContent = !(!pager || !pager.hugContent), pagerSpace = null !== (_a = pager && pager.space) && void 0 !== _a ? _a : DEFAULT_PAGER_SPACE;
|
|
346
352
|
if (this._pagerComponent.setTotal(totalPage), isHorizontal) {
|
|
347
353
|
let y;
|
|
348
|
-
y = "start" === position ? renderStartY : "end" === position ? renderStartY + compHeight - this._pagerComponent.AABBBounds.height() / 2 : renderStartY + compHeight / 2 - this._pagerComponent.AABBBounds.height() / 2
|
|
354
|
+
y = "start" === position ? renderStartY : "end" === position ? renderStartY + compHeight - this._pagerComponent.AABBBounds.height() / 2 : renderStartY + compHeight / 2 - this._pagerComponent.AABBBounds.height() / 2;
|
|
355
|
+
let x = compWidth - this._pagerComponent.AABBBounds.width();
|
|
356
|
+
hugContent && (x = Math.max(0, Math.min(this._itemsContainer.AABBBounds.width() + pagerSpace, x))),
|
|
349
357
|
this._pagerComponent.setAttributes({
|
|
350
|
-
x:
|
|
358
|
+
x: x,
|
|
351
359
|
y: y
|
|
352
360
|
});
|
|
353
361
|
} else {
|
|
354
362
|
let x;
|
|
355
|
-
x = "start" === position ? 0 : "end" === position ? compWidth - this._pagerComponent.AABBBounds.width() : (compWidth - this._pagerComponent.AABBBounds.width()) / 2
|
|
363
|
+
x = "start" === position ? 0 : "end" === position ? compWidth - this._pagerComponent.AABBBounds.width() : (compWidth - this._pagerComponent.AABBBounds.width()) / 2;
|
|
364
|
+
let y = compHeight - this._pagerComponent.AABBBounds.height();
|
|
365
|
+
hugContent && (y = Math.max(0, Math.min(renderStartY + this._itemsContainer.AABBBounds.height() + pagerSpace, y))),
|
|
356
366
|
this._pagerComponent.setAttributes({
|
|
357
367
|
x: x,
|
|
358
|
-
y:
|
|
368
|
+
y: y
|
|
359
369
|
});
|
|
360
370
|
}
|
|
361
371
|
}
|
|
@@ -459,11 +469,14 @@ export class DiscreteLegend extends LegendBase {
|
|
|
459
469
|
this._itemContext.totalPage = total, this._updatePositionOfPager(renderStartY, compWidth, compHeight);
|
|
460
470
|
}
|
|
461
471
|
defaultCurrent > 1 && (isHorizontal ? itemsContainer.setAttribute("y", -(defaultCurrent - 1) * (compHeight + spaceRow)) : itemsContainer.setAttribute("x", -(defaultCurrent - 1) * (compWidth + spaceCol)));
|
|
472
|
+
const hugContent = !!pager.hugContent;
|
|
473
|
+
let clipWidth = isHorizontal ? contentWidth : compWidth, clipHeight = isHorizontal ? compHeight : contentHeight;
|
|
474
|
+
hugContent && (isHorizontal ? clipWidth = Math.max(0, Math.min(clipWidth, itemsContainer.AABBBounds.width())) : clipHeight = Math.max(0, Math.min(clipHeight, itemsContainer.AABBBounds.height())));
|
|
462
475
|
const clipGroup = graphicCreator.group({
|
|
463
476
|
x: 0,
|
|
464
477
|
y: renderStartY,
|
|
465
|
-
width:
|
|
466
|
-
height:
|
|
478
|
+
width: clipWidth,
|
|
479
|
+
height: clipHeight,
|
|
467
480
|
clip: !0,
|
|
468
481
|
pickable: !1
|
|
469
482
|
});
|
|
@@ -606,8 +619,16 @@ export class DiscreteLegend extends LegendBase {
|
|
|
606
619
|
item.hasState(LegendStateValue.selected) && selectedData.push(item.data);
|
|
607
620
|
})), selectedData;
|
|
608
621
|
}
|
|
609
|
-
_appendDataToShape(shape, name, data, delegateShape, states =
|
|
610
|
-
shape.name = name, shape.data = data, shape.delegate = delegateShape, shape.states = merge({}, DEFAULT_STATES, states);
|
|
622
|
+
_appendDataToShape(shape, name, data, delegateShape, states, reuseStateDefinitions = !0) {
|
|
623
|
+
if (shape.name = name, shape.data = data, shape.delegate = delegateShape, !reuseStateDefinitions) return void (shape.states = merge({}, DEFAULT_STATES, states));
|
|
624
|
+
const source = null != states ? states : DEFAULT_STATES, cached = this._stateDefinitionsCache.get(source);
|
|
625
|
+
if (cached) return shape.states = cached.definitions, void shape.setStateDefinitionsWithCompiled(cached.definitions, cached.compiledDefinitions);
|
|
626
|
+
const definitions = states ? merge({}, DEFAULT_STATES, states) : DEFAULT_STATES, entry = {
|
|
627
|
+
definitions: definitions,
|
|
628
|
+
compiledDefinitions: (new StateDefinitionCompiler).compile(definitions)
|
|
629
|
+
};
|
|
630
|
+
this._stateDefinitionsCache.set(source, entry), shape.states = entry.definitions,
|
|
631
|
+
shape.setStateDefinitionsWithCompiled(entry.definitions, entry.compiledDefinitions);
|
|
611
632
|
}
|
|
612
633
|
_dispatchLegendEvent(eventName, legendItem, event) {
|
|
613
634
|
const currentSelectedItems = this._getSelectedLegends();
|
|
@@ -624,13 +645,18 @@ export class DiscreteLegend extends LegendBase {
|
|
|
624
645
|
}
|
|
625
646
|
_handleStyle(config, item, isSelected, index, items) {
|
|
626
647
|
const newConfig = {};
|
|
627
|
-
|
|
628
|
-
config.state
|
|
629
|
-
|
|
630
|
-
|
|
648
|
+
if (config.style && (isFunction(config.style) ? newConfig.style = config.style(item, isSelected, index, items) : newConfig.style = config.style),
|
|
649
|
+
config.state) {
|
|
650
|
+
const stateKeys = Object.keys(config.state), hasStateFunction = stateKeys.some((key => isFunction(config.state[key])));
|
|
651
|
+
newConfig.reuseStateDefinitions = !hasStateFunction, hasStateFunction ? (newConfig.state = {},
|
|
652
|
+
stateKeys.forEach((key => {
|
|
653
|
+
config.state[key] && (newConfig.state[key] = isFunction(config.state[key]) ? config.state[key](item, isSelected, index, items) : config.state[key]);
|
|
654
|
+
}))) : newConfig.state = config.state;
|
|
655
|
+
}
|
|
656
|
+
return newConfig;
|
|
631
657
|
}
|
|
632
658
|
release() {
|
|
633
|
-
super.release(), this.removeAllEventListeners();
|
|
659
|
+
this._stateDefinitionsCache = new WeakMap, super.release(), this.removeAllEventListeners();
|
|
634
660
|
}
|
|
635
661
|
}
|
|
636
662
|
|