From e3e0f2d62d6893250372e3bf635d669052135c48 Mon Sep 17 00:00:00 2001 From: Cory Loken Date: Thu, 21 Nov 2024 15:50:09 -0500 Subject: [PATCH] Add some better types. Ignore others --- .../src/components/chart/bar.gts | 21 +++++++++++++------ ember-apache-echarts/src/helpers/css-size.ts | 6 +++--- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/ember-apache-echarts/src/components/chart/bar.gts b/ember-apache-echarts/src/components/chart/bar.gts index edeb6e88..1ab82f01 100644 --- a/ember-apache-echarts/src/components/chart/bar.gts +++ b/ember-apache-echarts/src/components/chart/bar.gts @@ -1,7 +1,7 @@ -// @ts-nocheck import { action } from '@ember/object'; import { htmlSafe } from '@ember/template'; import { or } from 'ember-truth-helpers'; +// @ts-expect-error import { pick } from 'lodash-es'; import { tracked } from '@glimmer/tracking'; import barChart from '../../modifiers/bar-chart.ts'; @@ -46,6 +46,7 @@ import style from 'ember-style-modifier'; * `series` * : The series object for the series this item belongs to. */ +// @ts-expect-error const toTooltipItem = (param, dataset) => ({ ...pick(param, 'value', 'marker', 'dataIndex', 'data', 'seriesIndex'), label: param.name, @@ -69,6 +70,7 @@ type ToolTipAxis = { * Converts an axis EChart tooltip param into an object describing the axis the * tooltip is for. */ +// @ts-expect-error const toTooltipAxis = ([firstParam]) => ({ id: firstParam.axisId, index: firstParam.axisIndex, @@ -80,8 +82,8 @@ const toTooltipAxis = ([firstParam]) => ({ interface S { Args: { - width?: string; - height?: string; + width?: string | number; + height?: string | number; series?: unknown[]; data?: unknown; variant?: string; @@ -92,7 +94,7 @@ interface S { chartStyle?: unknown; chartTitleStyle?: unknown; maxColumns?: number; - orientation?: string; + orientation?: 'horizontal' | 'vertical'; colorMap?: unknown; cellStyle?: unknown; cellTitleStyle?: unknown; @@ -140,11 +142,15 @@ interface S { } export default class BarChartComponent extends Component { + // @ts-expect-error axisTooltipElement; + // @ts-expect-error itemTooltipElement; - + // @ts-expect-error @tracked tooltipItem; + // @ts-expect-error @tracked tooltipItems; + // @ts-expect-error @tracked tooltipAxis; // HACK: The way we're currently transforming the data for the grouped or @@ -158,15 +164,17 @@ export default class BarChartComponent extends Component { } @action - setup(element) { + setup(element: HTMLElement) { this.axisTooltipElement = element.querySelector('[data-role=axisTooltip]'); this.itemTooltipElement = element.querySelector('[data-role=itemTooltip]'); } @action + // @ts-expect-error tooltipFormatter(params, dataset) { if (params.length) { this.tooltipAxis = toTooltipAxis(params); + // @ts-expect-error this.tooltipItems = params.map((param) => toTooltipItem(param, dataset)); return this.axisTooltipElement; @@ -182,6 +190,7 @@ export default class BarChartComponent extends Component {
+const isNumeric = (value?: string | number) => typeof value === 'number' || (typeof value === 'string' && value.match(numberRegEx) != null); /** @@ -17,12 +17,12 @@ const isNumeric = (value: unknown) => * @return {string} The value formatted as a CSS size */ -export default helper(function cssSize(positional: [string?, string?] /*, named*/): string { +export default helper(function cssSize(positional: [(string | number)?, (string | number)?] /*, named*/): string { const size = positional[0] != null && positional[0] !== '' ? positional[0] : positional[1]; return isNumeric(size) || size === '' ? size?.toString() !== '0' ? `${size}px` : '0' - : (size ?? '0'); + : (`${size ?? '0'}`); });