Repository navigation
FEATURE: add interactive 2D maths graphs with function-plot - #191
Merged
Merged
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
Two critical lockfile findings block reproducible frozen installs, and two moderate client-side correctness findings remain unresolved.
2 open issues
1 file not reviewed
public/function-plot/build/pnpm-lock.yaml: Generated file
What changed in this PR
This pull request adds locally rendered, interactive 2D mathematical graphs to Chatbot across posts, PMs, previews, and Chat. It introduces the plot_function tool, secure expression validation, a bundled function-plot renderer, tracing, pan/zoom, fallbacks, documentation, and test coverage.
Changes:
- Adds function, implicit, parametric, polar, points, polyline, and vector plot support with localized tool guidance and trust-level configuration.
- Adds lazy-loaded client rendering with CSP-compatible parsing, tracing, snapping, pan/zoom, interval limits, and lifecycle cleanup.
- Adds pinned vendor build metadata, licensing, documentation, plugin version 3.1.9, and backend/browser/unit tests.
Open findings:
- Critical, 1 vote:
public/function-plot/build/pnpm-lock.yamlomits the directinterval-arithmetic-evalimporter dependency, causing documented frozen-lockfile builds to fail. - Critical, 3 votes:
public/function-plot/build/package.jsondeclaresinterval-arithmetic-evalwithout a matching lockfile importer entry, preventing reproducible vendor rebuilds. - Moderate, 1 vote: Client title-length validation counts UTF-16 code units rather than Unicode code points, rejecting some valid non-BMP titles.
- Moderate, 1 vote: Tracing accepts endpoint zeroes before checking discontinuity, allowing false snapping targets at jumps such as
floor(x).
| File | Description |
|---|---|
test/javascripts/unit/function-plot-trace-test.js |
Tests tracing, snapping, intersections, poles, and domain gaps. |
test/javascripts/unit/function-plot-renderer-test.js |
Tests interval evaluation and undefined-domain segmentation. |
test/javascripts/unit/function-plot-expression-test.js |
Tests expression parsing and graph-definition validation. |
spec/system/read_function_plots_spec.rb |
Covers rendering, fallbacks, tracing, plot families, and pan/zoom. |
spec/system/page_objects/components/function_plots.rb |
Provides graph-specific system-test helpers. |
spec/lib/tools/function_plot_spec.rb |
Tests tool arguments, output, validation, graph families, and escaping. |
spec/lib/site_setting_dependencies_spec.rb |
Updates expected default tool lists. |
spec/lib/bot_function_plot_spec.rb |
Tests tool selection and model/tool/model integration. |
README.md |
Documents graph syntax, limits, behavior, configuration, and fallbacks. |
public/function-plot/README.md |
Documents the pinned vendor bundle, rebuild process, licenses, and checksum. |
public/function-plot/build/pnpm-lock.yaml |
Locks vendor build dependencies. |
public/function-plot/build/package.json |
Defines pinned vendor build dependencies and scripts. |
public/function-plot/build/entry.js |
Exposes the renderer and interval arithmetic to the browser. |
public/function-plot/build/build.mjs |
Builds the vendor bundle and generates license notices. |
public/function-plot/1.26.0/THIRD-PARTY-LICENSES.txt |
Provides third-party dependency license notices. |
public/function-plot/1.26.0/LICENSE |
Provides the renderer license. |
plugin.rb |
Bumps the plugin version to 3.1.9. |
lib/discourse_chatbot/tools/function_plot.rb |
Defines the plot_function tool interface and processing. |
lib/discourse_chatbot/tool.rb |
Registers plot_function as a built-in tool. |
lib/discourse_chatbot/function_plot.rb |
Validates graph inputs and produces fenced graph definitions. |
lib/discourse_chatbot/bot.rb |
Adds graph-tool eligibility and feature-setting checks. |
config/settings.yml |
Adds the rendering setting and trust-level tool defaults. |
config/locales/server.en.yml |
Adds tool descriptions, parameter guidance, and correction messages. |
config/locales/client.en.yml |
Adds graph loading, fallback, tracing, and help strings. |
assets/stylesheets/common/chatbot_common.scss |
Styles graph containers, legends, coordinates, and errors. |
assets/javascripts/discourse/lib/function-plot-trace.js |
Implements axis and series-intersection snapping. |
assets/javascripts/discourse/lib/function-plot-renderer.js |
Integrates the bundled renderer, interval evaluation, graph families, and tracing. |
assets/javascripts/discourse/lib/function-plot-expression.js |
Parses and validates graph definitions and mathematical expressions. |
assets/javascripts/discourse/initializers/function-plot.js |
Decorates cooked content and Chat messages with graph components. |
assets/javascripts/discourse/components/function-plot-block.gjs |
Manages graph rendering, lazy loading, interaction, cleanup, and fallbacks. |
Review effort: Lite
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Chatbot can pair mathematical explanations with interactive 2D graphs rendered locally using function-plot 1.26.0. The renderer and one
plot_functiontool ship together, including posts, PMs, previews and Chat.Supported plot types are documented here and in the README:
plot_typeexpressionsformat, one entry per linefunction(default)sin(x)for y=f(x)implicitx^2+y^2-4for F(x,y)=0parametriccos(t); sin(t)for x(t); y(t)polar2*cos(3*theta)for r(theta)points1,2for x,y scatter pointspolyline1,2for connected x,y points in supplied ordervector3,2for dx,dy from the origin;1,1,3,2for x0,y0,dx,dyEach graph uses one family. Keep the tool interface to nine fields: expressions, title, plot type, four axis bounds and two optional parameter bounds. The parameter bounds select t/theta for parametric/polar curves and are ignored for other families, including strict-schema placeholders. Axes default to [-10,10]; t/theta defaults to [0,2*pi]. Existing 2D
functionsfences retain their format. 3D surfaces are unsupported.plot_functionin low, medium and high trust defaults while preserving customised lists.chatbot_function_plot_enableddefaults to true and controls rendering and tool eligibility. Use the existing System One tool-selection pipeline.cbrt(...).Tracing applies to ordinary function curves; the other families support pan/zoom. Graphs and snapping are numerical approximations; tangencies can be missed. Pole, discontinuity and coincident-series checks prevent false snapping targets.
Validation:
pnpm lintpassed (JavaScript, SCSS, formatting and types). Ruby formatting/RuboCop, YAML parsing andgit diff --checkpassed. The pinned pnpm vendor build reproduced its checksum.Backend/browser checks used the local Discourse checkout with automation, chat, discourse-local-dates and discourse-chatbot loaded, plus the local plugin-test bootstrap. QUnit used a single-thread Puma test server within the test database connection limit.