Skip to content

[FEATURE] Add new star marker #10836

@sebacastroh

Description

@sebacastroh

Currently, Bokeh offers several markers such as asterisk, circle, diamond, square, triangle, and variations of these. However, the typical star shape is not included, so I tried to add this feature.

The star border's path I'm using in bokehjs/src/lib/models/glyphs/defs.ts is

const SQ5 = Math.sqrt(5)

function _one_star(ctx: Context2d, r: number): void {
    const a = Math.sqrt(5-2*SQ5)*r
    const c36 = (SQ5+1)/4
    const s36 = Math.sqrt((5-SQ5)/8)
    const c72 = (SQ5-1)/4
    const s72 = Math.sqrt((5+SQ5)/8)
    
    ctx.moveTo(0, -r)
    ctx.lineTo(a*c72, -r+a*s72)
    ctx.lineTo(a*(1+c72), -r+a*s72)
    ctx.lineTo(a*(1+c72-c36), -r+a*(s72+s36))
    ctx.lineTo(a*(1+2*c72-c36), -r+a*(2*s72+s36))
    ctx.lineTo(0, -r+a*2*s72)
    ctx.lineTo(-a*(1+2*c72-c36), -r+a*(2*s72+s36))
    ctx.lineTo(-a*(1+c72-c36), -r+a*(s72+s36))
    ctx.lineTo(-a*(1+c72), -r+a*s72)
    ctx.lineTo(-a*c72, -r+a*s72)
    ctx.closePath()
}

function star(ctx: Context2d, i: number, r: number, visuals: VectorVisuals): void {
    _one_star(ctx, r)

    if (visuals.fill.doit) {
        visuals.fill.set_vectorize(ctx, i)
        ctx.fill()
    }

    if (visuals.hatch.doit) {
        visuals.hatch.set_vectorize(ctx, i)
        ctx.fill()
    }

    if (visuals.line.doit) {
        visuals.line.set_vectorize(ctx, i)
        ctx.stroke()
    }
}

and for the (I suppose) size of the marker in bokehjs/src/lib/models/glyphs/webgl/markers.frag I copied the code for the hex case, i.e.

#ifdef USE_STAR
// star
float marker(vec2 P, float size)
{
    vec2 q = abs(P);
    return max(q.y * 0.57735 + q.x - 1.0 * size/2.0, q.y - 0.866 * size/2.0);
}
#endif

Then I added "star" in all the files where other markers were written, for example in all the bokehjs codes bokehjs/src/lib/api/plotting.ts, bokehjs/src/lib/core/enums.ts, bokehjs/src/lib/models/glyphs/webgl/markers.ts, bokehjs/test/integration/glyphs/markers.ts, bokehjs/test/integration/regressions.ts, bokehjs/test/unit/core/enums.ts, but also in examples, documentation, etc.

Unfortunately, I can't pass the integration test

✗ Bug
 └┬─ in issue #10457
  └── prevents rendering marker glyphs with reversed ranges
diff --git a/bokehjs/test/baselines/Bug__in_issue_#10457__prevents_rendering_marker_glyphs_with_reversed_ranges b/bokehjs/test/baselines/Bug__in_issue_#10457__prevents_rendering_marker_glyphs_with_reversed_ranges
index 9779355..3a5dcdf 100644
--- a/bokehjs/test/baselines/Bug__in_issue_#10457__prevents_rendering_marker_glyphs_with_reversed_ranges
+++ b/bokehjs/test/baselines/Bug__in_issue_#10457__prevents_rendering_marker_glyphs_with_reversed_ranges
@@ -1,4 +1,4 @@
-Column bbox=[0, 0, 400, 1300]
+Column bbox=[0, 0, 400, 1350]
   Row bbox=[0, 0, 400, 50]
     Plot bbox=[0, 0, 100, 50]
     Plot bbox=[100, 0, 100, 50]
@@ -129,3 +129,8 @@ Column bbox=[0, 0, 400, 1300]
     Plot bbox=[100, 0, 100, 50]
     Plot bbox=[200, 0, 100, 50]
     Plot bbox=[300, 0, 100, 50]
+  Row bbox=[0, 1300, 400, 50]
+    Plot bbox=[0, 0, 100, 50]
+    Plot bbox=[100, 0, 100, 50]
+    Plot bbox=[200, 0, 100, 50]
+    Plot bbox=[300, 0, 100, 50]


✗ Marker glyph
 └── should support 'star' marker type
missing baseline
diff --git a/test/baselines/Marker_glyph__should_support_'star'_marker_type b/test/baselines/Marker_glyph__should_support_'star'_marker_type
new file mode 100644
index 0000000..10abf94
--- /dev/null
+++ b/test/baselines/Marker_glyph__should_support_'star'_marker_type
@@ -0,0 +1,7 @@
+Row bbox=[0, 0, 450, 150]
+  Plot bbox=[0, 0, 150, 150]
+    Title bbox=[5, 0, 140, 28]
+  Plot bbox=[150, 0, 150, 150]
+    Title bbox=[5, 0, 140, 28]
+  Plot bbox=[300, 0, 150, 150]
+    Title bbox=[5, 0, 140, 28]

[02:36:45] Finished 'test:integration' after 33.54 s
[02:36:45] failed: tests failed
[02:36:45] failed: tests failed
[02:36:45] failed: task 'top-level' failed because 'test:integration' failed
[02:36:45] failed: task 'top-level' failed because 'test:integration' failed
[02:36:45] failed: task 'top-level' failed because 'test:lib' failed
[02:36:45] failed: task 'top-level' failed because 'test:lib' failed
[02:36:45] failed: task 'top-level' failed because 'test' failed
[02:36:45] failed: task 'top-level' failed because 'test' failed
Error: Process completed with exit code 1.

I think this marker is a nice addition to the current collection and an easy implementation. I don't understand why the test is not being passed, do you have any idea? Is there something I'm not considering?

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions