提交 e01e4565 编写于 作者: J Jason Park 提交者: GitHub

Merge pull request #188 from nadr0/more-colors

added color customization
...@@ -14,10 +14,8 @@ class Array2DTracer extends Tracer { ...@@ -14,10 +14,8 @@ class Array2DTracer extends Tracer {
constructor(name) { constructor(name) {
super(name); super(name);
this.colorClass = { this.selectColor = '#2962ff';
selected: 'selected', this.notifyColor = '#c51162';
notified: 'notified'
};
if (this.isNew) initView(this); if (this.isNew) initView(this);
} }
...@@ -25,6 +23,7 @@ class Array2DTracer extends Tracer { ...@@ -25,6 +23,7 @@ class Array2DTracer extends Tracer {
_notify(x, y, v) { _notify(x, y, v) {
this.manager.pushStep(this.capsule, { this.manager.pushStep(this.capsule, {
type: 'notify', type: 'notify',
color: this.notifyColor,
x: x, x: x,
y: y, y: y,
v: v v: v
...@@ -146,7 +145,8 @@ class Array2DTracer extends Tracer { ...@@ -146,7 +145,8 @@ class Array2DTracer extends Tracer {
} }
} }
var step = { var step = {
type: type type: type,
color: this.selectColor
}; };
$.extend(step, coord); $.extend(step, coord);
this.manager.pushStep(this.capsule, step); this.manager.pushStep(this.capsule, step);
...@@ -163,7 +163,7 @@ class Array2DTracer extends Tracer { ...@@ -163,7 +163,7 @@ class Array2DTracer extends Tracer {
case 'denotify': case 'denotify':
case 'select': case 'select':
case 'deselect': case 'deselect':
var colorClass = step.type == 'select' || step.type == 'deselect' ? this.colorClass.selected : this.colorClass.notified; var colorClass = step.color;
var addClass = step.type == 'select' || step.type == 'notify'; var addClass = step.type == 'select' || step.type == 'notify';
var sx = step.sx; var sx = step.sx;
var sy = step.sy; var sy = step.sy;
...@@ -297,14 +297,17 @@ class Array2DTracer extends Tracer { ...@@ -297,14 +297,17 @@ class Array2DTracer extends Tracer {
var $row = this.$table.find('.mtbl-row').eq(i); var $row = this.$table.find('.mtbl-row').eq(i);
for (var j = sy; j <= ey; j++) { for (var j = sy; j <= ey; j++) {
var $col = $row.find('.mtbl-col').eq(j); var $col = $row.find('.mtbl-col').eq(j);
if (addClass) $col.addClass(colorClass); if(addClass) $col[0].style.backgroundColor = colorClass;
else $col.removeClass(colorClass); else $col[0].style.backgroundColor = "";
} }
} }
} }
clearColor() { clearColor() {
this.$table.find('.mtbl-col').removeClass(Object.keys(this.colorClass).join(' ')); var divs = this.$table.find('.mtbl-col');
for (var i = 0; i < divs.length; i++){
divs[i].style.backgroundColor = "";
}
} }
separate(x, y) { separate(x, y) {
......
...@@ -10,11 +10,9 @@ class ChartTracer extends Tracer { ...@@ -10,11 +10,9 @@ class ChartTracer extends Tracer {
constructor(name) { constructor(name) {
super(name); super(name);
this.color = { this.selectColor = '#2962ff';
selected: '#2962ff', this.notifyColor = '#c51162';
notified: '#c51162', this.defaultColor = 'rgb(136, 136, 136)';
default: 'rgb(136, 136, 136)'
};
if (this.isNew) initView(this); if (this.isNew) initView(this);
} }
...@@ -27,7 +25,7 @@ class ChartTracer extends Tracer { ...@@ -27,7 +25,7 @@ class ChartTracer extends Tracer {
} }
var color = []; 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 = { this.chart.config.data = {
labels: C.map(String), labels: C.map(String),
datasets: [{ datasets: [{
...@@ -83,7 +81,7 @@ class ChartTracer extends Tracer { ...@@ -83,7 +81,7 @@ class ChartTracer extends Tracer {
case 'denotify': case 'denotify':
case 'select': case 'select':
case 'deselect': 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) if (step.e !== undefined)
for (var i = step.s; i <= step.e; i++) for (var i = step.s; i <= step.e; i++)
this.chart.config.data.datasets[0].backgroundColor[i] = color; this.chart.config.data.datasets[0].backgroundColor[i] = color;
...@@ -109,7 +107,7 @@ class ChartTracer extends Tracer { ...@@ -109,7 +107,7 @@ class ChartTracer extends Tracer {
if (data.datasets.length) { if (data.datasets.length) {
const backgroundColor = data.datasets[0].backgroundColor; const backgroundColor = data.datasets[0].backgroundColor;
for (let i = 0; i < backgroundColor.length; i++) { for (let i = 0; i < backgroundColor.length; i++) {
backgroundColor[i] = this.color.default; backgroundColor[i] = this.defaultColor;
} }
this.chart.update(); this.chart.update();
} }
......
...@@ -26,7 +26,7 @@ class CoordinateSystemTracer extends DirectedGraphTracer { ...@@ -26,7 +26,7 @@ class CoordinateSystemTracer extends DirectedGraphTracer {
y: C[i][1], y: C[i][1],
label: '' + i, label: '' + i,
size: 1, size: 1,
color: this.color.default color: this.defaultColor
}); });
this.graph.read({ this.graph.read({
nodes: nodes, nodes: nodes,
...@@ -49,7 +49,7 @@ class CoordinateSystemTracer extends DirectedGraphTracer { ...@@ -49,7 +49,7 @@ class CoordinateSystemTracer extends DirectedGraphTracer {
case 'leave': case 'leave':
var visit = step.type == 'visit'; var visit = step.type == 'visit';
var targetNode = this.graph.nodes(this.n(step.target)); 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; targetNode.color = color;
if (step.source !== undefined) { if (step.source !== undefined) {
var edgeId = this.e(step.source, step.target); var edgeId = this.e(step.source, step.target);
......
...@@ -14,12 +14,10 @@ class DirectedGraphTracer extends Tracer { ...@@ -14,12 +14,10 @@ class DirectedGraphTracer extends Tracer {
constructor(name) { constructor(name) {
super(name); super(name);
this.color = { this.selectColor = '#2962ff';
selected: '#2962ff', this.visitedColor = '#f50057';
visited: '#f50057', this.leftColor = '#616161';
left: '#616161', this.defaultColor = '#bdbdbd';
default: '#bdbdbd'
};
if (this.isNew) initView(this); if (this.isNew) initView(this);
} }
...@@ -59,7 +57,7 @@ class DirectedGraphTracer extends Tracer { ...@@ -59,7 +57,7 @@ class DirectedGraphTracer extends Tracer {
case 'leave': case 'leave':
var visit = step.type == 'visit'; var visit = step.type == 'visit';
var targetNode = this.graph.nodes(this.n(step.target)); 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; targetNode.color = color;
if (step.source !== undefined) { if (step.source !== undefined) {
var edgeId = this.e(step.source, step.target); var edgeId = this.e(step.source, step.target);
...@@ -137,7 +135,7 @@ class DirectedGraphTracer extends Tracer { ...@@ -137,7 +135,7 @@ class DirectedGraphTracer extends Tracer {
x: .5 + Math.sin(currentAngle) / 2, x: .5 + Math.sin(currentAngle) / 2,
y: .5 + Math.cos(currentAngle) / 2, y: .5 + Math.cos(currentAngle) / 2,
size: 1, size: 1,
color: this.color.default, color: this.defaultColor,
weight: 0 weight: 0
}); });
...@@ -149,7 +147,7 @@ class DirectedGraphTracer extends Tracer { ...@@ -149,7 +147,7 @@ class DirectedGraphTracer extends Tracer {
id: this.e(i, j), id: this.e(i, j),
source: this.n(i), source: this.n(i),
target: this.n(j), target: this.n(j),
color: this.color.default, color: this.defaultColor,
size: 1, size: 1,
weight: refineByType(value) weight: refineByType(value)
}); });
...@@ -162,7 +160,7 @@ class DirectedGraphTracer extends Tracer { ...@@ -162,7 +160,7 @@ class DirectedGraphTracer extends Tracer {
id: this.e(i, j), id: this.e(i, j),
source: this.n(i), source: this.n(i),
target: this.n(j), target: this.n(j),
color: this.color.default, color: this.defaultColor,
size: 1, size: 1,
weight: refineByType(G[i][j]) weight: refineByType(G[i][j])
}); });
...@@ -210,10 +208,10 @@ class DirectedGraphTracer extends Tracer { ...@@ -210,10 +208,10 @@ class DirectedGraphTracer extends Tracer {
var tracer = this; var tracer = this;
this.graph.nodes().forEach(function (node) { this.graph.nodes().forEach(function (node) {
node.color = tracer.color.default; node.color = tracer.defaultColor;
}); });
this.graph.edges().forEach(function (edge) { this.graph.edges().forEach(function (edge) {
edge.color = tracer.color.default; edge.color = tracer.defaultColor;
}); });
} }
......
...@@ -15,6 +15,12 @@ class Tracer { ...@@ -15,6 +15,12 @@ class Tracer {
constructor(name) { constructor(name) {
this.module = this.constructor; this.module = this.constructor;
this.selectColor;
this.notifyColor;
this.defaultColor;
this.leftColor;
this.visitedColor;
this.manager = app.getTracerManager(); this.manager = app.getTracerManager();
this.capsule = this.manager.allocate(this); this.capsule = this.manager.allocate(this);
$.extend(this, this.capsule); $.extend(this, this.capsule);
...@@ -42,6 +48,26 @@ class Tracer { ...@@ -42,6 +48,26 @@ class Tracer {
return this; 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) { processStep(step, options) {
const { const {
type, type,
......
...@@ -56,7 +56,7 @@ class WeightedDirectedGraphTracer extends DirectedGraphTracer { ...@@ -56,7 +56,7 @@ class WeightedDirectedGraphTracer extends DirectedGraphTracer {
case 'leave': case 'leave':
var visit = step.type == 'visit'; var visit = step.type == 'visit';
var targetNode = this.graph.nodes(this.n(step.target)); var targetNode = this.graph.nodes(this.n(step.target));
var color = visit ? step.weight === undefined ? this.color.selected : this.color.visited : this.color.left; var color = visit ? step.weight === undefined ? this.selectColor : this.visitedColor : this.leftColor;
targetNode.color = color; targetNode.color = color;
if (step.weight !== undefined) targetNode.weight = refineByType(step.weight); if (step.weight !== undefined) targetNode.weight = refineByType(step.weight);
if (step.source !== undefined) { if (step.source !== undefined) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册