Skip to content

Fix/axis types #121

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Jun 18, 2025
Merged
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
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"prepack": "npx svelte-package",
"release-next": "npm version prerelease --preid next && npm publish && git push && git push --tags && sleep 1 && npm dist-tag add svelteplot@$(npm view . version) next",
"docs": "npm run build && cd build && rsync --recursive . vis4.net:svelteplot/alpha0/",
"screenshots": "node screenshot-examples.js"
"screenshots": "node screenshot-examples.js",
"check-js-extensions": "node scripts/check-js-extensions.js src"
},
"exports": {
".": {
Expand Down
138 changes: 138 additions & 0 deletions scripts/check-js-extensions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
#!/usr/bin/env node
/* eslint-disable no-console */

/**
* This script checks for missing .js extensions in import statements.
* It helps identify issues with ESM imports where TypeScript requires .js extensions.
*/

import { readFile, readdir, stat } from 'fs/promises';
import path from 'path';
import { fileURLToPath } from 'url';

// Convert file:// URLs to paths
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

// Regular expressions to match import statements without .js extensions
const regexImportFrom =
/import\s+(?:type\s+)?(?:{[^}]*}|\*\s+as\s+[^;]*|[^;{]*)\s+from\s+['"]([^'"]*)['"]/g;
const regexExportFrom =
/export\s+(?:type\s+)?(?:{[^}]*}|\*\s+as\s+[^;]*)\s+from\s+['"]([^'"]*)['"]/g;

// Skip node_modules and build directories
const excludedDirs = ['node_modules', 'build', '.svelte-kit', 'dist', '.git', 'examples', 'tests'];

// Only check certain file types
const includedExtensions = ['.ts', '.js', '.svelte'];

// Paths that should have .js extensions (relative paths and alias paths)
const shouldHaveJsExtension = (importPath) => {
// Skip Svelte imports
if (importPath.endsWith('.svelte')) return false;

// Skip npm package imports (those that don't start with . or /)
if (
!importPath.startsWith('.') &&
!importPath.startsWith('/') &&
!importPath.startsWith('$lib')
)
return false;

// Skip imports with extensions already
if (path.extname(importPath)) return false;

return true;
};

async function* walkDirectory(dir) {
const entries = await readdir(dir, { withFileTypes: true });

for (const entry of entries) {
const fullPath = path.join(dir, entry.name);

if (entry.isDirectory()) {
if (!excludedDirs.includes(entry.name)) {
yield* walkDirectory(fullPath);
}
} else if (includedExtensions.includes(path.extname(entry.name))) {
yield fullPath;
}
}
}

async function checkFile(filePath) {
const content = await readFile(filePath, 'utf8');
const issues = [];

// Find all import statements
let match;

// Check import statements
regexImportFrom.lastIndex = 0;
while ((match = regexImportFrom.exec(content)) !== null) {
const importPath = match[1];
if (shouldHaveJsExtension(importPath)) {
issues.push({
line: content.substring(0, match.index).split('\n').length,
importPath,
statement: match[0]
});
}
}

// Check export from statements
regexExportFrom.lastIndex = 0;
while ((match = regexExportFrom.exec(content)) !== null) {
const importPath = match[1];
if (shouldHaveJsExtension(importPath)) {
issues.push({
line: content.substring(0, match.index).split('\n').length,
importPath,
statement: match[0]
});
}
}

return { filePath, issues };
}

async function main() {
const rootDir = process.argv[2] || process.cwd();
console.log(`Checking for missing .js extensions in ${rootDir}...\n`);

let totalIssues = 0;
let filesWithIssues = 0;

for await (const filePath of walkDirectory(rootDir)) {
const { issues } = await checkFile(filePath);

if (issues.length > 0) {
console.log(`\x1b[33m${filePath}\x1b[0m`);
filesWithIssues++;

for (const issue of issues) {
totalIssues++;
console.log(
` Line ${issue.line}: Missing .js extension in import: ${issue.importPath}`
);
console.log(` ${issue.statement}`);
}
console.log('');
}
}

if (totalIssues === 0) {
console.log('\x1b[32mNo missing .js extensions found!\x1b[0m');
} else {
console.log(
`\x1b[31mFound ${totalIssues} missing .js extensions in ${filesWithIssues} files.\x1b[0m`
);
process.exit(1);
}
}

main().catch((err) => {
console.error('Error:', err);
process.exit(1);
});
2 changes: 1 addition & 1 deletion src/lib/Plot.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<script lang="ts">
import Plot from './core/Plot.svelte';

import type { PlotDefaults, PlotOptions } from './types/index.js';
import type { PlotOptions } from './types/index.js';

// implicit marks
import AxisX from './marks/AxisX.svelte';
Expand Down
2 changes: 1 addition & 1 deletion src/lib/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ScaleName, ScaleType, ScaledChannelName } from './types.js';
import type { ScaleName, ScaleType, ScaledChannelName } from './types/index.js';

