Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
Ovilia committed Jul 12, 2021
2 parents 2c80de2 + fca2cb7 commit e7fab2a
Show file tree
Hide file tree
Showing 64 changed files with 1,609 additions and 306 deletions.
2 changes: 1 addition & 1 deletion .github/stale.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Configuration for probot-stale - https://github.com/probot/stale

# Number of days of inactivity before an Issue or Pull Request becomes stale
daysUntilStale: 730 # two years
daysUntilStale: 731 # two years

# Number of days of inactivity before an Issue or Pull Request with the stale label is closed.
# Set to false to disable. If disabled, issues still need to be closed manually, but will remain marked as stale.
Expand Down
20 changes: 10 additions & 10 deletions package-lock.json

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

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@
"lint:dist": "echo 'It might take a while. Please wait ...' && npx jshint --config .jshintrc-dist dist/echarts.js"
},
"dependencies": {
"tslib": "2.0.3",
"zrender": "npm:zrender-nightly@^5.1.2-dev.20210625"
"tslib": "2.3.0",
"zrender": "npm:zrender-nightly@^5.1.2-dev.20210701"
},
"devDependencies": {
"@babel/code-frame": "7.10.4",
Expand Down Expand Up @@ -106,6 +106,6 @@
"socket.io": "2.2.0",
"terser": "^5.3.8",
"ts-jest": "^26.4.3",
"typescript": "4.1.2"
"typescript": "4.3.5"
}
}
17 changes: 16 additions & 1 deletion src/animation/universalTransition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,21 @@ function animateElementStyles(el: Element, dataIndex: number, seriesModel: Serie
}


function isAllIdSame(oldDiffItems: DiffItem[], newDiffItems: DiffItem[]) {
const len = oldDiffItems.length;
if (len !== newDiffItems.length) {
return false;
}
for (let i = 0; i < len; i++) {
const oldItem = oldDiffItems[i];
const newItem = newDiffItems[i];
if (oldItem.data.getId(oldItem.dataIndex) !== newItem.data.getId(newItem.dataIndex)) {
return false;
}
}
return true;
}

