Skip to content

Commit

Permalink
Fix tricont, evenodd fill and subpaths in js
Browse files Browse the repository at this point in the history
  • Loading branch information
maltedeckers committed Jan 23, 2020
1 parent 0c24ff6 commit 9c772ac
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
4 changes: 2 additions & 2 deletions js/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ default: gr.js
../lib/gr/gr_version.h: .FORCE
$(MAKE) -C ../lib/gr gr_version.h

gr.js: libGR.js
cat module.js libGR.js api.js jsterm.js >gr.js
gr.js: module.js libGR.js api.js jsterm.js
cat $^ > $@

fonts:
mkdir fonts
Expand Down
23 changes: 18 additions & 5 deletions js/library.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ mergeInto(LibraryManager.library, {
img.getContext("2d").putImageData(imageData, 0, 0);
var pattern = context.createPattern(img, "repeat");
context.fillStyle = pattern;
context.fill();
context.fill("evenodd");
},

js_fill_routine: function(n, px, py, colia) {
Expand All @@ -47,7 +47,7 @@ mergeInto(LibraryManager.library, {
}
context.lineTo(px[0], py[0]);
context.fillStyle = "rgba(" + rgba[0] + "," + rgba[1] + "," + rgba[2] + "," + rgba[3] + ")";
context.fill();
context.fill("evenodd");
},

js_cellarray: function(x, y, width, height, colia) {
Expand Down Expand Up @@ -122,15 +122,28 @@ mergeInto(LibraryManager.library, {
context.fillStyle = "rgba(" + rgb[0] + "," + rgb[1] + "," + rgb[2] + "," + rgb[3] + ")";
context.lineWidth = width;
context.moveTo(px[0], py[0]);
var nan_found = false;
for (var i = 1; i < n; i++) {
if (Number.isNaN(px[i]) && Number.isNaN(py[i])) {
nan_found = true;
continue;
}
if (nan_found) {
nan_found = false;
if (linetype == 0) {
context.closePath();
}
context.moveTo(px[i], py[i]);
} else {
context.lineTo(px[i], py[i]);
}
}
if (linetype == 0) {
context.lineTo(px[0], py[0]);
context.closePath();
}
context.stroke();
if (fill != 0) {
context.fill();
context.fill("evenodd");
}
},

Expand Down Expand Up @@ -161,7 +174,7 @@ mergeInto(LibraryManager.library, {
context.fillStyle = "rgba(" + rgb[0] + "," + rgb[1] + "," + rgb[2] + "," + 255 + ")";
context.arc(x, y, r, 0, 2 * Math.PI);
if (fill == 1) {
context.fill();
context.fill("evenodd");
} else {
context.stroke();
}
Expand Down
4 changes: 2 additions & 2 deletions lib/gr/meta.c
Original file line number Diff line number Diff line change
Expand Up @@ -3842,7 +3842,7 @@ void plot_process_viewport(gr_meta_args_t *subplot_args)
{
viewport[2] += (1 - (subplot[3] - subplot[2]) * (subplot[3] - subplot[2])) * 0.02;
}
if (str_equals_any(kind, 6, "contour", "contourf", "heatmap", "nonuniformheatmap", "hexbin", "quiver"))
if (str_equals_any(kind, 7, "tricont", "contour", "contourf", "heatmap", "nonuniformheatmap", "hexbin", "quiver"))
{
viewport[1] -= 0.1;
}
Expand Down Expand Up @@ -5297,7 +5297,7 @@ error_t plot_tricont(gr_meta_args_t *subplot_args)
++current_series;
}
plot_draw_axes(subplot_args, 2);
plot_draw_colorbar(subplot_args, 0.05, 256);
plot_draw_colorbar(subplot_args, 0.0, num_levels);
free(levels);

return NO_ERROR;
Expand Down

0 comments on commit 9c772ac

Please sign in to comment.