Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

zrender

Package Overview
Dependencies
Maintainers
1
Versions
76
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

zrender - npm Package Compare versions

Comparing version 4.0.7 to 4.1.0

.travis.yml

42

lib/contain/text.js

@@ -142,11 +142,14 @@ var BoundingRect = require("../core/BoundingRect");

/**
* Follow same interface to `Displayable.prototype.calculateTextPosition`.
* @public
* @param {stirng} textPosition
* @param {Object} rect {x, y, width, height}
* @param {number} distance
* @return {Object} {x, y, textAlign, textVerticalAlign}
* @param {Obejct} [out] Prepared out object. If not input, auto created in the method.
* @param {module:zrender/graphic/Style} style where `textPosition` and `textDistance` are visited.
* @param {Object} rect {x, y, width, height} Rect of the host elment, according to which the text positioned.
* @return {Object} The input `out`. Set: {x, y, textAlign, textVerticalAlign}
*/
function adjustTextPositionOnRect(textPosition, rect, distance) {
function calculateTextPosition(out, style, rect) {
var textPosition = style.textPosition;
var distance = style.textDistance;
var x = rect.x;

@@ -245,8 +248,26 @@ var y = rect.y;

return {
x: x,
y: y,
textAlign: textAlign,
textVerticalAlign: textVerticalAlign
out = out || {};
out.x = x;
out.y = y;
out.textAlign = textAlign;
out.textVerticalAlign = textVerticalAlign;
return out;
}
/**
* To be removed. But still do not remove in case that some one has imported it.
* @deprecated
* @public
* @param {stirng} textPosition
* @param {Object} rect {x, y, width, height}
* @param {number} distance
* @return {Object} {x, y, textAlign, textVerticalAlign}
*/
function adjustTextPositionOnRect(textPosition, rect, distance) {
var dummyStyle = {
textPosition: textPosition,
textDistance: distance
};
return calculateTextPosition({}, dummyStyle, rect);
}

@@ -686,2 +707,3 @@ /**

exports.adjustTextY = adjustTextY;
exports.calculateTextPosition = calculateTextPosition;
exports.adjustTextPositionOnRect = adjustTextPositionOnRect;

@@ -688,0 +710,0 @@ exports.truncateText = truncateText;

@@ -7,19 +7,37 @@ var Eventful = require("../mixin/Eventful");

var _fourPointsTransform = require("./fourPointsTransform");
var buildTransformer = _fourPointsTransform.buildTransformer;
/**
* 事件辅助类
* @module zrender/core/event
* @author Kener (@Kener-林峰, kener.linfeng@gmail.com)
* Utilities for mouse or touch events.
*/
var isDomLevel2 = typeof window !== 'undefined' && !!window.addEventListener;
var MOUSE_EVENT_REG = /^(?:mouse|pointer|contextmenu|drag|drop)|click/;
var EVENT_SAVED_PROP = '___zrEVENTSAVED';
var _calcOut = [];
/**
* Get the `zrX` and `zrY`, which are relative to the top-left of
* the input `el`.
* CSS transform (2D & 3D) is supported.
*
* The strategy to fetch the coords:
* + If `calculate` is not set as `true`, users of this method should
* ensure that `el` is the same or the same size & location as `e.target`.
* Otherwise the result coords are probably not expected. Because we
* firstly try to get coords from e.offsetX/e.offsetY.
* + If `calculate` is set as `true`, the input `el` can be any element
* and we force to calculate the coords based on `el`.
* + The input `el` should be positionable (not position:static).
*
* The force `calculate` can be used in case like:
* When mousemove event triggered on ec tooltip, `e.target` is not `el`(zr painter.dom).
*
* @param {HTMLElement} el DOM element.
* @param {Event} e Mouse event or touch event.
* @param {Object} out Get `out.zrX` and `out.zrY` as the result.
* @param {boolean} [calculate=false] Whether to force calculate
* the coordinates but not use ones provided by browser.
*/
function getBoundingClientRect(el) {
// BlackBerry 5, iOS 3 (original iPhone) don't have getBoundingRect
return el.getBoundingClientRect ? el.getBoundingClientRect() : {
left: 0,
top: 0
};
} // `calculate` is optional, default false
function clientToLocal(el, e, out, calculate) {

@@ -32,9 +50,5 @@ out = out || {}; // According to the W3C Working Draft, offsetX and offsetY should be relative

// In zr painter.dom, padding edge equals to border edge.
// FIXME
// When mousemove event triggered on ec tooltip, target is not zr painter.dom, and
// offsetX/Y is relative to e.target, where the calculation of zrX/Y via offsetX/Y
// is too complex. So css-transfrom dont support in this case temporarily.
if (calculate || !env.canvasSupported) {
defaultGetZrXY(el, e, out);
calculateZrXY(el, e, out);
} // Caution: In FireFox, layerX/layerY Mouse position relative to the closest positioned

@@ -56,3 +70,3 @@ // ancestor element, so we should make sure el is positioned (e.g., not position:static).

else {
defaultGetZrXY(el, e, out);
calculateZrXY(el, e, out);
}

@@ -63,11 +77,98 @@

function defaultGetZrXY(el, e, out) {
// This well-known method below does not support css transform.
var box = getBoundingClientRect(el);
out.zrX = e.clientX - box.left;
out.zrY = e.clientY - box.top;
function calculateZrXY(el, e, out) {
// BlackBerry 5, iOS 3 (original iPhone) don't have getBoundingRect.
if (el.getBoundingClientRect && env.domSupported) {
var ex = e.clientX;
var ey = e.clientY;
if (el.nodeName.toUpperCase() === 'CANVAS') {
// Original approach, which do not support CSS transform.
// marker can not be locationed in a canvas container
// (getBoundingClientRect is always 0). We do not support
// that input a pre-created canvas to zr while using css
// transform in iOS.
var box = el.getBoundingClientRect();
out.zrX = ex - box.left;
out.zrY = ey - box.top;
return;
} else {
var saved = el[EVENT_SAVED_PROP] || (el[EVENT_SAVED_PROP] = {});
var transformer = preparePointerTransformer(prepareCoordMarkers(el, saved), saved);
if (transformer) {
transformer(_calcOut, ex, ey);
out.zrX = _calcOut[0];
out.zrY = _calcOut[1];
return;
}
}
}
out.zrX = out.zrY = 0;
}
function prepareCoordMarkers(el, saved) {
var markers = saved.markers;
if (markers) {
return markers;
}
markers = saved.markers = [];
var propLR = ['left', 'right'];
var propTB = ['top', 'bottom'];
for (var i = 0; i < 4; i++) {
var marker = document.createElement('div');
var stl = marker.style;
var idxLR = i % 2;
var idxTB = (i >> 1) % 2;
stl.cssText = ['position:absolute', 'visibility: hidden', 'padding: 0', 'margin: 0', 'border-width: 0', 'width:0', 'height:0', // 'width: 5px',
// 'height: 5px',
propLR[idxLR] + ':0', propTB[idxTB] + ':0', propLR[1 - idxLR] + ':auto', propTB[1 - idxTB] + ':auto', ''].join('!important;');
el.appendChild(marker);
markers.push(marker);
}
return markers;
}
function preparePointerTransformer(markers, saved) {
var transformer = saved.transformer;
var oldSrcCoords = saved.srcCoords;
var useOld = true;
var srcCoords = [];
var destCoords = [];
for (var i = 0; i < 4; i++) {
var rect = markers[i].getBoundingClientRect();
var ii = 2 * i;
var x = rect.left;
var y = rect.top;
srcCoords.push(x, y);
useOld &= oldSrcCoords && x === oldSrcCoords[ii] && y === oldSrcCoords[ii + 1];
destCoords.push(markers[i].offsetLeft, markers[i].offsetTop);
} // Cache to avoid time consuming of `buildTransformer`.
return useOld ? transformer : (saved.srcCoords = srcCoords, saved.transformer = buildTransformer(srcCoords, destCoords));
}
/**
* 如果存在第三方嵌入的一些dom触发的事件,或touch事件,需要转换一下事件坐标.
* `calculate` is optional, default false.
* Normalize the coordinates of the input event.
*
* Get the `e.zrX` and `e.zrY`, which are relative to the top-left of
* the input `el`.
* Get `e.zrDelta` if using mouse wheel.
* Get `e.which`, see the comment inside this function.
*
* Do not calculate repeatly if `zrX` and `zrY` already exist.
*
* Notice: see comments in `clientToLocal`. check the relationship
* between the result coords and the parameters `el` and `calculate`.
*
* @param {HTMLElement} el DOM element.
* @param {Event} [e] Mouse event or touch event. For lagency IE,
* do not need to input it and `window.event` is used.
* @param {boolean} [calculate=false] Whether to force calculate
* the coordinates but not use ones provided by browser.
*/

@@ -94,3 +195,3 @@

// See jQuery: https://github.com/jquery/jquery/blob/master/src/event.js
// If e.which has been defined, if may be readonly,
// If e.which has been defined, it may be readonly,
// see: https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/which

@@ -155,8 +256,6 @@

* preventDefault and stopPropagation.
* Notice: do not do that in zrender. Upper application
* do that if necessary.
* Notice: do not use this method in zrender. It can only be
* used by upper applications if necessary.
*
* @memberOf module:zrender/core/event
* @method
* @param {Event} e : event对象
* @param {Event} e A mouse or touch event.
*/

@@ -193,3 +292,3 @@

return e.which > 1;
} // 做向上兼容
} // For backward compatibility

@@ -196,0 +295,0 @@

@@ -93,5 +93,7 @@ var curve = require("./curve");

*/
setScale: function (sx, sy) {
this._ux = mathAbs(1 / dpr / sx) || 0;
this._uy = mathAbs(1 / dpr / sy) || 0;
setScale: function (sx, sy, segmentIgnoreThreshold) {
// Compat. Previously there is no segmentIgnoreThreshold.
segmentIgnoreThreshold = segmentIgnoreThreshold || 0;
this._ux = mathAbs(segmentIgnoreThreshold / dpr / sx) || 0;
this._uy = mathAbs(segmentIgnoreThreshold / dpr / sy) || 0;
},

@@ -98,0 +100,0 @@ getContext: function () {

@@ -32,3 +32,3 @@ var Path = require("./Path");

paths[i].path.setScale(scale[0], scale[1]);
paths[i].path.setScale(scale[0], scale[1], paths[i].segmentIgnoreThreshold);
}

@@ -35,0 +35,0 @@ },

@@ -36,4 +36,6 @@ var zrUtil = require("../core/util");

this._rect = null; // Shapes for cascade clipping.
// Can only be `null`/`undefined` or an non-empty array, MUST NOT be an empty array.
// because it is easy to only using null to check whether clipPaths changed.
this.__clipPaths = []; // FIXME Stateful must be mixined after style is setted
this.__clipPaths = null; // FIXME Stateful must be mixined after style is setted
// Stateful.call(this, opts);

@@ -255,3 +257,24 @@ }

return this;
}
},
/**
* The string value of `textPosition` needs to be calculated to a real postion.
* For example, `'inside'` is calculated to `[rect.width/2, rect.height/2]`
* by default. See `contain/text.js#calculateTextPosition` for more details.
* But some coutom shapes like "pin", "flag" have center that is not exactly
* `[width/2, height/2]`. So we provide this hook to customize the calculation
* for those shapes. It will be called if the `style.textPosition` is a string.
* @param {Obejct} [out] Prepared out object. If not provided, this method should
* be responsible for creating one.
* @param {module:zrender/graphic/Style} style
* @param {Object} rect {x, y, width, height}
* @return {Obejct} out The same as the input out.
* {
* x: number. mandatory.
* y: number. mandatory.
* textAlign: string. optional. use style.textAlign by default.
* textVerticalAlign: string. optional. use style.textVerticalAlign by default.
* }
*/
calculateTextPosition: null
};

