Skip to content

Commit

Permalink
Workshop sample data
Browse files Browse the repository at this point in the history
Boilerplate widgets

Signed-off-by: Gordon Smith <[email protected]>
  • Loading branch information
GordonSmith committed May 16, 2016
1 parent fc28c51 commit 474566a
Show file tree
Hide file tree
Showing 11 changed files with 1,959 additions and 127 deletions.
3 changes: 2 additions & 1 deletion demos/dermatology.html
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@
<script>
require.config({
paths: {
"test": "../test"
"test": "../test",
"templates": "../templates"
}
});
</script>
Expand Down
1 change: 1 addition & 0 deletions src/common/HTMLWidget.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
Widget.call(this);

this._drawStartPos = "origin";
this._tag = "div";
this._boundingBox = null;
}
HTMLWidget.prototype = Object.create(Widget.prototype);
Expand Down
8 changes: 8 additions & 0 deletions templates/HTMLTemplate.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.template_HTMLTemplate ul {
padding-left: 24px;
}

.template_HTMLTemplate .dataRow {
list-style-type: disc;
}

42 changes: 42 additions & 0 deletions templates/HTMLTemplate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
"use strict";
(function (root, factory) {
if (typeof define === "function" && define.amd) {
define(["src/common/HTMLWidget", "css!./HTMLTemplate"], factory);
} else {
root.template_HTMLTemplate = factory(root.common_HTMLWidget);
}
}(this, function (HTMLWidget) {
function HTMLTemplate(target) {
HTMLWidget.call(this);
}
HTMLTemplate.prototype = Object.create(HTMLWidget.prototype);
HTMLTemplate.prototype.constructor = HTMLTemplate;
HTMLTemplate.prototype._class += " template_HTMLTemplate";

HTMLTemplate.prototype.publish("stringProp", "defaultValue", "string", "Sample Property");

HTMLTemplate.prototype.enter = function (domNode, element) {
HTMLWidget.prototype.enter.apply(this, arguments);
this._ul = element.append("ul");
};

HTMLTemplate.prototype.update = function (domNode, element) {
HTMLWidget.prototype.update.apply(this, arguments);

var li = this._ul.selectAll(".dataRow").data(this.data());
li.enter().append("li")
.attr("class", "dataRow")
;
li
.text(function (row) { return row[0]; })
;
li.exit().remove();
};

HTMLTemplate.prototype.exit = function (domNode, element) {
this._ul.remove(); // Not really needed ---
HTMLWidget.prototype.exit.apply(this, arguments);
};

return HTMLTemplate;
}));
5 changes: 5 additions & 0 deletions templates/SVGTemplate.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.template_SVGTemplate .someItem {
stroke: green;
fill: navy;
}

51 changes: 51 additions & 0 deletions templates/SVGTemplate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
"use strict";
(function (root, factory) {
if (typeof define === "function" && define.amd) {
define(["src/common/SVGWidget", "css!./SVGTemplate"], factory);
} else {
root.template_SVGTemplate = factory(root.common_SVGWidget);
}
}(this, function (SVGWidget) {
function SVGTemplate(target) {
SVGWidget.call(this);
this._drawStartPos = "origin";
}
SVGTemplate.prototype = Object.create(SVGWidget.prototype);
SVGTemplate.prototype.constructor = SVGTemplate;
SVGTemplate.prototype._class += " template_SVGTemplate";

SVGTemplate.prototype.publish("stringProp", "defaultValue", "string", "Sample Property");

SVGTemplate.prototype.enter = function (domNode, element) {
SVGWidget.prototype.enter.apply(this, arguments);
};

SVGTemplate.prototype.update = function (domNode, element) {
SVGWidget.prototype.update.apply(this, arguments);

var g = element.selectAll(".dataRow").data(this.data());
g.enter().append("g")
.attr("class", "dataRow")
.each(function (d) {
var g = d3.select(this);
g.append("circle")
.attr("cx", -8)
.attr("cy", -4)
.attr("r", 4)
;
g.append("text");
})
;
g
.attr("transform", function (d, idx) { return "translate(32 " + ((idx + 1) * 16) + ")";})
;
g.select("text").text(function (row) { return row[0]; });
g.exit().remove();
};

SVGTemplate.prototype.exit = function (domNode, element) {
SVGWidget.prototype.exit.apply(this, arguments);
};

return SVGTemplate;
}));
Loading

0 comments on commit 474566a

Please sign in to comment.