Skip to content

Commit 92e1516

Browse files
committed
fix(ui): mixed types tooltip
- debounce to add tooltip at the right time
1 parent bdf2707 commit 92e1516

File tree

4 files changed

+30
-16
lines changed

4 files changed

+30
-16
lines changed

scout-ui/package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,23 +51,23 @@
5151
"ampersand-view": "^7.0.1",
5252
"ampersand-view-switcher": "^2.0.0",
5353
"bootstrap": "https://github.com/twbs/bootstrap/archive/v3.3.2.tar.gz",
54+
"d3": "^3.5.5",
55+
"d3-tip": "^0.6.7",
5456
"debug": "^2.0.0",
5557
"domready": "^1.0.7",
5658
"event-stream": "^3.3.0",
5759
"flatnest": "^0.2.2",
5860
"font-awesome": "https://github.com/FortAwesome/Font-Awesome/archive/v4.3.0.tar.gz",
5961
"jade": "^1.9.2",
6062
"jquery": "^2.1.1",
63+
"lodash": "^3.8.0",
6164
"moment": "^2.8.2",
65+
"mongodb-schema": "git://github.com/mongodb-js/mongodb-schema.git#ampersand",
6266
"numeral": "^1.5.3",
6367
"octicons": "https://github.com/github/octicons/archive/v2.2.0.tar.gz",
6468
"phantomjs-polyfill": "0.0.1",
6569
"qs": "^2.2.4",
66-
"underscore": "^1.6.0",
67-
"mongodb-schema": "git://github.com/mongodb-js/mongodb-schema.git#ampersand",
68-
"d3": "^3.5.5",
69-
"d3-tip": "^0.6.7",
70-
"lodash": "^3.8.0"
70+
"underscore": "^1.6.0"
7171
},
7272
"devDependencies": {
7373
"browserify": "^9.0.3",

scout-ui/src/field-list/index.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ var MinichartView = require('../minicharts');
44
var FieldCollection = require('mongodb-schema').FieldCollection;
55
var ViewSwitcher = require('ampersand-view-switcher');
66
var _ = require('lodash');
7-
var debug = require('debug')('scout-ui:field-list');
87

98
var BasicFieldView = View.extend({
109
bindings: {
@@ -38,10 +37,10 @@ var BasicFieldView = View.extend({
3837
initialize: function() {
3938
var that = this;
4039
// the debounce cuts down computation time by a factor of 5-10 here
41-
this.model.on('change', _.debounce(function(model) {
40+
this.model.types.on('sync', _.debounce(function() {
4241
// for now pick first type, @todo: make the type bars clickable and toggle chart
43-
that.switchView(model.types.at(0));
44-
}, 100));
42+
that.switchView(that.model.types.at(0));
43+
}, 300));
4544
},
4645
render: function() {
4746
this.renderWithTemplate(this);

scout-ui/src/field-list/type-list-item.js

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
var AmpersandView = require('ampersand-view');
22
var $ = require('jquery');
33
var format = require('util').format;
4+
var _ = require('underscore');
5+
var numeral = require('numeral');
46

57
require('bootstrap/js/tooltip');
68

@@ -21,18 +23,27 @@ module.exports = AmpersandView.extend({
2123
{
2224
hook: 'bar',
2325
type: function(el) {
24-
var percent = Math.min(this.model.probability * 100, 100);
2526
$(el).css({
26-
width: percent + '%'
27+
width: Math.floor(this.model.probability * 100) + '%'
2728
});
28-
if (percent) {
29-
$(el).tooltip({
30-
title: format('%s (%d%)', this.model.getId(), percent)
31-
});
32-
}
3329
}
3430
}
3531
]
3632
},
33+
derived: {
34+
percent: {
35+
deps: ['model.probability'],
36+
fn: function() {
37+
return this.model.probability;
38+
}
39+
}
40+
},
41+
initialize: function() {
42+
this.listenTo(this.model, 'change:probability', _.debounce(function() {
43+
$(this.el).tooltip({
44+
title: format('%s (%s)', this.model.getId(), numeral(this.model.probability).format('%'))
45+
});
46+
}.bind(this), 300));
47+
},
3748
template: require('./type-list-item.jade')
3849
});

scout-ui/src/home/index.less

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,10 @@
102102
display: inline-block;
103103
}
104104

105+
&.schema-field-basic {
106+
min-height: 141px;
107+
}
108+
105109
&.schema-field-object, &.schema-field-array {
106110
.schema-field-name {
107111
cursor: pointer;

0 commit comments

Comments
 (0)