export const SCALE_TYPES: Record<ScaleName, symbol> = {
opacity: Symbol('opacity'),
Expand Down
2 changes: 2 additions & 0 deletions src/lib/core/FacetAxes.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
scaleType="band"
ticks={fxValues}
tickFormat={(d) => d}
tickFontSize={11}
Copy link
Preview

Copilot AI Jun 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The hardcoded font size (11) is a magic number; consider making this configurable via a prop or theme token to improve flexibility and maintainability.

Suggested change
tickFontSize={11}
tickFontSize={tickFontSize}

Copilot uses AI. Check for mistakes.

tickSize={0}
tickPadding={5}
anchor={plot.options.fx.axis}
Expand All @@ -53,6 +54,7 @@
scaleType="band"
ticks={fyValues}
tickFormat={(d) => d}
tickFontSize={11}
tickSize={0}
tickPadding={5}
anchor={plot.options.fy.axis}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/helpers/autoScales.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import type {
ScaleName,
ScaleOptions,
ScaleType
} from '../types.js';
} from '../types/index.js';
import {
categoricalSchemes,
isCategoricalScheme,
Expand Down
2 changes: 1 addition & 1 deletion src/lib/helpers/autoTicks.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { RawValue, ScaleType } from '$lib/types.js';
import type { RawValue, ScaleType } from '$lib/types/index.js';
import { maybeTimeInterval } from './time.js';
import { extent, range as rangei } from 'd3-array';

Expand Down
8 changes: 4 additions & 4 deletions src/lib/helpers/autoTimeFormat.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Scale } from '$lib/classes/Scale.svelte.js';
import { isDate } from '$lib/helpers/typeChecks';
import type { PlotScale } from '$lib/types/index.js';
import { isDate } from '$lib/helpers/typeChecks.js';

