diff --git a/plot/cube/cube.view.tree b/plot/cube/cube.view.tree index 7ebd40f..0c3c0a5 100644 --- a/plot/cube/cube.view.tree +++ b/plot/cube/cube.view.tree @@ -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 diff --git a/plot/cube/cube.view.ts b/plot/cube/cube.view.ts index 2aecb05..44b4c97 100644 --- a/plot/cube/cube.view.ts +++ b/plot/cube/cube.view.ts @@ -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() ] : [], ] } @@ -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< [string/*label*/, number/*json index*/], 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)=> { + + const prev = entries.get( label ) ?? [] + entries.set( label, [ ...prev, index ] ) + values.set( [ label, index ], points.v[i] ) + + 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] ) + } - return this.multi_jsons().map( (json: any, index: number) => { - const json_valid = $mpds_visavis_plot_cube_json( json ) + } ) + + } ) + + 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> = 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 @@ -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() ], ] } @@ -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 = []; diff --git a/plot/legend/cmp/cmp.view.tree b/plot/legend/cmp/cmp.view.tree index aef3282..fa0a8fb 100644 --- a/plot/legend/cmp/cmp.view.tree +++ b/plot/legend/cmp/cmp.view.tree @@ -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 / diff --git a/plot/legend/cmp/cmp.view.ts b/plot/legend/cmp/cmp.view.ts index d16841a..64ceb3f 100644 --- a/plot/legend/cmp/cmp.view.ts +++ b/plot/legend/cmp/cmp.view.ts @@ -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 {