File tree Expand file tree Collapse file tree 5 files changed +46
-4
lines changed Expand file tree Collapse file tree 5 files changed +46
-4
lines changed Original file line number Diff line number Diff line change @@ -30,6 +30,7 @@ import isDataRecord from './isDataRecord.js';
30
30
31
31
import { createProjection } from './projection.js' ;
32
32
import { maybeInterval } from './autoTicks.js' ;
33
+ import { IS_SORTED } from 'svelteplot/transforms/sort.js' ;
33
34
34
35
/**
35
36
* compute the plot scales
@@ -183,7 +184,8 @@ export function createScale<T extends ScaleOptions>(
183
184
// we're deliberately checking for !== undefined and not for != null
184
185
// since the explicit sort transforms like shuffle will set the
185
186
// sort channel to null to we know that there's an explicit order
186
- if ( name === 'x' && mark . options . sort != null ) {
187
+ if ( name === 'y' ) console . log ( mark . type , mark . options [ IS_SORTED ] ) ;
188
+ if ( mark . options [ IS_SORTED ] != null ) {
187
189
sortOrdinalDomain = false ;
188
190
}
189
191
for ( const channel of mark . channels ) {
Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ import { shuffler } from 'd3-array';
5
5
import { randomLcg } from 'd3-random' ;
6
6
7
7
export const SORT_KEY = Symbol ( 'sortKey' ) ;
8
+ export const IS_SORTED = Symbol ( 'isSorted' ) ;
8
9
9
10
export function sort (
10
11
{ data, ...channels } : TransformArg < DataRecord > ,
@@ -38,6 +39,7 @@ export function sort(
38
39
. map ( ( { [ SORT_KEY ] : a , ...rest } ) => rest ) ,
39
40
40
41
...channels ,
42
+ [ IS_SORTED ] : sort ,
41
43
// set the sort channel to null to disable the implicit alphabetical
42
44
// ordering of ordinal domains, and also to avoid double sorting in case
43
45
// this transform is used "outside" a mark
Original file line number Diff line number Diff line change @@ -445,7 +445,7 @@ export type PlotDefaults = {
445
445
css : ( d : string ) => string | undefined ;
446
446
} ;
447
447
448
- export type GenericMarkOptions = Record < string , any > ;
448
+ export type GenericMarkOptions = Record < string | symbol , any > ;
449
449
450
450
export type DataRecord = Record < string | symbol , RawValue > & {
451
451
___orig___ ?: RawValue | [ RawValue , RawValue ] ;
@@ -657,6 +657,15 @@ export type BaseMarkProps = Partial<{
657
657
dy : ConstantAccessor < number > ;
658
658
fill : ConstantAccessor < string > ;
659
659
fillOpacity : ConstantAccessor < number > ;
660
+ sort :
661
+ | string
662
+ | ConstantAccessor < RawValue >
663
+ | {
664
+ /** sort data using an already defined channel */
665
+ channel : string ;
666
+ /** sort order */
667
+ order ?: 'ascending' | 'descending' ;
668
+ } ;
660
669
stroke : ConstantAccessor < string > ;
661
670
strokeWidth : ConstantAccessor < number > ;
662
671
strokeOpacity : ConstantAccessor < number > ;
Original file line number Diff line number Diff line change 1
1
import { loadDatasets , loadJSON } from '$lib/helpers/data.js' ;
2
- import type { PageLoad } from './$types.js ' ;
2
+ import type { PageServerLoad } from '.. /$types' ;
3
3
4
4
export const ssr = true ;
5
5
6
- export const load : PageLoad = async ( { fetch } ) => {
6
+ export const load : PageServerLoad = async ( { fetch } ) => {
7
7
return {
8
8
data : {
9
9
world : await loadJSON ( fetch , 'countries-110m' ) ,
@@ -16,6 +16,7 @@ export const load: PageLoad = async ({ fetch }) => {
16
16
'co2' ,
17
17
'crimea' ,
18
18
'driving' ,
19
+ 'languages' ,
19
20
'penguins' ,
20
21
'riaa' ,
21
22
'stateage' ,
Original file line number Diff line number Diff line change
1
+ <script module >
2
+ export const title = ' Dot plot' ;
3
+ </script >
4
+
5
+ <script >
6
+ import { Plot , Dot , GridY } from ' svelteplot' ;
7
+ import { page } from ' $app/state' ;
8
+ let { languages } = $derived (page .data .data );
9
+ </script >
10
+
11
+ <Plot
12
+ frame
13
+ inset ={20 }
14
+ x ={{
15
+ type : ' log' ,
16
+ axis : ' both' ,
17
+ label : ' NUMBER OF SPEAKERS' ,
18
+ labelAnchor : ' center'
19
+ }}
20
+ y ={{ type : ' point' , label : ' ' }}>
21
+ <GridY strokeDasharray ="1,3" strokeOpacity ={0.5 } />
22
+ <Dot
23
+ data ={languages .filter ((d ) => d [' Total speakers' ] >= 70e6 )}
24
+ fill =" currentColor"
25
+ sort ={{ channel : ' -x' }}
26
+ y =" Language"
27
+ x =" Total speakers" />
28
+ </Plot >
You can’t perform that action at this time.
0 commit comments