Skip to content

Make style configurable #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
"name": "Christian d'Heureuse",
"email": "[email protected]",
"url": "http://www.source-code.biz"
},
{
"name": "Sébastien Guimmara",
"email": "[email protected]",
"url": "https://github.com/sguimmara"
}
],
"scripts": {
Expand Down
38 changes: 29 additions & 9 deletions src/FunctionCurveEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,13 @@ class FunctionPlotter {
const xMin = (wctx.eState.relevantXMin != undefined) ? Math.max(0, Math.min(width, wctx.mapLogicalToCanvasXCoordinate(wctx.eState.relevantXMin))) : 0;
const xMax = (wctx.eState.relevantXMax != undefined) ? Math.max(xMin, Math.min(width, wctx.mapLogicalToCanvasXCoordinate(wctx.eState.relevantXMax))) : width;
if (xMin > 0) {
ctx.fillStyle = "#F8F8F8";
ctx.fillStyle = wctx.eState.secondaryBackground;
ctx.fillRect(0, 0, xMin, height); }
if (xMax > xMin) {
ctx.fillStyle = "#FFFFFF";
ctx.fillStyle = wctx.eState.background;
ctx.fillRect(xMin, 0, xMax - xMin, height); }
if (xMax < width) {
ctx.fillStyle = "#F8F8F8";
ctx.fillStyle = wctx.eState.secondaryBackground;
ctx.fillRect(xMax, 0, width - xMax, height); }
ctx.restore(); }

Expand All @@ -118,7 +118,7 @@ class FunctionPlotter {
const r = bold ? 5 : 4;
ctx.arc(point.x, point.y, r, 0, 2 * Math.PI);
ctx.lineWidth = bold ? 3 : 1;
ctx.strokeStyle = (isDragging || isPotential) ? "#EE5500" : isSelected ? "#0080FF" : "#CC4444";
ctx.strokeStyle = (isDragging || isPotential) ? wctx.eState.activeKnotColor : isSelected ? wctx.eState.selectedKnotColor : wctx.eState.defaultKnotColor;
ctx.stroke();
ctx.restore(); }

Expand All @@ -139,7 +139,7 @@ class FunctionPlotter {
ctx.save();
ctx.textBaseline = "bottom";
ctx.font = "12px";
ctx.fillStyle = "#707070";
ctx.fillStyle = wctx.eState.labelColor;
const x = xy ? cPos + 5 : 5;
const y = xy ? wctx.canvas.height - 2 : cPos - 2;
const s = this.formatLabel(value, decPow);
Expand All @@ -150,7 +150,7 @@ class FunctionPlotter {
const wctx = this.wctx;
const ctx = this.ctx;
ctx.save();
ctx.fillStyle = (p == 0) ? "#989898" : (p % 10 == 0) ? "#D4D4D4" : "#EEEEEE";
ctx.fillStyle = (p == 0) ? wctx.eState.axisColor : (p % 10 == 0) ? wctx.eState.secondaryLineColor : wctx.eState.primaryLineColor;
ctx.fillRect(xy ? cPos : 0, xy ? 0 : cPos, xy ? 1 : wctx.canvas.width, xy ? wctx.canvas.height : 1);
ctx.restore(); }

Expand Down Expand Up @@ -188,7 +188,7 @@ class FunctionPlotter {
const ly = uniFunction(lx);
const cy = Math.max(-1E6, Math.min(1E6, wctx.mapLogicalToCanvasYCoordinate(ly)));
ctx.lineTo(cx, cy); }
ctx.strokeStyle = "#44CC44";
ctx.strokeStyle = wctx.eState.curveColor;
ctx.stroke();
ctx.restore(); }

Expand Down Expand Up @@ -1055,7 +1055,17 @@ export interface EditorState {
snapToGridEnabled: boolean; // true to enable snap to grid behavior
interpolationMethod: InterpolationMethod; // optimal interpolation method
primaryZoomMode: ZoomMode; // zoom mode to be used for mouse wheel when no shift/alt/ctrl-Key is pressed
focusShield: boolean; } // true to ignore mouse wheel events without focus
focusShield: boolean; // true to ignore mouse wheel events without focus
curveColor: string; // CSS color for the curve
defaultKnotColor: string; // default CSS color of knots
selectedKnotColor: string; // CSS color of selected knots
activeKnotColor: string; // default CSS color of active knot
labelColor: string; // CSS color of labels
primaryLineColor: string; // CSS color for primary lines
secondaryLineColor: string; // CSS color for secondary lines
axisColor: string; // CSS color for axes
background: string; // CSS color for background
secondaryBackground: string; } // CSS color for out of domain background

// Clones and adds missing fields.
function cloneEditorState (eState: Partial<EditorState>) : EditorState {
Expand All @@ -1072,7 +1082,17 @@ function cloneEditorState (eState: Partial<EditorState>) : EditorState {
snapToGridEnabled: eState.snapToGridEnabled ?? true,
interpolationMethod: eState.interpolationMethod ?? "akima",
primaryZoomMode: eState.primaryZoomMode ?? ZoomMode.xy,
focusShield: eState.focusShield ?? false }; }
focusShield: eState.focusShield ?? false,
curveColor: eState.curveColor ?? "#44CC44",
defaultKnotColor: eState.defaultKnotColor ?? "#CC4444",
selectedKnotColor: eState.selectedKnotColor ?? "#0080FF",
activeKnotColor: eState.activeKnotColor ?? "#EE5500",
labelColor: eState.labelColor ?? "#707070",
axisColor: eState.axisColor ?? "#989898",
secondaryLineColor: eState.secondaryLineColor ?? "#D4D4D4",
primaryLineColor: eState.primaryLineColor ?? "#EEEEEE",
secondaryBackground: eState.secondaryBackground ?? "#F8F8F8",
background: eState.background ?? "#FFFFFF" }; }

//--- Widget -------------------------------------------------------------------

Expand Down