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

Initial support for accessibility #2317

Open
wants to merge 4 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
6 changes: 5 additions & 1 deletion src/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ c3_chart_internal_fn.initParams = function () {
var $$ = this, d3 = $$.d3, config = $$.config;

// MEMO: clipId needs to be unique because it conflicts when multiple charts exist
$$.clipId = "c3-" + (+new Date()) + '-clip',
$$.chartId = "c3-" + (+new Date()),
$$.clipId = $$.chartId + '-clip',
$$.clipIdForXAxis = $$.clipId + '-xaxis',
$$.clipIdForYAxis = $$.clipId + '-yaxis',
$$.clipIdForGrid = $$.clipId + '-grid',
Expand All @@ -96,6 +97,8 @@ c3_chart_internal_fn.initParams = function () {
$$.clipPathForYAxis = $$.getClipPath($$.clipIdForYAxis);
$$.clipPathForGrid = $$.getClipPath($$.clipIdForGrid),
$$.clipPathForSubchart = $$.getClipPath($$.clipIdForSubchart),
$$.tooltipId = $$.chartId + '-tooltip',
$$.xgridFocusId = $$.chartId + '-xgrid',

$$.dragStart = null;
$$.dragging = false;
Expand Down Expand Up @@ -228,6 +231,7 @@ c3_chart_internal_fn.initWithData = function (data) {

// Define svgs
$$.svg = $$.selectChart.append("svg")
.attr('role', 'graphics-document document')
.style("overflow", "hidden")
.on('mouseenter', function () { return config.onmouseover.call($$); })
.on('mouseleave', function () { return config.onmouseout.call($$); });
Expand Down
1 change: 1 addition & 0 deletions src/grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ c3_chart_internal_fn.initGrid = function () {
if (config.grid_focus_show) {
$$.grid.append('g')
.attr("class", CLASS.xgridFocus)
.attr("id", $$.xgridFocusId)
.append('line')
.attr('class', CLASS.xgridFocus);
}
Expand Down
38 changes: 30 additions & 8 deletions src/interaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ c3_chart_internal_fn.initEventRect = function () {
var $$ = this;
$$.main.select('.' + CLASS.chart).append("g")
.attr("class", CLASS.eventRects)
.attr('aria-controls', $$.tooltipId + ' ' + $$.xgridFocusId)
.style('fill-opacity', 0);
};
c3_chart_internal_fn.redrawEventRect = function () {
Expand Down Expand Up @@ -106,15 +107,18 @@ c3_chart_internal_fn.updateEventRect = function (eventRectUpdate) {

eventRectUpdate
.attr('class', $$.classEvent.bind($$))
.select('rect')
.attr("x", x)
.attr("y", y)
.attr("width", w)
.attr("height", h);
};
c3_chart_internal_fn.generateEventRectsForSingleX = function (eventRectEnter) {
var $$ = this, d3 = $$.d3, config = $$.config;
eventRectEnter.append("rect")
eventRectEnter.append("a")
.attr("class", $$.classEvent.bind($$))
.attr("xlink:href", '')
.attr("aria-describedby", $$.tooltipId)
.style("cursor", config.data_selection_enabled && config.data_selection_grouped ? "pointer" : null)
.on('mouseover', function (d) {
var index = d.index;
Expand All @@ -131,6 +135,13 @@ c3_chart_internal_fn.generateEventRectsForSingleX = function (eventRectEnter) {
config.data_onmouseover.call($$.api, d);
});
})
.on('focus', function(d) {
$$.dispatchEvent('mouseover', d.index);
$$.dispatchEvent('mousemove', d.index);
})
.on('blur', function(d) {
$$.dispatchEvent('mouseout', d.index);
})
.on('mouseout', function (d) {
var index = d.index;
if (!$$.config) { return; } // chart is destroyed
Expand Down Expand Up @@ -201,6 +212,7 @@ c3_chart_internal_fn.generateEventRectsForSingleX = function (eventRectEnter) {
});
})
.on('click', function (d) {
d3.event.preventDefault();
var index = d.index;
if ($$.hasArcType() || !$$.toggleShape) { return; }
if ($$.cancelClick) {
Expand All @@ -224,7 +236,8 @@ c3_chart_internal_fn.generateEventRectsForSingleX = function (eventRectEnter) {
.on('dragstart', function () { $$.dragstart(d3.mouse(this)); })
.on('dragend', function () { $$.dragend(); })
) : function () {}
);
)
.append('rect');
};

c3_chart_internal_fn.generateEventRectsForMultipleXs = function (eventRectEnter) {
Expand All @@ -238,12 +251,10 @@ c3_chart_internal_fn.generateEventRectsForMultipleXs = function (eventRectEnter)
$$.unexpandBars();
}

eventRectEnter.append('rect')
.attr('x', 0)
.attr('y', 0)
.attr('width', $$.width)
.attr('height', $$.height)
eventRectEnter.append('a')
.attr('class', CLASS.eventRect)
.attr('xlink:href', '')
.attr("aria-describedby", $$.tooltipId)
.on('mouseout', function () {
if (!$$.config) { return; } // chart is destroyed
if ($$.hasArcType()) { return; }
Expand Down Expand Up @@ -299,7 +310,14 @@ c3_chart_internal_fn.generateEventRectsForMultipleXs = function (eventRectEnter)
}
}
})
.on('focus', function() {
$$.dispatchEvent('mousemove');
})
.on('blur', function() {
$$.dispatchEvent('mouseout');
})
.on('click', function () {
d3.event.preventDefault();
var targetsToShow = $$.filterTargetsToShow($$.data.targets);
var mouse, closest;
if ($$.hasArcType(targetsToShow)) { return; }
Expand All @@ -324,7 +342,11 @@ c3_chart_internal_fn.generateEventRectsForMultipleXs = function (eventRectEnter)
.on('dragstart', function () { $$.dragstart(d3.mouse(this)); })
.on('dragend', function () { $$.dragend(); })
) : function () {}
);
).append('rect')
.attr('x', 0)
.attr('y', 0)
.attr('width', $$.width)
.attr('height', $$.height);
};
c3_chart_internal_fn.dispatchEvent = function (type, index, mouse) {
var $$ = this,
Expand Down
6 changes: 4 additions & 2 deletions src/scss/tooltip.scss
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@
text-align:left;
color:#FFF;
}
.c3-tooltip td {
.c3-tooltip td, .c3-tooltip th[scope='row'] {
font-size:13px;
padding: 3px 6px;
background-color:#fff;
border-left:1px dotted #999;
color: black;
font-weight: normal;
}
.c3-tooltip td > span {
.c3-tooltip td > span, , .c3-tooltip th[scope='row'] > span {
display: inline-block;
width: 10px;
height: 10px;
Expand Down
2 changes: 2 additions & 0 deletions src/shape.line.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ c3_chart_internal_fn.updateTargetsForLine = function (targets) {
.attr('class', function (d) { return classChartLine(d) + classFocus(d); });
mainLineEnter = mainLineUpdate.enter().append('g')
.attr('class', classChartLine)
.attr('role', 'graphics-object group')
.style('opacity', 0)
.style("pointer-events", "none");
// Lines for each data
Expand Down Expand Up @@ -309,6 +310,7 @@ c3_chart_internal_fn.updateCircle = function () {
$$.mainCircle = $$.main.selectAll('.' + CLASS.circles).selectAll('.' + CLASS.circle)
.data($$.lineOrScatterData.bind($$));
$$.mainCircle.enter().append("circle")
.attr("role", "graphics-symbol img")
.attr("class", $$.classCircle.bind($$))
.attr("r", $$.pointR.bind($$))
.style("fill", $$.color);
Expand Down
4 changes: 2 additions & 2 deletions src/tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ c3_chart_internal_fn.getTooltipContent = function (d, defaultTitleFormat, defaul

if (! text) {
title = sanitise(titleFormat ? titleFormat(d[i].x) : d[i].x);
text = "<table class='" + $$.CLASS.tooltip + "'>" + (title || title === 0 ? "<tr><th colspan='2'>" + title + "</th></tr>" : "");
text = "<table id='" + $$.tooltipId + "' class='" + $$.CLASS.tooltip + "' role='tooltip'>" + (title || title === 0 ? "<thead><tr><th colspan='2'>" + title + "</th></tr></thead>" : "");
}

value = sanitise(valueFormat(d[i].value, d[i].ratio, d[i].id, d[i].index, d));
Expand All @@ -125,7 +125,7 @@ c3_chart_internal_fn.getTooltipContent = function (d, defaultTitleFormat, defaul
bgcolor = $$.levelColor ? $$.levelColor(d[i].value) : color(d[i].id);

text += "<tr class='" + $$.CLASS.tooltipName + "-" + $$.getTargetSelectorSuffix(d[i].id) + "'>";
text += "<td class='name'><span style='background-color:" + bgcolor + "'></span>" + name + "</td>";
text += "<th scope='row' class='name'><span style='background-color:" + bgcolor + "'></span>" + name + "</th>";
text += "<td class='value'>" + value + "</td>";
text += "</tr>";
}
Expand Down