Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions src/component/legend/LegendView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,15 +130,15 @@ class LegendView extends ComponentView {
selectorPosition = orient === 'horizontal' ? 'end' : 'start';
}

this.renderInner(itemAlign, legendModel, ecModel, api, selector, orient, selectorPosition);

// Perform layout.
const positionInfo = legendModel.getBoxLayoutParams();
const viewportSize = {width: api.getWidth(), height: api.getHeight()};
const padding = legendModel.get('padding');

const maxSize = layoutUtil.getLayoutRect(positionInfo, viewportSize, padding);

this.renderInner(itemAlign, legendModel, ecModel, api, selector, orient, selectorPosition, maxSize);

const mainRect = this.layoutInner(legendModel, itemAlign, maxSize, isFirstRender, selector, selectorPosition);

// Place mainGroup, based on the calculated `mainRect`.
Expand Down Expand Up @@ -173,7 +173,8 @@ class LegendView extends ComponentView {
api: ExtensionAPI,
selector: LegendSelectorButtonOption[],
orient: LegendOption['orient'],
selectorPosition: LegendOption['selectorPosition']
selectorPosition: LegendOption['selectorPosition'],
maxSize: layoutUtil.LayoutRect,
) {
const contentGroup = this.getContentGroup();
const legendDrawnMap = zrUtil.createHashMap();
Expand Down Expand Up @@ -221,7 +222,8 @@ class LegendView extends ComponentView {
const itemGroup = this._createItem(
seriesModel, name, dataIndex,
legendItemModel, legendModel, itemAlign,
lineVisualStyle, style, legendIcon, selectMode, api
lineVisualStyle, style, legendIcon, selectMode, api,
maxSize,
);

itemGroup.on('click', curry(dispatchSelectAction, name, null, api, excludeSeriesId))
Expand Down Expand Up @@ -276,7 +278,8 @@ class LegendView extends ComponentView {
const itemGroup = this._createItem(
seriesModel, name, dataIndex,
legendItemModel, legendModel, itemAlign,
{}, style, legendIcon, selectMode, api
{}, style, legendIcon, selectMode, api,
maxSize,
);

// FIXME: consider different series has items with the same name.
Expand Down Expand Up @@ -387,7 +390,8 @@ class LegendView extends ComponentView {
itemVisualStyle: PathStyleProps,
legendIcon: string,
selectMode: LegendOption['selectedMode'],
api: ExtensionAPI
api: ExtensionAPI,
maxSize: layoutUtil.LayoutRect,
) {
const drawType = seriesModel.visualDrawType;
const itemWidth = legendModel.get('itemWidth');
Expand Down Expand Up @@ -469,7 +473,8 @@ class LegendView extends ComponentView {
y: itemHeight / 2,
fill: textColor,
align: textAlign,
verticalAlign: 'middle'
verticalAlign: 'middle',
width: maxSize.width - textX,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If legend is layout horizontally, the "break" effect would be wrong.
And if the text has textStyle.backgroundColor, the effect would be broken by this change, since textStyle.width is shared by backgroundColor and overflow currently.

I think this feature currently can only serve for vertical layout.
And set width only if overflow: 'truncate' | 'break' | 'breakAll', for textStyle.backgroundColor` compromise.

And zrender need upgrade to support a more wise setting about text width, like maxWidth.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. Let's leave this to the next version.

}, {inheritColor: textColor})
}));

Expand Down
5 changes: 3 additions & 2 deletions src/component/legend/ScrollableLegendView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,13 @@ class ScrollableLegendView extends LegendView {
api: ExtensionAPI,
selector: LegendSelectorButtonOption[],
orient: ScrollableLegendOption['orient'],
selectorPosition: ScrollableLegendOption['selectorPosition']
selectorPosition: ScrollableLegendOption['selectorPosition'],
maxSize: layoutUtil.LayoutRect,
) {
const self = this;

// Render content items.
super.renderInner(itemAlign, legendModel, ecModel, api, selector, orient, selectorPosition);
super.renderInner(itemAlign, legendModel, ecModel, api, selector, orient, selectorPosition, maxSize);

const controllerGroup = this._controllerGroup;

Expand Down
147 changes: 147 additions & 0 deletions test/legend-overflow.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.