Skip to content

Commit

Permalink
fix(data): babel transform bug
Browse files Browse the repository at this point in the history
Correct the different transpiling result among env.

Fix #17 
Close #18
  • Loading branch information
sculove authored and netil committed Jun 21, 2017
1 parent 7ff837a commit 1f8efc2
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 21 deletions.
22 changes: 11 additions & 11 deletions spec/axis-spec.js
Expand Up @@ -278,9 +278,9 @@ describe("Axis", function() {
expect(tspan.attr("x")).to.be.equal(expectedX);

if (i === 0) {
expect(tspan.attr("dy")).to.be.equal(".71em");
expect(parseFloat(tspan.attr("dy"))).to.be.equal(0.71);
} else {
expect(tspan.attr("dy")).to.be.above(8);
expect(parseFloat(tspan.attr("dy"))).to.be.above(8);
}
});
});
Expand Down Expand Up @@ -377,9 +377,9 @@ describe("Axis", function() {
expect(tspan.attr("x")).to.be.equal(expectedX);

if (i === 0) {
expect(tspan.attr("dy")).to.be.below(0);
expect(parseFloat(tspan.attr("dy"))).to.be.below(0);
} else {
expect(tspan.attr("dy")).to.be.above(9);
expect(parseFloat(tspan.attr("dy"))).to.be.above(9);
}
});
});
Expand Down Expand Up @@ -483,9 +483,9 @@ describe("Axis", function() {

// unable to define pricise number because it differs depends on environment..
if (i === 0) {
expect(tspan.attr("dy")).to.be.equal(".71em");
expect(parseFloat(tspan.attr("dy"))).to.be.equal(0.71);
} else {
expect(tspan.attr("dy")).to.be.above(8);
expect(parseFloat(tspan.attr("dy"))).to.be.above(8);
}
});
});
Expand Down Expand Up @@ -538,9 +538,9 @@ describe("Axis", function() {

// unable to define pricise number because it differs depends on environment..
if (i === 0) {
expect(tspan.attr("dy")).to.be.below(0);
expect(parseFloat(tspan.attr("dy"))).to.be.below(0);
} else {
expect(tspan.attr("dy")).to.be.above(8);
expect(parseFloat(tspan.attr("dy"))).to.be.above(8);
}
});
});
Expand Down Expand Up @@ -594,9 +594,9 @@ describe("Axis", function() {

// unable to define pricise number because it differs depends on environment..
if (i === 0) {
expect(tspan.attr("dy")).to.be.below(0);
expect(parseFloat(tspan.attr("dy"))).to.be.below(0);
} else {
expect(tspan.attr("dy")).to.be.above(8);
expect(parseFloat(tspan.attr("dy"))).to.be.above(8);
}
});
});
Expand Down Expand Up @@ -708,7 +708,7 @@ describe("Axis", function() {
const text = tick.select("text");
const tspan = text.select("tspan");

expect(Math.round(text.attr("transform").replace(/\D/g, ""))).to.be.equal(45);
expect(Math.round(text.attr("transform").replace(/[A-z()]/g, ""))).to.be.equal(45);
expect(text.attr("y")).to.be.equal("4");
expect(parseFloat(tspan.attr("dx"))).to.be.closeTo(5.6, 0.5);
});
Expand Down
28 changes: 28 additions & 0 deletions spec/data-spec.js
Expand Up @@ -1387,4 +1387,32 @@ describe("Data", () => {
});
});
});

describe("inner functions", () => {
it("should check returns of mapToTargetIds", () => {
// Given
let data = [1, 2, 3];
// When
let newData = chart.internal.mapToTargetIds(data);
// Then
expect(newData).to.deep.equal(data);
expect(newData).to.not.equal(data);

// Given
data = 1;
// When
newData = chart.internal.mapToTargetIds(data);
// Then
expect(newData).to.deep.equal([data]);
expect(newData).to.not.equal([data]);

// Given
data = chart.internal.data.targets.map(d => d.id);
// When
newData = chart.internal.mapToTargetIds();
// Then
expect(newData).to.deep.equal(data);
expect(newData).to.not.equal(data);
});
});
});
2 changes: 1 addition & 1 deletion src/api/api.data.js
Expand Up @@ -25,7 +25,7 @@ const data = function(targetIds) {
const targets = this.internal.data.targets;

return typeof targetIds === "undefined" ?
targets : targets.filter(t => [].concat(targetIds).indexOf(t.id) >= 0);
targets : targets.filter(t => targetIds.indexOf(t.id) >= 0);
};

