Skip to content

Commit

Permalink
gsuiDotline: use of gsui0ne
Browse files Browse the repository at this point in the history
  • Loading branch information
mr21 committed Apr 19, 2024
1 parent 4af2092 commit e3da762
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 45 deletions.
78 changes: 33 additions & 45 deletions gsuiDotline/gsuiDotline.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"use strict";

class gsuiDotline extends HTMLElement {
#dispatch = GSUdispatchEvent.bind( null, this, "gsuiDotline" );
class gsuiDotline extends gsui0ne {
#data = {};
#dataSaved = null;
#dots = {};
Expand All @@ -22,55 +21,50 @@ class gsuiDotline extends HTMLElement {
#dotMinY = 0;
#mousebtn = 0;
#activeDot = null;
#onresizeBind = this.#onresize.bind( this );
#children = GSUgetTemplate( "gsui-dotline" );
#elements = GSUfindElements( this.#children, {
svg: "svg",
polyline: "polyline",
} );

constructor() {
super();
super( {
$cmpName: "gsuiDotline",
$tagName: "gsui-dotline",
$elements: {
$svg: "svg",
$polyline: "polyline",
},
$attributes: {
viewbox: "0 0 100 100",
xstep: 1,
ystep: 1,
},
} );
Object.seal( this );
this.oncontextmenu = GSUnoopFalse;
this.onpointerdown = this.#onpointerdown.bind( this );
}

// .........................................................................
connectedCallback() {
if ( !this.firstChild ) {
this.append( ...this.#children );
this.#children = null;
GSUrecallAttributes( this, {
viewbox: "0 0 100 100",
xstep: 1,
ystep: 1,
} );
}
GSUobserveSizeOf( this, this.#onresizeBind );
}
disconnectedCallback() {
GSUunobserveSizeOf( this, this.#onresizeBind );
}
static get observedAttributes() {
return [ "viewbox" ];
}
attributeChangedCallback( prop, prev, val ) {
if ( !this.#children && prev !== val ) {
switch ( prop ) {
case "viewbox": {
const v = val.split( " " );
$attributeChanged( prop, val ) {
switch ( prop ) {
case "viewbox": {
const v = val.split( " " );

this.#xmin = +v[ 0 ];
this.#ymin = +v[ 1 ];
this.#xmax = +v[ 2 ];
this.#ymax = +v[ 3 ];
this.#w = this.#xmax - this.#xmin;
this.#h = this.#ymax - this.#ymin;
} break;
}
this.#xmin = +v[ 0 ];
this.#ymin = +v[ 1 ];
this.#xmax = +v[ 2 ];
this.#ymax = +v[ 3 ];
this.#w = this.#xmax - this.#xmin;
this.#h = this.#ymax - this.#ymin;
} break;
}
}
$onresize( w, h ) {
this.#svgW = w;
this.#svgH = h;
GSUsetAttribute( this.$elements.$svg, "viewBox", `0 0 ${ w } ${ h }` );
this.#drawPolyline();
}

// .........................................................................
$change( diff ) {
Expand Down Expand Up @@ -121,14 +115,14 @@ class gsuiDotline extends HTMLElement {
return arr.join( " " );
}
#drawPolyline() {
GSUsetAttribute( this.#elements.polyline, "points",
GSUsetAttribute( this.$elements.$polyline, "points",
gsuiDotline.$draw( this.#data, this.#svgW, this.#svgH, this.#w, this.#h, this.#xmin, this.#ymin ) );
}
#onchange() {
const diff = GSUdiffObjects( this.#dataSaved, this.#data );

if ( diff ) {
this.#dispatch( "change", diff );
this.$dispatch( "change", diff );
}
}

Expand Down Expand Up @@ -179,12 +173,6 @@ class gsuiDotline extends HTMLElement {
}

// .........................................................................
#onresize( w, h ) {
this.#svgW = w;
this.#svgH = h;
GSUsetAttribute( this.#elements.svg, "viewBox", `0 0 ${ w } ${ h }` );
this.#drawPolyline();
}
#onpointerdown( e ) {
let id = e.target.dataset.id;

Expand Down
1 change: 1 addition & 0 deletions gsuiDotline/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
<script src="/gs-ui-components/gs-utils/gs-utils.js"></script>
<script src="/gs-ui-components/gs-utils/gs-utils-dom.js"></script>
<script src="/gs-ui-components/gs-utils/gs-utils-json.js"></script>
<script src="/gs-ui-components/gsui0ne/gsui0ne.js"></script>
<script src="/gs-ui-components/test-assets/test.js"></script>

<!-- ....................................................................... -->
Expand Down

0 comments on commit e3da762

Please sign in to comment.