Skip to content

Commit

Permalink
added data-id to the lines using the new chrt-object index function
Browse files Browse the repository at this point in the history
  • Loading branch information
littleark committed Sep 18, 2023
1 parent a60b62f commit b41bd8d
Show file tree
Hide file tree
Showing 7 changed files with 1,601 additions and 1,162 deletions.
2,604 changes: 1,480 additions & 1,124 deletions package-lock.json

Large diffs are not rendered by default.

22 changes: 11 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,25 +53,25 @@
"homepage": "chrt.io",
"dependencies": {
"chrt-interpolations": "0.0.14",
"chrt-object": "0.0.16"
"chrt-object": "0.0.17"
},
"devDependencies": {
"@babel/core": "^7.22.10",
"@babel/plugin-transform-modules-commonjs": "^7.22.5",
"@babel/plugin-transform-runtime": "^7.22.10",
"@babel/preset-env": "^7.22.10",
"@babel/core": "^7.22.20",
"@babel/plugin-transform-modules-commonjs": "^7.22.15",
"@babel/plugin-transform-runtime": "^7.22.15",
"@babel/preset-env": "^7.22.20",
"@rollup/plugin-babel": "^6.0.3",
"@rollup/plugin-node-resolve": "^15.1.0",
"@rollup/plugin-node-resolve": "^15.2.1",
"@rollup/plugin-terser": "^0.4.3",
"babel-jest": "^29.6.2",
"babel-jest": "^29.7.0",
"babel-plugin-root-import": "^6.6.0",
"babelify": "^10.0.0",
"budo": "^11.8.4",
"chrt": "0.0.154",
"eslint": "^8.46.0",
"chrt": "0.0.155",
"eslint": "^8.49.0",
"husky": "^8.0.3",
"jest": "^29.6.2",
"jest-environment-jsdom": "^29.6.2",
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
"npm-watch": "^0.11.0",
"rollup": "3",
"rollup-plugin-commonjs": "^10.1.0",
Expand Down
14 changes: 10 additions & 4 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@ import commonjs from 'rollup-plugin-commonjs';
import resolve from '@rollup/plugin-node-resolve';
import babel from '@rollup/plugin-babel';
import terser from '@rollup/plugin-terser';
import { default as meta } from './package.json' assert {
type: 'json',
};
// import * as meta from './package.json';
// assert import for JSON files
// import { default as meta } from './package.json' assert {
// type: 'json',
// };
import { readFile } from 'fs/promises';
const meta = JSON.parse(
await readFile(
new URL('./package.json', import.meta.url)
)
);

const STARTED = 2020;
const YEAR = new Date().getFullYear();
Expand Down
5 changes: 5 additions & 0 deletions src/chrtLine.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ function chrtLine() {

cssDisplay.call(this, this.attr('display')());

this.g.setAttribute('id', `${_area ? 'area' : 'line'}-${this.id()}`);
console.log('PARENT', this.parent().objects)

console.log('THIS', this.constructor.name)
this.g.setAttribute('data-id', `${this.constructor.name}-${this.parent().objects.filter(d => d.constructor.name === this.constructor.name).indexOf(this)}`);
this.g.classList.remove(...this.g.classList)
this.g.classList.add(...this._classNames);

Expand Down
48 changes: 25 additions & 23 deletions test/chrts/__snapshots__/charts.test.js.snap

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions test/chrts/charts/chrts.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ export { default as confidenceInterval } from './confidence-interval-chart.js';
export { default as areaChartWithSpline } from './area-chart-spline.js';
export { default as confidenceIntervalWithSpline } from './confidence-interval-chart-with-spline.js';
export { default as stackedAreaWithSpline } from './stacked-area-chart-with-spline.js';
export { default as multipleLines } from './multiple-lines.js';
69 changes: 69 additions & 0 deletions test/chrts/charts/multiple-lines.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import * as chrt from 'chrt';
import chrtLine from '../../../src/chrtLine'

const data1 = [
{
x: 'a',
y: 10
},
{
x: 'b',
y: 14
},
{
x: 'c',
y: 14
},
{
x: 'd',
y: 22
}
];

const data2 = [
{
x: 'a',
y: 2
},
{
x: 'b',
y: 6
},
{
x: 'c',
y: 18
},
{
x: 'd',
y: 20
}
];

export default async function(container) {
return chrt.Chrt()
.node(container)
.size(600, 200)
.x({ scale: 'ordinal' })
// .y({scale:'linear'})
// .y({domain:[1,10000], scale:'log'})
.add(chrt.xAxis())
.add(chrt.yAxis())
.add(
chrtLine()
.data(data1)
.width(0.5)
.color('#f00')
.opacity(0.8)
.hide()
.show()
)
.add(
chrtLine()
.data(data2)
.width(0.5)
.color('#00f')
.opacity(0.8)
.hide()
.show()
);
}

0 comments on commit b41bd8d

Please sign in to comment.