Skip to content

Commit

Permalink
Merge pull request #26 from mpds-io/intersection
Browse files Browse the repository at this point in the history
Intersections
  • Loading branch information
blokhin authored Mar 30, 2024
2 parents 6c1db79 + f8c1852 commit 759b370
Show file tree
Hide file tree
Showing 7 changed files with 182 additions and 60 deletions.
6 changes: 3 additions & 3 deletions plot/cube/cube.view.tree
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ $mpds_visavis_plot_cube $mol_view
hint \Continuous solid solutions and complete insolubility systems
title \Show non-formers
checked? <=> nonformers_checked? false
<= Difference_on $mol_check_box
title \Show difference
checked? <=> difference_checked? false
<= Intersection_on $mol_check_box
title \Show intersection
checked? <=> intersection_only? false
<= X_order $mol_labeler
title \X sort by
Content <= X_order_select $mol_select
Expand Down
113 changes: 95 additions & 18 deletions plot/cube/cube.view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace $.$$ {
setup() {
return [
... this.show_fixel() ? [ this.Fixel() ] : [],
this.multi_jsons() ? this.Difference_on() : this.Nonformers(),
this.multi_jsons() ? this.Intersection_on() : this.Nonformers(),
... this.show_setup() ? [ this.X_order(), this.Y_order(), this.Z_order() ] : [],
]
}
Expand Down Expand Up @@ -138,27 +138,103 @@ namespace $.$$ {
}

@ $mol_mem
multi_dataset(): any[] | null {
if( ! this.multi_jsons() ) return null
scatters() {

this.nonformers_checked( false )
const values: Map< [ label: string, json_index: number ], number/*v*/ > = new Map()

const entries: Map< string/*point label*/, number[]/*json indexes*/> = new Map()

const labels: Set< string > = new Set()
let points_x: number[] = []
let points_y: number[] = []
let points_z: number[] = []

this.multi_jsons().map( (json: any, index: number) => {

const points = $mpds_visavis_plot_cube_json( json ).payload.points
points.labels.forEach( (label, i)=> {

entries.get( label )?.push( index ) ?? entries.set( label, [ index ] )

values.set( [ label, index ], points.v[i] )

return this.multi_jsons().map( (json: any, index: number) => {
const json_valid = $mpds_visavis_plot_cube_json( json )
if( !labels.has( label ) ) {
labels.add( label )
points_x.push( points.x[i] )
points_y.push( points.y[i] )
points_z.push( points.z[i] )
}

} )

} )

const converted = this.convert_to_axes(
points_x, points_y, points_z,
this.x_sort() as Prop_name,
this.y_sort() as Prop_name,
this.z_sort() as Prop_name,
)

const points: Map< string, { x: number, y: number, z: number } > = new Map
;[...labels].forEach( ( label, i ) => points.set( label, {
x: converted.x[ i ],
y: converted.y[ i ],
z: converted.z[ i ],
}) )

const new_scatter = ( index: number | 'intersection' )=> {
return {
...this.scatter3d_common(),
text: json_valid.payload.points.labels,
marker: this.marker( index ),
...this.convert_to_axes(
json_valid.payload.points.x,
json_valid.payload.points.y,
json_valid.payload.points.z,
this.x_sort() as Prop_name,
this.y_sort() as Prop_name,
this.z_sort() as Prop_name,
)
marker: index == 'intersection' ? {color: "#303030", size: 5, opacity: 0.9} : this.marker( index ),
x: [] as number[],
y: [] as number[],
z: [] as number[],
v: [] as number[],
text: [] as string[],
}
}

const scatters_once: Map<number, ReturnType< typeof new_scatter >> = new Map()
const intersects = new_scatter( 'intersection' )

entries.forEach( ( entry, label )=> {

const point = points.get( label )!

let scatter = intersects
if( entry.length == 1 ) {
const index = entry[ 0 ]
scatter = scatters_once.get( index ) ?? new_scatter( index )
scatters_once.set( index, scatter )

scatter.v.push( values.get( [ label, index ] )! )
}

scatter.text.push( label )
scatter.x.push( point.x )
scatter.y.push( point.y )
scatter.z.push( point.z )

} )

return { intersects, scatters_once }

}

@ $mol_mem
multi_dataset(): any[] | null {

if( ! this.multi_jsons() ) return null

this.nonformers_checked( false )
const { intersects, scatters_once } = this.scatters()

return [
intersects,
... this.intersection_only() ? [] : scatters_once.values()
]

}

@ $mol_mem
Expand All @@ -168,9 +244,10 @@ namespace $.$$ {

@ $mol_mem
data_shown() {
const dataset = this.multi_dataset()
return [
... this.nonformers_checked() ? [ this.data_nonformers() ] : [],
... this.multi_dataset() ? this.multi_dataset()! : [ this.data() ],
... dataset ? dataset! : [ this.data() ],
]
}

Expand Down Expand Up @@ -276,7 +353,7 @@ namespace $.$$ {
z_op?: any
){
//console.log(x_src, y_src, z_src, x_sort, y_sort, z_sort, x_op, y_op, z_op);
var converted = {'x': [], 'y': [], 'z': []};
var converted: {x: number[], y: number[], z: number[]} = {'x': [], 'y': [], 'z': []}

if (x_op){
var x_temp = [];
Expand Down
6 changes: 4 additions & 2 deletions plot/legend/cmp/cmp.view.css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ namespace $.$$ {

$mol_style_define( $mpds_visavis_plot_legend_cmp, {

lineHeight: '1',
lineHeight: '1.3',

position: 'absolute',
left: 0,
Expand All @@ -11,7 +11,7 @@ namespace $.$$ {
padding: {
bottom: $mol_gap.space,
},

gap: $mol_gap.block,
align: {
items: 'center',
Expand All @@ -25,6 +25,8 @@ namespace $.$$ {
$mol_style_define( $mpds_visavis_plot_legend_cmp_label, {

color: 'white',
fontSize: '0.8em',
fontStyle: 'italic',
padding: {
left: $mol_gap.space,
right: $mol_gap.space,
Expand Down
5 changes: 3 additions & 2 deletions plot/legend/cmp/cmp.view.tree
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ $mpds_visavis_plot_legend_cmp $mol_view
<= Label*0 $mpds_visavis_plot_legend_cmp_label
label <= label* \
background <= background* \
\vs.
<= Label*1
<= Intersection $mpds_visavis_plot_legend_cmp_label
label \Intersection
background \gray
labels /
colorset /

Expand Down
8 changes: 5 additions & 3 deletions plot/legend/cmp/cmp.view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ namespace $.$$ {
export class $mpds_visavis_plot_legend_cmp extends $.$mpds_visavis_plot_legend_cmp {

sub(): readonly any[] {
return this.labels().length == 2
? super.sub()
: this.labels().map( ( label, ind ) => this.Label( ind ) )
const labels = this.labels()
return [
...labels.map( ( label, ind ) => this.Label( ind ) ),
...labels.length > 1 ? [ this.Intersection() ] : []
]
}

label( index: number ): string {
Expand Down
6 changes: 3 additions & 3 deletions plot/matrix/matrix.view.tree
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ $mpds_visavis_plot_matrix $mol_view
hint \Continuous solid solutions and complete insolubility systems
title \Show non-formers
checked? <=> nonformers_checked? false
<= Difference_on $mol_check_box
title \Show difference
checked? <=> difference_checked? false
<= Intersection_on $mol_check_box
title \Show intersection
checked? <=> intersection_only? false
<= Order $mol_labeler
title \Sort by
Content <= Order_switch $mol_switch
Expand Down
Loading

0 comments on commit 759b370

Please sign in to comment.