/**
Expand Down
9 changes: 7 additions & 2 deletions src/axis/bb.axis.js
Expand Up @@ -6,6 +6,7 @@ import {
scaleLinear as d3ScaleLinear,
select as d3Select
} from "d3";
import {isArray} from "../internals/util";

// Features:
// 1. category axis
Expand Down Expand Up @@ -256,9 +257,13 @@ export default function(params = {}) {

tspan = text.selectAll("tspan")
.data((d, i) => {
const splitted = params.tickMultiline ?
splitTickText(d, params.tickWidth) : [].concat(textFormatted(d));
let splitted;

if (params.tickMultiline) {
splitted = splitTickText(d, params.tickWidth);
} else {
splitted = isArray(textFormatted(d)) ? textFormatted(d).concat() : [textFormatted(d)];
}
counts[i] = splitted.length;

return splitted.map(s => ({
Expand Down
8 changes: 6 additions & 2 deletions src/data/data.convert.js
Expand Up @@ -108,7 +108,12 @@ extend(ChartInternal.prototype, {
});
data = this.convertRowsToData(newRows);
} else {
Object.keys(json).forEach(key => newRows.push([key].concat(json[key])));
Object.keys(json).forEach(key => {
const tmp = json[key].concat();

tmp.unshift(key);
newRows.push(tmp);
});
data = this.convertColumnsToData(newRows);
}
return data;
Expand Down Expand Up @@ -208,7 +213,6 @@ extend(ChartInternal.prototype, {
}
});


// check x is defined
ids.forEach(id => {
if (!$$.data.xs[id]) {
Expand Down
6 changes: 3 additions & 3 deletions src/data/data.js
Expand Up @@ -10,7 +10,7 @@ import {
} from "d3";
import CLASS from "../config/classes";
import ChartInternal from "../internals/ChartInternal";
import {extend, hasValue, isValue, notEmpty, isFunction} from "../internals/util";
import {extend, hasValue, isArray, isValue, notEmpty, isFunction} from "../internals/util";

extend(ChartInternal.prototype, {
isX(key) {
Expand Down Expand Up @@ -210,7 +210,7 @@ extend(ChartInternal.prototype, {
mapToTargetIds(ids) {
const $$ = this;

return ids ? [].concat(ids) : $$.mapToIds($$.data.targets);
return ids ? (isArray(ids) ? ids.concat() : [ids]) : $$.mapToIds($$.data.targets);
},

hasTarget(targets, id) {
Expand Down Expand Up @@ -453,7 +453,7 @@ extend(ChartInternal.prototype, {
},

convertValuesToStep(values) {
const converted = [].concat(values);
const converted = isArray(values) ? values.concat() : [values];
let i;

if (!this.isCategorized()) {
Expand Down
4 changes: 2 additions & 2 deletions src/internals/grid.js
Expand Up @@ -8,7 +8,7 @@ import {
} from "d3";
import ChartInternal from "./ChartInternal";
import CLASS from "../config/classes";
import {extend, isValue} from "./util";
import {extend, isArray, isValue} from "./util";

extend(ChartInternal.prototype, {
initGrid() {
Expand Down Expand Up @@ -327,7 +327,7 @@ extend(ChartInternal.prototype, {
return params ? function(line) {
let found = false;

[].concat(params).forEach(param => {
(isArray(params) ? params.concat() : [params]).forEach(param => {
if ((("value" in param && line.value === param.value) || ("class" in param && line.class === param.class))) {
found = true;
}
Expand Down

0 comments on commit 1f8efc2

Please sign in to comment.