Skip to content

Commit a18d636

Browse files
committed
chore: merge master branch
2 parents 4385bc6 + fc6656f commit a18d636

File tree

9 files changed

+185
-38
lines changed

9 files changed

+185
-38
lines changed

src/component/dataZoom/SliderZoomView.ts

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@
1717
* under the License.
1818
*/
1919

20-
import {bind, each, isFunction, isString, indexOf} from 'zrender/src/core/util';
20+
import { bind, each, isFunction, isString, indexOf } from 'zrender/src/core/util';
2121
import * as eventTool from 'zrender/src/core/event';
2222
import * as graphic from '../../util/graphic';
2323
import * as throttle from '../../util/throttle';
2424
import DataZoomView from './DataZoomView';
25-
import {linearMap, asc, parsePercent} from '../../util/number';
25+
import { linearMap, asc, parsePercent } from '../../util/number';
2626
import * as layout from '../../util/layout';
2727
import sliderMove from '../helper/sliderMove';
2828
import GlobalModel from '../../model/Global';
@@ -41,7 +41,7 @@ import { createSymbol, symbolBuildProxies } from '../../util/symbol';
4141
import { deprecateLog } from '../../util/log';
4242
import { PointLike } from 'zrender/src/core/Point';
4343
import Displayable from 'zrender/src/graphic/Displayable';
44-
import {createTextStyle} from '../../label/labelStyle';
44+
import { createTextStyle } from '../../label/labelStyle';
4545
import SeriesData from '../../data/SeriesData';
4646

