1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-11 08:06:13 +01:00
phorge-phorge/webroot/rsrc/js/application/fact/ChartCurtainView.js
epriestley a80426b339 Provide chart function labels over the wire instead of making them up
Summary: Ref T13279. Makes charts incrementally more useful by allowing the server to provide labels and colors for functions.

Test Plan: {F6438872}

Reviewers: amckinley

Reviewed By: amckinley

Subscribers: yelirekim

Maniphest Tasks: T13279

Differential Revision: https://secure.phabricator.com/D20501
2019-05-22 05:22:59 -07:00

89 lines
1.8 KiB
JavaScript

/**
* @provides javelin-chart-curtain-view
*/
JX.install('ChartCurtainView', {
construct: function() {
this._labels = [];
},
members: {
_node: null,
_labels: null,
_labelsNode: null,
getNode: function() {
if (!this._node) {
var attr = {
className: 'chart-curtain'
};
this._node = JX.$N('div', attr);
}
return this._node;
},
reset: function() {
this._labels = [];
},
addFunctionLabel: function(label) {
this._labels.push(label);
return this;
},
redraw: function() {
var content = [this._getFunctionLabelsNode()];
JX.DOM.setContent(this.getNode(), content);
return this;
},
_getFunctionLabelsNode: function() {
if (!this._labels.length) {
return null;
}
if (!this._labelsNode) {
var list_attrs = {
className: 'chart-function-label-list'
};
var labels = JX.$N('ul', list_attrs);
var items = [];
for (var ii = 0; ii < this._labels.length; ii++) {
items.push(this._newFunctionLabelItem(this._labels[ii]));
}
JX.DOM.setContent(labels, items);
this._labelsNode = labels;
}
return this._labelsNode;
},
_newFunctionLabelItem: function(label) {
var item_attrs = {
className: 'chart-function-label-list-item'
};
var icon = new JX.PHUIXIconView()
.setIcon(label.getIcon());
// Charts may use custom colors, so we can't rely on the CSS classes
// which only provide standard colors like "red" and "blue".
icon.getNode().style.color = label.getColor();
var content = [
icon.getNode(),
label.getName()
];
return JX.$N('li', item_attrs, content);
}
}
});