Chart.js icon indicating copy to clipboard operation
Chart.js copied to clipboard

[FEATURE] Add new dataset.steppedLine type

Open bril-andrew opened this issue 9 years ago • 3 comments

FEATURE

Add new dataset.steppedLine type to simplify migration from Google Charts. Suggested type: middle (or any other name) Stepped lines in Google Charts begins outside bar-columns.

My current solution jsFiddle

Current Behavior

image

Google Charts Behavior

image

bril-andrew avatar Jun 14 '17 13:06 bril-andrew

@bril-andrew seems a good enhancement, can you submit a PR with docs and tests? @ericnkatz any thoughts, since you implemented before and after?

simonbrunel avatar Jul 01 '17 21:07 simonbrunel

@bril-andrew @simonbrunel looks good to me. I used 'before' and 'after' because that's what D3 called the two styles of interpolation.

ericnkatz avatar Jul 06 '17 23:07 ericnkatz

To obtain the desired 'middle' behaviour, wouldn't it suffice a small change to function lineTo in src/helpers/helpers.canvas.js? Something like adding these 5 lines (actually 4 when putting the else and following if in the same line):

    lineTo: function(ctx, previous, target, flip) {
        if (target.steppedLine) {
+            if (target.steppedLine === 'middle') {
+                var midx = (previous.x + target.x)/2;
+                ctx.lineTo(midx, previous.y);
+                ctx.lineTo(midx, target.y);
+            } else
             if ((target.steppedLine === 'after' && !flip) || (target.steppedLine !== 'after' && flip)) {

I guessed that the flip parameter should be a no-op in the case of 'middle'. Nevertheless, I am not familiar enough with the code, so this might be breaking stuff somewhere.

ccreus avatar May 16 '18 09:05 ccreus