Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.0] [FEATURE] more configurable styles for lineStyle & borderStyle. #12961

Merged
merged 33 commits into from Aug 28, 2020
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
5362125
feat: more styles for line type.
plainheart Jul 13, 2020
b3011d3
tweak: lineStyle.dashArray can be a single number.
plainheart Jul 13, 2020
044654f
Merge branch 'next' of https://github.com/apache/incubator-echarts in…
plainheart Jul 16, 2020
35b9048
feat: support for miterLimit.
plainheart Jul 16, 2020
868dfc1
feat: support for border.
plainheart Jul 16, 2020
7b405b6
Merge branch 'next' of https://github.com/apache/incubator-echarts in…
plainheart Jul 19, 2020
666142d
fix: remove redundant semicolon
plainheart Jul 19, 2020
f17eca5
Merge branch 'next' of https://github.com/apache/incubator-echarts in…
plainheart Jul 19, 2020
d830228
tweak: tweak `getBorderLineDash` for item style.
plainheart Jul 20, 2020
a3c341f
fix: compatible with bar series.
plainheart Jul 20, 2020
051eeab
Merge branch 'next' of https://github.com/apache/incubator-echarts in…
plainheart Jul 22, 2020
09c6519
tweak: tweak the logic of border style for line series and bar series.
plainheart Jul 22, 2020
c9c8060
tweak: remove dev code.
plainheart Jul 22, 2020
02fcba3
feat: support for text dash line.
plainheart Jul 22, 2020
e8df502
fix: tweak label style.
plainheart Jul 22, 2020
a17d2a0
fix: border line dash bug in itemStyle.
plainheart Jul 22, 2020
f970eb2
Merge branch 'next' of https://github.com/apache/incubator-echarts in…
plainheart Jul 25, 2020
fc1c95f
Merge branch 'next' of https://github.com/apache/incubator-echarts in…
plainheart Jul 28, 2020
85494bc
test: added more test cases for components.
plainheart Jul 28, 2020
873cb10
Merge branch 'next' of https://github.com/apache/incubator-echarts in…
plainheart Jul 30, 2020
76b348c
Merge branch 'next' of https://github.com/apache/incubator-echarts in…
plainheart Jul 31, 2020
4ffd0fa
fix(axisPointer): improve the style of axisPointer label and support …
plainheart Jul 31, 2020
c13342d
Merge branch 'next' of https://github.com/apache/incubator-echarts in…
plainheart Jul 31, 2020
1264d47
Merge branch 'next' of https://github.com/apache/incubator-echarts in…
plainheart Jul 31, 2020
3051340
Merge branch 'next' of https://github.com/apache/incubator-echarts in…
plainheart Aug 9, 2020
db9d0b1
fix: simplify the merging logic of item style.
plainheart Aug 9, 2020
8923f29
Merge branch 'next' of https://github.com/apache/incubator-echarts in…
plainheart Aug 14, 2020
9001e86
Merge branch 'next' of https://github.com/apache/incubator-echarts in…
plainheart Aug 17, 2020
9279f75
refact(dash): normalize dash style in zrender.
plainheart Aug 17, 2020
7cb3b47
Merge branch 'next' of https://github.com/apache/incubator-echarts in…
plainheart Aug 24, 2020
c05642b
fix(axis): tweak line dash fetcher for SingleAxisView.
plainheart Aug 24, 2020
31937ab
fix: merge defined line style.
plainheart Aug 24, 2020
ad3992a
fix(axis): tweak line width set logic.
plainheart Aug 24, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/chart/bar/BarView.ts
Expand Up @@ -1054,4 +1054,4 @@ function createBackgroundEl(

ChartView.registerClass(BarView);

export default BarView;
export default BarView;
5 changes: 2 additions & 3 deletions src/chart/helper/Symbol.ts
Expand Up @@ -200,7 +200,6 @@ class Symbol extends graphic.Group {
const symbolPath = this.childAt(0) as ECSymbol;
const seriesModel = data.hostModel as SeriesModel;


let emphasisItemStyle;
let blurItemStyle;
let selectItemStyle;
Expand Down Expand Up @@ -232,8 +231,8 @@ class Symbol extends graphic.Group {
if (!seriesScope || data.hasItemOption) {
const itemModel = (seriesScope && seriesScope.itemModel)
? seriesScope.itemModel : data.getItemModel<SymbolDrawItemModelOption>(idx);

const emphasisModel = itemModel.getModel('emphasis');

emphasisItemStyle = emphasisModel.getModel('itemStyle').getItemStyle();
selectItemStyle = itemModel.getModel(['select', 'itemStyle']).getItemStyle();
blurItemStyle = itemModel.getModel(['blur', 'itemStyle']).getItemStyle();
Expand Down Expand Up @@ -383,4 +382,4 @@ function driftSymbol(this: ECSymbol, dx: number, dy: number) {
}


export default Symbol;
export default Symbol;
2 changes: 1 addition & 1 deletion src/chart/helper/SymbolDraw.ts
Expand Up @@ -290,4 +290,4 @@ class SymbolDraw {

}

export default SymbolDraw;
export default SymbolDraw;
17 changes: 5 additions & 12 deletions src/component/axisPointer/viewHelper.ts
Expand Up @@ -38,6 +38,7 @@ import ExtensionAPI from '../../ExtensionAPI';
import CartesianAxisModel from '../../coord/cartesian/AxisModel';
import Model from '../../model/Model';
import { PathStyleProps } from 'zrender/src/graphic/Path';
import { createTextStyle } from '../../label/labelStyle';

interface LayoutInfo {
position: VectorArray
Expand Down Expand Up @@ -121,21 +122,13 @@ export function buildLabelElOption(
// shape: {x: 0, y: 0, width: width, height: height, r: labelModel.get('borderRadius')},
x: position[0],
y: position[1],
// TODO: rich
style: {
style: createTextStyle(labelModel, {
text: text,
textFont: font,
font: font,
fill: labelModel.getTextColor(),
padding: paddings,
backgroundColor: bgColor as ColorString,
borderColor: labelModel.get('borderColor') || 'transparent',
borderRadius: labelModel.get('borderRadius'),
borderWidth: labelModel.get('borderWidth') || 0,
shadowBlur: labelModel.get('shadowBlur'),
shadowColor: labelModel.get('shadowColor'),
shadowOffsetX: labelModel.get('shadowOffsetX'),
shadowOffsetY: labelModel.get('shadowOffsetY')
},
backgroundColor: bgColor as ColorString
}),
// Lable should be over axisPointer.
z2: 10
};
Expand Down
4 changes: 2 additions & 2 deletions src/component/title.ts
Expand Up @@ -189,7 +189,7 @@ class TitleView extends ComponentView {
}
if (sublink) {
subTextEl.on('click', function () {
windowOpen(link, '_' + titleModel.get('subtarget'));
windowOpen(sublink, '_' + titleModel.get('subtarget'));
});
}

Expand Down Expand Up @@ -279,4 +279,4 @@ class TitleView extends ComponentView {
}
}

ComponentView.registerClass(TitleView);
ComponentView.registerClass(TitleView);
43 changes: 39 additions & 4 deletions src/label/labelStyle.ts
Expand Up @@ -20,7 +20,7 @@ import { deprecateReplaceLog } from '../util/log';

type TextCommonParams = {
/**
* Whether diable drawing box of block (outer most).
* Whether disable drawing box of block (outer most).
*/
disableBox?: boolean
/**
Expand Down Expand Up @@ -450,10 +450,27 @@ function setTokenTextStyle(
if (strokeColor != null) {
textStyle.stroke = strokeColor;
}
const lineWidth = retrieve2(textStyleModel.getShallow('textBorderWidth'), globalTextStyle.textBorderWidth);
if (lineWidth != null) {
textStyle.lineWidth = lineWidth;
const textBorderWidth = retrieve2(textStyleModel.getShallow('textBorderWidth'), globalTextStyle.textBorderWidth);
if (textBorderWidth != null) {
textStyle.lineWidth = textBorderWidth;
}
const textBorderType = retrieve2(textStyleModel.getShallow('textBorderType'), globalTextStyle.textBorderType);
if (!textBorderType || textBorderType === 'solid') {
textStyle.lineDash = [];
}
else {
let textBorderDashArray = retrieve2(textStyleModel.getShallow('textBorderDashArray'), globalTextStyle.textBorderDashArray);
// compatible with single number
if (textBorderDashArray != null && !isNaN(textBorderDashArray as number)) {
textBorderDashArray = [+textBorderDashArray];
}
textStyle.lineDash = textBorderDashArray as number[] || (textBorderType === 'dashed' ? [5, 5] : [1, 1]);
}
const textBorderDashOffset = retrieve2(textStyleModel.getShallow('textBorderDashOffset'), globalTextStyle.textBorderDashOffset);
if (textBorderDashOffset != null) {
textStyle.lineDashOffset = textBorderDashOffset;
}

// TODO
if (!isNotNormal && !isAttached) {
// Set default finally.
Expand Down Expand Up @@ -493,6 +510,23 @@ function setTokenTextStyle(
}
}

const borderType = retrieve2(textStyleModel.getShallow('borderType'), globalTextStyle.borderType);
if (!borderType || borderType === 'solid') {
textStyle.borderDash = [];
}
else {
let borderDashArray = retrieve2(textStyleModel.getShallow('borderDashArray'), globalTextStyle.borderDashArray);
// compatible with single number
if (borderDashArray != null && !isNaN(borderDashArray as number)) {
borderDashArray = [+borderDashArray];
}
textStyle.borderDash = borderDashArray as number[] || (borderType === 'dashed' ? [5, 5] : [1, 1]);
}
const borderDashOffset = retrieve2(textStyleModel.getShallow('borderDashOffset'), globalTextStyle.borderDashOffset);
if (borderDashOffset != null) {
textStyle.borderDashOffset = borderDashOffset;
}

if ((textStyle.backgroundColor === 'auto' || textStyle.backgroundColor === 'inherit') && inheritColor) {
if (__DEV__) {
if (textStyle.backgroundColor === 'auto') {
Expand All @@ -511,6 +545,7 @@ function setTokenTextStyle(
}
}
}

export function getFont(
opt: Pick<TextCommonOption, 'fontStyle' | 'fontWeight' | 'fontSize' | 'fontFamily'>,
ecModel: GlobalModel
Expand Down
33 changes: 26 additions & 7 deletions src/model/mixin/itemStyle.ts
Expand Up @@ -30,7 +30,12 @@ export const ITEM_STYLE_KEY_MAP = [
['shadowBlur'],
['shadowOffsetX'],
['shadowOffsetY'],
['shadowColor']
['shadowColor'],
['lineDash', 'borderDashArray'],
['lineDashOffset', 'borderDashOffset'],
['lineCap', 'borderCap'],
['lineJoin', 'borderJoin'],
['miterLimit', 'borderMiterLimit']
];

const getItemStyle = makeStyleMapper(ITEM_STYLE_KEY_MAP);
Expand All @@ -42,7 +47,12 @@ type ItemStyleKeys = 'fill'
| 'shadowBlur'
| 'shadowOffsetX'
| 'shadowOffsetY'
| 'shadowColor';
| 'shadowColor'
| 'lineDash'
| 'lineDashOffset'
| 'lineCap'
| 'lineJoin'
| 'miterLimit';

export type ItemStyleProps = Pick<PathStyleProps, ItemStyleKeys>;

Expand All @@ -54,15 +64,24 @@ class ItemStyleMixin {
includes?: readonly (keyof ItemStyleOption)[]
): ItemStyleProps {
const style = getItemStyle(this, excludes, includes);
const lineDash = this.getBorderLineDash();
lineDash && (style.lineDash = lineDash);
style.lineDash = this.getBorderLineDash(style.lineWidth);
return style;
}

getBorderLineDash(this: Model): number[] {
getBorderLineDash(this: Model, lineWidth?: number): number[] {
const lineType = this.get('borderType');
return (lineType === 'solid' || lineType == null) ? null
: (lineType === 'dashed' ? [5, 5] : [1, 1]);
if (lineType == null || lineType === 'solid') {
return [];
}

lineWidth = lineWidth || 0;

let dashArray = this.get('borderDashArray');
// compatible with single number
if (dashArray != null && !isNaN(dashArray)) {
dashArray = [+dashArray];
}
return dashArray || (lineType === 'dashed' ? [5, 5] : [1, 1]);
}
plainheart marked this conversation as resolved.
Show resolved Hide resolved
}

Expand Down
47 changes: 32 additions & 15 deletions src/model/mixin/lineStyle.ts
Expand Up @@ -29,7 +29,12 @@ export const LINE_STYLE_KEY_MAP = [
['shadowBlur'],
['shadowOffsetX'],
['shadowOffsetY'],
['shadowColor']
['shadowColor'],
['lineDash', 'dashArray'],
['lineDashOffset', 'dashOffset'],
['lineCap', 'cap'],
['lineJoin', 'join'],
['miterLimit']
];

const getLineStyle = makeStyleMapper(LINE_STYLE_KEY_MAP);
Expand All @@ -40,37 +45,49 @@ type LineStyleKeys = 'lineWidth'
| 'shadowBlur'
| 'shadowOffsetX'
| 'shadowOffsetY'
| 'shadowColor';
| 'shadowColor'
| 'lineDash'
| 'lineDashOffset'
| 'lineCap'
| 'lineJoin'
| 'miterLimit';

type LineStyleProps = Pick<PathStyleProps, LineStyleKeys>;

class LineStyleMixin {

getLineStyle(this: Model, excludes?: readonly (keyof LineStyleOption)[]): LineStyleProps {
getLineStyle(
this: Model,
excludes?: readonly (keyof LineStyleOption)[]
): LineStyleProps {
const style = getLineStyle(this, excludes);
// Always set lineDash whether dashed, otherwise we can not
// erase the previous style when assigning to el.style.
(style as any).lineDash = this.getLineDash((style as any).lineWidth);
style.lineDash = this.getLineDash(style.lineWidth);
return style;
}

getLineDash(this: Model, lineWidth?: number) {
if (lineWidth == null) {
lineWidth = 1;
}
getLineDash(this: Model, lineWidth?: number): false | number[] {
const lineType = this.get('type');
const dotSize = Math.max(lineWidth, 2);
const dashSize = lineWidth * 4;
return (lineType === 'solid' || lineType == null)
if (lineType == null || lineType === 'solid') {
// Use `false` but not `null` for the solid line here, because `null` might be
// ignored when assigning to `el.style`. e.g., when setting `lineStyle.type` as
// `'dashed'` and `emphasis.lineStyle.type` as `'solid'` in graph series, the
// `lineDash` gotten form the latter one is not able to erase that from the former
// one if using `null` here according to the emhpsis strategy in `util/graphic.js`.
? false
: lineType === 'dashed'
? [dashSize, dashSize]
: [dotSize, dotSize];
return false;
}
if (lineWidth == null) {
lineWidth = 1;
}
let dashArray = this.get('dashArray');
// compatible with single number
if (dashArray != null && !isNaN(dashArray)) {
dashArray = [+dashArray];
}
return lineType === 'dashed'
? dashArray || [lineWidth * 4]
: dashArray || [Math.max(lineWidth, 2)];
}
};

Expand Down
16 changes: 16 additions & 0 deletions src/util/types.ts
Expand Up @@ -655,6 +655,11 @@ export interface BorderOptionMixin {
borderColor?: string
borderWidth?: number
borderType?: ZRLineType
borderCap?: CanvasLineCap
borderJoin?: CanvasLineJoin
borderDashArray?: number | number[]
borderDashOffset?: number
borderMiterLimit?: number
}

export type AnimationDelayCallbackParam = {
Expand Down Expand Up @@ -777,6 +782,11 @@ export interface LineStyleOption<Clr = ZRColor> extends ShadowOptionMixin {
color?: Clr
opacity?: number
type?: ZRLineType
cap?: CanvasLineCap
join?: CanvasLineJoin
dashArray?: number | number[]
dashOffset?: number
miterLimit?: number
}

/**
Expand Down Expand Up @@ -848,13 +858,19 @@ export interface TextCommonOption extends ShadowOptionMixin {
}
borderColor?: string
borderWidth?: number
borderType?: ZRLineType
borderDashArray?: number | number[]
borderDashOffset?: number
borderRadius?: number | number[]
padding?: number | number[]

width?: number | string// Percent
height?: number
textBorderColor?: string
textBorderWidth?: number
textBorderType?: ZRLineType
textBorderDashArray?: number | number[]
textBorderDashOffset?: number

textShadowBlur?: number
textShadowColor?: string
Expand Down