Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

d3 v6 compatibility #295

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ help
image_creator
tmp
notes
examples/
49 changes: 35 additions & 14 deletions dist/dimple.latest.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
this.clamp = true;
// Help: http://github.com/PMSI-AlignAlytics/dimple/wiki/dimple.axis#wiki-ticks
this.ticks = null;
this.scaleStep = null;
// Help: http://github.com/PMSI-AlignAlytics/dimple/wiki/dimple.axis#wiki-fontSize
this.fontSize = "10px";
// Help: http://github.com/PMSI-AlignAlytics/dimple/wiki/dimple.axis#wiki-fontFamily
Expand All @@ -119,7 +120,6 @@
// The group order definition array
this._groupOrderRules = [];


// Copyright: 2015 AlignAlytics
// License: "https://github.com/PMSI-AlignAlytics/dimple/blob/master/MIT-LICENSE.txt"
// Source: /src/objects/axis/methods/_draw.js
Expand Down Expand Up @@ -397,6 +397,23 @@
this._min = (this.overrideMin !== null ? this.overrideMin : this._min);
this._max = (this.overrideMax !== null ? this.overrideMax : this._max);

const setTickValues = () => {
const TICKS_NUMBER_LIMIT = 200;
const {_draw: axisDraw, _scale: axisScale, scaleStep } = this;

if (scaleStep && axisDraw && axisScale) {
const [minTick, maxTick] = axisScale.domain();
const ticksRange = d3.range(minTick, maxTick, scaleStep);

const lastTick = ticksRange[ticksRange.length - 1];
if (lastTick + scaleStep === maxTick) {
ticksRange.push(maxTick);
}

ticksRange.length <= TICKS_NUMBER_LIMIT && this._draw.tickValues(ticksRange);
}
}

// If this is an x axis
if (this.position === "x" && (this._scale === null || refactor)) {
if (this._hasTimeField()) {
Expand Down Expand Up @@ -453,6 +470,8 @@
default:
break;
}

setTickValues();
}
} else if (this.position === "y" && (this._scale === null || refactor)) {
if (this._hasTimeField()) {
Expand Down Expand Up @@ -509,6 +528,8 @@
default:
break;
}

setTickValues();
}
} else if (this.position.length > 0 && this.position[0] === "z" && this._scale === null) {
if (this.useLog) {
Expand Down Expand Up @@ -1949,10 +1970,10 @@
// If the gaps are narrower than the widest label display all labels horizontally
widest = 0;
axis.shapes.selectAll("text").each(function () {
var w = this.getComputedTextLength();
var w = axis.maxTextWidth || this.getComputedTextLength();
widest = (w > widest ? w : widest);
});
if (widest > chartWidth / axis.shapes.selectAll("text").nodes().length) {
if (widest > (axis._scale.step ? axis._scale.step() : chartWidth / axis.shapes.selectAll("text").nodes().length)) {
rotated = true;
axis.shapes.selectAll("text")
.style("text-anchor", "start")
Expand Down Expand Up @@ -2018,7 +2039,7 @@
box.t = rec.y + rec.height - rec.width;
}
if (box.b === null || rec.height + rec.width > box.b) {
box.b = rec.height + rec.width;
box.b = (axis.maxTextWidth ? 20 : rec.height) + rec.width;
}
} else {
if (box.t === null || rec.y < box.t) {
Expand Down Expand Up @@ -3581,8 +3602,8 @@
})
.attr("width", function (d) { return (cat === "x" ? dimple._helpers.width(d, chart, series) : 0); })
.attr("height", function (d) { return (cat === "y" ? dimple._helpers.height(d, chart, series) : 0); })
.on("mouseover", function (e) { dimple._showBarTooltip(e, this, chart, series); })
.on("mouseleave", function (e) { dimple._removeTooltip(e, this, chart, series); })
.on("mouseover", function (e, d) { dimple._showBarTooltip(d, this, chart, series); })
.on("mouseleave", function (e, d) { dimple._removeTooltip(d, this, chart, series); })
.call(function (context) {
if (!chart.noFormats) {
context.attr("opacity", function (d) { return dimple._helpers.opacity(d, chart, series); })
Expand Down Expand Up @@ -3684,8 +3705,8 @@
.attr("cx", function (d) { return (series.x._hasCategories() ? dimple._helpers.cx(d, chart, series) : series.x._previousOrigin); })
.attr("cy", function (d) { return (series.y._hasCategories() ? dimple._helpers.cy(d, chart, series) : series.y._previousOrigin); })
.attr("r", 0)
.on("mouseover", function (e) { dimple._showPointTooltip(e, this, chart, series); })
.on("mouseleave", function (e) { dimple._removeTooltip(e, this, chart, series); })
.on("mouseover", function (e, d) { dimple._showPointTooltip(d, this, chart, series); })
.on("mouseleave", function (e, d) { dimple._removeTooltip(d, this, chart, series); })
.call(function (context) {
if (!chart.noFormats) {
context.attr("opacity", function (d) { return dimple._helpers.opacity(d, chart, series); })
Expand Down Expand Up @@ -4076,8 +4097,8 @@
return classes.join(" ") + " " + dimple._createClass(c) + " " + chart.customClassList.pieSeries + " " + dimple._helpers.css(d, chart);
})
.attr("d", getArc)
.on("mouseover", function (e) { dimple._showBarTooltip(e, this, chart, series); })
.on("mouseleave", function (e) { dimple._removeTooltip(e, this, chart, series); })
.on("mouseover", function (e, d) { dimple._showBarTooltip(d, this, chart, series); })
.on("mouseleave", function (e, d) { dimple._removeTooltip(d, this, chart, series); })
.call(function (context) {
if (!chart.noFormats) {
context.attr("opacity", function (d) { return dimple._helpers.opacity(d, chart, series); })
Expand Down Expand Up @@ -4350,11 +4371,11 @@
}
return dimple._createClass(fields) + " " + markerClasses.join(" ") + " " + chart.customClassList.lineMarker + " " + css;
})
.on("mouseover", function (e) {
enterEventHandler(e, this, chart, series);
.on("mouseover", function (e, d) {
enterEventHandler(d, this, chart, series);
})
.on("mouseleave", function (e) {
leaveEventHandler(e, this, chart, series);
.on("mouseleave", function (e, d) {
leaveEventHandler(d, this, chart, series);
})
.attr("cx", function (d) {
return (series.x._hasCategories() ? dimple._helpers.cx(d, chart, series) : series.x._previousOrigin);
Expand Down
4 changes: 1 addition & 3 deletions dist/dimple.latest.min.js

Large diffs are not rendered by default.

Loading