function transitionBetween(
oldList: TransitionSeries[],
newList: TransitionSeries[],
Expand Down Expand Up @@ -220,7 +235,7 @@ function transitionBetween(
// Use id if it's very likely to be an one to one animation
// It's more robust than groupId
// TODO Check if key dimension is specified.
const useId = oldDiffItems.length === newDiffItems.length;
const useId = isAllIdSame(oldDiffItems, newDiffItems);
const isElementStillInChart: Dictionary<boolean> = {};

if (!useId) {
Expand Down
7 changes: 6 additions & 1 deletion src/chart/bar/BarSeries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,15 @@ import { inheritDefaultOption } from '../../util/component';
import List from '../../data/List';
import { BrushCommonSelectorsForSeries } from '../../component/brush/selector';

export type PolarBarLabelPosition = SeriesLabelOption['position']
| 'start' | 'insideStart' | 'middle' | 'end' | 'insideEnd';

export type BarSeriesLabelOption = Omit<SeriesLabelOption, 'position'>
& {position: PolarBarLabelPosition | 'outside'};

export interface BarStateOption {
itemStyle?: BarItemStyleOption
label?: SeriesLabelOption
label?: BarSeriesLabelOption
}

export interface BarItemStyleOption extends ItemStyleOption {
Expand Down
94 changes: 67 additions & 27 deletions src/chart/bar/BarView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import Path, {PathProps} from 'zrender/src/graphic/Path';
import Group from 'zrender/src/graphic/Group';
import {extend, defaults, each, map} from 'zrender/src/core/util';
import {BuiltinTextPosition} from 'zrender/src/core/types';
import {
Rect,
Sector,
Expand All @@ -46,7 +47,7 @@ import {
OrdinalNumber,
ParsedValue
} from '../../util/types';
import BarSeriesModel, {BarSeriesOption, BarDataItemOption} from './BarSeries';
import BarSeriesModel, {BarSeriesOption, BarDataItemOption, PolarBarLabelPosition} from './BarSeries';
import type Axis2D from '../../coord/cartesian/Axis2D';
import type Cartesian2D from '../../coord/cartesian/Cartesian2D';
import type Polar from '../../coord/polar/Polar';
Expand All @@ -60,6 +61,7 @@ import CartesianAxisModel from '../../coord/cartesian/AxisModel';
import {LayoutRect} from '../../util/layout';
import {EventCallback} from 'zrender/src/core/Eventful';
import { warn } from '../../util/log';
import {createSectorCalculateTextPosition, SectorTextPosition, setSectorTextRotation} from '../../label/sectorLabel';
import { saveOldStyle } from '../../animation/basicTrasition';

const _eventPos = [0, 0];
Expand Down Expand Up @@ -759,6 +761,9 @@ const elementCreator: {

sector.name = 'item';

const positionMap = createPolarPositionMapping(isRadial);
sector.calculateTextPosition = createSectorCalculateTextPosition<PolarBarLabelPosition>(positionMap);

// Animation
if (animationModel) {
const sectorShape = sector.shape;
Expand Down Expand Up @@ -911,13 +916,31 @@ function isZeroOnPolar(layout: SectorLayout) {
&& layout.startAngle === layout.endAngle;
}

function createPolarPositionMapping(isRadial: boolean)
: (position: PolarBarLabelPosition) => SectorTextPosition {
return ((isRadial: boolean) => {
const arcOrAngle = isRadial ? 'Arc' : 'Angle';
return (position: PolarBarLabelPosition) => {
switch (position) {
case 'start':
case 'insideStart':
case 'end':
case 'insideEnd':
return position + arcOrAngle as SectorTextPosition;
default:
return position;
}
};
})(isRadial);
}

function updateStyle(
el: BarPossiblePath,
data: List, dataIndex: number,
itemModel: Model<BarDataItemOption>,
layout: RectLayout | SectorLayout,
seriesModel: BarSeriesModel,
isHorizontal: boolean,
isHorizontalOrRadial: boolean,
isPolar: boolean
) {
const style = data.getItemVisual(dataIndex, 'style');
Expand All @@ -931,34 +954,51 @@ function updateStyle(
const cursorStyle = itemModel.getShallow('cursor');
cursorStyle && (el as Path).attr('cursor', cursorStyle);

if (!isPolar) {
const labelPositionOutside = isHorizontal
? ((layout as RectLayout).height > 0 ? 'bottom' as const : 'top' as const)
: ((layout as RectLayout).width > 0 ? 'left' as const : 'right' as const);
const labelStatesModels = getLabelStatesModels(itemModel);

setLabelStyle(
el, labelStatesModels,
{
labelFetcher: seriesModel,
labelDataIndex: dataIndex,
defaultText: getDefaultLabel(seriesModel.getData(), dataIndex),
inheritColor: style.fill as ColorString,
defaultOpacity: style.opacity,
defaultOutsidePosition: labelPositionOutside
}
);

const label = el.getTextContent();

setLabelValueAnimation(
label,
labelStatesModels,
seriesModel.getRawValue(dataIndex) as ParsedValue,
(value: number) => getDefaultInterpolatedLabel(data, value)
const labelPositionOutside = isPolar
? (isHorizontalOrRadial
? ((layout as SectorLayout).r >= (layout as SectorLayout).r0 ? 'endArc' as const : 'startArc' as const)
: ((layout as SectorLayout).endAngle >= (layout as SectorLayout).startAngle
? 'endAngle' as const
: 'startAngle' as const
)
)
: (isHorizontalOrRadial
? ((layout as RectLayout).height >= 0 ? 'bottom' as const : 'top' as const)
: ((layout as RectLayout).width >= 0 ? 'right' as const : 'left' as const));

const labelStatesModels = getLabelStatesModels(itemModel);

setLabelStyle(
el, labelStatesModels,
{
labelFetcher: seriesModel,
labelDataIndex: dataIndex,
defaultText: getDefaultLabel(seriesModel.getData(), dataIndex),
inheritColor: style.fill as ColorString,
defaultOpacity: style.opacity,
defaultOutsidePosition: labelPositionOutside as BuiltinTextPosition
}
);

if (isPolar) {
const position = itemModel.get(['label', 'position']);
el.textConfig.inside = position === 'middle' ? true : null;
setSectorTextRotation(
el as Sector,
position === 'outside' ? labelPositionOutside : position,
createPolarPositionMapping(isHorizontalOrRadial),
itemModel.get(['label', 'rotate'])
);
}

const label = el.getTextContent();
setLabelValueAnimation(
label,
labelStatesModels,
seriesModel.getRawValue(dataIndex) as ParsedValue,
(value: number) => getDefaultInterpolatedLabel(data, value)
);

const emphasisModel = itemModel.getModel(['emphasis']);
enableHoverEmphasis(el, emphasisModel.get('focus'), emphasisModel.get('blurScope'));
setStatesStylesFromModel(el, itemModel);
Expand Down
2 changes: 1 addition & 1 deletion src/chart/bar/BaseBarSeries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class BaseBarSeriesModel<Opts extends BaseBarSeriesOption<unknown> = BaseBarSeri

getMarkerPosition(value: ScaleDataValue[]) {
const coordSys = this.coordinateSystem;
if (coordSys) {
if (coordSys && coordSys.clampData) {
// PENDING if clamp ?
const pt = coordSys.dataToPoint(coordSys.clampData(value));
const data = this.getData();
Expand Down
13 changes: 3 additions & 10 deletions src/chart/bar/PictorialBarView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import * as graphic from '../../util/graphic';
import {
enableHoverEmphasis
} from '../../util/states';
import {createSymbol} from '../../util/symbol';
import {createSymbol, normalizeSymbolOffset} from '../../util/symbol';
import {parsePercent, isNumeric} from '../../util/number';
import ChartView from '../../view/Chart';
import PictorialBarSeriesModel, {PictorialBarDataItemOption} from './PictorialBarSeries';
Expand All @@ -41,7 +41,6 @@ import { setLabelStyle, getLabelStatesModels } from '../../label/labelStyle';
import ZRImage from 'zrender/src/graphic/Image';
import { getECData } from '../../util/innerStore';


const BAR_BORDER_WIDTH_QUERY = ['itemStyle', 'borderWidth'] as const;

// index: +isHorizontal
Expand Down Expand Up @@ -280,13 +279,7 @@ function getSymbolMeta(
prepareLineWidth(itemModel, symbolMeta.symbolScale, rotation, opt, symbolMeta);

const symbolSize = symbolMeta.symbolSize;
let symbolOffset = itemModel.get('symbolOffset');
if (zrUtil.isArray(symbolOffset)) {
symbolOffset = [
parsePercent(symbolOffset[0], symbolSize[0]),
parsePercent(symbolOffset[1], symbolSize[1])
];
}
const symbolOffset = normalizeSymbolOffset(itemModel.get('symbolOffset'), symbolSize);

prepareLayoutInfo(
itemModel, symbolSize, layout, symbolRepeat, symbolClip, symbolOffset as number[],
Expand Down Expand Up @@ -946,4 +939,4 @@ function toIntTimes(times: number) {
: Math.ceil(times);
}

export default PictorialBarView;
export default PictorialBarView;
Loading

0 comments on commit e7fab2a

Please sign in to comment.