Skip to content

Commit

Permalink
Add lines example + doc
Browse files Browse the repository at this point in the history
  • Loading branch information
denis-migdal committed Nov 12, 2024
1 parent b00be2c commit c2ccd86
Show file tree
Hide file tree
Showing 27 changed files with 201 additions and 69 deletions.
26 changes: 25 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,28 @@
## Build

- `npm run build`
- `npm run watch`
- `npm run watch`

## TODO

### Bugs

- canvas overflow (1px de trop)
- default datalabel/zoom

### Features

- share components (clone)
- move components (remove and add)

- if color starts with -- => use css prop computed value ? (requires to manually update)

### Refactors

- refactor internals
- use signal/computedSignal/effect

### TS type errors

- LISS(extends)
- ChartHTML.XXX
5 changes: 5 additions & 0 deletions dist/dev/assets/examples/html-line/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<chart-html>
<curve-line>
[[0,0], [1,1], [2,0]]
</curve-line>
</chart-html>
5 changes: 5 additions & 0 deletions dist/dev/assets/examples/js-line/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const graph = new ChartHTML();
graph.addComponent(ChartHTML.Line, {
content: [[0,0], [1,1], [2,0]]
});
document.body.append(graph.host);
84 changes: 52 additions & 32 deletions dist/dev/index.js

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions dist/dev/pages/playground/index.js

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions dist/libs/LISS/src/LISSHost.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/libs/LISS/src/LISSHost.js.map

Large diffs are not rendered by default.

30 changes: 30 additions & 0 deletions doc/fr/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,34 @@ document.body.append(graph.host);
<a href="https://denis-migdal.github.io/ChartsHTML/dist/dev/pages/playground/?example=js-empty">playground</a>
</td></tr>
</tfoot>
</table>

