Skip to content

Commit

Permalink
GPII-1584: begin implementing transitions
Browse files Browse the repository at this point in the history
  • Loading branch information
waharnum committed Mar 8, 2016
1 parent 33ca0fd commit 3ae0c3d
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 18 deletions.
53 changes: 39 additions & 14 deletions public/src/js/line.js
Expand Up @@ -46,7 +46,9 @@ https://raw.githubusercontent.com/fluid-project/chartAuthoring/master/LICENSE.tx
addArea: false,
// Whether or not to add a point to each datapoint forming the line
addPoints: false,
pointRadius: 2
pointRadius: 2,
// In milliseconds
transitionLength: 2000
},
styles: {
svg: "floe-ca-lineChart-chart",
Expand Down Expand Up @@ -157,7 +159,7 @@ https://raw.githubusercontent.com/fluid-project/chartAuthoring/master/LICENSE.tx
// Remove any older drawn elements from a previous dataset
that.locate("xAxis").remove();
that.locate("yAxis").remove();
that.locate("chartLine").remove();
// that.locate("chartLine").remove();
that.locate("chartLinePoint").remove();
};

Expand Down Expand Up @@ -190,20 +192,43 @@ https://raw.githubusercontent.com/fluid-project/chartAuthoring/master/LICENSE.tx
var dataSet = that.model.wrappedDataSet,
chartLineClass = that.classes.chartLine,
svg = that.svg,
color = that.colorScale;
color = that.colorScale,
transitionLength = that.options.lineOptions.transitionLength;

// Append the line based on the dataset
fluid.each(dataSet, function (setItem, idx) {
svg.append("path")
.data([setItem.data])
.attr({
"class": chartLineClass,
"fill": "none",
"stroke": color(idx),
"d": that.line
});
});
// Bind data
var chartLinePaths = svg.selectAll("path")
.data(dataSet, function (d) {
return d.id;
});

// Append lines where needed
chartLinePaths.enter()
.append("path")
.attr({
"class": chartLineClass,
"fill": "none",
"stroke": function (d, idx) {
return color(idx);

},
"d": function (d) {
return that.line(d.data);
}

});

// Remove any removed lines
chartLinePaths.exit().remove();

// Transition lines where needed
var transitionPaths = svg.selectAll("." + chartLineClass);

transitionPaths.transition().duration(transitionLength)
.attr({
"d": function (d) {
return that.line(d.data);
}
});
};

floe.chartAuthoring.lineChart.chart.addArea = function (that) {
Expand Down
10 changes: 6 additions & 4 deletions public/tests/js/lineTests.js
Expand Up @@ -473,6 +473,7 @@ https://raw.githubusercontent.com/fluid-project/chartAuthoring/master/LICENSE.tx

fluid.each(chartLines, function (chartLine, idx) {
jqUnit.assertNotEquals("The chart line element is created with the proper selector", 0, chartLine.length);

floe.tests.chartAuthoring.validateBoundData(chartLine, expectedDataSet[idx].data);
});
};
Expand All @@ -481,7 +482,7 @@ https://raw.githubusercontent.com/fluid-project/chartAuthoring/master/LICENSE.tx
// dataset, checks that the data is bound and matches the dataset
floe.tests.chartAuthoring.validateBoundData = function (boundElement, expectedDataSet) {

var boundElementData = boundElement.__data__ !== undefined ? boundElement.__data__ : boundElement[0].__data__;
var boundElementData = boundElement.__data__ !== undefined ? boundElement.__data__.data : boundElement[0].__data__.data;

jqUnit.assertEquals("The length of the bound data is the same as that of the expected dataset", expectedDataSet.length, boundElementData.length);

Expand All @@ -497,7 +498,7 @@ https://raw.githubusercontent.com/fluid-project/chartAuthoring/master/LICENSE.tx
lineDescId = that.locate("description").attr("id"),
lineAriaLabelledByAttr = chart.attr("aria-labelledby"),
shouldHaveArea = that.options.lineOptions.addArea,
shouldHavPoints = that.options.lineOptions.addPoints;
shouldHavePoints = that.options.lineOptions.addPoints;

jqUnit.assertNotEquals("The SVG element is created with the proper selector", 0, chart.length);

Expand Down Expand Up @@ -530,7 +531,7 @@ https://raw.githubusercontent.com/fluid-project/chartAuthoring/master/LICENSE.tx
});
}

if (shouldHavPoints) {
if (shouldHavePoints) {
var chartLinePointGroups = that.locate("chartLinePointGroup");

jqUnit.assertNotEquals("The chart line point group element is created with the proper selector", 0, chartLinePointGroups.length);
Expand Down Expand Up @@ -569,7 +570,8 @@ https://raw.githubusercontent.com/fluid-project/chartAuthoring/master/LICENSE.tx
},
lineOptions: {
addArea: true,
addPoints: true
addPoints: true,
interpolation: "cardinal"
}
});

Expand Down

0 comments on commit 3ae0c3d

Please sign in to comment.