Compare commits

...

29 Commits
0.6.12 ... main

Author SHA1 Message Date
Coin de Gamma 348a289f1a Merge pull request '0.6.18' (#61) from 0.6.18 into main 1 month ago
glitch4347 17a2fdf94e 0.6.18 1 month ago
Coin de Gamma dc89f6cbb9 Merge pull request 'basic react component implementatino is sep project' (#59) from better-react-component-#58 into main 1 month ago
glitch4347 547c15c0b6 optimise excludes in libs in webpack 1 month ago
glitch4347 32d122ba4d back dev build 1 month ago
glitch4347 9c165f4e1f basic react component implementatino is sep project 1 month ago
Coin de Gamma ec2bd27acd Merge pull request '0.6.17' (#54) from 0.6.17 into main 2 months ago
glitch4347 815144d209 update core 0.6.23 2 months ago
glitch4347 1a80ca2cab 0.6.17 2 months ago
Coin de Gamma ee08db2f54 Merge pull request 'use events instead of eventsCallbacks' (#53) from core-0.6.23 into main 2 months ago
glitch4347 884fed6582 use events instead of eventsCallbacks 2 months ago
glitch4347 8aca72ce04 zoom out with ranges logic 2 months ago
Coin de Gamma c62a1c386f Merge pull request 'rename demo->basic, live and vertical && update readme' (#47) from rename-examples into main 2 months ago
glitch4347 de6237891c rename demo->basic, live and vertical && update readme 2 months ago
rozetko 7bcd0d298a 0.6.16 3 months ago
rozetko ee2f02be96 upd core 3 months ago
rozetko 456b888fe1 0.6.15 3 months ago
rozetko a34c0574e4 hotfix 3 months ago
rozetko 73dbf0ea67 0.6.14 3 months ago
rozetko ff5973b106 Merge pull request 'updateData: update segments and markers' (#44) from update-segments-and-markers-on-update-data into main 3 months ago
rozetko 878e86d849 updateData: update segments and markers 3 months ago
vargburz 1e8f8d0cb3 0.6.13 4 months ago
rozetko 39412e5f65 Merge pull request 'roken shared crosshair #42' (#43) from broken-shared-crosshair-#42 into main 4 months ago
rozetko 37da147343 Merge pull request '0.6.19 core usdage' (#41) from build-fail-on-core-0.6.18-udpate-#40 into main 4 months ago
glitch4347 0dac1c390e fix 4 months ago
glitch4347 07f454fe51 0.6.19 core usdage 4 months ago
vargburz 88d6b2b24a Merge pull request 'click-event' (#39) from click-event into main 4 months ago
glitch4347 837004c2ad onclick 4 months ago
glitch4347 e46c7bdfb6 some commit 4 months ago
  1. 11
      README.md
  2. 3
      build/webpack.base.conf.js
  3. 0
      examples/basic.html
  4. 0
      examples/live.html
  5. 33
      examples/mouse_click.html
  6. 0
      examples/mouse_move.html
  7. 0
      examples/vertical.html
  8. 37
      examples/zoom_out.html
  9. 11
      package.json
  10. 26
      react/build/webpack.base.conf.js
  11. 8
      react/build/webpack.dev.conf.js
  12. 6
      react/build/webpack.prod.conf.js
  13. 23
      react/package.json
  14. 11
      react/src/index.tsx
  15. 23
      react/tsconfig.json
  16. 1322
      react/yarn.lock
  17. 98
      src/index.ts
  18. 20
      src/types.ts
  19. 3
      tsconfig.json
  20. 10
      yarn.lock

11
README.md

@ -19,12 +19,11 @@
```
#### Other examples
[Static Chart](https://code.corpglory.net/chartwerk/line-pod/src/branch/main/examples/demo.html)
[Live Chart](https://code.corpglory.net/chartwerk/line-pod/src/branch/main/examples/demo_live.html)
[Vertical Chart](https://code.corpglory.net/chartwerk/line-pod/src/branch/main/examples/demo_vertical.html)
* [Basic](https://code.corpglory.net/chartwerk/line-pod/src/branch/main/examples/basic.html)
* [Live](https://code.corpglory.net/chartwerk/line-pod/src/branch/main/examples/live.html)
* [Vertical](https://code.corpglory.net/chartwerk/line-pod/src/branch/main/examples/vertical.html)
* [Segments](https://code.corpglory.net/chartwerk/line-pod/src/branch/main/examples/segments.html)
* [Markers](https://code.corpglory.net/chartwerk/line-pod/src/branch/main/examples/markers.html)
### Development

3
build/webpack.base.conf.js

@ -12,7 +12,8 @@ module.exports = {
plugins: [
new CopyPlugin({
patterns: [
{ from: "../react", to: "react" },
{ from: "../react/dist/index.js", to: "react/index.js" },
{ from: "../react/dist/index.d.ts", to: "react/index.d.ts" },
],
})
],

0
examples/demo.html → examples/basic.html

0
examples/demo_live.html → examples/live.html

33
examples/mouse_click.html

@ -0,0 +1,33 @@
<!DOCTYPE html>
<html>
<head>
<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
<meta content="utf-8" http-equiv="encoding">
<script src="../dist/index.dev.js" type="text/javascript"></script>
</head>
<body>
<div id="chart" style="width: 50%; height: 500px;"></div>
<script type="text/javascript">
const startTime = 1590590148;
const data = Array.from(
{ length: 20 },
(el, idx) => [startTime + idx * 10000, Math.floor(Math.random() * 30)]
);
let options = {
renderLegend: false, usePanning: false,
axis: { y: { range: [0, 50] } },
zoomEvents: { mouse: {
zoom: { isActive: false },
pan: { isActive: false },
} },
eventsCallbacks: { mouseClick: console.log }
}
var pod = new LinePod(
document.getElementById('chart'),
[{ datapoints: data }],
options
);
pod.render();
</script>
</body>
</html>

0
examples/mouse.html → examples/mouse_move.html

0
examples/demo_vertical.html → examples/vertical.html

37
examples/zoom_out.html

@ -0,0 +1,37 @@
<!DOCTYPE html>
<html>
<head>
<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
<meta content="utf-8" http-equiv="encoding">
<script src="../dist/index.dev.js" type="text/javascript"></script>
</head>
<body>
<div id="chart" style="width: 50%; height: 500px;"></div>
<script type="text/javascript">
const startTime = 1590590148;
const data = Array.from(
{ length: 20 },
(el, idx) => [startTime + idx * 10000, Math.floor(Math.random() * 30)]
);
let options = {
renderLegend: false, usePanning: false,
axis: { y: { range: [0, 50] } },
zoomEvents: { mouse: {
zoom: { isActive: true, orientation: "horizontal" },
pan: { isActive: false },
}},
events: {
zoomOut: function(centers, ranges) {
console.log('zoomOut', centers, ranges);
}
}
}
var pod = new LinePod(
document.getElementById('chart'),
[{ datapoints: data }],
options
);
pod.render();
</script>
</body>
</html>

11
package.json

@ -1,13 +1,13 @@
{
"name": "@chartwerk/line-pod",
"version": "0.6.12",
"version": "0.6.18",
"description": "Chartwerk line chart",
"main": "dist/index.js",
"files": [
"/dist"
],
"scripts": {
"build": "webpack --config build/webpack.prod.conf.js && webpack --config build/webpack.dev.conf.js",
"build": "rm -rf dist && cd react && yarn build && cd .. && webpack --config build/webpack.prod.conf.js && webpack --config build/webpack.dev.conf.js",
"dev": "webpack --watch --config build/webpack.dev.conf.js",
"test": "echo \"Error: no test specified\" && exit 1",
"update-core": "yarn up @chartwerk/core && yarn up @chartwerk/core@latest"
@ -19,7 +19,7 @@
"author": "CorpGlory",
"license": "ISC",
"dependencies": {
"@chartwerk/core": "latest"
"@chartwerk/core": "^0.6.23"
},
"devDependencies": {
"copy-webpack-plugin": "^11.0.0",
@ -30,5 +30,8 @@
"webpack": "^5.87.0",
"webpack-cli": "^5.1.4"
},
"packageManager": "yarn@3.2.1"
"packageManager": "yarn@3.2.1",
"workspaces": [
"react/*"
]
}

26
react/build/webpack.base.conf.js

@ -0,0 +1,26 @@
const path = require('path');
module.exports = {
entry: './src/index.tsx',
module: {
rules: [
{
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/,
},
],
},
resolve: {
extensions: ['.tsx', '.ts', '.js'],
},
output: {
filename: 'index.js',
path: path.resolve(__dirname, '../dist'),
libraryTarget: 'umd',
umdNamedDefine: true,
},
externals: [
'@chartwerk/line-pod', 'react'
]
};

8
react/build/webpack.dev.conf.js

@ -0,0 +1,8 @@
const baseWebpackConfig = require('./webpack.base.conf');
var conf = baseWebpackConfig;
conf.devtool = 'inline-source-map';
conf.mode = 'development';
conf.output.filename = 'index.dev.js';
module.exports = conf;

6
react/build/webpack.prod.conf.js

@ -0,0 +1,6 @@
const baseWebpackConfig = require('./webpack.base.conf');
var conf = baseWebpackConfig;
conf.mode = 'production';
module.exports = baseWebpackConfig;

23
react/package.json

@ -0,0 +1,23 @@
{
"name": "line-pod-react",
"version": "0.0.1",
"description": "React wrapper around line-pod",
"main": "dist/index.js",
"repository": "http://code.corpglory.net/chartwerk/line-pod.git",
"author": "CorpGlory Inc.",
"license": "ISC",
"scripts": {
"build": "webpack --config build/webpack.prod.conf.js",
"dev": "webpack --config build/webpack.dev.conf.js"
},
"dependencies": {
"@chartwerk/line-pod": "workspace:*",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"ts-loader": "^9.5.1",
"typescript": "^5.4.3",
"webpack": "^5.87.0"
}
}

11
react/ChartwerkLinePod.tsx → react/src/index.tsx

@ -2,7 +2,7 @@ import { LineTimeSerie, LineOptions, LinePod } from '@chartwerk/line-pod';
import { MarkersConf } from '@chartwerk/line-pod/dist/models/marker';
import { SegmentSerie } from '@chartwerk/line-pod/dist/models/segment';
import { useEffect, useRef, useState } from 'react';
import React, { useEffect, useRef, useState } from 'react';
import _ from 'lodash';
@ -17,7 +17,7 @@ export type ChartwerkLinePodProps = {
}
export function ChartwerkLinePod(props: ChartwerkLinePodProps) {
const [pod, setPod] = useState<LinePod | null>(null);
const [hack, setHack] = useState<number | null>(null);
@ -47,6 +47,12 @@ export function ChartwerkLinePod(props: ChartwerkLinePodProps) {
setPod(newPod);
newPod.render();
} else {
if(props.markersConf) {
pod.updateMarkers(props.markersConf);
}
if(props.segments) {
pod.updateSegments(props.segments);
}
// TODO: actually it's wrong logic with updates
// because it creates new pod anyway
pod.updateData(props.series, props.options);
@ -60,7 +66,6 @@ export function ChartwerkLinePod(props: ChartwerkLinePodProps) {
}
}, 1);
return (
<div id={props.id} className={props.className} ref={chartRef}></div>
);

23
react/tsconfig.json

@ -0,0 +1,23 @@
{
"compilerOptions": {
"target": "es5",
"rootDir": "./src",
"module": "esnext",
"moduleResolution": "node",
"declaration": true,
"declarationDir": "dist",
"allowSyntheticDefaultImports": true,
"inlineSourceMap": false,
"sourceMap": true,
"noEmitOnError": false,
"emitDecoratorMetadata": false,
"experimentalDecorators": true,
"noImplicitReturns": true,
"noImplicitThis": false,
"noImplicitUseStrict": false,
"noImplicitAny": false,
"noUnusedLocals": false,
"baseUrl": "./src",
"jsx": "react"
}
}

1322
react/yarn.lock

File diff suppressed because it is too large Load Diff

98
src/index.ts

@ -1,10 +1,11 @@
import { ChartwerkPod, VueChartwerkPodMixin, TimeFormat, CrosshairOrientation, BrushOrientation, yAxisOrientation } from '@chartwerk/core';
import { LineTimeSerie, LineOptions } from './types';
import { LineTimeSerie, LineOptions, MouseObj } from './types';
import { Markers } from './components/markers';
import { Segments } from './components/segments';
import { LineSeries } from './models/line_series';
import { MarkersConf } from './models/marker';
import { SegmentSerie } from './models/segment';
import * as d3 from 'd3';
import * as _ from 'lodash';
@ -28,8 +29,8 @@ class LinePod extends ChartwerkPod<LineTimeSerie, LineOptions> {
_el: HTMLElement,
_series: LineTimeSerie[] = [],
_options: LineOptions = {},
private _markersConf?: MarkersConf,
private _segmentSeries = [],
private _markersConf?: MarkersConf,
private _segmentSeries: SegmentSerie[] = [],
) {
super(_el, _series, _options);
this.series = new LineSeries(_series);
@ -53,7 +54,7 @@ class LinePod extends ChartwerkPod<LineTimeSerie, LineOptions> {
this._markersLayer = new Markers(this._markersConf, this.state);
this._markersLayer.render(this.metricContainer);
}
this._segmentsLayer = new Segments(this._segmentSeries, this.state);
this._segmentsLayer.render(this.metricContainer);
}
@ -167,23 +168,14 @@ class LinePod extends ChartwerkPod<LineTimeSerie, LineOptions> {
.style('pointer-events', 'none');
}
public renderSharedCrosshair(values: { x?: number, y?: number }): void {
this.onMouseOver(); // TODO: refactor to use it once
const eventX = this.state.xScale(values.x);
const eventY = this.state.yScale(values.y);
this.moveCrosshairLine(eventX, eventY);
const datapoints = this.findAndHighlightDatapoints(values.x, values.y);
this.options.callbackSharedCrosshairMove({
datapoints: datapoints,
eventX, eventY
});
}
public hideSharedCrosshair(): void {
this.crosshair.style('display', 'none');
}
// TODO: refactor to make xPosition and yPosition optional
// and trough error if they are provided for wrong orientation
moveCrosshairLine(xPosition: number, yPosition: number): void {
this.crosshair.style('display', null);
switch(this.options.crosshair.orientation) {
@ -290,18 +282,17 @@ class LinePod extends ChartwerkPod<LineTimeSerie, LineOptions> {
return _.max(intervals);
}
onMouseMove(): void {
getMouseObj(): MouseObj {
const eventX = d3.mouse(this.chartContainer.node())[0];
const eventY = d3.mouse(this.chartContainer.node())[1];
const xValue = this.state.xScale.invert(eventX); // mouse x position in xScale
const yValue = this.state.yScale.invert(eventY);
this.moveCrosshairLine(eventX, eventY);
const datapoints = this.findAndHighlightDatapoints(xValue, yValue);
// TDOO: is shift key pressed
// TODO: is shift key pressed
// TODO: need to refactor this object
this.options.callbackMouseMove({
return {
x: d3.event.pageX,
y: d3.event.pageY,
xVal: xValue,
@ -309,9 +300,40 @@ class LinePod extends ChartwerkPod<LineTimeSerie, LineOptions> {
series: datapoints,
chartX: eventX,
chartWidth: this.width
};
}
override onMouseMove(): void {
const obj = this.getMouseObj();
const eventX = d3.mouse(this.chartContainer.node())[0];
const eventY = d3.mouse(this.chartContainer.node())[1];
this.moveCrosshairLine(eventX, eventY);
// TODO: is shift key pressed
// TODO: need to refactor this object
this.options.callbackMouseMove(obj);
}
public renderSharedCrosshair(values: { x?: number, y?: number }): void {
this.showCrosshair();
this.moveCrosshairLine(
values.x ? this.state.xScale(values.x) : 0,
values.y ? this.state.yScale(values.y) : 0
);
const datapoints = this.findAndHighlightDatapoints(values.x, values.y);
this.options.callbackSharedCrosshairMove({
datapoints: datapoints,
eventX: values.x ? this.state.xScale(values.x) : 0,
eventY: values.y ? this.state.yScale(values.y) : 0
});
}
override onMouseClick(): void {
this.options.callbackMouseClick(this.getMouseObj());
}
findAndHighlightDatapoints(xValue: number, yValue: number): { value: [number, number], color: string, label: string }[] {
if(!this.series.isSeriesAvailable) {
return [];
@ -341,16 +363,26 @@ class LinePod extends ChartwerkPod<LineTimeSerie, LineOptions> {
return points;
}
onMouseOver(): void {
this.onMouseMove();
showCrosshair() {
this.crosshair.style('display', null);
this.crosshair.selectAll('.crosshair-circle')
.style('display', null);
}
onMouseOut(): void {
this.options.callbackMouseOut();
hideCrosshair() {
this.crosshair.style('display', 'none');
this.crosshair.selectAll('.crosshair-circle')
.style('display', 'none');
}
override onMouseOver(): void {
this.showCrosshair();
this.onMouseMove();
}
override onMouseOut(): void {
this.hideCrosshair();
this.options.callbackMouseOut();
}
isDoubleClickActive(): boolean {
@ -362,6 +394,14 @@ class LinePod extends ChartwerkPod<LineTimeSerie, LineOptions> {
this.onMouseOver();
}
updateMarkers(markersConf: MarkersConf): void {
this._markersConf = markersConf;
}
updateSegments(segments: SegmentSerie[]): void {
this._segmentSeries = segments;
}
// methods below rewrite s, (move more methods here)
protected zoomOut(): void {
if(d3.event.type === 'dblclick' && !this.isDoubleClickActive()) {
@ -403,7 +443,17 @@ class LinePod extends ChartwerkPod<LineTimeSerie, LineOptions> {
x: xAxisMiddleValue,
y: yAxisMiddleValue
}
this.options.callbackZoomOut(centers);
// TODO: refactor core not to take _options explicitly
if(
this.options._options.events !== undefined &&
this.options._options.events.zoomOut !== undefined
) {
this.options._options.events.zoomOut(
centers,
[this.state.xValueRange, this.state.yValueRange]
);
}
}
}

20
src/types.ts

@ -1,4 +1,5 @@
import { Serie, Options } from '@chartwerk/core';
import { AxisRange } from '@chartwerk/core/dist/types';
type LineTimeSerieParams = {
maxLength: number,
@ -10,4 +11,21 @@ type LineTimeSerieParams = {
}
export type LineTimeSerie = Serie & Partial<LineTimeSerieParams>;
export type LineOptions = Options;
export type LineOptions = Options & {
events? : {
zoomOut?: (centers: {
x: number;
y: number;
}, range: AxisRange[]) => void;
}
}
export type MouseObj = {
x: number,
y: number,
xVal: number,
yVal: number,
series: { value: [number, number], color: string, label: string }[],
chartX: number,
chartWidth: number
}

3
tsconfig.json

@ -19,6 +19,5 @@
"noUnusedLocals": false,
"baseUrl": "./src",
},
"include": ["src/**/*"],
"exclude": ["*.tsx"]
"include": ["src/**/*"]
}

10
yarn.lock

@ -5,13 +5,13 @@ __metadata:
version: 6
cacheKey: 8
"@chartwerk/core@npm:latest":
version: 0.6.14
resolution: "@chartwerk/core@npm:0.6.14"
"@chartwerk/core@npm:^0.6.23":
version: 0.6.23
resolution: "@chartwerk/core@npm:0.6.23"
dependencies:
d3: ^5.16.0
lodash: ^4.17.21
checksum: 34888b555d91a96d5a279f43dc4b33f345d055574855e1c90cb22913f7e42b13b6c9abbd0af07e6531b6f872cdf8e04660c22a2c14938189b67b9c494c6a0bfb
checksum: 629b0438e8cea02914e12956069d318caa98e6b3e2dd2514aab267474fa87e0aa92c190c4ca0fe95ca8091f83be1e1897801f5632c3f11d9cb3be39fa89cca84
languageName: node
linkType: hard
@ -19,7 +19,7 @@ __metadata:
version: 0.0.0-use.local
resolution: "@chartwerk/line-pod@workspace:."
dependencies:
"@chartwerk/core": latest
"@chartwerk/core": ^0.6.23
copy-webpack-plugin: ^11.0.0
css-loader: ^6.8.1
style-loader: ^3.3.3

Loading…
Cancel
Save