Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Porting to CHART.JS 3 (using master) #390

Merged
merged 24 commits into from
Nov 21, 2020
Merged

Conversation

stockiNail
Copy link
Contributor

fixes #376

@stockiNail
Copy link
Contributor Author

I submit this PR but I don't have enough experience about karma and testing part, therefore it should be review.
The tests should be anyway ready because I changed them to be align with new CHART.JS.
Be aware that I have tested it with dist/master (last commit) due to there are some new updates which are affecting the plugin

@benmccann
Copy link
Collaborator

@stockiNail it's possible that the tests are failing because you did not update the package.json file. Can you try updating it to use 3.0.0-beta.6 in both peerDependencies and devDependencies?

@@ -3,7 +3,8 @@

<head>
<title>Bar Chart Pan</title>
<script src="https://cdn.jsdelivr.net/npm/[email protected]"></script>
<!--script src="https://cdn.jsdelivr.net/npm/[email protected]"></script-->
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you could probably update this to 3.0.0-beta.6 now that it's out?

@stockiNail
Copy link
Contributor Author

I changed only the code because I'm not familiar with javascript and its compiling tools and configuration.
I'm also now working on some other topics.
I do my best to try asap.

@stockiNail
Copy link
Contributor Author

@benmccann I've started working on that

@stockiNail
Copy link
Contributor Author

@benmccann I've started working on that

FYI, only 1 test is failing now: should be called with default options
Let me take more time to fix it.

src/plugin.js Outdated
scale.options.ticks.min = rangeMinLimiter(zoomOptions, scale.min + minDelta);
scale.options.ticks.max = rangeMaxLimiter(zoomOptions, scale.max - maxDelta);
scale.options.min = rangeMinLimiter(zoomOptions, scale.min + minDelta);
scale.options.max = rangeMaxLimiter(zoomOptions, scale.max - maxDelta);
}

function zoomTimeScale(scale, zoom, center, zoomOptions) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you could remove this function now and call zoomNumericalScale where it's called since that's all it does anyway

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same with panTimeScale below

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you could remove this function now and call zoomNumericalScale where it's called since that's all it does anyway

done. I'm still having a look but I decided to push anyway the current updates

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same with panTimeScale below

I think you wanted to write panCategoryScale, doesn't it?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I mean is panTimeScale just calls panNumericalScale directly. You could just delete panTimeScale and call panNumericalScale where panTimeScale is used to avoid the extra method that no longer is really necessary

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done, removed also zoomTimeScale

@stockiNail
Copy link
Contributor Author

@benmccann fixed all test cases.
I have also implemented new defaults field of plugin in order to pass the defaults, instead of set the Chart.defaults.plugin.zoom.
I think now should be ok.

@stockiNail
Copy link
Contributor Author

@benmccann let me outline a couple of topics.
My updates had the goal to be able to use the plugin on CHART.JS 3 (in order to test it on my lib) and therefore I didn't apply any change on the logic or structure. It was simply changes on the calls.
Maybe going to a major version (I think it could be a good idea because CHART.JS is going to a major one) you would like to change and improve some logic or syntax of the current implementation.
In this case my help can be very low because I'm not a JS coder.

Other plugins of chartjs organization are now going to Chart.js 3 and I have seen that their building framework (and/or configuration) is changing.
I don't have any experiences on these topic (for JS) therefore I can not help too much if you would like to keep aligned this project with the others,
Apologize.
Anyway I think @kurkle and/or @simonbrunel can help more than me on this topic.
Maybe there is the goal that all plugins/projects of chartjs organization could be managed/compiled in the same way.

@benmccann
Copy link
Collaborator

