added color customization by nadr0 · Pull Request #188 · algorithm-visualizer/algorithm-visualizer · GitHub
Skip to content
Merged
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
21 changes: 12 additions & 9 deletions js/module/tracer/array2d.js
14 changes: 6 additions & 8 deletions js/module/tracer/chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@ class ChartTracer extends Tracer {
constructor(name) {
super(name);

this.color = {
selected: '#2962ff',
notified: '#c51162',
default: 'rgb(136, 136, 136)'
};
this.selectColor = '#2962ff';
this.notifyColor = '#c51162';
this.defaultColor = 'rgb(136, 136, 136)';

if (this.isNew) initView(this);
}
Expand All @@ -27,7 +25,7 @@ class ChartTracer extends Tracer {
}

var color = [];
for (var i = 0; i < C.length; i++) color.push(this.color.default);
for (var i = 0; i < C.length; i++) color.push(this.defaultColor);
this.chart.config.data = {
labels: C.map(String),
datasets: [{
Expand Down Expand Up @@ -83,7 +81,7 @@ class ChartTracer extends Tracer {
case 'denotify':
case 'select':
case 'deselect':
let color = step.type == 'notify' ? this.color.notified : step.type == 'select' ? this.color.selected : this.color.default;
let color = step.type == 'notify' ? this.notifyColor : step.type == 'select' ? this.selectColor : this.defaultColor;
if (step.e !== undefined)
for (var i = step.s; i <= step.e; i++)
this.chart.config.data.datasets[0].backgroundColor[i] = color;
Expand All @@ -109,7 +107,7 @@ class ChartTracer extends Tracer {
if (data.datasets.length) {
const backgroundColor = data.datasets[0].backgroundColor;
for (let i = 0; i < backgroundColor.length; i++) {
backgroundColor[i] = this.color.default;
backgroundColor[i] = this.defaultColor;
}
this.chart.update();
}
Expand Down
4 changes: 2 additions & 2 deletions js/module/tracer/coordinate_system.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class CoordinateSystemTracer extends DirectedGraphTracer {
y: C[i][1],
label: '' + i,
size: 1,
color: this.color.default
color: this.defaultColor
});
this.graph.read({
nodes: nodes,
Expand All @@ -49,7 +49,7 @@ class CoordinateSystemTracer extends DirectedGraphTracer {
case 'leave':
var visit = step.type == 'visit';
var targetNode = this.graph.nodes(this.n(step.target));
var color = visit ? this.color.visited : this.color.left;
var color = visit ? this.visitedColor : this.leftColor;
targetNode.color = color;
if (step.source !== undefined) {
var edgeId = this.e(step.source, step.target);
Expand Down
22 changes: 10 additions & 12 deletions js/module/tracer/directed_graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,10 @@ class DirectedGraphTracer extends Tracer {
constructor(name) {
super(name);

this.color = {
selected: '#2962ff',
visited: '#f50057',
left: '#616161',
default: '#bdbdbd'
};
this.selectColor = '#2962ff';
this.visitedColor = '#f50057';
this.leftColor = '#616161';
this.defaultColor = '#bdbdbd';

if (this.isNew) initView(this);
}
Expand Down Expand Up @@ -59,7 +57,7 @@ class DirectedGraphTracer extends Tracer {
case 'leave':
var visit = step.type == 'visit';
var targetNode = this.graph.nodes(this.n(step.target));
var color = visit ? this.color.visited : this.color.left;
var color = visit ? this.visitedColor : this.leftColor;
targetNode.color = color;
if (step.source !== undefined) {
var edgeId = this.e(step.source, step.target);
Expand Down Expand Up @@ -137,7 +135,7 @@ class DirectedGraphTracer extends Tracer {
x: .5 + Math.sin(currentAngle) / 2,
y: .5 + Math.cos(currentAngle) / 2,
size: 1,
color: this.color.default,
color: this.defaultColor,
weight: 0
});

Expand All @@ -149,7 +147,7 @@ class DirectedGraphTracer extends Tracer {
id: this.e(i, j),
source: this.n(i),
target: this.n(j),
color: this.color.default,
color: this.defaultColor,
size: 1,
weight: refineByType(value)
});
Expand All @@ -162,7 +160,7 @@ class DirectedGraphTracer extends Tracer {
id: this.e(i, j),
source: this.n(i),
target: this.n(j),
color: this.color.default,
color: this.defaultColor,
size: 1,
weight: refineByType(G[i][j])
});
Expand Down Expand Up @@ -210,10 +208,10 @@ class DirectedGraphTracer extends Tracer {
var tracer = this;

this.graph.nodes().forEach(function (node) {
node.color = tracer.color.default;
node.color = tracer.defaultColor;
});
this.graph.edges().forEach(function (edge) {
edge.color = tracer.color.default;
edge.color = tracer.defaultColor;
});
}

Expand Down
26 changes: 26 additions & 0 deletions js/module/tracer/tracer.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ class Tracer {
constructor(name) {
this.module = this.constructor;

this.selectColor;
this.notifyColor;
this.defaultColor;
this.leftColor;
this.visitedColor;

this.manager = app.getTracerManager();
this.capsule = this.manager.allocate(this);
$.extend(this, this.capsule);
Expand Down Expand Up @@ -42,6 +48,26 @@ class Tracer {
return this;
}

_setSelectFillColor(c) {
this.selectColor = c;
}

_setNotifyFillColor(c) {
this.notifyColor = c;
}

_setDefaultFillColor(c){
this.defaultColor = c;
}

_setLeftFillColor(c){
this.leftColor = c;
}

_setVisitedFillColor(c){
this.visitedColor = c;
}

processStep(step, options) {
const {
type,
Expand Down
2 changes: 1 addition & 1 deletion js/module/tracer/weighted_directed_graph.js