forked from hyoo-ru/mam_mol
-
Notifications
You must be signed in to change notification settings - Fork 0
/
graph.view.ts
56 lines (46 loc) · 1.3 KB
/
graph.view.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
namespace $.$$ {
export class $mol_plot_graph extends $.$mol_plot_graph {
viewport() {
const size = this.size_real()
return new this.$.$mol_vector_2d(
new this.$.$mol_vector_range(0, size.x),
new this.$.$mol_vector_range(0, size.y),
)
}
points() {
const [shift_x, shift_y] = this.shift()
const [scale_x, scale_y] = this.scale()
const series_x = this.series_x()
const series_y = this.series_y()
return this.indexes().map(index => {
const point_x = Math.round(shift_x + series_x[index] * scale_x)
const point_y = Math.round(shift_y + series_y[index] * scale_y)
return [point_x, point_y]
}) as readonly( readonly number[] )[]
}
@ $mol_mem
series_x() {
return this.series_y().map((val, index) => index) as readonly number[]
}
@ $mol_mem
dimensions() {
let next = new this.$.$mol_vector_2d(
$mol_vector_range_full.inversed,
$mol_vector_range_full.inversed
)
const series_x = this.series_x()
const series_y = this.series_y()
for(let i = 0; i < series_x.length; i++) {
next = next.expanded1([series_x[i], series_y[i]] as const)
}
return next
}
color() {
const hue = this.hue()
return hue ? `hsl( ${ hue } , 100% , 35% )` : ''
}
front() {
return [ this ] as unknown as readonly $.$mol_svg[]
}
}
}