Skip to content
Open
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
10 changes: 10 additions & 0 deletions packages/devextreme/js/__internal/viz/core/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,16 @@ export function normalizeArcParams(x, y, innerRadius, outerRadius, startAngle, e
];
}

interface VisualRangeObject<T> {
startValue: T;
endValue: T;
}

export function convertVisualRangeObject<T>(visualRange: VisualRangeObject<T>): T[];
export function convertVisualRangeObject<T>(
visualRange: VisualRangeObject<T>,
convertToVisualRange: boolean,
): T[] | VisualRangeObject<T>;
export function convertVisualRangeObject(visualRange, convertToVisualRange?) {
if (convertToVisualRange) {
return visualRange;
Expand Down
34 changes: 23 additions & 11 deletions packages/devextreme/js/__internal/viz/gauges/base_gauge.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/no-unsafe-declaration-merging */
import formatHelper from '@ts/core/format_helper';
import { noop } from '@ts/core/utils/common';
import { paintedColor } from '@ts/core/utils/css_variables';
Expand Down Expand Up @@ -32,18 +31,31 @@ export interface GaugeFormatOptions {
customizeText?: (this: ThemeValue, formatObject: ThemeValue) => ThemeValue;
}

export interface BaseGauge extends TooltipPluginMembers {
_change_TITLE: () => void;
_factory: ThemeValue;
_title: ThemeValue;
_updateExtraElements: () => void;
export abstract class BaseGauge extends BaseWidget {
declare _tooltip: TooltipPluginMembers['_tooltip'];

_DEBUG_change_title?: () => void;
_DEBUG_rootRect?: number[];
_debug_rendered?: () => void;
}
declare _disposeTooltip: TooltipPluginMembers['_disposeTooltip'];

declare _initTooltip: TooltipPluginMembers['_initTooltip'];

declare _setTooltipOptions: TooltipPluginMembers['_setTooltipOptions'];

declare _setTooltipRendererOptions: TooltipPluginMembers['_setTooltipRendererOptions'];

declare _change_TITLE: () => void;

declare _factory: ThemeValue;

declare _title: ThemeValue;

declare _updateExtraElements: () => void;

declare _DEBUG_change_title?: () => void;

declare _DEBUG_rootRect?: number[];

declare _debug_rendered?: () => void;

export abstract class BaseGauge extends BaseWidget {
_valueChangingLocker!: number;

_translator;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ export abstract class BaseIndicator extends BaseElement {

visible?: boolean;

declare index?: number;

_init(): void {
this._rootElement = this._createRoot()
.linkOn(this._owner, { name: 'value-indicator', after: 'core' });
Expand Down Expand Up @@ -251,6 +253,8 @@ export abstract class BaseIndicator extends BaseElement {
abstract _clear(): void;

abstract _move(): void;

abstract measure(layout: unknown): IndicatorMeasure;
}

// The following is from baseMarker.js
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ interface Segment {
}

export interface RangeInfo extends Segment {
color?: ThemeValue;
color?: string;
className?: string;
classIndex?: number;
startWidth?: number;
Expand Down Expand Up @@ -222,8 +222,8 @@ abstract class BaseRangeContainer extends BaseElement {
abstract _createRange(range: RangeInfo, layout: ThemeValue): ThemeValue;

// S170193
getColorForValue(value: number): ThemeValue {
let color: ThemeValue = null;
getColorForValue(value: number): string | null | undefined {
let color: string | null | undefined = null;
each(this._ranges, (_, range: RangeInfo) => {
const inRange = (range.start <= value && value <= range.end)
|| (range.start >= value && value >= range.end);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,7 @@ class CircularGauge extends dxGauge {
return this._area.radius;
}

_getTicksOrientation(scaleOptions: ThemeValue): string {
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
_getTicksOrientation(scaleOptions: { orientation: string }): string {
return scaleOptions.orientation;
}

Expand Down
67 changes: 48 additions & 19 deletions packages/devextreme/js/__internal/viz/gauges/common.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* eslint-disable max-classes-per-file */
/* eslint-disable @typescript-eslint/no-unsafe-return */
/* eslint-disable @typescript-eslint/no-use-before-define */

import { noop } from '@ts/core/utils/common';
Expand All @@ -10,6 +9,8 @@ import type { ThemeValue } from '@ts/viz/core/base_theme_manager';
import { setupWidgetPrototype } from '@ts/viz/core/helpers';
import { map, normalizeEnum } from '@ts/viz/core/utils';
import { BaseGauge, compareArrays } from '@ts/viz/gauges/base_gauge';
import type { BaseIndicator } from '@ts/viz/gauges/base_indicators';
import type BaseRangeContainer from '@ts/viz/gauges/base_range_container';

const SHIFT_ANGLE = 90;

Expand Down Expand Up @@ -38,14 +39,22 @@ export interface TicksCoefficients {
outer: number;
}

type GaugeElement = BaseRangeContainer | BaseIndicator | ValueIndicatorsSet;

type HardModeGauge = Gauge & { _valueIndicators: BaseIndicator[] | null };

type HardModeIndicator = BaseIndicator & { index: number };

function processValue(value: ThemeValue, fallbackValue: ThemeValue): ThemeValue {
if (value === null) {
return value;
}
return isFinite(value) ? Number(value) : fallbackValue;
}

function parseArrayOfNumbers(arg: ThemeValue): ThemeValue[] | null {
function parseArrayOfNumbers(
arg: unknown[] | number | string | null | undefined,
): unknown[] | null {
if (Array.isArray(arg)) {
return arg;
}
Expand All @@ -64,7 +73,7 @@ abstract class Gauge extends BaseGauge {

__subvalues!: ThemeValue[] | null;

_rangeContainer;
_rangeContainer!: BaseRangeContainer;

_subvalueIndicatorContainer;

Expand All @@ -74,9 +83,9 @@ abstract class Gauge extends BaseGauge {

_scale;

_valueIndicator;
_valueIndicator?: BaseIndicator | null;

_subvalueIndicatorsSet;
_subvalueIndicatorsSet?: ValueIndicatorsSet | null;

_baseValue!: number;

Expand Down Expand Up @@ -132,6 +141,7 @@ abstract class Gauge extends BaseGauge {
this._disposeValueIndicators();
this._subvalueIndicatorContainer.linkOff();

// @ts-expect-error dispose() drops the reference
this._rangeContainer = null;
this._labelsAxesGroup = null;
this._scaleGroup = null;
Expand Down Expand Up @@ -202,7 +212,7 @@ abstract class Gauge extends BaseGauge {
this._renderScale(scaleOptions);
this._subvalueIndicatorContainer.linkAppend();

const elements: ThemeValue[] = map(
const elements: GaugeElement[] = map(
[this._rangeContainer].concat(this._prepareValueIndicators()),
(element) => (element && element.enabled ? element : null),
);
Expand Down Expand Up @@ -234,11 +244,11 @@ abstract class Gauge extends BaseGauge {
scaleOptions.numberMultipliers = DEFAULT_NUMBER_MULTIPLIERS;
scaleOptions.tickOrientation = this._getTicksOrientation(scaleOptions);
if (scaleOptions.label.useRangeColors) {
const getColorForValue = (value: number): ThemeValue => this._rangeContainer
const getColorForValue = (value: number): string | null | undefined => this._rangeContainer
.getColorForValue(value);
scaleOptions.label.customizeColor = function customizeColor(
this: { value: number },
): ThemeValue {
): string | null | undefined {
return getColorForValue(this.value);
};
}
Expand Down Expand Up @@ -438,15 +448,33 @@ abstract class Gauge extends BaseGauge {
this._changeSubvalues(this.option(OPTION_SUBVALUES));
}

_createIndicator(
type: string,
owner: ThemeValue,
className?: string,
trackerType?: string,
trackerIndex?: number,
strict?: false,
): BaseIndicator;

_createIndicator(
type: string,
owner: ThemeValue,
className: string,
trackerType: string,
trackerIndex: number,
strict: boolean,
): BaseIndicator | null;

_createIndicator(
type: string,
owner: ThemeValue,
className?: string,
trackerType?: string,
trackerIndex?: number,
strict?: boolean,
): ThemeValue {
const indicator = this._factory.createIndicator({
): BaseIndicator | null {
const indicator: BaseIndicator | null = this._factory.createIndicator({
renderer: this._renderer,
translator: this._translator,
owner,
Expand Down Expand Up @@ -550,12 +578,12 @@ function selectHardMode(that: ThemeValue): void {
}

function updateActiveElementsHardMode(this: ThemeValue): void {
this._valueIndicators.forEach((valueIndicator) => {
this._valueIndicators.forEach((valueIndicator: HardModeIndicator) => {
valueIndicator.value(this._indicatorValues[valueIndicator.index], this._noAnimation);
});
}

function prepareValueIndicatorsHardMode(this: ThemeValue): ThemeValue[] {
function prepareValueIndicatorsHardMode(this: HardModeGauge): ThemeValue[] {
const valueIndicators = this._valueIndicators || [];
const userOptions = this.option('valueIndicators');
const optionList: ThemeValue[] = [];
Expand All @@ -568,7 +596,7 @@ function prepareValueIndicatorsHardMode(this: ThemeValue): ThemeValue[] {
}
const newValueIndicators: ThemeValue[] = [];
optionList.forEach((userSettings, index) => {
let valueIndicator = valueIndicators[index];
let valueIndicator: BaseIndicator | null = valueIndicators[index];
if (!userSettings) {
if (valueIndicator) {
valueIndicator.dispose();
Expand All @@ -594,12 +622,12 @@ function prepareValueIndicatorsHardMode(this: ThemeValue): ThemeValue[] {
}

function disposeValueIndicatorsHardMode(this: ThemeValue): void {
this._valueIndicators.forEach((valueIndicator) => valueIndicator.dispose());
this._valueIndicators.forEach((valueIndicator: BaseIndicator) => valueIndicator.dispose());
this._valueIndicators = null;
}

function cleanValueIndicatorsHardMode(this: ThemeValue): void {
this._valueIndicators.forEach((valueIndicator) => valueIndicator.clean());
this._valueIndicators.forEach((valueIndicator: BaseIndicator) => valueIndicator.clean());
}

function indicatorValueHardMode(this: ThemeValue, index: number, value?: ThemeValue): ThemeValue {
Expand All @@ -626,18 +654,18 @@ function accessPointerValue(
}

interface ValueIndicatorsSetParameters {
createIndicator: (type: string, index?: number) => ThemeValue;
createIndicator: (type: string, index?: number) => BaseIndicator;
createPalette: (palette: ThemeValue) => ThemeValue;
}

class ValueIndicatorsSet {
_parameters: ValueIndicatorsSetParameters;

_indicators: ThemeValue[];
_indicators: BaseIndicator[];

_options: ThemeValue;

_sample: ThemeValue;
_sample!: BaseIndicator;

_palette: ThemeValue;

Expand All @@ -647,7 +675,7 @@ class ValueIndicatorsSet {

type?: string;

enabled?: boolean;
enabled?: boolean | null;

constructor(parameters: ValueIndicatorsSetParameters) {
this._parameters = parameters;
Expand All @@ -669,6 +697,7 @@ class ValueIndicatorsSet {
this._indicators.forEach((indicator) => indicator.clean());
this._palette = null;
this._options = null;
// @ts-expect-error clean() drops the reference
this._sample = null;
return this;
}
Expand Down
12 changes: 8 additions & 4 deletions packages/devextreme/js/__internal/viz/gauges/linear_gauge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,13 @@ class LinearGauge extends dxGauge {

_area!: LinearArea;

_getTicksOrientation(scaleOptions: ThemeValue): string {
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
declare _rangeContainer: LinearRangeContainer;

_getTicksOrientation(scaleOptions: {
isHorizontal: boolean;
verticalOrientation: string;
horizontalOrientation: string;
}): string {
return scaleOptions.isHorizontal
? scaleOptions.verticalOrientation
: scaleOptions.horizontalOrientation;
Expand All @@ -86,8 +91,7 @@ class LinearGauge extends dxGauge {
}

_getInvertedState(): boolean {
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return !this._area.vertical && this.option('rtlEnabled');
return !this._area.vertical && (this.option('rtlEnabled') as boolean);
}

_prepareScaleSettings(): ThemeValue {
Expand Down
22 changes: 15 additions & 7 deletions packages/devextreme/js/__internal/viz/range_selector/common.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* eslint-disable func-names */
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */

import devices from '@ts/core/devices';
import { browser } from '@ts/core/utils/browser';
Expand All @@ -24,13 +23,22 @@ export const consts = {
pointerSize: POINTER_SIZE,
};

interface FormatObject {
value: unknown;
valueText: string;
}

interface ValueFormatOptions {
customizeText?: (this: FormatObject, formatObject: FormatObject) => unknown;
}

export const formatValue = function (
value,
formatOptions,
tickIntervalsInfo?,
valueType?,
type?,
logarithmBase?,
value: unknown,
formatOptions: ValueFormatOptions,
tickIntervalsInfo?: { ticks: unknown[]; tickInterval?: unknown },
valueType?: string,
type?: string,
logarithmBase?: number,
): string {
const formatObject = {
value,
Expand Down
Loading
Loading