Skip to content

Commit

Permalink
closes andredumas#152, refs andredumas#49: Perform an additional volu…
Browse files Browse the repository at this point in the history
…me select if not using up down append
  • Loading branch information
andredumas committed Sep 15, 2016
1 parent b11f213 commit fcb12dd
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 19 deletions.
9 changes: 7 additions & 2 deletions src/plot/volume.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,25 @@ module.exports = function(accessor_volume, plot, plotMixin) { // Injected depen
function volume(g) {
var group = p.dataSelector(g);

if(p.accessor.o && p.accessor.c) plot.appendPathsUpDownEqual(group.selection, p.accessor, 'volume');
if(isOhlcAccessor()) plot.appendPathsUpDownEqual(group.selection, p.accessor, 'volume');
else group.entry.append('path').attr('class', 'volume');

volume.refresh(g);
}

volume.refresh = function(g) {
g.selectAll('path.volume').attr('d', volumeGenerator);
if(isOhlcAccessor()) g.selectAll('path.volume').attr('d', volumeGenerator);
else p.dataSelector.select(g).select('path.volume').attr('d', volumeGenerator);
};

function binder() {
volumeGenerator = plot.joinPath(volumePath);
}

function isOhlcAccessor() {
return p.accessor.o && p.accessor.c;
}

function volumePath() {
var accessor = p.accessor,
x = p.xScale,
Expand Down
44 changes: 27 additions & 17 deletions test/spec/bundle/plot/volumeSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,22 @@ techanModule('plot/volume', function(specBuilder) {
childElements = scope.childElements;
});

describe('And on obtaining the data element', function() {
it('Then contains a single volume', function() {
expect(childElements[0].outerHTML)
.toEqual('<path class="volume" d="M -0.32894736842105265 0 l 0 10 l 1 0 l 0 -10 M 0 0 l 0 100 l 1 0 l 0 -100 M 0.32894736842105265 0 l 0 1 l 1 0 l 0 -1"></path>');
it('Then contains a single volume', function() {
expect(childElements[0].outerHTML)
.toEqual('<path class="volume" d="M -0.32894736842105265 0 l 0 10 l 1 0 l 0 -10 M 0 0 l 0 100 l 1 0 l 0 -100 M 0.32894736842105265 0 l 0 1 l 1 0 l 0 -1"></path>');
});

describe('And data is updated (cleared) and redrawn', function() {
var g;

beforeEach(function() {
g = scope.g;
g.datum([]);
scope.plot(g);
});

it('Then contain an empty volume path', function() {
expect(g[0][0].innerHTML).toBe('<g class="data"><path class="volume"></path></g>');
});
});
}
Expand All @@ -52,21 +64,19 @@ techanModule('plot/volume', function(specBuilder) {
childElements = scope.childElements;
});

describe('And on obtaining the data element', function() {
it('Then contains a up', function() {
expect(childElements[0].outerHTML)
.toEqual('<path class="volume up" d="M -0.32894736842105265 0 l 0 10 l 1 0 l 0 -10"></path>');
});
it('Then contains a up', function() {
expect(childElements[0].outerHTML)
.toEqual('<path class="volume up" d="M -0.32894736842105265 0 l 0 10 l 1 0 l 0 -10"></path>');
});

it('Then contains a down', function() {
expect(childElements[1].outerHTML)
.toEqual('<path class="volume down" d="M 0 0 l 0 100 l 1 0 l 0 -100"></path>');
});
it('Then contains a down', function() {
expect(childElements[1].outerHTML)
.toEqual('<path class="volume down" d="M 0 0 l 0 100 l 1 0 l 0 -100"></path>');
});

it('Then contains a equal', function() {
expect(childElements[2].outerHTML)
.toEqual('<path class="volume equal" d="M 0.32894736842105265 0 l 0 1 l 1 0 l 0 -1"></path>');
});
it('Then contains a equal', function() {
expect(childElements[2].outerHTML)
.toEqual('<path class="volume equal" d="M 0.32894736842105265 0 l 0 1 l 1 0 l 0 -1"></path>');
});
}
});
Expand Down

0 comments on commit fcb12dd

Please sign in to comment.