This is an automated email from the ASF dual-hosted git repository. sushuang pushed a commit to branch fix/useUTC in repository https://gitbox.apache.org/repos/asf/incubator-echarts.git
commit a3e658c6e6c437607bbd964ee625b51f7c0b843f Author: 100pah <sushuang0...@gmail.com> AuthorDate: Mon Nov 9 03:09:25 2020 +0800 fix: (1) tooltip should support useUTC by default (2) make the param useUTC/isUTC mandatory rather than optional. (3) change the order of the param isUTC and lang of time.format because isUTC is used more. --- src/component/tooltip/TooltipView.ts | 5 +++-- src/component/tooltip/tooltipMarkup.ts | 14 +++++++----- src/scale/Time.ts | 6 ++--- src/util/format.ts | 7 +++--- src/util/time.ts | 40 ++++++++++++++++++---------------- test/timeZone.html | 18 +++++++-------- 6 files changed, 48 insertions(+), 42 deletions(-) diff --git a/src/component/tooltip/TooltipView.ts b/src/component/tooltip/TooltipView.ts index 58669ec..61739d7 100644 --- a/src/component/tooltip/TooltipView.ts +++ b/src/component/tooltip/TooltipView.ts @@ -541,7 +541,7 @@ class TooltipView extends ComponentView { const orderMode = singleTooltipModel.get('order'); const builtMarkupText = buildTooltipMarkup( - articleMarkup, markupStyleCreator, renderMode, orderMode + articleMarkup, markupStyleCreator, renderMode, orderMode, ecModel.get('useUTC') ); builtMarkupText && markupTextArrLegacy.unshift(builtMarkupText); const blockBreak = renderMode === 'richText' ? '\n\n' : '<br/>'; @@ -619,7 +619,8 @@ class TooltipView extends ComponentView { seriesTooltipResult.markupFragment, markupStyleCreator, renderMode, - orderMode + orderMode, + ecModel.get('useUTC') ) : seriesTooltipResult.markupText; diff --git a/src/component/tooltip/tooltipMarkup.ts b/src/component/tooltip/tooltipMarkup.ts index 40f78c4..db1910c 100644 --- a/src/component/tooltip/tooltipMarkup.ts +++ b/src/component/tooltip/tooltipMarkup.ts @@ -212,7 +212,7 @@ const builderMap: { [key in TooltipMarkupBlockFragment['type']]: TooltipMarkupFr return subMarkupText; } - const displayableHeader = makeValueReadable(fragment.header, 'ordinal'); + const displayableHeader = makeValueReadable(fragment.header, 'ordinal', ctx.useUTC); if (ctx.renderMode === 'richText') { return wrapInlineNameRichText(ctx, displayableHeader) + gaps.richText + subMarkupText; @@ -247,6 +247,7 @@ const builderMap: { [key in TooltipMarkupBlockFragment['type']]: TooltipMarkupFr const noMarker = !fragment.markerType; const name = fragment.name; const value = fragment.value; + const useUTC = ctx.useUTC; if (noName && noValue) { return; @@ -261,16 +262,16 @@ const builderMap: { [key in TooltipMarkupBlockFragment['type']]: TooltipMarkupFr ); const readableName = noName ? '' - : makeValueReadable(name, 'ordinal'); + : makeValueReadable(name, 'ordinal', useUTC); const valueTypeOption = fragment.valueType; const readableValueList = noValue ? [] : (isArray(value) ? map(value, (val, idx) => makeValueReadable( - val, isArray(valueTypeOption) ? valueTypeOption[idx] : valueTypeOption + val, isArray(valueTypeOption) ? valueTypeOption[idx] : valueTypeOption, useUTC )) : [makeValueReadable( - value, isArray(valueTypeOption) ? valueTypeOption[0] : valueTypeOption + value, isArray(valueTypeOption) ? valueTypeOption[0] : valueTypeOption, useUTC )] ); const valueAlignRight = !noMarker || !noName; @@ -346,6 +347,7 @@ function buildSubBlocks( } interface TooltipMarkupBuildContext { + useUTC: boolean; renderMode: TooltipRenderMode; orderMode: TooltipOrderMode; markupStyleCreator: TooltipMarkupStyleCreator; @@ -358,7 +360,8 @@ export function buildTooltipMarkup( fragment: TooltipMarkupBlockFragment, markupStyleCreator: TooltipMarkupStyleCreator, renderMode: TooltipRenderMode, - orderMode: TooltipOrderMode + orderMode: TooltipOrderMode, + useUTC: boolean ): MarkupText { if (!fragment) { return; @@ -367,6 +370,7 @@ export function buildTooltipMarkup( const builder = getBuilder(fragment); builder.planLayout(fragment); const ctx: TooltipMarkupBuildContext = { + useUTC: useUTC, renderMode: renderMode, orderMode: orderMode, markupStyleCreator: markupStyleCreator diff --git a/src/scale/Time.ts b/src/scale/Time.ts index a5157b4..c195727 100644 --- a/src/scale/Time.ts +++ b/src/scale/Time.ts @@ -127,8 +127,8 @@ class TimeScale extends IntervalScale<TimeScaleSetting> { fullLeveledFormatter[ getDefaultFormatPrecisionOfInterval(getPrimaryTimeUnit(this._minLevelUnit)) ] || fullLeveledFormatter.second, - this.getSetting('locale'), - useUTC + useUTC, + this.getSetting('locale') ); } @@ -337,7 +337,7 @@ function isUnitValueSame( // millisecond: millisecondsGetterName(true) // }; -// function moveTick(date: Date, unitName: TimeUnit, step: number, isUTC?: boolean) { +// function moveTick(date: Date, unitName: TimeUnit, step: number, isUTC: boolean) { // step = step || 1; // switch (getPrimaryTimeUnit(unitName)) { // case 'year': diff --git a/src/util/format.ts b/src/util/format.ts index 1f59a74..904b645 100644 --- a/src/util/format.ts +++ b/src/util/format.ts @@ -79,7 +79,8 @@ export function encodeHTML(source: string): string { */ export function makeValueReadable( value: unknown, - valueType: DimensionType + valueType: DimensionType, + useUTC: boolean ): string { const USER_READABLE_DEFUALT_TIME_PATTERN = 'yyyy-MM-dd hh:mm:ss'; @@ -95,7 +96,7 @@ export function makeValueReadable( if (isTypeTime || isValueDate) { const date = isTypeTime ? parseDate(value) : value; if (!isNaN(+date)) { - return timeFormat(date, USER_READABLE_DEFUALT_TIME_PATTERN); + return timeFormat(date, USER_READABLE_DEFUALT_TIME_PATTERN, useUTC); } else if (isValueDate) { return '-'; @@ -273,7 +274,7 @@ export function getTooltipMarker(inOpt: ColorString | GetTooltipMarkerOpt, extra * and `module:echarts/util/number#parseDate`. * @inner */ -export function formatTime(tpl: string, value: unknown, isUTC?: boolean) { +export function formatTime(tpl: string, value: unknown, isUTC: boolean) { if (__DEV__) { deprecateReplaceLog('echarts.format.formatTime', 'echarts.time.format'); } diff --git a/src/util/time.ts b/src/util/time.ts index 712e396..4075026 100644 --- a/src/util/time.ts +++ b/src/util/time.ts @@ -106,7 +106,9 @@ export function getDefaultFormatPrecisionOfInterval(timeUnit: PrimaryTimeUnit): } export function format( - time: unknown, template: string, lang?: string | Model<LocaleOption>, isUTC?: boolean + // Note: The result based on `isUTC` are totally different, which can not be just simply + // substituted by the result without `isUTC`. So we make the param `isUTC` mandatory. + time: unknown, template: string, isUTC: boolean, lang?: string | Model<LocaleOption> ): string { const date = numberUtil.parseDate(time); const y = date[fullYearGetterName(isUTC)](); @@ -159,7 +161,7 @@ export function leveledFormat( idx: number, formatter: TimeAxisLabelFormatterOption, lang: string | Model<LocaleOption>, - isUTC?: boolean + isUTC: boolean ) { let template = null; if (typeof formatter === 'string') { @@ -212,7 +214,7 @@ export function leveledFormat( } } - return format(new Date(tick.value), template, lang, isUTC); + return format(new Date(tick.value), template, isUTC, lang); } export function getUnitFromValue( @@ -259,8 +261,8 @@ export function getUnitFromValue( export function getUnitValue( value: number | Date, - unit?: TimeUnit, - isUTC?: boolean + unit: TimeUnit, + isUTC: boolean ) : number { const date = typeof value === 'number' ? numberUtil.parseDate(value) @@ -291,58 +293,58 @@ export function getUnitValue( } } -export function fullYearGetterName(isUTC?: boolean) { +export function fullYearGetterName(isUTC: boolean) { return isUTC ? 'getUTCFullYear' : 'getFullYear'; } -export function monthGetterName(isUTC?: boolean) { +export function monthGetterName(isUTC: boolean) { return isUTC ? 'getUTCMonth' : 'getMonth'; } -export function dateGetterName(isUTC?: boolean) { +export function dateGetterName(isUTC: boolean) { return isUTC ? 'getUTCDate' : 'getDate'; } -export function hoursGetterName(isUTC?: boolean) { +export function hoursGetterName(isUTC: boolean) { return isUTC ? 'getUTCHours' : 'getHours'; } -export function minutesGetterName(isUTC?: boolean) { +export function minutesGetterName(isUTC: boolean) { return isUTC ? 'getUTCMinutes' : 'getMinutes'; } -export function secondsGetterName(isUTC?: boolean) { +export function secondsGetterName(isUTC: boolean) { return isUTC ? 'getUTCSeconds' : 'getSeconds'; } -export function millisecondsGetterName(isUTC?: boolean) { +export function millisecondsGetterName(isUTC: boolean) { return isUTC ? 'getUTCSeconds' : 'getSeconds'; } -export function fullYearSetterName(isUTC?: boolean) { +export function fullYearSetterName(isUTC: boolean) { return isUTC ? 'setUTCFullYear' : 'setFullYear'; } -export function monthSetterName(isUTC?: boolean) { +export function monthSetterName(isUTC: boolean) { return isUTC ? 'setUTCMonth' : 'setMonth'; } -export function dateSetterName(isUTC?: boolean) { +export function dateSetterName(isUTC: boolean) { return isUTC ? 'setUTCDate' : 'setDate'; } -export function hoursSetterName(isUTC?: boolean) { +export function hoursSetterName(isUTC: boolean) { return isUTC ? 'setUTCHours' : 'setHours'; } -export function minutesSetterName(isUTC?: boolean) { +export function minutesSetterName(isUTC: boolean) { return isUTC ? 'setUTCMinutes' : 'setMinutes'; } -export function secondsSetterName(isUTC?: boolean) { +export function secondsSetterName(isUTC: boolean) { return isUTC ? 'setUTCSeconds' : 'setSeconds'; } -export function millisecondsSetterName(isUTC?: boolean) { +export function millisecondsSetterName(isUTC: boolean) { return isUTC ? 'setUTCSeconds' : 'setSeconds'; } diff --git a/test/timeZone.html b/test/timeZone.html index 3711a92..7ba375e 100644 --- a/test/timeZone.html +++ b/test/timeZone.html @@ -91,7 +91,7 @@ under the License. tooltip: { trigger: 'axis', // test in Safari (NaN-NaN-NaN NaN:NaN:NaN) - formatter: '{yyyy}-{MM}-{dd} {HH}:{mm}:{ss}' + // formatter: '{yyyy}-{MM}-{dd} {HH}:{mm}:{ss}' }, xAxis: [{ type: 'time', @@ -121,15 +121,13 @@ under the License. smooth: true, data: data, label: { - normal: { - show: true, - formatter: function (params) { - return echarts.time.format( - params.value[0], - '{yyyy}-{MM}-{dd} {HH}:{mm}:{ss}', - useUTC - ); - } + show: true, + formatter: function (params) { + return echarts.time.format( + params.value[0], + '{yyyy}-{MM}-{dd} {HH}:{mm}:{ss}', + useUTC + ); } } }] --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@echarts.apache.org For additional commands, e-mail: commits-h...@echarts.apache.org