Skip to content

Commit

Permalink
Add some better types. Ignore others
Browse files Browse the repository at this point in the history
  • Loading branch information
cloke committed Nov 21, 2024
1 parent d7759d8 commit e3e0f2d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
21 changes: 15 additions & 6 deletions ember-apache-echarts/src/components/chart/bar.gts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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;
Expand All @@ -92,7 +94,7 @@ interface S {
chartStyle?: unknown;
chartTitleStyle?: unknown;
maxColumns?: number;
orientation?: string;
orientation?: 'horizontal' | 'vertical';
colorMap?: unknown;
cellStyle?: unknown;
cellTitleStyle?: unknown;
Expand Down Expand Up @@ -140,11 +142,15 @@ interface S {
}

export default class BarChartComponent extends Component<S> {
// @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
Expand All @@ -158,15 +164,17 @@ export default class BarChartComponent extends Component<S> {
}

@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;
Expand All @@ -182,6 +190,7 @@ export default class BarChartComponent extends Component<S> {
<div
...attributes
{{style width=(cssSize @width "100%") height=(cssSize @height "400")}}
{{! @glint-expect-error}}
{{barChart
this.args
tooltipFormatter=(if
Expand Down
6 changes: 3 additions & 3 deletions ember-apache-echarts/src/helpers/css-size.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { helper } from '@ember/component/helper';

const numberRegEx = /^\d+$/;

const isNumeric = (value: unknown) =>
const isNumeric = (value?: string | number) =>
typeof value === 'number' || (typeof value === 'string' && value.match(numberRegEx) != null);

/**
Expand All @@ -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'}`);
});

0 comments on commit e3e0f2d

Please sign in to comment.