const DATE_TIME: Intl.DateTimeFormatOptions = {
hour: 'numeric',
Expand Down Expand Up @@ -32,9 +32,9 @@ const autoFormatMonthYear = (locale: string) => {
return (date: Date) => format(date).replace(' ', '\n');
};

export default function autoTimeFormat(x: Scale, plotWidth: number, plotLocale: string) {
export default function autoTimeFormat(x: PlotScale, plotWidth: number, plotLocale: string) {
const daysPer100Px =
((toNumber(x.domain[1]) - toNumber(x.domain[0])) / plotWidth / 864e5) * 100;
((toNumber(x.domain[1] as Date) - toNumber(x.domain[0] as Date)) / plotWidth / 864e5) * 100;
const format =
Copy link
Preview

Copilot AI Jun 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of using inline as Date casts on x.domain, consider parameterizing PlotScale with a Date generic (e.g., PlotScale<Date>) to avoid type assertions and improve type safety.

Copilot uses AI. Check for mistakes.

daysPer100Px < 1
? autoFormatDateTime(plotLocale)
Expand Down
2 changes: 1 addition & 1 deletion src/lib/helpers/callWithProps.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { RawValue } from '$lib/types.js';
import type { RawValue } from '$lib/types/index.js';

type Setter = (v: any) => void;

Expand Down
2 changes: 1 addition & 1 deletion src/lib/helpers/colors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ import {
} from 'd3-scale-chromatic';

import { quantize } from 'd3-interpolate';
import type { ColorScheme } from '$lib/types.js';
import type { ColorScheme } from '$lib/types/index.js';

const schemeObservable10 = [
'#4269d0',
Expand Down
2 changes: 1 addition & 1 deletion src/lib/helpers/curves.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Curve } from '../types.js';
import type { Curve } from '../types/index.js';
import {
curveBasis,
curveBasisClosed,
Expand Down
2 changes: 1 addition & 1 deletion src/lib/helpers/facets.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { GenericMarkOptions, Mark, RawValue } from '$lib/types.js';
import type { GenericMarkOptions, Mark, RawValue } from '$lib/types/index.js';
import { resolveChannel } from './resolve.js';

/**
Expand Down
4 changes: 2 additions & 2 deletions src/lib/helpers/getBaseStyles.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Channels } from '$lib/types.js';
import type { MarkStyleProps, DataRow } from '$lib/types.js';
import type { Channels } from '$lib/types/index.js';
import type { MarkStyleProps, DataRow } from '$lib/types/index.js';
import { resolveProp } from './resolve.js';

/**
Expand Down
2 changes: 1 addition & 1 deletion src/lib/helpers/group.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { groupFacetsAndZ } from './group';
import { groupFacetsAndZ } from './group.js';
import { describe, it, expect } from 'vitest';

describe('groupFacetsAndZ', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/helpers/group.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { resolveChannel } from '$lib/helpers/resolve.js';
import type { ChannelName, Channels, DataRecord } from '$lib/types.js';
import type { ChannelName, Channels, DataRecord } from '$lib/types/index.js';
import { groups as d3Groups } from 'd3-array';

/**
Expand Down
2 changes: 1 addition & 1 deletion src/lib/helpers/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { coalesce, isObject, omit } from './index';
import { coalesce, isObject, omit } from './index.js';
import { describe, it, expect } from 'vitest';

describe('coalesce', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/helpers/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ChannelAccessor, ChannelName, DataRecord, RawValue } from '$lib/types.js';
import type { ChannelAccessor, ChannelName, DataRecord, RawValue } from '$lib/types/index.js';
import type { Snippet } from 'svelte';
import { resolveProp } from './resolve.js';
import { isDate } from '$lib/helpers/typeChecks.js';
Expand Down
2 changes: 1 addition & 1 deletion src/lib/helpers/isDataRecord.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { DataRecord } from '../types.js';
import type { DataRecord } from '../types/index.js';

export default function (value: any): value is DataRecord {
if (typeof value !== 'object' || value === null) return false;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/helpers/isRawValue.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { RawValue } from '$lib/types.js';
import type { RawValue } from '$lib/types/index.js';
import { isDate } from '$lib/helpers/typeChecks.js';

export default function (value: any): value is RawValue {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/helpers/reduce.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, it, expect } from 'vitest';
import { reduceOutputs, type ReducerName } from './reduce.js';
import type { ChannelAccessor, ChannelName } from '$lib/types.js';
import type { ChannelAccessor, ChannelName } from '$lib/types/index.js';

describe('reduceOutputs', () => {
it('should correctly reduce outputs', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/helpers/reduce.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ChannelName, Channels, DataRecord, DataRow, RawValue } from '$lib/types.js';
import type { ChannelName, Channels, DataRecord, DataRow, RawValue } from '$lib/types/index.js';
import { min, max, mode, sum, mean, median, variance, deviation, quantile } from 'd3-array';
import { resolveChannel } from './resolve.js';
import { POSITION_CHANNELS } from './index.js';
Expand Down
2 changes: 1 addition & 1 deletion src/lib/helpers/regressionLoess.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { DataRow } from '$lib/types.js';
import type { DataRow } from '$lib/types/index.js';
import Loess from 'loess';

type AccessorFn = (d: any) => number;
Expand Down
4 changes: 2 additions & 2 deletions src/lib/helpers/resolve.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { CHANNEL_SCALE } from '$lib/constants.js';
import isDataRecord from '$lib/helpers/isDataRecord.js';
import isRawValue from '$lib/helpers/isRawValue.js';
import type { MarkStyleProps, PlotState, ScaledDataRecord } from '$lib/types.js';
import type { MarkStyleProps, PlotState, ScaledDataRecord } from '$lib/types/index.js';
import { isValid } from './isValid.js';

import type {
Expand All @@ -13,7 +13,7 @@ import type {
RawValue,
DataRecord,
ConstantAccessor
} from '../types.js';
} from '../types/index.js';
import { getBaseStylesObject } from './getBaseStyles.js';
import { RAW_VALUE } from 'svelteplot/transforms/recordize.js';

Expand Down
2 changes: 1 addition & 1 deletion src/lib/helpers/scales.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import type {
ScaleType,
ScaledChannelName,
UsedScales
} from '../types.js';
} from '../types/index.js';
import isDataRecord from './isDataRecord.js';

import { createProjection } from './projection.js';
Expand Down
2 changes: 1 addition & 1 deletion src/lib/helpers/typeChecks.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { RawValue } from '$lib/types.js';
import type { RawValue } from '$lib/types/index.js';
import { isSymbol } from './symbols.js';
import { color } from 'd3-color';
import {
Expand Down
4 changes: 2 additions & 2 deletions src/lib/marks/Area.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@
ChannelAccessor,
ScaledDataRecord,
LinkableMarkProps,
PlotDefaults
PlotDefaults,
RawValue
} from '../types/index.js';
import type { RawValue } from 'svelteplot/types/index.js';
import type { StackOptions } from '$lib/transforms/stack.js';

let markProps: AreaMarkProps = $props();
Expand Down
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy