Skip to content

Commit f585704

Browse files
authored
Merge pull request #363 from jasonlong/2d-toggle
Add "Both" toggle to show 2D and 3D views together
2 parents 70eb534 + 40b90a6 commit f585704

File tree

6 files changed

+111
-8
lines changed

6 files changed

+111
-8
lines changed

biome.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,16 @@
3737
}
3838
}
3939
}
40+
},
41+
{
42+
"includes": ["src/iso.css"],
43+
"linter": {
44+
"rules": {
45+
"complexity": {
46+
"noImportantStyles": "off"
47+
}
48+
}
49+
}
4050
}
4151
]
4252
}

src/dom.test.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,11 @@ describe('applyViewType', () => {
3737
expect(element.classList.contains('ic-squares')).toBe(false)
3838
})
3939

40-
it('adds ic-cubes for any non-squares type', () => {
41-
applyViewType(element, 'anything')
42-
expect(element.classList.contains('ic-cubes')).toBe(true)
40+
it('adds ic-both class for both type', () => {
41+
applyViewType(element, 'both')
42+
expect(element.classList.contains('ic-both')).toBe(true)
4343
expect(element.classList.contains('ic-squares')).toBe(false)
44+
expect(element.classList.contains('ic-cubes')).toBe(false)
4445
})
4546

4647
it('handles toggling from cubes to squares', () => {

src/iso.css

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
1-
/* Normal chart display */
1+
/* Normal chart display (2D only) */
22
.ic-squares #isometric-contributions,
33
.ic-squares .ic-contributions-wrapper {
44
display: none;
55
}
66

7-
/* Isometric cube display */
7+
/* Isometric cube display (3D only) */
88
.ic-cubes .contrib-details {
99
display: none;
1010
}
1111

1212
.ic-cubes .js-calendar-graph {
13-
display: none;
13+
/* Override GitHub Primer's d-flex !important */
14+
display: none !important;
1415
}
16+
17+
/* Both display - no hiding needed, both are visible by default */

src/iso.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,19 @@ const initUI = () => {
118118
cubesButton.classList.add('selected')
119119
}
120120

121+
const bothButton = document.createElement('button')
122+
bothButton.textContent = 'Both'
123+
bothButton.className =
124+
'ic-toggle-option both btn BtnGroup-item btn-sm py-0 px-1'
125+
bothButton.dataset.icOption = 'both'
126+
bothButton.addEventListener('click', handleViewToggle)
127+
if (toggleSetting === 'both') {
128+
bothButton.classList.add('selected')
129+
}
130+
121131
buttonGroup.append(squaresButton)
122132
buttonGroup.append(cubesButton)
133+
buttonGroup.append(bothButton)
123134
insertLocation.before(buttonGroup)
124135

125136
setContainerViewType(toggleSetting)

src/utils.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,11 +172,12 @@ export const calculateStreaks = (days) => {
172172
/**
173173
* Apply view type classes to a container element.
174174
* @param {Element} element - The container element
175-
* @param {string} type - View type ('squares' or 'cubes')
175+
* @param {string} type - View type ('squares', 'cubes', or 'both')
176176
*/
177177
export const applyViewType = (element, type) => {
178178
element.classList.toggle('ic-squares', type === 'squares')
179-
element.classList.toggle('ic-cubes', type !== 'squares')
179+
element.classList.toggle('ic-cubes', type === 'cubes')
180+
element.classList.toggle('ic-both', type === 'both')
180181
}
181182

182183
/**

test-extension.js

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,83 @@ const run = async () => {
125125
`Canvas rendered: ${canvasDrawn.width}x${canvasDrawn.height} with ${canvasDrawn.nonTransparentPixels.toLocaleString()} drawn pixels`
126126
)
127127

128+
console.log('Checking that 2D graph is hidden in 3D mode...')
129+
const graphVisibility = await page.evaluate(() => {
130+
const calendarGraph = document.querySelector('.js-calendar-graph')
131+
if (!calendarGraph) return { exists: false }
132+
const style = window.getComputedStyle(calendarGraph)
133+
return {
134+
exists: true,
135+
display: style.display,
136+
visibility: style.visibility,
137+
isHidden: style.display === 'none'
138+
}
139+
})
140+
141+
if (!graphVisibility.exists) {
142+
throw new Error('Could not find .js-calendar-graph element')
143+
}
144+
145+
if (!graphVisibility.isHidden) {
146+
throw new Error(
147+
`2D graph should be hidden in 3D mode but has display: "${graphVisibility.display}"`
148+
)
149+
}
150+
151+
console.log('2D graph correctly hidden in 3D mode')
152+
153+
// Test 2D mode
154+
console.log('Clicking 2D toggle...')
155+
await page.click('[data-ic-option="squares"]')
156+
await new Promise((resolve) => setTimeout(resolve, 500))
157+
158+
const mode2D = await page.evaluate(() => {
159+
const canvas = document.querySelector('#isometric-contributions')
160+
const calendarGraph = document.querySelector('.js-calendar-graph')
161+
const canvasStyle = window.getComputedStyle(canvas)
162+
const graphStyle = window.getComputedStyle(calendarGraph)
163+
return {
164+
canvasHidden: canvasStyle.display === 'none',
165+
graphVisible: graphStyle.display !== 'none'
166+
}
167+
})
168+
169+
if (!mode2D.canvasHidden) {
170+
throw new Error('3D canvas should be hidden in 2D mode')
171+
}
172+
if (!mode2D.graphVisible) {
173+
throw new Error('2D graph should be visible in 2D mode')
174+
}
175+
console.log('2D mode working correctly')
176+
177+
// Test Both mode
178+
console.log('Clicking Both toggle...')
179+
await page.click('[data-ic-option="both"]')
180+
await new Promise((resolve) => setTimeout(resolve, 500))
181+
182+
const modeBoth = await page.evaluate(() => {
183+
const canvas = document.querySelector('#isometric-contributions')
184+
const calendarGraph = document.querySelector('.js-calendar-graph')
185+
const canvasStyle = window.getComputedStyle(canvas)
186+
const graphStyle = window.getComputedStyle(calendarGraph)
187+
return {
188+
canvasVisible: canvasStyle.display !== 'none',
189+
graphVisible: graphStyle.display !== 'none'
190+
}
191+
})
192+
193+
if (!modeBoth.canvasVisible) {
194+
throw new Error('3D canvas should be visible in Both mode')
195+
}
196+
if (!modeBoth.graphVisible) {
197+
throw new Error('2D graph should be visible in Both mode')
198+
}
199+
console.log('Both mode working correctly')
200+
201+
// Switch back to 3D for contribution data check
202+
await page.click('[data-ic-option="cubes"]')
203+
await new Promise((resolve) => setTimeout(resolve, 500))
204+
128205
console.log('Checking contribution data...')
129206
const contribTotal = await page.$eval(
130207
'.ic-contributions-wrapper ::-p-text(Contributions) + div ::-p-text(Total)',

0 commit comments

Comments
 (0)