@@ -258,0 +281,0 @@ zrUtil.inherits(Displayable, Element);

@@ -37,2 +37,4 @@ var _util = require("../../core/util");

var SHADOW_STYLE_COMMON_PROPS = [['textShadowBlur', 'shadowBlur', 0], ['textShadowOffsetX', 'shadowOffsetX', 0], ['textShadowOffsetY', 'shadowOffsetY', 0], ['textShadowColor', 'shadowColor', 'transparent']];
var _tmpTextPositionResult = {};
var _tmpBoxPositionResult = {};
/**

@@ -142,3 +144,3 @@ * @param {module:zrender/graphic/Style} style

var lineHeight = contentBlock.lineHeight;
var boxPos = getBoxPosition(outerHeight, style, rect);
var boxPos = getBoxPosition(_tmpBoxPositionResult, hostEl, style, rect);
var baseX = boxPos.baseX;

@@ -250,3 +252,3 @@ var baseY = boxPos.baseY;

var textPadding = style.textPadding;
var boxPos = getBoxPosition(outerHeight, style, rect);
var boxPos = getBoxPosition(_tmpBoxPositionResult, hostEl, style, rect);
var baseX = boxPos.baseX;

@@ -455,3 +457,3 @@ var baseY = boxPos.baseY;

function getBoxPosition(blockHeiht, style, rect) {
function getBoxPosition(out, hostEl, style, rect) {
var baseX = style.x || 0;

@@ -470,3 +472,3 @@ var baseY = style.y || 0;

} else {
var res = textContain.adjustTextPositionOnRect(textPosition, rect, style.textDistance);
var res = hostEl && hostEl.calculateTextPosition ? hostEl.calculateTextPosition(_tmpTextPositionResult, style, rect) : textContain.calculateTextPosition(_tmpTextPositionResult, style, rect);
baseX = res.x;

@@ -489,8 +491,8 @@ baseY = res.y; // Default align and baseline when has textPosition

return {
baseX: baseX,
baseY: baseY,
textAlign: textAlign,
textVerticalAlign: textVerticalAlign
};
out = out || {};
out.baseX = baseX;
out.baseY = baseY;
out.textAlign = textAlign;
out.textVerticalAlign = textVerticalAlign;
return out;
}

@@ -497,0 +499,0 @@

@@ -36,2 +36,6 @@ var Displayable = require("./Displayable");

strokeContainThreshold: 5,
// This item default to be false. But in map series in echarts,
// in order to improve performance, it should be set to true,
// so the shorty segment won't draw.
segmentIgnoreThreshold: 0,

@@ -90,3 +94,3 @@ /**

var scale = this.getGlobalScale();
path.setScale(scale[0], scale[1]); // Proxy context
path.setScale(scale[0], scale[1], this.segmentIgnoreThreshold); // Proxy context
// Rebuild path in following 2 cases

@@ -93,0 +97,0 @@ // 1. Path is dirty

@@ -82,3 +82,8 @@ var fixShadow = require("./helper/fixShadow");

/**
* @type {Array.<number>}
* `true` is not supported.
* `false`/`null`/`undefined` are the same.
* `false` is used to remove lineDash in some
* case that `null`/`undefined` can not be set.
* (e.g., emphasis.lineStyle in echarts)
* @type {Array.<number>|boolean}
*/