Nous pouvons ensuite ajouter, e.g. une ligne au graphe :
<table>
<thead>
<tr><th>HTML</th><th>JS</th></tr>
</thead>
<tbody>
<tr><td>
<pre><code lang="html">&lt;chart-html&gt;
&lt;curve-line&gt;
[[0,0], [1,1], [2,0]]
&lt;/curve-line&gt;
&lt;/chart-html&gt;</code></pre>
</td><td>
<pre><code lang="js">const graph = new ChartHTML();
graph.addComponent(ChartHTML.Line, {
content: [[0,0], [1,1], [2,0]]
});
document.body.append(graph.host);
</code></pre>
</td></tr>
</tbody>
<tfoot>
<tr><td>
<a href="https://denis-migdal.github.io/ChartsHTML/dist/dev/pages/playground/?example=html-line">playground</a>
</td><td>
<a href="https://denis-migdal.github.io/ChartsHTML/dist/dev/pages/playground/?example=js-line">playground</a>
</td></tr>
</tfoot>
</table>
5 changes: 5 additions & 0 deletions src/assets/examples/html-line/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<chart-html>
<curve-line>
[[0,0], [1,1], [2,0]]
</curve-line>
</chart-html>
5 changes: 5 additions & 0 deletions src/assets/examples/js-line/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const graph = new ChartHTML();
graph.addComponent(ChartHTML.Line, {
content: [[0,0], [1,1], [2,0]]
});
document.body.append(graph.host);
4 changes: 2 additions & 2 deletions src/components/curves/Bars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import LISS from "../../../libs/LISS/src/index.ts";
//@ts-ignore
export default class Bars extends LISS({extends: Dataset, attrs: ['reversed']}) {

constructor() {
super();
constructor(...args: any[]) {
super(...args);

this.setAttrDefault('type', 'bar');
}
Expand Down
4 changes: 2 additions & 2 deletions src/components/curves/HLine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import LISS from "../../../libs/LISS/src/index.ts";

export default class HLine extends LISS({extends: Line}) {

constructor() {
super();
constructor(...args: any[]) {
super(...args);

this.setAttrDefault('showPoints', 'false');
}
Expand Down
4 changes: 2 additions & 2 deletions src/components/curves/Histogram.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import LISS from "../../../libs/LISS/src/index.ts";

export default class Histogram extends LISS({extends: Bars, attrs: ['precision']}) {

constructor() {
super();
constructor(...args: any[]) {
super(...args);
}

override _contentParser(content: unknown) {
Expand Down
4 changes: 2 additions & 2 deletions src/components/curves/Line.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import LISS from "../../../libs/LISS/src/index.ts";
//@ts-ignore : "Property 'onAttrChanged' is protected in type 'Line' but public in type 'Dataset'." WTF ???
export default class Line extends LISS({extends: Dataset, attrs: ['show-points', 'decimate']}) {

constructor() {
super();
constructor(...args: any[]) {
super(...args);

this.setAttrDefault('type', 'scatter');
}
Expand Down
4 changes: 2 additions & 2 deletions src/components/curves/Points.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import LISS from "../../../libs/LISS/src/index.ts";
//@ts-ignore : "Property 'onAttrChanged' is protected in type 'Line' but public in type 'Dataset'." WTF ???
export default class Points extends LISS({extends: Dataset}) {

constructor() {
super();
constructor(...args: any[]) {
super(...args);

this.setAttrDefault('type', 'scatter');
}
Expand Down
4 changes: 2 additions & 2 deletions src/components/curves/Timelapse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import LISS from "../../../libs/LISS/src/index.ts";

export default class Timelapse extends LISS({extends: Line}) {

constructor() {
super();
constructor(...args: any[]) {
super(...args);
}

override _contentParser(content: unknown) {
Expand Down
4 changes: 2 additions & 2 deletions src/components/curves/VLine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import LISS from "../../../libs/LISS/src/index.ts";

export default class VLine extends LISS({extends: Line}) {

constructor() {
super();
constructor(...args: any[]) {
super(...args);

this.setAttrDefault('showPoints', 'false');
}
Expand Down
4 changes: 2 additions & 2 deletions src/components/datalabels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import LISS from "../../libs/LISS/src/index.ts";

export default class Datalabels extends LISS({extends: GraphComponent}) {

constructor() {
super();
constructor(...args: any[]) {
super(...args);
this.host.setAttribute('slot', 'options');

//TODO : move 2 parents....
Expand Down
8 changes: 5 additions & 3 deletions src/components/dataset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,17 @@ export default class Dataset extends LISS({extends: GraphComponent, attrs: ['typ

#chart?: ChartHTML;

constructor() {
super();
constructor(...args: any[]) {
super(...args);

this.host.setAttribute('slot', 'dataset');
this.setAttrDefault('color', 'black');
}

#dataset = {
name: this.attrs.name,
data: [],
type: ""
type: null
};
get dataset() {
return this.#dataset as any;
Expand Down
4 changes: 2 additions & 2 deletions src/components/datasets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { StringEval } from '..';

export default class Datasets extends LISS({extends: GraphComponent, shadow: ShadowCfg.OPEN, attrs: ['type', 'tooltip', 'color', 'colors']}) {

constructor() {
super();
constructor(...args: any[]) {
super(...args);
this.host.setAttribute('slot', 'datasets');
}

Expand Down
12 changes: 11 additions & 1 deletion src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,17 @@ export default class GraphComponent extends LISS({shadow: ShadowCfg.NONE,attrs:

#chart?: ChartHTML;

constructor() {
constructor(params: Record<string,any> = {}) {
super();

for(let key in params ) {
if( key === "content" ) {
this.host.textContent = JSON.stringify(params.content);
continue;
}
this.attrs[key] = params[key];
}

this.#contentInit();
}

Expand Down Expand Up @@ -67,6 +76,7 @@ export default class GraphComponent extends LISS({shadow: ShadowCfg.NONE,attrs:
_attach(chart: ChartHTML) {
this.#chart = chart;
this._insert();

if( this.isInDOM)
this._update();
}
Expand Down
4 changes: 2 additions & 2 deletions src/components/scale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ export default class Scale extends LISS({extends: GraphComponent, attrs: ['min',

#chart?: ChartHTML;

constructor() {
super();
constructor(...args: any[]) {
super(...args);

this.host.setAttribute('slot', 'scale');
}
Expand Down
4 changes: 2 additions & 2 deletions src/components/tooltip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import {Chart, ChartType, TooltipItem, ChartDataset} from 'chart.js';
//TODO: direction... (with zoom...)
export default class Tooltip extends LISS({extends: GraphComponent, attrs: ['direction']}) {

constructor() {
super();
constructor(...args: any[]) {
super(...args);

this.host.setAttribute('slot', 'options');

Expand Down
4 changes: 2 additions & 2 deletions src/components/value.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import {Chart} from 'chart.js';

export default class Value extends LISS({extends: GraphComponent}) {

constructor() {
super();
constructor(...args: any[]) {
super(...args);
this.host.setAttribute('slot', 'dataset');

const observer = new MutationObserver( () => {
Expand Down
4 changes: 2 additions & 2 deletions src/components/zoom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import {Chart} from 'chart.js';

export default class ChartZoom extends LISS({extends: GraphComponent, attrs:['direction']}) {

constructor() {
super();
constructor(...args: any[]) {
super(...args);
this.host.setAttribute('slot', 'options');

this.setAttrDefault('direction', 'xy');
Expand Down
21 changes: 20 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ Chart.register(CategoryScale);

const CSS = `
:host {
position: relative;
display: block;
width: 100%;
height: 100%;
Expand Down Expand Up @@ -93,6 +94,18 @@ export default class ChartHTML extends LISS({css: CSS, attrs: ["measure-render-t
this.updateAll();
}

addComponent(Component: Constructor<Dataset>, params: Record<string,string|null> = {}) {

let instance = new Component(params);
this.host.append(instance.host);
instance._attach(this);

this.#components.push(instance);

//instance._before_chart_update();
//this.update();
}

evalContext(context = {}) {
return {c: context, v: this.#values};
}
Expand Down Expand Up @@ -140,6 +153,7 @@ export default class ChartHTML extends LISS({css: CSS, attrs: ["measure-render-t
options: {
locale: 'en-IN',
animation: false,
responsive: true,
maintainAspectRatio: false,
scales: {},
plugins: {},
Expand Down Expand Up @@ -200,6 +214,8 @@ export default class ChartHTML extends LISS({css: CSS, attrs: ["measure-render-t
return;
this.#isUpdatingAll = true;

this._chartJS.resize();

for(let elem of this.#components)
elem.update(); //TODO...

Expand Down Expand Up @@ -248,13 +264,16 @@ import "./components/scale.ts";

import "./components/datasets.ts";
import "./components/dataset.ts";
import './components/curves/Line';
import Line from './components/curves/Line';
import './components/curves/HLine';
import './components/curves/VLine';
import './components/curves/Timelapse';
import './components/curves/Bars';
import './components/curves/Histogram';
import './components/curves/Points';
import Dataset from "./components/dataset";
import { Constructor } from "LISS/src/types.ts";

ChartHTML.Line = Line;

LISS.define('chart-html', ChartHTML);
2 changes: 2 additions & 0 deletions src/pages/playground/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ let iframe = document.querySelector('iframe')!;

const examples = [
"html-empty",
"html-line",

"js-empty",
"js-line",
];

const resources = [
Expand Down

0 comments on commit c2ccd86

Please sign in to comment.