-
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(static-mark): add legends (#5209)
- Loading branch information
Showing
29 changed files
with
406 additions
and
118 deletions.
There are no files selected for viewing
Binary file added
BIN
+34.9 KB
__tests__/integration/snapshots/interaction/weather-line-legend-mark/step0.png
Loading
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
+38.6 KB
__tests__/integration/snapshots/interaction/weather-line-legend-mark/step1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-74 Bytes
(100%)
__tests__/integration/snapshots/static/disastersPointBubbleLegendRight.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
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
+40.9 KB
__tests__/integration/snapshots/static/weatherLineMultiAxesLegend.png
Loading
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
112 changes: 112 additions & 0 deletions
112
__tests__/plots/interaction/weather-line-legend-mark.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,112 @@ | ||
import { G2Spec } from '../../../src'; | ||
import { LEGEND_ITEMS_CLASS_NAME } from '../../../src/interaction/legendFilter'; | ||
import { weather } from '../../data/weather'; | ||
import { step } from './utils'; | ||
|
||
export function weatherLineLegendMark(): G2Spec { | ||
const labelByValue = { | ||
'#EE6666': 'Temperature', | ||
'#5470C6': 'Evaporation', | ||
'#91CC75': 'Precipitation', | ||
}; | ||
const markerByValue = { | ||
'#EE6666': 'line', | ||
'#5470C6': 'rect', | ||
'#91CC75': 'line', | ||
}; | ||
return { | ||
type: 'view', | ||
data: weather, | ||
children: [ | ||
{ | ||
type: 'line', | ||
encode: { | ||
x: 'Month', | ||
y: 'Temperature', | ||
color: '#EE6666', | ||
shape: 'smooth', | ||
}, | ||
scale: { | ||
y: { independent: true, domainMax: 30 }, | ||
}, | ||
axis: { | ||
y: { | ||
title: 'Temperature (°C)', | ||
grid: false, | ||
style: { | ||
titleFill: '#EE6666', | ||
}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
type: 'interval', | ||
encode: { | ||
x: 'Month', | ||
y: 'Evaporation', | ||
color: '#5470C6', | ||
}, | ||
scale: { | ||
y: { independent: true, domainMax: 200 }, | ||
}, | ||
style: { | ||
fillOpacity: 0.8, | ||
}, | ||
axis: { | ||
y: { | ||
title: 'Evaporation (°C)', | ||
grid: null, | ||
style: { | ||
titleFill: '#5470C6', | ||
}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
type: 'line', | ||
encode: { | ||
x: 'Month', | ||
y: 'Precipitation', | ||
color: '#91CC75', | ||
}, | ||
scale: { | ||
y: { independent: true }, | ||
}, | ||
style: { | ||
lineWidth: 2, | ||
lineDash: [2, 2], | ||
}, | ||
axis: { | ||
y: { | ||
position: 'right', | ||
title: 'Precipitation (ml)', | ||
grid: false, | ||
style: { | ||
titleFill: '#91CC75', | ||
}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
type: 'legends', | ||
scale: { | ||
color: { | ||
type: 'ordinal', | ||
independent: true, | ||
domain: ['#EE6666', '#91CC75', '#5470C6'], | ||
range: ['#EE6666', '#91CC75', '#5470C6'], | ||
}, | ||
}, | ||
itemMarker: (d) => markerByValue[d], | ||
labelFormatter: (d) => labelByValue[d], | ||
}, | ||
], | ||
}; | ||
} | ||
|
||
weatherLineLegendMark.steps = ({ canvas }) => { | ||
const { document } = canvas; | ||
const elements = document.getElementsByClassName(LEGEND_ITEMS_CLASS_NAME); | ||
const [, , e2] = elements; | ||
return [step(e2, 'click'), step(e2, 'click')]; | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { G2Spec } from '../../../src'; | ||
|
||
export function mockLegendColorSize(): G2Spec { | ||
return { | ||
type: 'legends', | ||
padding: 'auto', | ||
height: 100, | ||
scale: { | ||
color: { | ||
type: 'ordinal', | ||
domain: ['a', 'b'], | ||
range: ['steelblue', 'orange'], | ||
}, | ||
size: { | ||
type: 'linear', | ||
domain: [0, 10], | ||
range: [0, 100], | ||
}, | ||
}, | ||
}; | ||
} |
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,16 @@ | ||
import { G2Spec } from '../../../src'; | ||
|
||
export function mockLegendColor(): G2Spec { | ||
return { | ||
type: 'legends', | ||
padding: 'auto', | ||
height: 100, | ||
scale: { | ||
color: { | ||
type: 'ordinal', | ||
domain: ['a', 'b'], | ||
range: ['steelblue', 'orange'], | ||
}, | ||
}, | ||
}; | ||
} |
103 changes: 103 additions & 0 deletions
103
__tests__/plots/static/weather-line-multi-axes-legend.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,103 @@ | ||
import { G2Spec } from '../../../src'; | ||
import { weather } from '../../data/weather'; | ||
|
||
export function weatherLineMultiAxesLegend(): G2Spec { | ||
const labelByValue = { | ||
'#EE6666': 'Temperature', | ||
'#5470C6': 'Evaporation', | ||
'#91CC75': 'Precipitation', | ||
}; | ||
const markerByValue = { | ||
'#EE6666': 'line', | ||
'#5470C6': 'rect', | ||
'#91CC75': 'line', | ||
}; | ||
return { | ||
type: 'view', | ||
data: weather, | ||
children: [ | ||
{ | ||
type: 'line', | ||
encode: { | ||
x: 'Month', | ||
y: 'Temperature', | ||
color: '#EE6666', | ||
shape: 'smooth', | ||
}, | ||
scale: { | ||
y: { independent: true, domainMax: 30 }, | ||
}, | ||
axis: { | ||
y: { | ||
title: 'Temperature (°C)', | ||
grid: false, | ||
style: { | ||
titleFill: '#EE6666', | ||
}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
type: 'interval', | ||
encode: { | ||
x: 'Month', | ||
y: 'Evaporation', | ||
color: '#5470C6', | ||
}, | ||
scale: { | ||
y: { independent: true, domainMax: 200 }, | ||
}, | ||
style: { | ||
fillOpacity: 0.8, | ||
}, | ||
axis: { | ||
y: { | ||
title: 'Evaporation (°C)', | ||
grid: null, | ||
style: { | ||
titleFill: '#5470C6', | ||
}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
type: 'line', | ||
encode: { | ||
x: 'Month', | ||
y: 'Precipitation', | ||
color: '#91CC75', | ||
}, | ||
scale: { | ||
y: { independent: true }, | ||
}, | ||
style: { | ||
lineWidth: 2, | ||
lineDash: [2, 2], | ||
}, | ||
axis: { | ||
y: { | ||
position: 'right', | ||
title: 'Precipitation (ml)', | ||
grid: false, | ||
style: { | ||
titleFill: '#91CC75', | ||
}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
type: 'legends', | ||
scale: { | ||
color: { | ||
type: 'ordinal', | ||
independent: true, | ||
domain: ['#EE6666', '#91CC75', '#5470C6'], | ||
range: ['#EE6666', '#91CC75', '#5470C6'], | ||
}, | ||
}, | ||
itemMarker: (d) => markerByValue[d], | ||
labelFormatter: (d) => labelByValue[d], | ||
}, | ||
], | ||
}; | ||
} |
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.