MCPcopy Index your code
hub / github.com/plotly/plotly.js / setupTitleToggle

Function setupTitleToggle

src/components/legend/draw.js:670–734  ·  view source on GitHub ↗
(scrollBox, gd, legendObj, legendId)

Source from the content-addressed store, hash-verified

668}
669
670function setupTitleToggle(scrollBox, gd, legendObj, legendId) {
671 // For now, skip title click for legends containing pie-like traces
672 const hasPie = gd._fullData.some(function(trace) {
673 const legend = trace.legend || 'legend';
674 const inThisLegend = Array.isArray(legend) ? legend.includes(legendId) : legend === legendId;
675 return inThisLegend && Registry.traceIs(trace, 'pie-like');
676 });
677 if(hasPie) return;
678
679 const doubleClickDelay = gd._context.doubleClickDelay;
680 var newMouseDownTime;
681 var numClicks = 1;
682
683 const titleToggle = Lib.ensureSingle(scrollBox, 'rect', legendId + 'titletoggle', function(s) {
684 if(!gd._context.staticPlot) {
685 s.style('cursor', 'pointer').attr('pointer-events', 'all');
686 }
687 s.call(Color.fill, 'rgba(0,0,0,0)');
688 });
689
690 if(gd._context.staticPlot) return;
691
692 titleToggle.on('mousedown', function() {
693 newMouseDownTime = (new Date()).getTime();
694 if(newMouseDownTime - gd._legendMouseDownTime < doubleClickDelay) {
695 // in a click train
696 numClicks += 1;
697 } else {
698 // new click train
699 numClicks = 1;
700 gd._legendMouseDownTime = newMouseDownTime;
701 }
702 });
703 titleToggle.on('mouseup', function() {
704 if(gd._dragged || gd._editing) return;
705
706 if((new Date()).getTime() - gd._legendMouseDownTime > doubleClickDelay) {
707 numClicks = Math.max(numClicks - 1, 1);
708 }
709
710 const evtData = {
711 event: d3.event,
712 legendId: legendId,
713 data: gd.data,
714 layout: gd.layout,
715 fullData: gd._fullData,
716 fullLayout: gd._fullLayout
717 };
718
719 if(numClicks === 1 && legendObj.titleclick) {
720 const clickVal = Events.triggerHandler(gd, 'plotly_legendtitleclick', evtData);
721 if(clickVal === false) return;
722
723 legendObj._titleClickTimeout = setTimeout(function() {
724 if(gd._fullLayout) handleTitleClick(gd, legendObj, legendObj.titleclick);
725 }, doubleClickDelay);
726 } else if(numClicks === 2) {
727 if(legendObj._titleClickTimeout) clearTimeout(legendObj._titleClickTimeout);

Callers 1

drawOneFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…