-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(interaction): add elementSelect, elementSelectByX, elementSelect…
…ByColor
- Loading branch information
Showing
37 changed files
with
444 additions
and
25 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
__tests__/integration/interactions/alphabet-interval-select-single.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { G2Spec, ELEMENT_CLASS_NAME } from '../../../src'; | ||
import { step } from './utils'; | ||
|
||
export function alphabetIntervalSelectSingle(): G2Spec { | ||
return { | ||
type: 'interval', | ||
padding: 0, | ||
transform: [{ type: 'sortX', by: 'y', reverse: true }], | ||
data: { | ||
type: 'fetch', | ||
value: 'data/alphabet.csv', | ||
}, | ||
axis: false, | ||
legend: false, | ||
encode: { | ||
x: 'letter', | ||
y: 'frequency', | ||
color: 'steelblue', | ||
}, | ||
interaction: [ | ||
{ | ||
type: 'elementSelect', | ||
selectedFill: 'red', | ||
unselectedOpacity: 0.6, | ||
single: true, | ||
}, | ||
], | ||
}; | ||
} | ||
|
||
alphabetIntervalSelectSingle.steps = ({ canvas }) => { | ||
const { document } = canvas; | ||
const elements = document.getElementsByClassName(ELEMENT_CLASS_NAME); | ||
const [e, e1] = elements; | ||
return [step(e, 'click'), step(e1, 'click'), step(e1, 'click')]; | ||
}; |
42 changes: 42 additions & 0 deletions
42
__tests__/integration/interactions/alphabet-interval-select.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { | ||
G2Spec, | ||
ELEMENT_CLASS_NAME, | ||
MAIN_LAYER_CLASS_NAME, | ||
} from '../../../src'; | ||
import { step } from './utils'; | ||
|
||
export function alphabetIntervalSelect(): G2Spec { | ||
return { | ||
type: 'interval', | ||
padding: 0, | ||
data: { | ||
type: 'fetch', | ||
value: 'data/alphabet.csv', | ||
}, | ||
axis: false, | ||
legend: false, | ||
encode: { | ||
x: 'letter', | ||
y: 'frequency', | ||
color: 'steelblue', | ||
}, | ||
interaction: [ | ||
{ type: 'elementSelect', selectedFill: 'red', unselectedOpacity: 0.6 }, | ||
], | ||
}; | ||
} | ||
|
||
alphabetIntervalSelect.steps = ({ canvas }) => { | ||
const { document } = canvas; | ||
const elements = document.getElementsByClassName(ELEMENT_CLASS_NAME); | ||
const [mainLayer] = document.getElementsByClassName(MAIN_LAYER_CLASS_NAME); | ||
const [e, e1] = elements; | ||
return [ | ||
step(e, 'click'), | ||
step(e1, 'click'), | ||
step(e1, 'click'), | ||
step(e, 'click'), | ||
step(e, 'click'), | ||
step(mainLayer, 'click'), // Reset the canvas. | ||
]; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
__tests__/integration/interactions/stateages-interval-select-by-color-single.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { | ||
G2Spec, | ||
ELEMENT_CLASS_NAME, | ||
MAIN_LAYER_CLASS_NAME, | ||
} from '../../../src'; | ||
import { step } from './utils'; | ||
|
||
export function stateAgesIntervalSelectByColorSingle(): G2Spec { | ||
return { | ||
type: 'interval', | ||
padding: 0, | ||
axis: false, | ||
legend: false, | ||
width: 800, | ||
transform: [ | ||
{ type: 'stackY' }, | ||
{ type: 'sortX', by: 'y', reverse: true, slice: 5 }, | ||
], | ||
data: { | ||
type: 'fetch', | ||
value: 'data/stateages.csv', | ||
format: 'csv', | ||
}, | ||
encode: { | ||
x: 'state', | ||
y: 'population', | ||
color: 'age', | ||
}, | ||
scale: { | ||
x: { paddingInner: 0.2 }, | ||
}, | ||
interaction: [ | ||
{ | ||
type: 'elementSelectByColor', | ||
link: true, | ||
linkFill: (d) => (d.state === 'CA' ? 'red' : undefined), | ||
selectedStroke: '#000', | ||
selectedStrokeWidth: 1, | ||
unselectedOpacity: 0.6, | ||
linkFillOpacity: 0.5, | ||
single: true, | ||
}, | ||
], | ||
}; | ||
} | ||
|
||
stateAgesIntervalSelectByColorSingle.steps = ({ canvas }) => { | ||
const { document } = canvas; | ||
const elements = document.getElementsByClassName(ELEMENT_CLASS_NAME); | ||
const [mainLayer] = document.getElementsByClassName(MAIN_LAYER_CLASS_NAME); | ||
const [e1] = elements; | ||
const e2 = elements[elements.length - 1]; | ||
return [ | ||
step(e1, 'click'), | ||
step(e1, 'click'), | ||
step(e1, 'click'), | ||
step(e2, 'click'), | ||
step(mainLayer, 'click'), | ||
]; | ||
}; |
53 changes: 53 additions & 0 deletions
53
__tests__/integration/interactions/stateages-interval-select-by-color.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { G2Spec, ELEMENT_CLASS_NAME } from '../../../src'; | ||
import { step } from './utils'; | ||
|
||
export function stateAgesIntervalSelectByColor(): G2Spec { | ||
return { | ||
type: 'interval', | ||
padding: 0, | ||
axis: false, | ||
legend: false, | ||
width: 800, | ||
transform: [ | ||
{ type: 'stackY' }, | ||
{ type: 'sortX', by: 'y', reverse: true, slice: 5 }, | ||
], | ||
data: { | ||
type: 'fetch', | ||
value: 'data/stateages.csv', | ||
format: 'csv', | ||
}, | ||
encode: { | ||
x: 'state', | ||
y: 'population', | ||
color: 'age', | ||
}, | ||
scale: { | ||
x: { paddingInner: 0.2 }, | ||
}, | ||
interaction: [ | ||
{ | ||
type: 'elementSelectByColor', | ||
link: true, | ||
linkFill: (d) => (d.state === 'CA' ? 'red' : undefined), | ||
selectedStroke: '#000', | ||
selectedStrokeWidth: 1, | ||
unselectedOpacity: 0.6, | ||
linkFillOpacity: 0.5, | ||
}, | ||
], | ||
}; | ||
} | ||
|
||
stateAgesIntervalSelectByColor.steps = ({ canvas }) => { | ||
const { document } = canvas; | ||
const elements = document.getElementsByClassName(ELEMENT_CLASS_NAME); | ||
const [e1] = elements; | ||
const e2 = elements[elements.length - 1]; | ||
return [ | ||
step(e1, 'click'), | ||
step(e2, 'click'), | ||
step(e1, 'click'), | ||
step(e2, 'click'), | ||
]; | ||
}; |
38 changes: 38 additions & 0 deletions
38
__tests__/integration/interactions/stateages-interval-select-by-x.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { G2Spec, ELEMENT_CLASS_NAME } from '../../../src'; | ||
import { step } from './utils'; | ||
|
||
export function stateAgesIntervalSelectByX(): G2Spec { | ||
return { | ||
type: 'interval', | ||
padding: 0, | ||
transform: [ | ||
{ type: 'sortX', by: 'y', reverse: true, reducer: 'sum', slice: 6 }, | ||
{ type: 'dodgeX' }, | ||
], | ||
data: { | ||
type: 'fetch', | ||
value: 'data/stateages.csv', | ||
}, | ||
axis: false, | ||
legend: false, | ||
encode: { | ||
x: 'state', | ||
y: 'population', | ||
color: 'age', | ||
}, | ||
interaction: [ | ||
{ | ||
type: 'elementSelectByX', | ||
selectedFill: 'red', | ||
unselectedOpacity: 0.6, | ||
}, | ||
], | ||
}; | ||
} | ||
|
||
stateAgesIntervalSelectByX.steps = ({ canvas }) => { | ||
const { document } = canvas; | ||
const elements = document.getElementsByClassName(ELEMENT_CLASS_NAME); | ||
const [e1] = elements; | ||
return [step(e1, 'click')]; | ||
}; |
Binary file added
BIN
+3.47 KB
__tests__/integration/snapshots/alphabet-interval-select-single/step0.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+3.47 KB
__tests__/integration/snapshots/alphabet-interval-select-single/step1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+3.45 KB
__tests__/integration/snapshots/alphabet-interval-select-single/step2.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+5.43 KB
...ts__/integration/snapshots/state-ages-interval-select-by-color-single/step0.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+4.07 KB
...ts__/integration/snapshots/state-ages-interval-select-by-color-single/step1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+5.43 KB
...ts__/integration/snapshots/state-ages-interval-select-by-color-single/step2.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+9.07 KB
...ts__/integration/snapshots/state-ages-interval-select-by-color-single/step3.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+4.07 KB
...ts__/integration/snapshots/state-ages-interval-select-by-color-single/step4.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+5.43 KB
__tests__/integration/snapshots/state-ages-interval-select-by-color/step0.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+10.4 KB
__tests__/integration/snapshots/state-ages-interval-select-by-color/step1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+9.07 KB
__tests__/integration/snapshots/state-ages-interval-select-by-color/step2.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+4.07 KB
__tests__/integration/snapshots/state-ages-interval-select-by-color/step3.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+4.5 KB
__tests__/integration/snapshots/state-ages-interval-select-by-x/step0.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.