4747
const Rect = graphic.Rect;
@@ -227,7 +227,7 @@ class SliderZoomView extends DataZoomView {
227227
// If some of x/y/width/height are not specified,
228228
// auto-adapt according to target grid.
229229
const coordRect = this._findCoordRect();
230-
const ecSize = {width: api.getWidth(), height: api.getHeight()};
230+
const ecSize = { width: api.getWidth(), height: api.getHeight() };
231231
// Default align by coordinate system rect.
232232
const positionInfo = this._orient === HORIZONTAL
233233
? {
@@ -261,7 +261,7 @@ class SliderZoomView extends DataZoomView {
261261
ecSize
262262
);
263263

264-
this._location = {x: layoutRect.x, y: layoutRect.y};
264+
this._location = { x: layoutRect.x, y: layoutRect.y };
265265
this._size = [layoutRect.width, layoutRect.height];
266266
this._orient === VERTICAL && this._size.reverse();
267267
}
@@ -375,6 +375,7 @@ class SliderZoomView extends DataZoomView {
375375
data !== this._shadowData || otherDim !== this._shadowDim
376376
|| size[0] !== oldSize[0] || size[1] !== oldSize[1]
377377
) {
378+
const thisDataExtent = data.getDataExtent(info.thisDim);
378379
let otherDataExtent = data.getDataExtent(otherDim);
379380
// Nice extent.
380381
const otherOffset = (otherDataExtent[1] - otherDataExtent[0]) * 0.3;
@@ -388,26 +389,35 @@ class SliderZoomView extends DataZoomView {
388389
const areaPoints = [[size[0], 0], [0, 0]];
389390
const linePoints: number[][] = [];
390391
const step = thisShadowExtent[1] / (data.count() - 1);
391-
let thisCoord = 0;
392+
const normalizationConstant = size[0] / (thisDataExtent[1] - thisDataExtent[0]);
393+
const isTimeAxis = info.thisAxis.type === 'time';
394+
let thisCoord = -step;
392395

393396
// Optimize for large data shadow
394397
const stride = Math.round(data.count() / size[0]);
395398
let lastIsEmpty: boolean;
396-
data.each([otherDim], function (value: ParsedValue, index) {
399+
400+
data.each([info.thisDim, otherDim], function (thisValue: ParsedValue, otherValue: ParsedValue, index) {
397401
if (stride > 0 && (index % stride)) {
398-
thisCoord += step;
402+
if (!isTimeAxis) {
403+
thisCoord += step;
404+
}
399405
return;
400406
}
401407

408+
thisCoord = isTimeAxis
409+
? (+thisValue - thisDataExtent[0]) * normalizationConstant
410+
: thisCoord + step;
411+
402412
// FIXME
403413
// Should consider axis.min/axis.max when drawing dataShadow.
404414

405415
// FIXME
406416
// 应该使用统一的空判断?还是在list里进行空判断?
407-
const isEmpty = value == null || isNaN(value as number) || value === '';
417+
const isEmpty = otherValue == null || isNaN(otherValue as number) || otherValue === '';
408418
// See #4235.
409419
const otherCoord = isEmpty
410-
? 0 : linearMap(value as number, otherDataExtent, otherShadowExtent, true);
420+
? 0 : linearMap(otherValue as number, otherDataExtent, otherShadowExtent, true);
411421

412422
// Attempt to draw data shadow precisely when there are empty value.
413423
if (isEmpty && !lastIsEmpty && index) {
@@ -422,7 +432,6 @@ class SliderZoomView extends DataZoomView {
422432
areaPoints.push([thisCoord, otherCoord]);
423433
linePoints.push([thisCoord, otherCoord]);
424434

425-
thisCoord += step;
426435
lastIsEmpty = isEmpty;
427436
});
428437

@@ -440,14 +449,14 @@ class SliderZoomView extends DataZoomView {
440449
const model = dataZoomModel.getModel(isSelectedArea ? 'selectedDataBackground' : 'dataBackground');
441450
const group = new graphic.Group();
442451
const polygon = new graphic.Polygon({
443-
shape: {points: polygonPts},
452+
shape: { points: polygonPts },
444453
segmentIgnoreThreshold: 1,
445454
style: model.getModel('areaStyle').getAreaStyle(),
446455
silent: true,
447456
z2: -20
448457
});
449458
const polyline = new graphic.Polyline({
450-
shape: {points: polylinePts},
459+
shape: { points: polylinePts },
451460
segmentIgnoreThreshold: 1,
452461
style: model.getModel('lineStyle').getLineStyle(),
453462
silent: true,
@@ -489,8 +498,8 @@ class SliderZoomView extends DataZoomView {
489498
}
490499

491500
if (showDataShadow !== true && indexOf(
492-
SHOW_DATA_SHADOW_SERIES_TYPE, seriesModel.get('type')
493-
) < 0
501+
SHOW_DATA_SHADOW_SERIES_TYPE, seriesModel.get('type')
502+
) < 0
494503
) {
495504
return;
496505
}
@@ -675,8 +684,8 @@ class SliderZoomView extends DataZoomView {
675684
});
676685

677686
actualMoveZone.on('mouseover', () => {
678-
api.enterEmphasis(moveHandle);
679-
})
687+
api.enterEmphasis(moveHandle);
688+
})
680689
.on('mouseout', () => {
681690
api.leaveEmphasis(moveHandle);
682691
});
@@ -882,8 +891,8 @@ class SliderZoomView extends DataZoomView {
882891
return isFunction(labelFormatter)
883892
? labelFormatter(value as number, valueStr)
884893
: isString(labelFormatter)
885-
? labelFormatter.replace('{value}', valueStr)
886-
: valueStr;
894+
? labelFormatter.replace('{value}', valueStr)
895+
: valueStr;
887896
}
888897

889898
/**
@@ -1103,7 +1112,7 @@ class SliderZoomView extends DataZoomView {
11031112
function getOtherDim(thisDim: 'x' | 'y' | 'radius' | 'angle' | 'single' | 'z') {
11041113
// FIXME
11051114
// 这个逻辑和getOtherAxis里一致,但是写在这里是否不好
1106-
const map = {x: 'y', y: 'x', radius: 'angle', angle: 'radius'};
1115+
const map = { x: 'y', y: 'x', radius: 'angle', angle: 'radius' };
11071116
return map[thisDim as 'x' | 'y' | 'radius' | 'angle'];
11081117
}
11091118

src/component/visualMap/ContinuousView.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,10 @@ class ContinuousView extends VisualMapView {
191191
style: createTextStyle(textStyleModel, {
192192
x: position[0],
193193
y: position[1],
194-
verticalAlign: orient === 'horizontal' ? 'middle' : align as TextVerticalAlign,
195-
align: orient === 'horizontal' ? align as TextAlign : 'center',
194+
verticalAlign: textStyleModel.get('verticalAlign')
195+
|| (orient === 'horizontal' ? 'middle' : align as TextVerticalAlign),
196+
align: textStyleModel.get('align')
197+
|| (orient === 'horizontal' ? align as TextAlign : 'center'),
196198
text
197199
})
198200
}));

src/component/visualMap/PiecewiseView.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@ class PiecewiseVisualMapView extends VisualMapView {
4444
const visualMapModel = this.visualMapModel;
4545
const textGap = visualMapModel.get('textGap');
4646
const textStyleModel = visualMapModel.textStyleModel;
47-
const textFont = textStyleModel.getFont();
48-
const textFill = textStyleModel.getTextColor();
4947
const itemAlign = this._getItemAlign();
5048
const itemSize = visualMapModel.itemSize;
5149
const viewData = this._getViewData();
@@ -74,17 +72,19 @@ class PiecewiseVisualMapView extends VisualMapView {
7472

7573
if (showLabel) {
7674
const visualState = this.visualMapModel.getValueState(representValue);
75+
const align = textStyleModel.get('align') || itemAlign as TextAlign;
7776
itemGroup.add(new graphic.Text({
78-
style: {
79-
x: itemAlign === 'right' ? -textGap : itemSize[0] + textGap,
77+
style: createTextStyle(textStyleModel, {
78+
x: align === 'right' ? -textGap : itemSize[0] + textGap,
8079
y: itemSize[1] / 2,
8180
text: piece.text,
82-
verticalAlign: 'middle',
83-
align: itemAlign as TextAlign,
84-
font: textFont,
85-
fill: textFill,
86-
opacity: visualState === 'outOfRange' ? 0.5 : 1,
87-
},
81+
verticalAlign: textStyleModel.get('verticalAlign') || 'middle',
82+
align,
83+
opacity: zrUtil.retrieve2(
84+
textStyleModel.get('opacity'),
85+
visualState === 'outOfRange' ? 0.5 : 1
86+
),
87+
}),
8888
silent
8989
}));
9090
}

src/label/labelStyle.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -395,15 +395,25 @@ function setTextStyleCommon(
395395
let richResult: TextStyleProps['rich'];
396396
if (richItemNames) {
397397
richResult = {};
398+
const richInheritPlainLabelOptionName = 'richInheritPlainLabel' as const;
399+
const richInheritPlainLabel = retrieve2(
400+
textStyleModel.get(richInheritPlainLabelOptionName),
401+
ecModel && ecModel.get(richInheritPlainLabelOptionName)
402+
);
398403
for (const name in richItemNames) {
399404
if (richItemNames.hasOwnProperty(name)) {
400405
// Cascade is supported in rich.
401-
const richTextStyle = textStyleModel.getModel(['rich', name]);
406+
const richTextStyle = textStyleModel.getModel(
407+
['rich', name],
408+
richInheritPlainLabel !== false ? textStyleModel : void 0
409+
);
402410
// In rich, never `disableBox`.
403-
// FIXME: consider `label: {formatter: '{a|xx}', color: 'blue', rich: {a: {}}}`,
411+
// consider `label: {formatter: '{a|xx}', color: 'blue', rich: {a: {}}}`,
404412
// the default color `'blue'` will not be adopted if no color declared in `rich`.
405413
// That might confuses users. So probably we should put `textStyleModel` as the
406414
// root ancestor of the `richTextStyle`. But that would be a break change.
415+
// Since v6, the rich style inherits plain label by default
416+
// but this behavior can be disabled by setting `richInheritPlainLabel` to `false`.
407417
setTokenTextStyle(
408418
richResult[name] = {}, richTextStyle, globalTextStyle, opt, isNotNormal, isAttached, false, true
409419
);

test/rich-inherit-plain-label.html

Lines changed: 119 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/richText.html

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/runTest/actions/__meta__.json

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/runTest/actions/rich-inherit-plain-label.json

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)