Hmm. Seems I am prevented from merging this because Travis is down. I think I will need someone to disable Travis. Then we can turn on Github Actions (#402)

@stockiNail
Copy link
Contributor Author

Hmm. Seems I am prevented from merging this because Travis is down. I think I will need someone to disable Travis. Then we can turn on Github Actions (#402)

I have tried some changes on Travis configuration but it does not work. It looks like you said.

@benmccann benmccann closed this Nov 20, 2020
@benmccann benmccann reopened this Nov 20, 2020
@benmccann benmccann closed this Nov 20, 2020
@benmccann benmccann reopened this Nov 20, 2020
@benmccann
Copy link
Collaborator

@stockiNail I switched the build to GitHub Actions on master. It's passing on master, but looks to be failing on this PR. If you can get the GitHub check passing then we can merge this PR and ignore the Travis one that's hanging. I'm not sure if you need to rebase against master or if there's more you'll need to do

@stockiNail
Copy link
Contributor Author

@stockiNail I switched the build to GitHub Actions on master. It's passing on master, but looks to be failing on this PR. If you can get the GitHub check passing then we can merge this PR and ignore the Travis one that's hanging. I'm not sure if you need to rebase against master or if there's more you'll need to do

done! and sounds working

@stockiNail
Copy link
Contributor Author

@stockiNail I switched the build to GitHub Actions on master. It's passing on master, but looks to be failing on this PR. If you can get the GitHub check passing then we can merge this PR and ignore the Travis one that's hanging. I'm not sure if you need to rebase against master or if there's more you'll need to do

done! and sounds working

It went wrong but I don't know why because the branch is currently rebased to the master and locally the tests are working.

@benmccann
Copy link
Collaborator

Maybe it's running a different sequence of commands. You can run git clean -xdf to blow away all files in .gitignore locally and then try npm ci, npm build, npm test

@stockiNail
Copy link
Contributor Author

@benmccann I have seen the following message in GH actions log that I don't have::

20 11 2020 21:37:46.372:WARN [filelist]: Pattern "/home/runner/work/chartjs-plugin-zoom/chartjs-plugin-zoom/node_modules/chart.js/dist/Chart.js" does not match any file.

The issue seems to be related to the path.
I dont' know why there is chartjs-plugin-zoom/chartjs-plugin-zoom. Sounds an error.

I have changed Karma configuration setting the basePath to '..' and in fact the tests went good (see log GHA):

Chrome 86.0.4240.198 (Linux x86_64): Executed 0 of 0 SUCCESS (0.001 secs / 0 secs)
Firefox 82.0 (Ubuntu 0.0.0): Executed 0 of 0 SUCCESS (0.077 secs / 0 secs)
TOTAL: 0 SUCCESS

but it's wrong to set '..'' because some warnings/issues are still there for this path and also locally it does not work with basePath '..', of course.

Therefore I revert the change, going to default basePath (as formerly was).

@kurkle
Copy link
Member

kurkle commented Nov 20, 2020

You need to make the node_modules/chart.js/dist/Chart.js lower case in karma config.

@stockiNail
Copy link
Contributor Author

You need to make the node_modules/chart.js/dist/Chart.js lower case in karma config.

@kurkle as usual, ur awesome!! THANK YOU! I was getting crazy even because I don't know Karma and GHA....

@stockiNail
Copy link
Contributor Author

You need to make the node_modules/chart.js/dist/Chart.js lower case in karma config.

Anyway something sounds strange, because setting basePath to ".." the tests ended correctly... I don't know why.
But now it works.

@kurkle
Copy link
Member

kurkle commented Nov 20, 2020

Anyway something sounds strange, because setting basePath to ".." the tests ended correctly... I don't know why.

I think it just did not find the tests anymore: TOTAL: 0 SUCCESS

@stockiNail
Copy link
Contributor Author

You are right... :(

@@ -4,9 +4,10 @@
<head>
<title>Line Chart</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.13.0/moment.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/chartjs-adapter-moment.min.js"></script>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make this just https://cdn.jsdelivr.net/npm/[email protected] instead of https://cdn.jsdelivr.net/npm/[email protected]/dist/chartjs-adapter-moment.min.js ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

src/plugin.js Outdated
}
}

function panTimeScale(scale, delta, panOptions) {
function panCategoryScale(scale, delta, panOptions) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you move this back above panNumericalScale? It's difficult to tell what's change since its location in the file has changed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not possible, due to:

  115:1   warning  Function 'zoomCategoryScale' has a complexity of 15  complexity
  240:2   error    'panNumericalScale' was used before it was defined   no-use-before-define
  243:1   warning  Function 'panNumericalScale' has a complexity of 13  complexity
  413:41  warning  Function has a complexity of 11                      complexity

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want to use the panNumericScale into panCategoryScale, we must define it before, otherwise we must remove the rule of no-use-before-define.
As you prefer.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. Let's not use panNumericScale in panCategoryScale to minimize the number of changes in this PR

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. Let's not use panNumericScale in panCategoryScale to minimize the number of changes in this PR

Done!

@benmccann benmccann merged commit 49de6c1 into chartjs:master Nov 21, 2020
@benmccann
Copy link
Collaborator

thank you so much for all the work on this upgrade!! appreciate your patience working through the issues and comments

@stockiNail
Copy link
Contributor Author

@benmccann I have to thank you for your patience.
You gave me the possibility to learn a lot about JS world and the chance to support better the users of my lib ad well.
I think this should be a starting point for this plugin because some items could be implemented (i.e. type definitions for TS, Javascript classes instead of adding functions to chart object) like other plugins of chartjs org are doing.

@benmccann
Copy link
Collaborator

Yes, the code for this plugin is a bit outdated and it would be nice to update it to more closely match the setup of the main library and the other plugins

@KoalaBear84
Copy link

Great to see it supporting v3. How can I use this? (As it is not yet released as a version).

Because when I put the plugin.js in my project and add it as a script tag I get the following error:
Uncaught SyntaxError: Cannot use import statement outside a module

And when I add type="module" to the script tag it says this:
Uncaught TypeError: Failed to resolve module specifier "chart.js". Relative references must start with either "/", "./", or "../".

I guess I need to add it all separately then. But having too low knowledge of Javascript module things :)

@stockiNail
Copy link
Contributor Author

Great to see it supporting v3. How can I use this? (As it is not yet released as a version).

Because when I put the plugin.js in my project and add it as a script tag I get the following error:
Uncaught SyntaxError: Cannot use import statement outside a module

And when I add type="module" to the script tag it says this:
Uncaught TypeError: Failed to resolve module specifier "chart.js". Relative references must start with either "/", "./", or "../".

I guess I need to add it all separately then. But having too low knowledge of Javascript module things :)

Answered in #376

@stockiNail stockiNail deleted the chartjs3 branch November 26, 2020 10:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Compatibility with Chart js 3.0
4 participants