Skip to content

Commit a57cf2b

Browse files
committed
manual linting
1 parent 693b7f5 commit a57cf2b

13 files changed

+175
-150
lines changed

.eslintrc.json

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,16 @@
2222
}
2323
},
2424
"rules": {
25-
"import/no-default-export": "error"
25+
"import/no-default-export": "error",
26+
"id-length": [
27+
"warn",
28+
{
29+
"exceptions": [
30+
"x",
31+
"y",
32+
"i"
33+
]
34+
}
35+
]
2636
}
2737
}

.vscode/settings.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,12 @@
2424
"composables",
2525
"datetime",
2626
"emperical",
27+
"esbuild",
2728
"idempotency",
2829
"pinia",
2930
"prefecthq",
30-
"vite"
31+
"scripthost",
32+
"vite",
33+
"vitejs"
3134
]
3235
}

src/BarChart.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<template>
22
<div ref="container" class="bar-chart">
33
<template v-if="_items.length">
4-
<svg :id="id" ref="chart" class="bar-chart__svg">
4+
<svg :id="id" class="bar-chart__svg">
55
<!-- -->
66
</svg>
77

@@ -42,7 +42,7 @@
4242
const props = defineProps<{
4343
intervalStart: Date,
4444
intervalEnd: Date,
45-
items: BarChartItem<any>[],
45+
items: BarChartItem[],
4646
chartPadding?: {
4747
top?: number,
4848
bottom?: number,

src/Base.ts

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -42,21 +42,21 @@ export interface IBaseOptions {
4242
},
4343
}
4444

45+
// typescript says crypto will be defined but it might not be
46+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
4547
if (crypto && !('randomUUID' in crypto)) {
4648
crypto.randomUUID = () => (+[1e7] + -1e3 + -4e3 + -8e3 + -1e11)
4749
.toString()
4850
.replace(/[018]/g,
49-
c => (+c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> +c / 4).toString(16),
51+
substring => (+substring ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> +substring / 4).toString(16),
5052
)
5153
}
5254

5355
// Starting these with "chart-" allows us to use UUIDs as HTMLElement ids
54-
const _uid = () => `chart-${crypto.randomUUID()}`
56+
const _uid = (): string => `chart-${crypto.randomUUID()}`
5557

5658

5759
export class Base implements IBase {
58-
private readonly container: ElementRef
59-
private resizeObserver: ResizeObserver | undefined
6060

6161
public id: string = _uid()
6262

@@ -71,8 +71,11 @@ export class Base implements IBase {
7171
right: 0,
7272
}
7373

74-
constructor(container: ElementRef, options?: IBaseOptions) {
75-
if (!container) {
74+
private readonly container: ElementRef
75+
private resizeObserver: ResizeObserver | undefined
76+
77+
public constructor(container: ElementRef, options?: IBaseOptions) {
78+
if (container.value === undefined) {
7679
throw new Error('Error initializing chart; must pass valid reference to element.')
7780
}
7881

@@ -87,6 +90,14 @@ export class Base implements IBase {
8790
}
8891
}
8992

93+
public get paddingY(): number {
94+
return this.padding.top + this.padding.middle + this.padding.bottom
95+
}
96+
97+
public get paddingX(): number {
98+
return this.padding.left + this.padding.right
99+
}
100+
90101
public initializeChart(): void {
91102
if (this.container.value) {
92103
this.resizeObserver = new ResizeObserver(this._onResize.bind(this))
@@ -101,15 +112,7 @@ export class Base implements IBase {
101112
}
102113
}
103114

104-
public get paddingY(): number {
105-
return this.padding.top + this.padding.middle + this.padding.bottom
106-
}
107-
108-
public get paddingX(): number {
109-
return this.padding.left + this.padding.right
110-
}
111-
112-
public onResize(): void { }
115+
public onResize(): void { /* silence? */ }
113116
private _onResize(): void {
114117
if (!this.container.value) {
115118
return
@@ -122,7 +125,7 @@ export class Base implements IBase {
122125
}
123126
}
124127

125-
const useBaseChart = (container: ElementRef, options?: IBaseOptions): Base => {
128+
export const useBaseChart = (container: ElementRef, options?: IBaseOptions): Base => {
126129
const base = new Base(container, options)
127130

128131
onMounted(() => {
@@ -136,7 +139,4 @@ const useBaseChart = (container: ElementRef, options?: IBaseOptions): Base => {
136139
})
137140

138141
return base
139-
}
140-
141-
export default useBaseChart
142-
export { useBaseChart }
142+
}

src/DivergingBarChart.vue

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<template>
22
<div ref="container" class="diverging-bar-chart">
3-
<svg :id="id" ref="chart" class="diverging-bar-chart__svg">
3+
<svg :id="id" class="diverging-bar-chart__svg">
44
<g class="diverging-bar-chart__axis-group" />
55
</svg>
66

@@ -11,9 +11,9 @@
1111
</div>
1212

1313
<div class="diverging-bar-chart__series-container">
14-
<template v-for="[key, series] in seriesMap" :key="key">
15-
<div class="diverging-bar-chart__series" :style="calculateSeriesPosition(series.data)">
16-
<template v-for="seriesPoint in series.series" :key="seriesPoint.key">
14+
<template v-for="[key, seriesItem] in seriesMap" :key="key">
15+
<div class="diverging-bar-chart__series" :style="calculateSeriesPosition(seriesItem.data)">
16+
<template v-for="seriesPoint in seriesItem.series" :key="seriesPoint.key">
1717
<div
1818
class="diverging-bar-chart__series-point"
1919
:style="calculateSeriesPointPosition(seriesPoint.value)"
@@ -22,7 +22,7 @@
2222
v-if="slots.default"
2323
:key="seriesPoint.key"
2424
:value="seriesPoint.value.data[seriesPoint.key]"
25-
:series="series"
25+
:series="seriesItem"
2626
/>
2727
<div v-else class="diverging-bar-chart__series-bar" />
2828
</div>
@@ -44,7 +44,7 @@
4444

4545
<script lang="ts" setup>
4646
import * as d3 from 'd3'
47-
import { computed, ref, onMounted, useSlots, watchEffect } from 'vue'
47+
import { computed, ref, onMounted, useSlots, watchEffect, StyleValue } from 'vue'
4848
import { useBaseChart } from './Base'
4949
import { DivergingBarChartItem, DivergingBarChartSeriesPoint, DivergingBarChartSeries, GroupSelection, TransitionSelection } from './types'
5050
import { formatLabel } from '@/utils/formatLabel'
@@ -54,8 +54,7 @@
5454
const props = defineProps<{
5555
intervalStart: Date,
5656
intervalEnd: Date,
57-
intervalSeconds: number,
58-
items: DivergingBarChartItem<any>[],
57+
items: DivergingBarChartItem[],
5958
staticMedian?: boolean,
6059
showAxis?: boolean,
6160
axisClass?: string,
@@ -103,10 +102,10 @@
103102
})
104103
105104
const xAxis = (
106-
g: GroupSelection,
107-
): GroupSelection | TransitionSelection => g
105+
group: GroupSelection,
106+
): GroupSelection | TransitionSelection => group
108107
.attr('class', () => {
109-
const existingClasses = g.attr('class').split(' ') ?? []
108+
const existingClasses = group.attr('class').split(' ')
110109
const propClasses = props.axisClass?.split(' ') ?? []
111110
const classes = [...existingClasses, ...propClasses.filter(pc => !existingClasses.includes(pc))]
112111
return classes.join(' ')
@@ -120,8 +119,8 @@
120119
.tickSizeInner(0)
121120
.tickSizeOuter(0),
122121
)
123-
.call((g) => g.select('.domain').remove())
124-
.call((g) => g.selectAll('.tick').style('opacity', 1))
122+
.call((group) => group.select('.domain').remove())
123+
.call((group) => group.selectAll('.tick').style('opacity', 1))
125124
126125
127126
const series = computed<DivergingBarChartSeries[]>(() => {
@@ -141,16 +140,16 @@
141140
142141
const seriesMap = computed<Map<Date, { data: DivergingBarChartItem, series: { key: string, value: DivergingBarChartSeriesPoint }[] }>>(() => {
143142
const itemsMap = props.items.map<[Date, { data: DivergingBarChartItem, series: { key: string, value: DivergingBarChartSeriesPoint }[] }]>((item, i) => {
144-
const seriesMap = series.value.map(s => {
145-
return { key: s.key, value: s[i] }
143+
const seriesMap = series.value.map(series => {
144+
return { key: series.key, value: series[i] }
146145
})
147146
return [item.intervalStart, { data: item, series: seriesMap }]
148147
})
149148
150149
return new Map(itemsMap)
151150
})
152151
153-
const calculateSeriesPosition = (item: DivergingBarChartItem) => {
152+
const calculateSeriesPosition = (item: DivergingBarChartItem): StyleValue => {
154153
const start = xScale.value(item.intervalStart)
155154
const end = xScale.value(item.intervalEnd)
156155
return {
@@ -159,7 +158,7 @@
159158
}
160159
}
161160
162-
const calculateSeriesPointPosition = (point: DivergingBarChartSeriesPoint) => {
161+
const calculateSeriesPointPosition = (point: DivergingBarChartSeriesPoint): StyleValue => {
163162
const offset = baseChart.padding.middle / 2
164163
let start = yScale.value(point[0])
165164
let end = yScale.value(point[1])

src/ScatterPlot.vue

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<template>
22
<div ref="container" class="scatter-plot">
3-
<svg :id="id" ref="chart" class="scatter-plot__svg">
3+
<svg :id="id" class="scatter-plot__svg">
44
<g class="scatter-plot__x-axis-group" />
55
<g class="scatter-plot__y-axis-group" />
66
</svg>
@@ -20,16 +20,16 @@
2020
<script lang="ts" setup>
2121
import * as d3 from 'd3'
2222
import { NumberValue } from 'd3'
23-
import { ref, computed, onMounted, watch, CSSProperties } from 'vue'
23+
import { ref, computed, onMounted, watch, CSSProperties, withDefaults } from 'vue'
2424
import { useBaseChart } from './Base'
2525
import { GroupSelection, TransitionSelection, ScatterPlotItem } from './types'
2626
import { extentUndefined } from './utils/extent'
27-
import formatLabel from './utils/formatLabel'
27+
import { formatLabel } from './utils/formatLabel'
2828
2929
const props = withDefaults(defineProps<{
3030
items: ScatterPlotItem[],
31-
startDate?: Date,
32-
endDate?: Date,
31+
startDate?: Date | null,
32+
endDate?: Date | null,
3333
showNowLine?: boolean,
3434
dotDiameter?: number,
3535
chartPadding?: {
@@ -38,15 +38,15 @@
3838
left?: number,
3939
right?: number,
4040
},
41-
}>(),
42-
{
43-
dotDiameter: 14,
44-
chartPadding: () => {
45-
return { top: 30, left: 70, bottom: 50, right: 20 }
46-
},
41+
}>(), {
42+
startDate: null,
43+
endDate: null,
44+
dotDiameter: 14,
45+
chartPadding: () => {
46+
return { top: 30, left: 70, bottom: 50, right: 20 }
47+
},
4748
48-
},
49-
)
49+
})
5050
5151
const container = ref<HTMLElement>()
5252
const xScale = ref(d3.scaleTime())
@@ -73,7 +73,7 @@
7373
return Math.max(ticks, 1)
7474
})
7575
76-
const xAxis = (g: GroupSelection): GroupSelection | TransitionSelection => g
76+
const xAxis = (group: GroupSelection): GroupSelection | TransitionSelection => group
7777
.call(d3.axisBottom(xScale.value)
7878
.tickPadding(10)
7979
.tickSizeInner(5)
@@ -87,7 +87,7 @@
8787
8888
const formatYAxis = (value: NumberValue): string => {
8989
if (typeof value !== 'number') {
90-
return `${value}`
90+
return `${value.valueOf()}`
9191
}
9292
9393
const formatter = d3.format('.0f')
@@ -100,16 +100,16 @@
100100
return `${formatter(value)}s`
101101
}
102102
103-
const yAxis = (g: GroupSelection): GroupSelection | TransitionSelection => g
103+
const yAxis = (group: GroupSelection): GroupSelection | TransitionSelection => group
104104
.call(d3.axisLeft(yScale.value)
105105
.tickPadding(10)
106106
.tickSizeInner(-(baseChart.width.value - baseChart.paddingX))
107-
.tickFormat(d => formatYAxis(d))
107+
.tickFormat(domain => formatYAxis(domain))
108108
.tickValues(yScale.value.ticks()),
109109
)
110110
111-
const xAccessor = (d: ScatterPlotItem) => d.x
112-
const yAccessor = (d: ScatterPlotItem) => d.y
111+
const xAccessor = (item: ScatterPlotItem): Date => item.x
112+
const yAccessor = (item: ScatterPlotItem): number => item.y
113113
114114
const calculateDotPosition = (item: ScatterPlotItem): CSSProperties => {
115115
const top = yScale.value(item.y) + baseChart.padding.top - props.dotDiameter / 2

0 commit comments

Comments
 (0)