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
9 changes: 7 additions & 2 deletions build/progress.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,13 @@ module.exports = function progress(options = {}) {
},

buildEnd() {
process.stdout.clearLine();
process.stdout.cursorTo(0);
if (process.stdout.isTTY) {
process.stdout.clearLine();
process.stdout.cursorTo(0);
}
else {
console.log('');
}
}
};
};
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"build:lib": "npx tsc -m ES2015 --outDir lib",
"watch:bundle": "node build/build.js --watch",
"watch:lib": "npx tsc -w -m ES2015 --outDir lib",
"test": "npx jest --config test/ut/jest.config.js"
"test": "npx jest --config test/ut/jest.config.js",
"lint": "npx eslint src/**/*.ts"
},
"license": "BSD-3-Clause",
"types": "index.d.ts",
Expand Down
1 change: 1 addition & 0 deletions src/Element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ export type ElementCalculateTextPosition = (
let tmpTextPosCalcRes = {} as TextPositionCalculationResult;
let tmpBoundingRect = new BoundingRect(0, 0, 0, 0);

// eslint-disable-next-line @typescript-eslint/no-unused-vars
interface Element<Props extends ElementProps = ElementProps> extends Transformable,
Eventful<{
[key in ElementEventName]: (e: ElementEvent) => void | boolean
Expand Down
8 changes: 4 additions & 4 deletions src/PainterBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import { GradientObject } from './graphic/Gradient';
import { PatternObject } from './graphic/Pattern';
import { Dictionary } from './core/types';

interface PainterOption {
width?: number | string // Can be 10 / 10px / auto
height?: number | string
}
// interface PainterOption {
// width?: number | string // Can be 10 / 10px / auto
// height?: number | string
// }

export interface PainterBase {

Expand Down
4 changes: 2 additions & 2 deletions src/animation/Animator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -430,8 +430,8 @@ class Track {
for (let i = 0; i < kfsLen; i++) {
if (arrDim === 0) {
if (this.isValueColor) {
kfs[i].additiveValue
= add1DArray([], kfs[i].value as NumberArray, startValue as NumberArray, -1);
kfs[i].additiveValue =
add1DArray([], kfs[i].value as NumberArray, startValue as NumberArray, -1);
}
else {
kfs[i].additiveValue = kfs[i].value as number - (startValue as number);
Expand Down
2 changes: 1 addition & 1 deletion src/animation/Clip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type ondestroyCallback = () => void
type onrestartCallback = () => void

export type DeferredEventTypes = 'destroy' | 'restart'
type DeferredEventKeys = 'ondestroy' | 'onrestart'
// type DeferredEventKeys = 'ondestroy' | 'onrestart'

export interface ClipProps {
life?: number
Expand Down
8 changes: 5 additions & 3 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ let dpr = 1;

// If in browser environment
if (typeof window !== 'undefined') {
dpr = Math.max(window.devicePixelRatio
|| (window.screen && (window.screen as any).deviceXDPI / (window.screen as any).logicalXDPI)
|| 1, 1);
dpr = Math.max(
window.devicePixelRatio
|| (window.screen && (window.screen as any).deviceXDPI / (window.screen as any).logicalXDPI)
|| 1, 1
);
}

/**
Expand Down
5 changes: 3 additions & 2 deletions src/core/PathProxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1059,8 +1059,8 @@ export default class PathProxy {
const psi = d[i++];
const anticlockwise = !d[i++];
const r = (rx > ry) ? rx : ry;
const scaleX = (rx > ry) ? 1 : rx / ry;
const scaleY = (rx > ry) ? ry / rx : 1;
// const scaleX = (rx > ry) ? 1 : rx / ry;
// const scaleY = (rx > ry) ? ry / rx : 1;
const isEllipse = mathAbs(rx - ry) > 1e-3;
let endAngle = startAngle + delta;
let breakBuild = false;
Expand Down Expand Up @@ -1174,6 +1174,7 @@ export interface PathRebuilder {
bezierCurveTo(x: number, y: number, x2: number, y2: number, x3: number, y3: number): void
quadraticCurveTo(x: number, y: number, x2: number, y2: number): void
arc(cx: number, cy: number, r: number, startAngle: number, endAngle: number, anticlockwise: boolean): void
// eslint-disable-next-line max-len
ellipse(cx: number, cy: number, radiusX: number, radiusY: number, rotation: number, startAngle: number, endAngle: number, anticlockwise: boolean): void
rect(x: number, y: number, width: number, height: number): void
closePath(): void
Expand Down
2 changes: 1 addition & 1 deletion src/core/arrayDiff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,6 @@ function clonePath(path: DiffPath) {
return { newPos: path.newPos, components: path.components.slice(0) };
}

export default function arrayDiff<T> (oldArr: T[], newArr: T[], equal?: EqualFunc<T>): DiffComponent[] {
export default function arrayDiff<T>(oldArr: T[], newArr: T[], equal?: EqualFunc<T>): DiffComponent[] {
return diff(oldArr, newArr, equal);
}
4 changes: 2 additions & 2 deletions src/core/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ function detect(ua: string, env: Env) {
if (edge) {
browser.edge = true;
browser.version = edge[1];
browser.newEdge = +edge[1].split('.')[0] > 18;
browser.newEdge = +edge[1].split('.')[0] > 18;
}

// It is difficult to detect WeChat in Win Phone precisely, because ua can
Expand Down Expand Up @@ -108,7 +108,7 @@ function detect(ua: string, env: Env) {

// except IE 6-8 and very old firefox 2-3 & opera 10.1
// other browsers all support `transform`
env.transformSupported = env.transform3dSupported
env.transformSupported = env.transform3dSupported
// transform 2D is supported in IE9
|| (browser.ie && +browser.version >= 9);

Expand Down
2 changes: 1 addition & 1 deletion src/debug/showDebugDirtyRect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class DebugRect {
extend(style, {
backgroundColor: 'rgba(0, 0, 255, 0.2)',
border: '1px solid #00f'
})
});
dom.style.cssText = `
position: absolute;
opacity: 0;
Expand Down
1 change: 1 addition & 0 deletions src/graphic/Displayable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export type DisplayableState = Pick<DisplayableProps, DisplayableStatePropNames>
const PRIMARY_STATES_KEYS = ['z', 'z2', 'invisible'] as const;
const PRIMARY_STATES_KEYS_IN_HOVER_LAYER = ['invisible'] as const;

// eslint-disable-next-line @typescript-eslint/no-unused-vars
interface Displayable<Props extends DisplayableProps = DisplayableProps> {
animate(key?: '', loop?: boolean): Animator<this>
animate(key: 'style', loop?: boolean): Animator<this['style']>
Expand Down
1 change: 1 addition & 0 deletions src/graphic/Path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ export interface PathProps extends DisplayableProps {
type PathKey = keyof PathProps
type PathPropertyType = PropType<PathProps, PathKey>

// eslint-disable-next-line @typescript-eslint/no-unused-vars
interface Path<Props extends PathProps = PathProps> {
animate(key?: '', loop?: boolean): Animator<this>
animate(key: 'style', loop?: boolean): Animator<this['style']>
Expand Down
4 changes: 2 additions & 2 deletions src/graphic/helper/dashStyle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ export function normalizeLineDash(lineType: any, lineWidth?: number): number[] |
return null;
}
lineWidth = lineWidth || 1;
return lineType === 'dashed'
return lineType === 'dashed'
? [4 * lineWidth, 2 * lineWidth]
: lineType === 'dotted'
: lineType === 'dotted'
? [lineWidth]
: isNumber(lineType)
? [lineType] : isArray(lineType) ? lineType : null;
Expand Down
42 changes: 23 additions & 19 deletions src/graphic/helper/roundSector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ type CornerTangents = {
};

function intersect(
x0: number, y0: number,
x1: number, y1: number,
x2: number, y2: number,
x0: number, y0: number,
x1: number, y1: number,
x2: number, y2: number,
x3: number, y3: number
): [number, number] {
const x10 = x1 - x0;
Expand All @@ -41,9 +41,9 @@ function intersect(

// Compute perpendicular offset line of length rc.
function computeCornerTangents(
x0: number, y0: number,
x1: number, y1: number,
radius: number, cr: number,
x0: number, y0: number,
x1: number, y1: number,
radius: number, cr: number,
clockwise: boolean
): CornerTangents {
const x01 = x0 - x1;
Expand Down Expand Up @@ -150,14 +150,14 @@ export function buildPath(ctx: CanvasRenderingContext2D | PathProxy, shape: {
// is a circle or annulus
else if (arc > PI2 - e) {
ctx.moveTo(
x + radius * mathCos(startAngle),
x + radius * mathCos(startAngle),
y + radius * mathSin(startAngle)
);
ctx.arc(x, y, radius, startAngle, endAngle, !clockwise);

if (innerRadius > e) {
ctx.moveTo(
x + innerRadius * mathCos(endAngle),
x + innerRadius * mathCos(endAngle),
y + innerRadius * mathSin(endAngle)
);
ctx.arc(x, y, innerRadius, endAngle, startAngle, clockwise);
Expand Down Expand Up @@ -219,15 +219,17 @@ export function buildPath(ctx: CanvasRenderingContext2D | PathProxy, shape: {

// Have the corners merged?
if (cr1 < cr) {
// eslint-disable-next-line max-len
ctx.arc(x + ct0.cx, y + ct0.cy, cr1, mathATan2(ct0.y01, ct0.x01), mathATan2(ct1.y01, ct1.x01), !clockwise);
}
else {
// draw the two corners and the ring
ctx.arc(x + ct0.cx, y + ct0.cy, cr1, mathATan2(ct0.y01, ct0.x01), mathATan2(ct0.y11, ct0.x11), !clockwise);

ctx.arc(x, y, radius, mathATan2(ct0.cy + ct0.y11, ct0.cx + ct0.x11), mathATan2(ct1.cy + ct1.y11, ct1.cx + ct1.x11), !clockwise);

ctx.arc(x + ct1.cx, y + ct1.cy, cr1, mathATan2(ct1.y11, ct1.x11), mathATan2(ct1.y01, ct1.x01), !clockwise);
// draw the two corners and the ring
// eslint-disable-next-line max-len
ctx.arc(x + ct0.cx, y + ct0.cy, cr1, mathATan2(ct0.y01, ct0.x01), mathATan2(ct0.y11, ct0.x11), !clockwise);
// eslint-disable-next-line max-len
ctx.arc(x, y, radius, mathATan2(ct0.cy + ct0.y11, ct0.cx + ct0.x11), mathATan2(ct1.cy + ct1.y11, ct1.cx + ct1.x11), !clockwise);
// eslint-disable-next-line max-len
ctx.arc(x + ct1.cx, y + ct1.cy, cr1, mathATan2(ct1.y11, ct1.x11), mathATan2(ct1.y01, ct1.x01), !clockwise);
}
}
// the outer ring is a circular arc
Expand All @@ -248,15 +250,17 @@ export function buildPath(ctx: CanvasRenderingContext2D | PathProxy, shape: {

// Have the corners merged?
if (cr0 < icr) {
// eslint-disable-next-line max-len
ctx.arc(x + ct0.cx, y + ct0.cy, cr0, mathATan2(ct0.y01, ct0.x01), mathATan2(ct1.y01, ct1.x01), !clockwise);
}
// draw the two corners and the ring
else {
ctx.arc(x + ct0.cx, y + ct0.cy, cr0, mathATan2(ct0.y01, ct0.x01), mathATan2(ct0.y11, ct0.x11), !clockwise);

ctx.arc(x, y, innerRadius, mathATan2(ct0.cy + ct0.y11, ct0.cx + ct0.x11), mathATan2(ct1.cy + ct1.y11, ct1.cx + ct1.x11), clockwise);

ctx.arc(x + ct1.cx, y + ct1.cy, cr0, mathATan2(ct1.y11, ct1.x11), mathATan2(ct1.y01, ct1.x01), !clockwise);
// eslint-disable-next-line max-len
ctx.arc(x + ct0.cx, y + ct0.cy, cr0, mathATan2(ct0.y01, ct0.x01), mathATan2(ct0.y11, ct0.x11), !clockwise);
// eslint-disable-next-line max-len
ctx.arc(x, y, innerRadius, mathATan2(ct0.cy + ct0.y11, ct0.cx + ct0.x11), mathATan2(ct1.cy + ct1.y11, ct1.cx + ct1.x11), clockwise);
// eslint-disable-next-line max-len
ctx.arc(x + ct1.cx, y + ct1.cy, cr0, mathATan2(ct1.y11, ct1.x11), mathATan2(ct1.y01, ct1.x01), !clockwise);
}
}
// the inner ring is just a circular arc
Expand Down
2 changes: 1 addition & 1 deletion src/graphic/shape/Sector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Sector extends Path<SectorProps> {
}

buildPath(ctx: CanvasRenderingContext2D, shape: SectorShape) {
roundSectorHelper.buildPath(ctx, shape)
roundSectorHelper.buildPath(ctx, shape);
}

isZeroArea() {
Expand Down
12 changes: 5 additions & 7 deletions src/svg/Painter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -444,13 +444,11 @@ class SVGPainter implements PainterBase {
dispose() {
this.root.innerHTML = '';

this._svgRoot
= this._backgroundRoot
= this._svgDom
= this._backgroundNode
= this._viewport
= this.storage
= null;
this._svgRoot =
this._backgroundRoot =
this._svgDom =
this._backgroundNode =
this._viewport = this.storage = null;
}

clear() {
Expand Down
2 changes: 1 addition & 1 deletion src/tool/dividePath.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { fromPoints } from '../core/bbox';
import BoundingRect from '../core/BoundingRect';
import Point from '../core/Point';
import { each, map } from '../core/util';
import { map } from '../core/util';
import Path from '../graphic/Path';
import Polygon from '../graphic/shape/Polygon';
import Rect from '../graphic/shape/Rect';
Expand Down
21 changes: 13 additions & 8 deletions src/tool/morphPath.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import PathProxy from '../core/PathProxy';
import { cubicSubdivide } from '../core/curve';
import Path from '../graphic/Path';
import Element, { ElementAnimateConfig } from '../Element';
import { defaults, extend, map } from '../core/util';
import { defaults, map } from '../core/util';
import { lerp } from '../core/vector';
import Group, { GroupLike } from '../graphic/Group';
import { clonePath } from './path';
Expand Down Expand Up @@ -558,10 +558,15 @@ function hilbert(x: number, y: number, minX: number, minY: number, maxX: number,
let d = 0;
let tmp: number;
for (let s = (1 << bits) / 2; s > 0; s /= 2) {
let rx = 0, ry = 0;
let rx = 0;
let ry = 0;

if ((x & s) > 0) rx = 1;
if ((y & s) > 0) ry = 1;
if ((x & s) > 0) {
rx = 1;
}
if ((y & s) > 0) {
ry = 1;
}

d += s * s * ((3 * rx) ^ ry);

Expand Down Expand Up @@ -603,7 +608,7 @@ function sortPaths(pathList: Path[]): Path[] {
cp,
z: hilbert(cp[0], cp[1], xMin, yMin, xMax, yMax),
path: pathList[idx]
}
};
});

return items.sort((a, b) => a.z - b.z).map(item => item.path);
Expand Down Expand Up @@ -645,7 +650,7 @@ function createEmptyReturn() {
fromIndividuals: [] as Path[],
toIndividuals: [] as Path[],
count: 0
}
};
}
/**
* Make combine morphing from many paths to one.
Expand Down Expand Up @@ -756,7 +761,7 @@ export function combineMorph(
restoreToPath();
oldDone && oldDone();
}
}
};
// Animate each element individually.
for (let i = 0; i < toLen; i++) {
// TODO only call during once?
Expand Down Expand Up @@ -886,4 +891,4 @@ export function separateMorph(
};
}

export { split as defaultDividePath }
export { split as defaultDividePath };
3 changes: 1 addition & 2 deletions src/vml/Painter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
* VML Painter.
*/

import {logError} from '../core/util';
import {logError, each} from '../core/util';
import * as vmlCore from './core';
import {each} from '../core/util';

function parseInt10(val) {
return parseInt(val, 10);
Expand Down
3 changes: 2 additions & 1 deletion src/zrender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import Storage from './Storage';
import {PainterBase} from './PainterBase';
import Animation from './animation/Animation';
import HandlerProxy from './dom/HandlerProxy';
import Element, {ElementEventCallback, ElementEvent} from './Element';
import Element, { ElementEventCallback } from './Element';
import { Dictionary, ElementEventName, RenderedEvent, WithThisType } from './core/types';
import { LayerConfig } from './canvas/Layer';
import { GradientObject } from './graphic/Gradient';
Expand Down Expand Up @@ -407,6 +407,7 @@ class ZRender {
}

on<Ctx>(eventName: ElementEventName, eventHandler: ElementEventCallback<Ctx, ZRenderType>, context?: Ctx): this
// eslint-disable-next-line max-len
on<Ctx>(eventName: string, eventHandler: WithThisType<EventCallback<any[]>, unknown extends Ctx ? ZRenderType : Ctx>, context?: Ctx): this
// eslint-disable-next-line max-len
on<Ctx>(eventName: string, eventHandler: (...args: any) => any, context?: Ctx): this {
Expand Down