Browse Source

Define state param as const

pull/1/head
Masayuki Tanaka 11 years ago
parent
commit
86fcdf2207
  1. 6
      c3.css
  2. 40
      c3.js

6
c3.css

@ -33,7 +33,7 @@ text {
} }
/*-- Point --*/ /*-- Point --*/
.-circle._e_ { .-circle._expanded_ {
stroke-width: 1px; stroke-width: 1px;
stroke: white; stroke: white;
} }
@ -44,12 +44,12 @@ text {
/*-- Bar --*/ /*-- Bar --*/
.-bar._e_ { .-bar._expanded_ {
stroke-width: 1px; stroke-width: 1px;
fill-opacity: 0.6; fill-opacity: 0.6;
} }
/* TODO: use this*/ /* TODO: use this*/
.-bar._s_ { .-bar._selected_ {
stroke-width: 1px; stroke-width: 1px;
fill-opacity: 0.3; fill-opacity: 0.3;
} }

40
c3.js

@ -10,6 +10,8 @@
var c3 = { data : {} }, var c3 = { data : {} },
cache = {}; cache = {};
var EXPANDED = '_expanded_', SELECTED = '_selected_', INCLUDED = '_included_';
/*-- Handle Config --*/ /*-- Handle Config --*/
function checkConfig (key, message) { function checkConfig (key, message) {
@ -867,13 +869,13 @@
// Expand circles if needed // Expand circles if needed
if (__point_focus_expand_enabled) { if (__point_focus_expand_enabled) {
main.selectAll('.-circle-'+i) main.selectAll('.-circle-'+i)
.classed("_e_", true) .classed(EXPANDED, true)
.attr('r', __point_focus_expand_r); .attr('r', __point_focus_expand_r);
} }
// Expand bars // Expand bars
main.selectAll(".-bar-"+i) main.selectAll(".-bar-"+i)
.classed("_e_", true); .classed(EXPANDED, true);
// Show xgrid focus line // Show xgrid focus line
main.selectAll('line.xgrid-focus') main.selectAll('line.xgrid-focus')
@ -893,12 +895,12 @@
tooltip.style("visibility", "hidden"); tooltip.style("visibility", "hidden");
// Undo expanded circles // Undo expanded circles
main.selectAll('.-circle-'+i) main.selectAll('.-circle-'+i)
.filter(function(){ return d3.select(this).classed('_e_'); }) .filter(function(){ return d3.select(this).classed(EXPANDED); })
.classed("_e_", false) .classed(EXPANDED, false)
.attr('r', __point_r); .attr('r', __point_r);
// Undo expanded bar // Undo expanded bar
main.selectAll(".-bar-"+i) main.selectAll(".-bar-"+i)
.classed("_e_", false); .classed(EXPANDED, false);
}) })
.on('mousemove', function(d,i){ .on('mousemove', function(d,i){
if ( ! __data_selection_enabled || dragging) return; if ( ! __data_selection_enabled || dragging) return;
@ -907,7 +909,7 @@
main.selectAll('.-shape-'+i) main.selectAll('.-shape-'+i)
.filter(function(d){ return __data_selection_isselectable(d); }) .filter(function(d){ return __data_selection_isselectable(d); })
.each(function(d){ .each(function(d){
var _this = d3.select(this).classed('_e_', true); var _this = d3.select(this).classed(EXPANDED, true);
if (this.nodeName === 'circle') _this.attr('r', __point_focus_expand_r); if (this.nodeName === 'circle') _this.attr('r', __point_focus_expand_r);
d3.select('.event-rect-'+i).style('cursor', null); d3.select('.event-rect-'+i).style('cursor', null);
}) })
@ -922,8 +924,8 @@
}) })
.each(function(d){ .each(function(d){
var _this = d3.select(this); var _this = d3.select(this);
if ( ! _this.classed('_e_')) { if ( ! _this.classed(EXPANDED)) {
_this.classed('_e_', true); _this.classed(EXPANDED, true);
if (this.nodeName === 'circle') _this.attr('r', __point_select_r); if (this.nodeName === 'circle') _this.attr('r', __point_select_r);
} }
d3.select('.event-rect-'+i).style('cursor', 'pointer'); d3.select('.event-rect-'+i).style('cursor', 'pointer');
@ -932,7 +934,7 @@
.on('click', function(d,i) { .on('click', function(d,i) {
main.selectAll('.-shape-'+i).each(function(d){ main.selectAll('.-shape-'+i).each(function(d){
var _this = d3.select(this), var _this = d3.select(this),
isSelected = _this.classed('_s_'); isSelected = _this.classed(SELECTED);
var isWithin = false, toggle; var isWithin = false, toggle;
if (this.nodeName === 'circle') { if (this.nodeName === 'circle') {
isWithin = isWithinCircle(this, __point_select_r*1.5); isWithin = isWithinCircle(this, __point_select_r*1.5);
@ -944,7 +946,7 @@
} }
if (__data_selection_grouped || isWithin) { if (__data_selection_grouped || isWithin) {
if (__data_selection_enabled && __data_selection_isselectable(d)) { if (__data_selection_enabled && __data_selection_isselectable(d)) {
_this.classed('_s_', !isSelected); _this.classed(SELECTED, !isSelected);
toggle(!isSelected, _this, d, i); toggle(!isSelected, _this, d, i);
} }
__point_onclick(d, _this); // TODO: should be __data_onclick __point_onclick(d, _this); // TODO: should be __data_onclick
@ -972,8 +974,8 @@
.filter(function(d){ return __data_selection_isselectable(d); }) .filter(function(d){ return __data_selection_isselectable(d); })
.each(function(d,i){ .each(function(d,i){
var _this = d3.select(this), var _this = d3.select(this),
isSelected = _this.classed('_s_'), isSelected = _this.classed(SELECTED),
isIncluded = _this.classed('_i_'), isIncluded = _this.classed(INCLUDED),
_x, _y, _w, toggle, isWithin = false; _x, _y, _w, toggle, isWithin = false;
if (this.nodeName === 'circle') { if (this.nodeName === 'circle') {
_x = _this.attr("cx")*1; _x = _this.attr("cx")*1;
@ -989,9 +991,9 @@
isWithin = minX < _x+_w && _x < maxX && _y < maxY; isWithin = minX < _x+_w && _x < maxX && _y < maxY;
} }
if (isWithin ^ isIncluded) { if (isWithin ^ isIncluded) {
_this.classed('_i_', !isIncluded); _this.classed(INCLUDED, !isIncluded);
// TODO: included/unincluded callback here // TODO: included/unincluded callback here
_this.classed('_s_', !isSelected); _this.classed(SELECTED, !isSelected);
toggle(!isSelected, _this, d, i); toggle(!isSelected, _this, d, i);
} }
}); });
@ -1012,7 +1014,7 @@
.style('opacity', 0) .style('opacity', 0)
.remove(); .remove();
main.selectAll('.-shape') main.selectAll('.-shape')
.classed('_i_', false); .classed(INCLUDED, false);
dragging = false; dragging = false;
// TODO: add callback here // TODO: add callback here
}) })
@ -1557,7 +1559,7 @@
var suffix = isDefined(target) ? '-' + target : ''; var suffix = isDefined(target) ? '-' + target : '';
return d3.merge( return d3.merge(
main.selectAll('.-shapes' + suffix).selectAll('.-shape') main.selectAll('.-shapes' + suffix).selectAll('.-shape')
.filter(function(){ return d3.select(this).classed('_s_'); }) .filter(function(){ return d3.select(this).classed(SELECTED); })
.map(function(d){ return d.map(function(_d){ return _d.__data__; }); }) .map(function(d){ return d.map(function(_d){ return _d.__data__; }); })
); );
}; };
@ -1569,10 +1571,10 @@
unselectShape = (this.nodeName === 'circle') ? unselectPoint : unselectBar; unselectShape = (this.nodeName === 'circle') ? unselectPoint : unselectBar;
if (indices.indexOf(i) >= 0) { if (indices.indexOf(i) >= 0) {
if (__data_selection_isselectable(d) && (__data_selection_grouped || isUndefined(ids) || ids.indexOf(d.id) >= 0)) { if (__data_selection_isselectable(d) && (__data_selection_grouped || isUndefined(ids) || ids.indexOf(d.id) >= 0)) {
selectShape(d3.select(this).classed('_s_',true), d, i); selectShape(d3.select(this).classed(SELECTED,true), d, i);
} }
} else if (isDefined(resetOther) && resetOther) { } else if (isDefined(resetOther) && resetOther) {
unselectShape(d3.select(this).classed('_s_',false), d, i); unselectShape(d3.select(this).classed(SELECTED,false), d, i);
} }
}); });
}; };
@ -1583,7 +1585,7 @@
var unselectShape = (this.nodeName === 'circle') ? unselectPoint : unselectBar; var unselectShape = (this.nodeName === 'circle') ? unselectPoint : unselectBar;
if (isUndefined(indices) || indices.indexOf(i) >= 0) { if (isUndefined(indices) || indices.indexOf(i) >= 0) {
if (__data_selection_isselectable(d) && (__data_selection_grouped || isUndefined(ids) || ids.indexOf(d.id) >= 0)) { if (__data_selection_isselectable(d) && (__data_selection_grouped || isUndefined(ids) || ids.indexOf(d.id) >= 0)) {
unselectShape(d3.select(this).classed('_s_',false), d, i); unselectShape(d3.select(this).classed(SELECTED,false), d, i);
} }
} }
}); });

Loading…
Cancel
Save