123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- define([
- "dojo/_base/declare",
- "dojo/_base/lang",
- "./DojoD3",
- "./Mapping",
- "dojo/text!./templates/DojoD3ScatterChart.css"
- ], function (declare, lang,
- DojoD3, Mapping,
- css) {
- return declare([Mapping, DojoD3], {
- mapping: {
- barChart: {
- display: "Bar Chart Data",
- fields: {
- x: "x",
- y: "y"
- }
- }
- },
- constructor: function (mappings, target) {
- if (mappings)
- this.setFieldMappings(mappings);
- if (target)
- this.renderTo(target);
- },
- renderTo: function (_target) {
- _target = lang.mixin({
- css: css,
- margin: { top: 0, right: 0, bottom: 20, left: 50 }
- }, _target);
- this.inherited(arguments);
- this.SvgG
- .style("fill", "none")
- ;
- this.x = d3.scale.linear()
- .domain([0, 10])
- .range([0, this.target.width - (this.target.margin.left + this.target.margin.right)])
- ;
- this.y = d3.scale.linear()
- .domain([0, 10])
- .range([this.target.height - (this.target.margin.top + this.target.margin.bottom), 0])
- ;
- this.xAxis = d3.svg.axis()
- .scale(this.x)
- .orient("bottom")
- ;
- this.yAxis = d3.svg.axis()
- .scale(this.y)
- .orient("left")
- ;
- this.SvgG
- .attr("transform", "translate(" + this.target.margin.left + "," + this.target.margin.top + ")")
- ;
- this.SvgX = this.Svg.append("g")
- .attr("transform", "translate(" + this.target.margin.left + "," + (this.target.height - this.target.margin.bottom) + ")")
- .attr("class", "x axis")
- .call(this.xAxis)
- ;
- this.SvgY = this.Svg.append("g")
- .attr("transform", "translate(" + this.target.margin.left + "," + this.target.margin.top + ")")
- .attr("class", "y axis")
- .call(this.yAxis)
- ;
- this.update([]);
- },
- display: function (data) {
- if (data)
- this.setData(data);
- var data = this.getMappedData();
- this.x.domain([d3.min(data, function (d) { return d.x; }), d3.max(data, function (d) { return d.x; })]);
- this.y.domain([d3.min(data, function (d) { return d.y; }), d3.max(data, function (d) { return d.y; })]);
- this.Svg.selectAll("g.y.axis").transition()
- .call(this.yAxis)
- ;
- this.Svg.selectAll("g.x.axis").transition()
- .call(this.xAxis)
- ;
- this.update(data);
- },
- update: function (data) {
- this.SvgG.selectAll(".dot").remove();
- var dot = this.SvgG.selectAll(".scatterDot").data(data);
- var x = dot.enter().append("g")
- .attr("class", "dot")
- ;
- x.append("line")
- .attr("x1", lang.hitch(this, function (d) { return this.x(d.x) - 4; }))
- .attr("y1", lang.hitch(this, function (d) { return this.y(d.y) - 4; }))
- .attr("x2", lang.hitch(this, function (d) { return this.x(d.x) + 4; }))
- .attr("y2", lang.hitch(this, function (d) { return this.y(d.y) + 4; }))
- ;
- x.append("line")
- .attr("x1", lang.hitch(this, function (d) { return this.x(d.x) - 4; }))
- .attr("y1", lang.hitch(this, function (d) { return this.y(d.y) + 4; }))
- .attr("x2", lang.hitch(this, function (d) { return this.x(d.x) + 4; }))
- .attr("y2", lang.hitch(this, function (d) { return this.y(d.y) - 4; }))
- ;
- }
- });
- });
|