@@ -85,0 +90,0 @@ lineDash: null,

@@ -62,4 +62,4 @@ var _config = require("./config");

function isClipPathChanged(clipPaths, prevClipPaths) {
// displayable.__clipPaths can only be `null`/`undefined` or an non-empty array.
if (clipPaths === prevClipPaths) {
// Can both be null or undefined
return false;

@@ -77,2 +77,4 @@ }

}
return false;
}

@@ -489,8 +491,9 @@

&& !(el.culling && isDisplayableCulled(el, this._width, this._height))) {
var clipPaths = el.__clipPaths; // Optimize when clipping on group with several elements
var clipPaths = el.__clipPaths;
var prevElClipPaths = scope.prevElClipPaths; // Optimize when clipping on group with several elements
if (!scope.prevElClipPaths || isClipPathChanged(clipPaths, scope.prevElClipPaths)) {
if (!prevElClipPaths || isClipPathChanged(clipPaths, prevElClipPaths)) {
// If has previous clipping state, restore from it
if (scope.prevElClipPaths) {
currentLayer.ctx.restore();
if (prevElClipPaths) {
ctx.restore();
scope.prevElClipPaths = null; // Reset prevEl since context has been restored

@@ -497,0 +500,0 @@

@@ -70,22 +70,2 @@ var _core = require("./core");

fill = fill === 'transparent' ? NONE : fill;
/**
* FIXME:
* This is a temporary fix for Chrome's clipping bug
* that happens when a clip-path is referring another one.
* This fix should be used before Chrome's bug is fixed.
* For an element that has clip-path, and fill is none,
* set it to be "rgba(0, 0, 0, 0.002)" will hide the element.
* Otherwise, it will show black fill color.
* 0.002 is used because this won't work for alpha values smaller
* than 0.002.
*
* See
* https://bugs.chromium.org/p/chromium/issues/detail?id=659790
* for more information.
*/
if (svgEl.getAttribute('clip-path') !== 'none' && fill === NONE) {
fill = 'rgba(0, 0, 0, 0.002)';
}
attr(svgEl, 'fill', fill);

@@ -327,2 +307,3 @@ attr(svgEl, 'fill-opacity', style.fillOpacity != null ? style.fillOpacity * style.opacity : style.opacity);

var tmpRect = new BoundingRect();
var tmpTextPositionResult = {};

@@ -351,3 +332,2 @@ var svgTextDrawRectText = function (el, rect, textRect) {

var textPosition = style.textPosition;
var distance = style.textDistance;
var align = style.textAlign || 'left';

@@ -360,3 +340,3 @@

var font = style.font || [style.fontStyle || '', style.fontWeight || '', style.fontSize || '', style.fontFamily || ''].join(' ') || textContain.DEFAULT_FONT;
var verticalAlign = getVerticalAlignForSvg(style.textVerticalAlign);
var verticalAlign = style.textVerticalAlign;
textRect = textContain.getBoundingRect(text, font, align, verticalAlign, style.textPadding, style.textLineHeight);

@@ -369,10 +349,10 @@ var lineHeight = textRect.lineHeight; // Text position represented by coord

} else {
var newPos = textContain.adjustTextPositionOnRect(textPosition, rect, distance);
var newPos = el.calculateTextPosition ? el.calculateTextPosition(tmpTextPositionResult, style, rect) : textContain.calculateTextPosition(tmpTextPositionResult, style, rect);
x = newPos.x;
y = newPos.y;
verticalAlign = getVerticalAlignForSvg(newPos.textVerticalAlign);
verticalAlign = newPos.textVerticalAlign;
align = newPos.textAlign;
}
attr(textSvgEl, 'alignment-baseline', verticalAlign);
setVerticalAlign(textSvgEl, verticalAlign);

@@ -441,3 +421,3 @@ if (font) {

if (verticalAlign === 'after-edge') {
if (verticalAlign === 'bottom') {
dy = -textRect.height + lineHeight;

@@ -464,3 +444,3 @@ textPadding && (dy -= textPadding[2]);

textSvgEl.appendChild(tspan);
attr(tspan, 'alignment-baseline', verticalAlign);
setVerticalAlign(tspan, verticalAlign);
attr(tspan, 'text-anchor', textAnchor);

@@ -499,9 +479,17 @@ } else {

function getVerticalAlignForSvg(verticalAlign) {
if (verticalAlign === 'middle') {
return 'middle';
} else if (verticalAlign === 'bottom') {
return 'after-edge';
} else {
return 'hanging';
function setVerticalAlign(textSvgEl, verticalAlign) {
switch (verticalAlign) {
case 'middle':
attr(textSvgEl, 'dominant-baseline', 'middle');
attr(textSvgEl, 'alignment-baseline', 'middle');
break;
case 'bottom':
attr(textSvgEl, 'dominant-baseline', 'ideographic');
attr(textSvgEl, 'alignment-baseline', 'ideographic');
break;
default:
attr(textSvgEl, 'dominant-baseline', 'hanging');
attr(textSvgEl, 'alignment-baseline', 'hanging');
}

@@ -508,0 +496,0 @@ }

@@ -140,5 +140,5 @@ var Definable = require("./Definable");

ClippathManager.prototype.markUsed = function (displayable) {
var that = this;
var that = this; // displayable.__clipPaths can only be `null`/`undefined` or an non-empty array.
if (displayable.__clipPaths && displayable.__clipPaths.length > 0) {
if (displayable.__clipPaths) {
zrUtil.each(displayable.__clipPaths, function (clipPath) {

@@ -145,0 +145,0 @@ if (clipPath._dom) {

@@ -238,3 +238,3 @@ var env = require("../core/env");

// }
if (style.lineDash != null) {
if (style.lineDash) {
el.dashstyle = style.lineDash.join(' ');

@@ -846,4 +846,3 @@ }

if (!fromTextEl) {
var textPosition = style.textPosition;
var distance = style.textDistance; // Text position represented by coord
var textPosition = style.textPosition; // Text position represented by coord

@@ -855,3 +854,3 @@ if (textPosition instanceof Array) {

} else {
var res = textContain.adjustTextPositionOnRect(textPosition, rect, distance);
var res = this.calculateTextPosition ? this.calculateTextPosition({}, style, rect) : textContain.calculateTextPosition({}, style, rect);
x = res.x;

@@ -970,3 +969,4 @@ y = res.y; // Default align and baseline when has textPosition

opacity: style.opacity,
lineDash: style.lineDash
lineDash: style.lineDash || null // style.lineDash can be `false`.
}, this);

@@ -973,0 +973,0 @@ textVmlEl.style.zIndex = getZIndex(this.zlevel, this.z, this.z2); // Attached to root

@@ -36,3 +36,3 @@ var guid = require("./core/guid");

var version = '4.0.7';
var version = '4.1.0';
/**

@@ -237,9 +237,6 @@ * Initializing a zrender instance

// Or it will cause zrender refreshes again and again.
this._needsRefresh = false;
this.painter.refresh();
/**
* Avoid trigger zr.refresh in Element#beforeUpdate hook
*/
this._needsRefresh = this._needsRefreshHover = false;
this.painter.refresh(); // Avoid trigger zr.refresh in Element#beforeUpdate hook
this._needsRefresh = false; // var end = new Date();
this._needsRefresh = this._needsRefreshHover = false; // var end = new Date();
// var log = document.getElementById('log');

@@ -246,0 +243,0 @@ // if (log) {

{
"name": "zrender",
"version": "4.0.7",
"version": "4.1.0",
"description": "A lightweight canvas library.",

@@ -16,10 +16,11 @@ "keywords": [

"build": "node build/build.js --release",
"dev": "node build/build.js --watch"
"dev": "node build/build.js --watch",
"test": "node build/build.js"
},
"license": "BSD",
"license": "BSD-3-Clause",
"devDependencies": {
"@babel/core": "7.0.0-beta.31",
"@babel/helper-module-transforms": "7.0.0-beta.31",
"@babel/helper-simple-access": "7.0.0-beta.31",
"@babel/template": "7.0.0-beta.31",
"@babel/core": "7.3.4",
"@babel/helper-module-transforms": "7.2.2",
"@babel/helper-simple-access": "7.1.0",
"@babel/template": "7.2.2",
"@babel/types": "7.0.0-beta.31",

@@ -26,0 +27,0 @@ "assert": "1.4.1",

ZRender
=======
A lightweight canvas library which providing 2d draw for [ECharts](https://github.com/ecomfe/echarts)
A lightweight canvas library which providing 2d draw for [ECharts](https://github.com/ecomfe/echarts).
[![Build Status](https://travis-ci.com/ecomfe/zrender.svg?branch=master)](https://travis-ci.com/ecomfe/zrender) [![](https://img.shields.io/npm/dw/zrender.svg?label=npm%20downloads&style=flat)](https://www.npmjs.com/package/zrender) ![Commits Since 4.0.0](https://img.shields.io/github/commits-since/ecomfe/zrender/4.0.0.svg?colorB=%234c1&style=flat)
## Document

@@ -7,0 +9,0 @@

@@ -145,9 +145,12 @@ import BoundingRect from '../core/BoundingRect';

/**
* Follow same interface to `Displayable.prototype.calculateTextPosition`.
* @public
* @param {stirng} textPosition
* @param {Object} rect {x, y, width, height}
* @param {number} distance
* @return {Object} {x, y, textAlign, textVerticalAlign}
* @param {Obejct} [out] Prepared out object. If not input, auto created in the method.
* @param {module:zrender/graphic/Style} style where `textPosition` and `textDistance` are visited.
* @param {Object} rect {x, y, width, height} Rect of the host elment, according to which the text positioned.
* @return {Object} The input `out`. Set: {x, y, textAlign, textVerticalAlign}
*/
export function adjustTextPositionOnRect(textPosition, rect, distance) {
export function calculateTextPosition(out, style, rect) {
var textPosition = style.textPosition;
var distance = style.textDistance;

@@ -237,11 +240,26 @@ var x = rect.x;

return {
x: x,
y: y,
textAlign: textAlign,
textVerticalAlign: textVerticalAlign
};
out = out || {};
out.x = x;
out.y = y;
out.textAlign = textAlign;
out.textVerticalAlign = textVerticalAlign;
return out;
}
/**
* To be removed. But still do not remove in case that some one has imported it.
* @deprecated
* @public
* @param {stirng} textPosition
* @param {Object} rect {x, y, width, height}
* @param {number} distance
* @return {Object} {x, y, textAlign, textVerticalAlign}
*/
export function adjustTextPositionOnRect(textPosition, rect, distance) {
var dummyStyle = {textPosition: textPosition, textDistance: distance};
return calculateTextPosition({}, dummyStyle, rect);
}
/**
* Show ellipsis if overflow.

@@ -248,0 +266,0 @@ *

/**
* 事件辅助类
* @module zrender/core/event
* @author Kener (@Kener-林峰, kener.linfeng@gmail.com)
* Utilities for mouse or touch events.
*/

@@ -9,2 +7,3 @@

import env from './env';
import {buildTransformer} from './fourPointsTransform';

@@ -14,9 +13,28 @@ var isDomLevel2 = (typeof window !== 'undefined') && !!window.addEventListener;

var MOUSE_EVENT_REG = /^(?:mouse|pointer|contextmenu|drag|drop)|click/;
var EVENT_SAVED_PROP = '___zrEVENTSAVED';
var _calcOut = [];
function getBoundingClientRect(el) {
// BlackBerry 5, iOS 3 (original iPhone) don't have getBoundingRect
return el.getBoundingClientRect ? el.getBoundingClientRect() : {left: 0, top: 0};
}
// `calculate` is optional, default false
/**
* Get the `zrX` and `zrY`, which are relative to the top-left of
* the input `el`.
* CSS transform (2D & 3D) is supported.
*
* The strategy to fetch the coords:
* + If `calculate` is not set as `true`, users of this method should
* ensure that `el` is the same or the same size & location as `e.target`.
* Otherwise the result coords are probably not expected. Because we
* firstly try to get coords from e.offsetX/e.offsetY.
* + If `calculate` is set as `true`, the input `el` can be any element
* and we force to calculate the coords based on `el`.
* + The input `el` should be positionable (not position:static).
*
* The force `calculate` can be used in case like:
* When mousemove event triggered on ec tooltip, `e.target` is not `el`(zr painter.dom).
*
* @param {HTMLElement} el DOM element.
* @param {Event} e Mouse event or touch event.
* @param {Object} out Get `out.zrX` and `out.zrY` as the result.
* @param {boolean} [calculate=false] Whether to force calculate
* the coordinates but not use ones provided by browser.
*/
export function clientToLocal(el, e, out, calculate) {

@@ -32,8 +50,4 @@ out = out || {};

// FIXME
// When mousemove event triggered on ec tooltip, target is not zr painter.dom, and
// offsetX/Y is relative to e.target, where the calculation of zrX/Y via offsetX/Y
// is too complex. So css-transfrom dont support in this case temporarily.
if (calculate || !env.canvasSupported) {
defaultGetZrXY(el, e, out);
calculateZrXY(el, e, out);
}

@@ -58,3 +72,3 @@ // Caution: In FireFox, layerX/layerY Mouse position relative to the closest positioned

else {
defaultGetZrXY(el, e, out);
calculateZrXY(el, e, out);
}

@@ -65,12 +79,115 @@

function defaultGetZrXY(el, e, out) {
// This well-known method below does not support css transform.
var box = getBoundingClientRect(el);
out.zrX = e.clientX - box.left;
out.zrY = e.clientY - box.top;
function calculateZrXY(el, e, out) {
// BlackBerry 5, iOS 3 (original iPhone) don't have getBoundingRect.
if (el.getBoundingClientRect && env.domSupported) {
var ex = e.clientX;
var ey = e.clientY;
if (el.nodeName.toUpperCase() === 'CANVAS') {
// Original approach, which do not support CSS transform.
// marker can not be locationed in a canvas container
// (getBoundingClientRect is always 0). We do not support
// that input a pre-created canvas to zr while using css
// transform in iOS.
var box = el.getBoundingClientRect();
out.zrX = ex - box.left;
out.zrY = ey - box.top;
return;
}
else {
var saved = el[EVENT_SAVED_PROP] || (el[EVENT_SAVED_PROP] = {});
var transformer = preparePointerTransformer(prepareCoordMarkers(el, saved), saved);
if (transformer) {
transformer(_calcOut, ex, ey);
out.zrX = _calcOut[0];
out.zrY = _calcOut[1];
return;
}
}
}
out.zrX = out.zrY = 0;
}
function prepareCoordMarkers(el, saved) {
var markers = saved.markers;
if (markers) {
return markers;
}
markers = saved.markers = [];
var propLR = ['left', 'right'];
var propTB = ['top', 'bottom'];
for (var i = 0; i < 4; i++) {
var marker = document.createElement('div');
var stl = marker.style;
var idxLR = i % 2;
var idxTB = (i >> 1) % 2;
stl.cssText = [
'position:absolute',
'visibility: hidden',
'padding: 0',
'margin: 0',
'border-width: 0',
'width:0',
'height:0',
// 'width: 5px',
// 'height: 5px',
propLR[idxLR] + ':0',
propTB[idxTB] + ':0',
propLR[1 - idxLR] + ':auto',
propTB[1 - idxTB] + ':auto',
''
].join('!important;');
el.appendChild(marker);
markers.push(marker);
}
return markers;
}
function preparePointerTransformer(markers, saved) {
var transformer = saved.transformer;
var oldSrcCoords = saved.srcCoords;
var useOld = true;
var srcCoords = [];
var destCoords = [];
for (var i = 0; i < 4; i++) {
var rect = markers[i].getBoundingClientRect();
var ii = 2 * i;
var x = rect.left;
var y = rect.top;
srcCoords.push(x, y);
useOld &= oldSrcCoords && x === oldSrcCoords[ii] && y === oldSrcCoords[ii + 1];
destCoords.push(markers[i].offsetLeft, markers[i].offsetTop);
}
// Cache to avoid time consuming of `buildTransformer`.
return useOld
? transformer
: (
saved.srcCoords = srcCoords,
saved.transformer = buildTransformer(srcCoords, destCoords)
);
}
/**
* 如果存在第三方嵌入的一些dom触发的事件,或touch事件,需要转换一下事件坐标.
* `calculate` is optional, default false.
* Normalize the coordinates of the input event.
*
* Get the `e.zrX` and `e.zrY`, which are relative to the top-left of
* the input `el`.
* Get `e.zrDelta` if using mouse wheel.
* Get `e.which`, see the comment inside this function.
*
* Do not calculate repeatly if `zrX` and `zrY` already exist.
*
* Notice: see comments in `clientToLocal`. check the relationship
* between the result coords and the parameters `el` and `calculate`.
*
* @param {HTMLElement} el DOM element.
* @param {Event} [e] Mouse event or touch event. For lagency IE,
* do not need to input it and `window.event` is used.
* @param {boolean} [calculate=false] Whether to force calculate
* the coordinates but not use ones provided by browser.
*/

@@ -101,3 +218,3 @@ export function normalizeEvent(el, e, calculate) {

// See jQuery: https://github.com/jquery/jquery/blob/master/src/event.js
// If e.which has been defined, if may be readonly,
// If e.which has been defined, it may be readonly,
// see: https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/which

@@ -162,8 +279,6 @@ var button = e.button;

* preventDefault and stopPropagation.
* Notice: do not do that in zrender. Upper application
* do that if necessary.
* Notice: do not use this method in zrender. It can only be
* used by upper applications if necessary.
*
* @memberOf module:zrender/core/event
* @method
* @param {Event} e : event对象
* @param {Event} e A mouse or touch event.
*/

@@ -202,3 +317,3 @@ export var stop = isDomLevel2

// 做向上兼容
// For backward compatibility
export {Eventful as Dispatcher};

@@ -100,5 +100,7 @@ /**

*/
setScale: function (sx, sy) {
this._ux = mathAbs(1 / dpr / sx) || 0;
this._uy = mathAbs(1 / dpr / sy) || 0;
setScale: function (sx, sy, segmentIgnoreThreshold) {
// Compat. Previously there is no segmentIgnoreThreshold.
segmentIgnoreThreshold = segmentIgnoreThreshold || 0;
this._ux = mathAbs(segmentIgnoreThreshold / dpr / sx) || 0;
this._uy = mathAbs(segmentIgnoreThreshold / dpr / sy) || 0;
},

@@ -105,0 +107,0 @@

@@ -34,3 +34,3 @@ // CompoundPath to improve performance

}
paths[i].path.setScale(scale[0], scale[1]);
paths[i].path.setScale(scale[0], scale[1], paths[i].segmentIgnoreThreshold);
}

@@ -37,0 +37,0 @@ },

@@ -41,3 +41,5 @@ /**

// Shapes for cascade clipping.
this.__clipPaths = [];
// Can only be `null`/`undefined` or an non-empty array, MUST NOT be an empty array.
// because it is easy to only using null to check whether clipPaths changed.
this.__clipPaths = null;

@@ -267,3 +269,24 @@ // FIXME Stateful must be mixined after style is setted

return this;
}
},
/**
* The string value of `textPosition` needs to be calculated to a real postion.
* For example, `'inside'` is calculated to `[rect.width/2, rect.height/2]`
* by default. See `contain/text.js#calculateTextPosition` for more details.
* But some coutom shapes like "pin", "flag" have center that is not exactly
* `[width/2, height/2]`. So we provide this hook to customize the calculation
* for those shapes. It will be called if the `style.textPosition` is a string.
* @param {Obejct} [out] Prepared out object. If not provided, this method should
* be responsible for creating one.
* @param {module:zrender/graphic/Style} style
* @param {Object} rect {x, y, width, height}
* @return {Obejct} out The same as the input out.
* {
* x: number. mandatory.
* y: number. mandatory.
* textAlign: string. optional. use style.textAlign by default.
* textVerticalAlign: string. optional. use style.textVerticalAlign by default.
* }
*/
calculateTextPosition: null
};

@@ -270,0 +293,0 @@

@@ -29,2 +29,4 @@

];
var _tmpTextPositionResult = {};
var _tmpBoxPositionResult = {};

@@ -148,3 +150,3 @@ /**

var boxPos = getBoxPosition(outerHeight, style, rect);
var boxPos = getBoxPosition(_tmpBoxPositionResult, hostEl, style, rect);
var baseX = boxPos.baseX;

@@ -260,3 +262,3 @@ var baseY = boxPos.baseY;

var boxPos = getBoxPosition(outerHeight, style, rect);
var boxPos = getBoxPosition(_tmpBoxPositionResult, hostEl, style, rect);
var baseX = boxPos.baseX;

@@ -494,3 +496,3 @@ var baseY = boxPos.baseY;

function getBoxPosition(blockHeiht, style, rect) {
function getBoxPosition(out, hostEl, style, rect) {
var baseX = style.x || 0;

@@ -510,5 +512,5 @@ var baseY = style.y || 0;

else {
var res = textContain.adjustTextPositionOnRect(
textPosition, rect, style.textDistance
);
var res = (hostEl && hostEl.calculateTextPosition)
? hostEl.calculateTextPosition(_tmpTextPositionResult, style, rect)
: textContain.calculateTextPosition(_tmpTextPositionResult, style, rect);
baseX = res.x;

@@ -530,10 +532,12 @@ baseY = res.y;

return {
baseX: baseX,
baseY: baseY,
textAlign: textAlign,
textVerticalAlign: textVerticalAlign
};
out = out || {};
out.baseX = baseX;
out.baseY = baseY;
out.textAlign = textAlign;
out.textVerticalAlign = textVerticalAlign;
return out;
}
function setCtx(ctx, prop, value) {

@@ -540,0 +544,0 @@ ctx[prop] = fixShadow(ctx, prop, value);

@@ -38,2 +38,7 @@ import Displayable from './Displayable';

// This item default to be false. But in map series in echarts,
// in order to improve performance, it should be set to true,
// so the shorty segment won't draw.
segmentIgnoreThreshold: 0,
/**

@@ -94,3 +99,3 @@ * See `module:zrender/src/graphic/helper/subPixelOptimize`.

var scale = this.getGlobalScale();
path.setScale(scale[0], scale[1]);
path.setScale(scale[0], scale[1], this.segmentIgnoreThreshold);

@@ -97,0 +102,0 @@ // Proxy context

@@ -91,3 +91,8 @@

/**
* @type {Array.<number>}
* `true` is not supported.
* `false`/`null`/`undefined` are the same.
* `false` is used to remove lineDash in some
* case that `null`/`undefined` can not be set.
* (e.g., emphasis.lineStyle in echarts)
* @type {Array.<number>|boolean}
*/

@@ -94,0 +99,0 @@ lineDash: null,

@@ -52,6 +52,6 @@ import {devicePixelRatio} from './config';

function isClipPathChanged(clipPaths, prevClipPaths) {
if (clipPaths === prevClipPaths) { // Can both be null or undefined
// displayable.__clipPaths can only be `null`/`undefined` or an non-empty array.
if (clipPaths === prevClipPaths) {
return false;
}
if (!clipPaths || !prevClipPaths || (clipPaths.length !== prevClipPaths.length)) {

@@ -65,2 +65,3 @@ return true;

}
return false;
}

@@ -511,12 +512,10 @@

var clipPaths = el.__clipPaths;
var prevElClipPaths = scope.prevElClipPaths;
// Optimize when clipping on group with several elements
if (!scope.prevElClipPaths
|| isClipPathChanged(clipPaths, scope.prevElClipPaths)
) {
if (!prevElClipPaths || isClipPathChanged(clipPaths, prevElClipPaths)) {
// If has previous clipping state, restore from it
if (scope.prevElClipPaths) {
currentLayer.ctx.restore();
if (prevElClipPaths) {
ctx.restore();
scope.prevElClipPaths = null;
// Reset prevEl since context has been restored

@@ -523,0 +522,0 @@ scope.prevEl = null;

@@ -65,22 +65,2 @@ // TODO

fill = fill === 'transparent' ? NONE : fill;
/**
* FIXME:
* This is a temporary fix for Chrome's clipping bug
* that happens when a clip-path is referring another one.
* This fix should be used before Chrome's bug is fixed.
* For an element that has clip-path, and fill is none,
* set it to be "rgba(0, 0, 0, 0.002)" will hide the element.
* Otherwise, it will show black fill color.
* 0.002 is used because this won't work for alpha values smaller
* than 0.002.
*
* See
* https://bugs.chromium.org/p/chromium/issues/detail?id=659790
* for more information.
*/
if (svgEl.getAttribute('clip-path') !== 'none' && fill === NONE) {
fill = 'rgba(0, 0, 0, 0.002)';
}
attr(svgEl, 'fill', fill);

@@ -333,2 +313,3 @@ attr(svgEl, 'fill-opacity', style.fillOpacity != null ? style.fillOpacity * style.opacity : style.opacity);

var tmpRect = new BoundingRect();
var tmpTextPositionResult = {};

@@ -359,3 +340,2 @@ var svgTextDrawRectText = function (el, rect, textRect) {

var textPosition = style.textPosition;
var distance = style.textDistance;
var align = style.textAlign || 'left';

@@ -375,3 +355,3 @@

var verticalAlign = getVerticalAlignForSvg(style.textVerticalAlign);
var verticalAlign = style.textVerticalAlign;

@@ -390,12 +370,12 @@ textRect = textContain.getBoundingRect(

else {
var newPos = textContain.adjustTextPositionOnRect(
textPosition, rect, distance
);
var newPos = el.calculateTextPosition
? el.calculateTextPosition(tmpTextPositionResult, style, rect)
: textContain.calculateTextPosition(tmpTextPositionResult, style, rect);
x = newPos.x;
y = newPos.y;
verticalAlign = getVerticalAlignForSvg(newPos.textVerticalAlign);
verticalAlign = newPos.textVerticalAlign;
align = newPos.textAlign;
}
attr(textSvgEl, 'alignment-baseline', verticalAlign);
setVerticalAlign(textSvgEl, verticalAlign);

@@ -468,3 +448,3 @@ if (font) {

var dy = 0;
if (verticalAlign === 'after-edge') {
if (verticalAlign === 'bottom') {
dy = -textRect.height + lineHeight;

@@ -491,3 +471,3 @@ textPadding && (dy -= textPadding[2]);

textSvgEl.appendChild(tspan);
attr(tspan, 'alignment-baseline', verticalAlign);
setVerticalAlign(tspan, verticalAlign);
attr(tspan, 'text-anchor', textAnchor);

@@ -524,12 +504,18 @@ }

function getVerticalAlignForSvg(verticalAlign) {
if (verticalAlign === 'middle') {
return 'middle';
function setVerticalAlign(textSvgEl, verticalAlign) {
switch (verticalAlign) {
case 'middle':
attr(textSvgEl, 'dominant-baseline', 'middle');
attr(textSvgEl, 'alignment-baseline', 'middle');
break;
case 'bottom':
attr(textSvgEl, 'dominant-baseline', 'ideographic');
attr(textSvgEl, 'alignment-baseline', 'ideographic');
break;
default:
attr(textSvgEl, 'dominant-baseline', 'hanging');
attr(textSvgEl, 'alignment-baseline', 'hanging');
}
else if (verticalAlign === 'bottom') {
return 'after-edge';
}
else {
return 'hanging';
}
}

@@ -536,0 +522,0 @@

@@ -159,3 +159,4 @@ /**

var that = this;
if (displayable.__clipPaths && displayable.__clipPaths.length > 0) {
// displayable.__clipPaths can only be `null`/`undefined` or an non-empty array.
if (displayable.__clipPaths) {
zrUtil.each(displayable.__clipPaths, function (clipPath) {

@@ -162,0 +163,0 @@ if (clipPath._dom) {

@@ -225,3 +225,3 @@ // http://www.w3.org/TR/NOTE-VML

// }
if (style.lineDash != null) {
if (style.lineDash) {
el.dashstyle = style.lineDash.join(' ');

@@ -879,3 +879,2 @@ }

var textPosition = style.textPosition;
var distance = style.textDistance;
// Text position represented by coord

@@ -889,5 +888,5 @@ if (textPosition instanceof Array) {

else {
var res = textContain.adjustTextPositionOnRect(
textPosition, rect, distance
);
var res = this.calculateTextPosition
? this.calculateTextPosition({}, style, rect)
: textContain.calculateTextPosition({}, style, rect);
x = res.x;

@@ -1026,3 +1025,3 @@ y = res.y;

opacity: style.opacity,
lineDash: style.lineDash
lineDash: style.lineDash || null // style.lineDash can be `false`.
}, this);

@@ -1029,0 +1028,0 @@

@@ -31,3 +31,3 @@ /*!

*/
export var version = '4.0.7';
export var version = '4.1.0';

@@ -231,10 +231,10 @@ /**

// var start = new Date();
// Clear needsRefresh ahead to avoid something wrong happens in refresh
// Or it will cause zrender refreshes again and again.
this._needsRefresh = false;
this._needsRefresh = this._needsRefreshHover = false;
this.painter.refresh();
/**
* Avoid trigger zr.refresh in Element#beforeUpdate hook
*/
this._needsRefresh = false;
// Avoid trigger zr.refresh in Element#beforeUpdate hook
this._needsRefresh = this._needsRefreshHover = false;
// var end = new Date();

@@ -241,0 +241,0 @@ // var log = document.getElementById('log');

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc