allow for running data
This commit is contained in:
parent
ad557ea596
commit
d9e44bca22
BIN
JetBrainsMono-Regular.ttf
Normal file
BIN
JetBrainsMono-Regular.ttf
Normal file
Binary file not shown.
106
module.jai
106
module.jai
@ -5,12 +5,17 @@ PlotSettings :: struct {
|
|||||||
bottom_right : Vector2;
|
bottom_right : Vector2;
|
||||||
}
|
}
|
||||||
|
|
||||||
PLOT_STYLE :: enum {
|
PLOT_STYLE :: enum s32 {
|
||||||
TICK_MARKS;
|
TICK_MARKS;
|
||||||
SCALE_MARKER;
|
SCALE_MARKER;
|
||||||
}
|
}
|
||||||
|
|
||||||
draw_plot :: (key: string, xdata: []float64, yarrays: [][]float64, style: PLOT_STYLE, using settings: PlotSettings) {
|
PLOT_DATA_STYLE :: enum {
|
||||||
|
ONCE;
|
||||||
|
EVERY_FRAME;
|
||||||
|
}
|
||||||
|
|
||||||
|
draw_plot :: (key: string, xdata: []float64, yarrays: [][]float64, using settings: PlotSettings, data_style := PLOT_DATA_STYLE.ONCE) {
|
||||||
plot_size := ImGui.GetContentRegionAvail();
|
plot_size := ImGui.GetContentRegionAvail();
|
||||||
|
|
||||||
plot, success := table_find(*plots, key);
|
plot, success := table_find(*plots, key);
|
||||||
@ -19,6 +24,7 @@ draw_plot :: (key: string, xdata: []float64, yarrays: [][]float64, style: PLOT_S
|
|||||||
init_plot(plot, key, xx plot_size.x, xx plot_size.y);
|
init_plot(plot, key, xx plot_size.x, xx plot_size.y);
|
||||||
table_set(*plots, key, plot);
|
table_set(*plots, key, plot);
|
||||||
|
|
||||||
|
if data_style == .ONCE {
|
||||||
plot.xfloat = NewArray(xdata.count, float);
|
plot.xfloat = NewArray(xdata.count, float);
|
||||||
|
|
||||||
for xdata {
|
for xdata {
|
||||||
@ -76,13 +82,75 @@ draw_plot :: (key: string, xdata: []float64, yarrays: [][]float64, style: PLOT_S
|
|||||||
plot.x_avg = plot.xmax - plot.xmin;
|
plot.x_avg = plot.xmax - plot.xmin;
|
||||||
plot.y_avg = plot.ymax - plot.ymin;
|
plot.y_avg = plot.ymax - plot.ymin;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//plot.pos.x = plot.x_avg;
|
|
||||||
//plot.pos.y = plot.y_avg;
|
|
||||||
plot.zoom = 1.0;
|
plot.zoom = 1.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if style == {
|
if data_style == .EVERY_FRAME {
|
||||||
|
plot.xfloat = NewArray(xdata.count, float);
|
||||||
|
|
||||||
|
for xdata {
|
||||||
|
plot.xfloat[it_index] = cast(float) it;
|
||||||
|
}
|
||||||
|
|
||||||
|
plot.xmin = 0.0;
|
||||||
|
plot.xmax = 0.0;
|
||||||
|
|
||||||
|
x_acc : float;
|
||||||
|
|
||||||
|
for xdata {
|
||||||
|
if it > plot.xmax plot.xmax = xx it;
|
||||||
|
if it < plot.xmin plot.xmin = xx it;
|
||||||
|
|
||||||
|
is_nan, is_inf := is_nan_is_inf(cast(float) it);
|
||||||
|
if !is_nan && !is_inf {
|
||||||
|
x_acc += cast(float) it;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
plot.x_avg = x_acc / xdata.count;
|
||||||
|
|
||||||
|
plot.ymin = 0.0;
|
||||||
|
plot.ymax = 0.0;
|
||||||
|
|
||||||
|
y_acc : float;
|
||||||
|
|
||||||
|
for ydata: yarrays {
|
||||||
|
|
||||||
|
yfloat := NewArray(ydata.count, float);
|
||||||
|
array_add(*plot.yfloats, yfloat);
|
||||||
|
|
||||||
|
for ydata {
|
||||||
|
yfloat[it_index] = cast(float) it;
|
||||||
|
|
||||||
|
if it > plot.ymax plot.ymax = xx it;
|
||||||
|
if it < plot.ymin plot.ymin = xx it;
|
||||||
|
|
||||||
|
is_nan, is_inf := is_nan_is_inf(cast(float) it);
|
||||||
|
if !is_nan && !is_inf {
|
||||||
|
y_acc += cast(float) it;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
plot.y_avg = y_acc / (yarrays[0].count * yarrays.count);
|
||||||
|
|
||||||
|
if fixed_bounds {
|
||||||
|
plot.xmin = top_left.x;
|
||||||
|
plot.xmax = bottom_right.x;
|
||||||
|
plot.ymin = bottom_right.y;
|
||||||
|
plot.ymax = top_left.y;
|
||||||
|
|
||||||
|
plot.x_avg = plot.xmax - plot.xmin;
|
||||||
|
plot.y_avg = plot.ymax - plot.ymin;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui.RadioButton("Tick marks", xx *plot.plot_style, 0); ImGui.SameLine();
|
||||||
|
ImGui.RadioButton("Scale marker", xx *plot.plot_style, 1);
|
||||||
|
|
||||||
|
if plot.plot_style == {
|
||||||
case .TICK_MARKS;
|
case .TICK_MARKS;
|
||||||
plot.left_bearing = 40;
|
plot.left_bearing = 40;
|
||||||
plot.bottom_bearing = 20;
|
plot.bottom_bearing = 20;
|
||||||
@ -132,9 +200,9 @@ draw_plot :: (key: string, xdata: []float64, yarrays: [][]float64, style: PLOT_S
|
|||||||
glClearColor(colors.background.x, colors.background.y, colors.background.z, 0.0);
|
glClearColor(colors.background.x, colors.background.y, colors.background.z, 0.0);
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
|
|
||||||
draw_axis(plot, style, colors);
|
draw_axis(plot, plot.plot_style, colors);
|
||||||
|
|
||||||
if style == .SCALE_MARKER
|
if plot.plot_style == .SCALE_MARKER
|
||||||
draw_scale(plot, colors);
|
draw_scale(plot, colors);
|
||||||
|
|
||||||
glViewport(xx plot.left_bearing, xx plot.bottom_bearing,
|
glViewport(xx plot.left_bearing, xx plot.bottom_bearing,
|
||||||
@ -192,6 +260,14 @@ draw_plot :: (key: string, xdata: []float64, yarrays: [][]float64, style: PLOT_S
|
|||||||
plot.last_frame = frame;
|
plot.last_frame = frame;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if data_style == .EVERY_FRAME {
|
||||||
|
array_free(plot.xfloat);
|
||||||
|
|
||||||
|
for plot.yfloats {
|
||||||
|
array_free(it);
|
||||||
|
remove it;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
free_old_plots :: () {
|
free_old_plots :: () {
|
||||||
@ -219,7 +295,7 @@ init :: (_win_width: s32, _win_height: s32) {
|
|||||||
|
|
||||||
window_projection_matrix = orthographic_projection_matrix(0.0, xx win_width, xx win_height, 0.0, -1.0, 1.0);
|
window_projection_matrix = orthographic_projection_matrix(0.0, xx win_width, xx win_height, 0.0, -1.0, 1.0);
|
||||||
|
|
||||||
init_font(*JetBrainsMonoRegular, "fonts/JetBrainsMono-Regular.ttf", 12);
|
init_font(*JetBrainsMonoRegular, "JetBrainsMono-Regular.ttf", 12);
|
||||||
}
|
}
|
||||||
|
|
||||||
window_resize :: (_win_width: s32, _win_height: s32) {
|
window_resize :: (_win_width: s32, _win_height: s32) {
|
||||||
@ -262,6 +338,9 @@ PlotColors :: struct {
|
|||||||
|
|
||||||
Plot :: struct {
|
Plot :: struct {
|
||||||
key : string;
|
key : string;
|
||||||
|
|
||||||
|
plot_style : PLOT_STYLE;
|
||||||
|
|
||||||
msfbo : GLuint;
|
msfbo : GLuint;
|
||||||
mstexture : GLuint;
|
mstexture : GLuint;
|
||||||
fbo : GLuint;
|
fbo : GLuint;
|
||||||
@ -581,6 +660,7 @@ is_in_rect :: (pos: Vector2, size: Vector2, test: Vector2) -> bool {
|
|||||||
#import "freetype-2.12.1";
|
#import "freetype-2.12.1";
|
||||||
#import "harfbuzz";
|
#import "harfbuzz";
|
||||||
#import "stb_rect_pack";
|
#import "stb_rect_pack";
|
||||||
|
#import "File";
|
||||||
|
|
||||||
ftlib : FT_Library;
|
ftlib : FT_Library;
|
||||||
|
|
||||||
@ -588,6 +668,8 @@ ATLAS_SIZE :: 2048;
|
|||||||
|
|
||||||
JetBrainsMonoRegular: Font;
|
JetBrainsMonoRegular: Font;
|
||||||
|
|
||||||
|
JetBrainsMonoRegular_text :: #run read_entire_file(tprint("%/JetBrainsMono-Regular.ttf", #filepath));
|
||||||
|
|
||||||
Glyph :: struct {
|
Glyph :: struct {
|
||||||
utf32 : u32;
|
utf32 : u32;
|
||||||
index : u32;
|
index : u32;
|
||||||
@ -622,7 +704,10 @@ init_font :: (using font: *Font, filename: string, size: s32) {
|
|||||||
pixel_size := size * 96.0 / 72.0;
|
pixel_size := size * 96.0 / 72.0;
|
||||||
//pixel_size := size;
|
//pixel_size := size;
|
||||||
|
|
||||||
FT_New_Face(ftlib, filename.data, 0, *face);
|
//FT_New_Face(ftlib, filename.data, 0, *face);
|
||||||
|
|
||||||
|
FT_New_Memory_Face(ftlib, JetBrainsMonoRegular_text.data, JetBrainsMonoRegular_text.count, 0, *face);
|
||||||
|
|
||||||
//error := FT_Set_Pixel_Sizes(face, 0, xx size);
|
//error := FT_Set_Pixel_Sizes(face, 0, xx size);
|
||||||
error := FT_Set_Char_Size(face, 0, size * 64, 0, 96);
|
error := FT_Set_Char_Size(face, 0, size * 64, 0, 96);
|
||||||
if error
|
if error
|
||||||
@ -690,7 +775,8 @@ init_font :: (using font: *Font, filename: string, size: s32) {
|
|||||||
|
|
||||||
graphics_init_font(*font.graphics_font, atlas);
|
graphics_init_font(*font.graphics_font, atlas);
|
||||||
|
|
||||||
blob : *hb_blob_t = hb_blob_create_from_file(filename.data);
|
blob : *hb_blob_t = hb_blob_create(JetBrainsMonoRegular_text.data, JetBrainsMonoRegular_text.count, .HB_MEMORY_MODE_READONLY, null, null);
|
||||||
|
|
||||||
hb_face : *hb_face_t = hb_face_create(blob, 0);
|
hb_face : *hb_face_t = hb_face_create(blob, 0);
|
||||||
hb = hb_font_create(hb_face);
|
hb = hb_font_create(hb_face);
|
||||||
hb_font_set_ppem(hb, xx pixel_size, xx pixel_size);
|
hb_font_set_ppem(hb, xx pixel_size, xx pixel_size);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user